### Motivation:
Swift 5.10 is no longer supported, we should bump the swift-tools
version.
### Modifications:
* Update Swift tools version to 6.0
* Correct the failing tests on macOS
### Result:
Code reflects our support window.
Currently, the certs returned by the sslContextCallback are added to the
context, rather than replacing the certs already in the context.
This means that, if a callback is used to return a new chain to be used,
the old and new chains are both presented (but only the new leaf). This
should not cause any problem, but it is inefficient
Change: Clear the additional certs before adding the new ones
Motivation:
It is sometimes useful, such as when converting between configuration
formats, to be able to recover the `TLSConfiguration` with which an
`NIOSSLContext` was created. This is not possible with the current API;
since the property is immutable, making it public poses no risk.
Modifications:
The `NIOSSLContext.configuration` property is now `public` instead of
`internal`. (Also, an extremely obsolete Linux testing note was removed
from `CONTRIBUTING.md`.)
Result:
This change has no functional impact; all behavior remains identical.
The only effect is to add the `configuration` property to the public API
of `NIOSSLContext`.
Motivation:
Users are currently able to register a custom callback in
`NIOSSLClientHandler` and `NIOSSLServerHandler` for verifiying the
certificates presented by the peer. However, there is no mechanism for
storing additional metadata for future use. This change adds support for
the peer's validated certificate chain to be returned from the custom
verification callback and later be accessed from the handler.
Modifications:
- Added a new custom verification callback type
`NIOSSLCustomVerificationCallbackWithMetadata`.
- This type is identical to the existing
`NIOSSLCustomVerificationCallback`, with the exception that callers must
complete the callback with a `NIOSSLVerificationResultWithMetadata`
(also introduced in this change). This result type can either be
initialized with no fields, or with a validated certificate chain.
- Added properties/methods to `NIOSSLHandler`, `Channel`, and
`ChannelPipeline` for accessing the validated certificate chain.
Result:
Users are now able to store the peer's validated certificate chain from
the custom verification callback and use the result downstream.
Motivation:
Documentation should accurately explain the methods.
Modifications:
Removed the phrase "providing a passphrase callback"
Result:
Documentation is more accurate
Motivation:
In #550 a use of `NIOSSLCertificafe(file:format:)` was replaced with
`NIOSSLCertificafe.loadPEMFile(_:).first`, which isn't necessarily the
same (the error flow is different for one). To avoid any subtle
behaioral changes revert back to the old API in that one instance.
Modifications:
- Use old API
Result:
Fewer behavioural changes
Motivation:
NIOSSLCertificate has an 'init' which loads a single cert from PEM or
DER encoded file. This, obviously, only loads the first PEM which is
very rarely what users actually want to do. This is a common source of
error when loading cert chains and is easy to miss in review.
Modifications:
- Deprecate the init and point users to the `fromPEMBytes` method for
PEM which returns an array of certs, and to a new `fromDERBytes` which
returns a single cert.
Result:
Harder to misuse API
Motivation:
The trust roots settings have sometimes got non-obvious impacts on which
validator is used. These are a legacy behaviour and so changing them is
likely to cause services to encounter challenging bugs, so it's probably
not worth fixing this behaviour without doing a deprecate-and-replace
cycle.
A deprecate-and-replace of TLSConfiguration is going to be necessary in
the near-term because it is a suboptimal structure that is carrying a
lot of load. For now, however, let's just make it possible for users to
diagnose what is going on.
Modifications:
- Document the existing behaviour
Result:
Users have a chance of figuring out what is going on.
Motivation:
When configuring for mTLS, there is really only one right way to do
that. This adds that behaviour.
Modifications:
- Add mTLSConfiguration option
- Add tests
Result:
Better behaviour for mTLS.
Resolves#542
Reverts apple/swift-nio-ssl#543
This may have resulted in a behavior change which would adversely affect
downstream, we should back it out whilst we investigate.
Motivation:
If a user sets the trust roots to a non-`none` value, they presumably
want to actually validate them. This patch enables an automatic setting
of validation if the trust roots are set.
Modifications:
- Use a didSet on TLSConfiguration to raise hostname validation when the
trustRoots are set.
- Fix up cases where the tests were doing the wrong thing
Result:
Safer APIs.
Motivation:
The certificate override callback incorrectly cached results on the
SSLContext, instead of the SSLConnection. The result is that it would
only fire once for a given SSLContext, instead of on every connection,
incorrectly caching the result indefinitely.
Modifications:
Move the callback state to SSLConnection
Write tests to validate that the callback is called the right
number of times.
Result:
Better behaviour.
This PR adds new API (`SSLPrivateKey/toDerBytes()`) to get the DER bytes
for a private key.
This is only supported for native (EVP) keys; if using a custom key, an
empty array of bytes will be returned instead.
This fixes linker errors such as
```
"CNIOBoringSSLShims_SSL_CTX_get_app_data(CNIOBoringSSL_ssl_ctx_st const*)", referenced from:
static NIOSSL.NIOSSLContext.(lookupFromRawContext in <...>)(ssl: Swift.OpaquePointer) -> NIOSSL.NIOSSLContext in SSLContext.swift.o
```
when building with Swift/C++ interoperability enabled.
This is similar to https://github.com/apple/swift-nio/pull/3251.
Motivation:
Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.
Modifications:
* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml
Result:
Code reflects our support window.
Motivation:
While we've supported the hybrid quantum-resistant KEM for a while
(because BoringSSL has), users have had to define the constant
themselves.
This patch makes the quantum-resistant KEM part of our API.
Modifications:
- Expose x25519_MLKEM768 as a curve type.
- Add tests
Result:
More quantum-resistance.
Motivation:
While swift-nio-ssl supports mTLS on the server, there's no api
available to get the verified X509 certificate after the handshake
completes.
Additionally, the existing API for NIOSSLCertificate doesn't have an API
to access the issuer and subject names.
Result:
These changes add new APIs. Specifically:
- nioSSL_peerCertificate() to the channel extension. Similar to
retrieving the tls version, this gets the verified peer X509 certificate
after the handshake completes.
- subjectName extension to NIOSSLCertificate. Grabs the subjectName from
the BoringSSL X509 object as an array of SSLCertificateName
- issuerName extension to the NIOSSLCertificate. Grabs the issuerName
from the BoringSSL X509 object as an array of SSLCertificateName
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
When viewing the documentation, deprecated methods clutter up available
options, sometimes below, making those options hard to find for a
developer working out how to add or create a TLSConfiguration.
Modifications:
Adds a DocC extension file (markdown format) the provides curation
(organization of the symbols) to order by task and ideally usefulness,
with deprecated methods pushed downward.
Result:
The documentation at
https://swiftpackageindex.com/apple/swift-nio-ssl/main/documentation/niossl/tlsconfiguration
(and future releases) will include this organization and be easier to
read through for developers.
A number of statics in the product code aren't something the compiler
currently believes are Sendable. There are a few tweaks here:
1. Two pointer statics into BoringSSL. These are thread-safe, but the
compiler doesn't know. Mark them `nonisolated(unsafe)`.
2. One static `var` should be a static `let`.
3. One instance of reminding the compiler that closures that don't
capture anything are Sendable.
Motivation:
swift-nio-ssl has long had a flag to disable its own certificate
validation behaviour. This flag works fine, and had the desired effect.
However, this flag did not take account of the fact that
Security.framework _also_ validates the hostname. Due to an
implementation bug, setting .noHostnameVerification disabled only one of
the two checks.
Modifications:
- Correctly check the flag before passing a hostname to
Security.framework
- Write some tests to make sure the behaviour works in all modes.
Result:
Better, more consistent behaviour.
Motivation:
The sslContextCallback overrides modify the SSL_CTX object itself.
That's not useful: in addition to having a global effect, which is
rarely what we want, certain modifications don't apply that late, and
setting the credentials is one of them. The result is that the callback
didn't actually do anything. Not that useful.
Modifications:
- Extract the cert chain setting functions from NIOSSLContext and move
them to general-purpose functions.
- Add support there for calling them on a SSL * as well as on a SSL_CTX
*
- Call them in an override function on SSLConnection
- Call that!
- Add a bunch of tests.
Result:
The callback actually does what it should.
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.
## Motivation
It would be handy to provide an API to create PKCS#12 files from a list
of `NIOSSLCertificates` and a `NIOSSLPrivateKey`.
This would be particularly useful when dealing with
Network.framework/NIOTransportServices/Security.framework, which use
`SecIdentity`s for SSL. Two particular use cases are
https://github.com/apple/swift-nio-ssl/issues/484#issuecomment-2410375188
and `grpc-swift-nio-transport`, which would use this API for testing the
NIOTS transport implementation.
## Modifications
This PR adds a static method to `NIOSSLPKCS12Bundle` that creates a
PKCS#12 file from the given array of certificates + private key, and
returns it as an array of bytes.
## Result
PKCS#12 files can be created using NIOSSL.
Migrate CI to use GitHub Actions.
### Motivation:
To migrate to GitHub actions and centralised infrastructure.
### Modifications:
Changes of note:
* Disable warnings-as-errors until issues with recent NIO changes are
resolved
* Adopt swift-format using rules from SwiftNIO
* Remove scripts which are no longer needed
### Result:
Feature parity with old CI minus allocation tests which remain on the
old CI.
This PR adds the support to specify what ECs the handler supports when
doing the handshake.
```swift
var config = TLSConfiguration.makeClientConfiguration()
config.curves = [.x25519]
```
This patch has 3 parts: a commit to update the vendoring script, a
commit that contains the results of running the script, and then a fixup
for the API breaks we got.
Hello,
As I was trying to implement some HTTP calls using `async-http-client`
and TLS-PSK authentication, I realised that my server was not sending
any PSK hint.
The actual implementation of the clientPSKCallback makes the server psk
hint mandatory.
Similarly the implementation of the serverPSKCallback makes the server
hint mandatory.
Reading
[RFC4279](https://datatracker.ietf.org/doc/html/rfc4279#section-5.2) it
seems that on the opposite the server psk hint should be provided only
on application that mandate it.
> [5.2](https://datatracker.ietf.org/doc/html/rfc4279#section-5.2).
Identity Hint
> In the absence of an application profile specification specifying
> otherwise, servers SHOULD NOT provide an identity hint and clients
> MUST ignore the identity hint field. Applications that do use this
> field MUST specify its contents, how the value is chosen by the TLS
> server, and what the TLS client is expected to do with the value.
I made this PR to provide an empty string to the callbacks in the case
the server doesn't provide one.
Providing an optional might be a better solution in term of semantic but
it would break the API.
---------
Co-authored-by: Martial Lienert <mlienert@netatmo.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
The NIOSSLHandler can enter a spin loop in `doUnbufferActions` if
writing data into BoringSSL fails with SSL_ERROR_WANT_READ or
SSL_ERROR_WANT_WRITE.
One way these errors can happen is if a write into BoringSSL happens
prior to the handshake completing. The NIOSSLHandler is explicit about
starting the handshake: it's done in channel active and in handler added
if the channel is already active.
However, the handshaking step is currently done without any state
checking, so if the state is 'closed' (as it would be after channel
inactive) then the handshake will still start. This can happen if
channel inactive happens before channel active.
To reach the write loop there must be a buffered write and flush prior
to the handshake step starting and the state isn't 'idle' or
'handshaking'. This can happen if a write and flush hapens while
'NIOSSLHandler' is in 'channelActive' (it forwards the 'channelActive'
event _before_ starting the handshake) and 'channelInactive' came first.
Modifications:
- Early exit from 'doHandshakeStep' if the state isn't applicable for
starting a handshake.
- Don't buffer writes when the state is 'closed' as they'll never
succeed and can be failed immediately.
- If the write isn't succesful in 'doUnbufferActions' then either write
to the network or try reading.
- Only allow a limited number of spins through 'doUnbufferActions'
Result:
- Resolves https://github.com/apple/swift-nio-ssl/issues/467
Motivation:
Per @jakepetroules, swift-build copies symlinks as-is into resource
bundles. That means these symlinks are dead when built with swift-build.
There's sort of no point in that.
Modifications:
Remove symlinks, replace with files.
Result:
Privacy info works.
swift-nio-ssl expects file to in specific format when loading the PrivateKey from a file baed on the extension of the file. This is prone to errors, since there is no standard agreement on the extension and format of the file.
An example of a mismatch is `.key` swift-nio-ssl tries to load such file as DER, though these can be in PEM format too.
We could based on the binary contents of the file provided infer the format of the file, but it doesn't seem like a logic this library should own. The clients should be able to load the file themselves.
In this PR `.file` case is marked deprecated and relevant deprecation flags and documentation is added to point to the preferred option.
Motivation:
When the private key file for a TLS configuration has an unknown type, the program crashes. Hence, users are unable to catch the error.
Modifications:
A new error was added to `NIOSSLExtraError` and the program throws that error instead of crashing.
Result:
The program now throws an error instead of crashing.
Motivation:
NIOSSL distributes a copy of BoringSSL, which means it needs a privacy
manifest.
Modifications:
- Add a privacy manifest
Result:
NIOSSL shouldn't be rejected from app submission by not declaring a
privacy manifest.