haikuwebkit/LayoutTests/crypto/subtle/wrap-key-malformed-paramete...

55 lines
1.6 KiB
HTML
Raw Permalink Normal View History

Update SubtleCrypto::wrapKey to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=164746 <rdar://problem/29258160> Reviewed by Brent Fulgham. LayoutTests/imported/w3c: * WebCryptoAPI/idlharness-expected.txt: Source/WebCore: This patch does following few things: 1. It updates the SubtleCrypto::wrapKey method to match the latest spec: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-wrapKey. It also refers to the latest Editor's Draft to a certain degree: https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-wrapKey. 2. It implements wrapKey operations of the following algorithms: AES-KW. 3. It also replaces JSSubtleCrypto* with auto in all promise functions. Tests: crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-private.html crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-public.html crypto/subtle/aes-kw-import-key-wrap-raw-key.html crypto/subtle/aes-kw-wrap-key-malformed-parameters.html crypto/subtle/rsa-oaep-import-key-wrap-jwk-oct-key.html crypto/subtle/wrapKey-malformed-parameters.html crypto/workers/subtle/aes-cbc-import-key-wrap-key.html crypto/workers/subtle/aes-kw-import-key-wrap-key.html crypto/workers/subtle/rsa-oaep-import-key-wrap-key.html * bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::normalizeCryptoAlgorithmParameters): (WebCore::supportExportKeyThrow): (WebCore::jsSubtleCryptoFunctionEncryptPromise): (WebCore::jsSubtleCryptoFunctionDecryptPromise): (WebCore::jsSubtleCryptoFunctionExportKeyPromise): (WebCore::jsSubtleCryptoFunctionWrapKeyPromise): (WebCore::JSSubtleCrypto::wrapKey): * crypto/CryptoAlgorithm.cpp: (WebCore::CryptoAlgorithm::wrapKey): * crypto/CryptoAlgorithm.h: * crypto/SubtleCrypto.idl: * crypto/algorithms/CryptoAlgorithmAES_KW.cpp: (WebCore::CryptoAlgorithmAES_KW::wrapKey): * crypto/algorithms/CryptoAlgorithmAES_KW.h: * crypto/gnutls/CryptoAlgorithmAES_KWGnuTLS.cpp: (WebCore::CryptoAlgorithmAES_KW::platformWrapKey): * crypto/mac/CryptoAlgorithmAES_KWMac.cpp: (WebCore::wrapKeyAES_KW): (WebCore::CryptoAlgorithmAES_KW::platformWrapKey): (WebCore::CryptoAlgorithmAES_KW::platformEncrypt): LayoutTests: * crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-private-expected.txt: Added. * crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-private.html: Added. * crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-public-expected.txt: Added. * crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-public.html: Added. * crypto/subtle/aes-kw-import-key-wrap-raw-key-expected.txt: Added. * crypto/subtle/aes-kw-import-key-wrap-raw-key.html: Added. * crypto/subtle/aes-kw-wrap-key-malformed-parameters-expected.txt: Added. * crypto/subtle/aes-kw-wrap-key-malformed-parameters.html: Added. * crypto/subtle/rsa-oaep-import-key-wrap-jwk-oct-key-expected.txt: Added. * crypto/subtle/rsa-oaep-import-key-wrap-jwk-oct-key.html: Added. * crypto/subtle/wrapKey-malformed-parameters-expected.txt: Added. * crypto/subtle/wrapKey-malformed-parameters.html: Added. * crypto/workers/subtle/aes-cbc-import-key-wrap-key-expected.txt: Added. * crypto/workers/subtle/aes-cbc-import-key-wrap-key.html: Added. * crypto/workers/subtle/aes-kw-import-key-wrap-key-expected.txt: Added. * crypto/workers/subtle/aes-kw-import-key-wrap-key.html: Added. * crypto/workers/subtle/resources/aes-cbc-import-key-wrap-key.js: Added. * crypto/workers/subtle/resources/aes-kw-import-key-wrap-key.js: Added. * crypto/workers/subtle/resources/rsa-oaep-import-key-wrap-key.js: Added. * crypto/workers/subtle/rsa-oaep-import-key-wrap-key-expected.txt: Added. * crypto/workers/subtle/rsa-oaep-import-key-wrap-key.html: Added. Canonical link: https://commits.webkit.org/182841@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209155 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-30 22:26:10 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test WrapKey operation with malformed parameters");
jsTestIsAsync = true;
var extractable = true;
var nonExtractable = false;
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
var aesCbcParams = {
name: "aes-cbc",
iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
}
// Not enough arguments.
shouldReject('crypto.subtle.wrapKey()');
shouldReject('crypto.subtle.wrapKey(1)');
shouldReject('crypto.subtle.wrapKey(1, 2)');
shouldReject('crypto.subtle.wrapKey(1, 2, 3)');
crypto.subtle.importKey("raw", rawKey, "aes-kw", extractable, ["wrapKey", "unwrapKey"]).then(function(result) {
wrappingKey = result;
return crypto.subtle.importKey("raw", rawKey, "aes-cbc", nonExtractable, ["encrypt", "decrypt"]);
}).then(function(result) {
key = result;
// Wrong AlgorithmIdentifier
shouldReject('crypto.subtle.wrapKey("raw", key, wrappingKey, "HMAC")');
shouldReject('crypto.subtle.wrapKey("raw", key, wrappingKey, aesCbcParams)');
// Non-extractable
shouldReject('crypto.subtle.wrapKey("raw", key, wrappingKey, "AES-KW")');
return crypto.subtle.importKey("raw", rawKey, "aes-kw", extractable, ["unwrapKey"]);
}).then(function(result) {
wrappingKey = result;
// Wrong usage
shouldReject('crypto.subtle.wrapKey("raw", key, wrappingKey, "AES-KW")').then(finishJSTest);
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>