<!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>[163244] 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/163244">163244</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2014-02-01 10:14:17 -0800 (Sat, 01 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Update WebCrypto JWK mapping to use key_ops
https://bugs.webkit.org/show_bug.cgi?id=127609

Reviewed by Sam Weinig.

Source/WebCore:

Updated JWK support ot match current editor draft.

* bindings/js/JSCryptoKeySerializationJWK.cpp:
(WebCore::getJSArrayFromJSON): Fixed this previously untested function to actually work.
(WebCore::tryJWKKeyOpsValue):
(WebCore::JSCryptoKeySerializationJWK::reconcileUsages):
(WebCore::JSCryptoKeySerializationJWK::reconcileExtractable): Removed an old comment,
these things are now specced.
(WebCore::addToJSON): Made static functions file static, there is no reason for
them to be class members.
(WebCore::buildJSONForOctetSequence):
(WebCore::buildJSONForRSAComponents):
(WebCore::addBoolToJSON):
(WebCore::addJWKAlgorithmToJSON):
(WebCore::addUsagesToJSON):
(WebCore::JSCryptoKeySerializationJWK::serialize):
* bindings/js/JSCryptoKeySerializationJWK.h:

* crypto/mac/CryptoAlgorithmAES_KWMac.cpp:
(WebCore::CryptoAlgorithmAES_KW::platformEncrypt):
(WebCore::CryptoAlgorithmAES_KW::platformDecrypt):
Check for length, so that we don't fail silently.

LayoutTests:

* crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt:
* crypto/subtle/aes-kw-wrap-unwrap-aes.html:
Removed a subtest for wrapping JWK. That doesn't really work per the spec, because
JWK is arbitatry length, and AES-KW requires 8*n bytes.

* crypto/subtle/aes-export-key-expected.txt:
* crypto/subtle/aes-export-key.html:
* crypto/subtle/hmac-export-key-expected.txt:
* crypto/subtle/hmac-export-key.html:
* crypto/subtle/jwk-export-use-values-expected.txt:
* crypto/subtle/jwk-export-use-values.html:
* crypto/subtle/jwk-import-use-values-expected.txt:
* crypto/subtle/jwk-import-use-values.html:
* crypto/subtle/rsa-export-key-expected.txt:
* crypto/subtle/rsa-export-key.html:
* crypto/subtle/rsa-export-private-key-expected.txt:
* crypto/subtle/rsa-export-private-key.html:
* crypto/subtle/rsa-oaep-key-manipulation-expected.txt:
* crypto/subtle/rsa-oaep-key-manipulation.html:
* crypto/subtle/rsa-postMessage-expected.txt:
* crypto/subtle/rsa-postMessage.html:
Updated for the fix.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestscryptosubtleaesexportkeyexpectedtxt">trunk/LayoutTests/crypto/subtle/aes-export-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtleaesexportkeyhtml">trunk/LayoutTests/crypto/subtle/aes-export-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtleaeskwwrapunwrapaesexpectedtxt">trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtleaeskwwrapunwrapaeshtml">trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlehmacexportkeyexpectedtxt">trunk/LayoutTests/crypto/subtle/hmac-export-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlehmacexportkeyhtml">trunk/LayoutTests/crypto/subtle/hmac-export-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlejwkexportusevaluesexpectedtxt">trunk/LayoutTests/crypto/subtle/jwk-export-use-values-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlejwkexportusevalueshtml">trunk/LayoutTests/crypto/subtle/jwk-export-use-values.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlejwkimportusevaluesexpectedtxt">trunk/LayoutTests/crypto/subtle/jwk-import-use-values-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlejwkimportusevalueshtml">trunk/LayoutTests/crypto/subtle/jwk-import-use-values.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaexportkeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-export-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaexportkeyhtml">trunk/LayoutTests/crypto/subtle/rsa-export-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaexportprivatekeyexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-export-private-key-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaexportprivatekeyhtml">trunk/LayoutTests/crypto/subtle/rsa-export-private-key.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaoaepkeymanipulationexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaoaepkeymanipulationhtml">trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation.html</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersapostMessageexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-postMessage-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersapostMessagehtml">trunk/LayoutTests/crypto/subtle/rsa-postMessage.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSCryptoKeySerializationJWKcpp">trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSCryptoKeySerializationJWKh">trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h</a></li>
<li><a href="#trunkSourceWebCorecryptomacCryptoAlgorithmAES_KWMaccpp">trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_KWMac.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/ChangeLog        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2014-02-01  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Update WebCrypto JWK mapping to use key_ops
+        https://bugs.webkit.org/show_bug.cgi?id=127609
+
+        Reviewed by Sam Weinig.
+
+        * crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt:
+        * crypto/subtle/aes-kw-wrap-unwrap-aes.html:
+        Removed a subtest for wrapping JWK. That doesn't really work per the spec, because
+        JWK is arbitatry length, and AES-KW requires 8*n bytes.
+
+        * crypto/subtle/aes-export-key-expected.txt:
+        * crypto/subtle/aes-export-key.html:
+        * crypto/subtle/hmac-export-key-expected.txt:
+        * crypto/subtle/hmac-export-key.html:
+        * crypto/subtle/jwk-export-use-values-expected.txt:
+        * crypto/subtle/jwk-export-use-values.html:
+        * crypto/subtle/jwk-import-use-values-expected.txt:
+        * crypto/subtle/jwk-import-use-values.html:
+        * crypto/subtle/rsa-export-key-expected.txt:
+        * crypto/subtle/rsa-export-key.html:
+        * crypto/subtle/rsa-export-private-key-expected.txt:
+        * crypto/subtle/rsa-export-private-key.html:
+        * crypto/subtle/rsa-oaep-key-manipulation-expected.txt:
+        * crypto/subtle/rsa-oaep-key-manipulation.html:
+        * crypto/subtle/rsa-postMessage-expected.txt:
+        * crypto/subtle/rsa-postMessage.html:
+        Updated for the fix.
+
</ins><span class="cx"> 2014-02-01  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Improve the JavaScript bindings of DatasetDOMStringMap
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtleaesexportkeyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/aes-export-key-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/aes-export-key-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/aes-export-key-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -23,7 +23,8 @@
</span><span class="cx"> PASS exportedJWK.k is 'jnOw99oOZFLIEPMrgJB55WL46tJSLGt7'
</span><span class="cx"> PASS exportedJWK.alg is 'A192CBC'
</span><span class="cx"> PASS exportedJWK.ext is true
</span><del>-PASS exportedJWK.use is 'enc'
</del><ins>+PASS exportedJWK.use is undefined
+PASS exportedJWK.key_ops is ['encrypt', 'decrypt', 'wrap', 'unwrap']
</ins><span class="cx"> 
</span><span class="cx"> Importing a key that's not extractable...
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtleaesexportkeyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/aes-export-key.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/aes-export-key.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/aes-export-key.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -53,7 +53,8 @@
</span><span class="cx">     shouldBe(&quot;exportedJWK.k&quot;, &quot;'jnOw99oOZFLIEPMrgJB55WL46tJSLGt7'&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.alg&quot;, &quot;'A192CBC'&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.ext&quot;, &quot;true&quot;);
</span><del>-    shouldBe(&quot;exportedJWK.use&quot;, &quot;'enc'&quot;);
</del><ins>+    shouldBe(&quot;exportedJWK.use&quot;, &quot;undefined&quot;);
+    shouldBe(&quot;exportedJWK.key_ops&quot;, &quot;['encrypt', 'decrypt', 'wrap', 'unwrap']&quot;);
</ins><span class="cx"> 
</span><span class="cx">     debug(&quot;\nImporting a key that's not extractable...&quot;);
</span><span class="cx">     return crypto.subtle.importKey(&quot;jwk&quot;, jwkKeyAsArrayBuffer, &quot;AES-CBC&quot;, nonExtractable, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtleaeskwwrapunwrapaesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -16,17 +16,6 @@
</span><span class="cx"> PASS unwrappedKey.usages is ['decrypt', 'encrypt', 'unwrapKey', 'wrapKey']
</span><span class="cx"> Exporting it...
</span><span class="cx"> PASS bytesToHexString(unwrappedKeyData) is bytesToHexString(keyData)
</span><del>-
-Wrapping it as JWK...
-Unwrapping it...
-PASS unwrappedKey.toString() is '[object Key]'
-PASS unwrappedKey.type is 'secret'
-PASS unwrappedKey.extractable is true
-PASS unwrappedKey.algorithm.name is 'AES-CBC'
-PASS unwrappedKey.algorithm.length is 128
-PASS unwrappedKey.usages is ['decrypt', 'encrypt', 'unwrapKey', 'wrapKey']
-Exporting it...
-PASS bytesToHexString(unwrappedKeyData) is bytesToHexString(keyData)
</del><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtleaeskwwrapunwrapaeshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/aes-kw-wrap-unwrap-aes.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -49,28 +49,6 @@
</span><span class="cx">     unwrappedKeyData = result;
</span><span class="cx">     shouldBe(&quot;bytesToHexString(unwrappedKeyData)&quot;, &quot;bytesToHexString(keyData)&quot;);
</span><span class="cx"> 
</span><del>-    debug(&quot;\nWrapping it as JWK...&quot;);
-    return crypto.subtle.wrapKey(&quot;jwk&quot;, key, kek, &quot;aes-kw&quot;);
-}).then(function(result) {
-    wrappedKey = result;
-
-    debug(&quot;Unwrapping it...&quot;);
-    return crypto.subtle.unwrapKey(&quot;jwk&quot;, wrappedKey, kek, &quot;aes-kw&quot;, &quot;aes-cbc&quot;, extractable, [&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrapKey&quot;, &quot;unwrapKey&quot;]);
-}).then(function(result) {
-    unwrappedKey = result;
-    shouldBe(&quot;unwrappedKey.toString()&quot;, &quot;'[object Key]'&quot;);
-    shouldBe(&quot;unwrappedKey.type&quot;, &quot;'secret'&quot;);
-    shouldBe(&quot;unwrappedKey.extractable&quot;, &quot;true&quot;);
-    shouldBe(&quot;unwrappedKey.algorithm.name&quot;, &quot;'AES-CBC'&quot;);
-    shouldBe(&quot;unwrappedKey.algorithm.length&quot;, &quot;128&quot;);
-    shouldBe(&quot;unwrappedKey.usages&quot;, &quot;['decrypt', 'encrypt', 'unwrapKey', 'wrapKey']&quot;);
-
-    debug(&quot;Exporting it...&quot;);
-    return crypto.subtle.exportKey(&quot;raw&quot;, unwrappedKey);
-}).then(function(result) {
-    unwrappedKeyData = result;
-    shouldBe(&quot;bytesToHexString(unwrappedKeyData)&quot;, &quot;bytesToHexString(keyData)&quot;);
-
</del><span class="cx">     finishJSTest();
</span><span class="cx"> });
</span><span class="cx"> &lt;/script&gt;
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlehmacexportkeyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/hmac-export-key-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/hmac-export-key-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/hmac-export-key-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -16,7 +16,8 @@
</span><span class="cx"> PASS exportedJWK.k is 'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'
</span><span class="cx"> PASS exportedJWK.alg is 'HS256'
</span><span class="cx"> PASS exportedJWK.ext is true
</span><del>-PASS exportedJWK.use is 'sig'
</del><ins>+PASS exportedJWK.use is undefined
+PASS exportedJWK.key_ops is ['sign', 'verify']
</ins><span class="cx"> 
</span><span class="cx"> Importing a key that's not extractable...
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlehmacexportkeyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/hmac-export-key.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/hmac-export-key.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/hmac-export-key.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -47,7 +47,8 @@
</span><span class="cx">     shouldBe(&quot;exportedJWK.k&quot;, &quot;'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.alg&quot;, &quot;'HS256'&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.ext&quot;, &quot;true&quot;);
</span><del>-    shouldBe(&quot;exportedJWK.use&quot;, &quot;'sig'&quot;);
</del><ins>+    shouldBe(&quot;exportedJWK.use&quot;, &quot;undefined&quot;);
+    shouldBe(&quot;exportedJWK.key_ops&quot;, &quot;['sign', 'verify']&quot;);
</ins><span class="cx"> 
</span><span class="cx">     debug(&quot;\nImporting a key that's not extractable...&quot;);
</span><span class="cx">     return crypto.subtle.importKey(&quot;jwk&quot;, jwkKeyAsArrayBuffer, { name: &quot;HMAC&quot;, hash: &quot;SHA-256&quot; }, nonExtractable, [&quot;sign&quot;, &quot;verify&quot;]);
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlejwkexportusevaluesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/jwk-export-use-values-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/jwk-export-use-values-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/jwk-export-use-values-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -4,37 +4,48 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> encrypt:
</span><del>-PASS jwk.use is 'enconly'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;encrypt&quot;]
</ins><span class="cx"> 
</span><span class="cx"> decrypt:
</span><del>-PASS jwk.use is 'deconly'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;decrypt&quot;]
</ins><span class="cx"> 
</span><span class="cx"> encrypt,decrypt:
</span><del>-PASS jwk.use is 'enconly,deconly'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;encrypt&quot;,&quot;decrypt&quot;]
</ins><span class="cx"> 
</span><span class="cx"> wrapKey:
</span><del>-PASS jwk.use is 'wrap'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;wrap&quot;]
</ins><span class="cx"> 
</span><span class="cx"> unwrapKey:
</span><del>-PASS jwk.use is 'unwrap'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;unwrap&quot;]
</ins><span class="cx"> 
</span><span class="cx"> wrapKey,unwrapKey:
</span><del>-PASS jwk.use is 'wrap,unwrap'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;wrap&quot;,&quot;unwrap&quot;]
</ins><span class="cx"> 
</span><span class="cx"> encrypt,decrypt,wrapKey:
</span><del>-PASS jwk.use is 'enconly,deconly,wrap'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;encrypt&quot;,&quot;decrypt&quot;,&quot;wrap&quot;]
</ins><span class="cx"> 
</span><span class="cx"> encrypt,decrypt,wrapKey,unwrapKey:
</span><del>-PASS jwk.use is 'enc'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;encrypt&quot;,&quot;decrypt&quot;,&quot;wrap&quot;,&quot;unwrap&quot;]
</ins><span class="cx"> 
</span><span class="cx"> sign:
</span><del>-PASS jwk.use is 'sigonly'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;sign&quot;]
</ins><span class="cx"> 
</span><span class="cx"> verify:
</span><del>-PASS jwk.use is 'vfyonly'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;verify&quot;]
</ins><span class="cx"> 
</span><span class="cx"> sign,verify:
</span><del>-PASS jwk.use is 'sig'
</del><ins>+PASS jwk.use is undefined
+PASS jwk.key_ops is [&quot;sign&quot;,&quot;verify&quot;]
</ins><span class="cx"> 
</span><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlejwkexportusevalueshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/jwk-export-use-values.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/jwk-export-use-values.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/jwk-export-use-values.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -18,42 +18,44 @@
</span><span class="cx"> var aesKeyAsArrayBuffer = Base64URL.parse(&quot;jnOw99oOZFLIEPMrgJB55WL46tJSLGt7&quot;);
</span><span class="cx"> var hmacKeyAsArrayBuffer = Base64URL.parse(&quot;ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs&quot;);
</span><span class="cx"> 
</span><del>-function testWithAESCBC(usages, expectedUse)
</del><ins>+function testWithAESCBC(usages, expectedKeyOps)
</ins><span class="cx"> {
</span><span class="cx">     return crypto.subtle.importKey(&quot;raw&quot;, aesKeyAsArrayBuffer, &quot;AES-CBC&quot;, extractable, usages).then(function(result) {
</span><span class="cx">         return crypto.subtle.exportKey(&quot;jwk&quot;, result);
</span><span class="cx">     }).then(function(result) {
</span><span class="cx">         jwk = JSON.parse(bytesToASCIIString(result));
</span><span class="cx">         debug(usages + &quot;:&quot;);
</span><del>-        shouldBe(&quot;jwk.use&quot;, &quot;'&quot; + expectedUse + &quot;'&quot;);
</del><ins>+        shouldBe(&quot;jwk.use&quot;, &quot;undefined&quot;);
+        shouldBe(&quot;jwk.key_ops&quot;, JSON.stringify(expectedKeyOps));
</ins><span class="cx">         debug(&quot;&quot;);
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function testWithHMAC(usages, expectedUse)
</del><ins>+function testWithHMAC(usages, expectedKeyOps)
</ins><span class="cx"> {
</span><span class="cx">     return crypto.subtle.importKey(&quot;raw&quot;, hmacKeyAsArrayBuffer, {name: 'hmac', hash: {name: 'sha-256'}}, extractable, usages).then(function(result) {
</span><span class="cx">         return crypto.subtle.exportKey(&quot;jwk&quot;, result);
</span><span class="cx">     }).then(function(result) {
</span><span class="cx">         jwk = JSON.parse(bytesToASCIIString(result));
</span><span class="cx">         debug(usages + &quot;:&quot;);
</span><del>-        shouldBe(&quot;jwk.use&quot;, &quot;'&quot; + expectedUse + &quot;'&quot;);
</del><ins>+        shouldBe(&quot;jwk.use&quot;, &quot;undefined&quot;);
+        shouldBe(&quot;jwk.key_ops&quot;, JSON.stringify(expectedKeyOps));
</ins><span class="cx">         debug(&quot;&quot;);
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Promise.all([
</span><del>-    testWithAESCBC([&quot;encrypt&quot;], &quot;enconly&quot;),
-    testWithAESCBC([&quot;decrypt&quot;], &quot;deconly&quot;),
-    testWithAESCBC([&quot;encrypt&quot;, &quot;decrypt&quot;], &quot;enconly,deconly&quot;),
-    testWithAESCBC([&quot;wrapKey&quot;], &quot;wrap&quot;),
-    testWithAESCBC([&quot;unwrapKey&quot;], &quot;unwrap&quot;),
-    testWithAESCBC([&quot;wrapKey&quot;, &quot;unwrapKey&quot;], &quot;wrap,unwrap&quot;),
-    testWithAESCBC([&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrapKey&quot;], &quot;enconly,deconly,wrap&quot;),
-    testWithAESCBC([&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrapKey&quot;, &quot;unwrapKey&quot;], &quot;enc&quot;),
-    testWithHMAC([&quot;sign&quot;], &quot;sigonly&quot;),
-    testWithHMAC([&quot;verify&quot;], &quot;vfyonly&quot;),
-    testWithHMAC([&quot;sign&quot;, &quot;verify&quot;], &quot;sig&quot;),
</del><ins>+    testWithAESCBC([&quot;encrypt&quot;], [&quot;encrypt&quot;]),
+    testWithAESCBC([&quot;decrypt&quot;], [&quot;decrypt&quot;]),
+    testWithAESCBC([&quot;encrypt&quot;, &quot;decrypt&quot;], [&quot;encrypt&quot;, &quot;decrypt&quot;]),
+    testWithAESCBC([&quot;wrapKey&quot;], [&quot;wrap&quot;]),
+    testWithAESCBC([&quot;unwrapKey&quot;], [&quot;unwrap&quot;]),
+    testWithAESCBC([&quot;wrapKey&quot;, &quot;unwrapKey&quot;], [&quot;wrap&quot;, &quot;unwrap&quot;]),
+    testWithAESCBC([&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrapKey&quot;], [&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrap&quot;]),
+    testWithAESCBC([&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrapKey&quot;, &quot;unwrapKey&quot;], [&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrap&quot;, &quot;unwrap&quot;]),
+    testWithHMAC([&quot;sign&quot;], [&quot;sign&quot;]),
+    testWithHMAC([&quot;verify&quot;], [&quot;verify&quot;]),
+    testWithHMAC([&quot;sign&quot;, &quot;verify&quot;], [&quot;sign&quot;, &quot;verify&quot;]),
</ins><span class="cx"> ]).then(function() { finishJSTest(); } );
</span><span class="cx"> &lt;/script&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlejwkimportusevaluesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/jwk-import-use-values-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/jwk-import-use-values-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/jwk-import-use-values-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -3,54 +3,50 @@
</span><span class="cx"> On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-enconly:
</del><ins>+PASS testWithAESCBC([&quot;encrypt&quot;], {key_ops: [&quot;encrypt&quot;, &quot;encrypt&quot;]}) threw exception TypeError: JWK key_ops contains a duplicate operation.
+
+{&quot;key_ops&quot;:[&quot;encrypt&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;encrypt&quot;]
</span><span class="cx"> 
</span><del>-deconly:
</del><ins>+{&quot;key_ops&quot;:[&quot;decrypt&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;decrypt&quot;]
</span><span class="cx"> 
</span><del>-enconly,deconly:
</del><ins>+{&quot;key_ops&quot;:[&quot;encrypt&quot;,&quot;decrypt&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;decrypt&quot;,&quot;encrypt&quot;]
</span><span class="cx"> 
</span><del>-wrap:
</del><ins>+{&quot;key_ops&quot;:[&quot;wrap&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;wrapKey&quot;]
</span><span class="cx"> 
</span><del>-unwrap:
</del><ins>+{&quot;key_ops&quot;:[&quot;unwrap&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;unwrapKey&quot;]
</span><span class="cx"> 
</span><del>-wrap,unwrap:
</del><ins>+{&quot;key_ops&quot;:[&quot;wrap&quot;,&quot;unwrap&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;unwrapKey&quot;,&quot;wrapKey&quot;]
</span><span class="cx"> 
</span><del>-enconly,deconly,wrap:
</del><ins>+{&quot;key_ops&quot;:[&quot;encrypt&quot;,&quot;decrypt&quot;,&quot;wrap&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;decrypt&quot;,&quot;encrypt&quot;,&quot;wrapKey&quot;]
</span><span class="cx"> 
</span><del>-enc:
</del><ins>+{&quot;use&quot;:&quot;enc&quot;}:
</ins><span class="cx"> PASS key.usages is [&quot;decrypt&quot;,&quot;encrypt&quot;,&quot;unwrapKey&quot;,&quot;wrapKey&quot;]
</span><span class="cx"> 
</span><del>-sigonly:
</del><ins>+{&quot;key_ops&quot;:[&quot;sign&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;sign&quot;]
</span><span class="cx"> 
</span><del>-vfyonly:
</del><ins>+{&quot;key_ops&quot;:[&quot;verify&quot;]}:
</ins><span class="cx"> PASS key.usages is [&quot;verify&quot;]
</span><span class="cx"> 
</span><del>-sig:
</del><ins>+{&quot;use&quot;:&quot;sig&quot;}:
</ins><span class="cx"> PASS key.usages is [&quot;sign&quot;,&quot;verify&quot;]
</span><span class="cx"> 
</span><del>-'enconly':
</del><ins>+{&quot;key_ops&quot;:[&quot;'encrypt'&quot;]}:
</ins><span class="cx"> PASS key.usages is []
</span><span class="cx"> 
</span><del>-enconly :
</del><ins>+{&quot;key_ops&quot;:[&quot;encrypt &quot;]}:
</ins><span class="cx"> PASS key.usages is []
</span><span class="cx"> 
</span><del>-EncOnly:
</del><ins>+{&quot;key_ops&quot;:[&quot;Encrypt&quot;]}:
</ins><span class="cx"> PASS key.usages is []
</span><span class="cx"> 
</span><del>-enconly, deconly:
-PASS key.usages is [&quot;encrypt&quot;]
-
-enconly,,deconly:
-PASS key.usages is [&quot;decrypt&quot;,&quot;encrypt&quot;]
-
</del><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlejwkimportusevalueshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/jwk-import-use-values.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/jwk-import-use-values.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/jwk-import-use-values.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -29,47 +29,63 @@
</span><span class="cx">     &quot;k&quot;: &quot;ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs&quot;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-function testWithAESCBC(expectedUsages, use)
</del><ins>+function testWithAESCBC(expectedUsages, jwkUsages)
</ins><span class="cx"> {
</span><del>-    aesKeyAsJSON.use = use;
</del><ins>+    if (jwkUsages.key_ops) {
+        aesKeyAsJSON.key_ops = jwkUsages.key_ops;
+        delete aesKeyAsJSON.use;
+    } else {
+        delete aesKeyAsJSON.key_ops;
+        aesKeyAsJSON.use = jwkUsages.use;
+    }
+
</ins><span class="cx">     return crypto.subtle.importKey(&quot;jwk&quot;, asciiToUint8Array(JSON.stringify(aesKeyAsJSON)), &quot;AES-CBC&quot;, extractable, [&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrapKey&quot;, &quot;unwrapKey&quot;]).then(function(result) {
</span><span class="cx">         key = result;
</span><del>-        debug(use + &quot;:&quot;);
</del><ins>+        debug(JSON.stringify(jwkUsages) + &quot;:&quot;);
</ins><span class="cx">         shouldBe(&quot;key.usages&quot;, JSON.stringify(expectedUsages));
</span><span class="cx">         debug(&quot;&quot;);
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function testWithHMAC(expectedUsages, use)
</del><ins>+function testWithHMAC(expectedUsages, jwkUsages)
</ins><span class="cx"> {
</span><del>-    hmacKeyAsJSON.use = use;
</del><ins>+    if (jwkUsages.key_ops) {
+        hmacKeyAsJSON.key_ops = jwkUsages.key_ops;
+        delete hmacKeyAsJSON.use;
+    } else {
+        delete hmacKeyAsJSON.key_ops;
+        hmacKeyAsJSON.use = jwkUsages.use;
+    }
+
</ins><span class="cx">     return crypto.subtle.importKey(&quot;jwk&quot;, asciiToUint8Array(JSON.stringify(hmacKeyAsJSON)), {name: 'hmac', hash: {name: 'sha-256'}}, extractable, [&quot;sign&quot;, &quot;verify&quot;]).then(function(result) {
</span><span class="cx">         key = result;
</span><del>-        debug(use + &quot;:&quot;);
</del><ins>+        debug(JSON.stringify(jwkUsages) + &quot;:&quot;);
</ins><span class="cx">         shouldBe(&quot;key.usages&quot;, JSON.stringify(expectedUsages));
</span><span class="cx">         debug(&quot;&quot;);
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// Duplicates are not allowed. We currently raise an exception, although we should reject the promise instead.
+shouldThrow('testWithAESCBC([&quot;encrypt&quot;], {key_ops: [&quot;encrypt&quot;, &quot;encrypt&quot;]})');
+debug(&quot;&quot;);
+
</ins><span class="cx"> Promise.all([
</span><del>-    testWithAESCBC([&quot;encrypt&quot;], &quot;enconly&quot;),
-    testWithAESCBC([&quot;decrypt&quot;], &quot;deconly&quot;),
-    testWithAESCBC([&quot;decrypt&quot;, &quot;encrypt&quot;], &quot;enconly,deconly&quot;),
-    testWithAESCBC([&quot;wrapKey&quot;], &quot;wrap&quot;),
-    testWithAESCBC([&quot;unwrapKey&quot;], &quot;unwrap&quot;),
-    testWithAESCBC([&quot;unwrapKey&quot;, &quot;wrapKey&quot;], &quot;wrap,unwrap&quot;),
-    testWithAESCBC([&quot;decrypt&quot;, &quot;encrypt&quot;, &quot;wrapKey&quot;], &quot;enconly,deconly,wrap&quot;),
-    testWithAESCBC([&quot;decrypt&quot;, &quot;encrypt&quot;, &quot;unwrapKey&quot;, &quot;wrapKey&quot;], &quot;enc&quot;),
-    testWithHMAC([&quot;sign&quot;], &quot;sigonly&quot;),
-    testWithHMAC([&quot;verify&quot;], &quot;vfyonly&quot;),
-    testWithHMAC([&quot;sign&quot;, &quot;verify&quot;], &quot;sig&quot;),
</del><ins>+    testWithAESCBC([&quot;encrypt&quot;], {key_ops: [&quot;encrypt&quot;]}),
+    testWithAESCBC([&quot;decrypt&quot;], {key_ops: [&quot;decrypt&quot;]}),
+    testWithAESCBC([&quot;decrypt&quot;, &quot;encrypt&quot;], {key_ops: [&quot;encrypt&quot;, &quot;decrypt&quot;]}),
+    testWithAESCBC([&quot;wrapKey&quot;], {key_ops: [&quot;wrap&quot;]}),
+    testWithAESCBC([&quot;unwrapKey&quot;], {key_ops: [&quot;unwrap&quot;]}),
+    testWithAESCBC([&quot;unwrapKey&quot;, &quot;wrapKey&quot;], {key_ops: [&quot;wrap&quot;, &quot;unwrap&quot;]}),
+    testWithAESCBC([&quot;decrypt&quot;, &quot;encrypt&quot;, &quot;wrapKey&quot;], {key_ops: [&quot;encrypt&quot;, &quot;decrypt&quot;, &quot;wrap&quot;]}),
+    testWithAESCBC([&quot;decrypt&quot;, &quot;encrypt&quot;, &quot;unwrapKey&quot;, &quot;wrapKey&quot;], {use: &quot;enc&quot;}),
+    testWithHMAC([&quot;sign&quot;], {key_ops: [&quot;sign&quot;]}),
+    testWithHMAC([&quot;verify&quot;], {key_ops: [&quot;verify&quot;]}),
+    testWithHMAC([&quot;sign&quot;, &quot;verify&quot;], {use: &quot;sig&quot;}),
</ins><span class="cx"> 
</span><del>-// Incorrect use strings. There is currently no spec for what to do, but ignoring unknown uses seems right.
-    testWithAESCBC([], &quot;'enconly'&quot;),
-    testWithAESCBC([], &quot;enconly &quot;),
-    testWithAESCBC([], &quot;EncOnly&quot;),
-    testWithAESCBC([&quot;encrypt&quot;], &quot;enconly, deconly&quot;),
-    testWithAESCBC([&quot;decrypt&quot;,&quot;encrypt&quot;], &quot;enconly,,deconly&quot;),
</del><ins>+// Unknown key_ops strings are ignored.
+    testWithAESCBC([], {key_ops: [&quot;'encrypt'&quot;]}),
+    testWithAESCBC([], {key_ops: [&quot;encrypt &quot;]}),
+    testWithAESCBC([], {key_ops: [&quot;Encrypt&quot;]}),
</ins><span class="cx"> 
</span><span class="cx"> ]).then(function() { finishJSTest(); } );
</span><span class="cx"> &lt;/script&gt;
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaexportkeyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-export-key-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-export-key-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-export-key-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -17,7 +17,8 @@
</span><span class="cx"> PASS exportedJWK.e is publicKeyJSON.e
</span><span class="cx"> PASS exportedJWK.alg is 'RS256'
</span><span class="cx"> PASS exportedJWK.ext is true
</span><del>-PASS exportedJWK.use is 'sig'
</del><ins>+PASS exportedJWK.use is undefined
+PASS exportedJWK.key_ops is ['sign', 'verify']
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaexportkeyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-export-key.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-export-key.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-export-key.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -45,7 +45,8 @@
</span><span class="cx">     shouldBe(&quot;exportedJWK.e&quot;, &quot;publicKeyJSON.e&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.alg&quot;, &quot;'RS256'&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.ext&quot;, &quot;true&quot;);
</span><del>-    shouldBe(&quot;exportedJWK.use&quot;, &quot;'sig'&quot;);
</del><ins>+    shouldBe(&quot;exportedJWK.use&quot;, &quot;undefined&quot;);
+    shouldBe(&quot;exportedJWK.key_ops&quot;, &quot;['sign', 'verify']&quot;);
</ins><span class="cx"> 
</span><span class="cx">     finishJSTest();
</span><span class="cx"> });
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaexportprivatekeyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-export-private-key-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-export-private-key-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-export-private-key-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -19,7 +19,8 @@
</span><span class="cx"> PASS exportedJWK.oth is privateKeyJSON.oth
</span><span class="cx"> PASS exportedJWK.alg is privateKeyJSON.alg
</span><span class="cx"> PASS exportedJWK.ext is true
</span><del>-PASS exportedJWK.use is 'sig'
</del><ins>+PASS exportedJWK.key_ops is ['sign', 'verify']
+PASS exportedJWK.use is undefined
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaexportprivatekeyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-export-private-key.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-export-private-key.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-export-private-key.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -53,7 +53,8 @@
</span><span class="cx">     shouldBe(&quot;exportedJWK.oth&quot;, &quot;privateKeyJSON.oth&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.alg&quot;, &quot;privateKeyJSON.alg&quot;);
</span><span class="cx">     shouldBe(&quot;exportedJWK.ext&quot;, &quot;true&quot;);
</span><del>-    shouldBe(&quot;exportedJWK.use&quot;, &quot;'sig'&quot;);
</del><ins>+    shouldBe(&quot;exportedJWK.key_ops&quot;, &quot;['sign', 'verify']&quot;);
+    shouldBe(&quot;exportedJWK.use&quot;, &quot;undefined&quot;);
</ins><span class="cx"> 
</span><span class="cx">     finishJSTest();
</span><span class="cx"> });
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaoaepkeymanipulationexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -27,7 +27,8 @@
</span><span class="cx"> Exporting public key to JWK...
</span><span class="cx"> PASS jwkPublicKey.alg is 'RSA-OAEP'
</span><span class="cx"> PASS jwkPublicKey.ext is true
</span><del>-PASS jwkPublicKey.use is 'enc'
</del><ins>+PASS jwkPublicKey.key_ops is ['encrypt', 'decrypt', 'wrap', 'unwrap']
+PASS jwkPublicKey.use is undefined
</ins><span class="cx"> PASS jwkPublicKey.kty is 'RSA'
</span><span class="cx"> PASS bytesToHexString(Base64URL.parse(jwkPublicKey.e)) is '010001'
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaoaepkeymanipulationhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-oaep-key-manipulation.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -56,7 +56,8 @@
</span><span class="cx">     jwkPublicKey = JSON.parse(bytesToASCIIString(jwkPublicKeyArray));
</span><span class="cx">     shouldBe(&quot;jwkPublicKey.alg&quot;, &quot;'RSA-OAEP'&quot;);
</span><span class="cx">     shouldBe(&quot;jwkPublicKey.ext&quot;, &quot;true&quot;);
</span><del>-    shouldBe(&quot;jwkPublicKey.use&quot;, &quot;'enc'&quot;);
</del><ins>+    shouldBe(&quot;jwkPublicKey.key_ops&quot;, &quot;['encrypt', 'decrypt', 'wrap', 'unwrap']&quot;);
+    shouldBe(&quot;jwkPublicKey.use&quot;, &quot;undefined&quot;);
</ins><span class="cx">     shouldBe(&quot;jwkPublicKey.kty&quot;, &quot;'RSA'&quot;);
</span><span class="cx">     shouldBe(&quot;bytesToHexString(Base64URL.parse(jwkPublicKey.e))&quot;, &quot;'010001'&quot;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersapostMessageexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-postMessage-expected.txt (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-postMessage-expected.txt        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-postMessage-expected.txt        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -15,7 +15,8 @@
</span><span class="cx"> PASS exportedJWK.kty is 'RSA'
</span><span class="cx"> PASS exportedJWK.alg is 'RS256'
</span><span class="cx"> PASS exportedJWK.ext is true
</span><del>-PASS exportedJWK.use is 'sig'
</del><ins>+PASS exportedJWK.key_ops is ['sign','verify']
+PASS exportedJWK.use is undefined
</ins><span class="cx"> PASS exportedJWK.n is privateKeyJSON.n
</span><span class="cx"> PASS exportedJWK.e is privateKeyJSON.e
</span><span class="cx"> PASS exportedJWK.d is privateKeyJSON.d
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersapostMessagehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/crypto/subtle/rsa-postMessage.html (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-postMessage.html        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/LayoutTests/crypto/subtle/rsa-postMessage.html        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -41,7 +41,8 @@
</span><span class="cx">         shouldBe(&quot;exportedJWK.kty&quot;, &quot;'RSA'&quot;);
</span><span class="cx">         shouldBe(&quot;exportedJWK.alg&quot;, &quot;'RS256'&quot;);
</span><span class="cx">         shouldBe(&quot;exportedJWK.ext&quot;, &quot;true&quot;);
</span><del>-        shouldBe(&quot;exportedJWK.use&quot;, &quot;'sig'&quot;);
</del><ins>+        shouldBe(&quot;exportedJWK.key_ops&quot;, &quot;['sign','verify']&quot;);
+        shouldBe(&quot;exportedJWK.use&quot;, &quot;undefined&quot;);
</ins><span class="cx">         shouldBe(&quot;exportedJWK.n&quot;, &quot;privateKeyJSON.n&quot;);
</span><span class="cx">         shouldBe(&quot;exportedJWK.e&quot;, &quot;privateKeyJSON.e&quot;);
</span><span class="cx">         shouldBe(&quot;exportedJWK.d&quot;, &quot;privateKeyJSON.d&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/Source/WebCore/ChangeLog        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2014-02-01  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Update WebCrypto JWK mapping to use key_ops
+        https://bugs.webkit.org/show_bug.cgi?id=127609
+
+        Reviewed by Sam Weinig.
+
+        Updated JWK support ot match current editor draft.
+
+        * bindings/js/JSCryptoKeySerializationJWK.cpp:
+        (WebCore::getJSArrayFromJSON): Fixed this previously untested function to actually work.
+        (WebCore::tryJWKKeyOpsValue):
+        (WebCore::JSCryptoKeySerializationJWK::reconcileUsages):
+        (WebCore::JSCryptoKeySerializationJWK::reconcileExtractable): Removed an old comment,
+        these things are now specced.
+        (WebCore::addToJSON): Made static functions file static, there is no reason for
+        them to be class members.
+        (WebCore::buildJSONForOctetSequence):
+        (WebCore::buildJSONForRSAComponents):
+        (WebCore::addBoolToJSON):
+        (WebCore::addJWKAlgorithmToJSON):
+        (WebCore::addUsagesToJSON):
+        (WebCore::JSCryptoKeySerializationJWK::serialize):
+        * bindings/js/JSCryptoKeySerializationJWK.h:
+
+        * crypto/mac/CryptoAlgorithmAES_KWMac.cpp:
+        (WebCore::CryptoAlgorithmAES_KW::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_KW::platformDecrypt):
+        Check for length, so that we don't fail silently.
+
</ins><span class="cx"> 2014-02-01  David Kilzer  &lt;ddkilzer@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add security-checked casts for all WebCore::CachedResource subclasses
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSCryptoKeySerializationJWKcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -60,7 +60,7 @@
</span><span class="cx"> 
</span><span class="cx">     JSValue value = slot.getValue(exec, identifier);
</span><span class="cx">     ASSERT(!exec-&gt;hadException());
</span><del>-    if (isJSArray(value)) {
</del><ins>+    if (!isJSArray(value)) {
</ins><span class="cx">         throwTypeError(exec, String::format(&quot;Expected an array for \&quot;%s\&quot; JSON key&quot;,  key));
</span><span class="cx">         return false;
</span><span class="cx">     }
</span><span class="lines">@@ -248,40 +248,67 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCryptoKeySerializationJWK::reconcileUsages(CryptoKeyUsage&amp; suggestedUsages) const
</del><ins>+static bool tryJWKKeyOpsValue(ExecState* exec, CryptoKeyUsage&amp; usages, const String&amp; operation, const String&amp; tryOperation, CryptoKeyUsage tryUsage)
</ins><span class="cx"> {
</span><del>-    String jwkUseString;
-    if (!getStringFromJSON(m_exec, m_json.get(), &quot;use&quot;, jwkUseString)) {
-        // &quot;use&quot; is optional in JWK.
-        return;
</del><ins>+    if (operation == tryOperation) {
+        if (usages &amp; tryUsage) {
+            throwTypeError(exec, &quot;JWK key_ops contains a duplicate operation&quot;);
+            return false;
+        }
+        usages |= tryUsage;
</ins><span class="cx">     }
</span><ins>+    return true;
+}
</ins><span class="cx"> 
</span><del>-    // Implemented according to a proposal in &lt;https://www.w3.org/Bugs/Public/show_bug.cgi?id=23796&gt;.
-    Vector&lt;String&gt; jwkUsageValues;
-    jwkUseString.split(',', jwkUsageValues);
</del><ins>+void JSCryptoKeySerializationJWK::reconcileUsages(CryptoKeyUsage&amp; suggestedUsages) const
+{
</ins><span class="cx">     CryptoKeyUsage jwkUsages = 0;
</span><del>-    for (size_t i = 0, size = jwkUsageValues.size(); i &lt; size; ++i) {
-        String jwkUse = jwkUsageValues[i];
-        if (jwkUse == &quot;sig&quot;)
</del><ins>+
+    JSArray* keyOps;
+    if (getJSArrayFromJSON(m_exec, m_json.get(), &quot;key_ops&quot;, keyOps)) {
+        for (size_t i = 0; i &lt; keyOps-&gt;length(); ++i) {
+            JSValue jsValue = keyOps-&gt;getIndex(m_exec, i);
+            String operation;
+            if (!jsValue.getString(m_exec, operation)) {
+                if (!m_exec-&gt;hadException())
+                    throwTypeError(m_exec, &quot;JWK key_ops attribute could not be processed&quot;);
+                return;
+            }
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;sign&quot;), CryptoKeyUsageSign))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;verify&quot;), CryptoKeyUsageVerify))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;encrypt&quot;), CryptoKeyUsageEncrypt))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;decrypt&quot;), CryptoKeyUsageDecrypt))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;wrap&quot;), CryptoKeyUsageWrapKey))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;unwrap&quot;), CryptoKeyUsageUnwrapKey))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;deriveKey&quot;), CryptoKeyUsageDeriveKey))
+                return;
+            if (!tryJWKKeyOpsValue(m_exec, jwkUsages, operation, ASCIILiteral(&quot;deriveBits&quot;), CryptoKeyUsageDeriveBits))
+                return;
+        }
+    } else {
+        if (m_exec-&gt;hadException())
+            return;
+
+        String jwkUseString;
+        if (!getStringFromJSON(m_exec, m_json.get(), &quot;use&quot;, jwkUseString)) {
+            // We have neither key_ops nor use.
+            return;
+        }
+
+        if (jwkUseString == &quot;enc&quot;)
+            jwkUsages |= (CryptoKeyUsageEncrypt | CryptoKeyUsageDecrypt | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey);
+        else if (jwkUseString == &quot;sig&quot;)
</ins><span class="cx">             jwkUsages |= (CryptoKeyUsageSign | CryptoKeyUsageVerify);
</span><del>-        else if (jwkUse == &quot;enc&quot;)
-            jwkUsages |= (CryptoKeyUsageEncrypt | CryptoKeyUsageDecrypt | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey);
-        else if (jwkUse == &quot;enconly&quot;)
-            jwkUsages |= CryptoKeyUsageEncrypt;
-        else if (jwkUse == &quot;deconly&quot;)
-            jwkUsages |= CryptoKeyUsageDecrypt;
-        else if (jwkUse == &quot;sigonly&quot;)
-            jwkUsages |= CryptoKeyUsageSign;
-        else if (jwkUse == &quot;vfyonly&quot;)
-            jwkUsages |= CryptoKeyUsageVerify;
-        else if (jwkUse == &quot;drvkey&quot;)
-            jwkUsages |= CryptoKeyUsageDeriveKey;
-        else if (jwkUse == &quot;drvbits&quot;)
-            jwkUsages |= CryptoKeyUsageDeriveBits;
-        else if (jwkUse == &quot;wrap&quot;)
-            jwkUsages |= CryptoKeyUsageWrapKey;
-        else if (jwkUse == &quot;unwrap&quot;)
-            jwkUsages |= CryptoKeyUsageUnwrapKey;
</del><ins>+        else {
+            throwTypeError(m_exec, &quot;Unsupported JWK key use value \&quot;&quot; + jwkUseString + &quot;\&quot;&quot;);
+            return;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     suggestedUsages = suggestedUsages &amp; jwkUsages;
</span><span class="lines">@@ -290,10 +317,8 @@
</span><span class="cx"> void JSCryptoKeySerializationJWK::reconcileExtractable(bool&amp; suggestedExtractable) const
</span><span class="cx"> {
</span><span class="cx">     bool jwkExtractable;
</span><del>-    if (!getBooleanFromJSON(m_exec, m_json.get(), &quot;ext&quot;, jwkExtractable)) {
-        // &quot;ext&quot; not in JWK or WebCrypto specs yet, implemented according to a proposal in &lt;https://www.w3.org/Bugs/Public/show_bug.cgi?id=23796&gt;.
</del><ins>+    if (!getBooleanFromJSON(m_exec, m_json.get(), &quot;ext&quot;, jwkExtractable))
</ins><span class="cx">         return;
</span><del>-    }
</del><span class="cx"> 
</span><span class="cx">     suggestedExtractable = suggestedExtractable &amp;&amp; jwkExtractable;
</span><span class="cx"> }
</span><span class="lines">@@ -472,13 +497,20 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCryptoKeySerializationJWK::buildJSONForOctetSequence(ExecState* exec, const Vector&lt;uint8_t&gt;&amp; keyData, JSObject* result)
</del><ins>+static void addToJSON(ExecState* exec, JSObject* json, const char* key, const String&amp; value)
</ins><span class="cx"> {
</span><ins>+    VM&amp; vm = exec-&gt;vm();
+    Identifier identifier(&amp;vm, key);
+    json-&gt;putDirect(vm, identifier, jsString(exec, value));
+}
+
+static void buildJSONForOctetSequence(ExecState* exec, const Vector&lt;uint8_t&gt;&amp; keyData, JSObject* result)
+{
</ins><span class="cx">     addToJSON(exec, result, &quot;kty&quot;, &quot;oct&quot;);
</span><span class="cx">     addToJSON(exec, result, &quot;k&quot;, base64URLEncode(keyData));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCryptoKeySerializationJWK::buildJSONForRSAComponents(JSC::ExecState* exec, const CryptoKeyDataRSAComponents&amp; data, JSC::JSObject* result)
</del><ins>+static void buildJSONForRSAComponents(JSC::ExecState* exec, const CryptoKeyDataRSAComponents&amp; data, JSC::JSObject* result)
</ins><span class="cx"> {
</span><span class="cx">     addToJSON(exec, result, &quot;kty&quot;, &quot;RSA&quot;);
</span><span class="cx">     addToJSON(exec, result, &quot;n&quot;, base64URLEncode(data.modulus()));
</span><span class="lines">@@ -512,21 +544,14 @@
</span><span class="cx">     result-&gt;putDirect(exec-&gt;vm(), Identifier(exec, &quot;oth&quot;), oth);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCryptoKeySerializationJWK::addToJSON(ExecState* exec, JSObject* json, const char* key, const String&amp; value)
</del><ins>+static void addBoolToJSON(ExecState* exec, JSObject* json, const char* key, bool value)
</ins><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx">     Identifier identifier(&amp;vm, key);
</span><del>-    json-&gt;putDirect(vm, identifier, jsString(exec, value));
-}
-
-void JSCryptoKeySerializationJWK::addBoolToJSON(ExecState* exec, JSObject* json, const char* key, bool value)
-{
-    VM&amp; vm = exec-&gt;vm();
-    Identifier identifier(&amp;vm, key);
</del><span class="cx">     json-&gt;putDirect(vm, identifier, jsBoolean(value));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCryptoKeySerializationJWK::addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoKey&amp; key)
</del><ins>+static void addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoKey&amp; key)
</ins><span class="cx"> {
</span><span class="cx">     String jwkAlgorithm;
</span><span class="cx">     switch (key.algorithmIdentifier()) {
</span><span class="lines">@@ -627,53 +652,31 @@
</span><span class="cx">     addToJSON(exec, json, &quot;alg&quot;, jwkAlgorithm);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool processUseValue(StringBuilder&amp; builder, CryptoKeyUsage&amp; usages, const String&amp; useString, CryptoKeyUsage usagesForUseString)
</del><ins>+static void addUsagesToJSON(ExecState* exec, JSObject* json, CryptoKeyUsage usages)
</ins><span class="cx"> {
</span><del>-    if ((usages &amp; usagesForUseString) != usagesForUseString)
-        return false;
</del><ins>+    JSArray* keyOps = constructEmptyArray(exec, 0, exec-&gt;lexicalGlobalObject(), 0);
</ins><span class="cx"> 
</span><del>-    if (!builder.isEmpty())
-        builder.append(',');
-    builder.append(useString);
</del><ins>+    unsigned index = 0;
+    if (usages &amp; CryptoKeyUsageSign)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;sign&quot;)));
+    if (usages &amp; CryptoKeyUsageVerify)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;verify&quot;)));
+    if (usages &amp; CryptoKeyUsageEncrypt)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;encrypt&quot;)));
+    if (usages &amp; CryptoKeyUsageDecrypt)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;decrypt&quot;)));
+    if (usages &amp; CryptoKeyUsageWrapKey)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;wrap&quot;)));
+    if (usages &amp; CryptoKeyUsageUnwrapKey)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;unwrap&quot;)));
+    if (usages &amp; CryptoKeyUsageDeriveKey)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;deriveKey&quot;)));
+    if (usages &amp; CryptoKeyUsageDeriveBits)
+        keyOps-&gt;putDirectIndex(exec, index++, jsString(exec, ASCIILiteral(&quot;deriveBits&quot;)));
</ins><span class="cx"> 
</span><del>-    usages &amp;= ~usagesForUseString;
-
-    return true;
</del><ins>+    json-&gt;putDirect(exec-&gt;vm(), Identifier(exec, &quot;key_ops&quot;), keyOps);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCryptoKeySerializationJWK::addJWKUseToJSON(ExecState* exec, JSObject* json, CryptoKeyUsage usages)
-{
-    // Use mapping implemented according to a proposal in &lt;https://www.w3.org/Bugs/Public/show_bug.cgi?id=23796&gt;.
-    StringBuilder useBuilder;
-    CryptoKeyUsage remainingUsages = usages;
-    while (remainingUsages) {
-        if (processUseValue(useBuilder, remainingUsages, &quot;enc&quot;, CryptoKeyUsageEncrypt | CryptoKeyUsageDecrypt | CryptoKeyUsageWrapKey | CryptoKeyUsageUnwrapKey))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;sig&quot;, CryptoKeyUsageSign | CryptoKeyUsageVerify))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;enconly&quot;, CryptoKeyUsageEncrypt))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;deconly&quot;, CryptoKeyUsageDecrypt))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;sigonly&quot;, CryptoKeyUsageSign))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;vfyonly&quot;, CryptoKeyUsageVerify))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;drvkey&quot;, CryptoKeyUsageDeriveKey))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;drvbits&quot;, CryptoKeyUsageDeriveBits))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;wrap&quot;, CryptoKeyUsageWrapKey))
-            continue;
-        if (processUseValue(useBuilder, remainingUsages, &quot;unwrap&quot;, CryptoKeyUsageUnwrapKey))
-            continue;
-        throwTypeError(exec, &quot;Key usages cannot be represented in JWK.&quot;);
-        return;
-    }
-
-    addToJSON(exec, json, &quot;use&quot;, useBuilder.toString());
-}
-
</del><span class="cx"> String JSCryptoKeySerializationJWK::serialize(ExecState* exec, const CryptoKey&amp; key)
</span><span class="cx"> {
</span><span class="cx">     std::unique_ptr&lt;CryptoKeyData&gt; keyData = key.exportData();
</span><span class="lines">@@ -691,7 +694,7 @@
</span><span class="cx"> 
</span><span class="cx">     addBoolToJSON(exec, result, &quot;ext&quot;, key.extractable());
</span><span class="cx"> 
</span><del>-    addJWKUseToJSON(exec, result, key.usagesBitmap());
</del><ins>+    addUsagesToJSON(exec, result, key.usagesBitmap());
</ins><span class="cx">     if (exec-&gt;hadException())
</span><span class="cx">         return String();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSCryptoKeySerializationJWKh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.h        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -66,13 +66,6 @@
</span><span class="cx"> 
</span><span class="cx">     virtual std::unique_ptr&lt;CryptoKeyData&gt; keyData() const override;
</span><span class="cx"> 
</span><del>-    static void buildJSONForOctetSequence(JSC::ExecState*, const Vector&lt;uint8_t&gt;&amp;, JSC::JSObject* result);
-    static void buildJSONForRSAComponents(JSC::ExecState*, const CryptoKeyDataRSAComponents&amp;, JSC::JSObject* result);
-    static void addJWKAlgorithmToJSON(JSC::ExecState*, JSC::JSObject*, const CryptoKey&amp; key);
-    static void addJWKUseToJSON(JSC::ExecState*, JSC::JSObject*, CryptoKeyUsage);
-    static void addToJSON(JSC::ExecState*, JSC::JSObject*, const char* key, const String&amp; value);
-    static void addBoolToJSON(JSC::ExecState*, JSC::JSObject*, const char* key, bool value);
-
</del><span class="cx">     bool keySizeIsValid(size_t sizeInBits) const;
</span><span class="cx">     std::unique_ptr&lt;CryptoKeyData&gt; keyDataOctetSequence() const;
</span><span class="cx">     std::unique_ptr&lt;CryptoKeyData&gt; keyDataRSAComponents() const;
</span></span></pre></div>
<a id="trunkSourceWebCorecryptomacCryptoAlgorithmAES_KWMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_KWMac.cpp (163243 => 163244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_KWMac.cpp        2014-02-01 17:31:48 UTC (rev 163243)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_KWMac.cpp        2014-02-01 18:14:17 UTC (rev 163244)
</span><span class="lines">@@ -36,6 +36,13 @@
</span><span class="cx"> 
</span><span class="cx"> void CryptoAlgorithmAES_KW::platformEncrypt(const CryptoKeyAES&amp; key, const CryptoOperationData&amp; data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&amp;)
</span><span class="cx"> {
</span><ins>+    if (data.second % 8) {
+        // RFC 3394 uses 64-bit blocks as input.
+        // &lt;rdar://problem/15949992&gt; CommonCrypto doesn't detect incorrect data length, silently producing a bad cyphertext.
+        failureCallback();
+        return;
+    }
+
</ins><span class="cx">     Vector&lt;uint8_t&gt; result(CCSymmetricWrappedSize(kCCWRAPAES, data.second));
</span><span class="cx">     size_t resultSize = result.size();
</span><span class="cx">     int status = CCSymmetricKeyWrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, key.key().data(), key.key().size(), data.first, data.second, result.data(), &amp;resultSize);
</span><span class="lines">@@ -51,6 +58,12 @@
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;uint8_t&gt; result(CCSymmetricUnwrappedSize(kCCWRAPAES, data.second));
</span><span class="cx">     size_t resultSize = result.size();
</span><ins>+
+    if (resultSize % 8) {
+        failureCallback();
+        return;
+    }
+
</ins><span class="cx">     int status = CCSymmetricKeyUnwrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, key.key().data(), key.key().size(), data.first, data.second, result.data(), &amp;resultSize);
</span><span class="cx">     if (status) {
</span><span class="cx">         failureCallback();
</span></span></pre>
</div>
</div>

</body>
</html>