Changeset 199401 in webkit


Ignore:
Timestamp:
Apr 12, 2016 7:29:23 PM (8 years ago)
Author:
dbates@webkit.org
Message:

REGRESSION (r198933): Unable to login to Google account from Internet Accounts preference pane
https://bugs.webkit.org/show_bug.cgi?id=156447
<rdar://problem/25628133>

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}.
Location:
trunk/Source/WebKit2
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r199399 r199401  
     12016-04-12  Daniel Bates  <dabates@apple.com>
     2
     3        REGRESSION (r198933): Unable to login to Google account from Internet Accounts preference pane
     4        https://bugs.webkit.org/show_bug.cgi?id=156447
     5        <rdar://problem/25628133>
     6
     7        Reviewed by Darin Adler.
     8
     9        Reverts the workaround landed in r199301 and teaches ProcessLauncherMac to use the code
     10        signing identifier of the UI process as the client-identifier if it is signed. Otherwise,
     11        we fall back to using the main bundle identifier or _NSGetProgname() depending on whether
     12        the UI process has an associated app bundle.
     13
     14        * PlatformMac.cmake: Add file Shared/mac/CodeSigning.mm.
     15        * Shared/mac/ChildProcessMac.mm:
     16        (WebKit::ChildProcess::initializeSandbox):
     17        (WebKit::codeSigningIdentifierForProcess): Deleted; moved from here to file Shared/mac/CodeSigning.mm.
     18        * Shared/mac/CodeSigning.h: Added.
     19        * Shared/mac/CodeSigning.mm: Added.
     20        (WebKit::secCodeForCurrentProcess): Added.
     21        (WebKit::secCodeForProcess): Added.
     22        (WebKit::secCodeSigningInformation): Added.
     23        (WebKit::appleSignedOrMacAppStoreSignedOrAppleDeveloperSignedRequirement): Added.
     24        (WebKit::secCodeSigningIdentifier): Added.
     25        (WebKit::codeSigningIdentifier): Returns the code signing identifier for the current process.
     26        (WebKit::codeSigningIdentifierForProcess): Moved from file Shared/mac/ChildProcessMac.mm. Extracted logic
     27        into various helper functions (above) so that it can be shared with WebKit::codeSigningIdentifier() as
     28        well as to improve the readability of the code. Removed the OSStatus out argument that was used by callers
     29        for logging purposes and moved such logging responsibility into WebKit::secCodeSigningIdentifier() as
     30        a release assertion message since we always want to log this error when code signing validation fails. We
     31        use a release assertion to cause a noticeable crash because we such failures should not occur and if they
     32        do then we want to see crash reports so that we can handle such failures. Using a release assertion for
     33        validation failures also simplifies the possible return values of this function as such failures represented
     34        the only case where this function would return an empty string. We now return either a null string or a non-
     35        empty string. We return a null string when the specified process is either unsigned or signed by a third-party;
     36        otherwise, we return a non-empty string that represents the code signing identifier.
     37        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     38        (WebKit::connectToService): Use the code signing identifier for the client-identifier if we have one (e.g.
     39        we are signed app). If we do not have a code signing identifier then take client-identifier to be the
     40        bundle identifier of our main bundle. Failing that we take client-identifier to be _NSGetProgname().
     41        * WebKit2.xcodeproj/project.pbxproj: Add files Shared/mac/CodeSigning.{h, mm}.
     42
    1432016-04-12  Enrica Casucci  <enrica@apple.com>
    244
  • trunk/Source/WebKit2/PlatformMac.cmake

    r199257 r199401  
    123123    Shared/mac/AttributedString.mm
    124124    Shared/mac/ChildProcessMac.mm
     125    Shared/mac/CodeSigning.mm
    125126    Shared/mac/ColorSpaceData.mm
    126127    Shared/mac/CookieStorageShim.mm
  • trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm

    r199301 r199401  
    2929#import "ChildProcess.h"
    3030
     31#import "CodeSigning.h"
    3132#import "SandboxInitializationParameters.h"
    3233#import "WebKitSystemInterface.h"
     
    3940#import <stdlib.h>
    4041#import <sysexits.h>
    41 #import <wtf/cf/TypeCastsCF.h>
    4242#import <wtf/spi/darwin/SandboxSPI.h>
    4343
     
    7777    initializeTimerCoalescingPolicy();
    7878    [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
    79 }
    80 
    81 static String codeSigningIdentifierForProcess(pid_t pid, OSStatus& errorCode)
    82 {
    83     RetainPtr<CFNumberRef> pidCFNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid));
    84     const void* keys[] = { kSecGuestAttributePid };
    85     const void* values[] = { pidCFNumber.get() };
    86     RetainPtr<CFDictionaryRef> attributes = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    87     SecCodeRef code = nullptr;
    88     if ((errorCode = SecCodeCopyGuestWithAttributes(nullptr, attributes.get(), kSecCSDefaultFlags, &code)))
    89         return String();
    90     RetainPtr<SecCodeRef> codePtr = adoptCF(code);
    91     RELEASE_ASSERT(codePtr);
    92 
    93     CFStringRef macAppStoreSignedOrAppleDeveloperSignedRequirement = CFSTR("(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])");
    94     SecRequirementRef signingRequirement = nullptr;
    95     RELEASE_ASSERT(!SecRequirementCreateWithString(macAppStoreSignedOrAppleDeveloperSignedRequirement, kSecCSDefaultFlags, &signingRequirement));
    96     RetainPtr<SecRequirementRef> signingRequirementPtr = adoptCF(signingRequirement);
    97     errorCode = SecCodeCheckValidity(codePtr.get(), kSecCSDefaultFlags, signingRequirementPtr.get());
    98     if (errorCode == errSecCSUnsigned || errorCode == errSecCSReqFailed)
    99         return String(); // Unsigned, signed by Apple, or signed by a third-party
    100     if (errorCode != errSecSuccess)
    101         return emptyString(); // e.g. invalid/malformed signature
    102     String codeSigningIdentifier;
    103     CFDictionaryRef signingInfo = nullptr;
    104     RELEASE_ASSERT(!SecCodeCopySigningInformation(codePtr.get(), kSecCSDefaultFlags, &signingInfo));
    105     RetainPtr<CFDictionaryRef> signingInfoPtr = adoptCF(signingInfo);
    106     if (CFDictionaryRef plist = dynamic_cf_cast<CFDictionaryRef>(CFDictionaryGetValue(signingInfoPtr.get(), kSecCodeInfoPList)))
    107         codeSigningIdentifier = String(dynamic_cf_cast<CFStringRef>(CFDictionaryGetValue(plist, kCFBundleIdentifierKey)));
    108     else
    109         codeSigningIdentifier = String(dynamic_cf_cast<CFStringRef>(CFDictionaryGetValue(signingInfoPtr.get(), kSecCodeInfoIdentifier)));
    110     RELEASE_ASSERT(!codeSigningIdentifier.isEmpty());
    111     return codeSigningIdentifier;
    11279}
    11380
     
    211178    if (willUseUserDirectorySuffixInitializationParameter)
    212179        return;
    213     error = noErr;
    214     String clientCodeSigningIdentifier = codeSigningIdentifierForProcess(xpc_connection_get_pid(parameters.connectionIdentifier.xpcConnection.get()), error);
     180    String clientCodeSigningIdentifier = codeSigningIdentifierForProcess(xpc_connection_get_pid(parameters.connectionIdentifier.xpcConnection.get()));
    215181    bool isClientCodeSigned = !clientCodeSigningIdentifier.isNull();
    216182    if (isClientCodeSigned && clientCodeSigningIdentifier != parameters.clientIdentifier) {
    217         WTFLogAlways("%s: Code signing identifier of client differs from passed client identifier: %ld\n", getprogname(), static_cast<long>(error));
     183        WTFLogAlways("%s: Code signing identifier of client differs from passed client identifier.\n", getprogname());
    218184        exit(EX_NOPERM);
    219185    }
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r196661 r199401  
    4545#import <wtf/text/WTFString.h>
    4646
     47#if PLATFORM(MAC)
     48#import "CodeSigning.h"
     49#endif
     50
    4751namespace WebKit {
    4852
     
    137141    mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
    138142
    139     NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    140     CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
     143    String clientIdentifier;
     144#if PLATFORM(MAC)
     145    clientIdentifier = codeSigningIdentifier();
     146#endif
     147    if (clientIdentifier.isNull())
     148        clientIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    141149
    142150    // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
     
    147155    mach_port_deallocate(mach_task_self(), listeningPort);
    148156
    149     xpc_dictionary_set_string(bootstrapMessage.get(), "client-identifier", clientIdentifier.data());
     157    xpc_dictionary_set_string(bootstrapMessage.get(), "client-identifier", !clientIdentifier.isEmpty() ? clientIdentifier.utf8().data() : *_NSGetProgname());
    150158    xpc_dictionary_set_string(bootstrapMessage.get(), "ui-process-name", [[[NSProcessInfo processInfo] processName] UTF8String]);
    151159
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r199311 r199401  
    17121712                CDCA85C8132ABA4E00E961DF /* WKFullScreenWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDCA85C6132ABA4E00E961DF /* WKFullScreenWindowController.mm */; };
    17131713                CDCA85C9132ABA4E00E961DF /* WKFullScreenWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */; };
     1714                CE11AD501CBC47F800681EE5 /* CodeSigning.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */; };
     1715                CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */ = {isa = PBXBuildFile; fileRef = CE11AD511CBC482F00681EE5 /* CodeSigning.h */; };
    17141716                CE1A0BD21A48E6C60054EF74 /* AssertionServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BCC1A48E6C60054EF74 /* AssertionServicesSPI.h */; };
    17151717                CE1A0BD31A48E6C60054EF74 /* CorePDFSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BCD1A48E6C60054EF74 /* CorePDFSPI.h */; };
     
    37873789                CDCA85C7132ABA4E00E961DF /* WKFullScreenWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFullScreenWindowController.h; sourceTree = "<group>"; };
    37883790                CDCA85D4132AC2B300E961DF /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
     3791                CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CodeSigning.mm; sourceTree = "<group>"; };
     3792                CE11AD511CBC482F00681EE5 /* CodeSigning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeSigning.h; sourceTree = "<group>"; };
    37893793                CE1A0BCC1A48E6C60054EF74 /* AssertionServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AssertionServicesSPI.h; sourceTree = "<group>"; };
    37903794                CE1A0BCD1A48E6C60054EF74 /* CorePDFSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CorePDFSPI.h; sourceTree = "<group>"; };
     
    62246228                                E1A31734134CEA80007C9A4F /* AttributedString.mm */,
    62256229                                9F54F88E16488E87007DF81A /* ChildProcessMac.mm */,
     6230                                CE11AD511CBC482F00681EE5 /* CodeSigning.h */,
     6231                                CE11AD4F1CBC47F800681EE5 /* CodeSigning.mm */,
    62266232                                1A2A4AFE158693920090C9E9 /* ColorSpaceData.h */,
    62276233                                1A2A4AFD158693920090C9E9 /* ColorSpaceData.mm */,
     
    73207326                                E1513C67166EABB200149FCB /* ChildProcessProxy.h in Headers */,
    73217327                                290F4272172A0C7400939FF0 /* ChildProcessSupplement.h in Headers */,
     7328                                CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */,
    73227329                                1A6F9F9011E13EFC00DB1371 /* CommandLine.h in Headers */,
    73237330                                37BEC4E119491486008B4286 /* CompletionHandlerCallChecker.h in Headers */,
     
    87628769                                51FAEC3B1B0657680009C4E7 /* ChildProcessMessageReceiver.cpp in Sources */,
    87638770                                E1513C66166EABB200149FCB /* ChildProcessProxy.cpp in Sources */,
     8771                                CE11AD501CBC47F800681EE5 /* CodeSigning.mm in Sources */,
    87648772                                1A2A4B0E1586A2240090C9E9 /* ColorSpaceData.mm in Sources */,
    87658773                                1A6F9FB711E1408500DB1371 /* CommandLinePOSIX.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.