<!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>[199401] trunk/Source/WebKit2</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/199401">199401</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2016-04-12 19:29:23 -0700 (Tue, 12 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/198933">r198933</a>): Unable to login to Google account from Internet Accounts preference pane
https://bugs.webkit.org/show_bug.cgi?id=156447
&lt;rdar://problem/25628133&gt;

Reviewed by Darin Adler.

Reverts the workaround landed in <a href="http://trac.webkit.org/projects/webkit/changeset/199301">r199301</a> and teaches ProcessLauncherMac to use the code
signing identifier of the UI process as the client-identifier if it is signed. Otherwise,
we fall back to using the main bundle identifier or _NSGetProgname() depending on whether
the UI process has an associated app bundle.

* PlatformMac.cmake: Add file Shared/mac/CodeSigning.mm.
* Shared/mac/ChildProcessMac.mm:
(WebKit::ChildProcess::initializeSandbox):
(WebKit::codeSigningIdentifierForProcess): Deleted; moved from here to file Shared/mac/CodeSigning.mm.
* Shared/mac/CodeSigning.h: Added.
* Shared/mac/CodeSigning.mm: Added.
(WebKit::secCodeForCurrentProcess): Added.
(WebKit::secCodeForProcess): Added.
(WebKit::secCodeSigningInformation): Added.
(WebKit::appleSignedOrMacAppStoreSignedOrAppleDeveloperSignedRequirement): Added.
(WebKit::secCodeSigningIdentifier): Added.
(WebKit::codeSigningIdentifier): Returns the code signing identifier for the current process.
(WebKit::codeSigningIdentifierForProcess): Moved from file Shared/mac/ChildProcessMac.mm. Extracted logic
into various helper functions (above) so that it can be shared with WebKit::codeSigningIdentifier() as
well as to improve the readability of the code. Removed the OSStatus out argument that was used by callers
for logging purposes and moved such logging responsibility into WebKit::secCodeSigningIdentifier() as
a release assertion message since we always want to log this error when code signing validation fails. We
use a release assertion to cause a noticeable crash because we such failures should not occur and if they
do then we want to see crash reports so that we can handle such failures. Using a release assertion for
validation failures also simplifies the possible return values of this function as such failures represented
the only case where this function would return an empty string. We now return either a null string or a non-
empty string. We return a null string when the specified process is either unsigned or signed by a third-party;
otherwise, we return a non-empty string that represents the code signing identifier.
* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::connectToService): Use the code signing identifier for the client-identifier if we have one (e.g.
we are signed app). If we do not have a code signing identifier then take client-identifier to be the
bundle identifier of our main bundle. Failing that we take client-identifier to be _NSGetProgname().
* WebKit2.xcodeproj/project.pbxproj: Add files Shared/mac/CodeSigning.{h, mm}.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformMaccmake">trunk/Source/WebKit2/PlatformMac.cmake</a></li>
<li><a href="#trunkSourceWebKit2SharedmacChildProcessMacmm">trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessLaunchermacProcessLauncherMacmm">trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2SharedmacCodeSigningh">trunk/Source/WebKit2/Shared/mac/CodeSigning.h</a></li>
<li><a href="#trunkSourceWebKit2SharedmacCodeSigningmm">trunk/Source/WebKit2/Shared/mac/CodeSigning.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (199400 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-04-13 01:31:52 UTC (rev 199400)
+++ trunk/Source/WebKit2/ChangeLog        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -1,3 +1,45 @@
</span><ins>+2016-04-12  Daniel Bates  &lt;dabates@apple.com&gt;
+
+        REGRESSION (r198933): Unable to login to Google account from Internet Accounts preference pane
+        https://bugs.webkit.org/show_bug.cgi?id=156447
+        &lt;rdar://problem/25628133&gt;
+
+        Reviewed by Darin Adler.
+
+        Reverts the workaround landed in r199301 and teaches ProcessLauncherMac to use the code
+        signing identifier of the UI process as the client-identifier if it is signed. Otherwise,
+        we fall back to using the main bundle identifier or _NSGetProgname() depending on whether
+        the UI process has an associated app bundle.
+
+        * PlatformMac.cmake: Add file Shared/mac/CodeSigning.mm.
+        * Shared/mac/ChildProcessMac.mm:
+        (WebKit::ChildProcess::initializeSandbox):
+        (WebKit::codeSigningIdentifierForProcess): Deleted; moved from here to file Shared/mac/CodeSigning.mm.
+        * Shared/mac/CodeSigning.h: Added.
+        * Shared/mac/CodeSigning.mm: Added.
+        (WebKit::secCodeForCurrentProcess): Added.
+        (WebKit::secCodeForProcess): Added.
+        (WebKit::secCodeSigningInformation): Added.
+        (WebKit::appleSignedOrMacAppStoreSignedOrAppleDeveloperSignedRequirement): Added.
+        (WebKit::secCodeSigningIdentifier): Added.
+        (WebKit::codeSigningIdentifier): Returns the code signing identifier for the current process.
+        (WebKit::codeSigningIdentifierForProcess): Moved from file Shared/mac/ChildProcessMac.mm. Extracted logic
+        into various helper functions (above) so that it can be shared with WebKit::codeSigningIdentifier() as
+        well as to improve the readability of the code. Removed the OSStatus out argument that was used by callers
+        for logging purposes and moved such logging responsibility into WebKit::secCodeSigningIdentifier() as
+        a release assertion message since we always want to log this error when code signing validation fails. We
+        use a release assertion to cause a noticeable crash because we such failures should not occur and if they
+        do then we want to see crash reports so that we can handle such failures. Using a release assertion for
+        validation failures also simplifies the possible return values of this function as such failures represented
+        the only case where this function would return an empty string. We now return either a null string or a non-
+        empty string. We return a null string when the specified process is either unsigned or signed by a third-party;
+        otherwise, we return a non-empty string that represents the code signing identifier.
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::connectToService): Use the code signing identifier for the client-identifier if we have one (e.g.
+        we are signed app). If we do not have a code signing identifier then take client-identifier to be the
+        bundle identifier of our main bundle. Failing that we take client-identifier to be _NSGetProgname().
+        * WebKit2.xcodeproj/project.pbxproj: Add files Shared/mac/CodeSigning.{h, mm}.
+
</ins><span class="cx"> 2016-04-12  Enrica Casucci  &lt;enrica@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Should retrieve text surrounding the selection when performing lookup.
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformMaccmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PlatformMac.cmake (199400 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PlatformMac.cmake        2016-04-13 01:31:52 UTC (rev 199400)
+++ trunk/Source/WebKit2/PlatformMac.cmake        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -122,6 +122,7 @@
</span><span class="cx">     Shared/mac/ArgumentCodersMac.mm
</span><span class="cx">     Shared/mac/AttributedString.mm
</span><span class="cx">     Shared/mac/ChildProcessMac.mm
</span><ins>+    Shared/mac/CodeSigning.mm
</ins><span class="cx">     Shared/mac/ColorSpaceData.mm
</span><span class="cx">     Shared/mac/CookieStorageShim.mm
</span><span class="cx">     Shared/mac/CookieStorageShimLibrary.cpp
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacChildProcessMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm (199400 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm        2016-04-13 01:31:52 UTC (rev 199400)
+++ trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> #import &quot;ChildProcess.h&quot;
</span><span class="cx"> 
</span><ins>+#import &quot;CodeSigning.h&quot;
</ins><span class="cx"> #import &quot;SandboxInitializationParameters.h&quot;
</span><span class="cx"> #import &quot;WebKitSystemInterface.h&quot;
</span><span class="cx"> #import &lt;WebCore/CFNetworkSPI.h&gt;
</span><span class="lines">@@ -38,7 +39,6 @@
</span><span class="cx"> #import &lt;pwd.h&gt;
</span><span class="cx"> #import &lt;stdlib.h&gt;
</span><span class="cx"> #import &lt;sysexits.h&gt;
</span><del>-#import &lt;wtf/cf/TypeCastsCF.h&gt;
</del><span class="cx"> #import &lt;wtf/spi/darwin/SandboxSPI.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="lines">@@ -78,39 +78,6 @@
</span><span class="cx">     [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static String codeSigningIdentifierForProcess(pid_t pid, OSStatus&amp; errorCode)
-{
-    RetainPtr&lt;CFNumberRef&gt; pidCFNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &amp;pid));
-    const void* keys[] = { kSecGuestAttributePid };
-    const void* values[] = { pidCFNumber.get() };
-    RetainPtr&lt;CFDictionaryRef&gt; attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks));
-    SecCodeRef code = nullptr;
-    if ((errorCode = SecCodeCopyGuestWithAttributes(nullptr, attributes.get(), kSecCSDefaultFlags, &amp;code)))
-        return String();
-    RetainPtr&lt;SecCodeRef&gt; codePtr = adoptCF(code);
-    RELEASE_ASSERT(codePtr);
-
-    CFStringRef macAppStoreSignedOrAppleDeveloperSignedRequirement = CFSTR(&quot;(anchor apple generic and certificate leaf[field.1.2.840.113635.100.6.1.9]) or (anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] and certificate leaf[field.1.2.840.113635.100.6.1.13])&quot;);
-    SecRequirementRef signingRequirement = nullptr;
-    RELEASE_ASSERT(!SecRequirementCreateWithString(macAppStoreSignedOrAppleDeveloperSignedRequirement, kSecCSDefaultFlags, &amp;signingRequirement));
-    RetainPtr&lt;SecRequirementRef&gt; signingRequirementPtr = adoptCF(signingRequirement);
-    errorCode = SecCodeCheckValidity(codePtr.get(), kSecCSDefaultFlags, signingRequirementPtr.get());
-    if (errorCode == errSecCSUnsigned || errorCode == errSecCSReqFailed)
-        return String(); // Unsigned, signed by Apple, or signed by a third-party
-    if (errorCode != errSecSuccess)
-        return emptyString(); // e.g. invalid/malformed signature
-    String codeSigningIdentifier;
-    CFDictionaryRef signingInfo = nullptr;
-    RELEASE_ASSERT(!SecCodeCopySigningInformation(codePtr.get(), kSecCSDefaultFlags, &amp;signingInfo));
-    RetainPtr&lt;CFDictionaryRef&gt; signingInfoPtr = adoptCF(signingInfo);
-    if (CFDictionaryRef plist = dynamic_cf_cast&lt;CFDictionaryRef&gt;(CFDictionaryGetValue(signingInfoPtr.get(), kSecCodeInfoPList)))
-        codeSigningIdentifier = String(dynamic_cf_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(plist, kCFBundleIdentifierKey)));
-    else
-        codeSigningIdentifier = String(dynamic_cf_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(signingInfoPtr.get(), kSecCodeInfoIdentifier)));
-    RELEASE_ASSERT(!codeSigningIdentifier.isEmpty());
-    return codeSigningIdentifier;
-}
-
</del><span class="cx"> void ChildProcess::initializeSandbox(const ChildProcessInitializationParameters&amp; parameters, SandboxInitializationParameters&amp; sandboxParameters)
</span><span class="cx"> {
</span><span class="cx">     NSBundle *webkit2Bundle = [NSBundle bundleForClass:NSClassFromString(@&quot;WKView&quot;)];
</span><span class="lines">@@ -210,11 +177,10 @@
</span><span class="cx"> 
</span><span class="cx">     if (willUseUserDirectorySuffixInitializationParameter)
</span><span class="cx">         return;
</span><del>-    error = noErr;
-    String clientCodeSigningIdentifier = codeSigningIdentifierForProcess(xpc_connection_get_pid(parameters.connectionIdentifier.xpcConnection.get()), error);
</del><ins>+    String clientCodeSigningIdentifier = codeSigningIdentifierForProcess(xpc_connection_get_pid(parameters.connectionIdentifier.xpcConnection.get()));
</ins><span class="cx">     bool isClientCodeSigned = !clientCodeSigningIdentifier.isNull();
</span><span class="cx">     if (isClientCodeSigned &amp;&amp; clientCodeSigningIdentifier != parameters.clientIdentifier) {
</span><del>-        WTFLogAlways(&quot;%s: Code signing identifier of client differs from passed client identifier: %ld\n&quot;, getprogname(), static_cast&lt;long&gt;(error));
</del><ins>+        WTFLogAlways(&quot;%s: Code signing identifier of client differs from passed client identifier.\n&quot;, getprogname());
</ins><span class="cx">         exit(EX_NOPERM);
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacCodeSigningh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/mac/CodeSigning.h (0 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/CodeSigning.h                                (rev 0)
+++ trunk/Source/WebKit2/Shared/mac/CodeSigning.h        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include &lt;wtf/Forward.h&gt;
+
+namespace WebKit {
+
+// These functions return a null string if the process is either unsigned or signed by a third-party.
+String codeSigningIdentifier();
+String codeSigningIdentifierForProcess(pid_t);
+
+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedmacCodeSigningmm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/mac/CodeSigning.mm (0 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/CodeSigning.mm                                (rev 0)
+++ trunk/Source/WebKit2/Shared/mac/CodeSigning.mm        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -0,0 +1,100 @@
</span><ins>+/*
+ * Copyright (C) 2016 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;CodeSigning.h&quot;
+
+#if PLATFORM(MAC)
+
+#include &lt;Security/Security.h&gt;
+#include &lt;wtf/RetainPtr.h&gt;
+#include &lt;wtf/cf/TypeCastsCF.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+namespace WebKit {
+
+static RetainPtr&lt;SecCodeRef&gt; secCodeForCurrentProcess()
+{
+    SecCodeRef code = nullptr;
+    RELEASE_ASSERT(!SecCodeCopySelf(kSecCSDefaultFlags, &amp;code));
+    return adoptCF(code);
+}
+
+static RetainPtr&lt;SecCodeRef&gt; secCodeForProcess(pid_t pid)
+{
+    RetainPtr&lt;CFNumberRef&gt; pidCFNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &amp;pid));
+    const void* keys[] = { kSecGuestAttributePid };
+    const void* values[] = { pidCFNumber.get() };
+    RetainPtr&lt;CFDictionaryRef&gt; attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks));
+    SecCodeRef code = nullptr;
+    RELEASE_ASSERT(!SecCodeCopyGuestWithAttributes(nullptr, attributes.get(), kSecCSDefaultFlags, &amp;code));
+    return adoptCF(code);
+}
+
+static RetainPtr&lt;CFDictionaryRef&gt; secCodeSigningInformation(SecCodeRef code)
+{
+    CFDictionaryRef signingInfo = nullptr;
+    RELEASE_ASSERT(!SecCodeCopySigningInformation(code, kSecCSDefaultFlags, &amp;signingInfo));
+    return adoptCF(signingInfo);
+}
+
+static RetainPtr&lt;SecRequirementRef&gt; appleSignedOrMacAppStoreSignedOrAppleDeveloperSignedRequirement()
+{
+    CFStringRef requirement = CFSTR(&quot;(anchor apple) or (anchor apple generic and certificate leaf[field.1.2.840.113635.100.6.1.9]) or (anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] and certificate leaf[field.1.2.840.113635.100.6.1.13])&quot;);
+    SecRequirementRef signingRequirement = nullptr;
+    RELEASE_ASSERT(!SecRequirementCreateWithString(requirement, kSecCSDefaultFlags, &amp;signingRequirement));
+    return adoptCF(signingRequirement);
+}
+
+static String secCodeSigningIdentifier(SecCodeRef code)
+{
+    RetainPtr&lt;SecRequirementRef&gt; signingRequirement = appleSignedOrMacAppStoreSignedOrAppleDeveloperSignedRequirement();
+    OSStatus errorCode = SecCodeCheckValidity(code, kSecCSDefaultFlags, signingRequirement.get());
+    if (errorCode == errSecCSUnsigned || errorCode == errSecCSReqFailed)
+        return String(); // Unsigned or signed by a third-party
+    RELEASE_ASSERT_WITH_MESSAGE(!errorCode, &quot;SecCodeCheckValidity() failed with error: %ld&quot;, static_cast&lt;long&gt;(errorCode));
+    String codeSigningIdentifier;
+    RetainPtr&lt;CFDictionaryRef&gt; signingInfo = secCodeSigningInformation(code);
+    if (CFDictionaryRef plist = dynamic_cf_cast&lt;CFDictionaryRef&gt;(CFDictionaryGetValue(signingInfo.get(), kSecCodeInfoPList)))
+        codeSigningIdentifier = dynamic_cf_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(plist, kCFBundleIdentifierKey));
+    else
+        codeSigningIdentifier = dynamic_cf_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(signingInfo.get(), kSecCodeInfoIdentifier));
+    RELEASE_ASSERT(!codeSigningIdentifier.isEmpty());
+    return codeSigningIdentifier;
+}
+
+String codeSigningIdentifier()
+{
+    return secCodeSigningIdentifier(secCodeForCurrentProcess().get());
+}
+
+String codeSigningIdentifierForProcess(pid_t pid)
+{
+    return secCodeSigningIdentifier(secCodeForProcess(pid).get());
+}
+    
+} // namespace WebKit
+
+#endif // PLATFORM(MAC)
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessLaunchermacProcessLauncherMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (199400 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm        2016-04-13 01:31:52 UTC (rev 199400)
+++ trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -44,6 +44,10 @@
</span><span class="cx"> #import &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #import &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(MAC)
+#import &quot;CodeSigning.h&quot;
+#endif
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> typedef void (ProcessLauncher::*DidFinishLaunchingProcessFunction)(pid_t, IPC::Connection::Identifier);
</span><span class="lines">@@ -136,8 +140,12 @@
</span><span class="cx">     // Insert a send right so we can send to it.
</span><span class="cx">     mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
</span><span class="cx"> 
</span><del>-    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
-    CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
</del><ins>+    String clientIdentifier;
+#if PLATFORM(MAC)
+    clientIdentifier = codeSigningIdentifier();
+#endif
+    if (clientIdentifier.isNull())
+        clientIdentifier = [[NSBundle mainBundle] bundleIdentifier];
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
</span><span class="cx">     auto bootstrapMessage = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
</span><span class="lines">@@ -146,7 +154,7 @@
</span><span class="cx">     xpc_dictionary_set_mach_send(bootstrapMessage.get(), &quot;server-port&quot;, listeningPort);
</span><span class="cx">     mach_port_deallocate(mach_task_self(), listeningPort);
</span><span class="cx"> 
</span><del>-    xpc_dictionary_set_string(bootstrapMessage.get(), &quot;client-identifier&quot;, clientIdentifier.data());
</del><ins>+    xpc_dictionary_set_string(bootstrapMessage.get(), &quot;client-identifier&quot;, !clientIdentifier.isEmpty() ? clientIdentifier.utf8().data() : *_NSGetProgname());
</ins><span class="cx">     xpc_dictionary_set_string(bootstrapMessage.get(), &quot;ui-process-name&quot;, [[[NSProcessInfo processInfo] processName] UTF8String]);
</span><span class="cx"> 
</span><span class="cx">     if (forDevelopment) {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (199400 => 199401)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-04-13 01:31:52 UTC (rev 199400)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-04-13 02:29:23 UTC (rev 199401)
</span><span class="lines">@@ -1711,6 +1711,8 @@
</span><span class="cx">                 CDC3831017212440008A2FC3 /* CookieStorageShim.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC3830D1721242D008A2FC3 /* CookieStorageShim.mm */; };
</span><span class="cx">                 CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */; };
</span><span class="cx">                 CDCA85C9132ABA4E00E961DF /* WKFullScreenWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */; };
</span><ins>+                CE11AD501CBC47F800681EE5 /* CodeSigning.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */; };
+                CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */ = {isa = PBXBuildFile; fileRef = CE11AD511CBC482F00681EE5 /* CodeSigning.h */; };
</ins><span class="cx">                 CE1A0BD21A48E6C60054EF74 /* AssertionServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BCC1A48E6C60054EF74 /* AssertionServicesSPI.h */; };
</span><span class="cx">                 CE1A0BD31A48E6C60054EF74 /* CorePDFSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BCD1A48E6C60054EF74 /* CorePDFSPI.h */; };
</span><span class="cx">                 CE1A0BD41A48E6C60054EF74 /* DataDetectorsUISPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BCE1A48E6C60054EF74 /* DataDetectorsUISPI.h */; };
</span><span class="lines">@@ -3786,6 +3788,8 @@
</span><span class="cx">                 CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKFullScreenWindowController.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFullScreenWindowController.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CDCA85D4132AC2B300E961DF /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><ins>+                CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CodeSigning.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
+                CE11AD511CBC482F00681EE5 /* CodeSigning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeSigning.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CE1A0BCC1A48E6C60054EF74 /* AssertionServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AssertionServicesSPI.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CE1A0BCD1A48E6C60054EF74 /* CorePDFSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CorePDFSPI.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CE1A0BCE1A48E6C60054EF74 /* DataDetectorsUISPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsUISPI.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -6223,6 +6227,8 @@
</span><span class="cx">                                 E1A31731134CEA6C007C9A4F /* AttributedString.h */,
</span><span class="cx">                                 E1A31734134CEA80007C9A4F /* AttributedString.mm */,
</span><span class="cx">                                 9F54F88E16488E87007DF81A /* ChildProcessMac.mm */,
</span><ins>+                                CE11AD511CBC482F00681EE5 /* CodeSigning.h */,
+                                CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */,
</ins><span class="cx">                                 1A2A4AFE158693920090C9E9 /* ColorSpaceData.h */,
</span><span class="cx">                                 1A2A4AFD158693920090C9E9 /* ColorSpaceData.mm */,
</span><span class="cx">                                 CDC3830E1721242D008A2FC3 /* CookieStorageShim.h */,
</span><span class="lines">@@ -7319,6 +7325,7 @@
</span><span class="cx">                                 51FAEC3A1B0657630009C4E7 /* ChildProcessMessages.h in Headers */,
</span><span class="cx">                                 E1513C67166EABB200149FCB /* ChildProcessProxy.h in Headers */,
</span><span class="cx">                                 290F4272172A0C7400939FF0 /* ChildProcessSupplement.h in Headers */,
</span><ins>+                                CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */,
</ins><span class="cx">                                 1A6F9F9011E13EFC00DB1371 /* CommandLine.h in Headers */,
</span><span class="cx">                                 37BEC4E119491486008B4286 /* CompletionHandlerCallChecker.h in Headers */,
</span><span class="cx">                                 37C4E9F6131C6E7E0029BD5A /* config.h in Headers */,
</span><span class="lines">@@ -8761,6 +8768,7 @@
</span><span class="cx">                                 9F54F88F16488E87007DF81A /* ChildProcessMac.mm in Sources */,
</span><span class="cx">                                 51FAEC3B1B0657680009C4E7 /* ChildProcessMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 E1513C66166EABB200149FCB /* ChildProcessProxy.cpp in Sources */,
</span><ins>+                                CE11AD501CBC47F800681EE5 /* CodeSigning.mm in Sources */,
</ins><span class="cx">                                 1A2A4B0E1586A2240090C9E9 /* ColorSpaceData.mm in Sources */,
</span><span class="cx">                                 1A6F9FB711E1408500DB1371 /* CommandLinePOSIX.cpp in Sources */,
</span><span class="cx">                                 37BEC4E019491486008B4286 /* CompletionHandlerCallChecker.mm in Sources */,
</span></span></pre>
</div>
</div>

</body>
</html>