<!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>[164181] trunk/Source</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/164181">164181</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2014-02-15 15:26:21 -0800 (Sat, 15 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Mac] All WebKit clients should encrypt WebCrypto keys automatically
https://bugs.webkit.org/show_bug.cgi?id=128852

Reviewed by Oliver Hunt.

Source/WebCore: 

Install a persistent master key in Keychain on first use of WebCrypto key serialization.
The key is per application, protected with ACL.

* English.lproj/Localizable.strings:
* WebCore.exp.in:
* crypto/SerializedCryptoKeyWrap.h:
* crypto/mac/SerializedCryptoKeyWrapMac.mm:
(WebCore::masterKeyAccountNameForCurrentApplication):
(WebCore::getDefaultWebCryptoMasterKey):
(WebCore::createAndStoreMasterKey):
(WebCore::findMasterKey):
* platform/LocalizedStrings.cpp:
(WebCore::webCryptoMasterKeyKeychainLabel):
(WebCore::webCryptoMasterKeyKeychainComment):
* platform/LocalizedStrings.h:

Source/WebKit/mac: 

* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::wrapCryptoKey):
(WebChromeClient::unwrapCryptoKey):
Call the default implementation if key is not provided by a client.

Source/WebKit2: 

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::wrapCryptoKey):
(WebKit::WebPageProxy::unwrapCryptoKey):
Call the default implementation if key is not provided by a client.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreEnglishlprojLocalizablestrings">trunk/Source/WebCore/English.lproj/Localizable.strings</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</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>
<li><a href="#trunkSourceWebCoreplatformLocalizedStringscpp">trunk/Source/WebCore/platform/LocalizedStrings.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformLocalizedStringsh">trunk/Source/WebCore/platform/LocalizedStrings.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>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/ChangeLog        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2014-02-15  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        [Mac] All WebKit clients should encrypt WebCrypto keys automatically
+        https://bugs.webkit.org/show_bug.cgi?id=128852
+
+        Reviewed by Oliver Hunt.
+
+        Install a persistent master key in Keychain on first use of WebCrypto key serialization.
+        The key is per application, protected with ACL.
+
+        * English.lproj/Localizable.strings:
+        * WebCore.exp.in:
+        * crypto/SerializedCryptoKeyWrap.h:
+        * crypto/mac/SerializedCryptoKeyWrapMac.mm:
+        (WebCore::masterKeyAccountNameForCurrentApplication):
+        (WebCore::getDefaultWebCryptoMasterKey):
+        (WebCore::createAndStoreMasterKey):
+        (WebCore::findMasterKey):
+        * platform/LocalizedStrings.cpp:
+        (WebCore::webCryptoMasterKeyKeychainLabel):
+        (WebCore::webCryptoMasterKeyKeychainComment):
+        * platform/LocalizedStrings.h:
+
</ins><span class="cx"> 2014-02-15  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         computeSelectionStart and computeSelectionEnd shouldn't trigger synchronous layout
</span></span></pre></div>
<a id="trunkSourceWebCoreEnglishlprojLocalizablestrings"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/English.lproj/Localizable.strings (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/English.lproj/Localizable.strings        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/English.lproj/Localizable.strings        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -40,6 +40,9 @@
</span><span class="cx"> /* Visible name of the web process. The argument is the application name. */
</span><span class="cx"> &quot;%@ Web Content&quot; = &quot;%@ Web Content&quot;;
</span><span class="cx"> 
</span><ins>+/* Name of application's single WebCrypto master key in Keychain */
+&quot;%@ WebCrypto Master Key&quot; = &quot;%@ WebCrypto Master Key&quot;;
+
</ins><span class="cx"> /* Label to describe the number of files selected in a file upload control that allows multiple files */
</span><span class="cx"> &quot;%d files&quot; = &quot;%d files&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -595,6 +598,9 @@
</span><span class="cx"> /* Undo action name */
</span><span class="cx"> &quot;Use Standard Ligatures (Undo action name)&quot; = &quot;Use Standard Ligatures&quot;;
</span><span class="cx"> 
</span><ins>+/* Description of WebCrypto master keys in Keychain */
+&quot;Used to encrypt WebCrypto keys in persistent storage, such as IndexedDB&quot; = &quot;Used to encrypt WebCrypto keys in persistent storage, such as IndexedDB&quot;;
+
</ins><span class="cx"> /* Web Inspector window title */
</span><span class="cx"> &quot;Web Inspector — %@&quot; = &quot;Web Inspector — %@&quot;;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -2625,6 +2625,7 @@
</span><span class="cx"> _wkCTFontTransformGlyphs
</span><span class="cx"> __ZN7WebCore23wrapSerializedCryptoKeyERKN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEES5_RS3_
</span><span class="cx"> __ZN7WebCore25unwrapSerializedCryptoKeyERKN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEES5_RS3_
</span><ins>+__ZN7WebCore28getDefaultWebCryptoMasterKeyERN3WTF6VectorIhLm0ENS0_15CrashOnOverflowEEE
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(3D_RENDERING)
</span></span></pre></div>
<a id="trunkSourceWebCorecryptoSerializedCryptoKeyWraph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/crypto/SerializedCryptoKeyWrap.h        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -33,6 +33,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+bool getDefaultWebCryptoMasterKey(Vector&lt;uint8_t&gt;&amp;);
+
</ins><span class="cx"> 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);
</span><span class="cx"> 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);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecryptomacSerializedCryptoKeyWrapMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -29,9 +29,12 @@
</span><span class="cx"> #if ENABLE(SUBTLE_CRYPTO)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CommonCryptoUtilities.h&quot;
</span><ins>+#include &quot;LocalizedStrings.h&quot;
</ins><span class="cx"> #include &lt;CommonCrypto/CommonSymmetricKeywrap.h&gt;
</span><ins>+#include &lt;wtf/text/Base64.h&gt;
</ins><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #include &lt;wtf/CryptographicUtilities.h&gt;
</span><ins>+#include &lt;wtf/RetainPtr.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -42,6 +45,8 @@
</span><span class="cx"> const NSString* encryptedKeyKey = @&quot;encryptedKey&quot;;
</span><span class="cx"> const NSString* tagKey = @&quot;tag&quot;;
</span><span class="cx"> 
</span><ins>+const size_t masterKeySizeInBytes = 16;
+
</ins><span class="cx"> inline Vector&lt;uint8_t&gt; vectorFromNSData(NSData* data)
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;uint8_t&gt; result;
</span><span class="lines">@@ -49,6 +54,109 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+
+bool getDefaultWebCryptoMasterKey(Vector&lt;uint8_t&gt;&amp; masterKey)
+{
+    // FIXME: Implement.
+    masterKey.resize(masterKeySizeInBytes);
+    memset(masterKey.data(), 0, masterKey.size());
+    return true;
+}
+
+#else
+
+static NSString* masterKeyAccountNameForCurrentApplication()
+{
+    return [NSString stringWithFormat:@&quot;com.apple.WebKit.WebCrypto.master+%@&quot;, [[NSRunningApplication currentApplication] bundleIdentifier]];
+}
+
+static bool createAndStoreMasterKey(Vector&lt;uint8_t&gt;&amp; masterKeyData)
+{
+    masterKeyData.resize(masterKeySizeInBytes);
+    CCRandomCopyBytes(kCCRandomDefault, masterKeyData.data(), masterKeyData.size());
+
+    NSString *localizedItemName = webCryptoMasterKeyKeychainLabel([[NSRunningApplication currentApplication] localizedName]);
+
+    SecAccessRef accessRef;
+    OSStatus status = SecAccessCreate((CFStringRef)localizedItemName, nullptr, &amp;accessRef);
+    if (status) {
+        WTFLogAlways(&quot;Cannot create a security access object for storing WebCrypto master key, error %d&quot;, (int)status);
+        return nullptr;
+    }
+    RetainPtr&lt;SecAccessRef&gt; access = adoptCF(accessRef);
+
+    RetainPtr&lt;CFArrayRef&gt; acls = adoptCF(SecAccessCopyMatchingACLList(accessRef, kSecACLAuthorizationExportClear));
+    SecACLRef acl = (SecACLRef)CFArrayGetValueAtIndex(acls.get(), 0);
+
+    SecTrustedApplicationRef trustedAppRef;
+    status = SecTrustedApplicationCreateFromPath(0, &amp;trustedAppRef);
+    if (status) {
+        WTFLogAlways(&quot;Cannot create a trusted application object for storing WebCrypto master key, error %d&quot;, (int)status);
+        return nullptr;
+    }
+    RetainPtr&lt;SecTrustedApplicationRef&gt; trustedApp = adoptCF(trustedAppRef);
+
+    status = SecACLSetContents(acl, (CFArrayRef)@[ (id)trustedApp.get() ], (CFStringRef)localizedItemName, kSecKeychainPromptRequirePassphase);
+    if (status) {
+        WTFLogAlways(&quot;Cannot set ACL for WebCrypto master key, error %d&quot;, (int)status);
+        return nullptr;
+    }
+
+    Vector&lt;char&gt; base64EncodedMasterKeyData;
+    base64Encode(masterKeyData, base64EncodedMasterKeyData);
+
+    // Cannot use kSecClassKey because of &lt;rdar://problem/16068207&gt;.
+    NSDictionary *attributes = @{
+        (id)kSecClass : (id)kSecClassGenericPassword,
+        (id)kSecAttrSynchronizable : @NO,
+        (id)kSecAttrIsPermanent : @YES,
+        (id)kSecAttrAccess : (id)access.get(),
+        (id)kSecAttrComment : webCryptoMasterKeyKeychainComment(),
+        (id)kSecAttrLabel : localizedItemName,
+        (id)kSecAttrAccount : masterKeyAccountNameForCurrentApplication(),
+        (id)kSecValueData : [NSData dataWithBytes:base64EncodedMasterKeyData.data() length:base64EncodedMasterKeyData.size()],
+    };
+
+    status = SecItemAdd((CFDictionaryRef)attributes, nullptr);
+    if (status) {
+        WTFLogAlways(&quot;Cannot store WebCrypto master key, error %d&quot;, (int)status);
+        return nullptr;
+    }
+    return true;
+}
+
+static bool findMasterKey(Vector&lt;uint8_t&gt;&amp; masterKeyData)
+{
+    NSDictionary *query = @{
+        (id)kSecClass : (id)kSecClassGenericPassword,
+        (id)kSecAttrAccount : masterKeyAccountNameForCurrentApplication(),
+        (id)kSecReturnData : @YES,
+    };
+
+    CFDataRef keyDataRef;
+    OSStatus status = SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef*)&amp;keyDataRef);
+    if (status) {
+        if (status != errSecItemNotFound &amp;&amp; status != errSecUserCanceled)
+            WTFLogAlways(&quot;Could not find WebCrypto master key in Keychain, error %d&quot;, (int)status);
+        return false;
+    }
+    RetainPtr&lt;CFDataRef&gt; keyData = adoptCF(keyDataRef);
+
+    Vector&lt;uint8_t&gt; base64EncodedMasterKeyData = vectorFromNSData((NSData *)keyData.get());
+    return base64Decode((const char*)base64EncodedMasterKeyData.data(), base64EncodedMasterKeyData.size(), masterKeyData);
+}
+
+bool getDefaultWebCryptoMasterKey(Vector&lt;uint8_t&gt;&amp; masterKey)
+{
+    if (!findMasterKey(masterKey) &amp;&amp; !createAndStoreMasterKey(masterKey))
+        return false;
+    RELEASE_ASSERT(masterKey.size() == masterKeySizeInBytes);
+    return true;
+}
+
+#endif
+
</ins><span class="cx"> 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)
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;uint8_t&gt; kek(16);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformLocalizedStringscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/LocalizedStrings.cpp (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/LocalizedStrings.cpp        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/platform/LocalizedStrings.cpp        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -1118,4 +1118,16 @@
</span><span class="cx">     return formatLocalizedString(WEB_UI_STRING(&quot;Show in blocked plug-in&quot;, &quot;Title of the context menu item to show when PDFPlugin was used instead of a blocked plugin&quot;));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(SUBTLE_CRYPTO)
+String webCryptoMasterKeyKeychainLabel(const String&amp; localizedApplicationName)
+{
+    return formatLocalizedString(WEB_UI_STRING(&quot;%@ WebCrypto Master Key&quot;, &quot;Name of application's single WebCrypto master key in Keychain&quot;), localizedApplicationName.createCFString().get());
+}
+
+String webCryptoMasterKeyKeychainComment()
+{
+    return WEB_UI_STRING(&quot;Used to encrypt WebCrypto keys in persistent storage, such as IndexedDB&quot;, &quot;Description of WebCrypto master keys in Keychain&quot;);
+}
+#endif
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformLocalizedStringsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/LocalizedStrings.h (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/LocalizedStrings.h        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebCore/platform/LocalizedStrings.h        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -263,6 +263,11 @@
</span><span class="cx"> 
</span><span class="cx">     String useBlockedPlugInContextMenuTitle();
</span><span class="cx"> 
</span><ins>+#if ENABLE(SUBTLE_CRYPTO)
+    String webCryptoMasterKeyKeychainLabel(const String&amp; localizedApplicationName);
+    String webCryptoMasterKeyKeychainComment();
+#endif
+
</ins><span class="cx"> #define WEB_UI_STRING(string, description) WebCore::localizedString(string)
</span><span class="cx"> #define WEB_UI_STRING_KEY(string, key, description) WebCore::localizedString(key)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-02-15  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        [Mac] All WebKit clients should encrypt WebCrypto keys automatically
+        https://bugs.webkit.org/show_bug.cgi?id=128852
+
+        Reviewed by Oliver Hunt.
+
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::wrapCryptoKey):
+        (WebChromeClient::unwrapCryptoKey):
+        Call the default implementation if key is not provided by a client.
+
</ins><span class="cx"> 2014-02-14  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Control tints don't update inside WebViews
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebChromeClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebChromeClient.mm        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -1002,27 +1002,27 @@
</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><ins>+    Vector&lt;uint8_t&gt; masterKey;
</ins><span class="cx">     SEL selector = @selector(webCryptoMasterKeyForWebView:);
</span><del>-    if (![[m_webView UIDelegate] respondsToSelector:selector])
</del><ins>+    if ([[m_webView UIDelegate] respondsToSelector:selector]) {
+        NSData *keyData = CallUIDelegate(m_webView, selector);
+        masterKey.append((uint8_t*)[keyData bytes], [keyData length]);
+    } else if (!getDefaultWebCryptoMasterKey(masterKey))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    NSData* keyData = CallUIDelegate(m_webView, selector);
-
-    Vector&lt;uint8_t&gt; masterKey;
-    masterKey.append((uint8_t*)[keyData bytes], [keyData length]);
</del><span class="cx">     return wrapSerializedCryptoKey(masterKey, key, wrappedKey);
</span><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><ins>+    Vector&lt;uint8_t&gt; masterKey;
</ins><span class="cx">     SEL selector = @selector(webCryptoMasterKeyForWebView:);
</span><del>-    if (![[m_webView UIDelegate] respondsToSelector:selector])
</del><ins>+    if ([[m_webView UIDelegate] respondsToSelector:selector]) {
+        NSData *keyData = CallUIDelegate(m_webView, selector);
+        masterKey.append((uint8_t*)[keyData bytes], [keyData length]);
+    } else if (!getDefaultWebCryptoMasterKey(masterKey))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    NSData *keyData = CallUIDelegate(m_webView, selector);
-
-    Vector&lt;uint8_t&gt; masterKey;
-    masterKey.append((uint8_t*)[keyData bytes], [keyData length]);
</del><span class="cx">     return unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
</span><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 (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebKit2/ChangeLog        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-02-15  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        [Mac] All WebKit clients should encrypt WebCrypto keys automatically
+        https://bugs.webkit.org/show_bug.cgi?id=128852
+
+        Reviewed by Oliver Hunt.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::wrapCryptoKey):
+        (WebKit::WebPageProxy::unwrapCryptoKey):
+        Call the default implementation if key is not provided by a client.
+
</ins><span class="cx"> 2014-02-15  Raphael Kubo da Costa  &lt;raphael.kubo.da.costa@intel.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL][WK2] Stop calling mktemp(3).
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (164180 => 164181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-02-15 22:32:05 UTC (rev 164180)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-02-15 23:26:21 UTC (rev 164181)
</span><span class="lines">@@ -4483,25 +4483,29 @@
</span><span class="cx"> #if ENABLE(SUBTLE_CRYPTO)
</span><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><ins>+    Vector&lt;uint8_t&gt; masterKey;
</ins><span class="cx">     RefPtr&lt;API::Data&gt; keyData = m_process-&gt;context().client().copyWebCryptoMasterKey(&amp;m_process-&gt;context());
</span><del>-    if (!keyData) {
</del><ins>+    if (keyData)
+        masterKey = keyData-&gt;dataReference().vector();
+    else if (!getDefaultWebCryptoMasterKey(masterKey)) {
</ins><span class="cx">         succeeded = false;
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Vector&lt;uint8_t&gt; masterKey = keyData-&gt;dataReference().vector();
</del><span class="cx">     succeeded = wrapSerializedCryptoKey(masterKey, key, wrappedKey);
</span><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><ins>+    Vector&lt;uint8_t&gt; masterKey;
</ins><span class="cx">     RefPtr&lt;API::Data&gt; keyData = m_process-&gt;context().client().copyWebCryptoMasterKey(&amp;m_process-&gt;context());
</span><del>-    if (!keyData) {
</del><ins>+    if (keyData)
+        masterKey = keyData-&gt;dataReference().vector();
+    else if (!getDefaultWebCryptoMasterKey(masterKey)) {
</ins><span class="cx">         succeeded = false;
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Vector&lt;uint8_t&gt; masterKey = keyData-&gt;dataReference().vector();
</del><span class="cx">     succeeded = unwrapSerializedCryptoKey(masterKey, wrappedKey, key);
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>