Title: [230225] trunk/Source
Revision
230225
Author
[email protected]
Date
2018-04-03 16:50:14 -0700 (Tue, 03 Apr 2018)

Log Message

Guard against keychain/certificate access outside the network process
https://bugs.webkit.org/show_bug.cgi?id=184214
<rdar://problem/38734795>

Reviewed by Youenn Fablet.

Use the ProcessPrivilege assertions to guard against accessing the Keychain from
a non-Networking process.

Source/WebCore:

* Modules/webauthn/cocoa/LocalAuthenticator.mm:
(WebCore::LocalAuthenticator::makeCredential): Assert if we access the keychain from
a proces other than the Network or UI process.
(WebCore::LocalAuthenticator::getAssertion): Ditto.
(WebCore::LocalAuthenticator::issueClientCertificate const): Ditto.
* crypto/mac/SerializedCryptoKeyWrapMac.mm:
(WebCore::createAndStoreMasterKey): Ditto.
(WebCore::findMasterKey): Ditto.
(WebCore::deleteDefaultWebCryptoMasterKey): Ditto.
* platform/mac/SSLKeyGeneratorMac.mm:
(WebCore::signedPublicKeyAndChallengeString): Ditto.
* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::createPrivateStorageSession): Ditto.
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::didReceiveAuthenticationChallenge): Ditto.

Source/WebKit:

* Shared/cf/ArgumentCodersCF.cpp:
(IPC::encode): Assert if we access the keychain from a proces other than the Network or UI process.
(IPC::decode): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (230224 => 230225)


--- trunk/Source/WebCore/ChangeLog	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebCore/ChangeLog	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,3 +1,30 @@
+2018-04-03  Brent Fulgham  <[email protected]>
+
+        Guard against keychain/certificate access outside the network process
+        https://bugs.webkit.org/show_bug.cgi?id=184214
+        <rdar://problem/38734795>
+
+        Reviewed by Youenn Fablet.
+
+        Use the ProcessPrivilege assertions to guard against accessing the Keychain from
+        a non-Networking process.
+
+        * Modules/webauthn/cocoa/LocalAuthenticator.mm:
+        (WebCore::LocalAuthenticator::makeCredential): Assert if we access the keychain from
+        a proces other than the Network or UI process.
+        (WebCore::LocalAuthenticator::getAssertion): Ditto.
+        (WebCore::LocalAuthenticator::issueClientCertificate const): Ditto.
+        * crypto/mac/SerializedCryptoKeyWrapMac.mm:
+        (WebCore::createAndStoreMasterKey): Ditto.
+        (WebCore::findMasterKey): Ditto.
+        (WebCore::deleteDefaultWebCryptoMasterKey): Ditto.
+        * platform/mac/SSLKeyGeneratorMac.mm:
+        (WebCore::signedPublicKeyAndChallengeString): Ditto.
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::createPrivateStorageSession): Ditto.
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandle::didReceiveAuthenticationChallenge): Ditto.
+
 2018-04-03  Youenn Fablet  <[email protected]>
 
         NetworkResourceLoader does not need to expose all redirect response headers

Modified: trunk/Source/WebCore/Modules/webauthn/cocoa/LocalAuthenticator.h (230224 => 230225)


--- trunk/Source/WebCore/Modules/webauthn/cocoa/LocalAuthenticator.h	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebCore/Modules/webauthn/cocoa/LocalAuthenticator.h	2018-04-03 23:50:14 UTC (rev 230225)
@@ -47,7 +47,7 @@
 class WEBCORE_EXPORT LocalAuthenticator {
     WTF_MAKE_NONCOPYABLE(LocalAuthenticator);
 public:
-    LocalAuthenticator() = default;
+    LocalAuthenticator();
     virtual ~LocalAuthenticator() = default;
 
     void makeCredential(const Vector<uint8_t>& hash, const PublicKeyCredentialCreationOptions&, CreationCallback&&, ExceptionCallback&&);

Modified: trunk/Source/WebCore/Modules/webauthn/cocoa/LocalAuthenticator.mm (230224 => 230225)


--- trunk/Source/WebCore/Modules/webauthn/cocoa/LocalAuthenticator.mm	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebCore/Modules/webauthn/cocoa/LocalAuthenticator.mm	2018-04-03 23:50:14 UTC (rev 230225)
@@ -39,6 +39,7 @@
 #import <wtf/BlockPtr.h>
 #import <wtf/HashSet.h>
 #import <wtf/MainThread.h>
+#import <wtf/ProcessPrivilege.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
 #import <wtf/text/StringHash.h>
@@ -109,6 +110,11 @@
 
 } // LocalAuthenticatorInternal
 
+LocalAuthenticator::LocalAuthenticator()
+{
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+}
+
 void LocalAuthenticator::makeCredential(const Vector<uint8_t>& hash, const PublicKeyCredentialCreationOptions& options, CreationCallback&& callback, ExceptionCallback&& exceptionCallback)
 {
     using namespace LocalAuthenticatorInternal;

Modified: trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm (230224 => 230225)


--- trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebCore/crypto/mac/SerializedCryptoKeyWrapMac.mm	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -35,6 +35,7 @@
 #include <wtf/text/Base64.h>
 #include <wtf/text/CString.h>
 #include <wtf/CryptographicUtilities.h>
+#include <wtf/ProcessPrivilege.h>
 #include <wtf/RetainPtr.h>
 
 #if PLATFORM(IOS)
@@ -80,6 +81,8 @@
 
 static bool createAndStoreMasterKey(Vector<uint8_t>& masterKeyData)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+
     masterKeyData.resize(masterKeySizeInBytes);
     int rc = CCRandomCopyBytes(kCCRandomDefault, masterKeyData.data(), masterKeyData.size());
     RELEASE_ASSERT(rc == kCCSuccess);
@@ -151,6 +154,8 @@
 
 static bool findMasterKey(Vector<uint8_t>& masterKeyData)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+
     NSDictionary *query = @{
         (id)kSecClass : (id)kSecClassGenericPassword,
         (id)kSecAttrAccount : masterKeyAccountNameForCurrentApplication(),
@@ -180,6 +185,8 @@
 
 bool deleteDefaultWebCryptoMasterKey()
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+
     NSDictionary *query = @{
         (id)kSecClass : (id)kSecClassGenericPassword,
         (id)kSecAttrAccount : masterKeyAccountNameForCurrentApplication(),

Modified: trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm (230224 => 230225)


--- trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003, 2005, 2008, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -33,6 +33,7 @@
 #import <Security/SecAsn1Coder.h>
 #import <Security/SecAsn1Templates.h>
 #import <Security/SecEncodeTransform.h>
+#import <wtf/ProcessPrivilege.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Scope.h>
 #import <wtf/cf/TypeCastsCF.h>

Modified: trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm (230224 => 230225)


--- trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -50,6 +50,7 @@
 #import <pal/spi/cocoa/NSURLConnectionSPI.h>
 #import <wtf/BlockObjCExceptions.h>
 #import <wtf/CompletionHandler.h>
+#import <wtf/ProcessPrivilege.h>
 #import <wtf/Ref.h>
 #import <wtf/SchedulePair.h>
 #import <wtf/text/Base64.h>
@@ -495,6 +496,7 @@
     // the keychain.  CFNetwork used to handle this until WebCore was changed to always
     // return NO to -connectionShouldUseCredentialStorage: for <rdar://problem/7704943>.
     if (!challenge.previousFailureCount() && challenge.protectionSpace().isProxy()) {
+        RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
         NSURLAuthenticationChallenge *macChallenge = mac(challenge);
         if (NSURLCredential *credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[macChallenge protectionSpace]]) {
             [challenge.sender() useCredential:credential forAuthenticationChallenge:macChallenge];

Modified: trunk/Source/WebKit/ChangeLog (230224 => 230225)


--- trunk/Source/WebKit/ChangeLog	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebKit/ChangeLog	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,3 +1,18 @@
+2018-04-03  Brent Fulgham  <[email protected]>
+
+        Guard against keychain/certificate access outside the network process
+        https://bugs.webkit.org/show_bug.cgi?id=184214
+        <rdar://problem/38734795>
+
+        Reviewed by Youenn Fablet.
+
+        Use the ProcessPrivilege assertions to guard against accessing the Keychain from
+        a non-Networking process.
+
+        * Shared/cf/ArgumentCodersCF.cpp:
+        (IPC::encode): Assert if we access the keychain from a proces other than the Network or UI process.
+        (IPC::decode): Ditto.
+
 2018-04-03  Youenn Fablet  <[email protected]>
 
         NetworkResourceLoader does not need to expose all redirect response headers

Modified: trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp (230224 => 230225)


--- trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,6 +30,7 @@
 #include "Decoder.h"
 #include "Encoder.h"
 #include <WebCore/CFURLExtras.h>
+#include <wtf/ProcessPrivilege.h>
 #include <wtf/Vector.h>
 #include <wtf/spi/cocoa/SecuritySPI.h>
 
@@ -644,6 +645,7 @@
 
 static CFDataRef copyPersistentRef(SecKeyRef key)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     // This function differs from SecItemCopyPersistentRef in that it specifies an access group.
     // This is necessary in case there are multiple copies of the key in the keychain, because we
     // need a reference to the one that the Networking process will be able to access.
@@ -674,6 +676,7 @@
     keyData = copyPersistentRef(key);
 #endif
 #if PLATFORM(MAC)
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     SecKeychainItemCreatePersistentReference((SecKeychainItemRef)key, &keyData);
 #endif
     CFRelease(key);
@@ -687,6 +690,10 @@
 
 bool decode(Decoder& decoder, RetainPtr<SecIdentityRef>& result)
 {
+#if PLATFORM(COCOA)
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+#endif
+
     RetainPtr<SecCertificateRef> certificate;
     if (!decode(decoder, certificate))
         return false;
@@ -721,6 +728,8 @@
 #if HAVE(SEC_KEYCHAIN)
 void encode(Encoder& encoder, SecKeychainItemRef keychainItem)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+
     CFDataRef data;
     if (SecKeychainItemCreatePersistentReference(keychainItem, &data) == errSecSuccess) {
         encode(encoder, data);
@@ -730,6 +739,8 @@
 
 bool decode(Decoder& decoder, RetainPtr<SecKeychainItemRef>& result)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+
     RetainPtr<CFDataRef> data;
     if (!IPC::decode(decoder, data))
         return false;
@@ -746,6 +757,7 @@
 #if HAVE(SEC_ACCESS_CONTROL)
 void encode(Encoder& encoder, SecAccessControlRef accessControl)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     RetainPtr<CFDataRef> data = ""
     if (data)
         encode(encoder, data.get());
@@ -753,6 +765,7 @@
 
 bool decode(Decoder& decoder, RetainPtr<SecAccessControlRef>& result)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     RetainPtr<CFDataRef> data;
     if (!decode(decoder, data))
         return false;

Modified: trunk/Source/WebKit/Shared/mac/SecItemShim.cpp (230224 => 230225)


--- trunk/Source/WebKit/Shared/mac/SecItemShim.cpp	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebKit/Shared/mac/SecItemShim.cpp	2018-04-03 23:50:14 UTC (rev 230225)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,6 +38,7 @@
 #include <atomic>
 #include <dlfcn.h>
 #include <mutex>
+#include <wtf/ProcessPrivilege.h>
 
 #if USE(APPLE_INTERNAL_SDK)
 #include <CFNetwork/CFURLConnectionPriv.h>
@@ -72,6 +73,8 @@
 
 static std::optional<SecItemResponseData> sendSecItemRequest(SecItemRequestData::Type requestType, CFDictionaryRef query, CFDictionaryRef attributesToMatch = 0)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
+
     std::optional<SecItemResponseData> response;
 
     auto semaphore = adoptOSObject(dispatch_semaphore_create(0));
@@ -90,6 +93,7 @@
 
 static OSStatus webSecItemCopyMatching(CFDictionaryRef query, CFTypeRef* result)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     auto response = sendSecItemRequest(SecItemRequestData::CopyMatching, query);
     if (!response)
         return errSecInteractionNotAllowed;
@@ -100,6 +104,7 @@
 
 static OSStatus webSecItemAdd(CFDictionaryRef query, CFTypeRef* result)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     auto response = sendSecItemRequest(SecItemRequestData::Add, query);
     if (!response)
         return errSecInteractionNotAllowed;
@@ -111,6 +116,7 @@
 
 static OSStatus webSecItemUpdate(CFDictionaryRef query, CFDictionaryRef attributesToUpdate)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     auto response = sendSecItemRequest(SecItemRequestData::Update, query, attributesToUpdate);
     if (!response)
         return errSecInteractionNotAllowed;
@@ -120,6 +126,7 @@
 
 static OSStatus webSecItemDelete(CFDictionaryRef query)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     auto response = sendSecItemRequest(SecItemRequestData::Delete, query);
     if (!response)
         return errSecInteractionNotAllowed;
@@ -129,6 +136,7 @@
 
 void initializeSecItemShim(ChildProcess& process)
 {
+    RELEASE_ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials));
     sharedProcess = &process;
 
 #if PLATFORM(IOS)

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (230224 => 230225)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2018-04-03 22:20:21 UTC (rev 230224)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2018-04-03 23:50:14 UTC (rev 230225)
@@ -33,7 +33,6 @@
 #import "ObjCObjectGraph.h"
 #import "SandboxExtension.h"
 #import "SandboxInitializationParameters.h"
-#import "SecItemShim.h"
 #import "SessionTracker.h"
 #import "WKAPICast.h"
 #import "WKBrowsingContextHandleInternal.h"
@@ -304,10 +303,6 @@
 #if USE(OS_STATE)
     registerWithStateDumper();
 #endif
-
-#if ENABLE(SEC_ITEM_SHIM)
-    initializeSecItemShim(*this);
-#endif
 }
 
 #if USE(APPKIT)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to