Single C file TLS 1.2/1.3 implementation using tomcrypt
github.com
github.com
I don't mean to critique an honest effort here, if someone wants to make their own implementation that's great. But the world has enough cryptography that isn't secure by default, and I don't think backwards compatibility should be encouraged.
How's My SSL [1] is a good resource (ignore that it still uses SSL nomenclature instead of TLS). To give an example, whenever I have to set up a new Nginx instance with HTTPS these days I remove TLS 1.0/1.1 support and disable half or so of the available cipher suites letsencrypt gives you out of the box.
_____________________
Since you're talking about setting up a web server you can mostly get away with this, esp. since most people are on auto updating chrome, so it's not an issue. But try to configure your browser to be that restrictive and you'll get pretty annoyed very soon. I tried this about a year ago. Horrible experience.
edit: i also have security.ssl3.rsa_aes_256_sha disabled, so my only non forward secrecy cipher fallback is TLS_RSA_WITH_AES_128_CBC_SHA
[0] https://www.zdnet.com/article/chrome-edge-ie-firefox-and-saf...
It's embarassaing that Android didn't enable support for TLS 1.2 everywhere until 5.0 (lollipop), but that was released late 2014, and most of 4 _can_ use 1.2 if you use the right options when making your sockets. And most people stopped supporting anything before Android 4.
Not at all sure (rather unsure) that this is practically exposed, but defenses against these kinds of attacks are why you generally want well-tested well-understood TLS implementations.
A broader critique is that this one-file TLS state machine just delegates the gnarliest bits of TLS --- most importantly X.509 and ASN.1 --- to its library dependencies.
Depending on how much bandwidth the adversary can get to you, it may be practical to attack clients doing PFS because the adversary can stall them and then use your oracle to have you sign the "Yes I'm really me" message they otherwise could not make.
On the one hand, this problem doesn't make the code unsuitable for clients. On the other hand, this is not a subtle failure, this is specifically called out in the RFCs as something you need to do, so what else did they miss?
By the way people, this sort of thing is why we're always telling you that wildcard certs and having a hundred unrelated SANs in a cert are dangerous. A box labelled "Bob's toy IRC server" running this code and sharing keys with your production web server makes "Bob's toy IRC server" into a working oracle for that production web server.
A good example of that IMO is cJSON[1], it's a small self-contained single file implementation of a JSON reader and parser. It's easy to use, the code is pretty clean and easy to follow and I never ran into any obvious limitation. I very much recommend it.
There are also projects that are developed as multiple files but amalgamated into a single huge file before release. SQLite does that: https://sqlite.org/amalgamation.html
> Over 100 separate source files are concatenated into a single large files of C-code named "sqlite3.c" and called "the amalgamation". The amalgamation contains everything an application needs to embed SQLite. The amalgamation file is more than 220,000 lines long and over 7.5 megabytes in size (as of 2018-11-24).
> Combining all the code for SQLite into one big file makes SQLite easier to deploy — there is just one file to keep track of. And because all code is in a single translation unit, compilers can do better inter-procedure optimization resulting in machine code that is between 5% and 10% faster.
You can use includes to have "a single file to add to the project", and still split your code in smaller, readable files.
See https://github.com/jedisct1/libhydrogen for example. It's a single-file crypto library from an application perspective, but everything was not stored into a single, hard-to-navigate file.
#include "mycrypto.1.1.h"
Doesn't that have the same effect of being easy to include? The amalgamation may be better for the compiler but I'm not sure why.
But within a single object the compiler doesn't need to obey the ABI rule at all if that's faster.
Now, you obviously could imagine an object and more powerful linkers that had enough optimisation magic to produce the same output executable from the sixty object files, but just spitting out a single source code file is a LOT easier than making that optimisation work on every platform now and in the future.
The invocation above creates one object file for each C source file, as temporary files, (in a Unix system you can watch it do this with a suitably powerful syscall tracer, presumably something similar is possible on non-Unix systems but I don't know exactly how)
Then it links them and produces the output you've mistaken for an "object file", then it deletes the temporary files.
does this hold even when non-amalgated code uses `-flto` or equivalent flag?
Until one of the C/C++ package managers gets good and wins, this is the nicest alternative.
Note that people don't necessarily develop the libraries in one big file or don't have dependencies. Many newer libraries use a single C file as a distribution format.
The other nice thing about it is that if the code is small it can be more easily debugged and audited by humans. If it pulls in hundreds of thousands of lines of code, that can be a problem. Also, small code is a requirement on some projects because of speed or memory limitations.
The size of the code is independent of the number of files the code is in.
Eventually there will be a security vulnerability found and every app will be on some random version making it exploitable.
I think it's also people giving up on build systems and package managers.