Decouple certificate CN from device_id
- ca.sign_csr's identity parameter renamed to `common_name`, fully decoupled from device_id. - New resolve_common_name(): CN comes from the device's own CSR: falls back to device_id only if the CSR has no CN (malformed request). - Renewal unaffected: a renewed cert always keeps the CN of the device's current, still-valid cert, regardless of what the renewal CSR claims (verified against an adversarial CSR asserting a different CN). - device_id remains the sole storage key (pending/issued/revoked) and MQTT topic routing key, and must still be unique per physical device even when CN is deliberately shared across many. - /api/pending and /api/issued now also expose the CSR-resolved CN for display, without changing what's actually stored. No topic structure changes. No new MQTT payload fields.
This commit is contained in:
@@ -7,17 +7,28 @@ MQTT broker (unauthenticated, or with a shared bootstrap username/password
|
||||
|
||||
Default topic prefix is `cert/enroll`, configurable in the add-on options.
|
||||
Replace `<device_id>` with a stable, unique identifier for the node (e.g.
|
||||
its MAC address with colons stripped, or a serial number). This value is
|
||||
used as both the MQTT topic segment and the certificate's Common Name /
|
||||
SAN, so keep it short, DNS-safe, and unique on your network.
|
||||
its MAC address with colons stripped, or a serial number) — this MUST be
|
||||
unique per physical device, even if many devices share the same MQTT
|
||||
login for connecting to the broker. It's what topic routing and this
|
||||
add-on's own record-keeping are both keyed on; two devices sharing a
|
||||
`device_id` will collide with each other.
|
||||
|
||||
The cert's Common Name (CN) is a separate, independent concept — see
|
||||
step 2.
|
||||
|
||||
## 1. Generate a key pair and CSR (on-device, once)
|
||||
|
||||
The private key never leaves the device. Generate an RSA-2048 (or EC
|
||||
P-256) key pair and a PKCS#10 CSR with:
|
||||
- Common Name = `<device_id>`
|
||||
- No need for extensions in the CSR itself; the add-on sets the ones that
|
||||
matter (basic constraints, key usage, SAN) when it signs.
|
||||
- Common Name = whatever identity you want written into the issued
|
||||
certificate. This does NOT have to be `device_id` and does NOT have to
|
||||
be unique per device — a common pattern is to share one CN across a
|
||||
whole category of devices (e.g. every TH sensor uses CN `TH-Sensors`,
|
||||
every light sensor uses CN `Light-Sensors`), which is useful if you're
|
||||
writing broker ACL rules grouped by category rather than by individual
|
||||
device.
|
||||
- No need for other extensions in the CSR itself; the add-on sets the
|
||||
ones that matter (basic constraints, key usage, SAN) when it signs.
|
||||
|
||||
Persist the key pair to flash. If a cert is later lost or expires, reuse
|
||||
the same key and just repeat step 2 — no need to regenerate the key.
|
||||
@@ -40,9 +51,22 @@ Payload (JSON):
|
||||
`meta` is optional and only shown to the human approving the request — put
|
||||
anything there that helps you recognize the device in the UI.
|
||||
|
||||
The issued certificate's CN is taken directly from your CSR's own CN
|
||||
(step 1) — there's no separate field for it here. If your CSR has no CN
|
||||
at all, the add-on falls back to using `device_id` as the CN, but that's
|
||||
a safety net for malformed requests, not something to rely on.
|
||||
|
||||
This does NOT apply to renewal (§5) — a renewed cert always keeps the CN
|
||||
of the device's current, still-valid cert, regardless of what a renewal
|
||||
request's CSR claims. Changing identity requires a fresh, human-approved
|
||||
enrollment, not a renewal.
|
||||
|
||||
## 3. Subscribe for the result, before or immediately after publishing
|
||||
|
||||
Subscribe to both of these (QoS 1) so you catch whichever response comes:
|
||||
Subscribe to both of these (QoS 1) so you catch whichever response comes.
|
||||
Since `device_id` is unique per device (per the requirement above), each
|
||||
device has its own dedicated topics here — no filtering needed, unlike
|
||||
setups where many devices might share one topic.
|
||||
|
||||
- `cert/enroll/<device_id>/issued` — retained. Payload:
|
||||
```json
|
||||
|
||||
Reference in New Issue
Block a user