1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Moved the PureBasic version to OldSource/, Started the Rust rewrite in Source/

The rewrite's plan and decisions are in revamp.md. Steps 0 to 10 are done:
the workspace and checks, bakashrot-proto, bakashrot-pki and
bakashrot-cert, bakashrot-config, bakashrot-storage (schema v9), the
server and the client library (every request but replication's,
attachments and retention included), the C DLL with its C, PureBasic and
Python bindings, and the bakashrot tool. Step 11 (replication) is next.

OldSource/ is the old implementation, kept building and passing as the
reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RwFeVTGs2SsufaH6zquzcb
This commit is contained in:
2026-11-14 12:47:40 +01:00
parent d0048b17c8
commit e044fcf359
225 changed files with 21849 additions and 123 deletions
+135
View File
@@ -0,0 +1,135 @@
# Certificates
Who connects to whom, and how it's checked. The code is
`crates/bakashrot-pki` (the library) and `crates/bakashrot-tools`
(`bakashrot-cert`, the tool). Decided in `../../revamp.md`, "Decided".
## The idea
One CA per deployment. Every client and every server has a certificate
from it, saying who it is: a node's name and its roles. Servers trust the
CA, not lists of keys; clients trust the CA, not a server's key. Revoking
is a CRL file from the CA, pushed to the servers.
## Certificates
- **Keys:** ECDSA P-384, signatures SHA-384 (the strongest rustls checks).
- **The identity**, an extension of BakaShrot's own, non-critical (rustls
refuses critical extensions it doesn't know):
```
BakaShrotIdentity ::= SEQUENCE {
version INTEGER, -- 1
name UTF8String, -- the node: "kitchen"
roles SEQUENCE OF UTF8String -- free: "sensor", "peer"...
}
```
Names and roles follow the name rules (1-64 of `A-Z a-z 0-9 _ . -`, not
only digits), 64 roles at most. Roles mean nothing to the certificates:
the server's config says what each may do.
- **Its OID is a placeholder** (`IDENTITY_OID`, `1.3.6.1.4.1.32473.1.1`,
under the PEN RFC 5612 reserves for documentation; `bakashrot-cert`
warns while it is): it goes under NibblePoker's own PEN before
certificates are issued for real. Why, how to request it, what to change:
`oid.md`.
- **The CN is the name too**, for people (`openssl x509 -text`, logs). Only
the extension is trusted.
- **Clients' certificates** are for `clientAuth`. **Servers'** are for
`serverAuth` and `clientAuth` (a server is its peers' client), and have
one DNS name, `bakashrot-server` (`SERVER_NAME`): a label, not a host.
- **No host names or IPs:** a client connects to any address and asks for
`bakashrot-server`; rustls' own verifier then checks the server's
certificate is the CA's, valid, not revoked... and for servers. A
client's certificate can't pose as a server's: it isn't for `serverAuth`
and doesn't have the name.
- **Lifetimes:** the CA 10 years, the others 1 year, by default.
- **The CA's key stays off the servers:** whoever has it can make any
identity, peers included.
## TLS
`bakashrot_pki::tls`: TLS 1.3 only, through aws-lc, offering only the
strongest of everything (both ends are ours, nothing to negotiate down to):
- cipher suite `TLS13_AES_256_GCM_SHA384`;
- key exchange `X25519MLKEM768`, the X25519 + ML-KEM hybrid (holds against
quantum computers too);
- ALPN `bakashrot`: what isn't BakaShrot is refused in the handshake (the
protocol's version is checked right after, `protocol.md`);
- a certificate from the CA on both ends;
- randomness (keys, nonces) from the OS: aws-lc's generator seeded from
Windows' `ProcessPrng` or Linux's `getrandom`, plus RDRAND, as BoringSSL
and `ring` do. Built without its CPU Jitter Entropy
(`AWS_LC_SYS_NO_JITTER_ENTROPY`, `../.cargo/config.toml`), which only adds
a source and cost 25 ms in every process, at its first connection.
`server_config()` checks clients with rustls' verifier, `client_config()`
checks the server with rustls' verifier too (for `bakashrot-server`). Then
both check the certificate isn't revoked and has an identity. Once
connected, `peer_identity()` gives the other end's `Identity`.
## Revocation
- `bakashrot-cert revoke` writes `ca.crl`, signed by the CA, with every
certificate revoked before (written aside, then moved in place).
- A server reads it into `Revocations`, which its TLS setup shares
(`SharedRevocations`): replacing what's inside takes effect for the next
handshake, no new configuration needed. `Revocations::revokes()` tells
the server which open connections to drop.
- **Both ends check it:** `server_config()` and `client_config()` both take
the revocations (`Revocations::none()` without a CRL). A server dialing
its peer is the peer's client, with the same CRL: servers block each
other, whichever end dials.
- **Revoking is by certificate, not by name:** each certificate has its own
key and its own serial number (made from that key), so two of the same
name (two servers named alike, a new one before the old one goes) are
revoked one at a time.
- A CRL is only taken if it's the CA's: issued by it, its signature
checked. One that isn't is refused, the server keeps the previous one.
Its "next update" isn't held against it: CRLs are pushed by hand.
- The server watches the file (its time and size, every 5 s), reloads
it, and drops a revoked certificate's connection at its next request
(`server.md`).
## The tool
```
bakashrot-cert ca --name "Home CA" ca.crt, ca.key
bakashrot-cert issue --name kitchen --role sensor kitchen.crt, kitchen.key
bakashrot-cert issue --name server-1 --role peer --server
bakashrot-cert revoke kitchen.crt ca.crl
bakashrot-cert show kitchen.crt
```
`--ca` (the folder of `ca.crt` / `ca.key`, `.` by default), `--out` (where
to write), `--days`, `--file` (the files' name when it isn't the node's:
another certificate of the same name, `--file server-1b`). Files are PEM. Nothing is ever written over an
existing certificate or key; keys are readable by their owner only on
Unix. `revoke` only takes certificates the CA issued.
## Tests
- `bakashrot-pki/tests/tls.rs`: handshakes in memory. The strongest
settings negotiated, identities both ways, a server as its peer's
client; refused: a client or a server of another CA, a client's
certificate posing as a server's, a revoked client (and taken again once
the CRL changes, on the same configuration), a certificate without an
identity, another protocol; clients given the CRL refusing a revoked
server, servers blocking each other both ways, two servers of the same
name each with its own certificate, revoked one at a time.
- `bakashrot-pki/tests/ca.rs`: what certificates say, a CA's key that isn't
its own, CRLs revoking exactly what they list, another CA's or a
tampered CRL refused, and OpenSSL agreeing (`openssl verify` for clients
and servers, the CRL's signature, a revoked certificate; skipped without
OpenSSL, Git's is found).
- `bakashrot-tools/tests/cert.rs`: the tool end to end, two certificates
of the same name, and what it refuses (overwriting, bad names and roles,
another CA's certificate).
## For later
- **`AllowedServerNames`** in a client's config and for the peers a
server dials: the server names it accepts (any of the CA's servers
without it).
- NibblePoker's PEN, replacing the placeholder OID (`oid.md`).