12 Commits
Author SHA1 Message Date
Cory Benfield 6617eb0d3a Move syscalls to a port of Posix enum. (#24)
Motivation:

Right now we make a bunch of naked syscalls that don't correctly
handle reporting errno or catching EINTR. We can't use the NIO Posix
enum to fix this for us because it's internal, and because it doesn't
have the function we need. Instead, we create a temporary port of those
functions.

Ideally we'd reconcile these at some time in the future.

Modifications:

Add a port of the Posix enum and its core functions.
Improve wrapErrorIsNullReturnCall to be more useful.
Adopt the posix functions.

Result:

Better safety in the face of EINTR.
Better reporting of errnos.
2018-07-12 12:26:00 +01:00
Cory Benfield f9a2581ceb Correctly keep buffers alive. (#22)
Motivation:

BIO_new_mem_buf does not take a copy of its underlying memory, so it's
enormously important that the pointer we pass it remain valid for the
duration of the lifetime of the BIO. This was previously not actually
something we did. Very bad.

Modifications:

Extended the scope of the `withUnsafeBytes` call until the `BIO` created
from those bytes is supposed to go out of scope.

Result:

Better memory safety.
2018-07-12 11:50:34 +01:00
Cory Benfield c5e345b62e Add support for PKCS#12 bundles. (#23)
Motivation:

As requested in #17, it's not uncommon to want to support PKCS#12 bundles.
This patch adds support for unpacking PKCS#12 bundles into useful data types
for NIOOpenSSL.

Modifications:

Added new OpenSSLPKCS12Bundle type.
Added new fromUnsafePointer(takingOwnership:) static functions to
    OpenSSLCertificate and OpenSSLPrivateKey.
Deprecated fromUnsafePointer(pointer:) on OpenSSLCertificate and
    OpenSSLPrivateKey.

Result:

PKCS#12 bundles can be used to distribute certs/keys for SwiftNIO.
2018-07-12 11:48:28 +01:00
Cory Benfield c0e3f285bc Support private keys with passphrases. (#21)
Motivation:

Many users want to use passphrases to secure their private keys. We have not
previously supported any mechanism to provide that passphrase other than
the default OpenSSL passphrase callback. This is not useful in all
circumstances, and is particularly troubling in the case of automated
systems. We should add better support.

Modifications:

Enhance OpenSSLPrivateKey to allow setting a passphrase callback.
Enhance SSLContext to allow setting a passphrase callback.

Result:

Users can set passphrase callbacks.
2018-07-09 16:26:45 +01:00
Cory Benfield 8e0aa765e3 Set SSL_MODE_RELEASE_BUFFERS and SSL_MODE_AUTO_RETRY. (#14)
Motivation:

There are two key issues at play here.

Firstly, OpenSSL connections by default hang on to buffers for idle
connections. This isn't really necessary, and setting
SSL_MODE_RELEASE_BUFFERS can save enormous amounts of memory (tens of kb
per connection in some cases).

Secondly, and more profoundly, OpenSSL's default behaviour on SSL_read
is unexpected. In particular, it is possible to get SSL_read to return
SSL_ERROR_WANT_READ in cases where the receive BIO does actually have
an application data record in it, but where a non-application data
record was received first.

Handling that is a tricky case, but it's much easier to ask OpenSSL to
do it for us by just setting SSL_MODE_AUTO_RETRY. This really ought to
be the default behaviour: the fact that it isn't is fairly perplexing.

See https://github.com/openssl/openssl/issues/6234 for more discussion
of SSL_MODE_AUTO_RETRY.

Modifications:

Set SSL_MODE_RELEASE_BUFFERS and SSL_MODE_AUTO_RETRY.

Result:

Less memory usage, fewer subtle bugs.
2018-05-14 21:32:14 +01:00
Joe Smith 38955a5f80 Include md5 openssl Header (#13)
Motivation:

I'm switching [an AWS SDK](https://github.com/noppoMan/aws-sdk-swift) to use NIO under the hood, and there are some MD5 sum operations we need to complete related to requests + file operations.

Including [the `md5.h` header ](https://github.com/libressl/libressl/blob/master/src/crypto/md5/md5.h) will make it much easier to utilize and prevent requiring an additional package to get  at the functions already present here.

Modifications:

Included the `md5.h` header in `CNIOOpenSSL

Result:

This will allow md5 related functions to be used by packages including `CNIOOpenSSL`.
2018-04-30 11:25:11 +01:00
Cory Benfield fb3bc221d6 Remove processing of now-nonexistent flush promises. (#6)
Motivation:

There are no more flush promises in NIO, so we don't need to bend
over backwards to track them appropriately.

Modifications:

Remove the code that handles flush promises. Simplify.

Result:

Simpler, easier to follow code for buffered writes.
2018-02-23 11:03:40 +01:00
Johannes Weiss 66863edf2a adopt latest API 2018-02-21 18:56:19 +00:00
Cory Benfield 46b3a8448c Update to newer breaking change of NIO 2018-02-14 09:23:25 +00:00
Cory Benfield bcc121011b Fix compiles on Swift 4.1
Without this change we break on Swift 4.1 on Linux due to
SR-6963.
2018-02-09 09:50:17 +00:00
Cory Benfield 044b978525 Bring up-to-date with NIO latest 2018-02-08 16:50:53 +00:00
Johannes Weiß a6936a36f1 move OpenSSL support from NIO main repo 2018-01-25 18:35:14 +00:00