367 points · by ukj · 11y ago · 97 comments
OCaml TLS: ~4400 LoC
OCaml X509: ~1550 LoC
OCaml ASN1: ~1400 LoC
OCaml nocrypto: ~5250 LoC
Total ~12600 LoC but you get a fully self-contained implementation, having only some crypto code in C and the rest as pure OCaml:https://mirage.io/blog/why-ocaml-tls https://mirage.io/blog/announcing-mirage-25-release
At first I was really surprised/impressed/worried that they managed to pull off an ASN.1 parser in C along with TLS is just 6,000 lines of code. Alas, they did not.
So, when they mention the 500,000 lines of OpenSSL, they are probably actually using a good 20,000+ of it for ASN.1 and all of the ciphers.
Yay marketing!
However, he does not want to give it away.
ASN.1 is a rather hairy standard overall, but AFAIK only a part of it is needed for TLS.
We really like the idea of continuing the self-service security bounties, irrespective of their size. One of the nice things about unikernels is that it makes it easy to link in logic like this -- in a conventional OS, it would mean faffing around with kernel modules in order to safely seal the Bitcoins away, whereas here it's just normal high-level language code.
Incidentally, we're working on exposing a C interface to the OCaml TLS stack so that it can be used as a normal shared library as well. The approach is to use the OCaml Ctypes library (which is normally used to bind to C libraries from OCaml), but deploy it in inverted mode. This means that we expose a C ABI from OCaml code instead.
See https://github.com/yallop/ocaml-ctypes-inverted-stubs-exampl... for an example that exposes a C parsing interface to the OCaml XMLM library. The TLS stack isn't much more complex, but is pending us looking into libtls that are easier to expose than OpenSSL's. The s2n release here is thus nice and timely...
"[...] security bounties can be a very effective way to show the presence of vulnerabilities, but they are hopelessly inadequate for showing their absence."
No amount of prize money can ever really tell you how secure something is. We knew this before we announced it (see background at [1]).
I think the dream is there for many but as other comments have pointed out, getting to the battle tested level of OpenSSL is really really hard.
Where is the OCaml source / repo?
"Yo sn2, I'm really happy for you, Imma let you finish but Ocaml had one of the best TLS stacks of all time ... one of the best TLS stacks of all time!"
If you have a bunch of micro services that need to communicate with each other securely, client cert validation solves a big problem.
TLS is the right solution iff you need to communicate with third parties whom you can't securely share code or keys with in advance.
The fact that they are focusing on the TLS protocol itself and not the actual encryption implementation is a good way to start; the "extraneous complexity" is not really in algorithms like RSA/ECDSA/AES since those are specified mathematically, but in the handling of the protocol messages and states. That is also where most of the bugs tend to be.
It reminds me of this Hoare quote: "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."
My biggest issue with OpenSSL is that it also tries to do IO, but does it in a not too well-performing and non cross-platform way.
Looks like currently you must set a file descriptor (though the docs mention the possibility of using a pipe). Once an FD is set, you do control pulling/pushing data to s2n.
Can you elaborate more on "not too well-performing"?
Or any file in that directory.
I really thought OpenSSL was in a much better shape.
Both are bad, but I'd say that "remote root" trumps "side channel attack".
"Today s2n supports OpenSSL, LibreSSL, BoringSSL".
"Our pill has been clinically tested."
What were the results?
Anyone else think this was a contraction of the a11y, i18n, a16z or f6s variety?
sawn scan seen sewn shin shun sign skin soon sown span spin spun stun swan
"Yeh, we're not vulnerable, because we've been using the swan library"
Yeah, who would name a crypto implementation something stupid like "swan". Oh wait... https://en.wikipedia.org/wiki/Openswan
Woodchipper, Bad-scan, NSA has seen your secrets, Hands sewn together, Shin kicker, shunned2death, Sign fail, Skin flogger, Too soon, SownPwn, Span Wham, Spinning in place, Spun out of control, Stunned, Birdcatcher
N = number of https sites M = number of tls implementations