Skip to content

Commit 0eef5f0

Browse files
committed
TLSConfiguration convert to NWProtocolTLS.Options changes
Added macOS 10.14 fallbacks for min/max TLS protocol Enabled applicationProtocols code, now uses `String.withCString`
1 parent 69b0e38 commit 0eef5f0

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ internal extension TLSVersion {
3535
}
3636
}
3737

38+
internal extension TLSVersion {
39+
/// return as SSL protocol
40+
var sslProtocol: SSLProtocol {
41+
switch self {
42+
case .tlsv1:
43+
return .tlsProtocol1
44+
case .tlsv11:
45+
return .tlsProtocol11
46+
case .tlsv12:
47+
return .tlsProtocol12
48+
case .tlsv13:
49+
return .tlsProtocol13
50+
}
51+
}
52+
}
53+
3854
@available (macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
3955
internal extension TLSConfiguration {
4056

@@ -51,28 +67,25 @@ internal extension TLSConfiguration {
5167
// minimum TLS protocol
5268
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) {
5369
sec_protocol_options_set_min_tls_protocol_version(options.securityProtocolOptions, self.minimumTLSVersion.nwTLSProtocolVersion)
70+
} else {
71+
sec_protocol_options_set_tls_min_version(options.securityProtocolOptions, self.minimumTLSVersion.sslProtocol)
5472
}
5573

5674
// maximum TLS protocol
5775
if let maximumTLSVersion = self.maximumTLSVersion {
5876
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) {
5977
sec_protocol_options_set_max_tls_protocol_version(options.securityProtocolOptions, maximumTLSVersion.nwTLSProtocolVersion)
6078
} else {
61-
precondition(self.maximumTLSVersion != nil, "TLSConfiguration.maximumTLSVersion is not supported")
79+
sec_protocol_options_set_tls_max_version(options.securityProtocolOptions, maximumTLSVersion.sslProtocol)
6280
}
6381
}
6482

6583
// application protocols
66-
if self.applicationProtocols.count > 0 {
67-
preconditionFailure("TLSConfiguration.applicationProtocols is not supported")
68-
}
69-
/*for applicationProtocol in self.applicationProtocols {
70-
applicationProtocol.utf8.withContiguousStorageIfAvailable { buffer in
71-
guard let opaquePointer = OpaquePointer(buffer.baseAddress) else { return }
72-
let int8Pointer = UnsafePointer<Int8>(opaquePointer)
73-
sec_protocol_options_add_tls_application_protocol(options.securityProtocolOptions, int8Pointer)
84+
for applicationProtocol in self.applicationProtocols {
85+
applicationProtocol.withCString { buffer in
86+
sec_protocol_options_add_tls_application_protocol(options.securityProtocolOptions, buffer)
7487
}
75-
}*/
88+
}
7689

7790
// the certificate chain
7891
if self.certificateChain.count > 0 {

0 commit comments

Comments
 (0)