Title: [249684] trunk
Revision
249684
Author
[email protected]
Date
2019-09-09 18:39:18 -0700 (Mon, 09 Sep 2019)

Log Message

Disable TLS 1.0 and 1.1 in WebSockets
https://bugs.webkit.org/show_bug.cgi?id=201573

Reviewed by Youenn Fablet.

Source/WebCore:

This expands on what I started in r249019 when I disabled legacy TLS for our use of NSURLSession.
Since our WebSocket implementation uses a different network interface, disable legacy TLS for them, too.
I use the same temporary default to re-enable legacy TLS.  I also add a unit test for both WebSockets and NSURLSession use.

* platform/network/cf/SocketStreamHandleImpl.h:
* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::Function<bool):
(WebCore::SocketStreamHandleImpl::setLegacyTLSEnabledCheck):
(WebCore::SocketStreamHandleImpl::createStreams):

Source/WebCore/PAL:

* pal/spi/cf/CFNetworkSPI.h:

Source/WebKit:

* NetworkProcess/NetworkProcessCreationParameters.cpp:
(WebKit::NetworkProcessCreationParameters::encode const):
(WebKit::NetworkProcessCreationParameters::decode):
* NetworkProcess/NetworkProcessCreationParameters.h:
* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _allowAnyTLSCertificateForWebSocketTesting]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeNetworkProcess):

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):

Tools:

* TestWebKitAPI/SourcesCocoa.txt:
* TestWebKitAPI/TCPServer.cpp:
(sk_CRYPTO_BUFFER_num):
(sk_CRYPTO_BUFFER_value):
(TestWebKitAPI::deleter<CRYPTO_BUFFER>::operator()):
(TestWebKitAPI::TCPServer::TCPServer):
(TestWebKitAPI::TCPServer::listenForConnections):
(TestWebKitAPI::deleter<X509>::operator()): Deleted.
(TestWebKitAPI::deleter<uint8_t::operator()): Deleted.
* TestWebKitAPI/TCPServer.h:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm: Added.
(-[WebSocketDelegate waitForMessage]):
(-[WebSocketDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestNavigationDelegate.h:
* TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
(-[TestNavigationDelegate webView:didReceiveAuthenticationChallenge:completionHandler:]):
(-[TestNavigationDelegate waitForDidFailProvisionalNavigation]):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249683 => 249684)


--- trunk/Source/WebCore/ChangeLog	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebCore/ChangeLog	2019-09-10 01:39:18 UTC (rev 249684)
@@ -1,3 +1,20 @@
+2019-09-09  Alex Christensen  <[email protected]>
+
+        Disable TLS 1.0 and 1.1 in WebSockets
+        https://bugs.webkit.org/show_bug.cgi?id=201573
+
+        Reviewed by Youenn Fablet.
+
+        This expands on what I started in r249019 when I disabled legacy TLS for our use of NSURLSession.
+        Since our WebSocket implementation uses a different network interface, disable legacy TLS for them, too.
+        I use the same temporary default to re-enable legacy TLS.  I also add a unit test for both WebSockets and NSURLSession use.
+
+        * platform/network/cf/SocketStreamHandleImpl.h:
+        * platform/network/cf/SocketStreamHandleImplCFNet.cpp:
+        (WebCore::Function<bool):
+        (WebCore::SocketStreamHandleImpl::setLegacyTLSEnabledCheck):
+        (WebCore::SocketStreamHandleImpl::createStreams):
+
 2019-09-09  Saam Barati  <[email protected]>
 
         Unreviewed follow up to r249630. We need padding for ADDRESS32 CPUs to allow replaceWith to work on the intended types.

Modified: trunk/Source/WebCore/PAL/ChangeLog (249683 => 249684)


--- trunk/Source/WebCore/PAL/ChangeLog	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebCore/PAL/ChangeLog	2019-09-10 01:39:18 UTC (rev 249684)
@@ -1,3 +1,12 @@
+2019-09-09  Alex Christensen  <[email protected]>
+
+        Disable TLS 1.0 and 1.1 in WebSockets
+        https://bugs.webkit.org/show_bug.cgi?id=201573
+
+        Reviewed by Youenn Fablet.
+
+        * pal/spi/cf/CFNetworkSPI.h:
+
 2019-08-30  Alex Christensen  <[email protected]>
 
         Remove HAVE_CFNETWORK_WITH_AUTO_ADDED_HTTP_HEADER_SUPPRESSION_SUPPORT conditional

Modified: trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h (249683 => 249684)


--- trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2019-09-10 01:39:18 UTC (rev 249684)
@@ -55,7 +55,9 @@
 
 WTF_EXTERN_C_END
 
-#endif
+#else // PLATFORM(WIN)
+#include <CFNetwork/CFSocketStreamPriv.h>
+#endif // PLATFORM(WIN)
 
 // FIXME: Remove the defined(__OBJC__)-guard once we fix <rdar://problem/19033610>.
 #if defined(__OBJC__) && PLATFORM(COCOA)
@@ -282,6 +284,7 @@
 extern const CFStringRef _kCFURLCachePartitionKey;
 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
 extern const CFStringRef _kCFURLStorageSessionIsPrivate;
+extern const CFStringRef kCFStreamSocketSecurityLevelTLSv1_2;
 
 #if HAVE(CFNETWORK_WITH_CONTENT_ENCODING_SNIFFING_OVERRIDE)
 extern const CFStringRef kCFURLRequestContentDecoderSkipURLCheck;

Modified: trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImpl.h (249683 => 249684)


--- trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImpl.h	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImpl.h	2019-09-10 01:39:18 UTC (rev 249684)
@@ -51,6 +51,8 @@
 
     virtual ~SocketStreamHandleImpl();
 
+    WEBCORE_EXPORT static void setLegacyTLSEnabled(bool);
+
     WEBCORE_EXPORT void platformSend(const uint8_t* data, size_t length, Function<void(bool)>&&) final;
     WEBCORE_EXPORT void platformSendHandshake(const uint8_t* data, size_t length, const Optional<CookieRequestHeaderFieldProxy>&, Function<void(bool, bool)>&&) final;
     WEBCORE_EXPORT void platformClose() final;

Modified: trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp (249683 => 249684)


--- trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp	2019-09-10 01:39:18 UTC (rev 249684)
@@ -305,6 +305,13 @@
     CFReadStreamSetProperty(stream, kCFStreamPropertyCONNECTProxy, connectDictionary.get());
 }
 
+static bool gLegacyTLSEnabled = false;
+
+void SocketStreamHandleImpl::setLegacyTLSEnabled(bool enabled)
+{
+    gLegacyTLSEnabled = enabled;
+}
+
 void SocketStreamHandleImpl::createStreams()
 {
     if (m_connectionType == Unknown)
@@ -327,7 +334,6 @@
         CFReadStreamSetProperty(readStream, kCFStreamPropertySourceApplication, m_auditData.sourceApplicationAuditData.get());
         CFWriteStreamSetProperty(writeStream, kCFStreamPropertySourceApplication, m_auditData.sourceApplicationAuditData.get());
     }
-    
 #endif
 
     m_readStream = adoptCF(readStream);
@@ -355,8 +361,20 @@
 
     if (shouldUseSSL()) {
         CFBooleanRef validateCertificateChain = DeprecatedGlobalSettings::allowsAnySSLCertificate() ? kCFBooleanFalse : kCFBooleanTrue;
-        const void* keys[] = { kCFStreamSSLPeerName, kCFStreamSSLLevel, kCFStreamSSLValidatesCertificateChain };
-        const void* values[] = { host.get(), kCFStreamSocketSecurityLevelNegotiatedSSL, validateCertificateChain };
+        const void* keys[] = {
+            kCFStreamSSLPeerName,
+            kCFStreamSSLLevel,
+            kCFStreamSSLValidatesCertificateChain
+        };
+        const void* values[] = {
+            host.get(),
+#if PLATFORM(COCOA)
+            gLegacyTLSEnabled ? kCFStreamSocketSecurityLevelNegotiatedSSL : kCFStreamSocketSecurityLevelTLSv1_2,
+#else
+            kCFStreamSocketSecurityLevelNegotiatedSSL,
+#endif
+            validateCertificateChain
+        };
         RetainPtr<CFDictionaryRef> settings = adoptCF(CFDictionaryCreate(0, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
         CFReadStreamSetProperty(m_readStream.get(), kCFStreamPropertySSLSettings, settings.get());
         CFWriteStreamSetProperty(m_writeStream.get(), kCFStreamPropertySSLSettings, settings.get());

Modified: trunk/Source/WebKit/ChangeLog (249683 => 249684)


--- trunk/Source/WebKit/ChangeLog	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/ChangeLog	2019-09-10 01:39:18 UTC (rev 249684)
@@ -1,3 +1,22 @@
+2019-09-09  Alex Christensen  <[email protected]>
+
+        Disable TLS 1.0 and 1.1 in WebSockets
+        https://bugs.webkit.org/show_bug.cgi?id=201573
+
+        Reviewed by Youenn Fablet.
+
+        * NetworkProcess/NetworkProcessCreationParameters.cpp:
+        (WebKit::NetworkProcessCreationParameters::encode const):
+        (WebKit::NetworkProcessCreationParameters::decode):
+        * NetworkProcess/NetworkProcessCreationParameters.h:
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _allowAnyTLSCertificateForWebSocketTesting]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeNetworkProcess):
+
 2019-09-09  Tim Horton  <[email protected]>
 
         Clarify some macCatalyst feature flags

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp (249683 => 249684)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.cpp	2019-09-10 01:39:18 UTC (rev 249684)
@@ -93,6 +93,7 @@
     encoder << enableAdClickAttributionDebugMode;
     encoder << hstsStorageDirectory;
     encoder << hstsStorageDirectoryExtensionHandle;
+    encoder << enableLegacyTLS;
 }
 
 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
@@ -228,6 +229,9 @@
     if (!decoder.decode(result.hstsStorageDirectoryExtensionHandle))
         return false;
     
+    if (!decoder.decode(result.enableLegacyTLS))
+        return false;
+
     return true;
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h (249683 => 249684)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcessCreationParameters.h	2019-09-10 01:39:18 UTC (rev 249684)
@@ -111,6 +111,7 @@
     bool enableAdClickAttributionDebugMode { false };
     String hstsStorageDirectory;
     SandboxExtension::Handle hstsStorageDirectoryExtensionHandle;
+    bool enableLegacyTLS { false };
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm (249683 => 249684)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm	2019-09-10 01:39:18 UTC (rev 249684)
@@ -39,6 +39,7 @@
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SecurityOrigin.h>
 #import <WebCore/SecurityOriginData.h>
+#import <WebCore/SocketStreamHandleImpl.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/CallbackAggregator.h>
@@ -69,6 +70,8 @@
 
 void NetworkProcess::platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters& parameters)
 {
+    WebCore::SocketStreamHandleImpl::setLegacyTLSEnabled(parameters.enableLegacyTLS);
+
     WebCore::setApplicationBundleIdentifier(parameters.uiProcessBundleIdentifier);
     WebCore::setApplicationSDKVersion(parameters.uiProcessSDKVersion);
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (249683 => 249684)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2019-09-10 01:39:18 UTC (rev 249684)
@@ -647,4 +647,9 @@
     _processPool->clearPermanentCredentialsForProtectionSpace(WebCore::ProtectionSpace(protectionSpace));
 }
 
+- (void)_allowAnyTLSCertificateForWebSocketTesting
+{
+    _processPool->setAllowsAnySSLCertificateForWebSocket(true);
+}
+
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (249683 => 249684)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2019-09-10 01:39:18 UTC (rev 249684)
@@ -123,6 +123,7 @@
 - (void)_getActivePagesOriginsInWebProcessForTesting:(pid_t)pid completionHandler:(void(^)(NSArray<NSString *> *))completionHandler WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
 - (BOOL)_networkProcessHasEntitlementForTesting:(NSString *)entitlement WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
 - (void)_clearPermanentCredentialsForProtectionSpace:(NSURLProtectionSpace *)protectionSpace WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_allowAnyTLSCertificateForWebSocketTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (nonatomic, getter=_isCookieStoragePartitioningEnabled, setter=_setCookieStoragePartitioningEnabled:) BOOL _cookieStoragePartitioningEnabled WK_API_DEPRECATED("Partitioned cookies are no longer supported", macos(10.12.3, 10.14.4), ios(10.3, 12.2));
 @property (nonatomic, getter=_isStorageAccessAPIEnabled, setter=_setStorageAccessAPIEnabled:) BOOL _storageAccessAPIEnabled WK_API_AVAILABLE(macos(10.13.4), ios(11.3));

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (249683 => 249684)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2019-09-10 01:39:18 UTC (rev 249684)
@@ -281,7 +281,8 @@
         }
     }
 
-    parameters.defaultDataStoreParameters.networkSessionParameters.enableLegacyTLS = [defaults boolForKey:@"WebKitEnableLegacyTLS"];
+    parameters.enableLegacyTLS = [defaults boolForKey:@"WebKitEnableLegacyTLS"];
+    parameters.defaultDataStoreParameters.networkSessionParameters.enableLegacyTLS = parameters.enableLegacyTLS;
 
     parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
 

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (249683 => 249684)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2019-09-10 01:39:18 UTC (rev 249684)
@@ -1,3 +1,13 @@
+2019-09-09  Alex Christensen  <[email protected]>
+
+        Disable TLS 1.0 and 1.1 in WebSockets
+        https://bugs.webkit.org/show_bug.cgi?id=201573
+
+        Reviewed by Youenn Fablet.
+
+        * WebView/WebView.mm:
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+
 2019-09-06  Alex Christensen  <[email protected]>
 
         When disabling legacy private browsing for testing, change the SessionID back to what it was, not the defaultSessionID

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (249683 => 249684)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2019-09-10 01:39:18 UTC (rev 249684)
@@ -205,6 +205,7 @@
 #import <WebCore/Settings.h>
 #import <WebCore/ShouldTreatAsContinuingLoad.h>
 #import <WebCore/SocketProvider.h>
+#import <WebCore/SocketStreamHandleImpl.h>
 #import <WebCore/StringUtilities.h>
 #import <WebCore/StyleProperties.h>
 #import <WebCore/TextResourceDecoder.h>
@@ -1419,6 +1420,9 @@
         if (IOSApplication::isMobileSafari())
             DeprecatedGlobalSettings::setShouldManageAudioSessionCategory(true);
 #endif
+        
+        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitEnableLegacyTLS"])
+            SocketStreamHandleImpl::setLegacyTLSEnabled(true);
 
         didOneTimeInitialization = true;
     }

Modified: trunk/Tools/ChangeLog (249683 => 249684)


--- trunk/Tools/ChangeLog	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/ChangeLog	2019-09-10 01:39:18 UTC (rev 249684)
@@ -1,3 +1,30 @@
+2019-09-09  Alex Christensen  <[email protected]>
+
+        Disable TLS 1.0 and 1.1 in WebSockets
+        https://bugs.webkit.org/show_bug.cgi?id=201573
+
+        Reviewed by Youenn Fablet.
+
+        * TestWebKitAPI/SourcesCocoa.txt:
+        * TestWebKitAPI/TCPServer.cpp:
+        (sk_CRYPTO_BUFFER_num):
+        (sk_CRYPTO_BUFFER_value):
+        (TestWebKitAPI::deleter<CRYPTO_BUFFER>::operator()):
+        (TestWebKitAPI::TCPServer::TCPServer):
+        (TestWebKitAPI::TCPServer::listenForConnections):
+        (TestWebKitAPI::deleter<X509>::operator()): Deleted.
+        (TestWebKitAPI::deleter<uint8_t::operator()): Deleted.
+        * TestWebKitAPI/TCPServer.h:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm: Added.
+        (-[WebSocketDelegate waitForMessage]):
+        (-[WebSocketDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/cocoa/TestNavigationDelegate.h:
+        * TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
+        (-[TestNavigationDelegate webView:didReceiveAuthenticationChallenge:completionHandler:]):
+        (-[TestNavigationDelegate waitForDidFailProvisionalNavigation]):
+
 2019-09-09  Fujii Hironori  <[email protected]>
 
         [Win][MiniBrowser] WebKitLegacyBrowserWindow is leaked by circular references

Modified: trunk/Tools/TestWebKitAPI/SourcesCocoa.txt (249683 => 249684)


--- trunk/Tools/TestWebKitAPI/SourcesCocoa.txt	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/TestWebKitAPI/SourcesCocoa.txt	2019-09-10 01:39:18 UTC (rev 249684)
@@ -28,3 +28,5 @@
 cocoa/TestNavigationDelegate.mm
 cocoa/TestProtocol.mm
 cocoa/TestWKWebView.mm
+
+Tests/WebKitCocoa/TLSDeprecation.mm

Modified: trunk/Tools/TestWebKitAPI/TCPServer.cpp (249683 => 249684)


--- trunk/Tools/TestWebKitAPI/TCPServer.cpp	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/TestWebKitAPI/TCPServer.cpp	2019-09-10 01:39:18 UTC (rev 249684)
@@ -33,46 +33,59 @@
 #include <wtf/text/Base64.h>
 
 #if HAVE(SSL)
+
+#define STACK_OF(type) struct stack_st_##type
+
 extern "C" {
 
+enum ssl_verify_result_t {
+    ssl_verify_ok,
+    ssl_verify_invalid,
+    ssl_verify_retry,
+};
+
 struct BIO;
-struct X509;
+struct CRYPTO_BUFFER;
 struct SSL_CTX;
 struct EVP_PKEY;
 struct SSL_METHOD;
-struct X509_STORE_CTX {
-    void* unused;
-    X509* cert;
-};
+struct SSL_PRIVATE_KEY_METHOD;
+struct _STACK;
+struct CRYPTO_BUFFER_POOL;
 struct pem_password_cb;
 int BIO_free(BIO*);
 int SSL_free(SSL*);
-int X509_free(X509*);
 int SSL_CTX_free(SSL_CTX*);
 int EVP_PKEY_free(EVP_PKEY*);
 int SSL_library_init();
-const SSL_METHOD* SSLv23_server_method();
+const SSL_METHOD* TLS_with_buffers_method();
 BIO* BIO_new_mem_buf(const void*, int);
-X509* PEM_read_bio_X509(BIO*, X509**, pem_password_cb*, void*);
 EVP_PKEY* PEM_read_bio_PrivateKey(BIO*, EVP_PKEY**, pem_password_cb*, void*);
 SSL_CTX* SSL_CTX_new(const SSL_METHOD*);
-const SSL_METHOD* SSLv23_server_method();
-int SSL_CTX_use_certificate(SSL_CTX*, X509*);
-int SSL_CTX_use_PrivateKey(SSL_CTX*, EVP_PKEY*);
 SSL* SSL_new(SSL_CTX*);
 int SSL_accept(SSL*);
 int SSL_set_fd(SSL*, int);
-void SSL_CTX_set_verify(SSL_CTX*, int, int (*)(int, X509_STORE_CTX*));
-void SSL_CTX_set_cert_verify_callback(SSL_CTX*, int (*)(X509_STORE_CTX*, void*), void*);
 int SSL_get_error(const SSL*, int);
+void SSL_CTX_set_custom_verify(SSL_CTX*, int mode, enum ssl_verify_result_t (*callback)(SSL *ssl, uint8_t *out_alert));
 int SSL_read(SSL*, void*, int);
 int SSL_write(SSL*, const void*, int);
-int i2d_X509(X509*, unsigned char**);
+const uint8_t* CRYPTO_BUFFER_data(const CRYPTO_BUFFER*);
+size_t CRYPTO_BUFFER_len(const CRYPTO_BUFFER*);
 void OPENSSL_free(void*);
+int SSL_CTX_set_chain_and_key(SSL_CTX*, CRYPTO_BUFFER *const *certs, size_t num_certs, EVP_PKEY*, const SSL_PRIVATE_KEY_METHOD*);
+CRYPTO_BUFFER* CRYPTO_BUFFER_new(const uint8_t*, size_t, CRYPTO_BUFFER_POOL*);
+void CRYPTO_BUFFER_free(CRYPTO_BUFFER*);
+size_t sk_num(const _STACK*);
+void* sk_value(const _STACK*, size_t);
+const STACK_OF(CRYPTO_BUFFER) *SSL_get0_peer_certificates(const SSL*);
+void SSL_CTX_set_max_proto_version(SSL_CTX*, uint16_t);
 #define SSL_VERIFY_PEER 0x01
 #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
 
 } // extern "C"
+
+inline size_t sk_CRYPTO_BUFFER_num(const STACK_OF(CRYPTO_BUFFER) *sk) { return sk_num((const _STACK *)sk); }
+inline CRYPTO_BUFFER* sk_CRYPTO_BUFFER_value(const STACK_OF(CRYPTO_BUFFER) *sk, size_t i) { return (CRYPTO_BUFFER *)sk_value((const _STACK *)sk, i); }
 #endif // HAVE(SSL)
 
 namespace TestWebKitAPI {
@@ -91,12 +104,6 @@
         SSL_free(ssl);
     }
 };
-template<> struct deleter<X509> {
-    void operator()(X509* x509)
-    {
-        X509_free(x509);
-    }
-};
 template<> struct deleter<SSL_CTX> {
     void operator()(SSL_CTX* ctx)
     {
@@ -109,12 +116,15 @@
         EVP_PKEY_free(key);
     }
 };
-template<> struct deleter<uint8_t[]> {
-    void operator()(uint8_t* buffer)
+template<> struct deleter<CRYPTO_BUFFER> {
+    void operator()(CRYPTO_BUFFER* buffer)
     {
-        OPENSSL_free(buffer);
+        CRYPTO_BUFFER_free(buffer);
     }
 };
+namespace ssl {
+template <typename T> using unique_ptr = std::unique_ptr<T, deleter<T>>;
+}
 #endif // HAVE(SSL)
 
 TCPServer::TCPServer(Function<void(Socket)>&& connectionHandler, size_t connections)
@@ -124,50 +134,33 @@
 }
 
 #if HAVE(SSL)
-TCPServer::TCPServer(Protocol protocol, Function<void(SSL*)>&& secureConnectionHandler)
+TCPServer::TCPServer(Protocol protocol, Function<void(SSL*)>&& secureConnectionHandler, Optional<uint16_t> maxTLSVersion)
 {
-    auto startSecureConnection = [secureConnectionHandler = WTFMove(secureConnectionHandler), protocol] (Socket socket) {
+    auto startSecureConnection = [secureConnectionHandler = WTFMove(secureConnectionHandler), protocol, maxTLSVersion] (Socket socket) {
         SSL_library_init();
 
-        std::unique_ptr<SSL_CTX, deleter<SSL_CTX>> ctx(SSL_CTX_new(SSLv23_server_method()));
+        ssl::unique_ptr<SSL_CTX> ctx(SSL_CTX_new(TLS_with_buffers_method()));
 
         // This is a test certificate from BoringSSL.
-        char kCertPEM[] =
-        "-----BEGIN CERTIFICATE-----\n"
-        "MIICWDCCAcGgAwIBAgIJAPuwTC6rEJsMMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV\n"
-        "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n"
-        "aWRnaXRzIFB0eSBMdGQwHhcNMTQwNDIzMjA1MDQwWhcNMTcwNDIyMjA1MDQwWjBF\n"
-        "MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n"
-        "ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n"
-        "gQDYK8imMuRi/03z0K1Zi0WnvfFHvwlYeyK9Na6XJYaUoIDAtB92kWdGMdAQhLci\n"
-        "HnAjkXLI6W15OoV3gA/ElRZ1xUpxTMhjP6PyY5wqT5r6y8FxbiiFKKAnHmUcrgfV\n"
-        "W28tQ+0rkLGMryRtrukXOgXBv7gcrmU7G1jC2a7WqmeI8QIDAQABo1AwTjAdBgNV\n"
-        "HQ4EFgQUi3XVrMsIvg4fZbf6Vr5sp3Xaha8wHwYDVR0jBBgwFoAUi3XVrMsIvg4f\n"
-        "Zbf6Vr5sp3Xaha8wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQA76Hht\n"
-        "ldY9avcTGSwbwoiuIqv0jTL1fHFnzy3RHMLDh+Lpvolc5DSrSJHCP5WuK0eeJXhr\n"
-        "T5oQpHL9z/cCDLAKCKRa4uV0fhEdOWBqyR9p8y5jJtye72t6CuFUV5iqcpF4BH4f\n"
-        "j2VNHwsSrJwkD4QUGlUtH7vwnQmyCFxZMmWAJg==\n"
-        "-----END CERTIFICATE-----\n";
+        String certPEM(
+        "MIICWDCCAcGgAwIBAgIJAPuwTC6rEJsMMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV"
+        "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX"
+        "aWRnaXRzIFB0eSBMdGQwHhcNMTQwNDIzMjA1MDQwWhcNMTcwNDIyMjA1MDQwWjBF"
+        "MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50"
+        "ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB"
+        "gQDYK8imMuRi/03z0K1Zi0WnvfFHvwlYeyK9Na6XJYaUoIDAtB92kWdGMdAQhLci"
+        "HnAjkXLI6W15OoV3gA/ElRZ1xUpxTMhjP6PyY5wqT5r6y8FxbiiFKKAnHmUcrgfV"
+        "W28tQ+0rkLGMryRtrukXOgXBv7gcrmU7G1jC2a7WqmeI8QIDAQABo1AwTjAdBgNV"
+        "HQ4EFgQUi3XVrMsIvg4fZbf6Vr5sp3Xaha8wHwYDVR0jBBgwFoAUi3XVrMsIvg4f"
+        "Zbf6Vr5sp3Xaha8wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQA76Hht"
+        "ldY9avcTGSwbwoiuIqv0jTL1fHFnzy3RHMLDh+Lpvolc5DSrSJHCP5WuK0eeJXhr"
+        "T5oQpHL9z/cCDLAKCKRa4uV0fhEdOWBqyR9p8y5jJtye72t6CuFUV5iqcpF4BH4f"
+        "j2VNHwsSrJwkD4QUGlUtH7vwnQmyCFxZMmWAJg==");
+        Vector<uint8_t> certDER;
+        base64Decode(certPEM, certDER, WTF::Base64DecodeOptions::Base64Default);
+        ssl::unique_ptr<CRYPTO_BUFFER> cert(CRYPTO_BUFFER_new(certDER.data(), certDER.size(), nullptr));
+        ASSERT(cert);
 
-        std::unique_ptr<BIO, deleter<BIO>> certBIO(BIO_new_mem_buf(kCertPEM, strlen(kCertPEM)));
-        std::unique_ptr<X509, deleter<X509>> certX509(PEM_read_bio_X509(certBIO.get(), nullptr, nullptr, nullptr));
-        ASSERT(certX509);
-        SSL_CTX_use_certificate(ctx.get(), certX509.get());
-
-        if (protocol == Protocol::HTTPSWithClientCertificateRequest) {
-            SSL_CTX_set_verify(ctx.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr);
-            SSL_CTX_set_cert_verify_callback(ctx.get(), [] (X509_STORE_CTX* store_ctx, void*) -> int {
-                uint8_t* bufferPointer = nullptr;
-                auto length = i2d_X509(store_ctx->cert, &bufferPointer);
-                std::unique_ptr<uint8_t[], deleter<uint8_t[]>> buffer(bufferPointer);
-                auto expectedCert = testCertificate();
-                EXPECT_EQ(static_cast<int>(expectedCert.size()), length);
-                for (int i = 0; i < length; ++i)
-                    EXPECT_EQ(buffer.get()[i], expectedCert[i]);
-                return 1;
-            }, nullptr);
-        }
-
         // This is a test key from BoringSSL.
         char kKeyPEM[] =
         "-----BEGIN RSA PRIVATE KEY-----\n"
@@ -186,19 +179,33 @@
         "moZWgjHvB2W9Ckn7sDqsPB+U2tyX0joDdQEyuiMECDY8oQ==\n"
         "-----END RSA PRIVATE KEY-----\n";
 
-        std::unique_ptr<BIO, deleter<BIO>> privateKeyBIO(BIO_new_mem_buf(kKeyPEM, strlen(kKeyPEM)));
-        std::unique_ptr<EVP_PKEY, deleter<EVP_PKEY>> privateKey(PEM_read_bio_PrivateKey(privateKeyBIO.get(), nullptr, nullptr, nullptr));
+        ssl::unique_ptr<BIO> privateKeyBIO(BIO_new_mem_buf(kKeyPEM, strlen(kKeyPEM)));
+        ssl::unique_ptr<EVP_PKEY> privateKey(PEM_read_bio_PrivateKey(privateKeyBIO.get(), nullptr, nullptr, nullptr));
         ASSERT(privateKey);
-        SSL_CTX_use_PrivateKey(ctx.get(), privateKey.get());
 
-        std::unique_ptr<SSL, deleter<SSL>> ssl(SSL_new(ctx.get()));
+        SSL_CTX_set_chain_and_key(ctx.get(), reinterpret_cast<CRYPTO_BUFFER *const *>(&cert), 1, privateKey.get(), nullptr);
+
+        if (protocol == Protocol::HTTPSWithClientCertificateRequest) {
+            SSL_CTX_set_custom_verify(ctx.get(), SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, [] (SSL* ssl, uint8_t*) -> ssl_verify_result_t {
+                auto chain = SSL_get0_peer_certificates(ssl);
+                EXPECT_EQ(sk_CRYPTO_BUFFER_num(chain), 2u);
+                auto cert = sk_CRYPTO_BUFFER_value(chain, 0);
+                auto expectedCert = testCertificate();
+                EXPECT_EQ(CRYPTO_BUFFER_len(cert), expectedCert.size());
+                EXPECT_TRUE(!memcmp(CRYPTO_BUFFER_data(cert), expectedCert.data(), expectedCert.size()));
+                return ssl_verify_ok;
+            });
+        }
+
+        if (maxTLSVersion)
+            SSL_CTX_set_max_proto_version(ctx.get(), *maxTLSVersion);
+
+        ssl::unique_ptr<SSL> ssl(SSL_new(ctx.get()));
         ASSERT(ssl);
         SSL_set_fd(ssl.get(), socket);
 
         auto acceptResult = SSL_accept(ssl.get());
-        ASSERT_UNUSED(acceptResult, acceptResult > 0);
-        
-        secureConnectionHandler(ssl.get());
+        secureConnectionHandler(acceptResult > 0 ? ssl.get() : nullptr);
     };
 
     switch (protocol) {
@@ -239,6 +246,7 @@
                 close(connectionSocket);
             }));
         }
+        close(listeningSocket);
     });
 }
 

Modified: trunk/Tools/TestWebKitAPI/TCPServer.h (249683 => 249684)


--- trunk/Tools/TestWebKitAPI/TCPServer.h	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/TestWebKitAPI/TCPServer.h	2019-09-10 01:39:18 UTC (rev 249684)
@@ -27,6 +27,7 @@
 
 #include <thread>
 #include <wtf/Function.h>
+#include <wtf/Optional.h>
 #include <wtf/Vector.h>
 
 #if HAVE(SSL)
@@ -46,7 +47,7 @@
     enum class Protocol : uint8_t {
         HTTPS, HTTPSProxy, HTTPSWithClientCertificateRequest
     };
-    TCPServer(Protocol, Function<void(SSL*)>&&);
+    TCPServer(Protocol, Function<void(SSL*)>&&, Optional<uint16_t> maxTLSVersion = WTF::nullopt);
 #endif // HAVE(SSL)
     ~TCPServer();
     

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (249683 => 249684)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-10 01:39:18 UTC (rev 249684)
@@ -1865,6 +1865,7 @@
 		5C69BDD41F82A7EB000F4F4B /* _javascript_DuringNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _javascript_DuringNavigation.mm; sourceTree = "<group>"; };
 		5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = URLCanonicalization.mm; sourceTree = "<group>"; };
 		5C7148942123A40700FDE3C5 /* WKWebsiteDatastore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebsiteDatastore.mm; sourceTree = "<group>"; };
+		5C73A81A2323059800DEA85A /* TLSDeprecation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TLSDeprecation.mm; sourceTree = "<group>"; };
 		5C75715F221249BD00B9E5AC /* BundleRetainPagePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleRetainPagePlugIn.mm; sourceTree = "<group>"; };
 		5C79640F1EB0269B0075D74C /* EventModifiers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventModifiers.cpp; sourceTree = "<group>"; };
 		5C7C74CA1FB528D4002F9ABE /* WebViewScheduleInRunLoop.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewScheduleInRunLoop.mm; sourceTree = "<group>"; };
@@ -2873,6 +2874,7 @@
 				F4CD74C820FDB49600DE3794 /* TestURLSchemeHandler.mm */,
 				5C16F8FB230C942B0074C4A8 /* TextSize.mm */,
 				C22FA32A228F8708009D7988 /* TextWidth.mm */,
+				5C73A81A2323059800DEA85A /* TLSDeprecation.mm */,
 				5CB40B4D1F4B98BE007DC7B9 /* UIDelegate.mm */,
 				5C3A77A922F20B8A003827FF /* UploadDirectory.mm */,
 				7CC3E1FA197E234100BE6252 /* UserContentController.mm */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm (0 => 249684)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TLSDeprecation.mm	2019-09-10 01:39:18 UTC (rev 249684)
@@ -0,0 +1,193 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+
+#import "PlatformUtilities.h"
+#import "TCPServer.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import "WebCoreTestSupport.h"
+#import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+@interface WebSocketDelegate : NSObject <WKUIDelegate, WebUIDelegate>
+- (NSString *)waitForMessage;
+@end
+
+@implementation WebSocketDelegate {
+    RetainPtr<NSString> _message;
+}
+
+- (NSString *)waitForMessage
+{
+    while (!_message)
+        TestWebKitAPI::Util::spinRunLoop();
+    return _message.autorelease();
+}
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+    _message = message;
+    completionHandler();
+}
+
+- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
+{
+    _message = message;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+const uint16_t tls1_1 = 0x0302;
+static NSString *defaultsKey = @"WebKitEnableLegacyTLS";
+
+TEST(WebKit, TLSVersionWebSocket)
+{
+    auto getWebSocketEvent = [] (bool clientAllowDeprecatedTLS, bool serverLimitTLS) {
+        Optional<uint16_t> maxServerTLSVersion;
+        if (serverLimitTLS)
+            maxServerTLSVersion = tls1_1;
+        TCPServer server(TCPServer::Protocol::HTTPS, [=](SSL *ssl) {
+            EXPECT_TRUE(!ssl == (clientAllowDeprecatedTLS != serverLimitTLS));
+        }, maxServerTLSVersion);
+
+        if (clientAllowDeprecatedTLS)
+            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:defaultsKey];
+        
+        auto webView = adoptNS([TestWKWebView new]);
+        auto delegate = adoptNS([WebSocketDelegate new]);
+        [webView setUIDelegate:delegate.get()];
+        [webView synchronouslyLoadHTMLString:@"start network process"];
+        [[webView configuration].processPool _allowAnyTLSCertificateForWebSocketTesting];
+        [webView synchronouslyLoadHTMLString:[NSString stringWithFormat:
+            @"<script>"
+            "const socket = new WebSocket('wss://localhost:%d');"
+            "socket._onclose_ = function(event){ alert('close'); };"
+            "socket._onerror_ = function(event){ alert('error: ' + event.data); };"
+            "</script>", server.port()]];
+        NSString *message = [delegate waitForMessage];
+        
+        if (clientAllowDeprecatedTLS)
+            [[NSUserDefaults standardUserDefaults] removeObjectForKey:defaultsKey];
+
+        return message;
+    };
+
+    EXPECT_WK_STREQ(getWebSocketEvent(true, true), "close");
+    EXPECT_WK_STREQ(getWebSocketEvent(false, true), "error: undefined");
+    EXPECT_WK_STREQ(getWebSocketEvent(false, false), "close");
+}
+
+NSString *getWebSocketEventWebKitLegacy(bool clientAllowDeprecatedTLS, bool serverLimitTLS)
+{
+    Optional<uint16_t> maxServerTLSVersion;
+    if (serverLimitTLS)
+        maxServerTLSVersion = tls1_1;
+    TCPServer server(TCPServer::Protocol::HTTPS, [=](SSL *ssl) {
+        EXPECT_TRUE(!ssl == (clientAllowDeprecatedTLS != serverLimitTLS));
+    }, maxServerTLSVersion);
+
+    if (clientAllowDeprecatedTLS)
+        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:defaultsKey];
+    
+    auto webView = adoptNS([WebView new]);
+    auto delegate = adoptNS([WebSocketDelegate new]);
+    [webView setUIDelegate:delegate.get()];
+    WebCoreTestSupport::setAllowsAnySSLCertificate(true);
+    [[webView mainFrame] loadHTMLString:[NSString stringWithFormat:
+        @"<script>"
+        "const socket = new WebSocket('wss://localhost:%d');"
+        "socket._onclose_ = function(event){ alert('close'); };"
+        "socket._onerror_ = function(event){ alert('error: ' + event.data); };"
+        "</script>", server.port()] baseURL:nil];
+    NSString *message = [delegate waitForMessage];
+
+    if (clientAllowDeprecatedTLS)
+        [[NSUserDefaults standardUserDefaults] removeObjectForKey:defaultsKey];
+
+    return message;
+}
+
+TEST(WebKit, TLSVersionWebSocketWebKitLegacy1)
+{
+    EXPECT_WK_STREQ(getWebSocketEventWebKitLegacy(true, true), "close");
+}
+
+TEST(WebKit, TLSVersionWebSocketWebKitLegacy2)
+{
+    EXPECT_WK_STREQ(getWebSocketEventWebKitLegacy(false, true), "close");
+}
+
+TEST(WebKit, TLSVersionWebSocketWebKitLegacy3)
+{
+    EXPECT_WK_STREQ(getWebSocketEventWebKitLegacy(false, false), "close");
+}
+
+TEST(WebKit, TLSVersionNetworkSession)
+{
+    static auto delegate = adoptNS([TestNavigationDelegate new]);
+    auto makeWebViewWith = [&] (WKWebsiteDataStore *store) {
+        WKWebViewConfiguration *configuration = [[[WKWebViewConfiguration alloc] init] autorelease];
+        configuration.websiteDataStore = store;
+        auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration]);
+        [webView setNavigationDelegate:delegate.get()];
+        [delegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^callback)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
+            callback(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
+        }];
+        return webView;
+    };
+    {
+        TCPServer server(TCPServer::Protocol::HTTPS, [](SSL *ssl) {
+            EXPECT_FALSE(ssl);
+        }, tls1_1);
+        auto webView = makeWebViewWith([WKWebsiteDataStore defaultDataStore]);
+        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
+        [delegate waitForDidFailProvisionalNavigation];
+    }
+    {
+        TCPServer server(TCPServer::Protocol::HTTPS, [](SSL *ssl) {
+            EXPECT_FALSE(ssl);
+        }, tls1_1);
+        auto webView = makeWebViewWith([WKWebsiteDataStore nonPersistentDataStore]);
+        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
+        [delegate waitForDidFailProvisionalNavigation];
+    }
+    {
+        TCPServer server(TCPServer::Protocol::HTTPS, [](SSL *ssl) {
+            TCPServer::respondWithOK(ssl);
+        }, tls1_1);
+        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:defaultsKey];
+        auto webView = makeWebViewWith([WKWebsiteDataStore defaultDataStore]);
+        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]];
+        [delegate waitForDidFinishNavigation];
+        [[NSUserDefaults standardUserDefaults] removeObjectForKey:defaultsKey];
+    }
+}
+
+}

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h (249683 => 249684)


--- trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h	2019-09-10 01:39:18 UTC (rev 249684)
@@ -37,9 +37,11 @@
 @property (nonatomic, copy) void (^didFinishNavigation)(WKWebView *, WKNavigation *);
 @property (nonatomic, copy) void (^renderingProgressDidChange)(WKWebView *, _WKRenderingProgressEvents);
 @property (nonatomic, copy) void (^webContentProcessDidTerminate)(WKWebView *);
+@property (nonatomic, copy) void (^didReceiveAuthenticationChallenge)(WKWebView *, NSURLAuthenticationChallenge *, void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *));
 
 - (void)waitForDidStartProvisionalNavigation;
 - (void)waitForDidFinishNavigation;
+- (void)waitForDidFailProvisionalNavigation;
 
 @end
 

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm (249683 => 249684)


--- trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm	2019-09-10 01:31:06 UTC (rev 249683)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm	2019-09-10 01:39:18 UTC (rev 249684)
@@ -75,6 +75,14 @@
         _renderingProgressDidChange(webView, progressEvents);
 }
 
+- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
+{
+    if (_didReceiveAuthenticationChallenge)
+        _didReceiveAuthenticationChallenge(webView, challenge, completionHandler);
+    else
+        completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
+}
+
 - (void)waitForDidStartProvisionalNavigation
 {
     EXPECT_FALSE(self.didStartProvisionalNavigation);
@@ -103,6 +111,20 @@
     self.didFinishNavigation = nil;
 }
 
+- (void)waitForDidFailProvisionalNavigation
+{
+    EXPECT_FALSE(self.didFailProvisionalNavigation);
+
+    __block bool finished = false;
+    self.didFailProvisionalNavigation = ^(WKWebView *, WKNavigation *, NSError *) {
+        finished = true;
+    };
+
+    TestWebKitAPI::Util::run(&finished);
+
+    self.didFailProvisionalNavigation = nil;
+}
+
 @end
 
 @implementation WKWebView (TestWebKitAPIExtras)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to