motivation: test for api breakage on PR
changes:
* add script to detect api breakage
* amend docker setup to include jq
* amend docker-compose setup to include a shell utility task
Motivation:
Well-formed Linux assembly code declares a .note.GNU-stack section in
order to help out the linker. When absent, the linker makes some
suboptimal linking decisions that can cause pain in running programs.
Modifications:
- Amend the vendoring script to add the .note.GNU-stack section to all
assembly files on Linux.
- Updated BoringSSL
Results:
Better linker behaviour.
* swift 5.1 docker setup
motivation: support swift 5.1
changes:
* use formal swift docker images
* refactor docker-compose to seperate unit tests, integration tests and full test suites
* add docker compose file for swift 5.1, will add CI job once merged
* update swiftformat version to 0.40.12
Motivation:
Our scripts have code to catch the functions that are used with STACK_OF
and LHASH_OF data structures in BoringSSL in order to namespace them.
Sadly, some declarations were falling through the cracks: we missed some
LHASH_OF functions used internally, and we missed the
DEFINE_NAMED_STACK_OF macro used for a new C++ data type.
Modifications:
- Improved these scripts to catch more cases.
- Updated BoringSSL to 9806ae005b3085683a2fcf2953e4170893e0973d.
Result:
Fewer exported symbols from BoringSSL.
Motivation:
The BoringSSL version of `BIO_new_mem_buf` takes a const buffer but
we pass a mutable one.
Modifications:
Pass a const buffer.
Result:
Unsafe instead of Unsafe+Mutable.
Motivation:
On different platforms C may define `int` and `unsigned` to be different
types. When writing C interop code in Swift it's preferable to
use the `CInt` and `CUnsignedInt` typealiases as they will resolve to
the correct C type on all supported platforms. If the imported C API is
a definite-sized type, like `uint32_t` we leave the Swift type as
definitely-sized.
Modifications:
Use `CInt` instead of `Int32` for C `int` parameters and `CUnsignedInt`
instead of `UInt32` for C `unsigned` parameters.
Result:
Code is more portable and definite-sized types stand out.
Motivation:
The underlying BoringSSL BIO APIs used by NIOSSLCertificate,
NIOSSLPrivateKey take a raw byte buffer and a count,
and do not need the input buffers to be NUL-terminated. However, the API
currently takes an `Array<Int8>` (which is a typealias of `Array<CChar>` on
platforms where NIO is primarily developed). This suggests an incorrect
completion in Xcode (`utf8CString`) which includes a trailing NUL byte.
In fact, all of the NIOSSL unit tests make this mistake. The more common
use case of creating a these types from a `Data`, `ByteBuffer`, or
`String.UTF8View` is made more awkward as these are easy to convert to
`[UInt8]` but harder to convert to `[CChar]` without extending them with
an unnessary NUL byte.
Modifications:
Add new `bytes:` overloads to the convenience initializers and deprecate
the `buffer:` convenience initalizers. Use these new initializers in the
unit tests.
Result:
A more ergnomic way to correctly create these types from `Data`,
`ByteBuffer`, and `String.UTF8View`.
Motivation:
The README uses the '.file' case of 'NIOSSLCertificateSource' which has
been deprecated.
Modifications:
Update the README to use the recommended replacement method:
'fromPEMFile(_:)'.
Result:
The README no longer uses a deprecated enum case.
Motivation:
It is only possible to load multiple certificates from a PEM file,
sometimes it is useful to load multiple certificates from a buffer.
Modifications:
- Deprecate the `.file` source of loading a certificate, since it would
only load the first certificate in a file.
- Provide methods for loading multiple certificates from a PEM file or
buffer.
Result:
Multiple certificates can be loaded from a PEM file/buffer.
Motivation:
When including an xcodeproj generated by SwiftPM (which builds
CNIOBoringSSL) into an xcodeproj which wasn't generated by SwiftPM it
doesn't know about the correct header paths.
Modifications:
Update the vendor-boringssl script to:
- Namespace BoringSSL with CNIOBoringSSL_ instead of CNIOBoringSSL/
- Create an umbrealla CNIOBoringSSL header
- Apply a patch to replace inttypes.h with sys/types.h in bn.h
- Apply a patch to conditionally include arm_arch.h
BoringSSL was also updated to: ae223d6138807a13006342edfeef32e813246b39
Result:
Non-SwiftPM xcodeproj's can build a SwiftPM generated xcodeproj
which includes CNIOBoringSSL.
Motivation:
Previously, if the user tried to open a private key that had a password
but didn't specify one, we would just crash.
Modifications:
Throw an error instead of crashing if no password was supplied but one
was needed.
Result:
Fewer crashes.
Motivation:
The README suggested that configuration, SSL context, and the SSL
handler should be created in three lines following each other. That
leads to people copy & pasting this into the root of their `main.swift`
and then by accident reusing the SSL handler which leads to pretty bad
issues.
Modifications:
Make the README snippet clearer and closer to an actual usage.
Result:
API used more correctly.
Motivation:
If we don't import CNIOBoringSSL @_implementationOnly, then some details
of libssl's C structs might leak into NIOSSL's ABI which might lead to
clashes further down the line.
Modification:
- make all CNIOBoringSSL(Shims) imports @_implementationOnly
- remove all concrete libssl types from instance variables
Result:
- fixes#116
- works around SR-11125
Motivation:
While TLS renegotiation is in general a bad idea, it is widely used for
delayed TLS-based client authentication. We are able to support this
use-case, and so we should enable it.
As with BoringSSL, we'd like to continue to default to not supporting
this mode of operation. However, users are free to enable support if
they so choose.
Modifications:
- Added flags for configuring renegotiation.
- Added integration test harness.
- Added renegotiation integration test with s_server.
- Added renegotiation and client cert support to sample client.
Result:
Users will be able to perform TLS renegotiation.
Motivation:
The 32-bit assembly in BoringSSL doesn't assemble correctly on 32-bit
apple platforms. It took us a while to notice because we previously
haven't had any supported 32-bit platforms. NIOSSL still doesn't really
support any 32-bit Apple platforms, as all production use on those
platforms should use NIOTS, but there's no excuse for the compilation
failures really.
Modifications:
Remove assembly acceleration on 32-bit Apple platforms.
Result:
Better compilation on 32-bit Apple platforms.
Motivation:
When server users turn on certificate verification, they usually expect
that they'll actually require the certificate from their peer. Sadly,
this is not the BoringSSL default behaviour.
Modifications:
Set `SSL_VERIFY_FAIL_IF_NO_PEER_CERT` when requesting certificate
validation.
Result:
Better certificate validation.
Motivation:
Allowing readers of the API documentation to drill into the implementation of documented declarations can be educational and helpful for debugging, among several other reasons.
Modifications:
Add --github-file-prefix appending the current version in order to keep stable links. This means that documentation generated from any non-release revision may resolve incorrectly. This can be refined in the doc generation script later if it is deemed problematic by resolving to the commit sha if it doesn't exactly align with the version.
Result:
Users will be able to click a 'Show on GitHub' for all documented API declarations.
Motivation:
BoringSSL's docs make it pretty clear that ERR_error_string is not safe to use in a
concurrent context. Sadly, NIO is pretty damn concurrent, so we should probably stop using it.
Modifications:
- Rewrite the error printing logic to use ERR_error_string_n which takes a buffer to write
into.
Result:
Error strings will not be corrupted in multithreaded contexts.
Motivation:
The remote peer may not always respond to a close notify. This would
leave the SSL handler waiting to shutdown. The shutdown should timeout
in these cases to ensure shutdown completes.
Modifications:
- Added a shutdown timeout to the NIOSSLHandler, and a configurable
timeout amount to TLSConfiguration.
- Added a test to validate timing out a shutdown.
Result:
TLS shutdown will complete even if the remote peer does not respond to a
close notify.
Motivation:
In many cases it is useful to support dumping the keys used in a TLS
connection, primarily for debugging purposes. BoringSSL provides a
callback that can be used for this purpose: we should translate it into
Swift and expose it to our users.
Modifications:
- Added a keyLogCallback parameter to TLSConfiguration.
- Wired that callback up to BoringSSL.
Result:
Building blocks of SSLKEYLOGFILE support are present.
Motivation:
With package editing this problem surfaces:
```
$ jw-swift-5.0 swift test
error: multiple products named 'NIOHTTP1Client' in: swift-nio, swift-nio-ssl
error: multiple targets named 'NIOHTTP1Client' in: swift-nio, swift-nio-ssl
```
which is bad. Fortunately, these are executable targets that we can
rename.
Modification:
rename `NIOHTTP1Client` in swift-nio-ssl to `NIOSSLHTTP1Client`
Result:
usable with package editing.
Motivation:
We want to avoid BoringSSL falling too far out of date. This patch updates
BoringSSL.
Modifications:
Updated BoringSSL.
Result:
Newer BoringSSL.
* Handle close reentrancy in NIOSSLHandler.
Motivation:
- If the NIOSSLHandler had reads to fire during a clean shutdown, then
they could cause an additional reentrant shutdown.
- This would fail a precondition and crash.
Modifications:
- If we're already in the shutdown state then don't perform shutdown again
- Added a test
Result:
More correct code.
* Update Linux tests
Motivation:
We namespaced our header files, but some includes had weird whitespace in
the directive that we didn't notice. This meant that ARM builds failed.
Modifications:
- Became more tolerant of whitespace.
- Fixed an error in Package.swift
Result:
Better builds on ARM
Motivation:
We have a static library target that is used as part of the BoringSSL
vendoring setup to generate a list of hidden symbols. This works nicely,
but building it fires out a bunch of warnings due to files with no symbols
in them. That's fine during the build phase, but most developers should
never need to see it.
Modifications:
- Hide the static archive product most of the time.
- Update vendor script to un-hide the static archive product on vendoring.
- Enable warnings-as-errors.
Result:
Fewer warnings.
* Add "/.idea" to the project's ignore file.
Motivation:
To develop with AppCode.
Modifications:
Add "/.idea" to the project's ignore file.
Result:
Add "/.idea" to the project's ignore file.
* Provide an HTTPS example. (#12)
Motivation:
To provide an example for people to use swift-nio-ssl at their projects with ease.
Modifications:
- Add NIOHTTP1Client module.
Result:
A good example for getting started with swift-nio-ssl.
* * Create OpenSSLHandler instance in channelInitializer function and chain adding handlers.
* Make sendRequest function to return EventLoopFuture and cascade promise with it to properly finish application.
* Accept command line argument.
* Make channel closed after receiving HTTPClientResponsePart.end. Because if large response is returned, channelReadComplete is called twice or more times.
* Add README.md for documenting command line argument.
* Add Connection header with handling for channelInactive
* Remove print and write bytes to stdout.
* fix compile error for NIO2.
* rename ctx to context
* dependency on NIOFoundationCompat was missing
Motivation:
SecPolicyCreateSSL expects a `server` parameter which is a boolean. We
previously thought it identifies what our peer is but it really
specifies what the remote peer is.
Modification:
Flip the role.
Result:
Cert validation actually works.
Motivation:
While our main use-case is users on Linux, many of our users develop on
their Mac. We need to support their development model, which may well
involve making outbound requests. Those requests need certificate
validation.
Modifications:
- Added routines for using Security.framework to validate cert chains.
- Refactored code to be as platform-independent as possible.
Result:
Certificate verification works on Apple platforms.
Motivation:
When debugging, users may find it helpful to be able to nail down exactly
which version of BoringSSL is used to generate the specific release. We should
record this in two easy-to-find places: one in the Package.swift for users
going to GitHub, and one in the Sources tree for users who check the code
out.
Modifications:
- Updated the script to record the BoringSSL hash.
Result:
Easier to find out what BoringSSL release is in use.
Motivation:
It was too easy to forget passing serverHostname to NIOSSLClientHandler
which made certificate validation fail.
Modification:
Require users to pass a server hostname or `nil` explictly.
Result:
- harder to use NIOSSLClientHandler wrongly
- fixes#80
Motivation:
NIO1APIShims are a transitional thing that can now go away because of
convergence.
Modifications:
- remove NIO1APIShims
- require 2.0.0-convergence.1
Result:
proper dependencies
Motivation:
Our previous namespacing effort used symbol analysis of a compiled binary
to locate all the symbols that needed to be namespaced away. This works
fine for regular C and C++ symbols, but fails for any header-only
inline functions.
These functions, while not emitted into the binary, can cause problems
with the C++ ODR if they are included in multiple clang modules. This
unfortunately does happen if the user includes both this library and,
for example, modularised headers that include OpenSSL headers.
Fortunately, we can namespace the inline functions as well.
Modifications:
- Namespaced all the inline headers by source analysis.
Result:
Fewer code conflicts.
Motivation:
Due to the way SwiftPM builds projects it's possible for our
BoringSSL header files to clash with other people's OpenSSL header
files. That leads to build errors and sadness.
Modifications:
- Updated the BoringSSL vendor script to move all header files.
- Updated script to point C files at new header files.
- Brought in new BoringSSL version.
After your change, what will change:
Happier users
Motivation:
Unfortunately, it turns out that the word "OpenSSL" just ended up everwhere
in our codebase, including in the names of our types. This was, in hindsight,
a bit of an unfortunate bit of naming.
We should take this breaking opportunity to give these types better names.
In particular, we should stop identifying them as belonging to any library
other than this one, "NIOSSL". That way we become somewhat independent of
the specific way that this library is implemented.
Modifications:
Renamed a bunch of stuff. Internal types mostly got their names changed
from OpenSSL->BoringSSL. External types generally got their names changed
to "NIOSSL", except where those types directly reflected a BoringSSL
implementation detail, specifically in the errors.
The main name changes are:
SSLContext -> NIOSSLContext
OpenSSLError -> BoringSSLError
NIOOpenSSLError -> NIOSSLError
OpenSSLInternalError -> BoringSSLInternalError
OpenSSLPKCS12Bundle -> NIOSSLPKCS12Bundle
OpenSSLPassphraseCallback -> NIOSSLPassphraseCallback
OpenSSLPassphraseSetter -> NIOSSLPassphraseSetter
OpenSSLPrivateKey -> NIOSSLPrivateKey
OpenSSLPublicKey -> NIOSSLPublicKey
OpenSSLCertificate -> NIOSSLCertificate
OpenSSLVerificationResult -> NIOSSLVerificationResult
OpenSSLVerificationCallback -> NIOSSLVerificationCallback
OpenSSLCertificateSource -> NIOSSLCertificateSource
OpenSSLPrivateKeySource -> NIOSSLPrivateKeySource
OpenSSLTrustRoots -> NIOSSLTrustRoots
OpenSSLSerializationFormats -> NIOSSLSerializationFormats
OpenSSLHandler -> NIOSSLHandler
OpenSSLClientHandler -> NIOSSLClientHandler
OpenSSLServerHandler -> NIOSSLServerHandler
Oh, and renamed the module too: it's now NIOSSL, instead of NIOOpenSSL.
Result:
Users have better names for things.
Motivation:
OpenSSL went away a long time ago, we don't need to keep it around.
Modifications:
Deleted the old CNIOOpenSSL module source.
Result:
Less unnecessary source code.
Motivation:
The name SSLContext conflicts with a type in Security.framework. That's
a really unnecessary naming clash, and while it's unlikely to be a real
problem in most programs, we still shouldn't encourage that if we can
avoid it.
Modifications:
- Rename SSLContext to NIOSSLContext.
Result:
Fewer naming conflicts.
Motivation:
When we moved away from the system copy of OpenSSL, we lost the
compiled-in locations of the default root CAs. We should go looking for
them so that certificate verification still works!
Modifications:
- Added a runtime one-off search to locate the roots.
Result:
Certificate verification works on Linux