swift-server-dev Digest, Vol 2, Issue 8

Hi all, what about the crypto library GitHub - krzyzanowskim/CryptoSwift: CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift, It’s pure swift

···

在 2016年11月9日,02:00,swift-server-dev-request@swift.org 写道:

Send swift-server-dev mailing list submissions to
  swift-server-dev@swift.org

To subscribe or unsubscribe via the World Wide Web, visit
  https://lists.swift.org/mailman/listinfo/swift-server-dev
or, via email, send a message with subject or body 'help' to
  swift-server-dev-request@swift.org

You can reach the person managing the list at
  swift-server-dev-owner@swift.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of swift-server-dev digest..."

Today's Topics:

  1. Re: Crypto Library (Zach Drayer)
  2. Re: Crypto Library (Zach Drayer)
  3. Re: Crypto Library (Bill Abt)
  4. Re: Crypto Library (Brent Royal-Gordon)
  5. Re: HTTP Parser (Thiago Holanda)
  6. Re: Crypto Library (Chris Bailey)
  7. Re: Crypto Library (Joannis Orlandos)

----------------------------------------------------------------------

Message: 1
Date: Mon, 7 Nov 2016 12:48:58 +0000
From: Zach Drayer <zachary.drayer@gmail.com>
To: Helge Heß <me@helgehess.eu>, swift-server-dev@swift.org
Subject: Re: [swift-server-dev] Crypto Library
Message-ID: <D043B4C9-66B6-4D30-B735-018AFD036838@gmail.com>
Content-Type: text/plain; charset="utf-8"

<forking "HTTP Parser", thanks for reading and/or sorry in advance for any for threading issues that crop up>

On Nov 7, 2016, at 11:20 AM, Helge Heß via swift-server-dev <swift-server-dev@swift.org> wrote:

P.S.: As a sidenote, can’t someone (hm hm, who would come to mind?) sponsor the CryptoSwift guy to do a java.security like Security standard framework (which includes TLS)? That would be pretty cool :-)

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-server-dev

Assuming we want a pure-Swift crypto framework _right now_:

Before any crypto code can safely be written in Swift, there needs to be compiler support to prevent it from optimizing things incorrectly (for example, a memset() designed to clear a buffer of secret data).

I may have missed discussions about this on swift-evolution (and maybe swift-server-dev is a place to flesh out a SE proposal to send their way?), but, i'm not sure if all that work's been scoped out anywhere, or if it has, what the timeframe is. ABI stability might even be a soft requirement here before anyone can reasonably get started on this.

So, I don't think we really want a pure Swift crypto library yet.

Instead: while in C, Security.framework, and CommonCrypto.framework from  are both fully open source, and battle-hardened. This is one of (rare) the cases where practicality and strongly deferring to the thing that already exists seem to be the safe option (and not only in opinion).

Anyway, (to me) the more interesting questions that we can talk about are over API:
- what constructs are needed (bignum? secure random? hmac? checksumming? key derivation? wrapping a socket in a big TLS hug?)
- what umbrella(s) do these constructs live in? (maybe bignum is in separate framework, or hugging sockets with TLS is an i/o construct rather than a crypto construct, or.. etc)
- is there anything to explicitly not support? securing a socket with sslv2 and sslv3 seem like obvious candidates here, but maybe the API is even more opinionated and doesn't let you create weak RSA keys, etc.
- ??? other exciting things to consider here

-z
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20161107/8a3aab09/attachment-0001.html&gt;

------------------------------

Message: 2
Date: Mon, 7 Nov 2016 15:31:10 +0000
From: Zach Drayer <zachary.drayer@gmail.com>
To: Helge Heß <me@helgehess.eu>
Cc: Swift Server Dev <swift-server-dev@swift.org>
Subject: Re: [swift-server-dev] Crypto Library
Message-ID: <B2FB0028-4AE2-48B7-9EE2-24342C2FB013@gmail.com>
Content-Type: text/plain; charset="utf-8"

On Nov 7, 2016, at 2:45 PM, Helge Heß via swift-server-dev <swift-server-dev@swift.org> wrote:

On 07 Nov 2016, at 13:48, Zach Drayer <zachary.drayer@gmail.com> wrote:

On Nov 7, 2016, at 11:20 AM, Helge Heß via swift-server-dev <swift-server-dev@swift.org> wrote:

P.S.: As a sidenote, can’t someone (hm hm, who would come to mind?) sponsor the CryptoSwift guy to do a java.security like Security standard framework (which includes TLS)? That would be pretty cool :-)

Instead: while in C, Security.framework, and CommonCrypto.framework from  are both fully open source, and battle-hardened.

Do they provide a clean Linux story too? (.framework in the name kinda suggests they don’t :-)

Do they work with non-blocking I/O? The API read/write/handshake API suggests that they may not?

Looks like the approach people currently use is either Security.framework on Darwin and Open/LibreSSL on other platforms, or using OpenSSL on both. Some even forking OpenSSL.

Good question. My assumption was “yes, of course”, but, it looks like that isn’t correct in the way I expected it to be.

CommonCrypto looks like it makes some assumptions about Darwin (e.g. importing TargetConditionals or Availability.h) but looking one level deeper, we find `corecrypto` at the bottom of Security Overview - Apple Developer that is also open source, is what underlies CommonCrypto + Security, and, has the necessary `#if`s to build on Linux (even if it is lacking a Makefile at the moment).

This is one of (rare) the cases where practicality and strongly deferring to the thing that already exists seem to be the safe option (and not only in opinion).

This is all true, but then someone also thought it makes sense to have Security.framework despite OpenSSL being available. Or java.security. Or Windows SChannel/security. Just saying …

The thing which makes a pure-Swift thing attractive is that it would be cross platform and readily available. The C libs are really diverse between the platforms and forking OpenSSL into an embedded module is not exactly 1337 either.

No disagreement that there are a number of benefits to living in a pure Swift world, but as mentioned earlier: this may not be possible yet. There is little point in providing a security/crypto library that can’t be trusted — and with cryptography, the requirement for trust extends far beyond “does it compile?, or even “do all the tests pass?”. We don’t want another heartbleed, or a predictable PRNG (https://github.com/g0tmi1k/debian-ssh\).

But, I don’t know. Maybe the solution isn’t corecrypto, but is LibreSSL/OpenSSL, or, something else. Maybe adding compiler support for Crypto tasks is already done (or easy enough to do) and my argument is moot. Thats why we’re having this discussion, right?

Anyway, (to me) the more interesting questions that we can talk about are over API:
- what constructs are needed (bignum? secure random? hmac? checksumming? key derivation? wrapping a socket in a big TLS hug?)

The thing I need and which is a little awkward to get is async TLS, both client and server. I started working on an OpenSSL BIO and see whether I can get that running on top of GCD, looks like it should be possible.

For the hashes that I needed so far (just MD5 and SHA1) I use CryptoSwift.

These seem like excellent use cases to consider, thank you for bringing them up! Reading through https://swift.org/server-apis/, the section on "Security and Encryption”, definitely indicates that this is the right place to talk about these needs.

-z

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20161107/54a3ef77/attachment-0001.html&gt;

------------------------------

Message: 3
Date: Mon, 07 Nov 2016 13:48:22 -0500
From: Bill Abt <babt@me.com>
To: Swift Server Dev <swift-server-dev@swift.org>
Subject: Re: [swift-server-dev] Crypto Library
Message-ID: <9BAD41B0-4E48-4DB3-AD87-FA421D467A42@me.com>
Content-Type: text/plain; charset="utf-8"

We experimented with various different approaches when doing the lower levels of Kitura. Ultimately, we chose to use CommonCrypto on macOS and libcrypto (from OpenSSL) on Linux for the crypto portion. You can see the implementation (which works on both macOS and Linux) at https://github.com/IBM-Swift/BlueCryptor\. As far as the securing sockets, we chose to go with Apple Secure Transport on macOS and OpenSSL on Linux. This implementation can be found at https://github.com/IBM-Swift/BlueSSLService\. The BlueCryptor package can be used by virtually Swift application. The BlueSSLService, however, is an add-on to and dependent on BlueSocket, the underlying network layer for Kitura.

In my opinion, using the Security framework on macOS is fine but to get the “beast” running on Linux may be very, very problematic. The underlying codebase is massive and there are bits and pieces that are missing and would have to be re-implemented. Another factor that led us to not use the Security framework was relatively sparse documentation. CommonCrypto is a much smaller subset as is Secure Transport and the mapping between them and librcrypto and OpenSSL is much cleaner and straight forward. Plus, as others have pointed out, an implementation taking this approach doesn’t have to worry so much about FIPS certification since the underlying platform implementation are already certified.

On Nov 7, 2016, at 10:31 AM, Zach Drayer via swift-server-dev <swift-server-dev@swift.org> wrote:

On Nov 7, 2016, at 2:45 PM, Helge Heß via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>> wrote:

On 07 Nov 2016, at 13:48, Zach Drayer <zachary.drayer@gmail.com <mailto:zachary.drayer@gmail.com>> wrote:

On Nov 7, 2016, at 11:20 AM, Helge Heß via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>> wrote:

P.S.: As a sidenote, can’t someone (hm hm, who would come to mind?) sponsor the CryptoSwift guy to do a java.security like Security standard framework (which includes TLS)? That would be pretty cool :-)

Instead: while in C, Security.framework, and CommonCrypto.framework from  are both fully open source, and battle-hardened.

Do they provide a clean Linux story too? (.framework in the name kinda suggests they don’t :-)

Do they work with non-blocking I/O? The API read/write/handshake API suggests that they may not?

Looks like the approach people currently use is either Security.framework on Darwin and Open/LibreSSL on other platforms, or using OpenSSL on both. Some even forking OpenSSL.

Good question. My assumption was “yes, of course”, but, it looks like that isn’t correct in the way I expected it to be.

CommonCrypto looks like it makes some assumptions about Darwin (e.g. importing TargetConditionals or Availability.h) but looking one level deeper, we find `corecrypto` at the bottom of Security Overview - Apple Developer that is also open source, is what underlies CommonCrypto + Security, and, has the necessary `#if`s to build on Linux (even if it is lacking a Makefile at the moment).

This is one of (rare) the cases where practicality and strongly deferring to the thing that already exists seem to be the safe option (and not only in opinion).

This is all true, but then someone also thought it makes sense to have Security.framework despite OpenSSL being available. Or java.security. Or Windows SChannel/security. Just saying …

The thing which makes a pure-Swift thing attractive is that it would be cross platform and readily available. The C libs are really diverse between the platforms and forking OpenSSL into an embedded module is not exactly 1337 either.

No disagreement that there are a number of benefits to living in a pure Swift world, but as mentioned earlier: this may not be possible yet. There is little point in providing a security/crypto library that can’t be trusted — and with cryptography, the requirement for trust extends far beyond “does it compile?, or even “do all the tests pass?”. We don’t want another heartbleed, or a predictable PRNG (https://github.com/g0tmi1k/debian-ssh\).

But, I don’t know. Maybe the solution isn’t corecrypto, but is LibreSSL/OpenSSL, or, something else. Maybe adding compiler support for Crypto tasks is already done (or easy enough to do) and my argument is moot. Thats why we’re having this discussion, right?

Anyway, (to me) the more interesting questions that we can talk about are over API:
- what constructs are needed (bignum? secure random? hmac? checksumming? key derivation? wrapping a socket in a big TLS hug?)

The thing I need and which is a little awkward to get is async TLS, both client and server. I started working on an OpenSSL BIO and see whether I can get that running on top of GCD, looks like it should be possible.

For the hashes that I needed so far (just MD5 and SHA1) I use CryptoSwift.

These seem like excellent use cases to consider, thank you for bringing them up! Reading through https://swift.org/server-apis/, the section on "Security and Encryption”, definitely indicates that this is the right place to talk about these needs.

-z

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-server-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20161107/6c3ead79/attachment-0001.html&gt;

------------------------------

Message: 4
Date: Mon, 7 Nov 2016 11:54:21 -0800
From: Brent Royal-Gordon <brent@architechies.com>
To: Matt DeFoor <mattdefoor@gmail.com>
Cc: swift-server-dev@swift.org
Subject: Re: [swift-server-dev] Crypto Library
Message-ID: <AD308EF0-7DBA-469D-BDD3-6F1189F38EAC@architechies.com>
Content-Type: text/plain; charset=utf-8

On Nov 7, 2016, at 7:49 AM, Matt DeFoor via swift-server-dev <swift-server-dev@swift.org> wrote:

Ultimately, I think we'll want to stick with the known crypto libraries and frameworks that are compliant with FIPS 140-2 Level 1 until a decision can be made around the need/desire for a pure-Swift implementation and sponsor(s) for obtaining the validation. There are going to come cases where some software or perhaps embedded hardware that use Swift for crypto purposes will require FIPS 140-2 Level 1 validation.

Then again, perhaps FIPS isn't a concern for people at all. If so, please disregard :)

I'm not familiar with the specifics of the FIPS requirements, but naïvely, this sounds like a good case for some abstraction. If we define general protocols for crypto modules and conform both Darwin security and LibreSSL APIs to them, you'll be able to switch between FIPS-compliant and open-source implementations without rewriting any code.

--
Brent Royal-Gordon
Architechies

------------------------------

Message: 5
Date: Tue, 8 Nov 2016 10:01:02 -0200
From: Thiago Holanda <unnamedd@gmail.com>
To: James Lei <proyb7@gmail.com>
Cc: swift-server-dev@swift.org
Subject: Re: [swift-server-dev] HTTP Parser
Message-ID:
  <CACDpt5VCsvbAe3i9sMqHa6AUW+gWfZ4khfL9vcS6LjRycQAA0w@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi James, the early adopters form Swift Server APIs will be the
stakeholders team or who want to test what the steering team develop.

TH

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20161108/c59c1cf7/attachment-0001.html&gt;

------------------------------

Message: 6
Date: Tue, 8 Nov 2016 15:45:50 +0000
From: Chris Bailey <BAILEYC@uk.ibm.com>
To: Bill Abt <babt@me.com>
Cc: Swift Server Dev <swift-server-dev@swift.org>
Subject: Re: [swift-server-dev] Crypto Library
Message-ID:
  <OFDEE7346B.4FB7B287-ON80258065.00541210-80258065.005697A9@notes.na.collabserv.com>
  
Content-Type: text/plain; charset="utf-8"

Whilst there's legitimate debate on the use of C vs. Swift for HTTP
parsing, I think the situation for the security libraries in general is
more clear.

We've effectively got four choices on how to do the underlying
implementation of the security APIs:
Use OpenSSL/LibreSSL everywhere
The challenge his is iOS devices, where there is no support for
OpenSSL/LibreSSL. There's likely also an argument that using
OpenSSL/LibreSSL will be a regressive move for macOS users vs. the Apple
libraries that have been optimized for the platform. Additionally there
may be a granularity issue - we'd the Apple libraries are deliberately
broken into three libraries and we'd need to reflect that from
OpenSSL/LibreSSL. I think that means we at least have to have a "hybrid"
model of using the Apple libraries on macOS/iOS, and OpenSSL/LibreSSL
elsewhere
Use the Apple security libraries everywhere
This three libraries are a significant body of work, and based on the
effort required to port libdispatch to Linux, I would estimate that a
considerable amount of porting work. There would then be secondary
challenges on how we respond to security vulnerabilities on the new
platforms, and the effort and cost of trying to get FIPS compliance for
the new libraries on each platforms
Use a hybrid of Apple security libraries on macOS/iOS and OpenSSL/LibreSSL
elsewhere
This leverages existing "defacto standard" libraries on each platform,
where things like FIPS compliance certification already exists, and teams
already have a track record of responding to security vulnerabilities.
There is a challenge though on how we isolate/abstract the user away from
the differences between the libraries - particularly for things like
certificate handling and configuration.
Create a pure-Swift implementation
The implementation of OpenSSL is ~350K lines of code, which is a sizeable
amount of function to implement, and most importantly, to get right and do
rigorous security vulnerability testing for. Once done, we will then have
to react rapidly to any reported vulnerabilities and do the full set of
work and cost to get FIPS compliance certification.

For me, this points to option #3 as the most viable solution - and
therefore the first that we should investigate.

Chris

From: Bill Abt via swift-server-dev <swift-server-dev@swift.org>
To: Swift Server Dev <swift-server-dev@swift.org>
Date: 07/11/2016 18:48
Subject: Re: [swift-server-dev] Crypto Library
Sent by: swift-server-dev-bounces@swift.org

We experimented with various different approaches when doing the lower
levels of Kitura. Ultimately, we chose to use CommonCrypto on macOS and
libcrypto (from OpenSSL) on Linux for the crypto portion. You can see the
implementation (which works on both macOS and Linux) at
https://github.com/IBM-Swift/BlueCryptor\. As far as the securing sockets,
we chose to go with Apple Secure Transport on macOS and OpenSSL on Linux.
This implementation can be found at
https://github.com/IBM-Swift/BlueSSLService\. The BlueCryptor package can
be used by virtually Swift application. The BlueSSLService, however, is
an add-on to and dependent on BlueSocket, the underlying network layer for
Kitura.

In my opinion, using the Security framework on macOS is fine but to get
the “beast” running on Linux may be very, very problematic. The
underlying codebase is massive and there are bits and pieces that are
missing and would have to be re-implemented. Another factor that led us
to not use the Security framework was relatively sparse documentation.
CommonCrypto is a much smaller subset as is Secure Transport and the
mapping between them and librcrypto and OpenSSL is much cleaner and
straight forward. Plus, as others have pointed out, an implementation
taking this approach doesn’t have to worry so much about FIPS
certification since the underlying platform implementation are already
certified.

On Nov 7, 2016, at 10:31 AM, Zach Drayer via swift-server-dev < > swift-server-dev@swift.org> wrote:

On Nov 7, 2016, at 2:45 PM, Helge Heß via swift-server-dev < > swift-server-dev@swift.org> wrote:

On 07 Nov 2016, at 13:48, Zach Drayer <zachary.drayer@gmail.com> wrote:
On Nov 7, 2016, at 11:20 AM, Helge Heß via swift-server-dev < > swift-server-dev@swift.org> wrote:
P.S.: As a sidenote, can’t someone (hm hm, who would come to mind?)
sponsor the CryptoSwift guy to do a java.security like Security standard
framework (which includes TLS)? That would be pretty cool :-)

Instead: while in C, Security.framework, and CommonCrypto.framework from
 are both fully open source, and battle-hardened.

Do they provide a clean Linux story too? (.framework in the name kinda
suggests they don’t :-)

Do they work with non-blocking I/O? The API read/write/handshake API
suggests that they may not?

Looks like the approach people currently use is either Security.framework
on Darwin and Open/LibreSSL on other platforms, or using OpenSSL on both.
Some even forking OpenSSL.

Good question. My assumption was “yes, of course”, but, it looks like that
isn’t correct in the way I expected it to be.

CommonCrypto looks like it makes some assumptions about Darwin (e.g.
importing TargetConditionals or Availability.h) but looking one level
deeper, we find `corecrypto` at the bottom of
Security Overview - Apple Developer that is also open source, is what
underlies CommonCrypto + Security, and, has the necessary `#if`s to build
on Linux (even if it is lacking a Makefile at the moment).

This is one of (rare) the cases where practicality and strongly deferring
to the thing that already exists seem to be the safe option (and not only
in opinion).

This is all true, but then someone also thought it makes sense to have
Security.framework despite OpenSSL being available. Or java.security. Or
Windows SChannel/security. Just saying …

The thing which makes a pure-Swift thing attractive is that it would be
cross platform and readily available. The C libs are really diverse
between the platforms and forking OpenSSL into an embedded module is not
exactly 1337 either.

No disagreement that there are a number of benefits to living in a pure
Swift world, but as mentioned earlier: this may not be possible yet. There
is little point in providing a security/crypto library that can’t be
trusted — and with cryptography, the requirement for trust extends far
beyond “does it compile?, or even “do all the tests pass?”. We don’t want
another heartbleed, or a predictable PRNG (
https://github.com/g0tmi1k/debian-ssh\).

But, I don’t know. Maybe the solution isn’t corecrypto, but is
LibreSSL/OpenSSL, or, something else. Maybe adding compiler support for
Crypto tasks is already done (or easy enough to do) and my argument is
moot. Thats why we’re having this discussion, right?

Anyway, (to me) the more interesting questions that we can talk about are
over API:
- what constructs are needed (bignum? secure random? hmac? checksumming?
key derivation? wrapping a socket in a big TLS hug?)

The thing I need and which is a little awkward to get is async TLS, both
client and server. I started working on an OpenSSL BIO and see whether I
can get that running on top of GCD, looks like it should be possible.

For the hashes that I needed so far (just MD5 and SHA1) I use CryptoSwift.

These seem like excellent use cases to consider, thank you for bringing
them up! Reading through https://swift.org/server-apis/, the section on
"Security and Encryption”, definitely indicates that this is the right
place to talk about these needs.

-z

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-server-dev
_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-server-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20161108/e4040bb6/attachment-0001.html&gt;

------------------------------

Message: 7
Date: Tue, 8 Nov 2016 17:55:15 +0100
From: Joannis Orlandos <joannis@orlandos.nl>
To: Swift Server Dev <swift-server-dev@swift.org>
Subject: Re: [swift-server-dev] Crypto Library
Message-ID: <D8F1F92A-039A-4404-8D2C-606D80DA651D@orlandos.nl>
Content-Type: text/plain; charset="utf-8"

On 8 Nov 2016, at 17:54, Joannis Orlandos <joannis@orlandos.nl> wrote:

I think option #3 is the most viable but you seem to partially overestimate the amount of work that you'd have to put into a Swift variant to OpenSSL. LibreSSL, which does not contain a lot of legacy code, is ~200K lines of code which is a lot less than your OpenSSL figures. And in Swift we can probably be a lot more expressive in our statements so I think 180K would be a feature complete SSL implementation.

I think the FIPS compliance certification is going to be the toughest part. The API for the cryptography will have to be designed regardless of point 3 and 4 which I think would result in 150k lines of code that will have to be written specifically for point 4. It's not exactly unthinkable to write Swift Cryptography. The Vapor framework already counts 60k lines of code which is build by two people primarily but I think it's probably not worth the effort/maintenance at this scale to build a pure swift SSL implementation, at least initially.

Joannis

On 8 Nov 2016, at 16:45, Chris Bailey via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>> wrote:

Whilst there's legitimate debate on the use of C vs. Swift for HTTP parsing, I think the situation for the security libraries in general is more clear.

We've effectively got four choices on how to do the underlying implementation of the security APIs:
Use OpenSSL/LibreSSL everywhere
The challenge his is iOS devices, where there is no support for OpenSSL/LibreSSL. There's likely also an argument that using OpenSSL/LibreSSL will be a regressive move for macOS users vs. the Apple libraries that have been optimized for the platform. Additionally there may be a granularity issue - we'd the Apple libraries are deliberately broken into three libraries and we'd need to reflect that from OpenSSL/LibreSSL. I think that means we at least have to have a "hybrid" model of using the Apple libraries on macOS/iOS, and OpenSSL/LibreSSL elsewhere
Use the Apple security libraries everywhere
This three libraries are a significant body of work, and based on the effort required to port libdispatch to Linux, I would estimate that a considerable amount of porting work. There would then be secondary challenges on how we respond to security vulnerabilities on the new platforms, and the effort and cost of trying to get FIPS compliance for the new libraries on each platforms
Use a hybrid of Apple security libraries on macOS/iOS and OpenSSL/LibreSSL elsewhere
This leverages existing "defacto standard" libraries on each platform, where things like FIPS compliance certification already exists, and teams already have a track record of responding to security vulnerabilities. There is a challenge though on how we isolate/abstract the user away from the differences between the libraries - particularly for things like certificate handling and configuration.
Create a pure-Swift implementation
The implementation of OpenSSL is ~350K lines of code, which is a sizeable amount of function to implement, and most importantly, to get right and do rigorous security vulnerability testing for. Once done, we will then have to react rapidly to any reported vulnerabilities and do the full set of work and cost to get FIPS compliance certification.

For me, this points to option #3 as the most viable solution - and therefore the first that we should investigate.

Chris

From: Bill Abt via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>>
To: Swift Server Dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>>
Date: 07/11/2016 18:48
Subject: Re: [swift-server-dev] Crypto Library
Sent by: swift-server-dev-bounces@swift.org <mailto:swift-server-dev-bounces@swift.org>

We experimented with various different approaches when doing the lower levels of Kitura. Ultimately, we chose to use CommonCrypto on macOS and libcrypto (from OpenSSL) on Linux for the crypto portion. You can see the implementation (which works on both macOS and Linux) at https://github.com/IBM-Swift/BlueCryptor\. As far as the securing sockets, we chose to go with Apple Secure Transport on macOS and OpenSSL on Linux. This implementation can be found at https://github.com/IBM-Swift/BlueSSLService\. The BlueCryptor package can be used by virtually Swift application. The BlueSSLService, however, is an add-on to and dependent on BlueSocket, the underlying network layer for Kitura.

In my opinion, using the Security framework on macOS is fine but to get the “beast” running on Linux may be very, very problematic. The underlying codebase is massive and there are bits and pieces that are missing and would have to be re-implemented. Another factor that led us to not use the Security framework was relatively sparse documentation. CommonCrypto is a much smaller subset as is Secure Transport and the mapping between them and librcrypto and OpenSSL is much cleaner and straight forward. Plus, as others have pointed out, an implementation taking this approach doesn’t have to worry so much about FIPS certification since the underlying platform implementation are already certified.

On Nov 7, 2016, at 10:31 AM, Zach Drayer via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>> wrote:

On Nov 7, 2016, at 2:45 PM, Helge Heß via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>> wrote:

On 07 Nov 2016, at 13:48, Zach Drayer <zachary.drayer@gmail.com <mailto:zachary.drayer@gmail.com>> wrote:
On Nov 7, 2016, at 11:20 AM, Helge Heß via swift-server-dev <swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>> wrote:
P.S.: As a sidenote, can’t someone (hm hm, who would come to mind?) sponsor the CryptoSwift guy to do a java.security like Security standard framework (which includes TLS)? That would be pretty cool :-)

Instead: while in C, Security.framework, and CommonCrypto.framework from  are both fully open source, and battle-hardened.

Do they provide a clean Linux story too? (.framework in the name kinda suggests they don’t :-)

Do they work with non-blocking I/O? The API read/write/handshake API suggests that they may not?

Looks like the approach people currently use is either Security.framework on Darwin and Open/LibreSSL on other platforms, or using OpenSSL on both. Some even forking OpenSSL.

Good question. My assumption was “yes, of course”, but, it looks like that isn’t correct in the way I expected it to be.

CommonCrypto looks like it makes some assumptions about Darwin (e.g. importing TargetConditionals or Availability.h) but looking one level deeper, we find `corecrypto` at the bottom of Security Overview - Apple Developer that is also open source, is what underlies CommonCrypto + Security, and, has the necessary `#if`s to build on Linux (even if it is lacking a Makefile at the moment).

This is one of (rare) the cases where practicality and strongly deferring to the thing that already exists seem to be the safe option (and not only in opinion).

This is all true, but then someone also thought it makes sense to have Security.framework despite OpenSSL being available. Or java.security. Or Windows SChannel/security. Just saying …

The thing which makes a pure-Swift thing attractive is that it would be cross platform and readily available. The C libs are really diverse between the platforms and forking OpenSSL into an embedded module is not exactly 1337 either.

No disagreement that there are a number of benefits to living in a pure Swift world, but as mentioned earlier: this may not be possible yet. There is little point in providing a security/crypto library that can’t be trusted — and with cryptography, the requirement for trust extends far beyond “does it compile?, or even “do all the tests pass?”. We don’t want another heartbleed, or a predictable PRNG (https://github.com/g0tmi1k/debian-ssh\).

But, I don’t know. Maybe the solution isn’t corecrypto, but is LibreSSL/OpenSSL, or, something else. Maybe adding compiler support for Crypto tasks is already done (or easy enough to do) and my argument is moot. Thats why we’re having this discussion, right?

Anyway, (to me) the more interesting questions that we can talk about are over API:
- what constructs are needed (bignum? secure random? hmac? checksumming? key derivation? wrapping a socket in a big TLS hug?)

The thing I need and which is a little awkward to get is async TLS, both client and server. I started working on an OpenSSL BIO and see whether I can get that running on top of GCD, looks like it should be possible.

For the hashes that I needed so far (just MD5 and SHA1) I use CryptoSwift.

These seem like excellent use cases to consider, thank you for bringing them up! Reading through https://swift.org/server-apis/, the section on "Security and Encryption”, definitely indicates that this is the right place to talk about these needs.

-z

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-server-dev
_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-server-dev

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org <mailto:swift-server-dev@swift.org>
https://lists.swift.org/mailman/listinfo/swift-server-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20161108/cefd512d/attachment-0001.html&gt;

------------------------------

_______________________________________________
swift-server-dev mailing list
swift-server-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-server-dev

End of swift-server-dev Digest, Vol 2, Issue 8
**********************************************