Title: [209657] trunk
Revision
209657
Author
[email protected]
Date
2016-12-10 00:57:42 -0800 (Sat, 10 Dec 2016)

Log Message

[WebCrypto] RSA algorithms should allow importing keys without usages
https://bugs.webkit.org/show_bug.cgi?id=165680
<rdar://problem/29601354>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt:

Source/WebCore:

Tests: crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html
       crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html
       crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html
       crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html
       crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html

* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::importKey):

LayoutTests:

* crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages-expected.txt: Added.
* crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html: Added.
* crypto/subtle/rsa-oaep-import-spki-key-empty-usages-expected.txt: Added.
* crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt: Added.
* crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (209656 => 209657)


--- trunk/LayoutTests/ChangeLog	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/LayoutTests/ChangeLog	2016-12-10 08:57:42 UTC (rev 209657)
@@ -1,3 +1,24 @@
+2016-12-10  Jiewen Tan  <[email protected]>
+
+        [WebCrypto] RSA algorithms should allow importing keys without usages
+        https://bugs.webkit.org/show_bug.cgi?id=165680
+        <rdar://problem/29601354>
+
+        Reviewed by Brent Fulgham.
+
+        * crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages-expected.txt: Added.
+        * crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html: Added.
+        * crypto/subtle/rsa-oaep-import-spki-key-empty-usages-expected.txt: Added.
+        * crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt: Added.
+        * crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt: Added.
+        * crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html: Added.
+
 2016-12-09  Romain Bellessort  <[email protected]>
 
         [Readable Streams API] Implement ReadableByteStreamController desiredSize

Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages-expected.txt (0 => 209657)


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,18 @@
+Test importing a JWK RSA-OAEP public key with SHA-1 and empty usages
+
+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 [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html (0 => 209657)


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,47 @@
+<!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 empty usages");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RSA-OAEP",
+    use: "enc",
+    key_ops: ["encrypt", "wrapKey"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB"
+};
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "SHA-1"}, extractable, [ ]).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", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>
\ No newline at end of file

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


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-empty-usages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-empty-usages-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSA-OAEP key with empty usages
+
+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 [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

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


--- trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html	2016-12-10 08:57:42 UTC (rev 209657)
@@ -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 with empty usages");
+
+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, [ ]).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", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt (0 => 209657)


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,18 @@
+Test importing a JWK RSAES-PKCS1-v1_5 public key with empty usages
+
+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 [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html (0 => 209657)


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a JWK RSAES-PKCS1-v1_5 public key with empty usages");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RSA1_5",
+    use: "enc",
+    key_ops: ["encrypt"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB"
+};
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, "RSAES-PKCS1-v1_5", extractable, [ ]).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", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

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


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSAES-PKCS1-v1_5 key with empty usages
+
+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 [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

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


--- trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html	2016-12-10 08:57:42 UTC (rev 209657)
@@ -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 with empty usages");
+
+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, [ ]).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", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt (0 => 209657)


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,18 @@
+Test importing a JWK RSASSA-PKCS1-v1_5 public key with SHA-1 and empty usages
+
+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 [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html (0 => 209657)


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a JWK RSASSA-PKCS1-v1_5 public key with SHA-1 and empty usages");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "RSA",
+    alg: "RS1",
+    use: "sig",
+    key_ops: ["verify"],
+    ext: true,
+    n: "rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw",
+    e: "AQAB"
+};
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, {name: "RSASSA-PKCS1-v1_5", hash: "SHA-1"}, extractable, [ ]).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", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

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


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -0,0 +1,18 @@
+Test importing a SPKI RSASSA-PKCS1-v1_5 key with empty usages
+
+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 [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

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


--- trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html	                        (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html	2016-12-10 08:57:42 UTC (rev 209657)
@@ -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 with empty usages");
+
+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, [ ]).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", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (209656 => 209657)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-12-10 08:57:42 UTC (rev 209657)
@@ -1,3 +1,13 @@
+2016-12-10  Jiewen Tan  <[email protected]>
+
+        [WebCrypto] RSA algorithms should allow importing keys without usages
+        https://bugs.webkit.org/show_bug.cgi?id=165680
+        <rdar://problem/29601354>
+
+        Reviewed by Brent Fulgham.
+
+        * WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt:
+
 2016-12-09  Joseph Pecoraro  <[email protected]>
 
         Ignore LayoutTests/imported/w3c/web-platform-tests/config.json

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


--- trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt	2016-12-10 08:57:42 UTC (rev 209657)
@@ -97,16 +97,16 @@
 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
-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
+PASS RSA-OAEP with SHA-1 and no label no encrypt usage 
+PASS RSA-OAEP with SHA-256 and no label no encrypt usage 
+PASS RSA-OAEP with SHA-384 and no label no encrypt usage 
+PASS RSA-OAEP with SHA-512 and no label no encrypt usage 
+PASS RSA-OAEP with SHA-1 and empty label no encrypt usage 
+PASS RSA-OAEP with SHA-256 and empty label no encrypt usage 
+PASS RSA-OAEP with SHA-384 and empty label no encrypt usage 
+PASS RSA-OAEP with SHA-512 and empty label no encrypt usage 
+PASS RSA-OAEP with SHA-1 and a label no encrypt usage 
+PASS RSA-OAEP with SHA-256 and a label no encrypt usage 
+PASS RSA-OAEP with SHA-384 and a label no encrypt usage 
+PASS RSA-OAEP with SHA-512 and a label no encrypt usage 
 

Modified: trunk/Source/WebCore/ChangeLog (209656 => 209657)


--- trunk/Source/WebCore/ChangeLog	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/Source/WebCore/ChangeLog	2016-12-10 08:57:42 UTC (rev 209657)
@@ -1,3 +1,25 @@
+2016-12-10  Jiewen Tan  <[email protected]>
+
+        [WebCrypto] RSA algorithms should allow importing keys without usages
+        https://bugs.webkit.org/show_bug.cgi?id=165680
+        <rdar://problem/29601354>
+
+        Reviewed by Brent Fulgham.
+
+        Tests: crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html
+               crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html
+               crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html
+               crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html
+               crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html
+
+        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
+        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+        (WebCore::CryptoAlgorithmRSA_OAEP::importKey):
+
 2016-12-10  Frederic Wang  <[email protected]>
 
         Add STIX Two Math to the list of math fonts in mathml.css

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (209656 => 209657)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp	2016-12-10 08:57:42 UTC (rev 209657)
@@ -105,7 +105,7 @@
     switch (format) {
     case SubtleCrypto::KeyFormat::Jwk: {
         JsonWebKey key = WTFMove(WTF::get<JsonWebKey>(data));
-        if ((key.d && (usages ^ CryptoKeyUsageDecrypt)) || (!key.d && (usages ^ CryptoKeyUsageEncrypt))) {
+        if (usages && ((key.d && (usages ^ CryptoKeyUsageDecrypt)) || (!key.d && (usages ^ CryptoKeyUsageEncrypt)))) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }
@@ -121,7 +121,7 @@
         break;
     }
     case SubtleCrypto::KeyFormat::Spki: {
-        if (usages ^ CryptoKeyUsageEncrypt) {
+        if (usages && (usages ^ CryptoKeyUsageEncrypt)) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }
@@ -129,7 +129,7 @@
         break;
     }
     case SubtleCrypto::KeyFormat::Pkcs8: {
-        if (usages ^ CryptoKeyUsageDecrypt) {
+        if (usages && (usages ^ CryptoKeyUsageDecrypt)) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (209656 => 209657)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp	2016-12-10 08:57:42 UTC (rev 209657)
@@ -116,7 +116,7 @@
     case SubtleCrypto::KeyFormat::Jwk: {
         JsonWebKey key = WTFMove(WTF::get<JsonWebKey>(data));
 
-        if ((key.d && (usages ^ CryptoKeyUsageSign)) || (!key.d && (usages ^ CryptoKeyUsageVerify))) {
+        if (usages && ((key.d && (usages ^ CryptoKeyUsageSign)) || (!key.d && (usages ^ CryptoKeyUsageVerify)))) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }
@@ -154,7 +154,7 @@
         break;
     }
     case SubtleCrypto::KeyFormat::Spki: {
-        if (usages ^ CryptoKeyUsageVerify) {
+        if (usages && (usages ^ CryptoKeyUsageVerify)) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }
@@ -163,7 +163,7 @@
         break;
     }
     case SubtleCrypto::KeyFormat::Pkcs8: {
-        if (usages ^ CryptoKeyUsageSign) {
+        if (usages && (usages ^ CryptoKeyUsageSign)) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (209656 => 209657)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp	2016-12-10 08:43:46 UTC (rev 209656)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp	2016-12-10 08:57:42 UTC (rev 209657)
@@ -128,6 +128,7 @@
             isUsagesAllowed = isUsagesAllowed || !(usages ^ CryptoKeyUsageWrapKey);
             isUsagesAllowed = isUsagesAllowed || !(usages ^ (CryptoKeyUsageEncrypt | CryptoKeyUsageWrapKey));
         }
+        isUsagesAllowed = isUsagesAllowed || !usages;
         if (!isUsagesAllowed) {
             exceptionCallback(SYNTAX_ERR);
             return;
@@ -167,7 +168,7 @@
         break;
     }
     case SubtleCrypto::KeyFormat::Spki: {
-        if ((usages ^ CryptoKeyUsageEncrypt) && (usages ^ CryptoKeyUsageWrapKey) && (usages ^ (CryptoKeyUsageEncrypt | CryptoKeyUsageWrapKey))) {
+        if (usages && (usages ^ CryptoKeyUsageEncrypt) && (usages ^ CryptoKeyUsageWrapKey) && (usages ^ (CryptoKeyUsageEncrypt | CryptoKeyUsageWrapKey))) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }
@@ -176,7 +177,7 @@
         break;
     }
     case SubtleCrypto::KeyFormat::Pkcs8: {
-        if ((usages ^ CryptoKeyUsageDecrypt) && (usages ^ CryptoKeyUsageUnwrapKey) && (usages ^ (CryptoKeyUsageDecrypt | CryptoKeyUsageUnwrapKey))) {
+        if (usages && (usages ^ CryptoKeyUsageDecrypt) && (usages ^ CryptoKeyUsageUnwrapKey) && (usages ^ (CryptoKeyUsageDecrypt | CryptoKeyUsageUnwrapKey))) {
             exceptionCallback(SYNTAX_ERR);
             return;
         }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to