<!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>[163976] 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/163976">163976</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2014-02-12 13:08:40 -0800 (Wed, 12 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Wrap WebCrypto keys in SerializedScriptValue
https://bugs.webkit.org/show_bug.cgi?id=128680

Reviewed by Anders Carlsson.

Source/WebCore: 

Test: crypto/subtle/rsa-indexeddb.html

Added Mac code to wrap a key with AES-GCM. We then serialize it into a plist,
because more custom formats would be crazy (even the custom format in SerializedScriptValue
makes me nervous, we'll certainly need to change CryptoKey in the future).

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* crypto/CommonCryptoUtilities.h:
* crypto/SerializedCryptoKeyWrap.h: Added.
* crypto/mac/SerializedCryptoKeyWrapMac.mm: Added.
(WebCore::vectorFromNSData):
(WebCore::wrapSerializedCryptoKey):
(WebCore::unwrapSerializedCryptoKey):

Source/WebKit/mac: 

Retrieve a master key (placeholder code for now), and use it to wrap key data.

* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::wrapCryptoKey):
(WebChromeClient::unwrapCryptoKey):

Source/WebKit2: 

Retrieve a master key (placeholder code for now), and use it to wrap key data.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):

LayoutTests: 

* crypto/subtle/rsa-indexeddb-expected.txt: Added.
* crypto/subtle/rsa-indexeddb.html: Added.
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformeflTestExpectations">trunk/LayoutTests/platform/efl/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsplatformgtkTestExpectations">trunk/LayoutTests/platform/gtk/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk1TestExpectations">trunk/LayoutTests/platform/mac-wk1/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsplatformwinTestExpectations">trunk/LayoutTests/platform/win/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsplatformwincairoTestExpectations">trunk/LayoutTests/platform/wincairo/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorecryptoCommonCryptoUtilitiesh">trunk/Source/WebCore/crypto/CommonCryptoUtilities.h</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebChromeClientmm">trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebPageProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestscryptosubtlersaindexeddbexpectedtxt">trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt</a></li>
<li><a href="#trunkLayoutTestscryptosubtlersaindexeddbhtml">trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html</a></li>
<li><a href="#trunkSourceWebCorecryptoSerializedCryptoKeyWraph">trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h</a></li>
<li><a href="#trunkSourceWebCorecryptomacSerializedCryptoKeyWrapMacmm">trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/ChangeLog        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2014-02-12  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        * crypto/subtle/rsa-indexeddb-expected.txt: Added.
+        * crypto/subtle/rsa-indexeddb.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+        * platform/win/TestExpectations:
+        * platform/wincairo/TestExpectations:
+
</ins><span class="cx"> 2014-02-12  Brendan Long  &lt;b.long@cablelabs.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement DataCue for metadata cues
</span></span></pre></div>
<a id="trunkLayoutTestscryptosubtlersaindexeddbexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt (0 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt                                (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+Test storing a private RSA key in IndexedDB, and retrieving it.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS retrievedKey.type is 'private'
+PASS retrievedKey.extractable is true
+PASS retrievedKey.algorithm.name is 'RSASSA-PKCS1-v1_5'
+PASS retrievedKey.algorithm.modulusLength is 2048
+PASS bytesToHexString(retrievedKey.algorithm.publicExponent) is '010001'
+PASS retrievedKey.usages is [&quot;sign&quot;, &quot;verify&quot;]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins><span class="cx">Property changes on: trunk/LayoutTests/crypto/subtle/rsa-indexeddb-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestscryptosubtlersaindexeddbhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html (0 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html                                (rev 0)
+++ trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -0,0 +1,74 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;resources/common.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+
+description(&quot;Test storing a private RSA key in IndexedDB, and retrieving it.&quot;);
+
+jsTestIsAsync = true;
+
+var privateKeyJSON = {
+    kty: &quot;RSA&quot;,
+    alg: &quot;RS256&quot;,
+    n: &quot;rcCUCv7Oc1HVam1DIhCzqknThWawOp8QLk8Ziy2p10ByjQFCajoFiyuAWl-R1WXZaf4xitLRracT9agpzIzc-MbLSHIGgWQGO21lGiImy5ftZ-D8bHAqRz2y15pzD4c4CEou7XSSLDoRnR0QG5MsDhD6s2gV9mwHkrtkCxtMWdBi-77as8wGmlNRldcOSgZDLK8UnCSgA1OguZ989bFyc8tOOEIb0xUSfPSz3LPSCnyYz68aDjmKVeNH-ig857OScyWbGyEy3Biw64qun3juUlNWsJ3zngkOdteYWytx5Qr4XKNs6R-Myyq72KUp02mJDZiiyiglxML_i3-_CeecCw&quot;,
+    e: &quot;AQAB&quot;,
+    d: &quot;eNLS37aCz7RXSNPD_DtLBJ6j5T8cSxdzRBCjPaI6WcGqJp16lq3UTwuoDLAqlA9oGYm238dsIWpuucP_lQtbWe-7SpxoI6_vmYGf7YVUHv1-DF9qiOmSrMmdxMnVOzYXY8RaT6thPjn_J5cfLV2xI_LwsrMtmpdSyNlgX0zTUhwtuahgAKMEChYjH2EnjHdHw6sY2-wApdcQI7ULE0oo5RzbQZpmuhcN9hiBc0L3hhF0qo50mbl02_65_GQ7DpVkXBxNgRBLzlPabmzzG2oAhfefLgYmSC1opaCkXE6vRWQNWNL45RZNZFYM3uoJghOMqGeocM0BpjdChHrPOlFvSQ&quot;,
+    p: &quot;4miTuAjKMeH5uJ5KB397QUwhbkYEgSbcA2mifmSkvE2018gb55qkBHK1eVryf1_m43LNlc6O_ak6gfzdZIZvS5NCGjPl0q09plUpu8qFOSspBwA67qGH76lFlZLn_d4yglS7wfLru4_5Ys8qLLs-DqVLviwposOnyyWqwM5AXp0&quot;,
+    q: &quot;xHYrzkivtmnz_sGchnWGc0q-pDOkKicptRpv2pMFIIXxnFX5aMeEXIZjVujXtwUy1UlFIN2GZJSvy5KJ79mu_XyNnFHMzedH-A3ee3u8h1UUrZF-vUu1_e4U_x67NN1dedzUSKynN7pFl3OkuShMBWGV-cwzOPdcVAfVuZlxUMc&quot;,
+    dp: &quot;fBzDzYDUBmBQGop7Hn0dvf_T27V6RqpctWo074CQZcFbP2atFVtKSj3viWT3xid2VHzcgiDHdfpM3nEVlEO1wwIonGCSvdjGEOZiiFVOjrZAOVxA8guOjyyFvqbXke06VwPIIVvfKeSU2zuhbP__1tt6F_fxow4Kb2xonGT0GGk&quot;,
+    dq: &quot;jmE2DiIPdhwDgLXAQpIaBqQ81bO3XfVT_LRULAwwwwlPuQV148H04zlh9TJ6Y2GZHYokV1U0eOBpJxfkb7dLYtpJpuiBjRf4yIUEoGlkkI_QlJnFSFr-YjGRdfNHqWBkxlSMZL770R9mIATndGkH7z5x-r9KwBZFC4FCG2hg_zE&quot;,
+    qi: &quot;YCX_pLwbMBA1ThVH0WcwmnytqNcrMCEwTm7ByA2eU6nWbQrULvf7m9_kzfLUcjsnpAVlBQG5JMXMy0Sq4ptwbywsa5-G8KAOOOR2L3v4hC-Eys9ftgFM_3i0o40eeQH4b3haPbntrIeMg8IzlOuVYKf9-2QuKDoWeRdd7NsdxTk&quot;
+};
+
+crypto.subtle.importKey(&quot;jwk&quot;, asciiToUint8Array(JSON.stringify(privateKeyJSON)), null, true, [&quot;sign&quot;, &quot;verify&quot;]).then(function(key) {
+    var openRequest = indexedDB.open(&quot;crypto_subtle&quot;);
+    openRequest.onupgradeneeded = function(event) {
+        var objectStore = event.target.result.createObjectStore(&quot;rsa-indexeddb&quot;);
+    }
+    openRequest.onerror = function(event) {
+        testFailed(&quot;Could not open database: &quot; + event.target.error.name);
+        finishJSTest();
+    }
+    openRequest.onsuccess = function(event) {
+        db = event.target.result;
+        storeKey();
+    }
+
+    function storeKey() {
+        var objectStore = db.transaction(&quot;rsa-indexeddb&quot;, &quot;readwrite&quot;).objectStore(&quot;rsa-indexeddb&quot;);
+        var req = objectStore.put(key, &quot;mykey&quot;);
+        req.onerror = function(event) {
+            testFailed(&quot;Could not put a key into database: &quot; + event.target.error.name);
+            finishJSTest();
+        }
+        req.onsuccess = function(event) { readKey(); }
+    }
+
+    function readKey() {
+        var objectStore = db.transaction(&quot;rsa-indexeddb&quot;).objectStore(&quot;rsa-indexeddb&quot;);
+        var req = objectStore.get(&quot;mykey&quot;);
+        req.onerror = function(event) {
+            testFailed(&quot;Could not get a key from database: &quot; + event.target.error.name);
+            finishJSTest();
+        }
+        req.onsuccess = function(event) {
+            window.retrievedKey = event.target.result;
+            shouldBe(&quot;retrievedKey.type&quot;, &quot;'private'&quot;);
+            shouldBe(&quot;retrievedKey.extractable&quot;, &quot;true&quot;);
+            shouldBe(&quot;retrievedKey.algorithm.name&quot;, &quot;'RSASSA-PKCS1-v1_5'&quot;);
+            shouldBe(&quot;retrievedKey.algorithm.modulusLength&quot;, &quot;2048&quot;);
+            shouldBe(&quot;bytesToHexString(retrievedKey.algorithm.publicExponent)&quot;, &quot;'010001'&quot;);
+            shouldBe(&quot;retrievedKey.usages&quot;, '[&quot;sign&quot;, &quot;verify&quot;]');
+
+            finishJSTest();
+        }
+    }
+});
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/crypto/subtle/rsa-indexeddb.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="trunkLayoutTestsplatformeflTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/efl/TestExpectations (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/efl/TestExpectations        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/efl/TestExpectations        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -271,6 +271,7 @@
</span><span class="cx"> webkit.org/b/87661 http/tests/security/cross-origin-worker-indexeddb-allowed.html [ Skip ]
</span><span class="cx"> webkit.org/b/87661 http/tests/security/cross-origin-worker-indexeddb.html [ Skip ]
</span><span class="cx"> webkit.org/b/87661 http/tests/security/no-indexeddb-from-sandbox.html [ Skip ]
</span><ins>+webkit.org/b/87661 crypto/subtle/rsa-indexeddb.html [ Skip ]
</ins><span class="cx"> 
</span><span class="cx"> #////////////////////////////////////////////////////////////////////////////////////////
</span><span class="cx"> # TESTS EXPECTED TO FAIL
</span></span></pre></div>
<a id="trunkLayoutTestsplatformgtkTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/gtk/TestExpectations (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/gtk/TestExpectations        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/gtk/TestExpectations        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -493,6 +493,7 @@
</span><span class="cx"> webkit.org/b/107194 http/tests/security/cross-origin-worker-indexeddb-allowed.html [ Skip ]
</span><span class="cx"> webkit.org/b/107194 http/tests/security/cross-origin-worker-indexeddb.html [ Skip ]
</span><span class="cx"> webkit.org/b/107194 http/tests/security/no-indexeddb-from-sandbox.html [ Skip ]
</span><ins>+crypto/subtle/rsa-indexeddb.html
</ins><span class="cx"> 
</span><span class="cx"> # crypto.subtle is not yet enabled
</span><span class="cx"> crypto/subtle [ Skip ]
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk1TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk1/TestExpectations        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -5,3 +5,4 @@
</span><span class="cx"> http/tests/security/cross-origin-worker-indexeddb-allowed.html
</span><span class="cx"> http/tests/security/cross-origin-worker-indexeddb.html
</span><span class="cx"> http/tests/security/no-indexeddb-from-sandbox.html
</span><ins>+crypto/subtle/rsa-indexeddb.html
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformwinTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/win/TestExpectations (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/win/TestExpectations        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/win/TestExpectations        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -1084,6 +1084,7 @@
</span><span class="cx"> http/tests/security/cross-origin-worker-indexeddb-allowed.html
</span><span class="cx"> http/tests/security/cross-origin-worker-indexeddb.html
</span><span class="cx"> http/tests/security/no-indexeddb-from-sandbox.html
</span><ins>+crypto/subtle/rsa-indexeddb.html
</ins><span class="cx"> 
</span><span class="cx"> # StorageTracker is not enabled.
</span><span class="cx"> storage/domstorage/localstorage/storagetracker
</span></span></pre></div>
<a id="trunkLayoutTestsplatformwincairoTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/wincairo/TestExpectations        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -1581,6 +1581,7 @@
</span><span class="cx"> http/tests/security/cross-origin-worker-indexeddb-allowed.html
</span><span class="cx"> http/tests/security/cross-origin-worker-indexeddb.html
</span><span class="cx"> http/tests/security/no-indexeddb-from-sandbox.html
</span><ins>+crypto/subtle/rsa-indexeddb.html
</ins><span class="cx"> 
</span><span class="cx"> # StorageTracker is not enabled.
</span><span class="cx"> storage/domstorage/localstorage/storagetracker
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/ChangeLog        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-02-12  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        Test: crypto/subtle/rsa-indexeddb.html
+
+        Added Mac code to wrap a key with AES-GCM. We then serialize it into a plist,
+        because more custom formats would be crazy (even the custom format in SerializedScriptValue
+        makes me nervous, we'll certainly need to change CryptoKey in the future).
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * crypto/CommonCryptoUtilities.h:
+        * crypto/SerializedCryptoKeyWrap.h: Added.
+        * crypto/mac/SerializedCryptoKeyWrapMac.mm: Added.
+        (WebCore::vectorFromNSData):
+        (WebCore::wrapSerializedCryptoKey):
+        (WebCore::unwrapSerializedCryptoKey):
+
</ins><span class="cx"> 2014-02-12  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Wheel events don't latch to inner scrollable elements 
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -911,6 +911,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> __ZN7WebCore23getFileModificationTimeERKN3WTF6StringERl
</span><span class="cx"> __ZN7WebCore23getHostnamesWithCookiesERKNS_21NetworkStorageSessionERN3WTF7HashSetINS3_6StringENS3_10StringHashENS3_10HashTraitsIS5_EEEE
</span><ins>+__ZN7WebCore23wrapSerializedCryptoKeyERKN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEES5_RS3_
</ins><span class="cx"> __ZN7WebCore24CachedResourceHandleBase11setResourceEPNS_14CachedResourceE
</span><span class="cx"> __ZN7WebCore24DocumentMarkerController10markersForEPNS_4NodeENS_14DocumentMarker11MarkerTypesE
</span><span class="cx"> __ZN7WebCore24DocumentMarkerController13removeMarkersENS_14DocumentMarker11MarkerTypesE
</span><span class="lines">@@ -933,6 +934,7 @@
</span><span class="cx"> __ZN7WebCore25addLanguageChangeObserverEPvPFvS0_E
</span><span class="cx"> __ZN7WebCore25computeViewportAttributesENS_17ViewportArgumentsEiiifNS_7IntSizeE
</span><span class="cx"> __ZN7WebCore25createCanonicalUUIDStringEv
</span><ins>+__ZN7WebCore25unwrapSerializedCryptoKeyERKN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEES5_RS3_
</ins><span class="cx"> __ZN7WebCore26ContextDestructionObserver16contextDestroyedEv
</span><span class="cx"> __ZN7WebCore26ContextDestructionObserverC2EPNS_22ScriptExecutionContextE
</span><span class="cx"> __ZN7WebCore26ContextDestructionObserverD2Ev
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -5784,6 +5784,8 @@
</span><span class="cx">                 E18258AC0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */; };
</span><span class="cx">                 E187056316E54A0D00585E97 /* MainThreadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = E187056216E54A0D00585E97 /* MainThreadTask.h */; };
</span><span class="cx">                 E18772F1126E2629003DD586 /* Language.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18772F0126E2629003DD586 /* Language.cpp */; };
</span><ins>+                E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */; };
</ins><span class="cx">                 E19727161820549E00592D51 /* CryptoKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = E19727151820549E00592D51 /* CryptoKeyType.h */; };
</span><span class="cx">                 E19AC3EE1824DC7900349426 /* CryptoAlgorithmSHA224.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E19AC3E61824DC7900349426 /* CryptoAlgorithmSHA224.cpp */; };
</span><span class="cx">                 E19AC3EF1824DC7900349426 /* CryptoAlgorithmSHA224.h in Headers */ = {isa = PBXBuildFile; fileRef = E19AC3E71824DC7900349426 /* CryptoAlgorithmSHA224.h */; };
</span><span class="lines">@@ -13076,6 +13078,8 @@
</span><span class="cx">                 E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScopeCustom.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E187056216E54A0D00585E97 /* MainThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThreadTask.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E18772F0126E2629003DD586 /* Language.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Language.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedCryptoKeyWrap.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SerializedCryptoKeyWrapMac.mm; path = mac/SerializedCryptoKeyWrapMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 E19727151820549E00592D51 /* CryptoKeyType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyType.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E19AC3E61824DC7900349426 /* CryptoAlgorithmSHA224.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmSHA224.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E19AC3E71824DC7900349426 /* CryptoAlgorithmSHA224.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmSHA224.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -21035,6 +21039,7 @@
</span><span class="cx">                                 E19AC3F8182566F700349426 /* CryptoKeyMac.cpp */,
</span><span class="cx">                                 E164FAA418315E1A00DB4E61 /* CryptoKeyRSAMac.cpp */,
</span><span class="cx">                                 E1FE13621834351100892F13 /* CryptoDigestMac.cpp */,
</span><ins>+                                E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = mac;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -21236,6 +21241,7 @@
</span><span class="cx">                                 E125F855182C0F8300D84CD9 /* CryptoKeySerialization.h */,
</span><span class="cx">                                 E19727151820549E00592D51 /* CryptoKeyType.h */,
</span><span class="cx">                                 E172AF6F180F289500FBADB9 /* CryptoKeyUsage.h */,
</span><ins>+                                E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */,
</ins><span class="cx">                                 E1FF8F5C1807364B00132674 /* SubtleCrypto.idl */,
</span><span class="cx">                                 E1FF8F5D1807442100132674 /* SubtleCrypto.cpp */,
</span><span class="cx">                                 E1FF8F5E1807442100132674 /* SubtleCrypto.h */,
</span><span class="lines">@@ -23436,6 +23442,7 @@
</span><span class="cx">                                 2E37DFDB12DBAFB800A6B233 /* DOMURL.h in Headers */,
</span><span class="cx">                                 15C770A6100D41CD005BA267 /* DOMValidityState.h in Headers */,
</span><span class="cx">                                 BC1A37C0097C715F0019F3D8 /* DOMViews.h in Headers */,
</span><ins>+                                E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */,
</ins><span class="cx">                                 31C0FF490E4CEFDD007D6FE5 /* DOMWebKitAnimationEvent.h in Headers */,
</span><span class="cx">                                 31C0FF4B0E4CEFDD007D6FE5 /* DOMWebKitAnimationEventInternal.h in Headers */,
</span><span class="cx">                                 415B3A6E17CBE267000FCCE8 /* AccessibilitySearchFieldButtons.h in Headers */,
</span><span class="lines">@@ -26320,6 +26327,7 @@
</span><span class="cx">                                 512DD8FB0D91E6AF000F89EE /* ArchiveResource.cpp in Sources */,
</span><span class="cx">                                 E1FE137A184D21BB00892F13 /* CryptoAlgorithmAES_KW.cpp in Sources */,
</span><span class="cx">                                 512DD8F70D91E6AF000F89EE /* ArchiveResourceCollection.cpp in Sources */,
</span><ins>+                                E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */,
</ins><span class="cx">                                 49B3760C15C6C6840059131D /* ArrayValue.cpp in Sources */,
</span><span class="cx">                                 FD5686C913AC180200B69C68 /* AsyncAudioDecoder.cpp in Sources */,
</span><span class="cx">                                 E1CDE92015018ED000862CC5 /* AsyncFileStream.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoCommonCryptoUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/CommonCryptoUtilities.h (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/crypto/CommonCryptoUtilities.h        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebCore/crypto/CommonCryptoUtilities.h        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -89,6 +89,7 @@
</span><span class="cx"> extern &quot;C&quot; void CCRSACryptorRelease(CCRSACryptorRef key);
</span><span class="cx"> extern &quot;C&quot; 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 &quot;C&quot; CCRSAKeyType CCRSAGetKeyType(CCRSACryptorRef key);
</span><ins>+extern &quot;C&quot; 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);
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoSerializedCryptoKeyWraph"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h (0 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h                                (rev 0)
+++ trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SerializedCryptoKeyWrap_h
+#define SerializedCryptoKeyWrap_h
+
+#include &lt;wtf/Vector.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+namespace WebCore {
+
+bool wrapSerializedCryptoKey(const Vector&lt;uint8_t&gt;&amp; masterKey, const Vector&lt;uint8_t&gt;&amp; key, Vector&lt;uint8_t&gt;&amp; result);
+bool unwrapSerializedCryptoKey(const Vector&lt;uint8_t&gt;&amp; masterKey, const Vector&lt;uint8_t&gt;&amp; wrappedKey, Vector&lt;uint8_t&gt;&amp; key);
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
+
+#endif // SerializedCryptoKeyWrap_h
</ins><span class="cx">Property changes on: trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkSourceWebCorecryptomacSerializedCryptoKeyWrapMacmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm (0 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm                                (rev 0)
+++ trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -0,0 +1,155 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;SerializedCryptoKeyWrap.h&quot;
+
+#if ENABLE(SUBTLE_CRYPTO)
+
+#include &quot;CommonCryptoUtilities.h&quot;
+#include &lt;CommonCrypto/CommonSymmetricKeywrap.h&gt;
+#include &lt;wtf/text/CString.h&gt;
+#include &lt;wtf/CryptographicUtilities.h&gt;
+
+namespace WebCore {
+
+const NSUInteger currentSerializationVersion = 1;
+
+const NSString* versionKey = @&quot;version&quot;;
+const NSString* wrappedKEKKey = @&quot;wrappedKEK&quot;;
+const NSString* encryptedKeyKey = @&quot;encryptedKey&quot;;
+const NSString* tagKey = @&quot;tag&quot;;
+
+inline Vector&lt;uint8_t&gt; vectorFromNSData(NSData* data)
+{
+    Vector&lt;uint8_t&gt; result;
+    result.append((const uint8_t*)[data bytes], [data length]);
+    return result;
+}
+
+bool wrapSerializedCryptoKey(const Vector&lt;uint8_t&gt;&amp; masterKey, const Vector&lt;uint8_t&gt;&amp; key, Vector&lt;uint8_t&gt;&amp; result)
+{
+    Vector&lt;uint8_t&gt; kek(16);
+    CCRandomCopyBytes(kCCRandomDefault, kek.data(), kek.size());
+
+    Vector&lt;uint8_t&gt; wrappedKEK(CCSymmetricWrappedSize(kCCWRAPAES, kek.size()));
+
+    size_t wrappedKEKSize = wrappedKEK.size();
+    CCCryptorStatus status = CCSymmetricKeyWrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, masterKey.data(), masterKey.size(), kek.data(), kek.size(), wrappedKEK.data(), &amp;wrappedKEKSize);
+    if (status != kCCSuccess)
+        return false;
+
+    wrappedKEK.shrink(wrappedKEKSize);
+
+    Vector&lt;uint8_t&gt; encryptedKey(key.size());
+    size_t tagLength = 16;
+    uint8_t tag[tagLength];
+
+    status = CCCryptorGCM(kCCEncrypt, kCCAlgorithmAES128, kek.data(), kek.size(),
+        nullptr, 0, // iv
+        nullptr, 0, // auth data
+        key.data(), key.size(),
+        encryptedKey.data(),
+        tag, &amp;tagLength);
+
+    if (status != kCCSuccess)
+        return false;
+    RELEASE_ASSERT(tagLength == 16);
+
+    auto dictionary = @{
+        versionKey: [NSNumber numberWithUnsignedInteger:currentSerializationVersion],
+        wrappedKEKKey: [NSData dataWithBytes:wrappedKEK.data() length:wrappedKEK.size()],
+        encryptedKeyKey: [NSData dataWithBytes:encryptedKey.data() length:encryptedKey.size()],
+        tagKey: [NSData dataWithBytes:tag length:tagLength]
+    };
+
+    NSData* serialization = [NSPropertyListSerialization dataWithPropertyList:dictionary format:NSPropertyListBinaryFormat_v1_0 options:0 error:nullptr];
+    if (!serialization)
+        return false;
+
+    result = vectorFromNSData(serialization);
+    return true;
+}
+
+bool unwrapSerializedCryptoKey(const Vector&lt;uint8_t&gt;&amp; masterKey, const Vector&lt;uint8_t&gt;&amp; wrappedKey, Vector&lt;uint8_t&gt;&amp; key)
+{
+    NSDictionary* dictionary = [NSPropertyListSerialization propertyListWithData:[NSData dataWithBytesNoCopy:(void*)wrappedKey.data() length:wrappedKey.size() freeWhenDone:NO] options:0 format:nullptr error:nullptr];
+    if (!dictionary)
+        return false;
+
+    id versionObject = [dictionary objectForKey:versionKey];
+    if (![versionObject isKindOfClass:[NSNumber class]])
+        return false;
+    if ([versionObject unsignedIntegerValue] &gt; currentSerializationVersion)
+        return false;
+
+    id wrappedKEKObject = [dictionary objectForKey:wrappedKEKKey];
+    if (![wrappedKEKObject isKindOfClass:[NSData class]])
+        return false;
+    Vector&lt;uint8_t&gt; wrappedKEK = vectorFromNSData(wrappedKEKObject);
+
+    id encryptedKeyObject = [dictionary objectForKey:encryptedKeyKey];
+    if (![encryptedKeyObject isKindOfClass:[NSData class]])
+        return false;
+    Vector&lt;uint8_t&gt; encryptedKey = vectorFromNSData(encryptedKeyObject);
+
+    id tagObject = [dictionary objectForKey:tagKey];
+    if (![tagObject isKindOfClass:[NSData class]])
+        return false;
+    Vector&lt;uint8_t&gt; tag = vectorFromNSData(tagObject);
+    if (tag.size() != 16)
+        return false;
+
+    Vector&lt;uint8_t&gt; kek(CCSymmetricUnwrappedSize(kCCWRAPAES, wrappedKEK.size()));
+    size_t kekSize = kek.size();
+    CCCryptorStatus status = CCSymmetricKeyUnwrap(kCCWRAPAES, CCrfc3394_iv, CCrfc3394_ivLen, masterKey.data(), masterKey.size(), wrappedKEK.data(), wrappedKEK.size(), kek.data(), &amp;kekSize);
+    if (status != kCCSuccess)
+        return false;
+    kek.shrink(kekSize);
+
+    size_t tagLength = 16;
+    uint8_t actualTag[tagLength];
+
+    key.resize(encryptedKey.size());
+    status = CCCryptorGCM(kCCDecrypt, kCCAlgorithmAES128, kek.data(), kek.size(),
+        nullptr, 0, // iv
+        nullptr, 0, // auth data
+        encryptedKey.data(), encryptedKey.size(),
+        key.data(),
+        actualTag, &amp;tagLength);
+
+    if (status != kCCSuccess)
+        return false;
+    RELEASE_ASSERT(tagLength == 16);
+
+    if (constantTimeMemcmp(tag.data(), actualTag, tagLength))
+        return false;
+
+    return true;
+}
+
+}
+
+#endif // ENABLE(SUBTLE_CRYPTO)
</ins><span class="cx">Property changes on: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-02-12  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        Retrieve a master key (placeholder code for now), and use it to wrap key data.
+
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::wrapCryptoKey):
+        (WebChromeClient::unwrapCryptoKey):
+
</ins><span class="cx"> 2014-02-11  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Frame::rectForSelection shouldn't instantiate FrameSelection
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebChromeClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -79,6 +79,7 @@
</span><span class="cx"> #import &lt;WebCore/Page.h&gt;
</span><span class="cx"> #import &lt;WebCore/PlatformScreen.h&gt;
</span><span class="cx"> #import &lt;WebCore/ResourceRequest.h&gt;
</span><ins>+#import &lt;WebCore/SerializedCryptoKeyWrap.h&gt;
</ins><span class="cx"> #import &lt;WebCore/Widget.h&gt;
</span><span class="cx"> #import &lt;WebCore/WindowFeatures.h&gt;
</span><span class="cx"> #import &lt;wtf/PassRefPtr.h&gt;
</span><span class="lines">@@ -1001,13 +1002,15 @@
</span><span class="cx"> #if ENABLE(SUBTLE_CRYPTO)
</span><span class="cx"> bool WebChromeClient::wrapCryptoKey(const Vector&lt;uint8_t&gt;&amp; key, Vector&lt;uint8_t&gt;&amp; wrappedKey) const
</span><span class="cx"> {
</span><del>-    wrappedKey = key;
-    return true;
</del><ins>+    Vector&lt;uint8_t&gt; masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    return wrapSerializedCryptoKey(masterKey, key, wrappedKey);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool WebChromeClient::unwrapCryptoKey(const Vector&lt;uint8_t&gt;&amp; wrappedKey, Vector&lt;uint8_t&gt;&amp; key) const
</span><span class="cx"> {
</span><del>-    key = wrappedKey;
-    return true;
</del><ins>+    Vector&lt;uint8_t&gt; masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    return unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit2/ChangeLog        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-02-12  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        Wrap WebCrypto keys in SerializedScriptValue
+        https://bugs.webkit.org/show_bug.cgi?id=128680
+
+        Reviewed by Anders Carlsson.
+
+        Retrieve a master key (placeholder code for now), and use it to wrap key data.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::wrapCryptoKey):
+        (WebKit::WebPageProxy::unwrapCryptoKey):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::wrapCryptoKey):
+        (WebKit::WebPageProxy::unwrapCryptoKey):
+
</ins><span class="cx"> 2014-02-12  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -4479,19 +4479,17 @@
</span><span class="cx">         m_process-&gt;send(Messages::WebPage::SetScrollPinningBehavior(pinning), m_pageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(SUBTLE_CRYPTO)
</del><ins>+#if ENABLE(SUBTLE_CRYPTO) &amp;&amp; !PLATFORM(COCOA)
</ins><span class="cx"> void WebPageProxy::wrapCryptoKey(const Vector&lt;uint8_t&gt;&amp; key, bool&amp; succeeded, Vector&lt;uint8_t&gt;&amp; wrappedKey)
</span><span class="cx"> {
</span><del>-    // FIXME: Implement.
-    wrappedKey = key;
-    succeeded = true;
</del><ins>+    notImplemented();
+    succeeded = false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::unwrapCryptoKey(const Vector&lt;uint8_t&gt;&amp; wrappedKey, bool&amp; succeeded, Vector&lt;uint8_t&gt;&amp; key)
</span><span class="cx"> {
</span><del>-    // FIXME: Implement.
-    key = wrappedKey;
-    succeeded = true;
</del><ins>+    notImplemented();
+    succeeded = false;
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebPageProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (163975 => 163976)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-02-12 20:40:17 UTC (rev 163975)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-02-12 21:08:40 UTC (rev 163976)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> #import &lt;WebCore/DictationAlternative.h&gt;
</span><span class="cx"> #import &lt;WebCore/GraphicsLayer.h&gt;
</span><span class="cx"> #import &lt;WebCore/RuntimeApplicationChecks.h&gt;
</span><ins>+#import &lt;WebCore/SerializedCryptoKeyWrap.h&gt;
</ins><span class="cx"> #import &lt;WebCore/SharedBuffer.h&gt;
</span><span class="cx"> #import &lt;WebCore/TextAlternativeWithRange.h&gt;
</span><span class="cx"> #import &lt;WebCore/UserAgent.h&gt;
</span><span class="lines">@@ -572,4 +573,20 @@
</span><span class="cx">     [[NSWorkspace sharedWorkspace] openFile:pdfFilename];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(SUBTLE_CRYPTO)
+void WebPageProxy::wrapCryptoKey(const Vector&lt;uint8_t&gt;&amp; key, bool&amp; succeeded, Vector&lt;uint8_t&gt;&amp; wrappedKey)
+{
+    Vector&lt;uint8_t&gt; masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    succeeded = wrapSerializedCryptoKey(masterKey, key, wrappedKey);
+}
+
+void WebPageProxy::unwrapCryptoKey(const Vector&lt;uint8_t&gt;&amp; wrappedKey, bool&amp; succeeded, Vector&lt;uint8_t&gt;&amp; key)
+{
+    Vector&lt;uint8_t&gt; masterKey(16);
+    memset(masterKey.data(), 0, masterKey.size()); // FIXME: Not implemented yet, will be getting a key from client.
+    succeeded = unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
+}
+#endif
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>