haikuwebkit/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-key...

49 lines
3.0 KiB
HTML
Raw Permalink Normal View History

Update SubtleCrypto::decrypt to match the latest spec https://bugs.webkit.org/show_bug.cgi?id=164739 <rdar://problem/29257848> Reviewed by Brent Fulgham. LayoutTests/imported/w3c: * WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt: * WebCryptoAPI/idlharness-expected.txt: Source/WebCore: This patch does following few things: 1. It updates the SubtleCrypto::decrypt method to match the latest spec: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-decrypt. It also refers to the latest Editor's Draft to a certain degree: https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-decrypt. 2. It implements decrypt operations of the following algorithms: AES-CBC, RSAES-PKCS1-V1_5, and RSA-OAEP. Tests: crypto/subtle/aes-cbc-decrypt-malformed-parameters.html crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html crypto/subtle/aes-cbc-import-key-decrypt.html crypto/subtle/decrypt-malformed-parameters.html crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html crypto/subtle/rsa-oaep-import-key-decrypt-label.html crypto/subtle/rsa-oaep-import-key-decrypt.html crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html crypto/workers/subtle/aes-cbc-import-key-decrypt.html crypto/workers/subtle/rsa-oaep-import-key-decrypt.html crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html * bindings/js/JSSubtleCryptoCustom.cpp: (WebCore::normalizeCryptoAlgorithmParameters): (WebCore::toCryptoKey): (WebCore::toVector): (WebCore::jsSubtleCryptoFunctionEncryptPromise): (WebCore::jsSubtleCryptoFunctionDecryptPromise): (WebCore::jsSubtleCryptoFunctionExportKeyPromise): (WebCore::JSSubtleCrypto::decrypt): * crypto/CryptoAlgorithm.cpp: (WebCore::CryptoAlgorithm::decrypt): * crypto/CryptoAlgorithm.h: * crypto/SubtleCrypto.idl: * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: (WebCore::CryptoAlgorithmAES_CBC::decrypt): * crypto/algorithms/CryptoAlgorithmAES_CBC.h: * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp: (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt): * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h: * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp: (WebCore::CryptoAlgorithmRSA_OAEP::decrypt): * crypto/algorithms/CryptoAlgorithmRSA_OAEP.h: * crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp: (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): * crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp: (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt): * crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp: (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp: (WebCore::decryptRSAES_PKCS1_v1_5): (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt): * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp: (WebCore::decryptRSA_OAEP): (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt): LayoutTests: * crypto/subtle/aes-cbc-decrypt-malformed-parameters-expected.txt: Added. * crypto/subtle/aes-cbc-decrypt-malformed-parameters.html: Added. * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt-expected.txt: Added. * crypto/subtle/aes-cbc-generate-key-encrypt-decrypt.html: Added. * crypto/subtle/aes-cbc-import-key-decrypt-expected.txt: Added. * crypto/subtle/aes-cbc-import-key-decrypt.html: Added. * crypto/subtle/decrypt-malformed-parameters-expected.txt: Added. * crypto/subtle/decrypt-malformed-parameters.html: Added. * crypto/subtle/rsa-oaep-decrypt-malformed-parameters-expected.txt: Added. * crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html: Added. * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-expected.txt: Added. * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label-expected.txt: Added. * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html: Added. * crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html: Added. * crypto/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added. * crypto/subtle/rsa-oaep-import-key-decrypt-label-expected.txt: Added. * crypto/subtle/rsa-oaep-import-key-decrypt-label.html: Added. * crypto/subtle/rsa-oaep-import-key-decrypt.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added. * crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added. * crypto/workers/subtle/aes-cbc-import-key-decrypt-expected.txt: Added. * crypto/workers/subtle/aes-cbc-import-key-decrypt.html: Added. * crypto/workers/subtle/resources/aes-cbc-import-key-decrypt.js: Added. * crypto/workers/subtle/resources/rsa-oaep-import-key-decrypt.js: Added. * crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-decrypt.js: Added. * crypto/workers/subtle/rsa-oaep-import-key-decrypt-expected.txt: Added. * crypto/workers/subtle/rsa-oaep-import-key-decrypt.html: Added. * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt-expected.txt: Added. * crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html: Added. Canonical link: https://commits.webkit.org/182627@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208918 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-19 04:38:59 +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 decrypting using RSAES-PKCS1-v1_5 with an imported key");
jsTestIsAsync = true;
var extractable = false;
var cipherText = hexStringToUint8Array("87ca360442614b6590ea51ba84eb081ecda83c5a19e008ed21a6b93c78a7980348f9eac9a8120a6b67326b58ff6e7a10bec113b01f6bd18a04b82d159eb3532c03d4fca597450333cd4df81456b7b864a276cc3a7551964ccc16de86e2bc7a42981f29a0855fc151692d802f6d0b6fdcc0cc01977c579acde220b60d418a480f0ccdfd370f7e045114be39f03dfd516b51bcba6af20663cb2404e4e8c5b4c239936c672c3c2de4f4f3382cdc68f277fc66ed06a0642584ead53cd676673e8cecf59fe23cbe0a59cd82c8d56187eff6cda9b9e600b9890f42c65ee9a4f16f87c1c0b53cecb6fb59a4de165cc828d6bc5b5bf152e6c3060b54fd4e11b037668e4d");
var jwkKey = {
kty: "RSA",
alg: "RSA1_5",
use: "enc",
key_ops: ["decrypt", "unwrapKey"],
ext: true,
n: "lxHN0N9VRZ0_pl0xv3-NXx70WnjkODSkQ5LjHXTFy3DOQsvkagFzD9HqYQezCmcewLjdK5PLwSesDoMdfL6tusBHcvyit1kvydYFQ3NLbENNkYsiBG5_nW4IQGL6JKbZ5iGdUop98QHKm6YZR1u4zrAtxM6bVEo05VvhjRS0M8yWoZVi-7Vdsc0LqI0Qdq_NoctX5Fu-AqiBN7Uo1HkYGcP2oC82J_J5cjw98BQiP5kDWThq9RK-X6S-EUALx_m4iG6iOYKTA3SQyf1xBqFaXXoEJjcckbOqkegecz5b-YWUh8iZPvhwnt-RZwpIbLJgKwz19ndkn9KvoEEw7YbEow",
e: "AQAB",
d: "cj5DkDakjM2bKduGWJREO-_zyEtuA1dD9doqKMd7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Ulyr9bSFTwUBW4vXa8Xj9a8JfViuMCqzR-mL1rGIUQ5ARGhNcSsRlyKTqz5BlWlVKmXIx_p-DeVwPWiJJy4k_FqyBxrnxkzomHfrxk",
};
var expectedPlainText = "Hello, World!";
crypto.subtle.importKey("jwk", jwkKey, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]).then(function(key) {
return crypto.subtle.decrypt("RSAES-PKCS1-v1_5", key, cipherText);
}).then(function(result) {
plainText = result;
shouldBe("bytesToASCIIString(plainText)", "expectedPlainText");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>