The verification edge: what makes verified-by mean something.
Nothing. node.cljc states the contract -- "verified-by is the set of
peer-ids whose signature was checked at the edge; the state machine must
never see an unverified signature" -- and the edge did this:
(let [sender (:sender msg)]
(n/message-received sender msg #{sender}))
:sender is a field the sending peer writes into its own message. So
verified-by was the attacker's claim about who the attacker was, and
Tendermint's identity guard (contains? verified-by (:from msg)) was a
tautology over two fields the same party controls. urd.crypto was required
by four namespaces and called from none.
Every Byzantine property this library proves was therefore conditional on an authenticated transport that did not exist. That is the hole this closes.
Not a layering preference -- a constraint. ClojureScript's Web Crypto is
promise-based, so Ed25519 verification returns a channel on that platform;
geheimnis gives both platforms the same channel-returning contract so that
one implementation works on each. A step is a pure function and cannot
await a channel, so verification has to happen where there is already an
async context: the network handler. The same reasoning puts konserve's async
API at the store seam.
This is why the protocol carries verified-by at all rather than passing
signatures inward. The seam was right; only the implementation was missing.
The canonical CBOR encoding of {:chain :from :topic :to :seq :msg} -- see
urd.wire for why a signature covers RFC 8949 bytes rather than a
Clojure-specific hash, and digest below for why each of those fields is in
there.
:chain is domain separation and is not optional. Without it a signature
produced on a testnet verifies on mainnet, two deployments that can reach each
other cross-contaminate, and a vote captured from one network replays into
another. The audit found no domain separation anywhere in the codebase; this
is where it goes, because this is the only place every message passes through.
Ed25519 signatures are 64 raw bytes and geheimnis hands them over as a byte
array. A byte array is not a wire format: kabel serialises messages as EDN,
and a Java byte[] prints as #object[[B 0x...], which no reader can read
back. The first authenticated run over websockets died with "No reader
function for tag object" and every peer silently failed to assemble.
So seal base64-encodes and unseal decodes. The envelope is plain EDN --
keywords, a uuid, a string -- which is the contract every other message in
this library already meets.
The unit tests did not catch this because they passed the envelope straight
from seal to unseal in one process, where a byte array is a perfectly good
value. a-sealed-envelope-survives-the-wire round-trips through the reader,
because that is the thing that was actually broken.
authenticator requires keys. Running without them requires passing
:none explicitly. There is no permissive default, because a permissive
default is precisely how the original hole survived: the machinery was
described, the check was absent, and every test passed.
The verification edge: what makes `verified-by` mean something.
## What was here before
Nothing. `node.cljc` states the contract -- "`verified-by` is the set of
peer-ids whose signature was checked at the edge; the state machine must
never see an unverified signature" -- and the edge did this:
(let [sender (:sender msg)]
(n/message-received sender msg #{sender}))
`:sender` is a field the sending peer writes into its own message. So
`verified-by` was the attacker's claim about who the attacker was, and
Tendermint's identity guard `(contains? verified-by (:from msg))` was a
tautology over two fields the same party controls. `urd.crypto` was required
by four namespaces and called from none.
Every Byzantine property this library proves was therefore conditional on an
authenticated transport that did not exist. That is the hole this closes.
## Why it lives at the edge and not in the state machine
Not a layering preference -- a constraint. ClojureScript's Web Crypto is
promise-based, so Ed25519 verification returns a channel on that platform;
`geheimnis` gives both platforms the same channel-returning contract so that
one implementation works on each. A `step` is a pure function and cannot
await a channel, so verification has to happen where there is already an
async context: the network handler. The same reasoning puts konserve's async
API at the store seam.
This is why the protocol carries `verified-by` at all rather than passing
signatures inward. The seam was right; only the implementation was missing.
## What is signed
The canonical CBOR encoding of `{:chain :from :topic :to :seq :msg}` -- see
`urd.wire` for why a signature covers RFC 8949 bytes rather than a
Clojure-specific hash, and `digest` below for why each of those fields is in
there.
`:chain` is domain separation and is not optional. Without it a signature
produced on a testnet verifies on mainnet, two deployments that can reach each
other cross-contaminate, and a vote captured from one network replays into
another. The audit found no domain separation anywhere in the codebase; this
is where it goes, because this is the only place every message passes through.
## Why the signature is a string on the wire
Ed25519 signatures are 64 raw bytes and `geheimnis` hands them over as a byte
array. A byte array is not a wire format: kabel serialises messages as EDN,
and a Java `byte[]` prints as `#object[[B 0x...]`, which no reader can read
back. The first authenticated run over websockets died with "No reader
function for tag object" and every peer silently failed to assemble.
So `seal` base64-encodes and `unseal` decodes. The envelope is plain EDN --
keywords, a uuid, a string -- which is the contract every other message in
this library already meets.
The unit tests did not catch this because they passed the envelope straight
from `seal` to `unseal` in one process, where a byte array is a perfectly good
value. `a-sealed-envelope-survives-the-wire` round-trips through the reader,
because that is the thing that was actually broken.
## Refusing is a choice you have to make
`authenticator` requires keys. Running without them requires passing
`:none` explicitly. There is no permissive default, because a permissive
default is precisely how the original hole survived: the machinery was
described, the check was absent, and every test passed.(authenticator config peer-id)(authenticator config peer-id backend)Build the verification edge.
config is either :none -- an explicit, deliberate opt-out for in-process
and simulated networks -- or a map. peer-id is who we are, used when the
config does not name us.
The map form:
:chain an identifier for this deployment. REQUIRED; see the namespace docstring on why a signature that does not name its network is a replay waiting to happen. :peer-id who we are :private-key 32-byte Ed25519 seed :public-keys {peer-id 32-byte-public-key} for everyone we will believe
Throws on a partial configuration. A node that cannot verify its peers should refuse to start, not start and trust them.
Build the verification edge.
`config` is either `:none` -- an explicit, deliberate opt-out for in-process
and simulated networks -- or a map. `peer-id` is who we are, used when the
config does not name us.
The map form:
:chain an identifier for this deployment. REQUIRED; see the
namespace docstring on why a signature that does not name its
network is a replay waiting to happen.
:peer-id who we are
:private-key 32-byte Ed25519 seed
:public-keys {peer-id 32-byte-public-key} for everyone we will believe
Throws on a partial configuration. A node that cannot verify its peers should
refuse to start, not start and trust them.(fresh? {:keys [highest seen] :or {highest -1 seen #{}}} sq)Is sq a sequence number we have not already accepted from this peer?
Is `sq` a sequence number we have not already accepted from this peer?
(generate-keypair)A fresh Ed25519 keypair. Returns a channel of {:public :private}.
Here rather than in urd.crypto because that namespace's ClojureScript
branch throws "not yet implemented" for every primitive, which makes it
unusable for the one platform this seam exists to support.
A fresh Ed25519 keypair. Returns a channel of `{:public :private}`.
Here rather than in `urd.crypto` because that namespace's ClojureScript
branch throws "not yet implemented" for every primitive, which makes it
unusable for the one platform this seam exists to support.(seal this msg ctx)Attach this node's identity, a fresh sequence number, and a signature.
ctx is {:topic t :to peer-or-nil} -- what the transport is about to do
with this message. Both are SIGNED, so neither can be changed in flight.
Returns a channel of the envelope to put on the wire.
Attach this node's identity, a fresh sequence number, and a signature.
`ctx` is `{:topic t :to peer-or-nil}` -- what the transport is about to do
with this message. Both are SIGNED, so neither can be changed in flight.
Returns a channel of the envelope to put on the wire.(unseal this envelope)Check the envelope. Returns a channel of {:from id :msg m :verified-by s}
when it is good, or of nil when it is not -- a message that fails is not an
error to report, it is a packet that never happened.
Three ways to fail: an unknown author, a signature that does not verify, and a sequence number this peer has already used. The last is STATEFUL, so an authenticator is not a value you can share between nodes.
Check the envelope. Returns a channel of `{:from id :msg m :verified-by s}`
when it is good, or of nil when it is not -- a message that fails is not an
error to report, it is a packet that never happened.
Three ways to fail: an unknown author, a signature that does not verify,
and a sequence number this peer has already used. The last is STATEFUL, so
an authenticator is not a value you can share between nodes.(remember {:keys [highest seen] :or {highest -1 seen #{}}} sq)Record sq as seen, discarding anything that has fallen out of the window.
Record `sq` as seen, discarding anything that has fallen out of the window.
How far out of order a message may arrive and still be accepted.
A SET of recent sequence numbers per peer, not a bitmap. A 64-bit bitmap is
the textbook implementation and is not portable here: ClojureScript's bit
operations are 32-bit, and this project has already paid for that once --
rng.cljc documents the day it lost to (bit-and 0xFFFFFFFF 0xFFFFFFFF)
being -1 under cljs. A set of at most 33 small numbers per peer costs
nothing and cannot be wrong on one platform only.
A window at all, rather than a strict >, because messages legitimately
arrive out of order: the simulator reorders deliberately and pubsub can too.
A strict monotonic check would drop honest traffic, which is a worse failure
than the replay it prevents.
How far out of order a message may arrive and still be accepted. A SET of recent sequence numbers per peer, not a bitmap. A 64-bit bitmap is the textbook implementation and is not portable here: ClojureScript's bit operations are 32-bit, and this project has already paid for that once -- `rng.cljc` documents the day it lost to `(bit-and 0xFFFFFFFF 0xFFFFFFFF)` being -1 under cljs. A set of at most 33 small numbers per peer costs nothing and cannot be wrong on one platform only. A window at all, rather than a strict `>`, because messages legitimately arrive out of order: the simulator reorders deliberately and pubsub can too. A strict monotonic check would drop honest traffic, which is a worse failure than the replay it prevents.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |