Files
swift-nio-ssl/Sources/NIOSSL/NIOSSLServerHandler.swift
T
Cory Benfield 024bbd111e Remove giant write test (#398)
Motivation:

The giant write test requires an enormous commitment of RAM to run it.
This has caused problems for both our own CI and a number of downstream
CI systems, leading to long execution times or outright failures.

Unfortunately, we can't defend against the original failure using this
test suite, but we can at least exercise the new machinery we added and
trust that the configuration is right.

Modifications:

- Make the maximum write size configurable internally
- Test the maximum write size at a different value.

Result:

We feel confident that the write splitting continues to work correctly.
2022-09-02 12:03:19 +01:00

93 lines
4.4 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import NIOCore
/// A channel handler that wraps a channel in TLS using NIOSSL. This
/// handler can be used in channels that are acting as the server in
/// the TLS dialog. For client connections, use the ``NIOSSLClientHandler``.
public final class NIOSSLServerHandler: NIOSSLHandler {
/// Construct a new ``NIOSSLServerHandler`` with the given `context`.
///
/// - parameters:
/// - context: The ``NIOSSLContext`` to use on this connection.
public convenience init(context: NIOSSLContext) {
self.init(context: context, optionalCustomVerificationCallback: nil, optionalAdditionalPeerCertificateVerificationCallback: nil)
}
@available(*, deprecated, renamed: "init(context:customVerificationCallback:)")
public init(context: NIOSSLContext, verificationCallback: NIOSSLVerificationCallback? = nil) throws {
guard let connection = context.createConnection() else {
fatalError("Failed to create new connection in NIOSSLContext")
}
connection.setAcceptState()
if let verificationCallback = verificationCallback {
connection.setVerificationCallback(verificationCallback)
}
super.init(connection: connection, shutdownTimeout: context.configuration.shutdownTimeout, additionalPeerCertificateVerificationCallback: nil, maxWriteSize: NIOSSLHandler.defaultMaxWriteSize)
}
/// Construct a new ``NIOSSLClientHandler`` with the given `context` and a specific `serverHostname`.
///
/// - parameters:
/// - context: The ``NIOSSLContext`` to use on this connection.
/// - customVerificationCallback: A callback to use that will override NIOSSL's normal verification logic.
///
/// If set, this callback is provided the certificates presented by the peer. NIOSSL will not have pre-processed them. The callback will not be used if the
/// ``TLSConfiguration`` that was used to construct the ``NIOSSLContext`` has ``TLSConfiguration/certificateVerification`` set to ``CertificateVerification/none``.
public convenience init(context: NIOSSLContext, customVerificationCallback: @escaping NIOSSLCustomVerificationCallback) {
self.init(context: context, optionalCustomVerificationCallback: customVerificationCallback, optionalAdditionalPeerCertificateVerificationCallback: nil)
}
/// - warning: This API is not guaranteed to be stable and is likely to be changed without further notice, hence the underscore prefix.
public static func _makeSSLServerHandler(
context: NIOSSLContext,
additionalPeerCertificateVerificationCallback: @escaping _NIOAdditionalPeerCertificateVerificationCallback
) -> Self {
.init(context: context, optionalCustomVerificationCallback: nil, optionalAdditionalPeerCertificateVerificationCallback: additionalPeerCertificateVerificationCallback)
}
/// This exists to handle the explosion of initializers I got when I deprecated the first one.
private init(
context: NIOSSLContext,
optionalCustomVerificationCallback: NIOSSLCustomVerificationCallback?,
optionalAdditionalPeerCertificateVerificationCallback: _NIOAdditionalPeerCertificateVerificationCallback?
) {
guard let connection = context.createConnection() else {
fatalError("Failed to create new connection in NIOSSLContext")
}
connection.setAcceptState()
if let customVerificationCallback = optionalCustomVerificationCallback {
connection.setCustomVerificationCallback(.init(callback: customVerificationCallback))
}
super.init(
connection: connection,
shutdownTimeout: context.configuration.shutdownTimeout,
additionalPeerCertificateVerificationCallback: optionalAdditionalPeerCertificateVerificationCallback,
maxWriteSize: NIOSSLHandler.defaultMaxWriteSize
)
}
}
#if swift(>=5.6)
@available(*, unavailable)
extension NIOSSLServerHandler: Sendable {}
#endif