Skip to content

status: the device's public key and its fingerprint - #46

Merged
keyldev merged 3 commits into
masterfrom
feat/key-fingerprint
Oct 28, 2026
Merged

keyldev merged 3 commits into
masterfrom
feat/key-fingerprint

Conversation

@keyldev

@keyldev keyldev commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

cerberus status now prints two more lines:

public key     HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=
fingerprint    9946 8313 5dcd 688b cf07 0f57 1e50 618f

The fingerprint is SHA-256 of the 32 raw key bytes, the first 16 in lowercase hex, eight groups of four. The cloud's panel shows the same line on the device page ("Details"), so the owner can compare the two by eye and see that the cloud knows the camera by its own key rather than a substituted one. No prefix or salt on purpose: echo <key> | base64 -d | sha256sum checks it by hand. The suite pins the same vector as the coordinator's tests.

Why the public key is stored. status must not need randomness (there is a test for it), and deriving the public key does: mbedTLS 3 wants an RNG for X25519 blinding. So the agent keeps the public half in the store as cerberus_device_pubkey, written the first time it is derived and never again unless the key changes — one flash write per camera. Until a camera on an older agent restarts, status says - (known after the next start). clean and the installer remove the key.

Version 0.3.2, CHANGELOG and the three READMEs updated.

Tests: tests/run.sh 184 passed on Alpine (musl, mbedTLS 3); 182 passed, 1 skipped on Debian bookworm (glibc, mbedTLS 2.28).

`cerberus status` prints the public key and its fingerprint: SHA-256
of the 32 raw key bytes, the first 16 in lowercase hex, eight groups of
four. The cloud's panel shows the same line on the device page, so the
two can be compared by eye; `echo <key> | base64 -d | sha256sum`
checks it by hand. The suite pins the vector the coordinator's tests
pin too.

status must not need randomness and deriving the public key does (X25519
blinding), so the agent keeps the public half in the store as
cerberus_device_pubkey: written the first time it is derived, never
again unless the key changes. A key from an older agent shows "known
after the next start" until then. clean and the installer remove it.

Version 0.3.2.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Show device public key and fingerprint in status

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Show the device public key and cloud-compatible fingerprint so owners can compare identities.
• Cache the public key after derivation so status needs no randomness or additional flash writes.
• Cover fingerprint formatting and older keys; document the behavior and bump the version to 0.3.2.
Diagram

graph TD
  derive["Key derivation"] --> store[("Key store")] --> status["Status command"] --> hash["SHA-256 formatting"] --> output["Key and fingerprint"]
  status -->|missing public key| legacy["Legacy key notice"]
Loading
High-Level Assessment

Persisting the public key during normal derivation is appropriate because status must remain usable without randomness, while the public key itself must be displayed. Deriving it during status would violate that constraint; persisting only a fingerprint would not provide the requested public-key output.

Files changed (7) +65 / -7

Enhancement (2) +40 / -4
install.shRemove the cached public key during uninstall +1/-1

Remove the cached public key during uninstall

• Includes device_pubkey in the stored-key list cleared by the installer's uninstall path.

install.sh

cerberus.cPersist and display the device public key and fingerprint +39/-3

Persist and display the device public key and fingerprint

• Bumps the version to 0.3.2, stores the derived public key only when absent or changed, and adds SHA-256 fingerprint formatting to status without deriving a key there. Status reports when an older stored key has no cached public half, and clean removes the new store entry.

src/cerberus.c

Tests (1) +14 / -0
suite.shVerify fingerprint output and legacy-key behavior +14/-0

Verify fingerprint output and legacy-key behavior

• Checks status against the generated public key, an independently calculated hash, and the coordinator's pinned fingerprint vector. Also verifies that status does not derive or store a missing public key for an older installation.

tests/suite.sh

Documentation (4) +11 / -3
CHANGELOG.mdRecord the 0.3.2 identity-display release +8/-0

Record the 0.3.2 identity-display release

• Documents the new status fields, fingerprint definition, and reason for persisting the public key.

CHANGELOG.md

README.mdMention the fingerprint in the status command reference +1/-1

Mention the fingerprint in the status command reference

• Updates the English command list to include the key fingerprint among the information shown by status.

README.md

README.ru.mdUpdate the Russian status command reference +1/-1

Update the Russian status command reference

• Adds the key fingerprint to the Russian description of status output.

README.ru.md

README.zh-CN.mdUpdate the Chinese status command reference +1/-1

Update the Chinese status command reference

• Adds the key fingerprint to the Chinese description of status output.

README.zh-CN.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. A full store stops enrolled cameras ✓ Resolved
Description
device_key() writes the optional cerberus_device_pubkey through store_set(), whose U-Boot
implementation exits the process if fw_setenv fails. When an enrolled camera upgrades with no room
for the new variable, normal startup exits before configuring WireGuard or entering the watch loop,
even though its existing private key and enrollment material are present.
Code

src/cerberus.c[R1260-1261]

+    if (!store_get("cerberus_device_pubkey", stored, sizeof stored) || strcmp(stored, pub_b64) != 0)
+        store_set("cerberus_device_pubkey", pub_b64);
Evidence
The new write is fatal on the U-Boot backend, and normal startup reaches it before tunnel setup and
the watch loop.

src/cerberus.c[1254-1261]
src/cerberus.c[711-723]
src/cerberus.c[1294-1297]
src/cerberus.c[1444-1460]
src/cerberus.c[2648-2662]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A failed write of the optional public-key cache exits the agent before an enrolled camera can bring up its tunnel.
## Fix Focus Areas
- src/cerberus.c[1260-1261]
- src/cerberus.c[708-746]
- src/cerberus.c[1438-1453]
## Recommended Fix
Provide a best-effort write path for this cache that reports failure without calling `die()`. Warn on failure and continue using the already derived key for enrollment or WireGuard setup; leave status able to report that the fingerprint is unavailable.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Status can show the wrong camera key ✓ Resolved
Description
cmd_status() accepts any cached public key that decodes to 32 bytes without checking that a
private key is present or that the cache belongs to it. If the private key is replaced or removed
without updating the cache, status continues to print the old public key and fingerprint until
another command successfully runs device_key().
Code

src/cerberus.c[R2314-2316]

+    if (store_get("cerberus_device_pubkey", v, sizeof v) && key_fingerprint(v, fp) == 0) {
+        printf("public key     %s\n", v);
+        printf("fingerprint    %s\n", fp);
Evidence
Status checks only the cached value's decodability, while the cache is refreshed only in
device_key(). The added test vector even exercises status with a public-key cache and no private
key.

src/cerberus.c[1231-1261]
src/cerberus.c[1270-1283]
src/cerberus.c[2313-2321]
tests/suite.sh[275-278]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Status can present a cached public key as the camera's identity after its stored private key has changed or disappeared.
## Fix Focus Areas
- src/cerberus.c[1257-1261]
- src/cerberus.c[2313-2321]
## Recommended Fix
Persist a binding to the private-key value alongside the public-key cache without deriving the public key in status. Show the cached key and fingerprint only when the private key exists and matches that binding; otherwise report that the fingerprint is unavailable until the cache is refreshed.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/cerberus.c Resolved
Comment thread src/cerberus.c Resolved
Two review findings on the fingerprint (#46).

A full U-Boot environment stopped an enrolled camera: the public-key
cache went through store_set, which dies when fw_setenv fails, and
device_key runs before the interface is up. store_put now takes a soft
mode that warns and returns instead; the cache is written softly, and a
camera with no room for it starts as before, with status saying the
fingerprint is not known yet.

status could show another key's fingerprint: the cache was trusted on
its own, so a private key replaced or removed by hand left the old
public key on display. The cache is now "<public>:<binding>", the
binding being the first 8 bytes of SHA-256 of the raw private key
(nothing secret: it sits next to the key itself). status shows the
fingerprint only when the stored private key matches the binding, and
still derives nothing.
@keyldev

keyldev commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

Both findings fixed.

1 (a full store stops enrolled cameras): fixed in 10cd9b9. store_put has a soft mode that warns and returns instead of dying; the public-key cache is written softly, so a U-Boot env with no room for it costs a warning, not the camera's start. Test: a fake fw_setenv that refuses that key; up still succeeds and programs the interface.

2 (status can show the wrong key): fixed in 10cd9b9. The cache is now ":", binding = first 8 bytes of SHA-256 of the raw private key; status shows the fingerprint only when the stored private key matches it, and still derives nothing. Tests: a key replaced by hand and a missing key both show no fingerprint.

/review

@keyldev
keyldev merged commit ef45551 into master Oct 28, 2026
6 of 8 checks passed
@keyldev
keyldev deleted the feat/key-fingerprint branch October 28, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant