BearSSL: A smaller SSL/TLS library
bearssl.org
bearssl.org
I think this alone is an excellent reason to study the code, but only after you've already had a mental exercise of considering how you could write such an implementation without any dynamic allocation. One of the things that I've noticed in a lot of codebases is superfluous dynamic allocation, which can often be eliminated to make things simpler, more efficient, and removes a possible error-path.
"We're good, everyone. Justine is on it."
Also, Bear is unlikely to do e.g. 0-RTT which might be a TLS 1.3 feature you really wanted unless you just "want it so badly" because it's a bigger number.
TLS has always been weak to a few classes of attacks (historically both MITM and replay attacks), but these developers are taking that weakness very seriously. Also, most HTTP requests are idempotent, which is going to be the use case of 99% of people.
The other two reasons they give are about abstractions that they defined for themselves. The idea of buffering 0-RTT requests is also kind of silly, and completely untenable if you want to avoid memory waste.
- Its sans-I/O design. Too many networking-related libraries out there mix the protocol state machine logic and the I/O. In doing so, they impose a certain style of I/O and make it impossible to integrate with an existing event loop, unless you’re willing to sacrifice scalability by spawning a thread+semaphore for each connection. I’d love it if I could use libssh2 or libmysqlclient’s state machine with io_uring or DPDK! Other TLS libraries do have stuff like memory BIOs, but they’re managed by the library and force an extra memory copy to get your data to its final destination.
- No mutable global state. The fact that all functions are fully reentrant means that it’s easily usable in an interruptible context, common in freestanding environments or runtimes with fibers/coroutines.
The tradeoff is that it lacks TLS 1.3 and DTLS support. The latter in particular is something I look forward to so that a QUIC state machine in C is possible.
TLS 1.3 isn't mentioned.
Smaller code helps prevent bugs, as there's simply less code where bugs could be.
Thus it is not as clear as you picture it.
What is clear, however, is that it should be easier to make BearSSL's code bug-free, by virtue of having less code.
Which makes it complicated.
In contrast BearSSL is kept simple, and is primarily the work of a single author, who knows a lot about cryptography
And Heartbleed bug was in the extension, not in the core software.
> (citation needed, btw)
Not really. But if you insist, OpenSSL is defacto crypto library [1] , at least on server side. Browsers and OpenSSL takes the most burden for securing every-day use of internet in the world. There are billions testers every day.
Sure, this is done all the time via verification and other formal methods. It's not common in the industry, but not entirely uncommon either.
CompCert [2] is a formally verified optimizing C compiler.
Most formal verification happens in compilers or low-level mission critical systems due to the cost.
If you want to write some formally verified C, you can check out Frama-C [3].
Using proofs just shifts the bugs into the assumptions/axioms (i.e you think your proof is proving X but it's actually proving Y)
It is not recommended to use for general parties, even Google does not recommend.
To quote: https://boringssl.googlesource.com/boringssl/
BoringSSL arose because Google used OpenSSL for many years in various ways and, over time, built up a large number of patches that were maintained while tracking upstream OpenSSL. As Google's product portfolio became more complex, more copies of OpenSSL sprung up and the effort involved in maintaining all these patches in multiple places was growing steadily.
Currently BoringSSL is the SSL library in Chrome/Chromium, Android (but it's not part of the NDK) and a number of other apps/programs.
Counterpoints:
> Encryption Implemented in the Google Front End for Google Cloud Services and Implemented in the BoringSSL Cryptographic Library
https://cloud.google.com/docs/security/encryption-in-transit
> We use a common cryptographic library, Tink, which includes our FIPS 140-2 validated module (named BoringCrypto) to implement encryption consistently across Google Cloud
https://cloud.google.com/docs/security/encryption/default-en...
> It may (or may not!) come as surprise, but a few months ago we migrated Cloudflare’s edge SSL connection termination stack to use BoringSSL: Google's crypto and SSL implementation that started as a fork of OpenSSL.
https://blog.cloudflare.com/make-ssl-boring-again/
> We ported our SMTP server to use BoringSSL, Cloudflare’s SSL/TLS implementation of choice
https://blog.cloudflare.com/email-routing-leaves-beta/
> We are pleased to announce the availability of s2n-quic, an open-source Rust implementation of the QUIC protocol added to our set of AWS encryption open-source libraries. <snip> AWS-LC is a general-purpose cryptographic library maintained by AWS which originated from the Google project BoringSSL.
https://aws.amazon.com/blogs/security/introducing-s2n-quic-o...
This last one is not 100% clear but I would imagine AWS dogfoods their own encryption libraries to build their internal cloud stack.
On the other hand, every bug in OpenSSL gets CVE mark and will end up into the news. It gives distorted view and comparison of the software quality between many projects.
I still can't comprehend how the industry didn't simply move to libressl early on.
BearSSL GHASH is still fast whilst secure, openssl AES not.
I looked at this two years ago, and it didn't have TLS 1.3 support, so I went with openssl and have replaced that with s2n (which uses bits of openssl under-the-hood) last year for some things.
The features page looks like TLS 1.3 still isn't supported, and the git changelog doesn't show much happening...
And/or you want specific functionality, like the lack of dynamic allocation.
Monoculture is a dangerous trap.
That said, I use MbedTLS for production work on embedded hardware because it just integrates better with the other bits and pieces of code, and often comes as part of the platform SDK itself or has been tested with the platform. This plays a big part in getting people to use it.
I really hope this one gets more attention though.