Part 15 of 20 in Tools we built and why. Previous: Why our Mojo libraries copy Python byte for byte · Next: mojo-cv: working with pictures as numbers
What this is about
The little padlock in your browser means the page came to you over TLS. TLS stands for Transport Layer Security. It does three jobs: it proves you are talking to the right server, it hides what you say from anyone listening, and it notices if someone changes the messages on the way.
mojo-tls is our implementation of TLS, written in Mojo. It runs as a client, which connects to servers, and as a server, which accepts connections. It has no OpenSSL and no outside C library. It is 16.7 thousand lines of Mojo.
This post explains TLS in plain words and says what the library does. It also says plainly that it is young and has not had an independent audit.
Why it matters
Every login, every payment and every private message you send over the web uses TLS. It is some of the most carefully reviewed code in the world, and it is also code where one mistake can leak secrets. So "we wrote our own" is a statement that needs a lot of care.
The practical gain is simple: a program that uses mojo-tls has no OpenSSL or other C library to install or link. Whether you should use it is a different question, and the answer is in the status section below.
How a secure connection starts
Here is what happens when you open a secure site, in plain steps.
- Hello. Your computer says hello and lists the ways it can encrypt. The server picks one.
- A shared secret. Both sides do a short calculation that ends with the same secret key. An eavesdropper who sees every message still cannot compute it. This is called a key exchange.
- Proof of who. The server sends a certificate. It is a signed statement that this key belongs to this website. Your computer checks the signature against a list of trusted certificate authorities.
- Encrypted talk. From now on, everything is scrambled with the shared key.
mojo-tls does all four. It speaks TLS 1.3 and TLS 1.2. It supports three TLS 1.3 cipher suites, key exchange with x25519, P-256, P-384 and x448, and certificates of the ECDSA and RSA kinds, with chain checking against the system roots or a PEM file. It also handles name and IP matching, session resumption and client certificates.
The core engines are sans-IO. That means bytes go in and bytes and events come out. You bring your own socket. A server wrapper, built on our event loop mojo-aio, handles TLS 1.3 and 1.2 on one port and picks certificates by the name the client asks for.
How it is checked
The README says the library speaks to openssl, Firefox, Chromium and Vivaldi, in both directions. It is also tested against outside test suites, tlsfuzzer and testssl. The README lists 11 cells of its matrix that are skipped, because those scripts start from handshakes that our server refuses by policy.
What it refuses, on purpose
Some old and weak options are refused with a fatal alert, and tested:
- TLS 1.1 and below, and SSL.
- TLS 1.2 CBC suites and RSA key exchange, which have no forward secrecy.
- A TLS 1.2 client that does not send the extended master secret.
- Renegotiation.
- 0-RTT early data. It is ignored and skipped, never decrypted.
What it is not
Not implemented: DTLS, QUIC, OCSP stapling, certificate revocation, FFDHE groups, compression and post-quantum groups.
Status, in plain words
The version is 0.1.2. It has been internally audited, with 14 findings written up in a release note. It has not been independently audited. The README tells you to read its Security section before you put it on the open internet. We say the same. If you need TLS for something that matters, use a library that has had years of outside review. Use ours to learn, to test, and for projects where you accept that risk.
How to do it, step by step
- Read the "What it is not" and "Security" sections of the README first.
- Install the package with
pixi add mojo-tls. The import name istls. From source, clone it, run itsscripts/deps.shto fetch the one dependency, mojo-aio, and compile with-Iflags. - Run the quickstart in the README. It sets up a server.
- Connect to it with
openssl s_clientand watch the handshake from a tool you trust.
Words you may not know
- TLS: the standard that keeps web traffic private.
- Certificate: a signed statement that a key belongs to a website.
- Key exchange: a way for two sides to agree on a secret in public.
- Cipher suite: a named set of methods used to scramble data.
- Handshake: the opening exchange of a secure connection.
- Forward secrecy: old messages stay private even if a key leaks later.
- Sans-IO: code that never touches the network itself. You feed it bytes.
- Audit: a review of code for security mistakes.
Try it
- Read the README at github.com/amarbaro/mojo-tls.
- See where it sits on the shelf at the Mojo libraries page.
- Run the quickstart on your own computer, only on your own computer, and watch it with
openssl s_client. - Read the release note of its internal audit and see what the 14 findings were.
Read next
- Why our Mojo libraries copy Python byte for byte: how we check parts that have a reference.
- mojo-cv: working with pictures as numbers: the next post in this series.

Comments
No comments yet.
Log in to comment.