From a230b4acf3bf4b2f9f4a42f31be290b23f0e9403 Mon Sep 17 00:00:00 2001 From: Michal A Date: Fri, 11 Sep 2020 12:33:37 +0800 Subject: [PATCH 1/5] Fixed compilation on Mac Catalyst --- .../NIOTransportServices/TLSConfiguration.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift index e1003dd93..b8d60a01f 100644 --- a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift +++ b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift @@ -64,18 +64,22 @@ let options = NWProtocolTLS.Options() // minimum TLS protocol - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, macCatalyst 13.0, *) { sec_protocol_options_set_min_tls_protocol_version(options.securityProtocolOptions, self.minimumTLSVersion.nwTLSProtocolVersion) } else { + #if !targetEnvironment(macCatalyst) sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol) + #endif } // maximum TLS protocol if let maximumTLSVersion = self.maximumTLSVersion { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, macCatalyst 13.0, *) { sec_protocol_options_set_max_tls_protocol_version(options.securityProtocolOptions, maximumTLSVersion.nwTLSProtocolVersion) } else { + #if !targetEnvironment(macCatalyst) sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol) + #endif } } From cd3396ab651cb6edc00436dd21a33de70f9c9369 Mon Sep 17 00:00:00 2001 From: Michal A Date: Mon, 14 Sep 2020 15:11:46 +0800 Subject: [PATCH 2/5] Updates after review --- .../NIOTransportServices/TLSConfiguration.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift index b8d60a01f..57b6695da 100644 --- a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift +++ b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift @@ -64,21 +64,25 @@ let options = NWProtocolTLS.Options() // minimum TLS protocol - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, macCatalyst 13.0, *) { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { sec_protocol_options_set_min_tls_protocol_version(options.securityProtocolOptions, self.minimumTLSVersion.nwTLSProtocolVersion) } else { #if !targetEnvironment(macCatalyst) sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol) + #else + preconditionFailure("macCatalyst 13 is the first version of macCatalyst") #endif } // maximum TLS protocol if let maximumTLSVersion = self.maximumTLSVersion { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, macCatalyst 13.0, *) { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { sec_protocol_options_set_max_tls_protocol_version(options.securityProtocolOptions, maximumTLSVersion.nwTLSProtocolVersion) } else { #if !targetEnvironment(macCatalyst) sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol) + #else + preconditionFailure("macCatalyst 13 is the first version of macCatalyst") #endif } } From c01e323b35b081f324838634a20d11b72a187097 Mon Sep 17 00:00:00 2001 From: Michal A Date: Mon, 14 Sep 2020 15:13:21 +0800 Subject: [PATCH 3/5] Fix SSLProtocol depreciation warning --- .../AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift index 57b6695da..49418a330 100644 --- a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift +++ b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift @@ -35,6 +35,7 @@ } } + @available(iOS, introduced: 5.0, deprecated: 13.0) extension TLSVersion { /// return as SSL protocol var sslProtocol: SSLProtocol { From f04d4bf6fc0d27614d194ebc96d20ee1a620dced Mon Sep 17 00:00:00 2001 From: Michal A Date: Mon, 14 Sep 2020 18:57:47 +0800 Subject: [PATCH 4/5] Formatted code using swiftformat-44.6 --- .../NIOTransportServices/TLSConfiguration.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift index 49418a330..c4735f2da 100644 --- a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift +++ b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift @@ -69,9 +69,9 @@ sec_protocol_options_set_min_tls_protocol_version(options.securityProtocolOptions, self.minimumTLSVersion.nwTLSProtocolVersion) } else { #if !targetEnvironment(macCatalyst) - sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol) + sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol) #else - preconditionFailure("macCatalyst 13 is the first version of macCatalyst") + preconditionFailure("macCatalyst 13 is the first version of macCatalyst") #endif } @@ -81,9 +81,9 @@ sec_protocol_options_set_max_tls_protocol_version(options.securityProtocolOptions, maximumTLSVersion.nwTLSProtocolVersion) } else { #if !targetEnvironment(macCatalyst) - sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol) + sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol) #else - preconditionFailure("macCatalyst 13 is the first version of macCatalyst") + preconditionFailure("macCatalyst 13 is the first version of macCatalyst") #endif } } From 0106719c37eaad22b8cd05ac5287008fb73b2ac3 Mon Sep 17 00:00:00 2001 From: Michal A Date: Wed, 12 May 2021 23:01:57 +0800 Subject: [PATCH 5/5] Limit macCatalyst check to Swift 5.3 or later --- .../TLSConfiguration.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift index c4735f2da..4653a25eb 100644 --- a/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift +++ b/Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift @@ -68,10 +68,12 @@ if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { sec_protocol_options_set_min_tls_protocol_version(options.securityProtocolOptions, self.minimumTLSVersion.nwTLSProtocolVersion) } else { - #if !targetEnvironment(macCatalyst) - sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol) - #else - preconditionFailure("macCatalyst 13 is the first version of macCatalyst") + #if compiler(>=5.3) + #if !targetEnvironment(macCatalyst) + sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol) + #else + preconditionFailure("macCatalyst 13 is the first version of macCatalyst") + #endif #endif } @@ -80,10 +82,12 @@ if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) { sec_protocol_options_set_max_tls_protocol_version(options.securityProtocolOptions, maximumTLSVersion.nwTLSProtocolVersion) } else { - #if !targetEnvironment(macCatalyst) - sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol) - #else - preconditionFailure("macCatalyst 13 is the first version of macCatalyst") + #if compiler(>=5.3) + #if !targetEnvironment(macCatalyst) + sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol) + #else + preconditionFailure("macCatalyst 13 is the first version of macCatalyst") + #endif #endif } }