mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Removed the PureBasic version, Fixed refused certificates seen as lost connections
OldSource/ is deleted, with its PB-MessagePack submodule: it stays in git
history (up to 68966a8). What of its notes still holds is in
Source/docs/known-issues.md (the threat model, the known limits, ideas
for later); the old Docker image's publishing notes are in revamp.md's
step 13, the wheel's and releases' in Source/README.md. The Rust tests
are now the one runner. readme.md describes the Rust version.
The server now closes gently after refusing a certificate (shutdown,
then reading until the client closes, 1 s at most): closing at once
reset the connection, which could beat TLS's alert to the client
(ConnectionLost instead of AuthRejected, 14 of 160 runs under load).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-2
@@ -15,7 +15,7 @@ Source/
|
||||
check.ps1 what CI runs: fmt, clippy, tests, docs
|
||||
release.py a release for this platform: build, package, smoke test
|
||||
docs/ designs across crates: protocol.md, certificates.md, oid.md, config.md,
|
||||
storage.md, server.md, client.md
|
||||
storage.md, server.md, client.md, known-issues.md
|
||||
crates/
|
||||
bakashrot-proto/ packets, frames, names, limits, error codes, shared by everything
|
||||
bakashrot-pki/ certificates: issuing, identities, CRLs, the TLS setup
|
||||
@@ -27,7 +27,7 @@ Source/
|
||||
bakashrot-tools/ the CLI tools: bakashrot (push, read, query, list), bakashrot-cert
|
||||
bindings/
|
||||
c/ bakashrot.h, generated from bakashrot-capi
|
||||
purebasic/ the prototypes and error codes, as OldSource/Client/'s
|
||||
purebasic/ the prototypes and error codes, as the PureBasic version's
|
||||
python/ bakashrot.py over the DLL, check_bakashrot.py, make_wheel.py
|
||||
.cargo/config.toml the C runtime linked statically on Windows
|
||||
tests/ (13) end-to-end suites across processes
|
||||
@@ -66,6 +66,15 @@ Linux one in a manylinux 2.28 container, so it runs with glibc 2.28 and
|
||||
later. The version is the workspace's (`Cargo.toml`), and
|
||||
`bindings/python/bakashrot.py`'s `__version__` must be the same.
|
||||
|
||||
Publishing, as the old version did:
|
||||
|
||||
- **The wheel** to Gitea's registry, with twine 6.1+ (for the license
|
||||
metadata) and a token with `write:package`:
|
||||
`twine upload --repository-url https://git.nibblepoker.lu/api/packages/aziascreations/pypi -u aziascreations <wheel>`.
|
||||
- **On GitHub** (no Python registry), the archives and the wheels on a
|
||||
release: `gh release create v<version> --repo aziascreations/BakaShrot --title <version> <files>`
|
||||
(`gh release upload` for one that exists).
|
||||
|
||||
## Conventions
|
||||
|
||||
- LF line endings (`.gitattributes`), rustfmt's defaults.
|
||||
@@ -76,3 +85,5 @@ later. The version is the workspace's (`Cargo.toml`), and
|
||||
- Use existing crates rather than reimplementing (MessagePack is `rmp-serde`).
|
||||
- Protocol changes update `docs/protocol.md`; error codes are never
|
||||
renumbered, packet ids never reused.
|
||||
- `OldSource/` paths in comments and docs: the PureBasic version, removed
|
||||
2026-11-15, in git history up to commit `68966a8`.
|
||||
|
||||
@@ -121,17 +121,34 @@ async fn serve(shared: &Arc<Shared>, tcp: TcpStream, address: IpAddr) -> Result<
|
||||
}
|
||||
}
|
||||
|
||||
/// After a refused handshake (its alert sent): a close the client reads,
|
||||
/// not a reset that can beat the alert to it. In TLS 1.3 the client has
|
||||
/// already sent its version when the server refuses its certificate, and
|
||||
/// a socket closed with data unread is reset (Windows drops what the
|
||||
/// client hadn't read yet then). So: shut down, and read until the client
|
||||
/// closes, 1 s at most.
|
||||
async fn close_gently(mut tcp: TcpStream) {
|
||||
let _ = tcp.shutdown().await;
|
||||
let mut unread = [0; 1024];
|
||||
let _ = timeout(Duration::from_secs(1), async {
|
||||
while tcp.read(&mut unread).await.is_ok_and(|read| read > 0) {}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// TLS, the versions, the identity, the welcome (or the refusal).
|
||||
async fn open(
|
||||
shared: &Arc<Shared>,
|
||||
tcp: TcpStream,
|
||||
address: IpAddr,
|
||||
) -> Result<(Frames, Peer), String> {
|
||||
let mut stream = shared
|
||||
.acceptor
|
||||
.accept(tcp)
|
||||
.await
|
||||
.map_err(|error| format!("TLS: {error}"))?;
|
||||
let mut stream = match shared.acceptor.accept(tcp).into_fallible().await {
|
||||
Ok(stream) => stream,
|
||||
Err((error, tcp)) => {
|
||||
close_gently(tcp).await;
|
||||
return Err(format!("TLS: {error}"));
|
||||
}
|
||||
};
|
||||
|
||||
stream
|
||||
.write_all(&frame::version_bytes())
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# Known issues and ideas
|
||||
|
||||
What's still true of the PureBasic version's notes, for this one. That
|
||||
version was removed on 2026-11-15; it's in git history up to commit
|
||||
`68966a8` (`OldSource/Notes.md`, "Open items"; `OldSource/Design/`).
|
||||
|
||||
## Threat model
|
||||
|
||||
BakaShrot is an **internal tool, on trusted machines and a trusted
|
||||
network**, not exposed to the internet. So:
|
||||
|
||||
- TLS and the certificates are defence in depth: they stop a misconfigured
|
||||
client or server from talking to the wrong one and keep data off the
|
||||
wire in clear, they aren't holding off attackers.
|
||||
- The security issues below are low priority unless the deployment
|
||||
changes. If it ever faces an untrusted network, start with messages
|
||||
signed by their origin and rate limiting connections.
|
||||
- Correctness, durability and operations matter more: losing or mixing up
|
||||
data, or a server that can't run unattended, hurts on day one.
|
||||
|
||||
## Known issues
|
||||
|
||||
- **One server per node, not checked.** A node's messages are pushed to
|
||||
one server; the others get them by replication. A node pushing to two
|
||||
servers that replicate makes the same ids with different messages on
|
||||
each: only the last id per topic and node is compared, so it's never
|
||||
noticed, and a replicated id already stored keeps the local message.
|
||||
Fix if that rule ever has to go: one server owns each topic and node's
|
||||
ids (the others refuse or forward pushes), or at least compare a hash of
|
||||
the messages to log the drift.
|
||||
- **Gaps in a topic and node's ids aren't detected** on replication (old
|
||||
item 6). A server with `1, 2, 5` says 5 and never gets 3 and 4. Batches
|
||||
are sent in order and a refusal stops them, so it needs something
|
||||
unusual, but nothing repairs it. Fix: send the count with the last id
|
||||
(count = last id: no gaps), compare ranges when they differ.
|
||||
- **The attachments a server lacks:** it reports the 256 oldest at a
|
||||
time (`SyncState`). With several peers, ones none of them has can hold
|
||||
back newer ones.
|
||||
- **Peers are trusted with what they replicate** (old item 12): a server
|
||||
in `accept_from` can send any message its roles accept, for any node.
|
||||
Messages carry no proof of who first wrote them. Fix: sign each message
|
||||
with its node's key when first stored, check it on replication (every
|
||||
server then needs every node's public key).
|
||||
- **Private keys sit in PEM files**, readable by whoever can read them: on
|
||||
trusted machines, file permissions are enough.
|
||||
- **One connection per process in the DLL** (old item 10, `revamp.md`,
|
||||
"Open questions"): a handle-based API for several. Polling rather than
|
||||
pushed subscriptions; nothing reconnects by itself, on purpose.
|
||||
- **At least once:** a push whose answer was lost (the server stopped
|
||||
between committing and answering) is stored twice if retried. A client
|
||||
that minds reads the latest message before retrying.
|
||||
|
||||
## Ideas for later
|
||||
|
||||
From the old benchmarks and suggestions (`OldSource/Design/Suggestions.md`),
|
||||
worth it only when a use calls for them:
|
||||
|
||||
- **Several pushes in flight per connection.** One request at a time
|
||||
(`protocol.md`, "Rules") caps a node at one push per round trip:
|
||||
thousands a second on a LAN, about 20 over 50 ms. A client could send
|
||||
several before the first answer (answers come back in order; a request
|
||||
id to match them), with an asynchronous push in the DLL beside the
|
||||
blocking one. The server already groups pushes from every connection.
|
||||
- **Replication, lower lag:** a link checks in again at once after
|
||||
sending, otherwise every `sync_interval`. Next, cheapest first: check
|
||||
in as soon as the writer commits something (at most every 100 ms or so);
|
||||
send several batches before the first answer (the receiver must then
|
||||
refuse a batch that doesn't follow its last id, which also closes the
|
||||
gaps above); several connections per link, each topic and node always
|
||||
on the same one.
|
||||
- **Benchmark on two machines:** on one, the load generator and the
|
||||
servers compete for the CPU and the disk.
|
||||
- **A JSON field queried often:** a generated column with an index on it
|
||||
turns a full scan into a lookup (`storage.md`, "For later", has the
|
||||
other storage ideas).
|
||||
@@ -118,14 +118,18 @@ otherwise started over (`DataMismatch`). A stop between its last part
|
||||
and the check: started over at the next start.
|
||||
|
||||
**One server per node** stays the config's rule, as in the old version
|
||||
(`OldSource/Design/ReplicationIssues.md` #1): a node pushing to two
|
||||
servers that replicate makes the same ids with different messages,
|
||||
undetected.
|
||||
(`known-issues.md`): a node pushing to two servers that replicate makes
|
||||
the same ids with different messages, undetected.
|
||||
|
||||
## A connection
|
||||
|
||||
1. **TLS:** the client's certificate must be the CA's, valid, not revoked,
|
||||
with an identity (`certificates.md`).
|
||||
with an identity (`certificates.md`). A refused one gets TLS's alert,
|
||||
then a gentle close: the server shuts down and reads until the client
|
||||
closes (1 s at most). Closing at once reset the connection (the
|
||||
client's version bytes unread), which could beat the alert to the
|
||||
client: `ConnectionLost` instead of `AuthRejected`, about 1 in 10 under
|
||||
load on Windows.
|
||||
2. **The versions:** each end sends its own; different ones, the
|
||||
connection is dropped (the client says `VersionMismatch`).
|
||||
3. **The roles:** none of the certificate's roles in the config, the
|
||||
|
||||
Reference in New Issue
Block a user