2.11 Device Registry and Voucher Issuance: Exit Evidence
Evidence · Step: 2.11 Device Registry and Voucher Issuance
| Step | 2.11 Device Registry and Voucher Issuance |
| Date | 2026-11-16 |
| Database | PostgreSQL 18.6 (postgres:18-alpine) in Docker Desktop on Windows 11; postgres:18-alpine on GitHub’s ubuntu-latest in CI |
| Decision | ADR-0019 |
| Result | Passed; tier C only until attestation is verified; vectors published, firmware handover pending |
Deliverables
Section titled “Deliverables”| Deliverable | Where |
|---|---|
| Canonical encoders and signatures | crates/offline: encoding (protocol §3), crypto (P-256, low-S), Tier, DeviceCertificate, Voucher |
| Device registry | Migration 0011 (devices, offline_issuer_keys, offline_tier_limits); crates/engine/src/offline.rs: register_device, set_device_status |
| Voucher issuance | vouchers; issue_offline_voucher posts E16 with the issue_voucher.v1 template (crates/ops/src/offline.rs) and signs the voucher, in one transaction |
| API | POST /v1/offline/devices, GET …/{id}, POST …/{id}/revoke, POST /v1/offline/vouchers, GET …/{id}, GET /v1/offline/issuer-keys |
| Operator tools | mezgeb-cli offline key generate, tier, device, check; the offline runbook |
| Test vectors | test-vectors/offline/v1.json and its guide |
The work arrived in eight pull requests:
- the encoding, signatures and test vectors (#114);
- the schema (#115);
- the template (#116);
- the engine (#117);
- the API and its contract (#118);
- the CLI (#119);
- the documentation (#120);
- the Postman collection (#121).
One decision was made with the maintainer: attestation. No card chip
is chosen yet, and Android Key Attestation is not verified yet. So the API
accepts only none, which earns tier C, and refuses card and android as
attestation_unsupported. The engine and its tests cover all three tiers.
Implementation tasks
Section titled “Implementation tasks”| Task | Done |
|---|---|
devices table (id, owner account, tier, public key, attestation result, status active|frozen|revoked) |
Migration 0011. Also lost, from the protocol’s device states, and the signed certificate and next counter. The public key and its key ID are unique |
vouchers table |
Migration 0011. One escrow account and one E16 entry each, both unique. A partial unique index allows one open voucher per device |
issue_voucher.v1 template: a hold from the wallet into the device escrow, then a signed voucher |
The template books E16, Dr wallet / Cr a new 2050:vch-…, as the protocol specifies: the escrow is its own account, not a hold. It is engine-only, so clients cannot post it through /v1/operations. Then the voucher is signed, in the same transaction |
| Tier limits enforced (configured per tier) | offline_tier_limits, set with mezgeb-cli offline tier; a CHECK and the engine keep them at or below the maxima (2,000 / 1,000 / 200 ETB; 7 / 3 / 1 days). Also the 5,000 ETB per-customer cap |
revoke_device |
set_device_status, through POST …/revoke for the client and mezgeb-cli offline device for the operator, with the protocol’s transitions |
mezgeb-offline canonical encoders |
encoding.rs: tagged, length-prefixed, big-endian, no JSON |
The roadmap listed Ed25519; ADR-0019 decided P-256 for every device and
issuer signature, because card chips and phone keystores support it. The
ledger’s own receipts stay Ed25519. Key storage starts as a file
(MEZGEB_OFFLINE_ISSUER_KEY_FILE); step 3.12 evaluates an HSM.
Testing requirements
Section titled “Testing requirements”| Requirement | Test | Result |
|---|---|---|
| Issuing beyond the tier limit is rejected | issuing_beyond_the_tier_limit_is_refused (engine); the contract’s over_tier_limit |
Refused at the maximum + 1 santim; a lowered limit applies, a raised one is refused; tier C is off until enabled |
| Issuing for a frozen device is rejected | frozen_and_revoked_devices_get_no_voucher; the contract after revoke |
device_not_active; allowed again once unfrozen; revoked is final |
| Voucher signatures verify, and a single flipped bit fails | a_signature_verifies_and_one_bit_off_does_not (every bit position of a body and a signature); a_voucher_reserves_escrow_and_is_signed; the contract, with the published issuer key |
Every flip fails. High-S signatures and uncompressed keys are refused |
| Concurrent issuance cannot exceed the wallet balance | concurrent_issues_cannot_exceed_the_wallet_or_the_cap: 10 devices at once against 300 ETB |
Exactly 3 vouchers of 100; the wallet ends at 0 |
| Known-answer test vectors for the encoding, committed | test-vectors/offline/v1.json, checked by the_committed_vectors_match |
The file matches the code. Cross-checked with an independent implementation (Python cryptography): the keys, the signatures, the three refusals, and the voucher body rebuilt from its fields |
Also verified:
- The cap under concurrency.
concurrent_issues_respect_the_customer_cap: five cards of 2,000 ETB at once give exactly two vouchers. - Idempotency. A voucher retried with the same key, and new IDs, returns the same voucher and posts nothing.
- Isolation. Another client cannot see or move a device or a voucher (404).
- Privileges.
mezgeb_admincan unfreeze a device, as the CLI does.
The whole suite. On main after #120, cargo test --workspace against
PostgreSQL ran 41 test binaries and 322 tests, with 0 failures. CI ran the
same on every PR, plus the container and the Postman smoke collection.
Acceptance criteria
Section titled “Acceptance criteria”Escrow balance = SUM(unspent voucher value) at all times.
escrow_findings, run bymezgeb-cli offline check, compares every 2050 account with its voucher: the amount while the voucher is open, zero once it is returned or closed. It also flags money in a 2050 account with no voucher.- It is empty after every engine test, including both concurrency tests.
- It finds a stray escrow (
escrow_findings_catch_money_without_a_voucher). - Until receipts settle (step 2.12), a voucher’s unspent value is its amount.
Exit gate
Section titled “Exit gate”The test vectors are shared with the card and mobile firmware work. They are published in the repository with a guide for implementers:
- how to check an encoder, a verifier and a signer;
- the three cases a verifier must refuse.
No firmware team is engaged yet, as no card chip is chosen. Handing the vectors over is the first step when one is.
Found and fixed during the step
Section titled “Found and fixed during the step”- The engine named a template.
issue_voucher, as an engine function, broke the rule that the engine knows no template names; CI caught it. Renamedissue_offline_voucher. - A refused issue held the device lock. A refusal dropped its transaction without rolling back, so the device row stayed locked until the connection was reused. The pool hid it in the API; a test using two roles did not. Refusals now roll back at once.
The 2.10 exit gate
Section titled “The 2.10 exit gate”Step 2.10 asked for the external security review before step 2.11 builds device registration. The review has not happened. This step was built at the maintainer’s direction, within what does not depend on it:
- tier C only, with the lowest limits;
- tiers A and B stay off until attestation is verified and the review is done;
- no card is personalised.
Not done in this step
Section titled “Not done in this step”- Card and Android attestation: waits for a chip choice, and for Android Key Attestation chain verification.
- Receipts and settlement: step 2.12.
- Voucher expiry, grace, return and close: steps 2.12–2.13. Until then
vouchers stay
active. - The issuer key in a key service: step 3.12.
- Issuer key certificates signed by an offline root: the root key ceremony comes with the first real cards.
- The external security review: still requested.