188 Commits
Author SHA1 Message Date
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
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
2023-04-13 12:42:47 +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
George Barnett 4fb7ead803 Update BoringSSL to b819f7e9392d25db6705a6bd3c92be3bb91775e2 (#406) 2022-10-20 13:19:57 +01:00
David NadobaandCory Benfield b8a78b0846 Remove #if compiler(>=5.5) (#404)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-10-12 09:06:41 -07:00
David Nadoba 9fcdd00a9f Replace NIOSendable with Sendable (#405) 2022-10-12 08:41:16 -07:00
George Barnett ef0baa9dcc Raise minimum supported Swift version from 5.4 to 5.5 (#401)
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
2022-09-29 09:22:22 +01:00
George Barnett 9f1a28849b Update BoringSSL to cab31f65f1ad6e6daca62e95b25dd6cd805fce0b 2022-09-28 12:08:28 +01:00
Cory Benfield ba7c0d7f82 Update BoringSSL to 8462a367bb57e9524c3d8eca9c62733c63a63cf4 (#399)
* Update BoringSSL umbrella header

* Update BoringSSL to 8462a367bb57e9524c3d8eca9c62733c63a63cf4
2022-09-02 04:38:36 -07:00
Cory Benfield 024bbd111e Remove giant write test (#398)
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.
2022-09-02 12:03:19 +01:00
David Nadoba a6f9a034e5 Adopt Sendable for TLSConfiguration (#397)
Should have been already included in #395
2022-08-23 10:57:28 +01:00
David Nadoba 5c07eca3ac Adopt Sendable incrementally (#395)
* 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
2022-08-11 07:41:11 -07:00
Alex Shatberashvili e5526088a4 Store internal error file and line number information in error wrappers (#393)
* 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
2022-08-11 11:09:16 +01:00
David Nadoba c5eaf16b33 Adopt Sendable incrementally (#392)
* Adopt `Sendable`

* `@preconcurrency typealias` doesn’t work
2022-08-11 10:35:14 +01:00
David Nadoba 12638fed5b Adopt Sendable in SSLError.swift (#391) 2022-08-09 17:34:57 +01:00
Cory Benfield 1b16a07692 Use Docc for documentation (#390)
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
2022-08-09 08:33:58 +01:00
David Nadoba 0265283d35 Make NIOSSLCertificate._subjectAlternativeNames() return type non-optiona (#389) 2022-08-01 16:45:21 +01:00
David NadobaandCory Benfield c37f562e0e Invoke additionalPeerCertificateVerificationCallback with peer certificate (#387)
* 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>
2022-07-28 04:12:34 -07:00
Matt Eaton 8bb0412e8b Add TLS-PSK Support (#369)
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.
2022-07-28 11:42:55 +01:00
Cory Benfield ff0fccddad Clean up write logic (#385)
Motivation:

Unnecessary empty writes should be avoided, and we should avoid
completing promises too often.

Modifications:

- Avoid sending a split promise on every write when writes are too big.
- Avoid sending a zero-length write when writes are too big.

Result:

Slightly better write behaviour.

Note that this is fundamentally un-testable: there's no place to put a
test hook here, and we coalesce writes on the far side, so we can't do
much here.
2022-07-27 01:59:04 -07:00
Cory Benfield 45fe612e84 Add sendCANameList to best effort functions. (#386)
Motivation:

TLSConfiguration cannot be made equatable due to its use of closures, so
we have our own best-effort functions. Unfortunately, I forgot to make
sure everything was added to them, so I'm doing so now.

Modifications:

- Add missing fields to bestEffort functions.

Result:

Better bestEffort functions.
2022-07-27 09:38:24 +01:00
Cory Benfield 70649f8c93 Tolerate massive writes (#384)
Motivation:

In rare cases, users may attempt to write more data than can be
expressed in 2**31 bytes. This should not crash our program.

Modifications:

- Break up extremely long writes into smaller chunks
- Make sure to clamp on the read path too

Result:

Users who send hilariously long writes can do so.
2022-07-26 14:03:03 +01:00
Franz Busch c30c680c78 Unbuffer reads after handshake (#379)
# Motivation
We missed unbuffering reads after the handshake completed. This could result in reads that were buffered while the handshake was in progress to not unbuffer.

# Modification
This PR unbuffers any reads after the handshake is completed.

# Result
We are now unbuffering reads correctly.
2022-07-13 04:08:41 -07:00
George Barnett fd5f38b003 Update BoringSSL to c239ffd0552179f358de31517391679e9b62ccd3 (#378)
* Various vendor script fixes:

- Fix various 'gsed' occurrences with '$sed'
- Remove the delocate patch, it is no longer required
- Add another patch to include inttypes in
  CNIOBoringSSL/crypto/x509/t_x509.c where PRIu64 is used and remove it
  from CNIOBoringSSL_bn.h. this works around a build failure with
  xcodeproj.
- Use the host platform build directory when mangling C++ symbols
- Fix Python bytes/string writing in build-asm.py

* Update BoringSSL to c239ffd0552179f358de31517391679e9b62ccd3
2022-07-04 10:53:09 +01:00
David Nadoba 181802810e Include file path in IOErrors thrown by fopen (#375)
* Include file path in `IOError`s thrown by `fopen`

* change error reason formatting and also include mode

* use explicit `String` to `UnsafePointer<CChar>` transformation
2022-06-28 17:44:30 +01:00
George Barnett 42436a25ff Update BoringSSL to 1e469e45a46ff580899cbef939babe02ad916c85 (#370)
* Update vendor-boringssl.sh

* Update BoringSSL
2022-06-09 06:03:49 -07:00
fbaa52b24d Port SecureBytes from Swift Crypto to use with TLS-PSK (#366)
* Port SecureBytes from Swift Crypto to use with TLS-PSK

Motivation:

Porting SecureBytes to NIOSSLSecureBytes for using in (Add TLS-PSK Support #360).

Modifications:

Addition and modification of SecureBytes to work within SwiftNIO SSL.
Added additional test cases.

Result:

NIOSSLSecureBytes will be ported for usage in a later PR with TLS-PSK.

* secure-bytes-transfer: Added LinuxMain tests

* secure-bytes-transfer: Removed case from NIOSSLError

* secure-bytes-transfer: Addressed initial feedback

* secure-bytes-transfer: Removed NIOSSLSecureBytesError from SSLErrors

* secure-bytes-transfer: Remove public access from NIOSSLSecureBytes

* Remove remaining public declaration.

Co-authored-by: meaton2 <meaton3@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-13 01:05:56 -07:00
David Nadoba 32101fe2f3 Flush only after handshake (#362)
* support additional certificate validation

* run `scripts/generate_linux_tests.rb`

* fix review comments

- rename `CertificateChainVerificationCallback` to `AdditionalCertificateChainVerificationCallback`
- switch over `result` instead of try/catch
- add `. eofDuringAdditionalCertficiateChainValidation` error and throw it if channel becomes inactive while in `.additionalVerification` state

* add `Channel` parameter to `AdditionalCertificateChainVerificationCallback`

* get `context` from self instead of captering it

* save progress

* Only flush after handshake

* run `./scripts/generate_linux_tests.rb`
`

* Add NIOSSLCertficiateExtensions

* adopt naming of ObjectIdentifier

* address review comments
- namespace top level types with `NIO`
- add `withUnsafeBytes(_:)` that gives access to the buffer through an untyped buffer pointer
- fix indentation

* use real optional for `reference` in `_NIOSSLCertificateExtensions`

* fix review comments part 2

- nest `_Extensions` and `_Extension` under `NIOSSLCertificate`
- explain optional reference
- remove empty and copy constructor
- replace fancy force-unwraps with `!`

* use channel from argument

* fix review comments

- buffer the flush instead of ignoring it
- do not automatically flush after a succesfull handshake
2022-05-05 09:51:41 +01:00
David Nadoba 9bd76cc12d Add NIOSSLCertficiateExtensions (#359)
* Add NIOSSLCertficiateExtensions

* adopt naming of ObjectIdentifier

* address review comments
- namespace top level types with `NIO`
- add `withUnsafeBytes(_:)` that gives access to the buffer through an untyped buffer pointer
- fix indentation

* use real optional for `reference` in `_NIOSSLCertificateExtensions`

* fix review comments part 2

- nest `_Extensions` and `_Extension` under `NIOSSLCertificate`
- explain optional reference
- remove empty and copy constructor
- replace fancy force-unwraps with `!`
2022-05-04 16:32:40 +01:00
David NadobaandCory Benfield 534af7f0f3 support additional certificate validation (#361)
* support additional certificate validation

* run `scripts/generate_linux_tests.rb`

* fix review comments

- rename `CertificateChainVerificationCallback` to `AdditionalCertificateChainVerificationCallback`
- switch over `result` instead of try/catch
- add `. eofDuringAdditionalCertficiateChainValidation` error and throw it if channel becomes inactive while in `.additionalVerification` state

* add `Channel` parameter to `AdditionalCertificateChainVerificationCallback`

* get `context` from self instead of captering it

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-04 05:36:19 -07:00
David Nadoba 9bc329d9e4 Add support for owned references to NIOSSLObjectIdentifier (#358)
* Add support for owned references to `NIOSSLObjectIdentifier`
* rename `ObjectIdentifier.swift` to `ObjectIdentifierTests.swift`
2022-04-29 12:20:10 +02:00
Cory Benfield 1750873bce Remove non-generic generic. (#357)
As correctly reported by the nightly compiler, this function appears to
be generic but has a same-type requirement that means it's actually not
generic.
2022-04-22 10:54:48 +01:00
George Barnett 876748fde7 Update BoringSSL to f299342e38fd34b589604ef5b730623da13ee235 (#356)
* Update BoringSSL to f299342e38fd34b589604ef5b730623da13ee235

* Add a note about stray xcodeproj
2022-04-22 10:24:36 +01:00
David Nadoba 15b7c907a6 Add NIOSSLObjectIdentifier (OID) type (#352)
* add `NIOSSLObjectIdentifier` (OID) type

* fix review comments

* only backport for Swift 5.4+
2022-04-21 16:54:26 +01:00
Cory Benfield b5260a31c2 Update BoringSSL to 8bbefbfeee609b17622deedd100163c12f5c95dc (#350) 2022-03-22 15:10:36 +00:00
David Nadoba fb1a6a6702 Add support for URI SAN (#347) 2022-03-11 10:16:38 +00:00
David Nadoba 00a45ad9bb Add RandomAccessCollection conformance to SubjectAlternativeNames and make it public (#345)
* make `_SubjectAlternativeNames` and related types public

and add `RandomAccessCollection` conformance to `_SubjectAlternativeNames`

* move type conversion out of collection

* add `_SubjectAlternativeName`, `. NameType` and `. Contents`

* remove new error case

* add email as a supported name type

* fix review comments and move _SubjectAlternativeNames and related types to a separate file

* remove unused error code

* fix review comments

* add missing Glibc import for `in_addr` and related functionality

* add bounds check and use load instead of memoryRebound
2022-03-10 17:24:31 +00:00
David Nadoba 21b7349c95 Add Hashable conformance to NIOSSLPKCS12Bundle (#341)
* add Hashable conformance to NIOSSLPKCS12Bundle

* add tests
2022-01-28 18:04:44 +00:00
Matt Eatonandmeaton2 8abde3ea82 Enhancement to address issue-337 to query the final TLSVersion (#338)
* Enhancement to address issue-337 to query the final `TLSVersion`

Motivation:

To provide an enhancment to resolve issue-337 to query the final `TSLVersion`.
This allows a client channel to grab the final TLSVersion used for the connection.

Modifications:

Added extension points to allow querying the `TLSVersion` from the `SSLConnection` based on the `Channel` and `ChannelPipeline`.
Added an `unknown` type to `TLSVersion` to account for a default case where the `TLSVersion` cannot be derived from the conenction.
Added a unit test `testObtainingTLSVersionOnClientChannel` to query the final `TLSVersion` when the client channel is closed.

Result:

2 APIs added to query the `TLSVersion` when on a channel.

Additional Notes:

Note that I have 2 concerns about this PR that I would like some additional feedback on:
1. First is the `unknown` case for `TLSVersion`.  This may not be needed as BoringSSL may just return `tlsv12` each time the version cannot be derived from the connection.  Let me know your thoughts.
2. I am not wild about the way this is being unit-tested, but I wanted to do it this way because it provides the `TLSVersion` on the `Channel` after it is closed.  Let me know your thoughts.

* Removed unknown case as it cases an API breakage.

Motivation:

Removed unknown case as it cases an API breakage.

Modifications:

Defaulted to tlsv12 as this is what BoringSSL will default to.

Result:

Wiped out unknown and switched to tlsv12 as the default

* issue--337: Fix failure on soundness.sh for Linux test

* issue-337: Addressed feedback from review

* issue-337: Updated PR to address feedback

* issue-337: Updated the EventLoopFuture for the Channel extension

* issue-337: Refactored test case

Co-authored-by: meaton2 <meaton3@apple.com>
2022-01-20 10:20:49 +00:00
Cory Benfield 52a486ff6d Update BoringSSL to 295b31324f8c557dcd3c1c831857e33a7f23bc52 2022-01-11 08:55:02 +00:00
Cory Benfield 2b329e37e9 Update BoringSSL to 2042972e8458833714bce23386931b1c79978439 (#334) 2021-12-09 06:24:01 -08:00
Cory Benfield 0324d60429 Update BoringSSL to 3a667d10e94186fd503966f5638e134fe9fb4080 2021-11-25 17:30:53 +00:00
Cory Benfield 90101e7a15 Provide better error on EOF during handshake (#332)
Motivation:

When we get channelInactive during a handshake, we currently produce a
fairly useless error:
.handshakeFailed(NIOSSL.BoringSSLError.sslError([])). This error isn't
helpful to anyone, and it doesn't really communicate what's happened.

Sadly, due to the tightly constrained types it's really hard for us to
add new errors to handshakeFailed. Regardless, it would be good for us
to give as much diagnostic information as we can here.

Modifications:

- Changed the representation of BoringSSLInternalError to allow
  "synthetic" errors that don't come from BoringSSL at all.
- Added a new synthetic error for eof during handshake.
- Sent that error instead of a BoringSSL error stack that will always be
  empty.

Result:

- Easier to diagnose the error.
2021-11-25 13:46:38 +00:00
Cory Benfield 36f6419f2b Trust additional roots and defaults on Darwin
Motivation:

When we added additional trust roots on Darwin, we didn't add much
testing to cover that use-case because testing the default validator is
hard. This meant a bug slipped through: we called a pair of APIs in the
wrong order. As a result, users using additional trust roots on Darwin
_only_ trusted the additional ones: the defaults were unavailable.

Modifications:

- Fix the call so that we trust both the defaults and the additional
  roots.
- Refactor the security framework validator to make it possible to test
  it directly.
- Add unit tests for the security framework validator.

Result:

We'll correctly trust the additional roots and the defaults on Darwin.
2021-11-12 17:45:37 +00:00
Cory Benfield 08e701df9a Add x509_vfy.h to umbrella header 2021-11-10 09:09:23 +00:00
Cory Benfield 4b7979a723 Update BoringSSL to a9670a8b476470e6f874fef3554e8059683e1413 2021-11-10 09:09:23 +00:00
buttaface d5494402cd Fix build for Android armv7 (#328)
Motivation:

Fix compilation error because of a type mismatch between st_mode and mode_t on
32-bit Android.

Modifications:

- Zero-extend mode_t constants on Android armv7 to match the types.
- Scope an earlier modification in this vein to armv7 only.

Result:

The code builds on Android armv7 again.
2021-10-13 07:40:14 +01:00
Matt Eatonandmeaton2 21e2918756 issue-316: Support c_rehash Directory Format (#327)
* issue-316: Support c_rehash Directory Format

* issue-316: Address Feedback from PR

* issue-316: Addressed feedback

* issue-316: Addressed latest feedback

* issue-316: Refactor rehash check to be String.UTF8View:

* issue-316: Added split back into the String.UTF8View computational process

* issue-316: Added another split back to the computation of the rehash check

* issue-316: Added additional checks to rehash format

Co-authored-by: meaton2 <meaton3@apple.com>
2021-10-11 10:09:16 +01:00
Justin Leger 5e68c1ded1 Adding back the Explicit time_t import (#325) 2021-09-23 11:14:05 +01:00