338 Commits
Author SHA1 Message Date
Gus Cairo c7e9542133 Add API to create PKCS#12 (#486)
## 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.
2.29.2 2.29.0
2024-10-29 14:23:36 +00:00
Rick Newton-Rogers 8a6b89d9a4 Unify main.yml and scheduled.yml, remove 5_8 ref (#489)
### Motivation:

* `main.yml` and `scheduled.yml` are mostly duplicative.
* Scheduled runs failed because of a deprecated reference to a Swift 5.8
pipeline

### Modifications:

* Unify `main.yml` and `scheduled.yml`
* Remove the reference to the 5.8 pipeline

### Result:

Working scheduled runs.
2024-10-29 10:58:45 +00:00
Rick Newton-Rogers 75e5a978e8 Switch allocation benchmarks to GHA (#488)
### Motivation:

This will allow us to decommission the old CI hooks.

### Modifications:

* Migrate the existing tests to use the package-benchmark framework.
* Delete the obsolete integration tests
* Remove allocations test references from the docker files.

### Result:

Allocation counts are checked using GitHub Actions.
2024-10-25 16:17:41 +01:00
Rick Newton-Rogers 61cfaf9798 Migrate to GitHub Actions (#487)
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.
2024-10-25 09:32:23 +01:00
mads-frameo 27b25e29e7 Add support for supplying supported curves to TLSConfiguration (#485)
This PR adds the support to specify what ECs the handler supports when
doing the handshake.

```swift
var config = TLSConfiguration.makeClientConfiguration()
config.curves = [.x25519]
```
2024-10-18 15:41:46 +01:00
Cory Benfield d7ceaf0e4d Update BoringSSL to d0a175601b9e180ce58cb1e33649057f5c484146 (#483)
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.
2.28.0
2024-10-09 18:11:48 +01:00
Rick Newton-Rogers aa68d49ddf Update expired test certificate (#482)
Update expired test certificate.

### Motivation:

An expired test certificate was causing tests to fail.

### Modifications:

Updated the test certificate.

### Result:

Tests should pass.
2024-10-03 08:40:16 +01:00
Andrew BarbaandCory Benfield e9021d1a4e Implement SSL_CTX_set_cert_cb (#456)
This is a first pass at reviving
https://github.com/apple/swift-nio-ssl/pull/311 in order to fix
https://github.com/apple/swift-nio-ssl/issues/310

Credit to @TechnikEmpire, I did my best to address the comments in the
original PR from @Lukasa

If the approach looks okay I'll move to testing

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-09-16 12:26:04 +01:00
George Barnett d1088ebe07 Exclude privacy manifest when it isn't a resource (#480)
Motivation:

swift build warns when the privacy manifest isn't a package resource.

Modifications:

- Add it do the excluded files when it isn't a resource

Result:

- Resolves #466
2024-09-09 10:09:27 +01:00
Franz Busch fa0d30f367 Add release.yml (#479) 2024-09-06 12:56:08 +01:00
c7eef9ed36 Modify TLS PSK API to handle the case when no hint is provided by the server (#452)
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>
2024-08-22 17:01:27 +01:00
George Barnett 7b84abbdce Avoid a spin loop when inactive is fired before active (#470)
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
2.27.2
2024-08-19 10:26:01 +01:00
George Barnett 4086c44c2c Update test cert (#476)
Motivation:

Some of the test certs expired so some tests are failing.

Modifications:

Update the test certs

Result:

Tests pass
2024-08-13 15:38:40 +01:00
Cory Benfield a40a74e693 Stop using symlinks for PrivacyInfo (#475)
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.
2024-08-13 08:14:28 +01:00
Ayush Garg a9fa5efd86 Mark .file case deprecated for NIOSSLPrivateKeySource (#474)
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.
2.27.1
2024-07-29 03:10:26 -07:00
LamTrinh.Dev 62c9086897 Update swiftlang link in Package.swift (#472)
Update the new link from "https://github.com/apple/swift-docc-plugin" to "https://github.com/swiftlang/swift-docc-plugin.git"
2024-07-23 02:08:59 -07:00
MK 2c1178831a Fix incorrect filename (#471)
PR #459 added this privacy manifest, but refers to it by the wrong name here.
2024-07-22 00:26:14 -07:00
George Barnett 21fda641da Update certs for testing (#469)
Motivation:

A leaf certificate used for testing certificate verification only on
Darwin platforms had expired.

Modifications:

Update the cert

Result:

Tests pass
2024-07-19 06:14:39 -07:00
finagolfin 3eec6698d3 Use Bionic module and new Android overlay in Swift 6 (#468) 2024-07-15 09:52:21 +01:00
Nicolas Bachschmidt 2b09805797 Use case-insensitive comparison when validating cert domain name (#464) 2.27.0 2024-05-15 13:58:50 -07:00
Johannes Weiss 023c9d2435 test compiler version not language version (#462) 2024-05-09 13:00:09 +01:00
Clinton Nkwocha 45cb3bac27 Handle error when private key file type is unknown (#460)
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.
2024-05-01 16:47:11 +01:00
George Barnett 2d9c63d16f Add empty privacy manifest (#459)
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.
2024-04-09 08:04:43 +01:00
d7840f36ad fix https fail on Android (#453)
* fix https fail on Android

* add compatibility for https failure after Android14

---------

Co-authored-by: wangxiang13 <wangxiang13@lixiang.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-03-26 14:39:01 +00:00
George Barnett 3b2a01c9de Raise minimum Swift version to 5.8 (#458) 2024-03-11 08:50:45 +00:00
David Nadoba 7613886ed9 Update expired apple.com leaf certificate in tests (#457) 2024-02-13 23:16:42 +00:00
Gustavo Cairo 7c381eb608 Update expired apple.com certificates (#455) 2.26.0 2024-01-02 09:37:41 -08:00
Gustavo Cairo e0464ed61f Add cxx interop build pipeline (#454) 2024-01-02 13:55:07 +00:00
Alastair Houghton 0b3f5fef6e Define _DARWIN_C_SOURCE on Darwin to fix the build in Xcode. (#451) 2023-12-12 17:17:47 +00:00
Alastair Houghton 0f05af66c3 Changes to support building with Musl. (#450)
Define `_GNU_SOURCE` in the `Package.swift`.

Add imports for Musl in relevant places.

Remove types from sysXXX static variables.
2023-12-07 10:25:47 +00:00
finagolfin 90070b0ee1 Android: update Bionic declarations for nullability annotations added in NDK 26 (#449)
Also, force unwrap an `opendir()` call that could be null.
2023-11-27 09:52:27 +00:00
Sal fef859614f fclose fix for linux-glibc 2.38 (#448) 2023-11-06 10:13:39 +00:00
Cory Benfield a3d5e67ba5 Update Apple.com cert (#447)
Motivation:

The apple.com cert has expired, we need a new one.

Modifications:

Updated packaged apple.com cert.

Result:

Tests pass
2023-10-30 11:13:43 +00:00
Cory Benfield 13460776e7 Update BoringSSL to 3309ca66385ecb0c37f1ac1be9f88712e25aa8ec (#446)
* Update vendoring and perlasm

* Update vendoring script

* Update to BoringSSL 3309ca66385ecb0c37f1ac1be9f88712e25aa8ec

* Handle API break in BoringSSL
2023-10-30 10:48:37 +00:00
Rick Newton-Rogers c05ca760bd Bump minimum Swift version to 5.7 (#445)
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
2023-10-04 10:16:24 +01:00
Cory Benfield 7aabfa3b64 Add support for shrinking massive ByteBufferBIOs (#443)
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.
2023-09-18 14:11:27 +01:00
Honza Dvorsky 320bd978cc Bump minimum NIO version to 2.54.0 to fix test crashes (#442) 2.25.0 2023-08-14 03:33:34 -07:00
Honza Dvorsky a047d88c0e Fix expired test certs (#441) 2023-08-14 03:23:26 -07:00
Felix Schlegel 678b6412f5 NIOSSLHandler: behave sensibly on close(mode: .output) (#428)
* 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`
2023-06-26 14:36:35 +01:00
Rick Newton-Rogers 5f97ddb5db UnwrappingTests use own class member cert values (#437)
Motivation:

Running the tests with `--parallel --num-workers=1` revealed a failure
on tearDown

Modifications:

UnwrappingTests use own class member cert values rather than those from
NIOSSLIntegrationTest.

Result:

Tests pass
2023-06-22 08:02:50 -07:00
Franz Busch a30b69f26a Use #if canImport(Darwin) where possible (#435) 2023-06-21 14:12:27 +01:00
David Benjamin 11a85b6542 Use EVP_PKEY_assign_RSA instead of EVP_PKEY_assign (#434)
EVP_PKEY_assign_RSA, at least in C, is more type-safe. It also is
compatible with an upcoming BoringSSL change to make the RSA struct
opaque. For some Swift reasons I don't fully understand (but relating to
the OpaquePointer mess), when RSA becomes opaque, EVP_PKEY_assign no
longer works.

I assume it could be made to work with some appropriate cast, but
since EVP_PKEY_assign_RSA already exists (and will, in the future, be
more binary-size-friendly), just use that.
2023-06-09 10:12:15 +01:00
Cory Benfield 36ca628e90 Adopt the Swift CoC (#433)
Motivation:

We're centralizing on the Swift code of conduct, so we'll x-reference
that instead of holding our own.

Modifications:

Hyperlink out to Swift.

Result:

Shared CoC across the projects.
2023-06-06 09:06:58 -07:00
George Barnett dfdf5eb507 Update leaf cert (#431)
Motivation:

A few of cert the verification tests are failing on macOS.

Modifications:

Fetched a newer leaf cert by running 'openssl s_client -connect apple.com:443 -showcerts'

Result:

Tests pass.

After your change, what will change.
2023-05-24 04:59:25 -07:00
Mukesh Bharsakle 662d538281 Skipping testNotValidAfter on 32-bit platform (#426)
* the system must have a 64-bit time_t
2023-05-02 02:24:25 -07:00
David Nadoba e866a626e1 Use underscore version of NIOPreconcurrencySendable to silence warning (#427)
### 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
2.24.0
2023-04-25 15:04:47 +02:00
Cory Benfield 5c57d8e64a Drop Swift 5.5 (#425)
* 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
2023-04-13 16:48:55 +01:00
Cory Benfield 9d0d5d8798 Update BoringSSL to abfd5ebc87ddca0fab9fca067c9d7edbc355eae8 (#424)
* Update BoringSSL vendoring scripts for new perlasm

* More patches

* Update BoringSSL to abfd5ebc87ddca0fab9fca067c9d7edbc355eae8

* Fixup newly opaquified types
2.23.1
2023-04-13 12:42:47 +01:00
Yim Lee f042165759 Add docker-compose file for Swift 5.9 (#423) 2023-04-13 09:43:55 +01:00
Cory Benfield c608fe2787 Fix the docs and add infrastructure for CI-ing it (#422)
* Fix the docs and add infrastructure for CI-ing it

* Update soundness for 2023
2023-04-11 03:44:18 -07:00