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.
* Update vendoring and perlasm
* Update vendoring script
* Update to BoringSSL 3309ca66385ecb0c37f1ac1be9f88712e25aa8ec
* Handle API break in BoringSSL
Motivation:
Now that Swift 5.9 is GM we should update the supported versions and
remove 5.6
Modifications:
* Update `Package.swift`
* Remove `#if swift(>=5.7)` guards
* Delete the 5.6 docker compose file and make a 5.10 one
* Update docs
Result:
Remove support for Swift 5.6, add 5.10
Motivation:
ByteBufferBIOs will grow their outbound buffer until flush is
called. They will retain their capacity at however large it got
to avoid reallocating, as they assume that your write pattern will
be fairly consistent.
In some cases this is a bad strategy, because it overcommits data.
To allow users to reclaim this data, we can add a configuration
option that will shrink the playload on the next write.
Modifications:
- Added support for ByteBufferBIO to shrink the payload.
- Plumbed up support for handler configuration.
- Tests that shrinkage actually works.
Result:
Users can reclaim memory.
* NIOSSLHandler.close(mode: .output) new behaviour
Modifications:
* flush outstanding messages on NIOSSLHandler.close(mode: .output)
* change state once NIOSSLHandler.close(mode: .output) is invoked, so
that subsequent writes to the channel fail
* write integration tests to verify the behaviour
* * replace ConnectionState.closedOutput with ConnectionState.active(.output)
* Revert "* replace ConnectionState.closedOutput with ConnectionState.active(.output)"
This reverts commit 59cf0dfa147dcb794639b6a2dcd5331b7250c39f.
* close(mode: .output): perform TLS shutdown
* Insight comments from Cory about why test fail
Reason:
* atm our `NIOSSLServerHandler` does not support half-closure, thus it
closes TCP connection entirely on reception of close
-> our tests race
* Add temporary test demonstrating how half closure works for vanilla TCP connections
* testSubsequentWritesFailAfterCloseModeOutput: configure test server with allowRemoteHalfClosure
* First implementation of half-closure for NIOSSLServerHandlers
* NIOSSLHandler: throw ChannelError.outputClosed on NIOSSLHandler.bufferWrite
* Refactor
* Replace inputClosed: Bool with ConnectionState.inputClosed
* Add NIOSSLIntegrationTest.testMultipleCLoseOutput()
* Trigger TCP close when NIOSSLHandler.state == .inputClose
* testCloseModeOutputTriggersFlush: add allowHalfClosure to serverChannel
* * don't cache value of ChannelOptions.allowRemoteHalfClosure in NIOSSLHandler
* Refactor
* Refactor TCP input close handling
Modifications:
* send user event "input closed" onwards when in state .closed or .idle
* trigger closure of TCP input once we enter the .inputClosed state
* Refactor closingOutput procedure
Modifications:
* in `closeOuput` trigger the shutdown step regardless of the existence
of a promise
* remove redundant state transition to `.outputClosed`
* * closeOutput: flush before we doShutdown
* Refactor closeOutput state management
Modifications:
* remove `.closingOutput` state
* * closeOutput: remove closeOutputPromise
* * remove TCP half close example
* * add comment about not closing the entire channel after a half-closure
* * rework .inputClosed and .outputClosed state
* * add test for closing server output and client output
* Review Cory
Modifications:
* pass on user inbound event "input closed" to the next `ChannelHandler`
event in the event of an error
* cache value of `ChannelOptions.allowRemoteHalfClosure` across
`doFlushReadData` to avoid races in case the option's value
changes while `doFlushReadData` is being executed
* change behaviour: pass `closeOutputPromise` on in `context.close(mode:
.output, promise: closeOutputPromise`
* Review Cory
Modifications:
* `NIOSSLHandler.userInboundInputClosedTriggered`: execute
`fireErrorCaught` before `userInboundEventTriggered(.inputClosed)`
* `func completedAdditionalPeerCertificateVerification` fails with
invalid state when in states `{.input,.ouput}closed`
* Support close(.output) when handshaking
Modifications:
* create `enum BufferedAction` that allows `NIOSSLHandler` to buffer
actions instead of just writes
* rename `bufferedWrites` -> `bufferdActions`
* add `BufferedAction.closeOutput`, which allows us to buffer
invocations of `close(mode: .output)` when we are still in non-active
modes such as `.handshaking` or `.additionalVerification` -> this
means we'll invoke the closing of the output after our handshaking
step is completed and all our buffered writes have been flushed
* Review Cory
Modifications:
* Refactoring
* fixed wrong comment
* remove `MarkedCircularBuffer.forEachElementUntilMark()`
* discard all buffered actions that occured after the `.closeOutput`
buffered actions in `NIOSSLHandler.doUnbufferActions()`
* Fix race caused by setting .inputClosed
Motivation:
Previously we did not check the current state when setting the
`NIOSSLHandler`'s state to `.inputClosed`. This resulted in an issue
where when we were in state `.closing`, then set the state to
`.inputClosed`, we would end up with a fatalError in our shutdown /
scheduledShutdown as state `.inputClosed` is not a shutting-down state.
Modifications:
* check current state before setting `state = .inputClosed`,
specifically not setting the state to `.inputClosed` when we are
already in the process of doing a full closure
* NIOSSLHandler: full close if input & output closed
Modifications:
* `NIOSSLHandler`: escalate to full closure when both input and output
are closed
* `NIOSSLIntegrationTest.testCloseModeOutputServerAndClient`: assert
that having input and output closed in `NIOSSLHandler` results in full
closure
* `NIOSSLIntegrationTest.testCloseModeOutputServerAndClient`: assert
that if one side closes its output, the other side of the connection
closes its input
* Review Cory
Modifications:
* update comment on why we don't do a full channel close when we execute
`doShutDownStep` for state `.outputClosed`
* do not suppress error in `NIOSSLHandler.doUnbufferActions` when in
state `.outputClosed`
### Motivation
`swift-nio` has deprecated `NIOPreconcurrencySendable` in `2.51.0`. Removing the protocol conformance would be an API breaking change. Keeping the conformance is low cost and not worth the risk.
### Changes
- replace `NIOPreconcurrencySendable` with underscore version `_NIOPreconcurrencySendable`
### Result
We compile again with the latest `swift-nio` release without warnings
* Drop Swift 5.5
This patch drops Swift 5.5 support. It removes docker-compose files and
deletes any conditional compilation guards that are no longer necessary.
* Remove test generation script
Motivation:
SwiftNIO periodically drops support for older Swift versions. Now that
5.7 has been released, 5.4 will be dropped.
Modifications:
- Remove 5.4 specific Package.swift and docker-compose
- Update the 5.7 docker-compose to use the released 5.7 and move from
focal (2004) to jammy (2204)
- Fix the tools version in Package@swift-5.5.swift
- Update docs
Results:
Minimum Swift version is 5.5
Motivation:
The giant write test requires an enormous commitment of RAM to run it.
This has caused problems for both our own CI and a number of downstream
CI systems, leading to long execution times or outright failures.
Unfortunately, we can't defend against the original failure using this
test suite, but we can at least exercise the new machinery we added and
trust that the configuration is right.
Modifications:
- Make the maximum write size configurable internally
- Test the maximum write size at a different value.
Result:
We feel confident that the write splitting continues to work correctly.
* Adopt `Sendable`
* `@preconcurrency typealias` doesn’t work
* `NIOPSKClient/ServerIdentityCallback`
* `NIOSSLKeyLogCallback`
* `NIOSSLClientTLSProvider`
* Fix warnings in tests
* `@preconcurrency` is broken https://github.com/apple/swift/issues/60508
I think we don’t actually need it in that case and still don’t break API
* Fix warnigns in tets
* fix nightly
* Add file path and line number info to BoringSSL error wrappers
* Rename filename to filepath
* Renamed boringSSLErrorCode to boringSSLErrorInfo
* Store line number as Uint
* Change Int32 to Int
Motivation
Documentation is nice, and we can help support users by providing useful
clear docs.
Modifications
Add Docc to 5.6 and later builds
Make sure symbol references work
Add overview docs
Result
Nice rendering docs
* Invoke `NIOSSLContext.AdditionalCertificateChainVerificationCallback` with peer certificate and make it public without guaranteeing API stability
* move function typealias to the module namespace and improve documentation
* Move `additionalPeerCertificateVerificationCallback` from `NIOSSLContext` to `NIOSSHandler`
* make peer certificate non-optional in user callback
* Update Sources/NIOSSL/NIOSSLHandler.swift
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
Add TLS-PSK Support to address #230.
Modifications:
Modified SSLContext to take a passed in PSK callback to perform key and identity operations during the handshake.
Result:
TLS-PSK support for TLS 1.2. TLS 1.3 is not addressed due to API support in BoringSSL.