Cory Benfield 9cb641037b Enable X509_V_FLAG_TRUSTED_FIRST. (#220)
Motivation:

Unfortunately, while BoringSSL is mostly a fundamentally fantastic
library, it has inherited OpenSSL's X509 verifier. This verifier has a
number of issues, but its biggest problem is that it's simply not great
at verifying certificates!

Certificate chains are not so much "chains" as they are a single path
through a DAG. There are potentially many possible paths from a leaf
certificate to a set of roots. Some of these paths are not trusted, some
may be. BoringSSL's default verifier does not do a good job in some edge
cases because it prefers to use the intermediates provided by the client
when it could do a better job by using its own trust store.

As an example, consider the following three-certificate "chain":

CA A -- signs -- Intermediate CA B -- signs -- Leaf C

Imagine that CA A now becomes untrusted, either because it was revoked
or (more topically) because it expires. Imagine also that, in the
meantime, Intermediate CA B has become a fully-fledged CA, and has
re-issued its certificate as a self-signed root using the same key and
identifier.

The mistaken resolver may attempt to use as many certificates as
possible from the peer chain. If the peer chain is using the old,
now-replaced intermediate CA, this will cause BoringSSL to get confused:
it will build a chain that chains up to the intermediate CA, find the
old root in the trust store, and then complain that that root is expired
and fail the validation.

Instead, we want to ignore the intermediate CA B altogether! This is
because we now have a trusted root B', and if we use that then we'll
instantly get a valid chain and can move on.

This behaviour is controlled by a flag, `X509_V_FLAG_TRUSTED_FIRST`.
This flag is set by default in OpenSSL 1.1+. Sadly, it is not set by
default in BoringSSL. This patch resolves that issue.

Note that this issue only affects non-Apple platforms. On Apple
platforms we use the system resolver, which does not have this issue.

Modifications:

- Set `X509_V_FLAG_TRUSTED_FIRST`.
- Add a test to verify that flag is set.

Result:

We'll do a better (but still bad) job of building trust chains.
2020-06-04 20:39:42 +01:00
2020-05-05 08:49:53 +01:00
2020-03-23 16:26:05 +00:00
2018-01-24 12:13:14 +00:00
2018-01-24 12:13:14 +00:00
2018-01-24 12:13:14 +00:00
2019-02-25 16:52:26 +00:00
2020-03-04 16:04:20 +00:00

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!

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.forServer(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 = try NIOSSLServerHandler(context: sslContext)

        [...]
        channel.pipeline.addHandler(handler)
        [...]
    }

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 client = ClientBootstrap(group: group)
    .channelInitializer { channel in
        // important: The handler must be initialized _inside_ the `channelInitializer`
        let handler = try NIOSSLClientHandler(context: sslContext)

        [...]
        channel.pipeline.addHandler(handler)
        [...]
    }
S
Description
Mirror of github.com/apple/swift-nio-ssl
Readme Apache-2.0
19 MiB
0 Stars 1 Watchers 0 Forks
Languages
Assembly 33.1%
C++ 31%
C 26.5%
Swift 6.6%
NASL 1.8%
Other 0.9%