Do not terminate the NetworkProcess if a third party application sends a NSCredential...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2019 06:12:55 +0000 (06:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2019 06:12:55 +0000 (06:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196213

Patch by Alex Christensen <achristensen@webkit.org> on 2019-03-25
Reviewed by Geoff Garen.

Source/WebKit:

A release assertion added in r230225 was reachable.  I reached it in a unit test that responds to a challenge
with a SecIdentityRef wrapped in an NSCredential.

* Shared/cf/ArgumentCodersCF.cpp:
(IPC::decode):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm: Added.
(credentialWithIdentityAndKeychainPath):
(-[ChallengeDelegate webView:didFinishNavigation:]):
(-[ChallengeDelegate webView:didReceiveAuthenticationChallenge:completionHandler:]):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243487 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Shared/cf/ArgumentCodersCF.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm [new file with mode: 0644]

index 186f3e4..146491c 100644 (file)
@@ -1,3 +1,16 @@
+2019-03-25  Alex Christensen  <achristensen@webkit.org>
+
+        Do not terminate the NetworkProcess if a third party application sends a NSCredential with a SecIdentityRef
+        https://bugs.webkit.org/show_bug.cgi?id=196213
+
+        Reviewed by Geoff Garen.
+
+        A release assertion added in r230225 was reachable.  I reached it in a unit test that responds to a challenge
+        with a SecIdentityRef wrapped in an NSCredential.
+
+        * Shared/cf/ArgumentCodersCF.cpp:
+        (IPC::decode):
+
 2019-03-25  Chris Dumez  <cdumez@apple.com>
 
         Regression(r242369) Trying to change profile picture on linked in shows file picker, not the image picker
index 5de3fe6..27443bb 100644 (file)
@@ -697,10 +697,6 @@ void encode(Encoder& encoder, SecIdentityRef identity)
 
 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;
@@ -716,6 +712,11 @@ bool decode(Decoder& decoder, RetainPtr<SecIdentityRef>& result)
     if (!decode(decoder, keyData))
         return false;
 
+#if PLATFORM(COCOA)
+    if (!hasProcessPrivilege(ProcessPrivilege::CanAccessCredentials))
+        return true;
+#endif
+
     SecKeyRef key = nullptr;
 #if PLATFORM(IOS_FAMILY)
     if (secKeyRefDecodingAllowed)
index 8035de6..b2a60e1 100644 (file)
@@ -1,5 +1,19 @@
 2019-03-25  Alex Christensen  <achristensen@webkit.org>
 
+        Do not terminate the NetworkProcess if a third party application sends a NSCredential with a SecIdentityRef
+        https://bugs.webkit.org/show_bug.cgi?id=196213
+
+        Reviewed by Geoff Garen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm: Added.
+        (credentialWithIdentityAndKeychainPath):
+        (-[ChallengeDelegate webView:didFinishNavigation:]):
+        (-[ChallengeDelegate webView:didReceiveAuthenticationChallenge:completionHandler:]):
+        (TestWebKitAPI::TEST):
+
+2019-03-25  Alex Christensen  <achristensen@webkit.org>
+
         Expected shouldn't assume its contained types are copyable
         https://bugs.webkit.org/show_bug.cgi?id=195986
 
index 68cd69a..3818593 100644 (file)
                5C0BF8941DD599C900B00328 /* MenuTypesForMouseEvents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */; };
                5C0BF8951DD599CD00B00328 /* NavigatorLanguage.mm in Sources */ = {isa = PBXBuildFile; fileRef = E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */; };
                5C19A5241FD0F60100EEA323 /* CookiePrivateBrowsing.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C19A5231FD0F32600EEA323 /* CookiePrivateBrowsing.mm */; };
+               5C23DF0B2246015800F454B6 /* Challenge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C23DF0A2245C9D700F454B6 /* Challenge.mm */; };
                5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */; };
                5C2936961D5C00ED00DEAB1E /* CookieMessage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5C2936941D5BFD1900DEAB1E /* CookieMessage.html */; };
                5C4A84951F7EEFFC00ACFC54 /* Configuration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C4A84941F7EEFD400ACFC54 /* Configuration.mm */; };
                5C0BF88C1DD5957400B00328 /* MemoryPressureHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandler.mm; sourceTree = "<group>"; };
                5C0BF88F1DD5999B00B00328 /* WebViewCanPasteZeroPng.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewCanPasteZeroPng.mm; sourceTree = "<group>"; };
                5C19A5231FD0F32600EEA323 /* CookiePrivateBrowsing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookiePrivateBrowsing.mm; sourceTree = "<group>"; };
+               5C23DF0A2245C9D700F454B6 /* Challenge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Challenge.mm; sourceTree = "<group>"; };
                5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieAcceptPolicy.mm; sourceTree = "<group>"; };
                5C2936941D5BFD1900DEAB1E /* CookieMessage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = CookieMessage.html; sourceTree = "<group>"; };
                5C4A84941F7EEFD400ACFC54 /* Configuration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Configuration.mm; sourceTree = "<group>"; };
                                5C75715F221249BD00B9E5AC /* BundleRetainPagePlugIn.mm */,
                                1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */,
                                1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */,
+                               5C23DF0A2245C9D700F454B6 /* Challenge.mm */,
                                5CB18BA71F5645B200EE23C4 /* ClickAutoFillButton.mm */,
                                CDF92236216D186400647AA7 /* CloseWebViewAfterEnterFullscreen.mm */,
                                CDF0B789216D484300421ECC /* CloseWebViewDuringEnterFullscreen.mm */,
                                57303BCB2008376500355965 /* CBORReaderTest.cpp in Sources */,
                                57303BC9200824D300355965 /* CBORValueTest.cpp in Sources */,
                                57303BCA20082C0100355965 /* CBORWriterTest.cpp in Sources */,
+                               5C23DF0B2246015800F454B6 /* Challenge.mm in Sources */,
                                F44A531221B8990A00DBB99C /* ClassMethodSwizzler.mm in Sources */,
                                7CCE7EE61A411AE600447C4C /* CloseFromWithinCreatePage.cpp in Sources */,
                                7CCE7EB71A411A7E00447C4C /* CloseNewWindowInNavigationPolicyDelegate.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm
new file mode 100644 (file)
index 0000000..8a7913b
--- /dev/null
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "TCPServer.h"
+#import "Test.h"
+#import "TestWKWebView.h"
+
+#if PLATFORM(MAC)
+
+static std::pair<RetainPtr<NSURLCredential>, RetainPtr<NSString>> credentialWithIdentityAndKeychainPath()
+{
+    // Certificate and private key were generated by running this command:
+    // openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
+    // and entering this information:
+    /*
+     Country Name (2 letter code) []:US
+     State or Province Name (full name) []:New Mexico
+     Locality Name (eg, city) []:Santa Fe
+     Organization Name (eg, company) []:Self
+     Organizational Unit Name (eg, section) []:Myself
+     Common Name (eg, fully qualified host name) []:Me
+     Email Address []:me@example.com
+     */
+    
+    NSString *pemEncodedCertificate = @""
+    "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"
+    "3vjZD3y9kZk7mre9XHwkI8MdK5s=";
+    
+    NSString *pemEncodedPrivateKey = @""
+    "MIIJQ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J5yj8SKr0bHzqEtOy9/JeRjkYGHC6bVWpq5FA2MBhf4dNjJ4UDlnT"
+    "vuePcTjr7nnfY1sztvfVl9D8dmgT+TBnOOV6yWj1gm5bS1DxQSLgNmtKxJ8tAh2u"
+    "dEObvcpShP22ItOVjSampRuAuRG26ZemEbGCI3J6Mqx3y6m+6HwultsgtdzDgrFe"
+    "qJfU8bbdbu2pi47Y4FdJK0HLffl5Rw==";
+    
+    NSData *derEncodedCertificate = [[[NSData alloc] initWithBase64EncodedString:pemEncodedCertificate options:0] autorelease];
+    RetainPtr<SecCertificateRef> certificate = adoptCF(SecCertificateCreateWithData(nullptr, (__bridge CFDataRef)derEncodedCertificate));
+    
+    NSData *derEncodedPrivateKey = [[[NSData alloc] initWithBase64EncodedString:pemEncodedPrivateKey options:0] autorelease];
+    NSDictionary* options = @{
+        (id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA,
+        (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate,
+        (id)kSecAttrKeySizeInBits: @4096,
+    };
+    const NSUInteger pemEncodedPrivateKeyHeaderLength = 26;
+    CFErrorRef error = nullptr;
+    RetainPtr<SecKeyRef> privateKey = adoptCF(SecKeyCreateWithData((__bridge CFDataRef)[derEncodedPrivateKey subdataWithRange:NSMakeRange(pemEncodedPrivateKeyHeaderLength, derEncodedPrivateKey.length - pemEncodedPrivateKeyHeaderLength)], (__bridge CFDictionaryRef)options, &error));
+    EXPECT_NULL(error);
+    EXPECT_NOT_NULL(privateKey.get());
+
+    SecKeychainRef keychainRef = nullptr;
+    const char* keychainPassword = "testpassword";
+    NSString *keychainPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"TestKeychain"];
+    OSStatus status = SecKeychainCreate([keychainPath UTF8String], strlen(keychainPassword), keychainPassword, NO, nullptr, &keychainRef);
+    EXPECT_TRUE(status == errSecSuccess);
+    RetainPtr<SecKeychainRef> keychain = adoptCF(keychainRef);
+    EXPECT_NOT_NULL(keychain);
+
+    SecExternalItemType type = kSecItemTypePrivateKey;
+    status = SecItemImport((__bridge CFDataRef)derEncodedPrivateKey, nullptr, nullptr, &type, 0, nullptr, keychain.get(), nullptr);
+    EXPECT_TRUE(status == errSecSuccess);
+
+    SecIdentityRef identityRef = nullptr;
+    status = SecIdentityCreateWithCertificate(keychain.get(), certificate.get(), &identityRef);
+    EXPECT_NOT_NULL(identityRef);
+    EXPECT_TRUE(status == errSecSuccess);
+    RetainPtr<SecIdentityRef> identity = adoptCF(identityRef);
+    
+    return {
+        [NSURLCredential credentialWithIdentity:identity.get() certificates:@[(id)certificate.get()] persistence:NSURLCredentialPersistenceNone],
+        keychainPath
+    };
+}
+
+static bool navigationFinished;
+static RetainPtr<NSString> keychainPath;
+
+@interface ChallengeDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation ChallengeDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
+{
+    navigationFinished = true;
+}
+
+- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
+{
+    NSURLProtectionSpace *protectionSpace = challenge.protectionSpace;
+    EXPECT_NULL(challenge.proposedCredential);
+    EXPECT_EQ(challenge.previousFailureCount, 0);
+    EXPECT_TRUE([protectionSpace.realm isEqualToString:@"testrealm"]);
+    EXPECT_FALSE(protectionSpace.receivesCredentialSecurely);
+    EXPECT_FALSE(protectionSpace.isProxy);
+    EXPECT_TRUE([protectionSpace.host isEqualToString:@"127.0.0.1"]);
+    EXPECT_NULL(protectionSpace.proxyType);
+    EXPECT_TRUE([protectionSpace.protocol isEqualToString:NSURLProtectionSpaceHTTP]);
+    EXPECT_TRUE([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic]);
+    EXPECT_EQ([(NSHTTPURLResponse *)challenge.failureResponse statusCode], 401);
+
+    auto pair = credentialWithIdentityAndKeychainPath();
+    completionHandler(NSURLSessionAuthChallengeUseCredential, pair.first.get());
+    keychainPath = WTFMove(pair.second);
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(Challenge, SecIdentity)
+{
+    TCPServer server([] (auto socket) {
+        char readBuffer[1000];
+        auto bytesRead = ::read(socket, readBuffer, sizeof(readBuffer));
+        EXPECT_GT(bytesRead, 0);
+        EXPECT_TRUE(static_cast<size_t>(bytesRead) < sizeof(readBuffer));
+        
+        const char* challengeHeader =
+        "HTTP/1.1 401 Unauthorized\r\n"
+        "Date: Sat, 23 Mar 2019 06:29:01 GMT\r\n"
+        "Content-Length: 0\r\n"
+        "WWW-Authenticate: Basic realm=\"testrealm\"\r\n\r\n";
+        auto bytesWritten = ::write(socket, challengeHeader, strlen(challengeHeader));
+        EXPECT_EQ(static_cast<size_t>(bytesWritten), strlen(challengeHeader));
+        
+        bytesRead = ::read(socket, readBuffer, sizeof(readBuffer));
+        EXPECT_GT(bytesRead, 0);
+        EXPECT_TRUE(static_cast<size_t>(bytesRead) < sizeof(readBuffer));
+        
+        const char* responseHeader =
+        "HTTP/1.1 200 OK\r\n"
+        "Content-Length: 13\r\n\r\n"
+        "Hello, World!";
+        bytesWritten = ::write(socket, responseHeader, strlen(responseHeader));
+        EXPECT_EQ(static_cast<size_t>(bytesWritten), strlen(responseHeader));
+    });
+
+    auto webView = adoptNS([WKWebView new]);
+    auto delegate = adoptNS([ChallengeDelegate new]);
+    [webView setNavigationDelegate:delegate.get()];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
+
+    Util::run(&navigationFinished);
+    
+    EXPECT_NOT_NULL(keychainPath.get());
+    NSError *error = nil;
+    [[NSFileManager defaultManager] removeItemAtPath:keychainPath.get() error:&error];
+    EXPECT_NULL(error);
+}
+
+} // namespace TestWebKitAPI
+
+#endif