Skip to content

Commit

Permalink
Added TLSChannelConfiguration with async callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Feb 11, 2025
1 parent 1e8f9e2 commit 672f8b6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/HummingbirdHTTP2/TLSChannelConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import NIOSSL
/// TLSChannel configuration
public struct TLSChannelConfiguration: Sendable {
public typealias CustomVerificationCallback = @Sendable ([NIOSSLCertificate], EventLoopPromise<NIOSSLVerificationResult>) -> Void

// Manages configuration of TLS
public var tlsConfiguration: TLSConfiguration
/// A custom verification callback that allows completely overriding the certificate verification logic of BoringSSL.
Expand All @@ -38,6 +39,26 @@ public struct TLSChannelConfiguration: Sendable {
self.tlsConfiguration = tlsConfiguration
self.customVerificationCallback = customVerificationCallback
}

/// Initialize TLSChannel.Configuration
///
/// For details on custom callback see swift-nio-ssl documentation
/// https://swiftpackageindex.com/apple/swift-nio-ssl/main/documentation/niossl/niosslcustomverificationcallback
/// - Parameters:
/// - tlsConfiguration: TLS configuration
/// - customAsyncVerificationCallback: A custom verification callback that allows completely overriding the
/// certificate verification logic of BoringSSL.
public init(
tlsConfiguration: TLSConfiguration,
customAsyncVerificationCallback: @escaping @Sendable ([NIOSSLCertificate]) async throws -> NIOSSLVerificationResult
) {
self.tlsConfiguration = tlsConfiguration
self.customVerificationCallback = { certificates, promise in
promise.completeWithTask {
try await customAsyncVerificationCallback(certificates)
}
}
}

Check warning on line 61 in Sources/HummingbirdHTTP2/TLSChannelConfiguration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HummingbirdHTTP2/TLSChannelConfiguration.swift#L54-L61

Added lines #L54 - L61 were not covered by tests
}

/// TLSChannel configuration
Expand Down
21 changes: 21 additions & 0 deletions Sources/HummingbirdTLS/TLSChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ extension ServerChildChannel {
/// TLSChannel configuration
public struct TLSChannelConfiguration: Sendable {
public typealias CustomVerificationCallback = @Sendable ([NIOSSLCertificate], EventLoopPromise<NIOSSLVerificationResult>) -> Void

// Manages configuration of TLS
public let tlsConfiguration: TLSConfiguration
/// A custom verification callback that allows completely overriding the certificate verification logic of BoringSSL.
Expand All @@ -115,6 +116,26 @@ public struct TLSChannelConfiguration: Sendable {
self.tlsConfiguration = tlsConfiguration
self.customVerificationCallback = customVerificationCallback
}

/// Initialize TLSChannel.Configuration
///
/// For details on custom callback see swift-nio-ssl documentation
/// https://swiftpackageindex.com/apple/swift-nio-ssl/main/documentation/niossl/niosslcustomverificationcallback
/// - Parameters:
/// - tlsConfiguration: TLS configuration
/// - customAsyncVerificationCallback: A custom verification callback that allows completely overriding the
/// certificate verification logic of BoringSSL.
public init(
tlsConfiguration: TLSConfiguration,
customAsyncVerificationCallback: @escaping @Sendable ([NIOSSLCertificate]) async throws -> NIOSSLVerificationResult
) {
self.tlsConfiguration = tlsConfiguration
self.customVerificationCallback = { certificates, promise in
promise.completeWithTask {
try await customAsyncVerificationCallback(certificates)
}
}
}

Check warning on line 138 in Sources/HummingbirdTLS/TLSChannel.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HummingbirdTLS/TLSChannel.swift#L131-L138

Added lines #L131 - L138 were not covered by tests
}

/// TLSChannel configuration
Expand Down

0 comments on commit 672f8b6

Please sign in to comment.