Swiftpack.co - apple/swift-nio-ssl as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by apple.
apple/swift-nio-ssl 2.20.0
TLS Support for SwiftNIO, based on BoringSSL.
⭐️ 326
🕓 2 weeks ago
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.20.0")


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!

To get started, check out the API docs.

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.makeServerConfiguration(
    certificateChain: try NIOSSLCertificate.fromPEMFile("cert.pem").map { .certificate($0) },
    privateKey: .file("key.pem")
let sslContext = try NIOSSLContext(configuration: configuration)

let server = ServerBootstrap(group: group)
    .childChannelInitializer { channel in
        // important: The handler must be initialized _inside_ the `childChannelInitializer`
        let handler = NIOSSLServerHandler(context: sslContext)


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.makeClientConfiguration()
let sslContext = try NIOSSLContext(configuration: configuration)

let client = ClientBootstrap(group: group)
    .channelInitializer { channel in
        // important: The handler must be initialized _inside_ the `channelInitializer`
        let handler = try NIOSSLClientHandler(context: sslContext)


Note that SwiftNIO SSL currently requires Swift 5.4 and above. Release 2.13.x and prior support Swift 5.0 and 5.1, Release 2.18.x and prior supports Swift 5.2 and 5.3.


Stars: 326
Last commit: 4 hours ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.


Release Notes

SwiftNIO SSL 2.20.0
2 weeks ago

SemVer Minor

  • Add NIOSSLCertificateExtensions (#359)

SemVer Patch

  • Port SecureBytes from Swift Crypto to use with TLS-PSK (#366, patch credit to @agnosticdev)
  • Add support for owned references to NIOSSLObjectIdentifier (#358)
  • Support additional certificate validation (#361)
  • Flush only after handshake (#362)
  • Update BoringSSL to 1e469e45a46ff580899cbef939babe02ad916c85 (#370)

Other Changes

  • Parallel test fix for TLSConfigurationTest (#368, patch credit to @agnosticdev)
  • Update pod generation script (#363)
  • Remove build_podspec.sh (#365)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics