Motivation: Our previous namespacing effort used symbol analysis of a compiled binary to locate all the symbols that needed to be namespaced away. This works fine for regular C and C++ symbols, but fails for any header-only inline functions. These functions, while not emitted into the binary, can cause problems with the C++ ODR if they are included in multiple clang modules. This unfortunately does happen if the user includes both this library and, for example, modularised headers that include OpenSSL headers. Fortunately, we can namespace the inline functions as well. Modifications: - Namespaced all the inline headers by source analysis. Result: Fewer code conflicts.
SwiftNIO SSL
SwiftNIO SSL is a Swift package that contains an implementation of TLS based on BoringSSL. This package allows users of SwiftNIO to write protocol clients and servers that use TLS to secure data in flight.
The name is inspired primarily by the names of the library this package uses (BoringSSL), and not because we don't know the name of the protocol. We know the protocol is TLS!
Using SwiftNIO SSL
SwiftNIO SSL provides two ChannelHandlers to use to secure a data stream: the NIOSSLClientHandler and the NIOSSLServerHandler. Each of these can be added to a Channel to secure the communications on that channel.
Additionally, we provide a number of low-level primitives for configuring your TLS connections. These will be shown below.
To secure a server connection, you will need a X.509 certificate chain in a file (either PEM or DER, but PEM is far easier), and the associated private key for the leaf certificate. These objects can then be wrapped up in a TLSConfiguration object that is used to initialize the ChannelHandler.
For example:
let configuration = TLSConfiguration.forServer(certificateChain: [.file("cert.pem")], privateKey: .file("key.pem"))
let sslContext = try NIOSSLContext(configuration: configuration)
let handler = try NIOSSLServerHandler(context: sslContext)
// Add the created handler to the pipeline.
For clients, it is a bit simpler as there is no need to have a certificate chain or private key (though clients may have these things). Setup for clients may be done like this:
let configuration = TLSConfiguration.forClient()
let sslContext = try NIOSSLContext(configuration: configuration)
let handler = try NIOSSLClientHandler(context: sslContext)
// Add the created handler to the pipeline.