[Part 2 of 2] Add support for PKCS8 format while doing SubtleCrypto.importKey/exportKey
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Dec 2016 23:05:29 +0000 (23:05 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Dec 2016 23:05:29 +0000 (23:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129978
<rdar://problem/21799829>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt:

Source/WebCore:

This is part 2 of Bug 129978. In this patch, it adds the PKCS8 format support for
SubtleCrypto.importKey/exportKey. Currently support algorithms are RSAES-PKCS1-v1_5,
RSASSA-PKCS1-v1_5 and RSA-OAEP.

Tests: crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html
       crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html
       crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html
       crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html
       crypto/subtle/rsa-oaep-import-pkcs8-key.html
       crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html
       crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html
       crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html
       crypto/workers/subtle/rsa-export-pkcs8-key.html
       crypto/workers/subtle/rsa-import-pkcs8-key.html

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::toKeyData):
* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::exportKey):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::exportKey):
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::importKey):
(WebCore::CryptoAlgorithmRSA_OAEP::exportKey):
* crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
(WebCore::CryptoKeyRSA::importPkcs8):
(WebCore::CryptoKeyRSA::exportPkcs8):
* crypto/keys/CryptoKeyRSA.h:
* crypto/mac/CryptoKeyRSAMac.cpp:
(WebCore::CryptoKeyRSA::importSpki):
(WebCore::CryptoKeyRSA::importPkcs8):
(WebCore::CryptoKeyRSA::exportPkcs8):

LayoutTests:

* crypto/subtle/import-key-malformed-parameters-expected.txt:
* crypto/subtle/import-key-malformed-parameters.html:
* crypto/subtle/rsa-export-key-malformed-parameters-expected.txt:
* crypto/subtle/rsa-export-key-malformed-parameters.html:
* crypto/subtle/rsa-import-jwk-key-export-pkcs8-key-expected.txt: Added.
* crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html: Added.
* crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt:
* crypto/subtle/rsa-import-jwk-key-export-spki-key.html:
* crypto/subtle/rsa-import-key-malformed-parameters-expected.txt:
* crypto/subtle/rsa-import-key-malformed-parameters.html:
* crypto/subtle/rsa-import-pkcs8-key-export-jwk-key-expected.txt: Added.
* crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html: Added.
* crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key-expected.txt: Added.
* crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html: Added.
* crypto/subtle/rsa-oaep-generate-export-key-pkcs8-expected.txt: Added.
* crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html: Added.
* crypto/subtle/rsa-oaep-import-pkcs8-key-expected.txt: Added.
* crypto/subtle/rsa-oaep-import-pkcs8-key.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html: Added.
* crypto/workers/subtle/resources/rsa-export-pkcs8-key.js: Added.
* crypto/workers/subtle/resources/rsa-import-pkcs8-key.js: Added.
* crypto/workers/subtle/rsa-export-pkcs8-key-expected.txt: Added.
* crypto/workers/subtle/rsa-export-pkcs8-key.html: Added.
* crypto/workers/subtle/rsa-import-pkcs8-key-expected.txt: Added.
* crypto/workers/subtle/rsa-import-pkcs8-key.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209633 268f45cc-cd09-0410-ab3c-d52691b4dbfc

43 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/import-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/import-key-malformed-parameters.html
LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html
LayoutTests/crypto/subtle/rsa-import-jwk-key-export-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt
LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key.html
LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters.html
LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-jwk-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-pkcs8-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-oaep-import-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsa-oaep-import-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/rsa-export-pkcs8-key.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/rsa-import-pkcs8-key.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/rsa-export-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/rsa-export-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/rsa-import-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/rsa-import-pkcs8-key.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp
Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp
Source/WebCore/crypto/keys/CryptoKeyRSA.h
Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp

index 3e0f458..4c94b0f 100644 (file)
@@ -1,3 +1,44 @@
+2016-12-06  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [Part 2 of 2] Add support for PKCS8 format while doing SubtleCrypto.importKey/exportKey
+        https://bugs.webkit.org/show_bug.cgi?id=129978
+        <rdar://problem/21799829>
+
+        Reviewed by Brent Fulgham.
+
+        * crypto/subtle/import-key-malformed-parameters-expected.txt:
+        * crypto/subtle/import-key-malformed-parameters.html:
+        * crypto/subtle/rsa-export-key-malformed-parameters-expected.txt:
+        * crypto/subtle/rsa-export-key-malformed-parameters.html:
+        * crypto/subtle/rsa-import-jwk-key-export-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html: Added.
+        * crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt:
+        * crypto/subtle/rsa-import-jwk-key-export-spki-key.html:
+        * crypto/subtle/rsa-import-key-malformed-parameters-expected.txt:
+        * crypto/subtle/rsa-import-key-malformed-parameters.html:
+        * crypto/subtle/rsa-import-pkcs8-key-export-jwk-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html: Added.
+        * crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html: Added.
+        * crypto/subtle/rsa-oaep-generate-export-key-pkcs8-expected.txt: Added.
+        * crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html: Added.
+        * crypto/subtle/rsa-oaep-import-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/rsa-oaep-import-pkcs8-key.html: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html: Added.
+        * crypto/workers/subtle/resources/rsa-export-pkcs8-key.js: Added.
+        * crypto/workers/subtle/resources/rsa-import-pkcs8-key.js: Added.
+        * crypto/workers/subtle/rsa-export-pkcs8-key-expected.txt: Added.
+        * crypto/workers/subtle/rsa-export-pkcs8-key.html: Added.
+        * crypto/workers/subtle/rsa-import-pkcs8-key-expected.txt: Added.
+        * crypto/workers/subtle/rsa-import-pkcs8-key.html: Added.
+
 2016-12-09  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Some resources fetched via Fetch API do not have data
index fe13734..0ba56e6 100644 (file)
@@ -15,7 +15,6 @@ PASS crypto.subtle.importKey(undefined, rawKey, "aes-cbc", extractable, ["encryp
 PASS crypto.subtle.importKey(Symbol(), rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise  with TypeError: Type error.
 PASS crypto.subtle.importKey({ }, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise  with TypeError: Type error.
 PASS crypto.subtle.importKey("foo", rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise  with TypeError: Type error.
-PASS crypto.subtle.importKey("pkcs8", rawKey, "rsaes-pkcs1-v1_5", extractable, ["encrypt", "decrypt"]) rejected promise  with NotSupportedError (DOM Exception 9): The operation is not supported..
 PASS crypto.subtle.importKey("raw", jwkKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise  with TypeError: Type error.
 PASS crypto.subtle.importKey("raw", 1, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise  with TypeError: Type error.
 PASS crypto.subtle.importKey("raw", true, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise  with TypeError: Type error.
index 3dfc051..27da942 100644 (file)
@@ -48,8 +48,6 @@ shouldReject('crypto.subtle.importKey(undefined, rawKey, "aes-cbc", extractable,
 shouldReject('crypto.subtle.importKey(Symbol(), rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
 shouldReject('crypto.subtle.importKey({ }, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
 shouldReject('crypto.subtle.importKey("foo", rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
-// Currently not support formats.
-shouldReject('crypto.subtle.importKey("pkcs8", rawKey, "rsaes-pkcs1-v1_5", extractable, ["encrypt", "decrypt"])');
 // Wrong KeyData.
 shouldReject('crypto.subtle.importKey("raw", jwkKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
 shouldReject('crypto.subtle.importKey("raw", 1, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
index 0dde9b2..98e1ed6 100644 (file)
@@ -3,7 +3,7 @@ Test exporting a RSA key with malformed parameters
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS crypto.subtle.exportKey("pkcs8", publicKey) rejected promise  with NotSupportedError (DOM Exception 9): The algorithm is not supported.
+PASS crypto.subtle.exportKey("pkcs8", publicKey) rejected promise  with InvalidAccessError (DOM Exception 15): The requested operation is not valid for the provided key.
 PASS crypto.subtle.exportKey("raw", publicKey) rejected promise  with NotSupportedError (DOM Exception 9): The algorithm is not supported.
 PASS crypto.subtle.exportKey("spki", privateKey) rejected promise  with InvalidAccessError (DOM Exception 15): The requested operation is not valid for the provided key.
 PASS successfullyParsed is true
index 619a2f8..b802972 100644 (file)
@@ -26,7 +26,7 @@ crypto.subtle.generateKey(algorithmKeyGen, extractable, ["decrypt", "encrypt", "
     publicKey = result.publicKey;
     privateKey = result.privateKey;
 
-    // Currently not support format.
+    // Wrong key and format.
     return shouldReject('crypto.subtle.exportKey("pkcs8", publicKey)');
 }).then(function() {
     // Not support format.
diff --git a/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..9c55eab
--- /dev/null
@@ -0,0 +1,12 @@
+Test importing a JWK RSA-OAEP public key with SHA-1 and then export it in PKCS8 format
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+Exporting a key...
+PASS bytesToHexString(pkcs8Key) is expectedPkcs8Key
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html b/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html
new file mode 100644 (file)
index 0000000..2206b61
--- /dev/null
@@ -0,0 +1,49 @@
+<!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 importing a JWK RSA-OAEP public key with SHA-1 and then export it in PKCS8 format");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RSA-OAEP",
+    key_ops: ["decrypt", "unwrapKey"],
+    ext: true,
+    n: "v_dgJnIz-_l4noBUwEkMAc-TkUXOBXUb4homc5oLYbVKYee51acuc3m26xK-vPD7VMCwEt17ylKW6jiEIEG50cZxzvCnGn2AiaqzVeqmm79htT93aX74yD6lginrtSSky5pasjxLlIzvEEGCC3zuupFyxXmCztY3AXbfcTscgWgSiNrgNzuuxtG6tbigc9gEPQj8XgSecr8XXKTqVbwQwh8rOao2rHfe_IjiXwElsTaL2sl3IHIrHx6NVbj54_0HCuo5AZ4ZyJ_bkLVBFe4gO9pIlhVuAHr6adlM83-moDeowYKqU4me_2GR_JspZ3Kif-WEwSY6jJuIn7qXtD5jUw",
+    e: "AQAB",
+    d: "DxvDH4OBf-VkjuT-xpt5LHNP4_Egg-FxrlvshtCq8Ke6EPaR87TSvRfpQ5sYE_rLbSI1OWbhJU1Wv1xvWbKSk2YQ8v6RyE30XeFnd-2d60gmwoMaPN1Xazsy_4mZGYqmxbeCR-Di-fAVqKvfNlRA3cIwzEYB-5F0htL6Rwkl9zE8th1DTuBvqBLoTxYZKLnoCN8YdfTUr-CQOghMafCwi3ltAkZqxNNqP9RRSqfkNCqAKK_23jhXS9yZSes3QEO1LBxDNpdumIk4smpO_iFhxd5I68s8JCDogfNQulmErrYbAk6cAUXNMvpua9ipH-uIw8qgakzKfD6lIQmeFoM7MQ",
+    p: "7uKCNGo6nH5Kk6zz6H6n3LAkKr45IQb1CfyLi6Po-6lxHt2a5bi5CkRH7PNUz3QRYWAkYmlpfvoAqzXhOYIUewvcbzyzTUxpv-F1Xbw9KV6nc1LFe8W8733AzLtHBgjimwU9VYgsmV7DJDP7djODjskSGPC9O9rcq7jK_1atFy8",
+    q: "zbhQdf5AX_ssgZALSFhMmvR39c2XJXBLFuAF_c1EBRtch3X-_DgHiZ1srZrdIbnI7yjx7smJPg1Met1pHTgrk9jdlGwkzxFQWgo5XbhergrB7njOtWmkTUlpd01zidk0Nh138KTCchVe7h4JKy7wIomw9256B3ozh0DuP7eIrR0",
+    dp: "C5HAyJUUfZvINNq9fVcU_iUxuzg3QBg8Kd2nTH4FvJp6Ngp5hAKsQ4kHCrzGML3oUZT8bh-40kN9YM1dORHJuCPc6y4_aND4lihvLLj_JU_GQFmT4uiyu86VVdUEHZC0mNlqHQhZUJw8SzaRSSo5huLKE5clMw7ofRCYFEG4ZFU",
+    dq: "axFbpx2N6aZzUndit-Nk81z7Nk4rNUwNeLldxOtZVIMaFFKARErw-Vman3wzTQNBpd-ckxgHOul2_ZdQxuleHNPI9x-VxMORG1uo4bM8a76jkncDtn1mCueDYZlI4dzPBL8vlmpZ3UBsKOgvA2-pgYBCP3UbQ9sBCIrttPHTy60",
+    qi: "o3RcFTK_WfBFceq7ZG3u3imgQkIfRWZorEAKBffBNw0ggh7XjKKNx_dAinTmCE_UlNih-kO9UPTPEI3QyB3i_BIxcm122Ldzot-9Q7H-hsQ6p7AODSlc3xfYNQEG5PjEsDBBG_GlybmDeblhr67s2hDPEmMgAuoXNHxf4QMvmqM",
+};
+var expectedPkcs8Key = "308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100bff760267233fbf9789e8054c0490c01cf939145ce05751be21a26739a0b61b54a61e7b9d5a72e7379b6eb12bebcf0fb54c0b012dd7bca5296ea38842041b9d1c671cef0a71a7d8089aab355eaa69bbf61b53f77697ef8c83ea58229ebb524a4cb9a5ab23c4b948cef1041820b7ceeba9172c57982ced6370176df713b1c81681288dae0373baec6d1bab5b8a073d8043d08fc5e049e72bf175ca4ea55bc10c21f2b39aa36ac77defc88e25f0125b1368bdac97720722b1f1e8d55b8f9e3fd070aea39019e19c89fdb90b54115ee203bda4896156e007afa69d94cf37fa6a037a8c182aa53899eff6191fc9b296772a27fe584c1263a8c9b889fba97b43e63530203010001028201000f1bc31f83817fe5648ee4fec69b792c734fe3f12083e171ae5bec86d0aaf0a7ba10f691f3b4d2bd17e9439b1813facb6d22353966e1254d56bf5c6f59b292936610f2fe91c84df45de16777ed9deb4826c2831a3cdd576b3b32ff8999198aa6c5b78247e0e2f9f015a8abdf365440ddc230cc4601fb917486d2fa470925f7313cb61d434ee06fa812e84f161928b9e808df1875f4d4afe0903a084c69f0b08b796d02466ac4d36a3fd4514aa7e4342a8028aff6de38574bdc9949eb374043b52c1c4336976e988938b26a4efe2161c5de48ebcb3c2420e881f350ba5984aeb61b024e9c0145cd32fa6e6bd8a91feb88c3caa06a4cca7c3ea521099e16833b3102818100eee282346a3a9c7e4a93acf3e87ea7dcb0242abe392106f509fc8b8ba3e8fba9711edd9ae5b8b90a4447ecf354cf74116160246269697efa00ab35e13982147b0bdc6f3cb34d4c69bfe1755dbc3d295ea77352c57bc5bcef7dc0ccbb470608e29b053d55882c995ec32433fb7633838ec91218f0bd3bdadcabb8caff56ad172f02818100cdb85075fe405ffb2c81900b48584c9af477f5cd9725704b16e005fdcd44051b5c8775fefc3807899d6cad9add21b9c8ef28f1eec9893e0d4c7add691d382b93d8dd946c24cf11505a0a395db85eae0ac1ee78ceb569a44d4969774d7389d934361d77f0a4c272155eee1e092b2ef02289b0f76e7a077a338740ee3fb788ad1d0281800b91c0c895147d9bc834dabd7d5714fe2531bb383740183c29dda74c7e05bc9a7a360a798402ac4389070abcc630bde85194fc6e1fb8d2437d60cd5d3911c9b823dceb2e3f68d0f896286f2cb8ff254fc6405993e2e8b2bbce9555d5041d90b498d96a1d0859509c3c4b3691492a3986e2ca139725330ee87d10981441b864550281806b115ba71d8de9a673527762b7e364f35cfb364e2b354c0d78b95dc4eb5954831a145280444af0f9599a9f7c334d0341a5df9c9318073ae976fd9750c6e95e1cd3c8f71f95c4c3911b5ba8e1b33c6bbea3927703b67d660ae783619948e1dccf04bf2f966a59dd406c28e82f036fa98180423f751b43db01088aedb4f1d3cbad02818100a3745c1532bf59f04571eabb646deede29a042421f456668ac400a05f7c1370d20821ed78ca28dc7f7408a74e6084fd494d8a1fa43bd50f4cf108dd0c81de2fc1231726d76d8b773a2dfbd43b1fe86c43aa7b00e0d295cdf17d8350106e4f8c4b030411bf1a5c9b98379b961afaeecda10cf12632002ea17347c5fe1032f9aa3";
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]).then(function(cryptoKey) {
+    debug("Exporting a key...");
+    return crypto.subtle.exportKey("pkcs8", cryptoKey);
+}).then(function(result) {
+    pkcs8Key = result;
+
+    shouldBe("bytesToHexString(pkcs8Key)", "expectedPkcs8Key");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index 727e91f..54f2387 100644 (file)
@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 
 Importing a key...
 Exporting a key...
-PASS exportedSpkiKey.byteLength is 294
+PASS bytesToHexString(spkiKey) is expectedSpkiKey
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 3e8909d..81c2457 100644 (file)
@@ -21,6 +21,7 @@ var jwkKey = {
     n: "p55Xl-DyqKL06TE8GCuXd_e-ruTqVB19iDH6DwTIknTyM0fl8EY6qsyOBNTxjpLDsOldEJ8QblG78WY7xYTZtNn-fimz5eG80bwSZ6FUO10z3ikeKzPPC7K4AA196rMoiEu2G4mSfqeg5zz6_iqHf8u_md_n8yk_iPaXJ9RVT-W4zEQQ6WSlsOtYa7blSSAlq0JYDJciNeE0RGqUU-UjcxUWIEnT2ODHGRzSfKHgc8O3fGt4dpVm0op1yItBcSAY-0_f1p_YrVDo8bsyq2uodyDGYhcuQgYJ0NjMgT_rb8rUPpR3bUitd-IZJd_NO9i_NmvbnQfgl6kfnxe_2kM4Tw",
     e: "AQAB"
 };
+var expectedSpkiKey = "30820122300d06092a864886f70d01010105000382010f003082010a0282010100a79e5797e0f2a8a2f4e9313c182b9777f7beaee4ea541d7d8831fa0f04c89274f23347e5f0463aaacc8e04d4f18e92c3b0e95d109f106e51bbf1663bc584d9b4d9fe7e29b3e5e1bcd1bc1267a1543b5d33de291e2b33cf0bb2b8000d7deab328884bb61b89927ea7a0e73cfafe2a877fcbbf99dfe7f3293f88f69727d4554fe5b8cc4410e964a5b0eb586bb6e5492025ab42580c972235e134446a9453e5237315162049d3d8e0c7191cd27ca1e073c3b77c6b78769566d28a75c88b41712018fb4fdfd69fd8ad50e8f1bb32ab6ba87720c662172e420609d0d8cc813feb6fcad43e94776d48ad77e21925dfcd3bd8bf366bdb9d07e097a91f9f17bfda43384f0203010001";
 var extractable = true;
 
 debug("Importing a key...");
@@ -28,9 +29,9 @@ crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "sha-1"}, extrac
     debug("Exporting a key...");
     return crypto.subtle.exportKey("spki", cryptoKey);
 }).then(function(result) {
-    exportedSpkiKey = result;
+    spkiKey = result;
 
-    shouldBe("exportedSpkiKey.byteLength", "294");
+    shouldBe("bytesToHexString(spkiKey)", "expectedSpkiKey");
 
     finishJSTest();
 });
index fde18ae..9eed309 100644 (file)
@@ -39,6 +39,19 @@ PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, d
 PASS crypto.subtle.importKey("spki", spkiKey, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with SyntaxError (DOM Exception 12): A required parameter was missing or out-of-range.
 PASS crypto.subtle.importKey("spki", spkiKey, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["sign"]) rejected promise  with SyntaxError (DOM Exception 12): A required parameter was missing or out-of-range.
 PASS crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]) rejected promise  with SyntaxError (DOM Exception 12): A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with SyntaxError (DOM Exception 12): A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]) rejected promise  with SyntaxError (DOM Exception 12): A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]) rejected promise  with SyntaxError (DOM Exception 12): A required parameter was missing or out-of-range.
+PASS crypto.subtle.importKey("spki", malformedKey0, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey1, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey2, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey4, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("spki", malformedKey6, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey0, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey1, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey3, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey5, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
+PASS crypto.subtle.importKey("pkcs8", malformedKey7, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]) rejected promise  with DataError (DOM Exception 30): Data provided to an operation does not meet requirements.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 45a4060..39cb3e8 100644 (file)
@@ -22,6 +22,15 @@ var dp = "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgi
 var dq = "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE";
 var qi = "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk";
 var spkiKey = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382010f003082010a0282010100d61051c4920d4c7c04a33beabb2412bedc4173fdbe82c7db80f0052d00abd32e01656d2105abef4fa5417bb868bb77780c08d20cfe9e2d767ee952970941398f8bea59a966772b1d89f19693cfff5faba22ba39ef7982ac46257180d557d3cbf3f7e65dd835d1d351e679a841b904a3cf24a0323aac0bb89705777507c76f57663b6d846e995a63057ceb48053ddf9282a366d6dc6cbdceb2ebcb3b374c7dc49da160cba8a3656211b8597a39ef9b8cc44d0c5735f870679ffcb1cb9321bbfbc307844d3174ef5dc144a951071340f4d156bead21fd3d9bd4641afa5851512264b4eed228b5d6324de428b00cbb89a1a88cb138d59de0b4ad75f2196e0e7ba890203010001");
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var malformedKey0 = new Uint8Array(); // empty.
+var malformedKey1 = hexStringToUint8Array("30"); // only 1 byte.
+var malformedKey2 = hexStringToUint8Array("30820122300d06092a864886f70d010101050003"); // truncated Spki key
+var malformedKey3 = hexStringToUint8Array("308204bd020100300d06092a864886f70d010101050004"); // truncated Pkcs8 key
+var malformedKey4 = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382"); // truncated Spki key
+var malformedKey5 = hexStringToUint8Array("308204bd020100300d06092a864886f70d01010105000482"); // truncated Pkcs8 key
+var malformedKey6 = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382010f"); // truncated Spki key
+var malformedKey7 = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7"); // truncated Pkcs8 key
 
 // Jwk: Wrong usages
 shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
@@ -69,6 +78,21 @@ shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p
 shouldReject('crypto.subtle.importKey("spki", spkiKey, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
 shouldReject('crypto.subtle.importKey("spki", spkiKey, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["sign"])');
 shouldReject('crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"])');
+// Pkcs8: Wrong usages
+shouldReject('crypto.subtle.importKey("pkcs8", pkcs8Key, "RSAES-PKCS1-v1_5", extractable, ["encrypt"])');
+shouldReject('crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"])');
+shouldReject('crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"])');
+// Malformed Key for Spki and Pkcs8
+shouldReject('crypto.subtle.importKey("spki", malformedKey0, "RSAES-PKCS1-v1_5", extractable, ["encrypt"])');
+shouldReject('crypto.subtle.importKey("spki", malformedKey1, "RSAES-PKCS1-v1_5", extractable, ["encrypt"])');
+shouldReject('crypto.subtle.importKey("spki", malformedKey2, "RSAES-PKCS1-v1_5", extractable, ["encrypt"])');
+shouldReject('crypto.subtle.importKey("spki", malformedKey4, "RSAES-PKCS1-v1_5", extractable, ["encrypt"])');
+shouldReject('crypto.subtle.importKey("spki", malformedKey6, "RSAES-PKCS1-v1_5", extractable, ["encrypt"])');
+shouldReject('crypto.subtle.importKey("pkcs8", malformedKey0, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
+shouldReject('crypto.subtle.importKey("pkcs8", malformedKey1, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
+shouldReject('crypto.subtle.importKey("pkcs8", malformedKey3, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
+shouldReject('crypto.subtle.importKey("pkcs8", malformedKey5, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
+shouldReject('crypto.subtle.importKey("pkcs8", malformedKey7, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
 </script>
 
 <script src="../../resources/js-test-post.js"></script>
diff --git a/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-jwk-key-expected.txt b/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-jwk-key-expected.txt
new file mode 100644 (file)
index 0000000..49f562e
--- /dev/null
@@ -0,0 +1,23 @@
+Test importing a PKCS8 RSA-OAEP public key and then export it in JWK format
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+Exporting a key...
+PASS exportedJwkKey.kty is jwkKey.kty
+PASS exportedJwkKey.alg is jwkKey.alg
+PASS exportedJwkKey.key_ops is jwkKey.key_ops
+PASS exportedJwkKey.ext is jwkKey.ext
+PASS exportedJwkKey.n is jwkKey.n
+PASS exportedJwkKey.e is jwkKey.e
+PASS exportedJwkKey.d is jwkKey.d
+PASS exportedJwkKey.p is jwkKey.p
+PASS exportedJwkKey.q is jwkKey.q
+PASS exportedJwkKey.dp is jwkKey.dp
+PASS exportedJwkKey.dq is jwkKey.dq
+PASS exportedJwkKey.qi is jwkKey.qi
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html b/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html
new file mode 100644 (file)
index 0000000..d709e8a
--- /dev/null
@@ -0,0 +1,60 @@
+<!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 importing a PKCS8 RSA-OAEP public key and then export it in JWK format");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RSA-OAEP",
+    key_ops: ["decrypt", "unwrapKey"],
+    ext: true,
+    n: "ym7o7GK2oC4Ye3DBnKFaE8OGpHDuiBbHNAonD5b5BVEfkzYvj3quPmA5Taw0yynqX1QNbvgLHfcVW2ai1tbkQJK8uvv2mwYbP02ScGDIHQ-gfSL0gf9QPAWB_6RE9XNFIE3fCpOiJZecYa65aGVX92MgAuFlQwRSho0BDVBePM_tcxVDKimKm20abt6Y7nRsLIvSL1SVzuVj4tsk8eM9kc7YOvG6rHVNuk3bpDD2zz1Kx-2wv2mJEUCFTocABWp-9tBu1aYFoF507LOyRs6csxCzmwDHB686Y3hi49KRQBPeIS_wmjbbhNmbjWENDP02pEEdvxti4G6_8b7lDwQMpQ",
+    e: "AQAB",
+    d: "JHBkgzCduSWzCH1ajKxKv6YBlZYyidK31vlA4MCHYNqieWhWlVg7B0Vg60dlVXDdHH3P0TrbHXC9qm9GPq_99FW1nV7_nBY0T2fSRWJWg0yt0fi51LC1q6g-J1tVgm1WcyMxVAERPf0VjEvcWhtsAz8Xow0Zoj-j705wcwoVfJKLHHhAo0QB0Z2qtSz6m0JMyOEIQlTKWXMEviJUe3Ih6HW_H9yiOGuh6FXV4LyroDN2v9c96FE8B6sOZ8s1VNyMj3pn0jH5mitlOtRx7i-L07j61RsC-AfRMba3GrF-RaX68WHOO5GdlrXnjp5OEgLWOYqVTe9MGYDaH8ww1WFn4Q",
+    p: "7iS5JmjThGX92aImLmS-VoRr5WHkz7ztyCSWoxkLVJY2kj1hw-Wi1AzG0sRqPomsI-tErEDHdxR-PkmoC9OCuuBuKE8cxVP4nXjwx78g_Toz7lmM4sr2Hj9UV80ij_A_4AnxCVIga_JI4WHReVDGZVr3Wwl7vaG5CQONTXUs0R0",
+    q: "2Zy2UZWjmfmjrKHvFZNZKZLn2RzAKLcT7FtmG5l2_P_bCG9SPwQmmcuRAyH-e2eifdSnKCLm-7mNAFKAch78MtiJ1DHSc3ySpPNNSIXHqcYkTggaEmSig9B3RLdSpo67b7_zSSoDnj46DMW5RTdYKn0RzGuGeOTDOGcflr4Cmyk",
+    dp: "oaKnUJyhxCF9tPPLun2CezKSETTqmt1-_vNmkvjyqczy6TtkWhRI-mhZosDR4_SJtC-BgvDM8dQlA532w2AiQTkHS7C2tHCUND3cH5doirewe7yoVV6wwkL1ukpvhQbqM-RLh6oIe3wNX3yHMzJSFoUxksbTCBj2gFm61LINYzk",
+    dq: "NLO_dALJnIDZIvYU8SS-c1Mg03QjFblBGf0IvaZtKtjMMz7CrIBU2Op0NE4HU9vFfrQBx7asOkq1214fvYPDkIzg1IM8dLu2yDwke2vq7zMNl9heeBXnRgU23W2Ils36lxXl1dJXDfwEExPPyvOcZq3joZ5o8t50aTSQcfGSsAE",
+    qi: "YKgnH0UWHY7PYsOsXw-oU5tthqNRI6r8w3VB4tXlticVd32w73XzzfZ1Brj8rWuu2GLq-I-h8oD0Jza2mkHqej_qMc5iqgVjyF3x2bArg4OcSrlFPkIMXEAczpefb7e2rBK68ekUBUbu0k6S44O48tN7PkQQhE0jXHF1ES51HuA",
+};
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]).then(function(cryptoKey) {
+    debug("Exporting a key...");
+    return crypto.subtle.exportKey("jwk", cryptoKey);
+}).then(function(result) {
+    exportedJwkKey = result;
+
+    shouldBe("exportedJwkKey.kty", "jwkKey.kty");
+    shouldBe("exportedJwkKey.alg", "jwkKey.alg");
+    shouldBe("exportedJwkKey.key_ops", "jwkKey.key_ops");
+    shouldBe("exportedJwkKey.ext", "jwkKey.ext");
+    shouldBe("exportedJwkKey.n", "jwkKey.n");
+    shouldBe("exportedJwkKey.e", "jwkKey.e");
+    shouldBe("exportedJwkKey.d", "jwkKey.d");
+    shouldBe("exportedJwkKey.p", "jwkKey.p");
+    shouldBe("exportedJwkKey.q", "jwkKey.q");
+    shouldBe("exportedJwkKey.dp", "jwkKey.dp");
+    shouldBe("exportedJwkKey.dq", "jwkKey.dq");
+    shouldBe("exportedJwkKey.qi", "jwkKey.qi");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..1c91c2a
--- /dev/null
@@ -0,0 +1,11 @@
+Test importing a PKCS8 RSA-OAEP key and then export it in PKCS8 format
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS bytesToHexString(privateKey) is pkcs8KeyHex
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html b/LayoutTests/crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html
new file mode 100644 (file)
index 0000000..afbdaf0
--- /dev/null
@@ -0,0 +1,35 @@
+<!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 importing a PKCS8 RSA-OAEP key and then export it in PKCS8 format");
+
+jsTestIsAsync = true;
+
+var pkcs8KeyHex = "308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0";
+var pkcs8Key = hexStringToUint8Array(pkcs8KeyHex);
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]).then(function(privateKey) {
+    return crypto.subtle.exportKey("pkcs8", privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBe("bytesToHexString(privateKey)", "pkcs8KeyHex");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-pkcs8-expected.txt b/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-pkcs8-expected.txt
new file mode 100644 (file)
index 0000000..928fe72
--- /dev/null
@@ -0,0 +1,12 @@
+Test exporting a RSA-OAEP private key with PKCS8 format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the private key...
+PASS privateKey is an instance of ArrayBuffer
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html b/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html
new file mode 100644 (file)
index 0000000..d235806
--- /dev/null
@@ -0,0 +1,42 @@
+<!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 exporting a RSA-OAEP private key with PKCS8 format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "RSA-OAEP",
+    // RsaKeyGenParams
+    modulusLength: 2048,
+    publicExponent: new Uint8Array([0x01, 0x00, 0x01]),  // Equivalent to 65537
+    hash: "sha-1",
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["decrypt", "encrypt", "wrapKey", "unwrapKey"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the private key...");
+    return crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBeType("privateKey", "ArrayBuffer");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsa-oaep-import-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/rsa-oaep-import-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..7e6b50c
--- /dev/null
@@ -0,0 +1,18 @@
+Test importing a PKCS8 RSA-OAEP key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS privateKey.toString() is '[object CryptoKey]'
+PASS privateKey.type is 'private'
+PASS privateKey.extractable is true
+PASS privateKey.algorithm.name is 'RSA-OAEP'
+PASS privateKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(privateKey.algorithm.publicExponent) is '010001'
+PASS privateKey.algorithm.hash.name is 'SHA-1'
+PASS privateKey.usages is ['decrypt', 'unwrapKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsa-oaep-import-pkcs8-key.html b/LayoutTests/crypto/subtle/rsa-oaep-import-pkcs8-key.html
new file mode 100644 (file)
index 0000000..48528ac
--- /dev/null
@@ -0,0 +1,39 @@
+<!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 importing a PKCS8 RSA-OAEP key");
+
+jsTestIsAsync = true;
+
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.toString()", "'[object CryptoKey]'");
+    shouldBe("privateKey.type", "'private'");
+    shouldBe("privateKey.extractable", "true");
+    shouldBe("privateKey.algorithm.name", "'RSA-OAEP'");
+    shouldBe("privateKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(privateKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("privateKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("privateKey.usages", "['decrypt', 'unwrapKey']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt b/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt
new file mode 100644 (file)
index 0000000..69f32f9
--- /dev/null
@@ -0,0 +1,12 @@
+Test exporting a RSAES-PKCS1-v1_5 private key with PKCS8 format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the private key...
+PASS privateKey is an instance of ArrayBuffer
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html b/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html
new file mode 100644 (file)
index 0000000..477da38
--- /dev/null
@@ -0,0 +1,41 @@
+<!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 exporting a RSAES-PKCS1-v1_5 private key with PKCS8 format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "RSAES-PKCS1-v1_5",
+    // RsaKeyGenParams
+    modulusLength: 2048,
+    publicExponent: new Uint8Array([0x01, 0x00, 0x01]),  // Equivalent to 65537
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["decrypt", "encrypt"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the private key...");
+    return crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBeType("privateKey", "ArrayBuffer");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..64cc22b
--- /dev/null
@@ -0,0 +1,18 @@
+Test importing a PKCS8 RSAES-PKCS1-v1_5 key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS privateKey.toString() is '[object CryptoKey]'
+PASS privateKey.type is 'private'
+PASS privateKey.extractable is true
+PASS privateKey.algorithm.name is 'RSAES-PKCS1-v1_5'
+PASS privateKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(privateKey.algorithm.publicExponent) is '010001'
+PASS privateKey.algorithm.hash is undefined.
+PASS privateKey.usages is ['decrypt']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html b/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html
new file mode 100644 (file)
index 0000000..10b33ce
--- /dev/null
@@ -0,0 +1,39 @@
+<!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 importing a PKCS8 RSAES-PKCS1-v1_5 key");
+
+jsTestIsAsync = true;
+
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, "RSAES-PKCS1-v1_5", extractable, ["decrypt"]).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.toString()", "'[object CryptoKey]'");
+    shouldBe("privateKey.type", "'private'");
+    shouldBe("privateKey.extractable", "true");
+    shouldBe("privateKey.algorithm.name", "'RSAES-PKCS1-v1_5'");
+    shouldBe("privateKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(privateKey.algorithm.publicExponent)", "'010001'");
+    shouldBeUndefined("privateKey.algorithm.hash");
+    shouldBe("privateKey.usages", "['decrypt']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8-expected.txt
new file mode 100644 (file)
index 0000000..94a24a6
--- /dev/null
@@ -0,0 +1,12 @@
+Test exporting a RSASSA-PKCS1-v1_5 private key with PKCS8 format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the private key...
+PASS privateKey is an instance of ArrayBuffer
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html
new file mode 100644 (file)
index 0000000..0a34101
--- /dev/null
@@ -0,0 +1,42 @@
+<!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 exporting a RSASSA-PKCS1-v1_5 private key with PKCS8 format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "RSASSA-PKCS1-v1_5",
+    // RsaKeyGenParams
+    modulusLength: 2048,
+    publicExponent: new Uint8Array([0x01, 0x00, 0x01]),  // Equivalent to 65537
+    hash: "sha-1",
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["sign", "verify"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the private key...");
+    return crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBeType("privateKey", "ArrayBuffer");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..1fb00b4
--- /dev/null
@@ -0,0 +1,18 @@
+Test importing a PKCS8 RSASSA-PKCS1-v1_5 key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS privateKey.toString() is '[object CryptoKey]'
+PASS privateKey.type is 'private'
+PASS privateKey.extractable is true
+PASS privateKey.algorithm.name is 'RSASSA-PKCS1-v1_5'
+PASS privateKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(privateKey.algorithm.publicExponent) is '010001'
+PASS privateKey.algorithm.hash.name is 'SHA-1'
+PASS privateKey.usages is ['sign']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html b/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html
new file mode 100644 (file)
index 0000000..baaf2fa
--- /dev/null
@@ -0,0 +1,39 @@
+<!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 importing a PKCS8 RSASSA-PKCS1-v1_5 key");
+
+jsTestIsAsync = true;
+
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["sign"]).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.toString()", "'[object CryptoKey]'");
+    shouldBe("privateKey.type", "'private'");
+    shouldBe("privateKey.extractable", "true");
+    shouldBe("privateKey.algorithm.name", "'RSASSA-PKCS1-v1_5'");
+    shouldBe("privateKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(privateKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("privateKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("privateKey.usages", "['sign']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/resources/rsa-export-pkcs8-key.js b/LayoutTests/crypto/workers/subtle/resources/rsa-export-pkcs8-key.js
new file mode 100644 (file)
index 0000000..efd6dbe
--- /dev/null
@@ -0,0 +1,29 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts("../../../resources/common.js");
+
+description("Test exporting a RSA-OAEP private key with PKCS8 format in workers.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "RSA-OAEP",
+    // RsaKeyGenParams
+    modulusLength: 2048,
+    publicExponent: new Uint8Array([0x01, 0x00, 0x01]),  // Equivalent to 65537
+    hash: "sha-1",
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["decrypt", "encrypt", "wrapKey", "unwrapKey"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the private key...");
+    return crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBeType("privateKey", "ArrayBuffer");
+
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/resources/rsa-import-pkcs8-key.js b/LayoutTests/crypto/workers/subtle/resources/rsa-import-pkcs8-key.js
new file mode 100644 (file)
index 0000000..00d89e0
--- /dev/null
@@ -0,0 +1,25 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts("../../../resources/common.js");
+
+description("Test importing a PKCS8 RSA-OAEP key in workers");
+
+jsTestIsAsync = true;
+
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"]).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.toString()", "'[object CryptoKey]'");
+    shouldBe("privateKey.type", "'private'");
+    shouldBe("privateKey.extractable", "true");
+    shouldBe("privateKey.algorithm.name", "'RSA-OAEP'");
+    shouldBe("privateKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(privateKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("privateKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("privateKey.usages", "['decrypt', 'unwrapKey']");
+
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/rsa-export-pkcs8-key-expected.txt b/LayoutTests/crypto/workers/subtle/rsa-export-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..c8b027e
--- /dev/null
@@ -0,0 +1,13 @@
+[Worker] Test exporting a RSA-OAEP private key with PKCS8 format in workers.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsa-export-pkcs8-key.js
+[Worker] Generating a key pair...
+[Worker] Exporting the private key...
+PASS [Worker] privateKey is an instance of ArrayBuffer
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/rsa-export-pkcs8-key.html b/LayoutTests/crypto/workers/subtle/rsa-export-pkcs8-key.html
new file mode 100644 (file)
index 0000000..50b4379
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/rsa-export-pkcs8-key.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/rsa-import-pkcs8-key-expected.txt b/LayoutTests/crypto/workers/subtle/rsa-import-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..a4d2e1a
--- /dev/null
@@ -0,0 +1,19 @@
+[Worker] Test importing a PKCS8 RSA-OAEP key in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsa-import-pkcs8-key.js
+[Worker] Importing a key...
+PASS [Worker] privateKey.toString() is '[object CryptoKey]'
+PASS [Worker] privateKey.type is 'private'
+PASS [Worker] privateKey.extractable is true
+PASS [Worker] privateKey.algorithm.name is 'RSA-OAEP'
+PASS [Worker] privateKey.algorithm.modulusLength is 2048
+PASS [Worker] bytesToHexString(privateKey.algorithm.publicExponent) is '010001'
+PASS [Worker] privateKey.algorithm.hash.name is 'SHA-1'
+PASS [Worker] privateKey.usages is ['decrypt', 'unwrapKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/rsa-import-pkcs8-key.html b/LayoutTests/crypto/workers/subtle/rsa-import-pkcs8-key.html
new file mode 100644 (file)
index 0000000..86e7ff0
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/rsa-import-pkcs8-key.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index aa219f8..9e99399 100644 (file)
@@ -1,3 +1,13 @@
+2016-12-06  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [Part 2 of 2] Add support for PKCS8 format while doing SubtleCrypto.importKey/exportKey
+        https://bugs.webkit.org/show_bug.cgi?id=129978
+        <rdar://problem/21799829>
+
+        Reviewed by Brent Fulgham.
+
+        * WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt:
+
 2016-12-08  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebCrypto] Remove NoInterfaceObject attribute from SubtleCrypto Interface
index 35a8995..b5f6c8a 100644 (file)
 encrypt Tests for RSA-OAEP
 
 
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label decryption assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label decryption with altered ciphertext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label using publicKey to decrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label no decrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label with altered plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label too long plaintext assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label using privateKey to encrypt assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''The operation is not supported.'' Reached unreachable code
+PASS RSA-OAEP with SHA-1 and no label decryption 
+PASS RSA-OAEP with SHA-256 and no label decryption 
+PASS RSA-OAEP with SHA-384 and no label decryption 
+PASS RSA-OAEP with SHA-512 and no label decryption 
+PASS RSA-OAEP with SHA-1 and empty label decryption 
+PASS RSA-OAEP with SHA-256 and empty label decryption 
+PASS RSA-OAEP with SHA-384 and empty label decryption 
+PASS RSA-OAEP with SHA-512 and empty label decryption 
+PASS RSA-OAEP with SHA-1 and a label decryption 
+PASS RSA-OAEP with SHA-256 and a label decryption 
+PASS RSA-OAEP with SHA-384 and a label decryption 
+PASS RSA-OAEP with SHA-512 and a label decryption 
+PASS RSA-OAEP with SHA-1 and no label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-256 and no label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-384 and no label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-512 and no label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-1 and empty label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-256 and empty label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-384 and empty label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-512 and empty label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-1 and a label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-256 and a label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-384 and a label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-512 and a label decryption with altered ciphertext 
+PASS RSA-OAEP with SHA-1 and no label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-256 and no label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-384 and no label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-512 and no label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-1 and empty label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-256 and empty label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-384 and empty label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-512 and empty label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-1 and a label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-256 and a label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-384 and a label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-512 and a label using publicKey to decrypt 
+PASS RSA-OAEP with SHA-1 and no label no decrypt usage 
+PASS RSA-OAEP with SHA-256 and no label no decrypt usage 
+PASS RSA-OAEP with SHA-384 and no label no decrypt usage 
+PASS RSA-OAEP with SHA-512 and no label no decrypt usage 
+PASS RSA-OAEP with SHA-1 and empty label no decrypt usage 
+PASS RSA-OAEP with SHA-256 and empty label no decrypt usage 
+PASS RSA-OAEP with SHA-384 and empty label no decrypt usage 
+PASS RSA-OAEP with SHA-512 and empty label no decrypt usage 
+PASS RSA-OAEP with SHA-1 and a label no decrypt usage 
+PASS RSA-OAEP with SHA-256 and a label no decrypt usage 
+PASS RSA-OAEP with SHA-384 and a label no decrypt usage 
+PASS RSA-OAEP with SHA-512 and a label no decrypt usage 
+PASS RSA-OAEP with SHA-1 and no label with altered plaintext 
+PASS RSA-OAEP with SHA-256 and no label with altered plaintext 
+PASS RSA-OAEP with SHA-384 and no label with altered plaintext 
+PASS RSA-OAEP with SHA-512 and no label with altered plaintext 
+PASS RSA-OAEP with SHA-1 and empty label with altered plaintext 
+PASS RSA-OAEP with SHA-256 and empty label with altered plaintext 
+PASS RSA-OAEP with SHA-384 and empty label with altered plaintext 
+PASS RSA-OAEP with SHA-512 and empty label with altered plaintext 
+PASS RSA-OAEP with SHA-1 and a label with altered plaintext 
+PASS RSA-OAEP with SHA-256 and a label with altered plaintext 
+PASS RSA-OAEP with SHA-384 and a label with altered plaintext 
+PASS RSA-OAEP with SHA-512 and a label with altered plaintext 
+PASS RSA-OAEP with SHA-1 and no label 
+PASS RSA-OAEP with SHA-256 and no label 
+PASS RSA-OAEP with SHA-384 and no label 
+PASS RSA-OAEP with SHA-512 and no label 
+PASS RSA-OAEP with SHA-1 and empty label 
+PASS RSA-OAEP with SHA-256 and empty label 
+PASS RSA-OAEP with SHA-384 and empty label 
+PASS RSA-OAEP with SHA-512 and empty label 
+PASS RSA-OAEP with SHA-1 and a label 
+PASS RSA-OAEP with SHA-256 and a label 
+PASS RSA-OAEP with SHA-384 and a label 
+PASS RSA-OAEP with SHA-512 and a label 
+PASS RSA-OAEP with SHA-1 and no label too long plaintext 
+PASS RSA-OAEP with SHA-256 and no label too long plaintext 
+PASS RSA-OAEP with SHA-384 and no label too long plaintext 
+PASS RSA-OAEP with SHA-512 and no label too long plaintext 
+PASS RSA-OAEP with SHA-1 and empty label too long plaintext 
+PASS RSA-OAEP with SHA-256 and empty label too long plaintext 
+PASS RSA-OAEP with SHA-384 and empty label too long plaintext 
+PASS RSA-OAEP with SHA-512 and empty label too long plaintext 
+PASS RSA-OAEP with SHA-1 and a label too long plaintext 
+PASS RSA-OAEP with SHA-256 and a label too long plaintext 
+PASS RSA-OAEP with SHA-384 and a label too long plaintext 
+PASS RSA-OAEP with SHA-512 and a label too long plaintext 
+PASS RSA-OAEP with SHA-1 and no label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-256 and no label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-384 and no label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-512 and no label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-1 and empty label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-256 and empty label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-384 and empty label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-512 and empty label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-1 and a label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-256 and a label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-384 and a label using privateKey to encrypt 
+PASS RSA-OAEP with SHA-512 and a label using privateKey to encrypt 
 FAIL importVectorKeys step: RSA-OAEP with SHA-1 and no label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and no label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
 FAIL importVectorKeys step: RSA-OAEP with SHA-256 and no label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and no label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
 FAIL importVectorKeys step: RSA-OAEP with SHA-384 and no label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and no label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
index 9965165..2d489af 100644 (file)
@@ -1,3 +1,47 @@
+2016-12-06  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [Part 2 of 2] Add support for PKCS8 format while doing SubtleCrypto.importKey/exportKey
+        https://bugs.webkit.org/show_bug.cgi?id=129978
+        <rdar://problem/21799829>
+
+        Reviewed by Brent Fulgham.
+
+        This is part 2 of Bug 129978. In this patch, it adds the PKCS8 format support for
+        SubtleCrypto.importKey/exportKey. Currently support algorithms are RSAES-PKCS1-v1_5,
+        RSASSA-PKCS1-v1_5 and RSA-OAEP.
+
+        Tests: crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html
+               crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html
+               crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html
+               crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html
+               crypto/subtle/rsa-oaep-import-pkcs8-key.html
+               crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html
+               crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html
+               crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html
+               crypto/workers/subtle/rsa-export-pkcs8-key.html
+               crypto/workers/subtle/rsa-import-pkcs8-key.html
+
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::toKeyData):
+        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::exportKey):
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::exportKey):
+        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+        (WebCore::CryptoAlgorithmRSA_OAEP::importKey):
+        (WebCore::CryptoAlgorithmRSA_OAEP::exportKey):
+        * crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
+        (WebCore::CryptoKeyRSA::importPkcs8):
+        (WebCore::CryptoKeyRSA::exportPkcs8):
+        * crypto/keys/CryptoKeyRSA.h:
+        * crypto/mac/CryptoKeyRSAMac.cpp:
+        (WebCore::CryptoKeyRSA::importSpki):
+        (WebCore::CryptoKeyRSA::importPkcs8):
+        (WebCore::CryptoKeyRSA::exportPkcs8):
+
 2016-12-09  Geoffrey Garen  <ggaren@apple.com>
 
         Deploy OrdinalNumber in JSC::SourceCode
index fdc1f45..dca660a 100644 (file)
@@ -341,10 +341,8 @@ static KeyData toKeyData(ExecState& state, SubtleCrypto::KeyFormat format, JSVal
 
     KeyData result;
     switch (format) {
-    case SubtleCrypto::KeyFormat::Pkcs8:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
-        return result;
     case SubtleCrypto::KeyFormat::Spki:
+    case SubtleCrypto::KeyFormat::Pkcs8:
     case SubtleCrypto::KeyFormat::Raw: {
         BufferSource bufferSource = convert<IDLBufferSource>(state, value);
         RETURN_IF_EXCEPTION(scope, result);
index a474f75..ea8eca1 100644 (file)
@@ -128,6 +128,14 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::importKey(SubtleCrypto::KeyFormat format,
         result = CryptoKeyRSA::importSpki(parameters->identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
+    case SubtleCrypto::KeyFormat::Pkcs8: {
+        if (usages ^ CryptoKeyUsageDecrypt) {
+            exceptionCallback(SYNTAX_ERR);
+            return;
+        }
+        result = CryptoKeyRSA::importPkcs8(parameters->identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
@@ -166,6 +174,15 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::exportKey(SubtleCrypto::KeyFormat format,
         result = spki.releaseReturnValue();
         break;
     }
+    case SubtleCrypto::KeyFormat::Pkcs8: {
+        auto pkcs8 = rsaKey.exportPkcs8();
+        if (pkcs8.hasException()) {
+            exceptionCallback(pkcs8.releaseException().code());
+            return;
+        }
+        result = pkcs8.releaseReturnValue();
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
index cb973bd..9ff13fc 100644 (file)
@@ -162,6 +162,15 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(SubtleCrypto::KeyFormat format,
         result = CryptoKeyRSA::importSpki(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
+    case SubtleCrypto::KeyFormat::Pkcs8: {
+        if (usages ^ CryptoKeyUsageSign) {
+            exceptionCallback(SYNTAX_ERR);
+            return;
+        }
+        // FIXME: <webkit.org/b/165436>
+        result = CryptoKeyRSA::importPkcs8(parameters->identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
@@ -218,6 +227,15 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::exportKey(SubtleCrypto::KeyFormat format,
         result = spki.releaseReturnValue();
         break;
     }
+    case SubtleCrypto::KeyFormat::Pkcs8: {
+        auto pkcs8 = rsaKey.exportPkcs8();
+        if (pkcs8.hasException()) {
+            exceptionCallback(pkcs8.releaseException().code());
+            return;
+        }
+        result = pkcs8.releaseReturnValue();
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
index 9f35937..5734dde 100644 (file)
@@ -175,6 +175,15 @@ void CryptoAlgorithmRSA_OAEP::importKey(SubtleCrypto::KeyFormat format, KeyData&
         result = CryptoKeyRSA::importSpki(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
         break;
     }
+    case SubtleCrypto::KeyFormat::Pkcs8: {
+        if ((usages ^ CryptoKeyUsageDecrypt) && (usages ^ CryptoKeyUsageUnwrapKey) && (usages ^ (CryptoKeyUsageDecrypt | CryptoKeyUsageUnwrapKey))) {
+            exceptionCallback(SYNTAX_ERR);
+            return;
+        }
+        // FIXME: <webkit.org/b/165436>
+        result = CryptoKeyRSA::importPkcs8(parameters->identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
@@ -232,6 +241,16 @@ void CryptoAlgorithmRSA_OAEP::exportKey(SubtleCrypto::KeyFormat format, Ref<Cryp
         result = spki.releaseReturnValue();
         break;
     }
+    case SubtleCrypto::KeyFormat::Pkcs8: {
+        // FIXME: <webkit.org/b/165437>
+        auto pkcs8 = rsaKey.exportPkcs8();
+        if (pkcs8.hasException()) {
+            exceptionCallback(pkcs8.releaseException().code());
+            return;
+        }
+        result = pkcs8.releaseReturnValue();
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
index 327491f..0c77374 100644 (file)
@@ -126,6 +126,20 @@ ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportSpki() const
     return Exception { NOT_SUPPORTED_ERR };
 }
 
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::importPkcs8(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier>, Vector<uint8_t>&&, bool, CryptoKeyUsageBitmap)
+{
+    notImplemented();
+
+    return nullptr;
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportPkcs8() const
+{
+    notImplemented();
+
+    return Exception { NOT_SUPPORTED_ERR };
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)
index 1ed72a4..335bd44 100644 (file)
@@ -103,10 +103,12 @@ public:
     static void generatePair(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsageBitmap, KeyPairCallback&&, VoidCallback&& failureCallback, ScriptExecutionContext*);
     static RefPtr<CryptoKeyRSA> importJwk(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier> hash, JsonWebKey&&, bool extractable, CryptoKeyUsageBitmap);
     static RefPtr<CryptoKeyRSA> importSpki(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&&, bool extractable, CryptoKeyUsageBitmap);
+    static RefPtr<CryptoKeyRSA> importPkcs8(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&&, bool extractable, CryptoKeyUsageBitmap);
 
     PlatformRSAKey platformKey() const { return m_platformKey; }
     JsonWebKey exportJwk() const;
     ExceptionOr<Vector<uint8_t>> exportSpki() const;
+    ExceptionOr<Vector<uint8_t>> exportPkcs8() const;
 
     CryptoAlgorithmIdentifier hashAlgorithmIdentifier() const { return m_hash; }
 
index 1461ea2..c135b47 100644 (file)
@@ -40,9 +40,14 @@ namespace WebCore {
 
 // OID rsaEncryption: 1.2.840.113549.1.1.1. Per https://tools.ietf.org/html/rfc3279#section-2.3.1
 static unsigned char RSAOIDHeader[] = {0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00};
+// Version 0. Per https://tools.ietf.org/html/rfc5208#section-5
+static unsigned char Version[] = {0x02, 0x01, 0x00};
+
 // Per X.690 08/2015: https://www.itu.int/rec/T-REC-X.680-X.693/en
-static unsigned char SequenceMark = 0x30;
 static unsigned char BitStringMark = 0x03;
+static unsigned char OctetStringMark = 0x04;
+static unsigned char SequenceMark = 0x30;
+
 static unsigned char InitialOctet = 0x00;
 
 // FIXME: We should get rid of magic number 16384. It assumes that the length of provided key will not exceed 16KB.
@@ -332,10 +337,10 @@ RefPtr<CryptoKeyRSA> CryptoKeyRSA::importSpki(CryptoAlgorithmIdentifier identifi
     // the most common one for now.
     // Per https://tools.ietf.org/html/rfc5280#section-4.1. subjectPublicKeyInfo.
     size_t headerSize = 1;
-    if (keyData.size() < headerSize)
+    if (keyData.size() < headerSize + 1)
         return nullptr;
     headerSize += bytesUsedToEncodedLength(keyData[headerSize]) + sizeof(RSAOIDHeader) + sizeof(BitStringMark);
-    if (keyData.size() < headerSize)
+    if (keyData.size() < headerSize + 1)
         return nullptr;
     headerSize += bytesUsedToEncodedLength(keyData[headerSize]) + sizeof(InitialOctet);
 
@@ -378,6 +383,64 @@ ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportSpki() const
     return WTFMove(result);
 }
 
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::importPkcs8(CryptoAlgorithmIdentifier identifier, std::optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&& keyData, bool extractable, CryptoKeyUsageBitmap usages)
+{
+    // The current SecLibrary cannot import a PKCS8 format binary. Hence, we need to strip out the PKCS8 header.
+    // This hack can be removed when <rdar://problem/29523286> is resolved.
+    // The header format we assume is: SequenceMark(1) + Length(?) + Version(3) + rsaEncryption(15) + OctetStringMark(1) + Length(?).
+    // The header format could be varied. However since we don't have a full-fledged ASN.1 encoder/decoder, we want to restrict it to
+    // the most common one for now.
+    // Per https://tools.ietf.org/html/rfc5208#section-5. PrivateKeyInfo.
+    // We also assume there is no optional parameters.
+    size_t headerSize = 1;
+    if (keyData.size() < headerSize + 1)
+        return nullptr;
+    headerSize += bytesUsedToEncodedLength(keyData[headerSize]) + sizeof(Version) + sizeof(RSAOIDHeader) + sizeof(OctetStringMark);
+    if (keyData.size() < headerSize + 1)
+        return nullptr;
+    headerSize += bytesUsedToEncodedLength(keyData[headerSize]);
+
+    CCRSACryptorRef ccPrivateKey;
+    if (CCRSACryptorImport(keyData.data() + headerSize, keyData.size() - headerSize, &ccPrivateKey))
+        return nullptr;
+
+    // Notice: CryptoAlgorithmIdentifier::SHA_1 is just a placeholder. It should not have any effect if hash is std::nullopt.
+    return adoptRef(new CryptoKeyRSA(identifier, hash.value_or(CryptoAlgorithmIdentifier::SHA_1), !!hash, CryptoKeyType::Private, ccPrivateKey, extractable, usages));
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportPkcs8() const
+{
+    if (type() != CryptoKeyType::Private)
+        return Exception { INVALID_ACCESS_ERR };
+
+    // The current SecLibrary cannot output a valid PKCS8 format binary. Hence, we need the following hack.
+    // This hack can be removed when <rdar://problem/29523286> is resolved.
+    // Estimated size in produced bytes format. Per https://tools.ietf.org/html/rfc3447#appendix-A.1.2. RSAPrivateKey.
+    // O(size) = Sequence(1) + Length(3) + Integer(1) + Length(3) + Modulus + Integer(1) + Length(3) + publicExponent + Integer(1) + Length(3) +
+    // privateExponent + Integer(1) + Length(3) + prime1 + Integer(1) + Length(3) + prime2 + Integer(1) + Length(3) + exponent1 + Integer(1) +
+    // Length(3) + exponent2 + Integer(1) + Length(3) + coefficient.
+    Vector<uint8_t> keyBytes(keySizeInBits());
+    size_t keySize = keyBytes.size();
+    if (CCRSACryptorExport(platformKey(), keyBytes.data(), &keySize))
+        return Exception { OperationError };
+    keyBytes.shrink(keySize);
+
+    // Version + RSAOIDHeader + OctetStringMark + Length + keySize
+    size_t totalSize = sizeof(Version) + sizeof(RSAOIDHeader) + bytesNeededForEncodedLength(keySize) + keySize + 2;
+
+    // Per https://tools.ietf.org/html/rfc5208#section-5. PrivateKeyInfo.
+    Vector<uint8_t> result;
+    result.append(SequenceMark);
+    addEncodedASN1Length(result, totalSize);
+    result.append(Version, sizeof(Version));
+    result.append(RSAOIDHeader, sizeof(RSAOIDHeader));
+    result.append(OctetStringMark);
+    addEncodedASN1Length(result, keySize);
+    result.append(keyBytes.data(), keyBytes.size());
+
+    return WTFMove(result);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)