Compare commits

..

9 Commits

Author SHA1 Message Date
eta 31c9b9d862 visquitto: bug fix
build-and-push / check-branch (push) Successful in 9s
build-and-push / prepare (push) Successful in 9s
build-and-push / build (amd64, linux/amd64) (push) Successful in 57s
2026-11-08 15:12:36 +03:30
eta c3635e7034 visquitto: added rule to read issued topic in TLS mode
build-and-push / check-branch (push) Successful in 12s
build-and-push / prepare (push) Successful in 9s
build-and-push / build (amd64, linux/amd64) (push) Successful in 1m1s
2026-11-08 13:18:15 +03:30
eta bfefcbf636 mcm: revokation
build-and-push / check-branch (push) Successful in 14s
build-and-push / prepare (push) Successful in 8s
build-and-push / build (amd64, linux/amd64) (push) Successful in 19m43s
- Bug fix for revokation procedure
- Increased CRL (Certificate Revocation List) expiration from 7 days to 365
2026-11-07 11:36:38 +03:30
eta 75e9e347dd vis. changelog updated 2026-11-04 18:02:47 +03:30
eta 4611c14a81 visquitto: added discovery topic
build-and-push / check-branch (push) Successful in 11s
build-and-push / prepare (push) Successful in 9s
build-and-push / build (amd64, linux/amd64) (push) Successful in 1m22s
2026-11-04 16:19:15 +03:30
eta 209b697a39 mcm: edited device protocol 2026-10-31 14:07:20 +03:30
eta 676e0b3040 mcm: edited device protocol 2026-10-28 12:14:09 +03:30
eta cb4ac5c606 added visquitto changelog 2026-10-15 15:16:20 +03:30
eta 7fff51841a visquitto renew rework
build-and-push / check-branch (push) Successful in 13s
build-and-push / prepare (push) Successful in 8s
build-and-push / build (amd64, linux/amd64) (push) Successful in 1m3s
- added new ACL rules to support new renew system
2026-10-15 11:35:58 +03:30
9 changed files with 76 additions and 32 deletions
+5
View File
@@ -1,5 +1,10 @@
# Changelog
## 0.6.1
- Bug fix for revokation procedure
- Increased CRL expiration from 7 days to 365
## 0.6.0
- Changed certificate renwal procedure
+9 -13
View File
@@ -18,23 +18,19 @@ 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:
The private key never leaves the device. Generate an EC
P-256 (or RSA-2048 which is not recommended) key pair and a PKCS#10 CSR with:
- 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.
certificate. This have to be some `device_id`.
- 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.
the same key and just use auto renewal procedure (or repeat step 2 which
is not recommended) — no need to regenerate the key.
## 2. Publish the request
## 2. Publish the request (port = 1993)
Topic: `cert/enroll/<device_id>/request`
QoS: 1, retain: false
@@ -64,7 +60,7 @@ 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
## 3. Subscribe for the result, before or immediately after publishing (port = 1993)
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
@@ -105,14 +101,14 @@ setups where many devices might share one topic.
firmware to, say, stop operating or blink an error LED immediately
rather than waiting for the next failed connection.
## 4. Install and reconnect
## 4. Install and reconnect (port = 9993)
Store `cert` and `ca` to flash alongside the existing private key.
Reconnect to the broker using mutual TLS (client cert + key, broker CA
trust anchor = the same `ca`). Once confirmed working, you can stop
listening on the unauthenticated bootstrap connection for that device.
## 5. Renewal
## 5. Renewal (port = 9993)
Devices are trusted to renew themselves automatically once they're within
`renewal_window_days` (default 30) of `not_after` — **no human approval
+1 -1
View File
@@ -270,7 +270,7 @@ class CertificateAuthority:
x509.CertificateRevocationListBuilder()
.issuer_name(self.cert.subject)
.last_update(now)
.next_update(now + datetime.timedelta(days=7))
.next_update(now + datetime.timedelta(days=365))
)
for serial, revoked_at in revoked_entries:
revoked_cert = (
+2 -2
View File
@@ -195,7 +195,7 @@ def handle_renew_begin(device_id):
Only devices that already hold an issued, non-revoked cert get one, so
strangers can't make the server accumulate nonces. A device that gets no
answer should fall back to an ordinary enrollment request."""
if device_id in store.list_revoked():
if store.is_revoked(device_id):
log.info("renewal challenge refused for %s: device is revoked", device_id)
return
if device_id not in store.list_issued():
@@ -237,7 +237,7 @@ def handle_renew(device_id, csr_pem, nonce, signature_b64, meta):
log.info("renewal from %s falling back to manual approval: %s", device_id, why)
store.add_pending(device_id, csr_pem, meta)
if device_id in store.list_revoked():
if store.is_revoked(device_id):
fall_back_to_manual("device is revoked")
return
+31 -12
View File
@@ -1,10 +1,7 @@
"""Simple JSON-file store for pending requests and issued cert records.
Keyed by device_id -- the unique per-device identifier from the MQTT
topic path (cert/enroll/<device_id>/...). CN is deliberately NOT unique
in this deployment (many devices share one CN per category, for ACL
grouping), so it can't be used as a storage key -- device_id is the
only thing guaranteed unique per physical device.
topic path (cert/enroll/<device_id>/...).
A real deployment could swap this for sqlite, but request volume here is
tiny (one entry per physical device) so a flat file is fine and easy to
@@ -25,9 +22,17 @@ def _load():
return {"pending": {}, "issued": {}, "revoked": {}, "broker_cert": None}
with open(STATE_PATH, "r") as f:
state = json.load(f)
state.setdefault("broker_cert", None)
state.setdefault("revoked", {})
return state
state.setdefault("broker_cert", None)
state.setdefault("revoked", {})
# migrate old device_id-keyed revoked entries to serial-keyed
for key, entry in list(state["revoked"].items()):
if "device_id" not in entry:
del state["revoked"][key]
state["revoked"][str(entry["serial"])] = {
"device_id": key,
**entry,
}
return state
def _save(state):
@@ -100,16 +105,21 @@ def set_broker_cert(hostnames: list, not_after: str):
def revoke_device(device_id: str, reason: str):
"""Move a device from issued -> revoked. Keeps the issued record too
(for audit history) but also records it separately so the CRL builder
has a fast list to work from. Returns the serial number, or None if
the device has no issued cert on record."""
"""Revoke the device's current cert. Revocations are keyed by serial,
so re-issuing for the same device never un-revokes older certs and a
new cert can be revoked later. Returns the serial, or None if the
device has no issued cert or it is already revoked."""
with _lock:
state = _load()
issued = state["issued"].get(device_id)
if not issued:
return None
state["revoked"][device_id] = {
serial = str(issued["serial"]) # str: JSON keys must be strings, and
# these serials exceed safe int range elsewhere
if serial in state["revoked"]:
return None
state["revoked"][serial] = {
"device_id": device_id,
"serial": issued["serial"],
"reason": reason,
"revoked_at": time.time(),
@@ -117,7 +127,16 @@ def revoke_device(device_id: str, reason: str):
_save(state)
return issued["serial"]
def is_revoked(device_id: str) -> bool:
"""True only if the device's *current* cert is revoked."""
with _lock:
state = _load()
issued = state["issued"].get(device_id)
if not issued:
return False
return str(issued["serial"]) in state["revoked"]
def list_revoked():
"""All revoked certs, keyed by serial (use for building the CRL)."""
with _lock:
return _load()["revoked"]
+1 -1
View File
@@ -1,5 +1,5 @@
name: "MQTT Certificate Manager"
version: "0.6.0"
version: "0.6.1"
slug: "mqtt_cert_manager"
description: "Local CA that issues and manages TLS client certificates for MQTT nodes"
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/mqtt-cert-manager"
+16
View File
@@ -1,5 +1,21 @@
# Changelog
## 0.7.2
- Fixed renew bug
## 0.7.1
- Fixed renew bug
## 0.7.0
- Added rule for MQTT discovery
## 0.6.0
- Added new ACL rules to support new renew system
## 0.5.8
- Fixed TLS access control bug
+1 -1
View File
@@ -1,5 +1,5 @@
name: Visquitto
version: "0.5.8"
version: "0.7.2"
slug: visquitto
description: Second private Mosquitto broker for bitopa nodes
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/visquitto"
+10 -2
View File
@@ -81,8 +81,6 @@ cat > "$CONFIG/acl_plain" <<EOF
# ============================================================
user hamqtt
# Test topic
topic readwrite test
# Initial enrollment
topic write cert/enroll/+/request
topic read cert/enroll/+/issued
@@ -95,13 +93,23 @@ user viracert
topic read cert/enroll/+/request
topic write cert/enroll/+/issued
topic read cert/enroll/+/renew
topic read cert/enroll/+/renew-begin
topic write cert/enroll/+/challenge
EOF
# TLS ACL
cat > "$CONFIG/acl_tls" <<EOF
# Default rule for every certificate client. %u is the certificate CN.
# data exchange topic
pattern readwrite clients/%u/#
# discovery topic
pattern write vmqtt/sensor/%u/#
# connection topics
pattern read cert/enroll/%u/issued
pattern write cert/enroll/%u/renew
pattern write cert/enroll/%u/renew-begin
pattern read cert/enroll/%u/challenge
EOF
# ---- User customization in /share (created once, never overwritten) ----