<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 8 Nov 2016, at 17:54, Joannis Orlandos &lt;<a href="mailto:joannis@orlandos.nl" class="">joannis@orlandos.nl</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">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.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Joannis</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 8 Nov 2016, at 16:45, Chris Bailey via swift-server-dev &lt;<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><font size="2" face="sans-serif" class="">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.</font>
<br class="">
<br class=""><font size="2" face="sans-serif" class="">We've effectively got four choices on
how to do the underlying implementation of the security APIs:</font>
<ol class="">
<li value="1" class=""><font size="2" face="sans-serif" class="">Use OpenSSL/LibreSSL everywhere<br class="">
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</font>
</li><li value="2" class=""><font size="2" face="sans-serif" class="">Use the Apple security libraries
everywhere<br class="">
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</font>
</li><li value="3" class=""><font size="2" face="sans-serif" class="">Use a hybrid of Apple security
libraries on macOS/iOS and OpenSSL/LibreSSL elsewhere<br class="">
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.</font>
</li><li value="4" class=""><font size="2" face="sans-serif" class="">Create a pure-Swift implementation<br class="">
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. </font></li></ol>
<br class=""><font size="2" face="sans-serif" class="">For me, this points to option #3 as
the most viable solution - and therefore the first that we should investigate.</font>
<br class="">
<br class="">
<br class=""><font size="2" face="sans-serif" class="">Chris<br class="">
</font>
<br class="">
<br class="">
<br class="">
<br class=""><font size="1" color="#5f5f5f" face="sans-serif" class="">From: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size="1" face="sans-serif" class="">Bill Abt via swift-server-dev
&lt;<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>&gt;</font>
<br class=""><font size="1" color="#5f5f5f" face="sans-serif" class="">To: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size="1" face="sans-serif" class="">Swift Server Dev &lt;<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>&gt;</font>
<br class=""><font size="1" color="#5f5f5f" face="sans-serif" class="">Date: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size="1" face="sans-serif" class="">07/11/2016 18:48</font>
<br class=""><font size="1" color="#5f5f5f" face="sans-serif" class="">Subject: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size="1" face="sans-serif" class="">Re: [swift-server-dev]
Crypto Library</font>
<br class=""><font size="1" color="#5f5f5f" face="sans-serif" class="">Sent by: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size="1" face="sans-serif" class=""><a href="mailto:swift-server-dev-bounces@swift.org" class="">swift-server-dev-bounces@swift.org</a></font>
<br class="">
<hr noshade="" class="">
<br class="">
<br class="">
<br class=""><font size="3" class="">We experimented with various different approaches when
doing the lower levels of Kitura. &nbsp;Ultimately, we chose to use CommonCrypto
on macOS and libcrypto (from OpenSSL) on Linux for the crypto portion.
&nbsp;You can see the implementation (which works on both macOS and Linux)
at </font><a href="https://github.com/IBM-Swift/BlueCryptor" class=""><font size="3" color="blue" class=""><u class="">https://github.com/IBM-Swift/BlueCryptor</u></font></a><font size="3" class="">.
&nbsp;As far as the securing sockets, we chose to go with Apple Secure
Transport on macOS and OpenSSL on Linux. &nbsp;This implementation can
be found at </font><a href="https://github.com/IBM-Swift/BlueSSLService" class=""><font size="3" color="blue" class=""><u class="">https://github.com/IBM-Swift/BlueSSLService</u></font></a><font size="3" class="">.
&nbsp;The BlueCryptor package can be used by virtually Swift application.
&nbsp;The BlueSSLService, however, is an add-on to and dependent on BlueSocket,
the underlying network layer for Kitura.</font>
<br class="">
<br class=""><font size="3" class="">In my opinion, using the Security framework on macOS is
fine but to get the “beast” running on Linux may be very, very problematic.
&nbsp;The underlying codebase is massive and there are bits and pieces
that are missing and would have to be re-implemented. &nbsp;Another factor
that led us to not use the Security framework was relatively sparse documentation.
&nbsp;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. &nbsp;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.</font>
<br class="">
<br class=""><font size="3" class="">On Nov 7, 2016, at 10:31 AM, Zach Drayer via swift-server-dev
&lt;</font><a href="mailto:swift-server-dev@swift.org" class=""><font size="3" color="blue" class=""><u class="">swift-server-dev@swift.org</u></font></a><font size="3" class="">&gt;
wrote:</font>
<br class="">
<br class="">
<br class=""><font size="3" class="">On Nov 7, 2016, at 2:45 PM, Helge Heß via swift-server-dev
&lt;</font><a href="mailto:swift-server-dev@swift.org" class=""><font size="3" color="blue" class=""><u class="">swift-server-dev@swift.org</u></font></a><font size="3" class="">&gt;
wrote:</font>
<br class="">
<br class=""><font size="3" class="">On 07 Nov 2016, at 13:48, Zach Drayer &lt;</font><a href="mailto:zachary.drayer@gmail.com" class=""><font size="3" color="blue" class=""><u class="">zachary.drayer@gmail.com</u></font></a><font size="3" class="">&gt;
wrote:</font>
<br class=""><font size="3" class="">On Nov 7, 2016, at 11:20 AM, Helge Heß via swift-server-dev
&lt;</font><a href="mailto:swift-server-dev@swift.org" class=""><font size="3" color="blue" class=""><u class="">swift-server-dev@swift.org</u></font></a><font size="3" class="">&gt;
wrote:</font>
<br class=""><font size="3" class="">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 :-)</font>
<br class="">
<br class=""><font size="3" class="">Instead: while in C, Security.framework, and CommonCrypto.framework
from  are both fully open source, and battle-hardened.</font>
<br class=""><font size="3" class=""><br class="">
Do they provide a clean Linux story too? (.framework in the name kinda
suggests they don’t :-)<br class="">
<br class="">
Do they work with non-blocking I/O? The API read/write/handshake API suggests
that they may not?<br class="">
<br class="">
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.</font>
<br class="">
<br class=""><font size="3" class="">Good question. My assumption was “yes, of course”, but,
it looks like that isn’t correct in the way I expected it to be.</font>
<br class="">
<br class=""><font size="3" class="">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 </font><a href="https://developer.apple.com/security/" class=""><font size="3" color="blue" class=""><u class="">https://developer.apple.com/security/</u></font></a><font size="3" class="">
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).</font>
<br class="">
<br class=""><font size="3" class="">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).</font>
<br class=""><font size="3" class=""><br class="">
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 …<br class="">
<br class="">
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.</font>
<br class="">
<br class=""><font size="3" class="">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 (</font><a href="https://github.com/g0tmi1k/debian-ssh" class=""><font size="3" color="blue" class=""><u class="">https://github.com/g0tmi1k/debian-ssh</u></font></a><font size="3" class="">).</font>
<br class="">
<br class=""><font size="3" class="">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?</font>
<br class="">
<br class=""><font size="3" class="">Anyway, (to me) the more interesting questions that we
can talk about are over API:<br class="">
- what constructs are needed (bignum? secure random? hmac? checksumming?
key derivation? wrapping a socket in a big TLS hug?)</font>
<br class=""><font size="3" class=""><br class="">
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.<br class="">
<br class="">
For the hashes that I needed so far (just MD5 and SHA1) I use CryptoSwift.</font>
<br class="">
<br class=""><font size="3" class="">These seem like excellent use cases to consider, thank
you for bringing them up! Reading through </font><a href="https://swift.org/server-apis/" class=""><font size="3" color="blue" class=""><u class="">https://swift.org/server-apis/</u></font></a><font size="3" class="">,
the section on "Security and Encryption”, definitely indicates that
this is the right place to talk about these needs.</font>
<br class="">
<br class=""><font size="3" class="">-z</font>
<br class="">
<br class=""><font size="3" class="">_______________________________________________<br class="">
swift-server-dev mailing list</font><font size="3" color="blue" class=""><u class=""><br class="">
</u></font><a href="mailto:swift-server-dev@swift.org" class=""><font size="3" color="blue" class=""><u class="">swift-server-dev@swift.org</u></font></a><font size="3" class=""><br class="">
</font><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class=""><font size="3" class="">https://lists.swift.org/mailman/listinfo/swift-server-dev</font></a>
<br class=""><tt class=""><font size="2" class="">_______________________________________________<br class="">
swift-server-dev mailing list<br class="">
<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a><br class="">
</font></tt><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class=""><tt class=""><font size="2" class="">https://lists.swift.org/mailman/listinfo/swift-server-dev</font></tt></a><tt class=""><font size="2" class=""><br class="">
</font></tt>
<br class="">
<br class="">
_______________________________________________<br class="">swift-server-dev mailing list<br class=""><a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-server-dev" class="">https://lists.swift.org/mailman/listinfo/swift-server-dev</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>