Title: [209437] trunk
Revision
209437
Author
[email protected]
Date
2016-12-06 17:15:20 -0800 (Tue, 06 Dec 2016)

Log Message

[Part 1 of 2] Add support for SPKI format while doing SubtleCrypto.importKey/exportKey
https://bugs.webkit.org/show_bug.cgi?id=129978
<rdar://problem/21799829>

LayoutTests/imported/w3c:

Reviewed by Brent Fulgham.

* WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt:

Source/WebCore:

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

Reviewed by Brent Fulgham.

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

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::toKeyData):
* crypto/CommonCryptoUtilities.h:
* 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::importSpki):
(WebCore::CryptoKeyRSA::exportSpki):
* crypto/keys/CryptoKeyRSA.h:
* crypto/mac/CryptoKeyRSAMac.cpp:
(WebCore::bytesUsedToEncodedLength):
(WebCore::bytesNeededForEncodedLength):
(WebCore::addEncodedASN1Length):
(WebCore::CryptoKeyRSA::importSpki):
(WebCore::CryptoKeyRSA::exportSpki):

LayoutTests:

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-spki-key-expected.txt: Added.
* crypto/subtle/rsa-import-jwk-key-export-spki-key.html: Added.
* crypto/subtle/rsa-import-key-malformed-parameters-expected.txt:
* crypto/subtle/rsa-import-key-malformed-parameters.html:
* crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt: Added.
* crypto/subtle/rsa-import-spki-key-export-jwk-key.html: Added.
* crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt: Added.
* crypto/subtle/rsa-import-spki-key-export-spki-key.html: Added.
* crypto/subtle/rsa-import-spki-small-key-expected.txt: Added.
* crypto/subtle/rsa-import-spki-small-key.html: Added.
* crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt: Added.
* crypto/subtle/rsa-oaep-generate-export-key-spki.html: Added.
* crypto/subtle/rsa-oaep-import-spki-key-expected.txt: Added.
* crypto/subtle/rsa-oaep-import-spki-key.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html: Added.
* crypto/workers/subtle/resources/rsa-export-spki-key.js: Added.
* crypto/workers/subtle/resources/rsa-import-spki-key.js: Added.
* crypto/workers/subtle/rsa-export-spki-key-expected.txt: Added.
* crypto/workers/subtle/rsa-export-spki-key.html: Added.
* crypto/workers/subtle/rsa-import-spki-key-expected.txt: Added.
* crypto/workers/subtle/rsa-import-spki-key.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (209436 => 209437)


--- trunk/LayoutTests/ChangeLog	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/ChangeLog	2016-12-07 01:15:20 UTC (rev 209437)
@@ -1,3 +1,44 @@
+2016-12-05  Jiewen Tan  <[email protected]>
+
+        [Part 1 of 2] Add support for SPKI 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-spki-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-jwk-key-export-spki-key.html: Added.
+        * crypto/subtle/rsa-import-key-malformed-parameters-expected.txt:
+        * crypto/subtle/rsa-import-key-malformed-parameters.html:
+        * crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-spki-key-export-jwk-key.html: Added.
+        * crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-spki-key-export-spki-key.html: Added.
+        * crypto/subtle/rsa-import-spki-small-key-expected.txt: Added.
+        * crypto/subtle/rsa-import-spki-small-key.html: Added.
+        * crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt: Added.
+        * crypto/subtle/rsa-oaep-generate-export-key-spki.html: Added.
+        * crypto/subtle/rsa-oaep-import-spki-key-expected.txt: Added.
+        * crypto/subtle/rsa-oaep-import-spki-key.html: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html: Added.
+        * crypto/workers/subtle/resources/rsa-export-spki-key.js: Added.
+        * crypto/workers/subtle/resources/rsa-import-spki-key.js: Added.
+        * crypto/workers/subtle/rsa-export-spki-key-expected.txt: Added.
+        * crypto/workers/subtle/rsa-export-spki-key.html: Added.
+        * crypto/workers/subtle/rsa-import-spki-key-expected.txt: Added.
+        * crypto/workers/subtle/rsa-import-spki-key.html: Added.
+
 2016-12-06  Antoine Quint  <[email protected]>
 
         [Modern Media Controls] Media controls use the fullscreen layout after going from inline to fullscreen to PiP to inline

Modified: trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters-expected.txt (209436 => 209437)


--- trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters-expected.txt	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -16,7 +16,6 @@
 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("spki", 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.

Modified: trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters.html (209436 => 209437)


--- trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters.html	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -50,7 +50,6 @@
 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"])');
-shouldReject('crypto.subtle.importKey("spki", 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"])');

Modified: trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters-expected.txt (209436 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters-expected.txt	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -3,9 +3,9 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS crypto.subtle.exportKey("spki", publicKey) rejected promise  with NotSupportedError (DOM Exception 9): The algorithm is not supported.
 PASS crypto.subtle.exportKey("pkcs8", publicKey) rejected promise  with NotSupportedError (DOM Exception 9): The algorithm is not supported.
 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
 
 TEST COMPLETE

Modified: trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html (209436 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -24,14 +24,16 @@
 
 crypto.subtle.generateKey(algorithmKeyGen, extractable, ["decrypt", "encrypt", "wrapKey", "unwrapKey"]).then(function(result) {
     publicKey = result.publicKey;
+    privateKey = result.privateKey;
 
     // Currently not support format.
-    return shouldReject('crypto.subtle.exportKey("spki", publicKey)');
-}).then(function() {
     return shouldReject('crypto.subtle.exportKey("pkcs8", publicKey)');
 }).then(function() {
     // Not support format.
     return shouldReject('crypto.subtle.exportKey("raw", publicKey)');
+}).then(function() {
+    // Wrong key and format.
+    return shouldReject('crypto.subtle.exportKey("spki", privateKey)');
 }).then(finishJSTest, finishJSTest);
 
 </script>

Added: trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,12 @@
+Test importing a JWK RSA-OAEP public key with SHA-1 and then export it in SPKI format
+
+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 successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</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 SPKI format");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RSA-OAEP",
+    key_ops: ["encrypt", "wrapKey"],
+    ext: true,
+    n: "p55Xl-DyqKL06TE8GCuXd_e-ruTqVB19iDH6DwTIknTyM0fl8EY6qsyOBNTxjpLDsOldEJ8QblG78WY7xYTZtNn-fimz5eG80bwSZ6FUO10z3ikeKzPPC7K4AA196rMoiEu2G4mSfqeg5zz6_iqHf8u_md_n8yk_iPaXJ9RVT-W4zEQQ6WSlsOtYa7blSSAlq0JYDJciNeE0RGqUU-UjcxUWIEnT2ODHGRzSfKHgc8O3fGt4dpVm0op1yItBcSAY-0_f1p_YrVDo8bsyq2uodyDGYhcuQgYJ0NjMgT_rb8rUPpR3bUitd-IZJd_NO9i_NmvbnQfgl6kfnxe_2kM4Tw",
+    e: "AQAB"
+};
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).then(function(cryptoKey) {
+    debug("Exporting a key...");
+    return crypto.subtle.exportKey("spki", cryptoKey);
+}).then(function(result) {
+    exportedSpkiKey = result;
+
+    shouldBe("exportedSpkiKey.byteLength", "294");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt (209436 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -36,6 +36,9 @@
 PASS crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dq: dq, qi: qi}, "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("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, qi: qi}, "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("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq}, "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("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 successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters.html (209436 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters.html	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -21,6 +21,7 @@
 var dp = "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk";
 var dq = "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE";
 var qi = "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk";
+var spkiKey = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382010f003082010a0282010100d61051c4920d4c7c04a33beabb2412bedc4173fdbe82c7db80f0052d00abd32e01656d2105abef4fa5417bb868bb77780c08d20cfe9e2d767ee952970941398f8bea59a966772b1d89f19693cfff5faba22ba39ef7982ac46257180d557d3cbf3f7e65dd835d1d351e679a841b904a3cf24a0323aac0bb89705777507c76f57663b6d846e995a63057ceb48053ddf9282a366d6dc6cbdceb2ebcb3b374c7dc49da160cba8a3656211b8597a39ef9b8cc44d0c5735f870679ffcb1cb9321bbfbc307844d3174ef5dc144a951071340f4d156bead21fd3d9bd4641afa5851512264b4eed228b5d6324de428b00cbb89a1a88cb138d59de0b4ad75f2196e0e7ba890203010001");
 
 // Jwk: Wrong usages
 shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
@@ -64,6 +65,10 @@
 shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dq: dq, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
 shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, qi: qi}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
 shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
+// Spki: Wrong usages
+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"])');
 </script>
 
 <script src=""

Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,17 @@
+Test importing a SPKI 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 successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a SPKI RSA-OAEP public key and then export it in JWK format");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RSA-OAEP",
+    key_ops: ["encrypt", "wrapKey"],
+    ext: true,
+    n: "1hBRxJINTHwEozvquyQSvtxBc_2-gsfbgPAFLQCr0y4BZW0hBavvT6VBe7hou3d4DAjSDP6eLXZ-6VKXCUE5j4vqWalmdysdifGWk8__X6uiK6Oe95gqxGJXGA1VfTy_P35l3YNdHTUeZ5qEG5BKPPJKAyOqwLuJcFd3UHx29XZjtthG6ZWmMFfOtIBT3fkoKjZtbcbL3OsuvLOzdMfcSdoWDLqKNlYhG4WXo575uMxE0MVzX4cGef_LHLkyG7-8MHhE0xdO9dwUSpUQcTQPTRVr6tIf09m9RkGvpYUVEiZLTu0ii11jJN5CiwDLuJoaiMsTjVneC0rXXyGW4Oe6iQ",
+    e: "AQAB"
+};
+var spkiKey = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382010f003082010a0282010100d61051c4920d4c7c04a33beabb2412bedc4173fdbe82c7db80f0052d00abd32e01656d2105abef4fa5417bb868bb77780c08d20cfe9e2d767ee952970941398f8bea59a966772b1d89f19693cfff5faba22ba39ef7982ac46257180d557d3cbf3f7e65dd835d1d351e679a841b904a3cf24a0323aac0bb89705777507c76f57663b6d846e995a63057ceb48053ddf9282a366d6dc6cbdceb2ebcb3b374c7dc49da160cba8a3656211b8597a39ef9b8cc44d0c5735f870679ffcb1cb9321bbfbc307844d3174ef5dc144a951071340f4d156bead21fd3d9bd4641afa5851512264b4eed228b5d6324de428b00cbb89a1a88cb138d59de0b4ad75f2196e0e7ba890203010001");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).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");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,11 @@
+Test importing a SPKI RSA-OAEP key and then export it in SPKI format
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS bytesToHexString(publicKey) is spkiKeyHex
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a SPKI RSA-OAEP key and then export it in SPKI format");
+
+jsTestIsAsync = true;
+
+var spkiKeyHex = "30820122300d06092a864886f70d01010105000382010f003082010a0282010100d61051c4920d4c7c04a33beabb2412bedc4173fdbe82c7db80f0052d00abd32e01656d2105abef4fa5417bb868bb77780c08d20cfe9e2d767ee952970941398f8bea59a966772b1d89f19693cfff5faba22ba39ef7982ac46257180d557d3cbf3f7e65dd835d1d351e679a841b904a3cf24a0323aac0bb89705777507c76f57663b6d846e995a63057ceb48053ddf9282a366d6dc6cbdceb2ebcb3b374c7dc49da160cba8a3656211b8597a39ef9b8cc44d0c5735f870679ffcb1cb9321bbfbc307844d3174ef5dc144a951071340f4d156bead21fd3d9bd4641afa5851512264b4eed228b5d6324de428b00cbb89a1a88cb138d59de0b4ad75f2196e0e7ba890203010001";
+var spkiKey = hexStringToUint8Array(spkiKeyHex);
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).then(function(publicKey) {
+    return crypto.subtle.exportKey("spki", publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("bytesToHexString(publicKey)", "spkiKeyHex");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSA 64 bit key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'RSA-OAEP'
+PASS publicKey.algorithm.modulusLength is 64
+PASS bytesToHexString(publicKey.algorithm.publicExponent) is '010001'
+PASS publicKey.algorithm.hash.name is 'SHA-1'
+PASS publicKey.usages is ['encrypt', 'wrapKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a SPKI RSA 64 bit key");
+
+jsTestIsAsync = true;
+
+// Generated from OpenSSL
+var spkiKey = Base64URL.parse("MCQwDQYJKoZIhvcNAQEBBQADEwAwEAIJAKNxac33yAq/AgMBAAE=");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'RSA-OAEP'");
+    shouldBe("publicKey.algorithm.modulusLength", "64");
+    shouldBe("bytesToHexString(publicKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("publicKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("publicKey.usages", "['encrypt', 'wrapKey']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,12 @@
+Test exporting a RSA-OAEP public key with SPKI format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS publicKey.byteLength is 294
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Copied: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki.html (from rev 209436, trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html) (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a RSA-OAEP public key with SPKI 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 public key...");
+    return crypto.subtle.exportKey("spki", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.byteLength", "294");
+
+    finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSA-OAEP key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'RSA-OAEP'
+PASS publicKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(publicKey.algorithm.publicExponent) is '010001'
+PASS publicKey.algorithm.hash.name is 'SHA-1'
+PASS publicKey.usages is ['encrypt', 'wrapKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a SPKI RSA-OAEP key");
+
+jsTestIsAsync = true;
+
+// Generated from OpenSSL
+var spkiKey = Base64URL.parse("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCjRCtFwvSNYMZ07u5SxARxglJl75T7bUZXFsDVxHkMhpNC2RaN4jWE5bwYUDMeD2fVmxhpaUQn/6AbFLh6gHxtwrCfc7rIo/SfDdGd3GkRlXK5xXwGuM6MvP9nuZHaarIyArRFh2U2UZxFlVsKI0pSHo6n58W1fPZ1syOoVEZ/WYE6gLhMMwfpeAm97mro7mekRdMULOV/mR5Ul3CHm9Zt93Dc8GpnPA8bhLiB0VNyGTEMa06nJul4gj1sjxLDoUvZY2EWq7oUUnfLBUYMfiqK0kQcW94wvBrIq2DQUApLyTTbaAOY46TLwX6c8LtubJriYKTC5a9Bb0/7ovTWB0wIDAQAB");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'RSA-OAEP'");
+    shouldBe("publicKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(publicKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("publicKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("publicKey.usages", "['encrypt', 'wrapKey']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,12 @@
+Test exporting a RSAES-PKCS1-v1_5 public key with SPKI format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS publicKey.byteLength is 294
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a RSAES-PKCS1-v1_5 public key with SPKI 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 public key...");
+    return crypto.subtle.exportKey("spki", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.byteLength", "294");
+
+    finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSAES-PKCS1-v1_5 key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'RSAES-PKCS1-v1_5'
+PASS publicKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(publicKey.algorithm.publicExponent) is '010001'
+PASS publicKey.algorithm.hash is undefined.
+PASS publicKey.usages is ['encrypt']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a SPKI RSAES-PKCS1-v1_5 key");
+
+jsTestIsAsync = true;
+
+// Generated from OpenSSL
+var spkiKey = Base64URL.parse("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCjRCtFwvSNYMZ07u5SxARxglJl75T7bUZXFsDVxHkMhpNC2RaN4jWE5bwYUDMeD2fVmxhpaUQn/6AbFLh6gHxtwrCfc7rIo/SfDdGd3GkRlXK5xXwGuM6MvP9nuZHaarIyArRFh2U2UZxFlVsKI0pSHo6n58W1fPZ1syOoVEZ/WYE6gLhMMwfpeAm97mro7mekRdMULOV/mR5Ul3CHm9Zt93Dc8GpnPA8bhLiB0VNyGTEMa06nJul4gj1sjxLDoUvZY2EWq7oUUnfLBUYMfiqK0kQcW94wvBrIq2DQUApLyTTbaAOY46TLwX6c8LtubJriYKTC5a9Bb0/7ovTWB0wIDAQAB");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, "RSAES-PKCS1-v1_5", extractable, ["encrypt"]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'RSAES-PKCS1-v1_5'");
+    shouldBe("publicKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(publicKey.algorithm.publicExponent)", "'010001'");
+    shouldBeUndefined("publicKey.algorithm.hash");
+    shouldBe("publicKey.usages", "['encrypt']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,12 @@
+Test exporting a RSASSA-PKCS1-v1_5 public key with SPKI format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS publicKey.byteLength is 294
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a RSASSA-PKCS1-v1_5 public key with SPKI 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 public key...");
+    return crypto.subtle.exportKey("spki", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.byteLength", "294");
+
+    finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSASSA-PKCS1-v1_5 key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'RSASSA-PKCS1-v1_5'
+PASS publicKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(publicKey.algorithm.publicExponent) is '010001'
+PASS publicKey.algorithm.hash.name is 'SHA-1'
+PASS publicKey.usages is ['verify']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a SPKI RSASSA-PKCS1-v1_5 key");
+
+jsTestIsAsync = true;
+
+// Generated from OpenSSL
+var spkiKey = Base64URL.parse("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCjRCtFwvSNYMZ07u5SxARxglJl75T7bUZXFsDVxHkMhpNC2RaN4jWE5bwYUDMeD2fVmxhpaUQn/6AbFLh6gHxtwrCfc7rIo/SfDdGd3GkRlXK5xXwGuM6MvP9nuZHaarIyArRFh2U2UZxFlVsKI0pSHo6n58W1fPZ1syOoVEZ/WYE6gLhMMwfpeAm97mro7mekRdMULOV/mR5Ul3CHm9Zt93Dc8GpnPA8bhLiB0VNyGTEMa06nJul4gj1sjxLDoUvZY2EWq7oUUnfLBUYMfiqK0kQcW94wvBrIq2DQUApLyTTbaAOY46TLwX6c8LtubJriYKTC5a9Bb0/7ovTWB0wIDAQAB");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "RSASSA-PKCS1-v1_5", hash: "sha-1"}, extractable, ["verify"]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'RSASSA-PKCS1-v1_5'");
+    shouldBe("publicKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(publicKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("publicKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("publicKey.usages", "['verify']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/workers/subtle/resources/rsa-export-spki-key.js (0 => 209437)


--- trunk/LayoutTests/crypto/workers/subtle/resources/rsa-export-spki-key.js	                        (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/resources/rsa-export-spki-key.js	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,29 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts("../../../resources/common.js");
+
+description("Test exporting a RSA-OAEP public key with SPKI 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 public key...");
+    return crypto.subtle.exportKey("spki", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.byteLength", "294");
+
+    finishJSTest();
+});
\ No newline at end of file

Added: trunk/LayoutTests/crypto/workers/subtle/resources/rsa-import-spki-key.js (0 => 209437)


--- trunk/LayoutTests/crypto/workers/subtle/resources/rsa-import-spki-key.js	                        (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/resources/rsa-import-spki-key.js	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,27 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts("../../../resources/common.js");
+
+description("Test importing a SPKI RSA key in workers");
+
+jsTestIsAsync = true;
+
+var spkiKey = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382010f003082010a0282010100d61051c4920d4c7c04a33beabb2412bedc4173fdbe82c7db80f0052d00abd32e01656d2105abef4fa5417bb868bb77780c08d20cfe9e2d767ee952970941398f8bea59a966772b1d89f19693cfff5faba22ba39ef7982ac46257180d557d3cbf3f7e65dd835d1d351e679a841b904a3cf24a0323aac0bb89705777507c76f57663b6d846e995a63057ceb48053ddf9282a366d6dc6cbdceb2ebcb3b374c7dc49da160cba8a3656211b8597a39ef9b8cc44d0c5735f870679ffcb1cb9321bbfbc307844d3174ef5dc144a951071340f4d156bead21fd3d9bd4641afa5851512264b4eed228b5d6324de428b00cbb89a1a88cb138d59de0b4ad75f2196e0e7ba890203010001");
+var extractable = true;
+
+shouldReject('crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["decrypt", "unwrapKey"])');
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'RSA-OAEP'");
+    shouldBe("publicKey.algorithm.modulusLength", "2048");
+    shouldBe("bytesToHexString(publicKey.algorithm.publicExponent)", "'010001'");
+    shouldBe("publicKey.algorithm.hash.name", "'SHA-1'");
+    shouldBe("publicKey.usages", "['encrypt', 'wrapKey']");
+
+    finishJSTest();
+});

Added: trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,13 @@
+[Worker] Test exporting a RSA-OAEP public key with SPKI format in workers.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsa-export-spki-key.js
+[Worker] Generating a key pair...
+[Worker] Exporting the public key...
+PASS [Worker] publicKey.byteLength is 294
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/rsa-export-spki-key.js');
+    </script>
+    <script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key-expected.txt (0 => 209437)


--- trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,20 @@
+[Worker] Test importing a SPKI RSA key in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/rsa-import-spki-key.js
+[Worker] Importing a key...
+PASS [Worker] 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 [Worker] publicKey.toString() is '[object CryptoKey]'
+PASS [Worker] publicKey.type is 'public'
+PASS [Worker] publicKey.extractable is true
+PASS [Worker] publicKey.algorithm.name is 'RSA-OAEP'
+PASS [Worker] publicKey.algorithm.modulusLength is 2048
+PASS [Worker] bytesToHexString(publicKey.algorithm.publicExponent) is '010001'
+PASS [Worker] publicKey.algorithm.hash.name is 'SHA-1'
+PASS [Worker] publicKey.usages is ['encrypt', 'wrapKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key.html (0 => 209437)


--- trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key.html	2016-12-07 01:15:20 UTC (rev 209437)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/rsa-import-spki-key.js');
+    </script>
+    <script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (209436 => 209437)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-12-07 01:15:20 UTC (rev 209437)
@@ -1,3 +1,13 @@
+2016-12-05  Jiewen Tan  <[email protected]>
+
+        [Part 1 of 2] Add support for SPKI 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-01  Jiewen Tan  <[email protected]>
 
         Update SubtleCrypto::unwrapKey to match the latest spec

Modified: trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt (209436 => 209437)


--- trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt	2016-12-07 01:15:20 UTC (rev 209437)
@@ -97,16 +97,16 @@
 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
-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: ''The operation is not supported.'' 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: ''The operation is not supported.'' 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: ''The operation is not supported.'' Reached unreachable code
-FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label no encrypt 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 encrypt 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 encrypt 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 encrypt 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 encrypt 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 encrypt 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 encrypt 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 encrypt 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 encrypt 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 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
+FAIL importVectorKeys step: RSA-OAEP with SHA-512 and no label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and no label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-1 and empty label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and empty label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-256 and empty label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and empty label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-384 and empty label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and empty label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-512 and empty label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and empty label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-1 and a label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-1 and a label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-256 and a label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-256 and a label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-384 and a label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-384 and a label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
+FAIL importVectorKeys step: RSA-OAEP with SHA-512 and a label no encrypt usage assert_unreached: importVectorKeys failed for RSA-OAEP with SHA-512 and a label. Message: ''A required parameter was missing or out-of-range'' Reached unreachable code
 

Modified: trunk/Source/WebCore/ChangeLog (209436 => 209437)


--- trunk/Source/WebCore/ChangeLog	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/ChangeLog	2016-12-07 01:15:20 UTC (rev 209437)
@@ -1,3 +1,51 @@
+2016-12-05  Jiewen Tan  <[email protected]>
+
+        [Part 1 of 2] Add support for SPKI format while doing SubtleCrypto.importKey/exportKey
+        https://bugs.webkit.org/show_bug.cgi?id=129978
+        <rdar://problem/21799829>
+
+        This is part 1 of Bug 129978. In this patch, it adds the SPKI format support for
+        SubtleCrypto.importKey/exportKey. Currently support algorithms are RSAES-PKCS1-v1_5,
+        RSASSA-PKCS1-v1_5 and RSA-OAEP.
+
+        Reviewed by Brent Fulgham.
+
+        Tests: crypto/subtle/rsa-import-jwk-key-export-spki-key.html
+               crypto/subtle/rsa-import-spki-key-export-jwk-key.html
+               crypto/subtle/rsa-import-spki-key-export-spki-key.html
+               crypto/subtle/rsa-import-spki-small-key.html
+               crypto/subtle/rsa-oaep-generate-export-key-spki.html
+               crypto/subtle/rsa-oaep-import-spki-key.html
+               crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html
+               crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html
+               crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html
+               crypto/workers/subtle/rsa-export-spki-key.html
+               crypto/workers/subtle/rsa-import-spki-key.html
+
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::toKeyData):
+        * crypto/CommonCryptoUtilities.h:
+        * 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::importSpki):
+        (WebCore::CryptoKeyRSA::exportSpki):
+        * crypto/keys/CryptoKeyRSA.h:
+        * crypto/mac/CryptoKeyRSAMac.cpp:
+        (WebCore::bytesUsedToEncodedLength):
+        (WebCore::bytesNeededForEncodedLength):
+        (WebCore::addEncodedASN1Length):
+        (WebCore::CryptoKeyRSA::importSpki):
+        (WebCore::CryptoKeyRSA::exportSpki):
+
 2016-12-06  Simon Fraser  <[email protected]>
 
         Fix editing text flakiness introduced in r209411

Modified: trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp (209436 => 209437)


--- trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp	2016-12-07 01:15:20 UTC (rev 209437)
@@ -341,10 +341,10 @@
 
     KeyData result;
     switch (format) {
-    case SubtleCrypto::KeyFormat::Spki:
     case SubtleCrypto::KeyFormat::Pkcs8:
         setDOMException(&state, NOT_SUPPORTED_ERR);
         return result;
+    case SubtleCrypto::KeyFormat::Spki:
     case SubtleCrypto::KeyFormat::Raw: {
         BufferSource bufferSource = convert<IDLBufferSource>(state, value);
         RETURN_IF_EXCEPTION(scope, result);

Modified: trunk/Source/WebCore/crypto/CommonCryptoUtilities.h (209436 => 209437)


--- trunk/Source/WebCore/crypto/CommonCryptoUtilities.h	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/CommonCryptoUtilities.h	2016-12-07 01:15:20 UTC (rev 209437)
@@ -82,6 +82,8 @@
 extern "C" CCCryptorStatus CCRSAGetKeyComponents(CCRSACryptorRef rsaKey, uint8_t *modulus, size_t *modulusLength, uint8_t *exponent, size_t *exponentLength, uint8_t *p, size_t *pLength, uint8_t *q, size_t *qLength);
 extern "C" CCRSAKeyType CCRSAGetKeyType(CCRSACryptorRef key);
 extern "C" CCCryptorStatus CCCryptorGCM(CCOperation op, CCAlgorithm alg, const void* key, size_t keyLength, const void* iv, size_t ivLen, const void* aData, size_t aDataLen, const void* dataIn, size_t dataInLength, void* dataOut, const void* tag, size_t* tagLength);
+extern "C" CCCryptorStatus CCRSACryptorImport(const void *keyPackage, size_t keyPackageLen, CCRSACryptorRef *key);
+extern "C" CCCryptorStatus CCRSACryptorExport(CCRSACryptorRef key, void *out, size_t *outLen);
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (209436 => 209437)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp	2016-12-07 01:15:20 UTC (rev 209437)
@@ -120,6 +120,14 @@
         result = CryptoKeyRSA::importJwk(parameters->identifier, std::nullopt, WTFMove(key), extractable, usages);
         break;
     }
+    case SubtleCrypto::KeyFormat::Spki: {
+        if (usages ^ CryptoKeyUsageEncrypt) {
+            exceptionCallback(SYNTAX_ERR);
+            return;
+        }
+        result = CryptoKeyRSA::importSpki(parameters->identifier, std::nullopt, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
@@ -149,6 +157,15 @@
         result = WTFMove(jwk);
         break;
     }
+    case SubtleCrypto::KeyFormat::Spki: {
+        auto spki = rsaKey.exportSpki();
+        if (spki.hasException()) {
+            exceptionCallback(spki.releaseException().code());
+            return;
+        }
+        result = spki.releaseReturnValue();
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (209436 => 209437)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp	2016-12-07 01:15:20 UTC (rev 209437)
@@ -153,6 +153,15 @@
         result = CryptoKeyRSA::importJwk(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(key), extractable, usages);
         break;
     }
+    case SubtleCrypto::KeyFormat::Spki: {
+        if (usages ^ CryptoKeyUsageVerify) {
+            exceptionCallback(SYNTAX_ERR);
+            return;
+        }
+        // FIXME: <webkit.org/b/165436>
+        result = CryptoKeyRSA::importSpki(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
@@ -200,6 +209,15 @@
         result = WTFMove(jwk);
         break;
     }
+    case SubtleCrypto::KeyFormat::Spki: {
+        auto spki = rsaKey.exportSpki();
+        if (spki.hasException()) {
+            exceptionCallback(spki.releaseException().code());
+            return;
+        }
+        result = spki.releaseReturnValue();
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (209436 => 209437)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp	2016-12-07 01:15:20 UTC (rev 209437)
@@ -166,6 +166,15 @@
         result = CryptoKeyRSA::importJwk(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(key), extractable, usages);
         break;
     }
+    case SubtleCrypto::KeyFormat::Spki: {
+        if ((usages ^ CryptoKeyUsageEncrypt) && (usages ^ CryptoKeyUsageWrapKey) && (usages ^ (CryptoKeyUsageEncrypt | CryptoKeyUsageWrapKey))) {
+            exceptionCallback(SYNTAX_ERR);
+            return;
+        }
+        // FIXME: <webkit.org/b/165436>
+        result = CryptoKeyRSA::importSpki(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(WTF::get<Vector<uint8_t>>(data)), extractable, usages);
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;
@@ -213,6 +222,16 @@
         result = WTFMove(jwk);
         break;
     }
+    case SubtleCrypto::KeyFormat::Spki: {
+        // FIXME: <webkit.org/b/165437>
+        auto spki = rsaKey.exportSpki();
+        if (spki.hasException()) {
+            exceptionCallback(spki.releaseException().code());
+            return;
+        }
+        result = spki.releaseReturnValue();
+        break;
+    }
     default:
         exceptionCallback(NOT_SUPPORTED_ERR);
         return;

Modified: trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp (209436 => 209437)


--- trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp	2016-12-07 01:15:20 UTC (rev 209437)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmRegistry.h"
 #include "CryptoKeyDataRSAComponents.h"
 #include "CryptoKeyPair.h"
+#include "ExceptionCode.h"
 #include "NotImplemented.h"
 
 namespace WebCore {
@@ -111,6 +112,20 @@
     UNUSED_PARAM(context);
 }
 
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::importSpki(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier>, Vector<uint8_t>&&, bool, CryptoKeyUsageBitmap)
+{
+    notImplemented();
+
+    return nullptr;
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportSpki() const
+{
+    notImplemented();
+
+    return Exception { NOT_SUPPORTED_ERR };
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)

Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h (209436 => 209437)


--- trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h	2016-12-07 01:15:20 UTC (rev 209437)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "CryptoKey.h"
+#include "ExceptionOr.h"
 #include <wtf/Function.h>
 
 #if ENABLE(SUBTLE_CRYPTO)
@@ -101,9 +102,11 @@
     using VoidCallback = WTF::Function<void()>;
     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);
 
     PlatformRSAKey platformKey() const { return m_platformKey; }
     JsonWebKey exportJwk() const;
+    ExceptionOr<Vector<uint8_t>> exportSpki() const;
 
     CryptoAlgorithmIdentifier hashAlgorithmIdentifier() const { return m_hash; }
 

Modified: trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp (209436 => 209437)


--- trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp	2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp	2016-12-07 01:15:20 UTC (rev 209437)
@@ -32,11 +32,19 @@
 #include "CryptoAlgorithmRegistry.h"
 #include "CryptoKeyDataRSAComponents.h"
 #include "CryptoKeyPair.h"
+#include "ExceptionCode.h"
 #include "ScriptExecutionContext.h"
 #include <wtf/MainThread.h>
 
 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};
+// 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 InitialOctet = 0x00;
+
 // FIXME: We should get rid of magic number 16384. It assumes that the length of provided key will not exceed 16KB.
 // https://bugs.webkit.org/show_bug.cgi?id=164942
 static CCCryptorStatus getPublicKeyComponents(CCRSACryptorRef rsaKey, Vector<uint8_t>& modulus, Vector<uint8_t>& publicExponent)
@@ -235,6 +243,41 @@
     return true;
 }
 
+static size_t bytesUsedToEncodedLength(uint8_t octet)
+{
+    if (octet < 128)
+        return 1;
+    return octet - 127;
+}
+
+static size_t bytesNeededForEncodedLength(size_t length)
+{
+    if (!length)
+        return 0;
+    size_t result = 1;
+    while (result < sizeof(length) && length >= (1 << (result * 8)))
+        result += 1;
+    return result;
+}
+
+static void addEncodedASN1Length(Vector<uint8_t>& in, size_t length)
+{
+    if (length < 128) {
+        in.append(length);
+        return;
+    }
+
+    size_t extraBytes = bytesNeededForEncodedLength(length);
+    in.append(128 + extraBytes);
+
+    size_t lastPosition = in.size() + extraBytes - 1;
+    in.grow(in.size() + extraBytes);
+    for (size_t i = 0; i < extraBytes; i++) {
+        in[lastPosition - i] = length & 0xff;
+        length = length >> 8;
+    }
+}
+
 // FIXME: We should use WorkQueue here instead of dispatch_async once WebKitSubtleCrypto is deprecated.
 // https://bugs.webkit.org/show_bug.cgi?id=164943
 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsageBitmap usage, KeyPairCallback&& callback, VoidCallback&& failureCallback, ScriptExecutionContext* context)
@@ -280,6 +323,61 @@
     });
 }
 
+RefPtr<CryptoKeyRSA> CryptoKeyRSA::importSpki(CryptoAlgorithmIdentifier identifier, std::optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&& keyData, bool extractable, CryptoKeyUsageBitmap usages)
+{
+    // The current SecLibrary cannot import a SPKI format binary. Hence, we need to strip out the SPKI header.
+    // This hack can be removed when <rdar://problem/29523286> is resolved.
+    // The header format we assume is: SequenceMark(1) + Length(?) + rsaEncryption(15) + BitStringMark(1) + Length(?) + InitialOctet(1).
+    // 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/rfc5280#section-4.1. subjectPublicKeyInfo.
+    size_t headerSize = 1;
+    if (keyData.size() < headerSize)
+        return nullptr;
+    headerSize += bytesUsedToEncodedLength(keyData[headerSize]) + sizeof(RSAOIDHeader) + sizeof(BitStringMark);
+    if (keyData.size() < headerSize)
+        return nullptr;
+    headerSize += bytesUsedToEncodedLength(keyData[headerSize]) + sizeof(InitialOctet);
+
+    CCRSACryptorRef ccPublicKey;
+    if (CCRSACryptorImport(keyData.data() + headerSize, keyData.size() - headerSize, &ccPublicKey))
+        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::Public, ccPublicKey, extractable, usages));
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoKeyRSA::exportSpki() const
+{
+    if (type() != CryptoKeyType::Public)
+        return Exception { INVALID_ACCESS_ERR };
+
+    // The current SecLibrary cannot output a valid SPKI 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/rfc3279#section-2.3.1. RSAPublicKey.
+    // O(size) = Sequence(1) + Length(3) + Integer(1) + Length(3) + Modulus + Integer(1) + Length(3) + Exponent
+    Vector<uint8_t> keyBytes(keySizeInBits() / 4);
+    size_t keySize = keyBytes.size();
+    if (CCRSACryptorExport(platformKey(), keyBytes.data(), &keySize))
+        return Exception { OperationError };
+    keyBytes.shrink(keySize);
+
+    // RSAOIDHeader + BitStringMark + Length + keySize + InitialOctet
+    size_t totalSize = sizeof(RSAOIDHeader) + bytesNeededForEncodedLength(keySize + 1) + keySize + 3;
+
+    // Per https://tools.ietf.org/html/rfc5280#section-4.1. subjectPublicKeyInfo.
+    Vector<uint8_t> result;
+    result.append(SequenceMark);
+    addEncodedASN1Length(result, totalSize);
+    result.append(RSAOIDHeader, sizeof(RSAOIDHeader));
+    result.append(BitStringMark);
+    addEncodedASN1Length(result, keySize + 1);
+    result.append(InitialOctet);
+    result.append(keyBytes.data(), keyBytes.size());
+
+    return WTFMove(result);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SUBTLE_CRYPTO)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to