Skip to content

Commit 102b7e4

Browse files
authored
Update NIO family dependencies to 5.2+ versions and fix deprecations (#381)
Updated: NIO NIOSSL NIO Extras NIOTS Also fix TLSConfiguration.forClient() warnings by converting to TLSConfiguration.makeClientConfiguration(). Also the same for forServer().
1 parent 132dc3e commit 102b7e4

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed

Diff for: Package.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ let package = Package(
2121
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"]),
2222
],
2323
dependencies: [
24-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.29.0"),
25-
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.13.0"),
26-
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.9.1"),
27-
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.5.1"),
24+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.30.0"),
25+
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.0"),
26+
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.10.0"),
27+
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.11.0"),
2828
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.0"),
2929
],
3030
targets: [

Diff for: Sources/AsyncHTTPClient/HTTPClient.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public class HTTPClient {
637637

638638
/// `HTTPClient` configuration.
639639
public struct Configuration {
640-
/// TLS configuration, defaults to `TLSConfiguration.forClient()`.
640+
/// TLS configuration, defaults to `TLSConfiguration.makeClientConfiguration()`.
641641
public var tlsConfiguration: Optional<TLSConfiguration>
642642
/// Enables following 3xx redirects automatically, defaults to `RedirectConfiguration()`.
643643
///
@@ -701,7 +701,9 @@ public class HTTPClient {
701701
proxy: Proxy? = nil,
702702
ignoreUncleanSSLShutdown: Bool = false,
703703
decompression: Decompression = .disabled) {
704-
self.init(tlsConfiguration: TLSConfiguration.forClient(certificateVerification: certificateVerification),
704+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
705+
tlsConfig.certificateVerification = certificateVerification
706+
self.init(tlsConfiguration: tlsConfig,
705707
redirectConfiguration: redirectConfiguration,
706708
timeout: timeout,
707709
connectionPool: ConnectionPool(),
@@ -718,7 +720,9 @@ public class HTTPClient {
718720
ignoreUncleanSSLShutdown: Bool = false,
719721
decompression: Decompression = .disabled,
720722
backgroundActivityLogger: Logger?) {
721-
self.init(tlsConfiguration: TLSConfiguration.forClient(certificateVerification: certificateVerification),
723+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
724+
tlsConfig.certificateVerification = certificateVerification
725+
self.init(tlsConfiguration: tlsConfig,
722726
redirectConfiguration: redirectConfiguration,
723727
timeout: timeout,
724728
connectionPool: ConnectionPool(),

Diff for: Sources/AsyncHTTPClient/Utils.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extension NIOClientTCPBootstrap {
7272
//
7373
// Note that TLS proxies are not supported at the moment. This means that we will always speak
7474
// plaintext to the proxy but we do support sending HTTPS traffic through the proxy.
75-
sslContext = sslContextCache.sslContext(tlsConfiguration: configuration.tlsConfiguration ?? .forClient(),
75+
sslContext = sslContextCache.sslContext(tlsConfiguration: configuration.tlsConfiguration ?? .makeClientConfiguration(),
7676
eventLoop: eventLoop,
7777
logger: logger).map { $0 }
7878
} else {
@@ -130,7 +130,7 @@ extension NIOClientTCPBootstrap {
130130
eventLoop: eventLoop,
131131
requiresTLS: requiresTLS,
132132
sslContextCache: sslContextCache,
133-
tlsConfiguration: configuration.tlsConfiguration ?? .forClient(),
133+
tlsConfiguration: configuration.tlsConfiguration ?? .makeClientConfiguration(),
134134
useProxy: configuration.proxy != nil,
135135
logger: logger)
136136
.map { bootstrap -> NIOClientTCPBootstrap in

Diff for: Tests/AsyncHTTPClientTests/HTTPClientNIOTSTests.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ class HTTPClientNIOTSTests: XCTestCase {
9797
guard isTestingNIOTS() else { return }
9898
#if canImport(Network)
9999
let httpBin = HTTPBin(ssl: true)
100+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
101+
tlsConfig.certificateVerification = .none
102+
tlsConfig.minimumTLSVersion = .tlsv11
103+
tlsConfig.maximumTLSVersion = .tlsv1
100104
let httpClient = HTTPClient(
101105
eventLoopGroupProvider: .shared(self.clientGroup),
102-
configuration: .init(tlsConfiguration: TLSConfiguration.forClient(minimumTLSVersion: .tlsv11, maximumTLSVersion: .tlsv1, certificateVerification: .none))
106+
configuration: .init(tlsConfiguration: tlsConfig)
103107
)
104108
defer {
105109
XCTAssertNoThrow(try httpClient.syncShutdown(requiresCleanClose: true))
@@ -116,7 +120,8 @@ class HTTPClientNIOTSTests: XCTestCase {
116120
guard isTestingNIOTS() else { return }
117121
#if canImport(Network)
118122
if #available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
119-
let tlsConfig = TLSConfiguration.forClient(trustRoots: .file("not/a/certificate"))
123+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
124+
tlsConfig.trustRoots = .file("not/a/certificate")
120125

121126
XCTAssertThrowsError(try tlsConfig.getNWProtocolTLSOptions()) { error in
122127
switch error {

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ internal final class HTTPBin {
289289
}
290290

291291
static func configureTLS(channel: Channel) -> EventLoopFuture<Void> {
292-
let configuration = TLSConfiguration.forServer(certificateChain: [.certificate(try! NIOSSLCertificate(bytes: Array(cert.utf8), format: .pem))],
293-
privateKey: .privateKey(try! NIOSSLPrivateKey(bytes: Array(key.utf8), format: .pem)))
292+
let configuration = TLSConfiguration.makeServerConfiguration(certificateChain: [.certificate(try! NIOSSLCertificate(bytes: Array(cert.utf8), format: .pem))],
293+
privateKey: .privateKey(try! NIOSSLPrivateKey(bytes: Array(key.utf8), format: .pem)))
294294
let context = try! NIOSSLContext(configuration: configuration)
295295
return channel.pipeline.addHandler(NIOSSLServerHandler(context: context), position: .first)
296296
}
@@ -773,8 +773,8 @@ internal class HttpBinForSSLUncleanShutdown {
773773
.childChannelInitializer { channel in
774774
let requestDecoder = HTTPRequestDecoder()
775775
return channel.pipeline.addHandler(ByteToMessageHandler(requestDecoder)).flatMap {
776-
let configuration = TLSConfiguration.forServer(certificateChain: [.certificate(try! NIOSSLCertificate(bytes: Array(cert.utf8), format: .pem))],
777-
privateKey: .privateKey(try! NIOSSLPrivateKey(bytes: Array(key.utf8), format: .pem)))
776+
let configuration = TLSConfiguration.makeServerConfiguration(certificateChain: [.certificate(try! NIOSSLCertificate(bytes: Array(cert.utf8), format: .pem))],
777+
privateKey: .privateKey(try! NIOSSLPrivateKey(bytes: Array(key.utf8), format: .pem)))
778778
let context = try! NIOSSLContext(configuration: configuration)
779779
return channel.pipeline.addHandler(NIOSSLServerHandler(context: context), name: "NIOSSLServerHandler", position: .first).flatMap {
780780
channel.pipeline.addHandler(HttpBinForSSLUncleanShutdownHandler(channelPromise: channelPromise))

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,10 @@ class HTTPClientTests: XCTestCase {
28582858

28592859
// We use a specially crafted client that has no cipher suites to offer. To do this we ask
28602860
// only for cipher suites incompatible with our TLS version.
2861-
let tlsConfig = TLSConfiguration.forClient(minimumTLSVersion: .tlsv13, maximumTLSVersion: .tlsv12, certificateVerification: .none)
2861+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
2862+
tlsConfig.minimumTLSVersion = .tlsv13
2863+
tlsConfig.maximumTLSVersion = .tlsv12
2864+
tlsConfig.certificateVerification = .none
28622865
let localHTTPBin = HTTPBin(ssl: true)
28632866
let localClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
28642867
configuration: HTTPClient.Configuration(tlsConfiguration: tlsConfig))
@@ -2951,15 +2954,17 @@ class HTTPClientTests: XCTestCase {
29512954
}
29522955

29532956
// First two requests use identical TLS configurations.
2954-
let firstRequest = try HTTPClient.Request(url: "https://localhost:\(localHTTPBin.port)/get", method: .GET, tlsConfiguration: .forClient(certificateVerification: .none))
2957+
var tlsConfig = TLSConfiguration.makeClientConfiguration()
2958+
tlsConfig.certificateVerification = .none
2959+
let firstRequest = try HTTPClient.Request(url: "https://localhost:\(localHTTPBin.port)/get", method: .GET, tlsConfiguration: tlsConfig)
29552960
let firstResponse = try localClient.execute(request: firstRequest).wait()
29562961
guard let firstBody = firstResponse.body else {
29572962
XCTFail("No request body found")
29582963
return
29592964
}
29602965
let firstConnectionNumber = try decoder.decode(RequestInfo.self, from: firstBody).connectionNumber
29612966

2962-
let secondRequest = try HTTPClient.Request(url: "https://localhost:\(localHTTPBin.port)/get", method: .GET, tlsConfiguration: .forClient(certificateVerification: .none))
2967+
let secondRequest = try HTTPClient.Request(url: "https://localhost:\(localHTTPBin.port)/get", method: .GET, tlsConfiguration: tlsConfig)
29632968
let secondResponse = try localClient.execute(request: secondRequest).wait()
29642969
guard let secondBody = secondResponse.body else {
29652970
XCTFail("No request body found")
@@ -2968,7 +2973,10 @@ class HTTPClientTests: XCTestCase {
29682973
let secondConnectionNumber = try decoder.decode(RequestInfo.self, from: secondBody).connectionNumber
29692974

29702975
// Uses a differrent TLS config.
2971-
let thirdRequest = try HTTPClient.Request(url: "https://localhost:\(localHTTPBin.port)/get", method: .GET, tlsConfiguration: .forClient(maximumTLSVersion: .tlsv1, certificateVerification: .none))
2976+
var tlsConfig2 = TLSConfiguration.makeClientConfiguration()
2977+
tlsConfig2.certificateVerification = .none
2978+
tlsConfig2.maximumTLSVersion = .tlsv1
2979+
let thirdRequest = try HTTPClient.Request(url: "https://localhost:\(localHTTPBin.port)/get", method: .GET, tlsConfiguration: tlsConfig2)
29722980
let thirdResponse = try localClient.execute(request: thirdRequest).wait()
29732981
guard let thirdBody = thirdResponse.body else {
29742982
XCTFail("No request body found")

Diff for: Tests/AsyncHTTPClientTests/SSLContextCacheTests.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class SSLContextCacheTests: XCTestCase {
2626
XCTAssertNoThrow(try group.syncShutdownGracefully())
2727
}
2828

29-
XCTAssertNoThrow(try cache.sslContext(tlsConfiguration: .forClient(),
29+
XCTAssertNoThrow(try cache.sslContext(tlsConfiguration: .makeClientConfiguration(),
3030
eventLoop: eventLoop,
3131
logger: HTTPClient.loggingDisabled).wait())
3232
}
@@ -42,10 +42,10 @@ final class SSLContextCacheTests: XCTestCase {
4242
var firstContext: NIOSSLContext?
4343
var secondContext: NIOSSLContext?
4444

45-
XCTAssertNoThrow(firstContext = try cache.sslContext(tlsConfiguration: .forClient(),
45+
XCTAssertNoThrow(firstContext = try cache.sslContext(tlsConfiguration: .makeClientConfiguration(),
4646
eventLoop: eventLoop,
4747
logger: HTTPClient.loggingDisabled).wait())
48-
XCTAssertNoThrow(secondContext = try cache.sslContext(tlsConfiguration: .forClient(),
48+
XCTAssertNoThrow(secondContext = try cache.sslContext(tlsConfiguration: .makeClientConfiguration(),
4949
eventLoop: eventLoop,
5050
logger: HTTPClient.loggingDisabled).wait())
5151
XCTAssertNotNil(firstContext)
@@ -64,12 +64,14 @@ final class SSLContextCacheTests: XCTestCase {
6464
var firstContext: NIOSSLContext?
6565
var secondContext: NIOSSLContext?
6666

67-
XCTAssertNoThrow(firstContext = try cache.sslContext(tlsConfiguration: .forClient(),
67+
XCTAssertNoThrow(firstContext = try cache.sslContext(tlsConfiguration: .makeClientConfiguration(),
6868
eventLoop: eventLoop,
6969
logger: HTTPClient.loggingDisabled).wait())
7070

7171
// Second one has a _different_ TLSConfiguration.
72-
XCTAssertNoThrow(secondContext = try cache.sslContext(tlsConfiguration: .forClient(certificateVerification: .none),
72+
var testTLSConfig = TLSConfiguration.makeClientConfiguration()
73+
testTLSConfig.certificateVerification = .none
74+
XCTAssertNoThrow(secondContext = try cache.sslContext(tlsConfiguration: testTLSConfig,
7375
eventLoop: eventLoop,
7476
logger: HTTPClient.loggingDisabled).wait())
7577
XCTAssertNotNil(firstContext)

0 commit comments

Comments
 (0)