[WebCrypto] Add tests for wrap/unwrap SPKI/PKCS8 keys
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 11 Dec 2016 22:00:17 +0000 (22:00 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 11 Dec 2016 22:00:17 +0000 (22:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165557

Reviewed by Darin Adler.

* crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key-expected.txt: Added.
* crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html: Added.
* crypto/subtle/aes-cbc-import-key-unwrap-spki-key-expected.txt: Added.
* crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html: Added.
* crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key-expected.txt: Added.
* crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html: Added.
* crypto/subtle/aes-cbc-import-key-wrap-spki-key-expected.txt: Added.
* crypto/subtle/aes-cbc-import-key-wrap-spki-key.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-spki-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-spki-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-spki-key.html [new file with mode: 0644]

index 45433db..f1ea0f2 100644 (file)
@@ -1,3 +1,19 @@
+2016-12-11  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [WebCrypto] Add tests for wrap/unwrap SPKI/PKCS8 keys
+        https://bugs.webkit.org/show_bug.cgi?id=165557
+
+        Reviewed by Darin Adler.
+
+        * crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html: Added.
+        * crypto/subtle/aes-cbc-import-key-unwrap-spki-key-expected.txt: Added.
+        * crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html: Added.
+        * crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key-expected.txt: Added.
+        * crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html: Added.
+        * crypto/subtle/aes-cbc-import-key-wrap-spki-key-expected.txt: Added.
+        * crypto/subtle/aes-cbc-import-key-wrap-spki-key.html: Added.
+
 2016-12-11  Dan Bernstein  <mitz@apple.com>
 
         [Cocoa] NSAttributedString representation of text copied from -webkit-nbsp-mode:space element contains non-breaking space characters, but shouldn’t
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..a04e002
--- /dev/null
@@ -0,0 +1,10 @@
+Test unwrapping a PKCS8 key with AES-CBC using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new Uint8Array(unwrappedKey) is pkcs8Key
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html b/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html
new file mode 100644 (file)
index 0000000..c32556f
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test unwrapping a PKCS8 key with AES-CBC using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var aesCbcParams = {
+    name: "aes-cbc",
+    iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var wrappedKey = hexStringToUint8Array( "7aedac7ca0885c4c8340e7414b45b160a872c38eb56f25fa17eeb885abcbd72ce35fb0d8dcfa023dcb0bf94b0fe2a98a693b30e8a993207d646f2b14f673eddddc53815cb3b63cadf3b275bd0c387276e792fbdfd0bab94951ce109ff42ad4c739e5bd6e3f21140d0de7fbd3b60b8a05b29e1aae6385ced993546140a143db854d5b54e2a5d0be425d2aa8a4eee00b779a7b905c3e7fc4a91c37582871eb0b6daddba5d9497271e82e71589a31058fe0c38a7506f72acbc70f88139654cb1a26580f9c20b228c8f22865233d6a705eb68249a906f7d022ef28c84a5dccba26455391f4ce3572e9cfa50b7b4cefcdadf1eec50afc1df31a43f9dda40cd14524aa075b8f081a8b708ce1214b8ec0bd1c9a9af21596d7520b032a7588edaff8116e8710b47f8cda2caace8386cf176507c664f2757d3d728f6ea3be81abe58f36f751a32833d8689b7008a66b72d325ae729bb1064e88ace17c767c376d5c88eff8e8f1cf377639e66390614af43b4aa171fe144ad69c5a0d4d5d4129461da5250fb389b0eb0d53e65263a4b6265ad3fc0d375d42426f3ca1373c044aa47ec9973c77c46ae34f07ba6cc7d43c56438a9d678bf961f7bd7a4155f7cf813dd7a6fe434f04f052d86f5fc79813e85c0817f952e13e99ddea5d21d92e517a8f269a8da660c1d1432ad2d476bd2d13c1f3207b0a5c3f0f250fc195f406e89c1c107d5733cbaaacefc411ea7377880caa09847560b4dfe86f1ce8a0aac3d142eb9aa315a7e36383b5aa4f027f6ee6603053dd877e57755ae13a0b01453b3806610f98ed85ea574a2c040d0df9e861091f72a285fb563da4ac9d6098a2e4cf232455d8529e80ec8b9334690bca941caa8d8c6c2ebb29c73176c736b2e1cd897aaecdb7d51fbf2eeb5716bb441c0a2646643530f1618a5923b7fe3c6d8fcd55ec18ddbc5053d09af3f3ca058b3471d3cc327cdcdaa8a0dcada0dd3e52365d5ad2d36643769e8f274ef2020ce47975dceefb1fa3a4ff092927ebd2dc9017b4e36ab0591358a65c98d981f1e687e9cde16b3953b0f4b5a8f0b305fdfbbc60d11046d633a8c96e705290300a145a58f61983a3b95dc57615863faa2c217f3656a627b6a3e438ff55cd87c6462699a3db064213f30831e8be8d058ea6313af2d468904dfa544b4caf0598fcb2e59d5a1b4ee022f32e86b4ef0fd2e55ecb38edc114758d97718bc3c43f300614554a19320b7c7687d3d2218bb7fef7a01950c028c14f0bdede849924c0cab8161a7d0600d46f9e37bdbb7f7b2d3ca72e75eb6da10e015c5c2bed171ac50ff94a3291a6fc5b5a093d4c9cfbc269fc4f295c881676706f1fadda515c6f9441f5f05af0a8255706b18f8b76bf4b5f729cddea05b099470f02f71df46a3b0b53ec5429bdfd29c9c50f72c0359bdf4ee7435dcbc415fa5b2633ebdc5d6213fe5eefcfdeda6a14b9f4d9ba837afae59549a31428a9ead0c3e32c66cf93e42d5b0266e0ad7d6ed5027923c6d0eb8191f55d987a2ebf4c87f4d49c1b75c3e938c8c54d502877e54ef1fbae0851e6b55c3fbc443fe6ae1ef97aa4d4c4a0dd7a74191fa72bf1f127b63001f36c9b3d1bb8d9d1fe609cf24423b84cc96afed8e38508efb9bf01638ca75abcc46fc371aac26c493ee9b0a71c95e310eeb30460ef6baf622cbc74c89b01558d0913e4394369a782d3536c8ca0b90aaf087004a7d18836c0b9d45a48fd235a12e687d80c6e");
+
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["unwrapKey"]).then(function(unwrappingKey) {
+    return crypto.subtle.unwrapKey("pkcs8", wrappedKey, unwrappingKey, aesCbcParams, {name: "rsa-oaep", hash: "sha-1"}, extractable, ["decrypt"]);
+}).then(function(cryptoKey) {
+    return crypto.subtle.exportKey("pkcs8", cryptoKey);
+}).then(function(result) {
+    unwrappedKey = result;
+
+    shouldBe("new Uint8Array(unwrappedKey)", "pkcs8Key");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-spki-key-expected.txt b/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-spki-key-expected.txt
new file mode 100644 (file)
index 0000000..fb24920
--- /dev/null
@@ -0,0 +1,10 @@
+Test unwrapping a SPKI key with AES-CBC using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new Uint8Array(unwrappedKey) is spkiKey
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html b/LayoutTests/crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html
new file mode 100644 (file)
index 0000000..aaf74ce
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test unwrapping a SPKI key with AES-CBC using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var spkiKey = Base64URL.parse("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCjRCtFwvSNYMZ07u5SxARxglJl75T7bUZXFsDVxHkMhpNC2RaN4jWE5bwYUDMeD2fVmxhpaUQn/6AbFLh6gHxtwrCfc7rIo/SfDdGd3GkRlXK5xXwGuM6MvP9nuZHaarIyArRFh2U2UZxFlVsKI0pSHo6n58W1fPZ1syOoVEZ/WYE6gLhMMwfpeAm97mro7mekRdMULOV/mR5Ul3CHm9Zt93Dc8GpnPA8bhLiB0VNyGTEMa06nJul4gj1sjxLDoUvZY2EWq7oUUnfLBUYMfiqK0kQcW94wvBrIq2DQUApLyTTbaAOY46TLwX6c8LtubJriYKTC5a9Bb0/7ovTWB0wIDAQAB");
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var aesCbcParams = {
+    name: "aes-cbc",
+    iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var wrappedKey = hexStringToUint8Array( "578a2ab61e1e4964362e4b26694f81269c7d7c007a4108b6daa078a4360e00ec15d26856934527339eff2a704d1abcd32cd3e7ce4d266bb19f9d2ddf4ebd743bf427c12fc0c787ca3815cd533b69a1e08093a417f19308ed811f192531ee3a477b16166fb77e438466cc7c7ce858e98e62f2e8e2add4ab99322e61c9b16c6c7991822994f9d007e5452abaf45426acaedbfb9b2cc7aec2fb01ff1a34ae434d600cce9c10c5db3235803412c5af890f135cc49d94694cef68a41b0e12b96f3cae8ca375f84495c78419cfaeec6b3762e4550c423392bfabd8f4b6617cc16b1adeb7f0cf55dfa9639957ebca7453fef05ab7e6da652618fd9d7c9f9a1a026397d047cdfb7a8520e11a61cc9714c414794f76cc4c36a8f1de59eb0f30f6d10a6f4108a2c2d6bce3539c02cac3aa7e3843da");
+
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["unwrapKey"]).then(function(unwrappingKey) {
+    return crypto.subtle.unwrapKey("spki", wrappedKey, unwrappingKey, aesCbcParams, {name: "rsa-oaep", hash: "sha-1"}, extractable, ["encrypt"]);
+}).then(function(cryptoKey) {
+    return crypto.subtle.exportKey("spki", cryptoKey);
+}).then(function(result) {
+    unwrappedKey = result;
+
+    shouldBe("new Uint8Array(unwrappedKey)", "spkiKey");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key-expected.txt b/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key-expected.txt
new file mode 100644 (file)
index 0000000..0baf997
--- /dev/null
@@ -0,0 +1,10 @@
+Test wrapping a PKCS8 key with AES-CBC using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(wrappedKey) is expectWrappedKey
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html b/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html
new file mode 100644 (file)
index 0000000..cfa5b68
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test wrapping a PKCS8 key with AES-CBC using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var pkcs8Key = hexStringToUint8Array("308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100ca6ee8ec62b6a02e187b70c19ca15a13c386a470ee8816c7340a270f96f905511f93362f8f7aae3e60394dac34cb29ea5f540d6ef80b1df7155b66a2d6d6e44092bcbafbf69b061b3f4d927060c81d0fa07d22f481ff503c0581ffa444f57345204ddf0a93a225979c61aeb9686557f7632002e165430452868d010d505e3ccfed7315432a298a9b6d1a6ede98ee746c2c8bd22f5495cee563e2db24f1e33d91ced83af1baac754dba4ddba430f6cf3d4ac7edb0bf69891140854e8700056a7ef6d06ed5a605a05e74ecb3b246ce9cb310b39b00c707af3a637862e3d2914013de212ff09a36db84d99b8d610d0cfd36a4411dbf1b62e06ebff1bee50f040ca502030100010282010024706483309db925b3087d5a8cac4abfa60195963289d2b7d6f940e0c08760daa279685695583b074560eb47655570dd1c7dcfd13adb1d70bdaa6f463eaffdf455b59d5eff9c16344f67d2456256834cadd1f8b9d4b0b5aba83e275b55826d567323315401113dfd158c4bdc5a1b6c033f17a30d19a23fa3ef4e70730a157c928b1c7840a34401d19daab52cfa9b424cc8e1084254ca597304be22547b7221e875bf1fdca2386ba1e855d5e0bcaba03376bfd73de8513c07ab0e67cb3554dc8c8f7a67d231f99a2b653ad471ee2f8bd3b8fad51b02f807d131b6b71ab17e45a5faf161ce3b919d96b5e78e9e4e1202d6398a954def4c1980da1fcc30d56167e102818100ee24b92668d38465fdd9a2262e64be56846be561e4cfbcedc82496a3190b549636923d61c3e5a2d40cc6d2c46a3e89ac23eb44ac40c777147e3e49a80bd382bae06e284f1cc553f89d78f0c7bf20fd3a33ee598ce2caf61e3f5457cd228ff03fe009f10952206bf248e161d17950c6655af75b097bbda1b909038d4d752cd11d02818100d99cb65195a399f9a3aca1ef1593592992e7d91cc028b713ec5b661b9976fcffdb086f523f042699cb910321fe7b67a27dd4a72822e6fbb98d005280721efc32d889d431d2737c92a4f34d4885c7a9c6244e081a1264a283d07744b752a68ebb6fbff3492a039e3e3a0cc5b94537582a7d11cc6b8678e4c338671f96be029b2902818100a1a2a7509ca1c4217db4f3cbba7d827b32921134ea9add7efef36692f8f2a9ccf2e93b645a1448fa6859a2c0d1e3f489b42f8182f0ccf1d425039df6c360224139074bb0b6b47094343ddc1f97688ab7b07bbca8555eb0c242f5ba4a6f8506ea33e44b87aa087b7c0d5f7c8733325216853192c6d30818f68059bad4b20d633902818034b3bf7402c99c80d922f614f124be735320d3742315b94119fd08bda66d2ad8cc333ec2ac8054d8ea74344e0753dbc57eb401c7b6ac3a4ab5db5e1fbd83c3908ce0d4833c74bbb6c83c247b6beaef330d97d85e7815e7460536dd6d8896cdfa9715e5d5d2570dfc041313cfcaf39c66ade3a19e68f2de7469349071f192b00102818060a8271f45161d8ecf62c3ac5f0fa8539b6d86a35123aafcc37541e2d5e5b62715777db0ef75f3cdf67506b8fcad6baed862eaf88fa1f280f42736b69a41ea7a3fea31ce62aa0563c85df1d9b02b83839c4ab9453e420c5c401cce979f6fb7b6ac12baf1e9140546eed24e92e383b8f2d37b3e4410844d235c7175112e751ee0");
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var aesCbcParams = {
+    name: "aes-cbc",
+    iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var expectWrappedKey = "7aedac7ca0885c4c8340e7414b45b160a872c38eb56f25fa17eeb885abcbd72ce35fb0d8dcfa023dcb0bf94b0fe2a98a693b30e8a993207d646f2b14f673eddddc53815cb3b63cadf3b275bd0c387276e792fbdfd0bab94951ce109ff42ad4c739e5bd6e3f21140d0de7fbd3b60b8a05b29e1aae6385ced993546140a143db854d5b54e2a5d0be425d2aa8a4eee00b779a7b905c3e7fc4a91c37582871eb0b6daddba5d9497271e82e71589a31058fe0c38a7506f72acbc70f88139654cb1a26580f9c20b228c8f22865233d6a705eb68249a906f7d022ef28c84a5dccba26455391f4ce3572e9cfa50b7b4cefcdadf1eec50afc1df31a43f9dda40cd14524aa075b8f081a8b708ce1214b8ec0bd1c9a9af21596d7520b032a7588edaff8116e8710b47f8cda2caace8386cf176507c664f2757d3d728f6ea3be81abe58f36f751a32833d8689b7008a66b72d325ae729bb1064e88ace17c767c376d5c88eff8e8f1cf377639e66390614af43b4aa171fe144ad69c5a0d4d5d4129461da5250fb389b0eb0d53e65263a4b6265ad3fc0d375d42426f3ca1373c044aa47ec9973c77c46ae34f07ba6cc7d43c56438a9d678bf961f7bd7a4155f7cf813dd7a6fe434f04f052d86f5fc79813e85c0817f952e13e99ddea5d21d92e517a8f269a8da660c1d1432ad2d476bd2d13c1f3207b0a5c3f0f250fc195f406e89c1c107d5733cbaaacefc411ea7377880caa09847560b4dfe86f1ce8a0aac3d142eb9aa315a7e36383b5aa4f027f6ee6603053dd877e57755ae13a0b01453b3806610f98ed85ea574a2c040d0df9e861091f72a285fb563da4ac9d6098a2e4cf232455d8529e80ec8b9334690bca941caa8d8c6c2ebb29c73176c736b2e1cd897aaecdb7d51fbf2eeb5716bb441c0a2646643530f1618a5923b7fe3c6d8fcd55ec18ddbc5053d09af3f3ca058b3471d3cc327cdcdaa8a0dcada0dd3e52365d5ad2d36643769e8f274ef2020ce47975dceefb1fa3a4ff092927ebd2dc9017b4e36ab0591358a65c98d981f1e687e9cde16b3953b0f4b5a8f0b305fdfbbc60d11046d633a8c96e705290300a145a58f61983a3b95dc57615863faa2c217f3656a627b6a3e438ff55cd87c6462699a3db064213f30831e8be8d058ea6313af2d468904dfa544b4caf0598fcb2e59d5a1b4ee022f32e86b4ef0fd2e55ecb38edc114758d97718bc3c43f300614554a19320b7c7687d3d2218bb7fef7a01950c028c14f0bdede849924c0cab8161a7d0600d46f9e37bdbb7f7b2d3ca72e75eb6da10e015c5c2bed171ac50ff94a3291a6fc5b5a093d4c9cfbc269fc4f295c881676706f1fadda515c6f9441f5f05af0a8255706b18f8b76bf4b5f729cddea05b099470f02f71df46a3b0b53ec5429bdfd29c9c50f72c0359bdf4ee7435dcbc415fa5b2633ebdc5d6213fe5eefcfdeda6a14b9f4d9ba837afae59549a31428a9ead0c3e32c66cf93e42d5b0266e0ad7d6ed5027923c6d0eb8191f55d987a2ebf4c87f4d49c1b75c3e938c8c54d502877e54ef1fbae0851e6b55c3fbc443fe6ae1ef97aa4d4c4a0dd7a74191fa72bf1f127b63001f36c9b3d1bb8d9d1fe609cf24423b84cc96afed8e38508efb9bf01638ca75abcc46fc371aac26c493ee9b0a71c95e310eeb30460ef6baf622cbc74c89b01558d0913e4394369a782d3536c8ca0b90aaf087004a7d18836c0b9d45a48fd235a12e687d80c6e";
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["wrapKey"]).then(function(result) {
+    wrappingKey = result;
+    return crypto.subtle.importKey("pkcs8", pkcs8Key, { name: "rsa-oaep", hash: "sha-1" }, extractable, ["decrypt"]);
+}).then(function(result) {
+    key = result;
+    return crypto.subtle.wrapKey("pkcs8", key, wrappingKey, aesCbcParams);
+}).then(function(result) {
+    wrappedKey = result;
+
+    shouldBe("bytesToHexString(wrappedKey)", "expectWrappedKey");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-spki-key-expected.txt b/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-spki-key-expected.txt
new file mode 100644 (file)
index 0000000..cbcb5a0
--- /dev/null
@@ -0,0 +1,10 @@
+Test wrapping a SPKI key with AES-CBC using an imported key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(wrappedKey) is expectWrappedKey
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-spki-key.html b/LayoutTests/crypto/subtle/aes-cbc-import-key-wrap-spki-key.html
new file mode 100644 (file)
index 0000000..0ecc64f
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test wrapping a SPKI key with AES-CBC using an imported key");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var spkiKey = Base64URL.parse("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCjRCtFwvSNYMZ07u5SxARxglJl75T7bUZXFsDVxHkMhpNC2RaN4jWE5bwYUDMeD2fVmxhpaUQn/6AbFLh6gHxtwrCfc7rIo/SfDdGd3GkRlXK5xXwGuM6MvP9nuZHaarIyArRFh2U2UZxFlVsKI0pSHo6n58W1fPZ1syOoVEZ/WYE6gLhMMwfpeAm97mro7mekRdMULOV/mR5Ul3CHm9Zt93Dc8GpnPA8bhLiB0VNyGTEMa06nJul4gj1sjxLDoUvZY2EWq7oUUnfLBUYMfiqK0kQcW94wvBrIq2DQUApLyTTbaAOY46TLwX6c8LtubJriYKTC5a9Bb0/7ovTWB0wIDAQAB");
+var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
+var aesCbcParams = {
+    name: "aes-cbc",
+    iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
+}
+var expectWrappedKey = "578a2ab61e1e4964362e4b26694f81269c7d7c007a4108b6daa078a4360e00ec15d26856934527339eff2a704d1abcd32cd3e7ce4d266bb19f9d2ddf4ebd743bf427c12fc0c787ca3815cd533b69a1e08093a417f19308ed811f192531ee3a477b16166fb77e438466cc7c7ce858e98e62f2e8e2add4ab99322e61c9b16c6c7991822994f9d007e5452abaf45426acaedbfb9b2cc7aec2fb01ff1a34ae434d600cce9c10c5db3235803412c5af890f135cc49d94694cef68a41b0e12b96f3cae8ca375f84495c78419cfaeec6b3762e4550c423392bfabd8f4b6617cc16b1adeb7f0cf55dfa9639957ebca7453fef05ab7e6da652618fd9d7c9f9a1a026397d047cdfb7a8520e11a61cc9714c414794f76cc4c36a8f1de59eb0f30f6d10a6f4108a2c2d6bce3539c02cac3aa7e3843da";
+
+crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["wrapKey"]).then(function(result) {
+    wrappingKey = result;
+    return crypto.subtle.importKey("spki", spkiKey, { name: "rsa-oaep", hash: "sha-1" }, extractable, ["encrypt"]);
+}).then(function(result) {
+    key = result;
+    return crypto.subtle.wrapKey("spki", key, wrappingKey, aesCbcParams);
+}).then(function(result) {
+    wrappedKey = result;
+
+    shouldBe("bytesToHexString(wrappedKey)", "expectWrappedKey");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>