Files
swift-nio-ssl/Sources/NIOOpenSSL/OpenSSLServerHandler.swift
T
Cory Benfield 081068d62f Support extracting public keys in handshakes. (#49)
Motivation:

Users have requested the ability to extract information about the
public keys provided by peers during TLS handshakes. This is a reasonable
request: it's potentially very useful to have access to this information.

While I'm reluctant to add too much in the way of general cryptographic
functionality, it seems like a good idea to enable it for others. For
this reason, this patch extends NIOOpenSSL to enable this use case.

Modifications:

1. Added an OpenSSLPublicKey class that can be serialized to bytes.
2. Added support for obtaining an OpenSSLPublicKey from an
    OpenSSLCertificate.
3. Added support for setting the OpenSSL cert verification callback.

Result:

Much more flexibility and power in the library.
2018-11-05 13:16:09 +00:00

36 lines
1.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2018 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 NIO
/// A channel handler that wraps a channel in TLS using OpenSSL, or an
/// OpenSSL-compatible library. This handler can be used in channels that
/// are acting as the server in the TLS dialog. For client connections,
/// use the `OpenSSLClientHandler`.
public final class OpenSSLServerHandler: OpenSSLHandler {
public init(context: SSLContext, verificationCallback: OpenSSLVerificationCallback? = nil) throws {
guard let connection = context.createConnection() else {
throw NIOOpenSSLError.unableToAllocateOpenSSLObject
}
connection.setAcceptState()
if let verificationCallback = verificationCallback {
connection.setVerificationCallback(verificationCallback)
}
super.init(connection: connection)
}
}