423 Commits
Author SHA1 Message Date
Si Beaumont d930168b86 Merge commit from fork
When building the byte view of a subject alternative name, NIOSSL reads
the `ASN1_STRING` member of the BoringSSL `GENERAL_NAME` union for every
entry without checking the name's type. The union only holds an
`ASN1_STRING` for the string-shaped GeneralName types (`dNSName`,
`rfc822Name`, `uniformResourceIdentifier`, `iPAddress`). For the other
types (`otherName`, `x400Address`, `directoryName`, `ediPartyName`,
`registeredID`) the union holds a different structure, so this reads the
buffer's base pointer and length out of unrelated memory.

The SAN list is parsed from an X.509 certificate, which is untrusted in
the usual TLS/mTLS case, and `contents` is reachable through the public,
albeit underscored, `_subjectAlternativeNames()` API.

NIOSSL should only interpret the union as an `ASN1_STRING` for the
string-shaped types and expose empty contents for the rest.

- In `_SubjectAlternativeNames.Storage.subscript`, switch on the GeneralName
  type. Build the `ASN1_STRING`-backed byte buffer only for `dNSName`,
  `rfc822Name`, `uniformResourceIdentifier` and `iPAddress`; expose an empty
  buffer for every other type.
- Add a test that parses a certificate carrying an `otherName` SAN followed by a
  `dNSName`, asserting the `otherName` has empty `contents` while the `dNSName`
  is read normally.

Reading the `contents` of a non-string subject alternative name no longer reads
out of bounds; it returns empty. String-typed names are unaffected. NIOSSL's
built-in identity verification already filters by name type, so the default
handshake path was not affected; this fixes the behaviour for callers of
`_subjectAlternativeNames()` that read `contents` for arbitrary name types.
2.37.2
2026-07-15 13:05:47 +01:00
Si Beaumont fd221573c7 Reserve a byte for the NUL terminator in the PSK client identity (#588)
### Motivation

When a PSK cipher suite is negotiated on the client, BoringSSL's
gives our callback a buffer of length `PSK_MAX_IDENTITY_LEN` + 1, and
passes its full size as `max_identity_len`. The callback is expected to
populate the identity with a NUL-terminated string, which is relied upon
by the subsequent BoringSSL code, which calls `strdup`. However, our
code guarded the adopter-provided identity against the
`max_identity_len`, without taking into account the space for the NUL,
so it permitted identities of length `PSK_MAX_IDENTITY_LEN` and
clobbered the NUL, leading to UB.

### Modifications

- In `clientPSKCallback`, reject identities whose length is `>=
  max_identity_len` (was `>`).
- NUL-terminate the copied identity explicitly. BoringSSL is
  zero-initialising the buffer, but it's not documented to behaviour and
  it doesn't hurt for us to be safe.
- Add a test that shows we accept an identity of `PSK_MAX_IDENTITY_LEN`
- Add a test that shows we reject an identity of `PSK_MAX_IDENTITY_LEN`
  + 1 bytes (previously accepted).

### Result

An adopter-supplied PSK client identity of exactly `max_identity_len`
bytes is now rejected instead of triggering an out-of-bounds read in
BoringSSL's `OPENSSL_strdup`. Identities up to `PSK_MAX_IDENTITY_LEN`
still work.
2026-07-10 11:13:08 +01:00
f6b21a8b27 NIOSSL: enable CA trust roots for FreeBSD (#587)
## Summary

`platformDefaultConfiguration()` in `SSLContext.swift` has branches for
Linux and Android but not FreeBSD. On FreeBSD the function is a no-op:
no CA trust roots are loaded, so every HTTPS client connection fails
immediately with `CERTIFICATE_VERIFY_FAILED`.

`LinuxCABundle.swift` already compiles for FreeBSD (`#if os(Linux) ||
os(FreeBSD)`) and defines `rootCAFilePath`/`rootCADirectoryPath`, but
the search path arrays contained only Linux distro paths — no FreeBSD
path was ever matched, so `rootCAFilePath` and `rootCADirectoryPath`
were always `nil`.

## Changes

**`SSLContext.swift`** — one line:
```diff
-#if os(Linux)
+#if os(Linux) || os(FreeBSD)
```

**`LinuxCABundle.swift`** — add FreeBSD paths to both search arrays:
```swift
// rootCAFileSearchPaths additions:
"/usr/local/etc/ssl/cert.pem",          // security/openssl port
"/etc/ssl/cert.pem",                     // base system (FreeBSD 14+)
"/usr/local/share/certs/ca-root-nss.crt", // security/ca_root_nss port

// rootCADirectorySearchPaths addition:
"/usr/local/share/certs",               // security/ca_root_nss port
```

## Testing

Verified on FreeBSD 15.1 aarch64 (NXP DPAA2, Swift 6.3.2-RELEASE). With
this fix, all HTTPS requests to `swift.org` and `download.swift.org`
succeed. Without it, every connection fails at the TLS handshake
regardless of which CA bundle is installed.

Tested as part of the swiftly FreeBSD port (swiftlang/swiftly#565),
where `HTTPClientTests` makes live HTTPS requests:

```
✔ Test getSwiftOrgGPGKeys() passed after 0.700 seconds.
✔ Test getSwiftToolchain() passed after 109.816 seconds.
✔ Test getSwiftlyLinuxReleases(url:) with 6 test cases passed after 31.636 seconds.
✔ Suite HTTPClientTests passed after 183.785 seconds.
```

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

---------

Co-authored-by: lushan.ai <kequeue@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2026-06-29 08:58:12 +01:00
Karan KuraniandCory Benfield e168589846 Reject partial wildcard SAN matches that produce IDNA A-label first label (#580)
### Motivation

`AnalysedCertificateHostname.init` already refuses to construct a
wildcard matcher when the certificate's first label begins with the IDNA
A-label prefix `xn--` (line 287). The symmetric case is not enforced: a
wildcard SAN whose own first label is plain ASCII can still expand into
a target hostname whose first label begins with `xn--`.

A SAN of the form `*-5wao1o.example.com` will currently match a target
hostname `xn--rksmrgs-5wao1o.example.com` (the IDNA A-label form of
`räksmörgås.example.com`). Both OpenSSL's `equal_wildcard` and CPython's
`ssl._dnsname_match` reject that case explicitly; this library accepts
it.

Verified by copying `AnalysedCertificateHostname` verbatim from `main`
into a standalone executable and running:

```
[OK     ] Sanity: wildcard matches normal subdomain
           cert SAN: *.example.com
           target:   foo.example.com
           expected: true   got: true

[OK     ] Sanity: wildcard does NOT match different parent
           cert SAN: *.example.com
           target:   foo.evil.com
           expected: false   got: false

[OK     ] Sanity: cert that IS an A-label wildcard rejected at parse
           cert SAN: xn--*.example.com
           target:   xn--anything.example.com
           expected: false   got: false

[BROKEN ] VULN: partial wildcard expansion produces A-label target
           cert SAN: *-5wao1o.example.com
           target:   xn--rksmrgs-5wao1o.example.com
           expected: false   got: true
```

After the patch in this PR the BROKEN case becomes OK.

### Modifications

In `validMatchForName`, after splitting the target around its first
period, return `false` if the target's first label begins with `xn--`.
Mirrors the existing cert-side check at line 287 and the
`caseInsensitiveElementsEqual(asciiIDNAIdentifier)` idiom already in use
in this file.

### Result

Wildcard SANs no longer expand into IDNA A-label targets, matching the
behaviour of OpenSSL and CPython. The existing
`testDoesNotMatchIDNALabelWithWildcard` continues to cover the cert-side
variant; the target-side variant is the new case this patch addresses.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2026-06-25 11:04:38 +01:00
Rafael Cepeda 407d82d5b6 Demote ImplementationOnlyDeprecated warning in main CI (#586)
The Main CI workflow currently fails on Swift 6.1, 6.2, and 6.3 because
`-Xswiftc -warnings-as-errors` is enabled, while the
`@_implementationOnly` imports in this codebase emit deprecation
warnings (`ImplementationOnlyDeprecated`).
The PR workflow already handles this correctly; this change brings the
main workflow in line.

Specifically:
- 6.1: Drops `-warnings-as-errors` entirely, since this toolchain
doesn't support demoting the ImplementationOnlyDeprecated warning. A
comment explains why.
- 6.2 / 6.3: Adds `-Xswiftc -Wwarning -Xswiftc`
ImplementationOnlyDeprecated to demote the warning while still failing
on other warnings.
2.37.1
2026-06-02 13:01:48 +00:00
Rafael Cepeda 73f8803df4 Enable x25519_MLKEM768 by default (#582)
Default `TLSConfiguration.curves` is now [`.x25519_MLKEM768`, `.x25519`,
`.secp384r1`], enabling post-quantum hybrid key exchange out of the box.
Users can still set curves to nil to fall back to BoringSSL's built-in
curve list, or override with any custom set.

Updated `quantum-secure-tls.md` to reflect that PQ is enabled by default
and document how to customise or disable it.
2026-06-01 17:24:41 +01:00
Oliver DrobnikandClaude Opus 4.8 ae6b517f53 Define _WINSOCKAPI_/NOMINMAX/NOCRYPT for CNIOBoringSSL on Windows (#585)
### Motivation

`CNIOBoringSSL` fails to compile on recent Windows SDKs (e.g.
**10.0.26100**, as shipped on the `windows-latest` GitHub runner).
BoringSSL includes `<windows.h>` / `<winsock2.h>`, and the SDK
transitively pulls in headers whose symbols collide with BoringSSL's
own:

- the legacy `<winsock.h>` redefines `sockaddr` / `fd_set` / `WSAData`
against the `<winsock2.h>` BoringSSL includes;
- the `min()` / `max()` macros break `std::numeric_limits<>::max()`;
- `<wincrypt.h>` `#define`s `X509_NAME`, `X509_EXTENSIONS` and
`X509_CERT_PAIR`, which collide with BoringSSL's types (e.g.
`ssl_x509.cc`: *"template argument for template type parameter must be a
type"* on `STACK_OF(X509_NAME)`).

### Modifications

Define `_WINSOCKAPI_`, `NOMINMAX` and `NOCRYPT` for the `CNIOBoringSSL`
C and C++ sources on Windows, via `cSettings` / `cxxSettings` with
`.when(platforms: [.windows])`.

Scoping them to the BoringSSL target (rather than passing them globally,
e.g. via `-Xcc`) is deliberate: a global `_WINSOCKAPI_` also reaches the
Swift clang module importer, where it makes `IPPROTO_UDP` import as the
`IPPROTO` enum instead of an integer and breaks downstream swift-nio
(`NIOPosix/System.swift`: `CInt(IPPROTO_UDP)`).

### Result

`CNIOBoringSSL` compiles against current Windows SDKs. No change on any
other platform (the defines are Windows-only).

Verified with an isolated `swift build --target CNIOBoringSSL` on
`windows-latest` (Swift 6.3.1, Windows SDK 10.0.26100): [green
run](https://github.com/odrobnik/swift-nio-ssl/actions/runs/26755253073).
`swift-format` and `swift package dump-package` both pass.

Note: I couldn't find a Windows job in this repo's CI, so this isn't
exercised by the existing matrix — happy to add one if that'd be useful.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 15:28:41 +01:00
Rick Newton-Rogers 8e3d34d5b6 Migrate macOS build argument overrides to Swift version inputs (#581)
Motivation

* The shared `macos_tests.yml` workflow no longer accepts
  `xcode_16_2_build_arguments_override` and the `xcode_16_3` input is a
  no-op. Passing the removed input causes CI to fail.
* Older Xcodes are being removed from the runners; Swift version inputs
  are the replacement.

Modifications

* Replace `xcode_16_2/16_3_build_arguments_override` with
  `swift_6_1/6_2/6_3_build_arguments_override` carrying the same
  `-Xswiftc -Xfrontend -Xswiftc -require-explicit-sendable` value.

Result

* macOS CI passes again using the Swift version inputs.
2026-05-15 11:30:30 +02:00
aryan-25 52f83a14ee Fix optional certificate verification test case (#578)
Motivation:

The
[`testMacOSConnectionFailsIfServerVerificationOptionalAndPeerPresentsUntrustedCert`](https://github.com/apple/swift-nio-ssl/blob/3f337058ccd7243c4cac7911477d8ad4c598d4da/Tests/NIOSSLTests/NIOSSLIntegrationTest.swift#L2603)
test case in `NIOSSLIntegrationTest` verifies that the handshake fails
when the server's certificate verification mode is set to
[`.optionalVerification`](https://github.com/apple/swift-nio-ssl/blob/3f337058ccd7243c4cac7911477d8ad4c598d4da/Sources/NIOSSL/TLSConfiguration.swift#L199)
and the client presents an untrusted certificate chain.

In that test case, there is a `defer` block in which the client channel
is closed:

https://github.com/apple/swift-nio-ssl/blob/3f337058ccd7243c4cac7911477d8ad4c598d4da/Tests/NIOSSLTests/NIOSSLIntegrationTest.swift#L2650-L2652

However, since the handshake will fail in this test case, the
`doDecodeData` method will close the client channel (line 630):

https://github.com/apple/swift-nio-ssl/blob/3f337058ccd7243c4cac7911477d8ad4c598d4da/Sources/NIOSSL/NIOSSLHandler.swift#L626-L634

If the client channel has already closed before the test case calls `try
clientChannel.close().wait()`, then a
[`ChannelError.alreadyClosed`](https://github.com/apple/swift-nio/blob/32e3d863795292c49e1aa3dc1f72a31802e74a1f/Sources/NIOCore/Channel.swift#L377)
will be thrown, which will result in the `XCTAssertNoThrow` failing.

We should instead be waiting for the client channel's `closeFuture` at
the end of the test case.

Modifications:

Removed the `defer` block containing the call to `try
clientChannel.close().wait()`, and instead added a call to `try
clientChannel.closeFuture.wait()` at the end of the test case.

Result:

The
`testMacOSConnectionFailsIfServerVerificationOptionalAndPeerPresentsUntrustedCert`
test case is no longer flaky.
2026-04-23 13:38:05 +01:00
aryan-25 c73384d02f Update test helper to use SocketAddressError.UnknownHost (#579)
Motivation:

In https://github.com/apple/swift-nio/pull/3558,
`SocketAddressError.unknown` was deprecated and replaced with a richer
`SocketAddressError.UnknownHost` type.

However, in `IdentityVerificationTest.ipv6Supported()` (a test helper
method), we are catching the `SocketAddressError.unknown` case to
determine whether IPv6 is supported (line 57):

https://github.com/apple/swift-nio-ssl/blob/3f337058ccd7243c4cac7911477d8ad4c598d4da/Tests/NIOSSLTests/IdentityVerificationTest.swift#L53-L60

Since `SocketAddress.makeAddressResolvingHost(_:port:)` now throws
`SocketAddressError.UnknownHost` instead of
`SocketAddressError.unknown`, the
`IdentityVerificationTest.ipv6Supported()` method no longer works as
expected. This is causing CI failures over the past few days.

Modifications:

- Updated `IdentityVerificationTest.ipv6Supported()` to catch
`SocketAddressError.UnknownHost` instead of the deprecated
`SocketAddressError.unknown` enum case.
- Raised the `swift-nio` dependency to
[`v2.98.0`](https://github.com/apple/swift-nio/releases/tag/2.98.0) (the
version that `SocketAddressError.UnknownHost` was introduced in).

Result:
 
`IdentityVerificationTest.ipv6Supported()` now works as expected.
2026-04-22 14:32:02 +01:00
Rick Newton-RogersandGeorge Barnett 3f337058cc Drop Swift 6.0 (#576)
Motivation:

Swift 6.0 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 6.1
* Remove Swift 6.0 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2.37.0
2026-04-07 12:07:47 +00:00
Rick Newton-Rogers fad35ae01f Enable Swift 6.3 jobs in CI (#574)
Motivation:

Swift 6.3 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.3 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2026-04-01 15:34:34 +01:00
Raphael ba3329300b Update expired certificate in tests (#575)
**Motivation:**

Tests fail because of an expired certificate.

**Modifications:**

Run documented commands to get new certificate and update the test data
accordingly.

**Results:**

Tests pass again.
2026-04-01 14:33:59 +01:00
Allison df9c340602 Set custom private keys via sslContextOverride (#573)
Motivation:

NIOCertificateReloading provides updated versions of a certificate and
private key pair, in the form of a NIOSSLContextConfigurationOverride,
to be used when performing a TLS handshake in NIO. Prior to this change,
the Swift customPrivateKey callback did not see the override. It always
read the private key from the immutable TLSConfiguration if one was
provided at initialization. This configuration might have been nil and
resulted in a precondition failure if the user was expecting to set the
key on the first reloader run. Otherwise, it would have contained a
stale key.

Modifications:
- Store the NIOSSLContextConfigurationOverride in SSLConnection when
applyOverride() is called.
- Update the customKey computed property to check the stored override
first and fall back to the parent context.
- Add tests:
- Server configuration sets a native key, reloader switches to a custom
key for signing.
- Server configuration sets a custom key, reloader switches to a native
key for signing.
- Server configuration sets a native key, reloader switches to a custom
key for decryption.
    - Client key and cert are set by reloader.

Result:

NIOCertificateReloading will work as expected with custom private keys.
2.36.1
2026-03-06 11:56:02 +00:00
Rick Newton-Rogers a0140bf29e update actions/checkout from v4 to v6 (#572)
Motivation

* Following [GitHub's
announcement](https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/),
Node 20 is being deprecated and runners will begin using Node 24 by
default starting March 4th, 2026. Node 20 will reach end-of-life in
April 2026.

Modifications

* Upgrade GitHub Actions to their latest versions to ensure
compatibility with Node 24.
* Replace `actions/checkout@v4` with `actions/checkout@v6` in all
workflow files.

Result

* Workflow files reference `actions/checkout@v6`.
2026-03-02 13:26:09 +00:00
Rick Newton-Rogers 0d3c933ee2 switch from main to 0.0.7 for swiftlang workflows (#570)
Motivation

* `@main` references to `swiftlang/github-workflows` are deprecated.

Modifications

* Replace `@main` with `@0.0.7` in all workflow files.
* Update benchmark thresholds so CI passes. These seemed to have the
wrong filenames so I'm not sure how it ever worked.
* Add tolerance to benchmarks in line with NIO

Result

* Workflow files reference a pinned version of
`swiftlang/github-workflows`.
2026-02-27 14:11:55 +00:00
Gwynne Raskind 88c4694e15 Do not log the caCerts value if PKCS#12 parsing goes haywire (#571)
The `caCerts` value is, from Swift's perspective, merely an
`OpaquePointer?`; logging its value as part of a `preconditionFailure()`
is not particularly useful. In addition, including it in the log message
causes GitHub's CodeQL code analysis to inaccurately report a
high-severity information disclosure vulnerability in any repo using it
which has `swift-nio-ssl` as a direct or indirect dependency. Since
logging it serves no useful purpose anyway, might as well get rid of it.
2026-02-23 18:49:58 +00:00
Rick Newton-Rogers 8c179eebff Add explicit read permissions to workflows (#566)
Motivation:

* More secure GitHub Actions workflows

Modifications:

Add explicit 'contents: read' permissions to workflows that did not have
explicit permissions defined. This follows GitHub Actions security best
practices by limiting the default GITHUB_TOKEN permissions.

Result:

An extra layer of security.
2025-10-30 16:51:53 +00:00
Raphaelandaryan-25 173cc69a05 Enable opportunistic TLS verification (#565)
### Motivation:

In some scenarios a server might want to accept connections from both,
authenticated and not authenticated peers and defer decisions after the
handshake. This new options allows a host to only do TLS verificaiton if
the peer presents certificates and accept connections otherwise.

### Modifications:

Add a new associated value to the `none` case of
`CertificationVerification` to maintain backwards compatibility. This
option enables opportunistic verification.

### Result:

A new configuration case for TLS verification.

---------

Co-authored-by: aryan-25 <aryan_shah@apple.com>
2.36.0
2025-10-29 14:57:22 +00:00
Cory Benfield f6599fda39 Use weak let when available (#564)
This suppresses some warnings on newer builds.
2025-10-28 16:19:19 +00:00
Cory Benfield c1bcde58f6 Revert to @_implementationOnly import (#562)
Motivation:

Unfortunately, `internal import` doesn't do implementation-hiding in the
build system. This means that the C header files do become visible to
all dependencies, which can cause problems when the ssl.h headers from
elsewhere are included.

Modifications:

Revert to `@_implementationOnly` imports.

Result:

Better builds, unfortunately more warnings
2025-10-28 15:52:53 +00:00
aryan-25 394f2d1741 Update expired apple.com certificates (#563)
### Motivation:
Tests using hard-coded apple.com certificates are failing because those
certificates have now expired.

### Modifications:
Updated the expired leaf and intermediate certificates.

### Result:
Tests no longer fail.
2025-10-28 13:02:01 +00:00
Joseph Heck d3bad3847c update README to use sync operations for addHandler (#561)
Update readme to resolve issues that otherwise pop up with Swift 6.2
2.35.0
2025-10-13 19:32:36 +01:00
Gwynne Raskind aa0d800ad4 Use Context.environment in Package.swift instead of importing Foundation (#560)
#### Motivation:

Importing `Foundation` in `Package.swift` is undesirable; nowhere else
in the actual `NIOSSL` package is `Foundation` used, it appears only in
tests and examples. This removes the usage from the manifest altogether.
There is no compatibility concern; `Context.environment` has been
available since SwiftPM 5.6.

#### Modifications:

Replaced `ProcessInfo.processInfo.environment` with
`Context.environment`.

#### Result:

There is no functional impact. `Package.swift` no longer imports
`Foundation`.
2025-10-01 08:10:56 +00:00
Orhan Yigit Yazicilar 4a1819a281 Drop Swift 5.10 (#559)
### 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.
2025-09-25 13:45:48 +01:00
Rick Newton-Rogers b2b043a881 Enable Swift 6.2 jobs in CI (#558)
Motivation:

Swift 6.2 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.2 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2.34.1
2025-09-22 12:45:52 +00:00
hamzahrmalik 6ae36f2273 Make sslContextCallback overrides replace the existing chain, rather than adding to it (#557)
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
2025-09-16 15:29:14 +01:00
Gwynne Raskind 737e550e60 Make NIOSSLContext.configuration public. (#556)
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`.
2.34.0
2025-08-27 10:29:08 +00:00
aryan-25 1d4afc64e8 Allow the peer's validated certificate chain to be returned in the custom verification handler (#553)
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.
2025-08-21 12:55:53 +01:00
Cory Benfield 191e95e74c Remove incorrect documentation (#555)
Motivation:

Documentation should accurately explain the methods.

Modifications:

Removed the phrase "providing a passphrase callback"

Result:

Documentation is more accurate
2025-08-15 07:55:36 +00:00
aryan-25 69535f9882 Updated test certificates in NIOSSLTestHelpers (#554)
Motivation:

Some tests are failing in `TLSConfigurationTest` due to the certificates
in `NIOSSLTestHelpers` having expired.

Modifications:

Updated `NIOSSLTestHelpers` with regenerated certificates.

Result:

Tests no longer fail.
2025-08-14 16:30:15 +00:00
Raphael ab2784eb0f Enable release mode builds (#552)
### Motivation:

Some errors do not show up in debug builds. Enabling release mode builds
improves the CI coverage.

### Modifications:

Enable release mode builds for pull requests and scheduled builds on
main.

### Result:

Improved CI coverage.
2025-07-30 08:09:20 +00:00
George Barnett 385f5bd783 Avoid small behaviour change in #550 (#551)
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
2.33.0
2025-07-15 13:16:38 +00:00
George Barnett 5108dbdec9 Deprecate NIOSSLCertificate(file:format:) (#550)
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
2025-07-15 13:20:55 +01:00
Rafael Cepeda f64263a41f Enabled -require-explicit-sendable compiler flag (#549)
Enabled -require-explicit-sendable compiler flag and fixed the errors
highlighted by the compiler.
2025-07-10 18:49:30 +01:00
Cory Benfield dacd828b9c Add documentation of how trust roots settings affect validators (#548)
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.
2025-07-09 15:24:14 +01:00
Cory Benfield 8d6730f567 Add mTLSConfiguration option for TLSConfiguration (#545)
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
2025-07-07 10:18:27 +00:00
George Barnett f76bfe9041 Remove per-benchmark wiggle room (#546)
Motivation:

The benchmarks have a 2000 alloc wiggle room defined at the per-test
level. It's not obvious why this is there as the numbers seem stable.
Their presence allows for improvements/regressions to go unnoticed which
isn't good.

Modifications:

- Remove the wiggle room
- Rename the benchmark target from NIOSSHBenchmarks to NIOSSLBenchmarks

Result:

Easier to catch regressions/improvements
2025-07-04 13:21:19 +01:00
Rick Newton-Rogers f19bb9918d Revert "Enable certificate verification if trustRoots are set to non-nil" (#544)
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.
2025-07-03 16:14:23 +00:00
Cory Benfield 34486a9057 Enable certificate verification if trustRoots are set to non-nil (#543)
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.
2025-07-02 17:35:14 +00:00
Rick Newton-Rogers fe415631b1 Add static SDK CI workflow (#515)
Add static SDK CI workflow which runs on commits to PRs, merges to main
and daily on main.
2025-06-26 11:56:53 +01:00
Cory Benfield 36b48956eb Fix incorrect callback caching (#541)
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.
2.32.0
2025-06-16 14:43:38 +01:00
Gus Cairo 9173d857de Add toDerBytes to SSLPrivateKey (#540)
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.
2025-06-16 11:35:42 +01:00
Egor Zhdan 43e4c3c7be Make CNIOBoringSSLShims compatible with C++ interop (#538)
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.
2025-05-28 15:21:29 +01:00
Rick Newton-Rogers 4b38f35946 Drop Swift 5.9 (#536)
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.
2.31.0
2025-05-05 12:13:41 +01:00
Cory Benfield 8061e1edd9 Add explicit API support for X25519_MLKEM768 hybrid KEM (#535)
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.
2025-04-30 10:41:13 +01:00
Jeff DaveyandCory Benfield 874ad69680 Add subjectName, issuerName, and access to the peerCert (#533)
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>
2025-04-23 13:39:24 +00:00
Zane Enders 6df102a39c Fix typo in NIOSSLServerHandler documentation. (#534)
Motivation:

NIOSSLServerHandler miss named NIOSSLClientHandler in documentation.

Modifications:

Fix Typo.

Result:

Correct name in documentation.
2.30.0
2025-04-22 09:20:11 +00:00
Joseph Heck 66cfda0cbd Add DocC extension page to provide curation for TLSConfiguration (#532)
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.
2025-04-16 10:22:38 +01:00
Rick Newton-Rogers e5f59aeca6 Enable Swift 6.1 jobs in CI (#531)
Motivation:

Swift 6.1 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.1 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2025-04-14 10:39:35 +01:00