<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[209437] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/209437">209437</a></dd>
<dt>Author</dt> <dd>jiewen_tan@apple.com</dd>
<dt>Date</dt> <dd>2016-12-06 17:15:20 -0800 (Tue, 06 Dec 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[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.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestscryptosubtleimportkeymalformedparametersexpectedtxt">trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtleimportkeymalformedparametershtml">trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaexportkeymalformedparametersexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaexportkeymalformedparametershtml">trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportkeymalformedparametersexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportkeymalformedparametershtml">trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cWebCryptoAPIencrypt_decrypttest_rsa_oaepexpectedtxt">trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSSubtleCryptoCustomcpp">trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp</a></li>
<li><a href="#trunkSourceWebCorecryptoCommonCryptoUtilitiesh">trunk/Source/WebCore/crypto/CommonCryptoUtilities.h</a></li>
<li><a href="#trunkSourceWebCorecryptoalgorithmsCryptoAlgorithmRSAES_PKCS1_v1_5cpp">trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp</a></li>
<li><a href="#trunkSourceWebCorecryptoalgorithmsCryptoAlgorithmRSASSA_PKCS1_v1_5cpp">trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp</a></li>
<li><a href="#trunkSourceWebCorecryptoalgorithmsCryptoAlgorithmRSA_OAEPcpp">trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp</a></li>
<li><a href="#trunkSourceWebCorecryptognutlsCryptoKeyRSAGnuTLScpp">trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp</a></li>
<li><a href="#trunkSourceWebCorecryptokeysCryptoKeyRSAh">trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h</a></li>
<li><a href="#trunkSourceWebCorecryptomacCryptoKeyRSAMaccpp">trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestscryptosubtlersaimportjwkkeyexportspkikeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportjwkkeyexportspkikeyhtml">trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportspkikeyexportjwkkeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportspkikeyexportjwkkeyhtml">trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportspkikeyexportspkikeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportspkikeyexportspkikeyhtml">trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportspkismallkeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaimportspkismallkeyhtml">trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaoaepgenerateexportkeyspkiexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaoaepgenerateexportkeyspkihtml">trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaoaepimportspkikeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaoaepimportspkikeyhtml">trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaespkcs1v1_5generateexportkeyspkiexpectedtxt">trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaespkcs1v1_5generateexportkeyspkihtml">trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaespkcs1v1_5importspkikeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaespkcs1v1_5importspkikeyhtml">trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersassapkcs1v1_5generateexportkeyspkiexpectedtxt">trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersassapkcs1v1_5generateexportkeyspkihtml">trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersassapkcs1v1_5importspkikeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersassapkcs1v1_5importspkikeyhtml">trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html</a></li>
<li><a href="#trunkLayoutTestscryptoworkerssubtleresourcesrsaexportspkikeyjs">trunk/LayoutTests/crypto/workers/subtle/resources/rsa-export-spki-key.js</a></li>
<li><a href="#trunkLayoutTestscryptoworkerssubtleresourcesrsaimportspkikeyjs">trunk/LayoutTests/crypto/workers/subtle/resources/rsa-import-spki-key.js</a></li>
<li><a href="#trunkLayoutTestscryptoworkerssubtlersaexportspkikeyexpectedtxt">trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptoworkerssubtlersaexportspkikeyhtml">trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key.html</a></li>
<li><a href="#trunkLayoutTestscryptoworkerssubtlersaimportspkikeyexpectedtxt">trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptoworkerssubtlersaimportspkikeyhtml">trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-12-07 00:46:23 UTC (rev 209436)
+++ trunk/LayoutTests/ChangeLog        2016-12-07 01:15:20 UTC (rev 209437)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2016-12-05 Jiewen Tan <jiewen_tan@apple.com>
+
+ [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.
+
</ins><span class="cx"> 2016-12-06 Antoine Quint <graouts@apple.com>
</span><span class="cx">
</span><span class="cx"> [Modern Media Controls] Media controls use the fullscreen layout after going from inline to fullscreen to PiP to inline
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtleimportkeymalformedparametersexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters-expected.txt (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -16,7 +16,6 @@
</span><span class="cx"> PASS crypto.subtle.importKey({ }, rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise with TypeError: Type error.
</span><span class="cx"> PASS crypto.subtle.importKey("foo", rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise with TypeError: Type error.
</span><span class="cx"> 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..
</span><del>-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..
</del><span class="cx"> PASS crypto.subtle.importKey("raw", jwkKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise with TypeError: Type error.
</span><span class="cx"> PASS crypto.subtle.importKey("raw", 1, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise with TypeError: Type error.
</span><span class="cx"> PASS crypto.subtle.importKey("raw", true, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]) rejected promise with TypeError: Type error.
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtleimportkeymalformedparametershtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/import-key-malformed-parameters.html (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -50,7 +50,6 @@
</span><span class="cx"> shouldReject('crypto.subtle.importKey("foo", rawKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
</span><span class="cx"> // Currently not support formats.
</span><span class="cx"> shouldReject('crypto.subtle.importKey("pkcs8", rawKey, "rsaes-pkcs1-v1_5", extractable, ["encrypt", "decrypt"])');
</span><del>-shouldReject('crypto.subtle.importKey("spki", rawKey, "rsaes-pkcs1-v1_5", extractable, ["encrypt", "decrypt"])');
</del><span class="cx"> // Wrong KeyData.
</span><span class="cx"> shouldReject('crypto.subtle.importKey("raw", jwkKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
</span><span class="cx"> shouldReject('crypto.subtle.importKey("raw", 1, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"])');
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaexportkeymalformedparametersexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters-expected.txt (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -3,9 +3,9 @@
</span><span class="cx"> On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
</span><span class="cx">
</span><span class="cx">
</span><del>-PASS crypto.subtle.exportKey("spki", publicKey) rejected promise with NotSupportedError (DOM Exception 9): The algorithm is not supported.
</del><span class="cx"> PASS crypto.subtle.exportKey("pkcs8", publicKey) rejected promise with NotSupportedError (DOM Exception 9): The algorithm is not supported.
</span><span class="cx"> PASS crypto.subtle.exportKey("raw", publicKey) rejected promise with NotSupportedError (DOM Exception 9): The algorithm is not supported.
</span><ins>+PASS crypto.subtle.exportKey("spki", privateKey) rejected promise with InvalidAccessError (DOM Exception 15): The requested operation is not valid for the provided key.
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaexportkeymalformedparametershtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-export-key-malformed-parameters.html (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -24,14 +24,16 @@
</span><span class="cx">
</span><span class="cx"> crypto.subtle.generateKey(algorithmKeyGen, extractable, ["decrypt", "encrypt", "wrapKey", "unwrapKey"]).then(function(result) {
</span><span class="cx"> publicKey = result.publicKey;
</span><ins>+ privateKey = result.privateKey;
</ins><span class="cx">
</span><span class="cx"> // Currently not support format.
</span><del>- return shouldReject('crypto.subtle.exportKey("spki", publicKey)');
-}).then(function() {
</del><span class="cx"> return shouldReject('crypto.subtle.exportKey("pkcs8", publicKey)');
</span><span class="cx"> }).then(function() {
</span><span class="cx"> // Not support format.
</span><span class="cx"> return shouldReject('crypto.subtle.exportKey("raw", publicKey)');
</span><ins>+}).then(function() {
+ // Wrong key and format.
+ return shouldReject('crypto.subtle.exportKey("spki", privateKey)');
</ins><span class="cx"> }).then(finishJSTest, finishJSTest);
</span><span class="cx">
</span><span class="cx"> </script>
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportjwkkeyexportspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportjwkkeyexportspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-jwk-key-export-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a JWK RSA-OAEP public key with SHA-1 and then export it in 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportkeymalformedparametersexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters-expected.txt (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -36,6 +36,9 @@
</span><span class="cx"> 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.
</span><span class="cx"> 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.
</span><span class="cx"> 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.
</span><ins>+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.
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx">
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportkeymalformedparametershtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-import-key-malformed-parameters.html (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -21,6 +21,7 @@
</span><span class="cx"> var dp = "fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk";
</span><span class="cx"> var dq = "jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE";
</span><span class="cx"> var qi = "YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk";
</span><ins>+var spkiKey = hexStringToUint8Array("30820122300d06092a864886f70d01010105000382010f003082010a0282010100d61051c4920d4c7c04a33beabb2412bedc4173fdbe82c7db80f0052d00abd32e01656d2105abef4fa5417bb868bb77780c08d20cfe9e2d767ee952970941398f8bea59a966772b1d89f19693cfff5faba22ba39ef7982ac46257180d557d3cbf3f7e65dd835d1d351e679a841b904a3cf24a0323aac0bb89705777507c76f57663b6d846e995a63057ceb48053ddf9282a366d6dc6cbdceb2ebcb3b374c7dc49da160cba8a3656211b8597a39ef9b8cc44d0c5735f870679ffcb1cb9321bbfbc307844d3174ef5dc144a951071340f4d156bead21fd3d9bd4641afa5851512264b4eed228b5d6324de428b00cbb89a1a88cb138d59de0b4ad75f2196e0e7ba890203010001");
</ins><span class="cx">
</span><span class="cx"> // Jwk: Wrong usages
</span><span class="cx"> shouldReject('crypto.subtle.importKey("jwk", {kty: "RSA", n: n, e: e}, "RSAES-PKCS1-v1_5", extractable, ["decrypt"])');
</span><span class="lines">@@ -64,6 +65,10 @@
</span><span class="cx"> 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"])');
</span><span class="cx"> 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"])');
</span><span class="cx"> 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"])');
</span><ins>+// 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"])');
</ins><span class="cx"> </script>
</span><span class="cx">
</span><span class="cx"> <script src="../../resources/js-test-post.js"></script>
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportspkikeyexportjwkkeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportspkikeyexportjwkkeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-jwk-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportspkikeyexportspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportspkikeyexportspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-key-export-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportspkismallkeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaimportspkismallkeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-import-spki-small-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaoaepgenerateexportkeyspkiexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-generate-export-key-spki-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaoaepgenerateexportkeyspkihtmlfromrev209436trunkLayoutTestscryptosubtlersaexportkeymalformedparametershtml"></a>
<div class="copfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a RSA-OAEP 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaoaepimportspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaoaepimportspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-oaep-import-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaespkcs1v1_5generateexportkeyspkiexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaespkcs1v1_5generateexportkeyspkihtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a RSAES-PKCS1-v1_5 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaespkcs1v1_5importspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaespkcs1v1_5importspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersassapkcs1v1_5generateexportkeyspkiexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersassapkcs1v1_5generateexportkeyspkihtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a RSASSA-PKCS1-v1_5 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersassapkcs1v1_5importspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersassapkcs1v1_5importspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a 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="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptoworkerssubtleresourcesrsaexportspkikeyjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/workers/subtle/resources/rsa-export-spki-key.js (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+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();
+});
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestscryptoworkerssubtleresourcesrsaimportspkikeyjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/workers/subtle/resources/rsa-import-spki-key.js (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,27 @@
</span><ins>+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();
+});
</ins></span></pre></div>
<a id="trunkLayoutTestscryptoworkerssubtlersaexportspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+[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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptoworkerssubtlersaexportspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/workers/subtle/rsa-export-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+ <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+ <script>
+ worker = startWorker('resources/rsa-export-spki-key.js');
+ </script>
+ <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestscryptoworkerssubtlersaimportspkikeyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key-expected.txt (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+[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
+
</ins></span></pre></div>
<a id="trunkLayoutTestscryptoworkerssubtlersaimportspkikeyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/workers/subtle/rsa-import-spki-key.html (0 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+ <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+ <script>
+ worker = startWorker('resources/rsa-import-spki-key.js');
+ </script>
+ <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-12-05 Jiewen Tan <jiewen_tan@apple.com>
+
+ [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:
+
</ins><span class="cx"> 2016-12-01 Jiewen Tan <jiewen_tan@apple.com>
</span><span class="cx">
</span><span class="cx"> Update SubtleCrypto::unwrapKey to match the latest spec
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cWebCryptoAPIencrypt_decrypttest_rsa_oaepexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -97,16 +97,16 @@
</span><span class="cx"> 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
</span><span class="cx"> 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
</span><span class="cx"> 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
</span><del>-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
</del><ins>+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
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2016-12-05 Jiewen Tan <jiewen_tan@apple.com>
+
+ [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):
+
</ins><span class="cx"> 2016-12-06 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix editing text flakiness introduced in r209411
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSSubtleCryptoCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -341,10 +341,10 @@
</span><span class="cx">
</span><span class="cx"> KeyData result;
</span><span class="cx"> switch (format) {
</span><del>- case SubtleCrypto::KeyFormat::Spki:
</del><span class="cx"> case SubtleCrypto::KeyFormat::Pkcs8:
</span><span class="cx"> setDOMException(&state, NOT_SUPPORTED_ERR);
</span><span class="cx"> return result;
</span><ins>+ case SubtleCrypto::KeyFormat::Spki:
</ins><span class="cx"> case SubtleCrypto::KeyFormat::Raw: {
</span><span class="cx"> BufferSource bufferSource = convert<IDLBufferSource>(state, value);
</span><span class="cx"> RETURN_IF_EXCEPTION(scope, result);
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoCommonCryptoUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/CommonCryptoUtilities.h (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -82,6 +82,8 @@
</span><span class="cx"> 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);
</span><span class="cx"> extern "C" CCRSAKeyType CCRSAGetKeyType(CCRSACryptorRef key);
</span><span class="cx"> 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);
</span><ins>+extern "C" CCCryptorStatus CCRSACryptorImport(const void *keyPackage, size_t keyPackageLen, CCRSACryptorRef *key);
+extern "C" CCCryptorStatus CCRSACryptorExport(CCRSACryptorRef key, void *out, size_t *outLen);
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoalgorithmsCryptoAlgorithmRSAES_PKCS1_v1_5cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -120,6 +120,14 @@
</span><span class="cx"> result = CryptoKeyRSA::importJwk(parameters->identifier, std::nullopt, WTFMove(key), extractable, usages);
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ 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;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> exceptionCallback(NOT_SUPPORTED_ERR);
</span><span class="cx"> return;
</span><span class="lines">@@ -149,6 +157,15 @@
</span><span class="cx"> result = WTFMove(jwk);
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ case SubtleCrypto::KeyFormat::Spki: {
+ auto spki = rsaKey.exportSpki();
+ if (spki.hasException()) {
+ exceptionCallback(spki.releaseException().code());
+ return;
+ }
+ result = spki.releaseReturnValue();
+ break;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> exceptionCallback(NOT_SUPPORTED_ERR);
</span><span class="cx"> return;
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoalgorithmsCryptoAlgorithmRSASSA_PKCS1_v1_5cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -153,6 +153,15 @@
</span><span class="cx"> result = CryptoKeyRSA::importJwk(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(key), extractable, usages);
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ 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;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> exceptionCallback(NOT_SUPPORTED_ERR);
</span><span class="cx"> return;
</span><span class="lines">@@ -200,6 +209,15 @@
</span><span class="cx"> result = WTFMove(jwk);
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ case SubtleCrypto::KeyFormat::Spki: {
+ auto spki = rsaKey.exportSpki();
+ if (spki.hasException()) {
+ exceptionCallback(spki.releaseException().code());
+ return;
+ }
+ result = spki.releaseReturnValue();
+ break;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> exceptionCallback(NOT_SUPPORTED_ERR);
</span><span class="cx"> return;
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoalgorithmsCryptoAlgorithmRSA_OAEPcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -166,6 +166,15 @@
</span><span class="cx"> result = CryptoKeyRSA::importJwk(rsaParameters.identifier, rsaParameters.hashIdentifier, WTFMove(key), extractable, usages);
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ 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;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> exceptionCallback(NOT_SUPPORTED_ERR);
</span><span class="cx"> return;
</span><span class="lines">@@ -213,6 +222,16 @@
</span><span class="cx"> result = WTFMove(jwk);
</span><span class="cx"> break;
</span><span class="cx"> }
</span><ins>+ 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;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> exceptionCallback(NOT_SUPPORTED_ERR);
</span><span class="cx"> return;
</span></span></pre></div>
<a id="trunkSourceWebCorecryptognutlsCryptoKeyRSAGnuTLScpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "CryptoAlgorithmRegistry.h"
</span><span class="cx"> #include "CryptoKeyDataRSAComponents.h"
</span><span class="cx"> #include "CryptoKeyPair.h"
</span><ins>+#include "ExceptionCode.h"
</ins><span class="cx"> #include "NotImplemented.h"
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -111,6 +112,20 @@
</span><span class="cx"> UNUSED_PARAM(context);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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 };
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(SUBTLE_CRYPTO)
</span></span></pre></div>
<a id="trunkSourceWebCorecryptokeysCryptoKeyRSAh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx">
</span><span class="cx"> #include "CryptoKey.h"
</span><ins>+#include "ExceptionOr.h"
</ins><span class="cx"> #include <wtf/Function.h>
</span><span class="cx">
</span><span class="cx"> #if ENABLE(SUBTLE_CRYPTO)
</span><span class="lines">@@ -101,9 +102,11 @@
</span><span class="cx"> using VoidCallback = WTF::Function<void()>;
</span><span class="cx"> static void generatePair(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsageBitmap, KeyPairCallback&&, VoidCallback&& failureCallback, ScriptExecutionContext*);
</span><span class="cx"> static RefPtr<CryptoKeyRSA> importJwk(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier> hash, JsonWebKey&&, bool extractable, CryptoKeyUsageBitmap);
</span><ins>+ static RefPtr<CryptoKeyRSA> importSpki(CryptoAlgorithmIdentifier, std::optional<CryptoAlgorithmIdentifier> hash, Vector<uint8_t>&&, bool extractable, CryptoKeyUsageBitmap);
</ins><span class="cx">
</span><span class="cx"> PlatformRSAKey platformKey() const { return m_platformKey; }
</span><span class="cx"> JsonWebKey exportJwk() const;
</span><ins>+ ExceptionOr<Vector<uint8_t>> exportSpki() const;
</ins><span class="cx">
</span><span class="cx"> CryptoAlgorithmIdentifier hashAlgorithmIdentifier() const { return m_hash; }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorecryptomacCryptoKeyRSAMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp (209436 => 209437)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,11 +32,19 @@
</span><span class="cx"> #include "CryptoAlgorithmRegistry.h"
</span><span class="cx"> #include "CryptoKeyDataRSAComponents.h"
</span><span class="cx"> #include "CryptoKeyPair.h"
</span><ins>+#include "ExceptionCode.h"
</ins><span class="cx"> #include "ScriptExecutionContext.h"
</span><span class="cx"> #include <wtf/MainThread.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><ins>+// 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;
+
</ins><span class="cx"> // FIXME: We should get rid of magic number 16384. It assumes that the length of provided key will not exceed 16KB.
</span><span class="cx"> // https://bugs.webkit.org/show_bug.cgi?id=164942
</span><span class="cx"> static CCCryptorStatus getPublicKeyComponents(CCRSACryptorRef rsaKey, Vector<uint8_t>& modulus, Vector<uint8_t>& publicExponent)
</span><span class="lines">@@ -235,6 +243,41 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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;
+ }
+}
+
</ins><span class="cx"> // FIXME: We should use WorkQueue here instead of dispatch_async once WebKitSubtleCrypto is deprecated.
</span><span class="cx"> // https://bugs.webkit.org/show_bug.cgi?id=164943
</span><span class="cx"> 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)
</span><span class="lines">@@ -280,6 +323,61 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(SUBTLE_CRYPTO)
</span></span></pre>
</div>
</div>
</body>
</html>