in reviewhumanPR #368Auth

auth: hmac.bound.v1, so a signed message cannot be replayed to someone else as something else

hmac.v1 signs the message body alone. Whoever receives a signed message can put the same body and signature in a new envelope, under the original sender's name, addressed to anyone and labelled as any kind. It verifies.

Author

Status
In review
Opened on
Nov 14
Branch
auth-bound-envelope

Description

The pitch.

## The gap

`hmac.v1` signs the message body alone. Whoever receives a signed message can put the same body and signature in a new envelope, under the original sender's name, addressed to anyone and labelled as any kind. It verifies.

Reproduced on `main` (`6f9a7c0`) in `auction_replay_unbound`. The auctioneer sends its signed `auction_result` to every bidder. A losing bidder replays that body and signature to `bidder-late` as `auction_won` (`ev-43`). `bidder-late`, whose only bid was rejected, pays the auctioneer 900 cents (`ev-49`) and receives nothing. The auctioneer is paid twice for one item. Nothing was forged: the attacker only used what it was sent.

## Layer

`auth`. New plugin `hmac.bound.v1` in `src/nandatown/layers/auth.py`. It subclasses `HmacAuth`; `hmac.v1` and `plain.v1` are unchanged.

| Situation | hmac.v1 | hmac.bound.v1 |
|---|---|---|
| Signed body re-sent to another recipient as another kind | delivered | refused (`signature_invalid`, `delivery_failed`) |
| Untouched envelope handed to a recipient it does not name | delivered | refused |
| Any of message id, conversation, sender, recipient, kind or body changed | only a body change is caught | refused |
| Envelope missing a signed field, or with no signature | n/a | refused |
| Genuine message | delivered | delivered |
| Same envelope redelivered by the transport's duplicate fault | delivered | delivered |
| Cards and attestations | signed as before | signed as before |

## Core footprint

`TownAPI.send` and `Engine.deliver` call `sign_envelope` / `verify_envelope` only when the selected auth plugin defines them. Every other plugin takes the existing path, and a test pins that `hmac.v1` still signs the body alone.

## Scenarios

- `auction_replay`: the replay on `hmac.bound.v1`. Passes.
- `auction_replay_unbound`: the same agents on `hmac.v1`. Fails on purpose at `settlement` and `replay_refused`.

The validator runs the existing auction stages and adds `replay_attempted` and `replay_refused`. It does not pass a run with no replay in it, and it fails if a non-winner pays even when the replay was refused.

## Not in this PR

An exact copy of an envelope sent again to the same recipient is still delivered, the same as a transport duplicate. Recognising it stays with the agent, as `Buyer.handle_delivery` does. Refusing it in the auth layer would change how the duplicate fault behaves, so I left it out; I can follow up if you want it.

## Testing

`tests/test_auth_bound.py` (35 tests) covers the gap on `hmac.v1`, each signed field, the fail-closed cases, both scenarios with bundle verification, and the six stock scenarios on the new plugin. `pytest -q` passes on Python 3.12. Both scenarios run from the CLI and `nandatown verify` accepts both bundles. `scripts/check_distributions.py` and `tests/test_schema_sync.py` pass.

Try it

Open PR on GitHubView diff

Checkout locally

git fetch origin pull/368/head:pr-368
git checkout pr-368