258 Commits
Author SHA1 Message Date
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.
2.20.2
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
2.20.1
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
Cory BenfieldandGeorge Barnett e71a0f38df Update scripts/vendor-boringssl.sh
Co-authored-by: George Barnett <gbarnett@apple.com>
2022-06-20 14:27:29 +01:00
Cory Benfield 83c2001852 Update BoringSSL vendor for Apple Silicon
We updated the swift-crypto build scripts for Apple Silicon, let's make
a change here too.
2022-06-20 14:27:29 +01:00
David Nadoba 4e5f439075 Remove try from Server Example (#372)
The constructor of `NIOSSLServerHandler` no longer throws. The throwing version is deprecated and should not be used.
2022-06-14 20:03:05 +02:00
Cory Benfield 2054785706 Use the 5.7 nightlies 2022-06-13 11:07:21 +01:00
George Barnett 42436a25ff Update BoringSSL to 1e469e45a46ff580899cbef939babe02ad916c85 (#370)
* Update vendor-boringssl.sh

* Update BoringSSL
2.20.0
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
meaton2 efc0a67ea5 issue-367 address feedback 2022-05-12 08:08:13 +01:00
meaton2 23cb003a50 Parallel test fix for TLSConfigurationTest
Motivation:

Address the issue the race condition brought up in #367

Modifications:

Created directories based on the test name so that each file would be isolated.

Result:

Avoid race condition in parallel test.
2022-05-12 08:08:13 +01: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
George Barnett 4941a5e1d9 Remove build_podspec.sh (#365)
Motivation:

We no longer support Cocoapods.

Modifications:

- Remove build_podspec.sh and associated scripts

Result:

Less unused code.
2022-05-04 03:39:40 -07:00
George Barnett 36880de810 Update pod generation script
Motivation:

To workaround https://github.com/apple/swift-nio/issues/2073 we must
list all transitive dependencies when building podspecs.

Modifications:

- Copy over `list_transitive_dependencies.py` from the NIO repo.
- Include transitive dependencies in the build_podspec script
- Bump C++ language standard from 11 to 14
- Ignore non-modular header warnings
- Be more precise when specifying 'CNIOBoringSSL*' targets
- Use python3 in build-asm.py (The soundness script includes the
  shebang as part of the 'hash' when checking for license headers and
  only allows for one shebang per extension so we cannot use both Python
  2 and 3 in the same repo.)

Result:

Podspec generation script includes transitive dependencies.
2022-05-04 10:59:20 +01: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.
2.19.0
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
Fabian Fett c753000014 Fix warnings, that appeared after requiring Swift 5.4 (#355) 2022-04-21 09:11:11 -07: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
Fabian Fett e018a45ee1 Drop support for Swift 5.2 and 5.3 (#353)
As outlined in a [Swift forums post in November ’21](https://forums.swift.org/t/swiftnio-swift-version-support/53232), SwiftNIO will only support the latest non-patch Swift release and the 2 immediately prior non-patch versions.

- drop support for Swift 5.2 and 5.3
- update CI for Swift 5.4 to run on bionic instead of focal to ensure that we still test bionic
2022-04-20 08:55:29 +02:00
Franz Busch 1750965a1c Use SPM API diff checker (#351)
### Motivation:

SPM has built in functionality to check the API of modules against a target git treeish. We can use this to simplify our `check_no_api_breakages.sh` script. Closes https://github.com/apple/swift-nio/issues/1239

### Modifications:

This PR, exchanges the direct calls to Swift's API checker with the new SPM `diagnose-api-breaking-changes` tool. This allows us to get rid of the manual module parsing, build invocations and result comparisons.

### Result:

We are now using SPMs `diagnose-api-breaking-changes` to check for breaking changes.
2022-03-24 11:35:22 -07:00
Cory Benfield b5260a31c2 Update BoringSSL to 8bbefbfeee609b17622deedd100163c12f5c95dc (#350) 2.18.0 2022-03-22 15:10:36 +00:00
tomer doron 389adf055c ci update (#349)
motivation: 5.6 is out

changes:
* use release version of 5.6
* add docker setup for 5.7 (using nightly for now)
2022-03-16 21:19:27 -07: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 3604f9db82 Make 2022 a valid year in licence headers (#346) 2022-03-09 10:15:06 -08: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 59d9dcaf1a Add 5.6 nightly CI. (#339)
The 5.6 nightly images are available, let's use them.
2022-01-18 01:10:52 -08:00
Cory Benfield 52a486ff6d Update BoringSSL to 295b31324f8c557dcd3c1c831857e33a7f23bc52 2.17.2 2022-01-11 08:55:02 +00:00
George Barnett 76164f0237 Update doc generation script (#335)
Motivation:

The docs haven't been generated for a while.

See also: https://github.com/apple/swift-nio/pull/2013

Modifications:

- Pass `--spm` flag to sourcekitten
- Update source location of sourcekitten
- Fix link to NIO docs

Result:

Docs build.
2021-12-17 04:07:58 -08:00
Cory Benfield 2b329e37e9 Update BoringSSL to 2042972e8458833714bce23386931b1c79978439 (#334) 2.17.1 2021-12-09 06:24:01 -08:00
Cory Benfield 0324d60429 Update BoringSSL to 3a667d10e94186fd503966f5638e134fe9fb4080 2.17.0 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.
2.16.3
2021-11-12 17:45:37 +00:00
Cory Benfield 08e701df9a Add x509_vfy.h to umbrella header 2.16.2 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) 2.16.1 2021-09-23 11:14:05 +01:00
Cory Benfield 044f90dfa0 Migrate to Swift 5.5 release in CI (#324) 2.16.0 2021-09-22 09:23:20 +01:00
Cory Benfield 15d2090ae3 Tolerate zeroReturnError in closed/unwrapped (#323)
Motivation:

In some rare cases we've seen production applications crash due to us
getting a zeroReturnError in either closed or perhaps unwrapped. This is
pretty hard to get to trigger in realistic situations, but I've found a
contrived-but-possible way to hit it in tests. In both of these cases we
are able to simply ignore the error and move on.

Modifications:

- Added a test to replicate the issue
- Tolerate .unwrapped and .closed on zeroReturnError.

Result:

Fewer weird crashes
2021-09-21 15:43:17 +01:00
Cory Benfield 70da47e2d4 Add callback-based custom private keys. (#322)
Motivation:

NIOSSL traditionally handles private keys be requiring that they can be
decoded into a BoringSSL EVP_PKEY structure. This requires the key to
have an in-memory representation that BoringSSL understands, and
ultimately forces the bytes of the private key into memory.

In many cases, however, this is either undesirable or not possible.
For security reasons it is common to want to offload a private key into
secure storage, such as the iPhone's Secure Enclave or a portable smart
card. In other circumstances it may be useful to put the private key on
an entirely different machine and have the signing operations occur over
an RPC mechanism.

In all of these cases it is necessary to have a programmatic interface
to the private key that can be implemented in an essentially arbitrary
manner.

Modifications:

- Defined a new protocol, `NIOSSLCustomPrivateKey`, that allows users to
  implement the private key operations needed for TLS.
- Plumbed support for this interface through `NIOSSLPrivateKey`.
- Added support for the BoringSSL interface to `SSLConnection`.

Result:

Custom TLS private keys backed by function calls can now be provided to
NIOSSL.
2021-09-21 12:57:22 +01:00
Cory Benfield 77a3bf1788 Fixup CA name tests on Darwin (#320)
Motivation:

The recently-added CA name tests consistently fail on Darwin machines.
This is becuase they expect the handshake to fail due to certificate
verification errors, but that doesn't happen synchronously on Darwin.
This also introduces thread-unsafety into the tests. Neither is good.

Modifications:

- Modify the test configuration to use custom trust roots, which
  disables the Security.framework callbacks
- Modify the test configuration to disable hostname verification.

Result:

These tests now successfully perform their handshake on all platforms.
2.15.1
2021-09-16 09:45:42 +01:00
Cory Benfield 7ced2aed37 Remove the implementationOnly dance (#321)
Motivation:

When we added implementationOnly imports a while back, we supported
Swift 5.0, and so we needed to guard their availability behind a
compiler check. We only support 5.2 and later now, so that check is
redundant and can go away.

Modifications:

- Removed compiler checks around imports of our C libraries.

Result:

Cleaner code
2021-09-16 09:29:08 +01:00
Cory Benfield c359ba56f7 Clean up imports and dependencies (#319)
Motivation:

With NIO 2.32.0 we broke the core NIO module up into modules that split
apart the POSIX layer and the core abstractions. As a result, this
package no longer needs to express a hard dependency on the POSIX layer.

Modifications:

- Rewrote imports of NIO to NIOCore.
- Added NIOEmbedded and NIOPosix imports where necessary in tests.
- Extended soundness script to detect NIO imports.
- Note that the main modules still depend on NIO, which is necessary
for backwards-compatibility reasons. This dependency is unused.

Result:

No need to use NIOPosix.
2021-09-14 14:55:25 +01:00
Matt Eatonandmeaton2 d661f0fa95 Fix for nightly build. (#318)
Motivation:

Resolving build failures for the nightly build suite on each commit.

Modifications:

Modification to ClientSNITests.swift.

Result:

Surpressing the error on the nightly build.

Co-authored-by: meaton2 <meaton3@apple.com>
2021-09-09 17:07:01 +01:00
Cory Benfield 688f902407 Update BoringSSL to 25773430c07075a368416c3646fa4b07daf4968a (#315)
* Update BoringSSL to 25773430c07075a368416c3646fa4b07daf4968a

* Clean up the use of the X509 pointer

Motivation:

BoringSSL has begun opaquifying their X.509 library. This unfortunately
manifests as source code changes in Swift due to the way OpaquePointer
behaves. As a result, we need to change the places that held an X.509
pointer directly.

While we're here, we've been playing a bit fast-and-loose with the
lifetime of owned pointers. We should take this opportunity to clean
things up and be a bit better behaved.

Modifications:

- Replace the X509 pointers with OpaquePointer
- Use scoped access to the X.509 access outside the NIOSSLCertificate
  class.

Result:

Code compiles with better pointer hygeine.
2021-09-09 08:54:01 +01:00