uNetworking / uSockets

Miniscule cross-platform eventing, networking & crypto for async applications
Apache License 2.0
1.29k stars 267 forks source link

BearSSL support? #149

Closed mrakh closed 2 years ago

mrakh commented 3 years ago

I think adding BearSSL as a supported SSL backend is a worthwhile consideration.

Some niceties of using BearSSL:

  1. Makes absolutely no allocations. This allows fine grained control over the placement of TLS context objects in memory.
  2. Allows tuning the sizes of the TLS send/receive buffers to one's needs. This can give significant memory savings.
  3. Uses a state machine model. TLS context objects take bytes in and spit bytes out, and the library leaves it up to you to forward those bytes to/from the sockets. This clean separation of concerns makes it easier to swap out the underlying network event loop to something like io_uring or F-Stack or whatever, in case you want to add those in the future.
  4. The *_buf()/*_ack() API also allows reading and writing directly from/into a context object's receive/send buffers, minimizing the number of necessary copies.

Some caveats of using BearSSL:

  1. The BearSSL API makes use of vtables for its crypto operations. This adds some undesired indirections. Compiling with LTO might help devirtualize some of the indirect calls, but that is just speculation.
  2. It does not yet support TLS v1.3. It does not yet support DTLS either, in case you are planning on expanding the scope of your uWebSockets project to support RTCDataChannel or WebTransport APIs.
  3. Since it doesn't touch I/O, it can't take advantage of kTLS out of the box. The API has the necessary facilities (via overriding the relevant vtables) to extract the IV/key/record number from the TLS context object, so you can configure kTLS on the socket manually. But handling kTLS yourself is not easy - I have tried this before, and gave up pretty quickly.
  4. It is, by its own admission, beta-quality software. That said, the library has been around for about 5 years, undergoes extensive testing, and is authored by a well respected cryptographer.
ghost commented 2 years ago

I'm not going to add it. e have boringssl which runs incredibly fast and supports quic