Compare commits
23 Commits
visquitto/v0.5.0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 426651a7eb | |||
| 31c9b9d862 | |||
| c3635e7034 | |||
| bfefcbf636 | |||
| 75e9e347dd | |||
| 4611c14a81 | |||
| 209b697a39 | |||
| 676e0b3040 | |||
| cb4ac5c606 | |||
| 7fff51841a | |||
| e5478ed5ef | |||
| 084d7d65e0 | |||
| 62d571b0d7 | |||
| 97d5f4ed48 | |||
| 2b42f58803 | |||
| f53f2f6309 | |||
| 03cd5ee028 | |||
| fff4b994e1 | |||
| 13c399133c | |||
| 940a41669f | |||
| e9b43da768 | |||
| c14b628558 | |||
| a502aa0128 |
@@ -136,8 +136,8 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up QEMU
|
# - name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
# uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.6.1
|
||||||
|
|
||||||
|
- Bug fix for revokation procedure
|
||||||
|
- Increased CRL expiration from 7 days to 365
|
||||||
|
|
||||||
|
## 0.6.0
|
||||||
|
|
||||||
|
- Changed certificate renwal procedure
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
- Improved logging and error handling
|
||||||
|
|
||||||
|
## 0.5.1 - 2026-10-11
|
||||||
|
|
||||||
|
- Bug fix
|
||||||
|
|
||||||
## 0.5.0 - 2026-10-11
|
## 0.5.0 - 2026-10-11
|
||||||
|
|
||||||
- Upgraded image build precedure
|
- Upgraded image build precedure
|
||||||
|
|||||||
@@ -18,23 +18,19 @@ step 2.
|
|||||||
|
|
||||||
## 1. Generate a key pair and CSR (on-device, once)
|
## 1. Generate a key pair and CSR (on-device, once)
|
||||||
|
|
||||||
The private key never leaves the device. Generate an RSA-2048 (or EC
|
The private key never leaves the device. Generate an EC
|
||||||
P-256) key pair and a PKCS#10 CSR with:
|
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
|
- Common Name = whatever identity you want written into the issued
|
||||||
certificate. This does NOT have to be `device_id` and does NOT have to
|
certificate. This have to be some `device_id`.
|
||||||
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
|
- 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.
|
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
|
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`
|
Topic: `cert/enroll/<device_id>/request`
|
||||||
QoS: 1, retain: false
|
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
|
request's CSR claims. Changing identity requires a fresh, human-approved
|
||||||
enrollment, not a renewal.
|
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.
|
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
|
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
|
firmware to, say, stop operating or blink an error LED immediately
|
||||||
rather than waiting for the next failed connection.
|
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.
|
Store `cert` and `ca` to flash alongside the existing private key.
|
||||||
Reconnect to the broker using mutual TLS (client cert + key, broker CA
|
Reconnect to the broker using mutual TLS (client cert + key, broker CA
|
||||||
trust anchor = the same `ca`). Once confirmed working, you can stop
|
trust anchor = the same `ca`). Once confirmed working, you can stop
|
||||||
listening on the unauthenticated bootstrap connection for that device.
|
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
|
Devices are trusted to renew themselves automatically once they're within
|
||||||
`renewal_window_days` (default 30) of `not_after` — **no human approval
|
`renewal_window_days` (default 30) of `not_after` — **no human approval
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM ghcr.io/home-assistant/base:2026.10.1
|
FROM ghcr.io/home-assistant/base:3.24
|
||||||
|
|
||||||
RUN apk add --no-cache python3 py3-pip
|
RUN apk add --no-cache python3 py3-pip
|
||||||
|
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ class CertificateAuthority:
|
|||||||
x509.CertificateRevocationListBuilder()
|
x509.CertificateRevocationListBuilder()
|
||||||
.issuer_name(self.cert.subject)
|
.issuer_name(self.cert.subject)
|
||||||
.last_update(now)
|
.last_update(now)
|
||||||
.next_update(now + datetime.timedelta(days=7))
|
.next_update(now + datetime.timedelta(days=365))
|
||||||
)
|
)
|
||||||
for serial, revoked_at in revoked_entries:
|
for serial, revoked_at in revoked_entries:
|
||||||
revoked_cert = (
|
revoked_cert = (
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
"""
|
||||||
|
Server-issued challenges for certificate renewal.
|
||||||
|
|
||||||
|
Why this exists: a node with no trustworthy clock can't produce a timestamp
|
||||||
|
the server can check, so freshness has to come from the server instead.
|
||||||
|
For each renewal the server hands the node a random, single-use, short-lived
|
||||||
|
nonce, and the node signs that nonce together with a digest of its new CSR.
|
||||||
|
A captured renewal message is useless afterwards: the nonce is gone, and
|
||||||
|
swapping in a different CSR breaks the signature.
|
||||||
|
|
||||||
|
State is in memory only. If the add-on restarts, outstanding challenges are
|
||||||
|
simply lost and the node asks for a new one.
|
||||||
|
"""
|
||||||
|
import hashlib
|
||||||
|
import hmac
|
||||||
|
import secrets
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
from cryptography import x509
|
||||||
|
from cryptography.hazmat.primitives import serialization
|
||||||
|
|
||||||
|
CHALLENGE_TTL_SECONDS = 120
|
||||||
|
|
||||||
|
# Prefix on everything a node signs for renewal. It keeps a renewal
|
||||||
|
# signature from being valid in any other protocol that reuses the key.
|
||||||
|
RENEWAL_CONTEXT = "renew-v1"
|
||||||
|
|
||||||
|
|
||||||
|
def csr_digest(csr_pem: str) -> str:
|
||||||
|
"""SHA-256 (hex) of the CSR's DER encoding. Raises ValueError if the CSR
|
||||||
|
doesn't parse.
|
||||||
|
|
||||||
|
The DER form is hashed, not the PEM text, so line endings or whitespace
|
||||||
|
that differ between the node and the server don't change the result."""
|
||||||
|
csr = x509.load_pem_x509_csr(csr_pem.encode())
|
||||||
|
return hashlib.sha256(csr.public_bytes(serialization.Encoding.DER)).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def renewal_message(device_id: str, nonce: str, digest: str) -> bytes:
|
||||||
|
"""The exact bytes a node signs to prove a renewal request."""
|
||||||
|
return f"{RENEWAL_CONTEXT}|{device_id}|{nonce}|{digest}".encode()
|
||||||
|
|
||||||
|
|
||||||
|
class ChallengeStore:
|
||||||
|
"""One active challenge per device. Thread-safe."""
|
||||||
|
|
||||||
|
def __init__(self, ttl: int = CHALLENGE_TTL_SECONDS, clock=time.monotonic):
|
||||||
|
self._ttl = ttl
|
||||||
|
self._clock = clock
|
||||||
|
self._lock = threading.Lock()
|
||||||
|
self._active = {} # device_id -> (nonce, expires_at)
|
||||||
|
|
||||||
|
def _prune(self, now):
|
||||||
|
for device_id in [d for d, (_, exp) in self._active.items() if now >= exp]:
|
||||||
|
del self._active[device_id]
|
||||||
|
|
||||||
|
def issue(self, device_id: str):
|
||||||
|
"""Return (nonce, seconds_left) for this device.
|
||||||
|
|
||||||
|
If the device already has an unexpired challenge, that same one is
|
||||||
|
returned instead of minting another. A node that missed the first
|
||||||
|
message can simply ask again, and nobody else can invalidate a
|
||||||
|
device's challenge by asking for a new one."""
|
||||||
|
with self._lock:
|
||||||
|
now = self._clock()
|
||||||
|
self._prune(now)
|
||||||
|
current = self._active.get(device_id)
|
||||||
|
if current:
|
||||||
|
return current[0], max(1, int(current[1] - now))
|
||||||
|
nonce = secrets.token_hex(32)
|
||||||
|
self._active[device_id] = (nonce, now + self._ttl)
|
||||||
|
return nonce, self._ttl
|
||||||
|
|
||||||
|
def is_active(self, device_id: str, nonce) -> bool:
|
||||||
|
"""Cheap non-consuming check, used to skip signature work for nonces
|
||||||
|
that can't possibly be valid. consume() is the real gate."""
|
||||||
|
with self._lock:
|
||||||
|
current = self._active.get(device_id)
|
||||||
|
if not current or not isinstance(nonce, str):
|
||||||
|
return False
|
||||||
|
stored, expires_at = current
|
||||||
|
if self._clock() >= expires_at:
|
||||||
|
return False
|
||||||
|
return hmac.compare_digest(stored.encode(), nonce.encode())
|
||||||
|
|
||||||
|
def consume(self, device_id: str, nonce) -> bool:
|
||||||
|
"""Atomically check and burn the nonce. True only for the first caller
|
||||||
|
presenting this device's current, unexpired nonce."""
|
||||||
|
with self._lock:
|
||||||
|
current = self._active.get(device_id)
|
||||||
|
if not current:
|
||||||
|
return False
|
||||||
|
stored, expires_at = current
|
||||||
|
if self._clock() >= expires_at:
|
||||||
|
del self._active[device_id]
|
||||||
|
return False
|
||||||
|
if not isinstance(nonce, str) or not hmac.compare_digest(stored.encode(), nonce.encode()):
|
||||||
|
return False
|
||||||
|
del self._active[device_id]
|
||||||
|
return True
|
||||||
@@ -3,24 +3,38 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import sys
|
||||||
|
|
||||||
from flask import Flask, jsonify, render_template, request
|
from flask import Flask, jsonify, render_template, request
|
||||||
|
|
||||||
import store
|
import store
|
||||||
from ca import CertificateAuthority, extract_cert_common_name, extract_csr_common_name
|
from ca import CertificateAuthority, extract_cert_common_name, extract_csr_common_name
|
||||||
|
from challenges import ChallengeStore, csr_digest, renewal_message
|
||||||
from mqtt_worker import MqttWorker
|
from mqtt_worker import MqttWorker
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(message)s")
|
||||||
log = logging.getLogger("main")
|
log = logging.getLogger("main")
|
||||||
|
|
||||||
|
|
||||||
|
def _log_uncaught(exc_type, exc, tb):
|
||||||
|
# Python prints uncaught exceptions straight to stderr, bypassing
|
||||||
|
# logging entirely -- which is why a crash traceback had no timestamp
|
||||||
|
# while every other line did. Route it through the logger instead.
|
||||||
|
log.critical("uncaught exception, add-on is exiting", exc_info=(exc_type, exc, tb))
|
||||||
|
|
||||||
|
|
||||||
|
sys.excepthook = _log_uncaught
|
||||||
|
|
||||||
OPTIONS_PATH = "/data/options.json"
|
OPTIONS_PATH = "/data/options.json"
|
||||||
SSL_DIR = "/ssl"
|
SSL_DIR = "/ssl"
|
||||||
BROKER_CERT_FILENAME = "mosquitto-server.crt"
|
BROKER_CERT_FILENAME = "mosquitto-server.crt"
|
||||||
BROKER_KEY_FILENAME = "mosquitto-server.key"
|
BROKER_KEY_FILENAME = "mosquitto-server.key"
|
||||||
CA_FILENAME = "mqtt-cert-manager-ca.crt"
|
CA_FILENAME = "mqtt-cert-manager-ca.crt"
|
||||||
CRL_FILENAME = "mqtt-cert-manager-crl.pem"
|
CRL_FILENAME = "mqtt-cert-manager-crl.pem"
|
||||||
RENEWAL_TIMESTAMP_SKEW_SECONDS = 300
|
|
||||||
|
# Single-use renewal challenges (see challenges.py). Nodes have no clock, so
|
||||||
|
# freshness comes from the server issuing a nonce rather than a timestamp.
|
||||||
|
challenge_store = ChallengeStore()
|
||||||
|
|
||||||
|
|
||||||
def load_options():
|
def load_options():
|
||||||
@@ -175,14 +189,41 @@ def finalize_issuance(device_id: str, csr_pem: str, common_name: str, state=None
|
|||||||
return cert_pem, not_after
|
return cert_pem, not_after
|
||||||
|
|
||||||
|
|
||||||
def handle_renew(device_id, csr_pem, timestamp, signature_b64, meta):
|
def handle_renew_begin(device_id):
|
||||||
"""Auto-issue a renewed cert IF, and only if, the requester proves
|
"""Step 1 of renewal: a node asks for a challenge.
|
||||||
possession of the *currently on-record* cert's private key, that
|
|
||||||
cert isn't revoked, and we're actually within the renewal window.
|
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 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():
|
||||||
|
log.info(
|
||||||
|
"renewal challenge refused for %s: no issued cert on record "
|
||||||
|
"(it needs a normal enrollment request)", device_id,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
nonce, expires_in = challenge_store.issue(device_id)
|
||||||
|
mqtt_worker.publish_challenge(device_id, nonce, expires_in)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_renew(device_id, csr_pem, nonce, signature_b64, meta):
|
||||||
|
"""Step 2 of renewal. Auto-issue a renewed cert IF, and only if, the
|
||||||
|
requester proves possession of the *currently on-record* cert's private
|
||||||
|
key by signing the server's challenge, that cert isn't revoked, and
|
||||||
|
we're actually within the renewal window.
|
||||||
|
|
||||||
|
The signature must cover renew-v1|device_id|nonce|sha256(DER(csr)), so
|
||||||
|
it is bound to this device, to a nonce this server issued (single-use,
|
||||||
|
short-lived), and to the exact CSR being certified. A captured request
|
||||||
|
can't be replayed (the nonce is spent) and can't be re-targeted at a
|
||||||
|
different key (the CSR digest wouldn't match).
|
||||||
|
|
||||||
Any failure falls back to the ordinary manual-approval queue —
|
Any failure falls back to the ordinary manual-approval queue —
|
||||||
exactly as if this were a first-time request — rather than being
|
exactly as if this were a first-time request — rather than being
|
||||||
silently dropped, so a legitimate device with e.g. clock skew still
|
silently dropped, so a legitimate device that e.g. lost its challenge
|
||||||
gets a cert eventually, just with human review.
|
still gets a cert eventually, just with human review.
|
||||||
|
|
||||||
CN handling for renewal is intentionally NOT the same as fresh
|
CN handling for renewal is intentionally NOT the same as fresh
|
||||||
issuance: the renewed cert always keeps whatever CN the device's
|
issuance: the renewed cert always keeps whatever CN the device's
|
||||||
@@ -196,7 +237,7 @@ def handle_renew(device_id, csr_pem, timestamp, signature_b64, meta):
|
|||||||
log.info("renewal from %s falling back to manual approval: %s", device_id, why)
|
log.info("renewal from %s falling back to manual approval: %s", device_id, why)
|
||||||
store.add_pending(device_id, csr_pem, meta)
|
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")
|
fall_back_to_manual("device is revoked")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -205,33 +246,46 @@ def handle_renew(device_id, csr_pem, timestamp, signature_b64, meta):
|
|||||||
fall_back_to_manual("no prior issued cert on record")
|
fall_back_to_manual("no prior issued cert on record")
|
||||||
return
|
return
|
||||||
|
|
||||||
now = time.time()
|
|
||||||
try:
|
|
||||||
ts = float(timestamp)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
fall_back_to_manual("timestamp not a number")
|
|
||||||
return
|
|
||||||
if abs(now - ts) > RENEWAL_TIMESTAMP_SKEW_SECONDS:
|
|
||||||
fall_back_to_manual("timestamp outside allowed skew window")
|
|
||||||
return
|
|
||||||
|
|
||||||
not_after = datetime.datetime.fromisoformat(existing_issued["not_after"])
|
not_after = datetime.datetime.fromisoformat(existing_issued["not_after"])
|
||||||
renewal_opens_at = not_after - datetime.timedelta(days=int(options["renewal_window_days"]))
|
renewal_opens_at = not_after - datetime.timedelta(days=int(options["renewal_window_days"]))
|
||||||
if datetime.datetime.now(datetime.timezone.utc) < renewal_opens_at:
|
if datetime.datetime.now(datetime.timezone.utc) < renewal_opens_at:
|
||||||
fall_back_to_manual(f"too early to renew (opens {renewal_opens_at.isoformat()})")
|
fall_back_to_manual(f"too early to renew (opens {renewal_opens_at.isoformat()})")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not nonce:
|
||||||
|
fall_back_to_manual("no challenge nonce supplied (old or malformed renewal request)")
|
||||||
|
return
|
||||||
|
# Cheap pre-check so we don't do signature work for a nonce that can't
|
||||||
|
# be valid. The atomic consume below is what actually enforces single use.
|
||||||
|
if not challenge_store.is_active(device_id, nonce):
|
||||||
|
fall_back_to_manual("no active challenge for this device, or the nonce is wrong, expired or already used")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
signature = base64.b64decode(signature_b64)
|
signature = base64.b64decode(signature_b64)
|
||||||
except Exception:
|
except Exception:
|
||||||
fall_back_to_manual("signature not valid base64")
|
fall_back_to_manual("signature not valid base64")
|
||||||
return
|
return
|
||||||
|
|
||||||
message = f"{device_id}|{int(ts)}|renew".encode()
|
# Rebuilt here from the CSR we actually received -- never from any
|
||||||
|
# digest or field the node sent alongside it.
|
||||||
|
try:
|
||||||
|
digest = csr_digest(csr_pem)
|
||||||
|
except ValueError:
|
||||||
|
fall_back_to_manual("CSR could not be parsed")
|
||||||
|
return
|
||||||
|
|
||||||
|
message = renewal_message(device_id, nonce, digest)
|
||||||
if not ca.verify_renewal_proof(existing_issued["cert"], message, signature):
|
if not ca.verify_renewal_proof(existing_issued["cert"], message, signature):
|
||||||
fall_back_to_manual("proof-of-possession signature did not verify")
|
fall_back_to_manual("proof-of-possession signature did not verify")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Last gate before issuing. Invalid requests above never burn the nonce,
|
||||||
|
# and two concurrent requests with the same nonce can't both get here.
|
||||||
|
if not challenge_store.consume(device_id, nonce):
|
||||||
|
fall_back_to_manual("challenge was already used or has just expired")
|
||||||
|
return
|
||||||
|
|
||||||
# Past every check: keep the EXISTING cert's CN, full stop. Never
|
# Past every check: keep the EXISTING cert's CN, full stop. Never
|
||||||
# derived from the new CSR for a renewal.
|
# derived from the new CSR for a renewal.
|
||||||
preserved_common_name = extract_cert_common_name(existing_issued["cert"]) or device_id
|
preserved_common_name = extract_cert_common_name(existing_issued["cert"]) or device_id
|
||||||
@@ -256,6 +310,7 @@ mqtt_worker = MqttWorker(
|
|||||||
topic_prefix=options["request_topic_prefix"],
|
topic_prefix=options["request_topic_prefix"],
|
||||||
on_request=handle_request,
|
on_request=handle_request,
|
||||||
on_renew=handle_renew,
|
on_renew=handle_renew,
|
||||||
|
on_renew_begin=handle_renew_begin,
|
||||||
)
|
)
|
||||||
mqtt_worker.start()
|
mqtt_worker.start()
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,18 @@ MQTT side of the enrollment protocol.
|
|||||||
|
|
||||||
Topics (prefix is configurable, default "cert/enroll"):
|
Topics (prefix is configurable, default "cert/enroll"):
|
||||||
<prefix>/<device_id>/request node -> here {"csr": "<PEM>", "meta": {...}}
|
<prefix>/<device_id>/request node -> here {"csr": "<PEM>", "meta": {...}}
|
||||||
<prefix>/<device_id>/renew node -> here {"csr": "<PEM>", "timestamp": <int>, "signature": "<base64>", "meta": {...}}
|
<prefix>/<device_id>/renew-begin node -> here (payload ignored) asks for a renewal challenge
|
||||||
|
<prefix>/<device_id>/challenge here -> node {"nonce": "<hex>", "expires_in": <seconds>} (not retained)
|
||||||
|
<prefix>/<device_id>/renew node -> here {"csr": "<PEM>", "nonce": "<hex>", "signature": "<base64>", "meta": {...}}
|
||||||
<prefix>/<device_id>/issued here -> node {"cert": "<PEM>", "ca": "<PEM>"} (retained)
|
<prefix>/<device_id>/issued here -> node {"cert": "<PEM>", "ca": "<PEM>"} (retained)
|
||||||
<prefix>/<device_id>/rejected here -> node {"reason": "..."}
|
<prefix>/<device_id>/rejected here -> node {"reason": "..."}
|
||||||
<prefix>/<device_id>/revoked here -> node {"reason": "..."} (best-effort notice; see DEVICE_PROTOCOL.md)
|
<prefix>/<device_id>/revoked here -> node {"reason": "..."} (best-effort notice; see DEVICE_PROTOCOL.md)
|
||||||
|
|
||||||
|
Renewal needs no clock on the node. The node asks for a challenge, gets a
|
||||||
|
single-use nonce back, and signs "renew-v1|<device_id>|<nonce>|<sha256 of
|
||||||
|
the CSR's DER>" with its CURRENT key. See challenges.py and
|
||||||
|
RENEWAL_PROTOCOL.md.
|
||||||
|
|
||||||
device_id is expected to be unique per physical device (not a shared
|
device_id is expected to be unique per physical device (not a shared
|
||||||
bootstrap identity) -- that's what makes per-device topics work without
|
bootstrap identity) -- that's what makes per-device topics work without
|
||||||
any extra filtering in the payload. The cert's CN is a separate concern,
|
any extra filtering in the payload. The cert's CN is a separate concern,
|
||||||
@@ -20,6 +27,7 @@ See DEVICE_PROTOCOL.md for the full spec devices should implement.
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
@@ -29,31 +37,79 @@ log = logging.getLogger("mqtt_worker")
|
|||||||
|
|
||||||
|
|
||||||
class MqttWorker:
|
class MqttWorker:
|
||||||
def __init__(self, host, port, username, password, topic_prefix, on_request, on_renew):
|
def __init__(self, host, port, username, password, topic_prefix, on_request, on_renew, on_renew_begin):
|
||||||
self.topic_prefix = topic_prefix.rstrip("/")
|
self.topic_prefix = topic_prefix.rstrip("/")
|
||||||
self.on_request = on_request # callback(device_id, csr_pem, meta)
|
self.on_request = on_request # callback(device_id, csr_pem, meta)
|
||||||
self.on_renew = on_renew # callback(device_id, csr_pem, timestamp, signature_b64, meta)
|
self.on_renew_begin = on_renew_begin # callback(device_id)
|
||||||
|
self.on_renew = on_renew # callback(device_id, csr_pem, nonce, signature_b64, meta)
|
||||||
|
|
||||||
self.client = mqtt.Client(client_id="mqtt-cert-manager")
|
self.client = mqtt.Client(client_id="mqtt-cert-manager")
|
||||||
if username:
|
if username:
|
||||||
self.client.username_pw_set(username, password or None)
|
self.client.username_pw_set(username, password or None)
|
||||||
self.client.on_connect = self._on_connect
|
self.client.on_connect = self._on_connect
|
||||||
|
self.client.on_disconnect = self._on_disconnect
|
||||||
self.client.on_message = self._on_message
|
self.client.on_message = self._on_message
|
||||||
|
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.client.connect(self.host, self.port, keepalive=60)
|
# Returns immediately: the connect (and its retries) happen in the
|
||||||
thread = threading.Thread(target=self.client.loop_forever, daemon=True)
|
# background, so a broker that isn't reachable YET -- e.g. Home
|
||||||
|
# Assistant just booted and Mosquitto hasn't started -- doesn't
|
||||||
|
# crash the whole add-on or block the web UI from coming up.
|
||||||
|
thread = threading.Thread(target=self._run, daemon=True, name="mqtt-worker")
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
def _run(self):
|
||||||
|
self.client.reconnect_delay_set(min_delay=1, max_delay=30)
|
||||||
|
delay = 1
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
# This is the plain TCP connect. MQTT itself (CONNECT /
|
||||||
|
# CONNACK, auth) only starts once this succeeds.
|
||||||
|
self.client.connect(self.host, self.port, keepalive=60)
|
||||||
|
except OSError as exc:
|
||||||
|
# ConnectionRefusedError (nothing listening), gaierror
|
||||||
|
# (hostname doesn't resolve), timeouts, etc. all land here.
|
||||||
|
log.warning(
|
||||||
|
"cannot reach MQTT broker at %s:%s (%s: %s) - retrying in %ss. "
|
||||||
|
"Check the mqtt_host / mqtt_port options, and that Mosquitto is running.",
|
||||||
|
self.host, self.port, type(exc).__name__, exc, delay,
|
||||||
|
)
|
||||||
|
time.sleep(delay)
|
||||||
|
delay = min(delay * 2, 30)
|
||||||
|
continue
|
||||||
|
# Connected at the TCP level. From here paho handles drops and
|
||||||
|
# reconnects itself (using reconnect_delay_set above); this only
|
||||||
|
# returns if disconnect() is ever called explicitly.
|
||||||
|
self.client.loop_forever()
|
||||||
|
return
|
||||||
|
|
||||||
def _on_connect(self, client, userdata, flags, rc):
|
def _on_connect(self, client, userdata, flags, rc):
|
||||||
|
if rc != 0:
|
||||||
|
# The TCP connection worked but the BROKER said no -- a different
|
||||||
|
# failure from "connection refused". Usually bad credentials.
|
||||||
|
log.error(
|
||||||
|
"MQTT broker rejected the connection: %s "
|
||||||
|
"(check the mqtt_username / mqtt_password options)",
|
||||||
|
mqtt.connack_string(rc),
|
||||||
|
)
|
||||||
|
return
|
||||||
request_topic = f"{self.topic_prefix}/+/request"
|
request_topic = f"{self.topic_prefix}/+/request"
|
||||||
|
renew_begin_topic = f"{self.topic_prefix}/+/renew-begin"
|
||||||
renew_topic = f"{self.topic_prefix}/+/renew"
|
renew_topic = f"{self.topic_prefix}/+/renew"
|
||||||
client.subscribe(request_topic, qos=1)
|
client.subscribe(request_topic, qos=1)
|
||||||
|
client.subscribe(renew_begin_topic, qos=1)
|
||||||
client.subscribe(renew_topic, qos=1)
|
client.subscribe(renew_topic, qos=1)
|
||||||
log.info("connected to broker, subscribed to %s and %s", request_topic, renew_topic)
|
log.info(
|
||||||
|
"connected to broker, subscribed to %s, %s and %s",
|
||||||
|
request_topic, renew_begin_topic, renew_topic,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _on_disconnect(self, client, userdata, rc):
|
||||||
|
if rc != 0:
|
||||||
|
log.warning("lost connection to MQTT broker (rc=%s); retrying automatically", rc)
|
||||||
|
|
||||||
def _on_message(self, client, userdata, msg):
|
def _on_message(self, client, userdata, msg):
|
||||||
parts = msg.topic.split("/")
|
parts = msg.topic.split("/")
|
||||||
@@ -61,11 +117,21 @@ class MqttWorker:
|
|||||||
return
|
return
|
||||||
device_id, kind = parts[-2], parts[-1]
|
device_id, kind = parts[-2], parts[-1]
|
||||||
|
|
||||||
|
if kind == "renew-begin":
|
||||||
|
# Nothing in this payload is used, so don't insist on valid JSON
|
||||||
|
# (a node may well send an empty message).
|
||||||
|
log.info("renewal challenge requested by %s", device_id)
|
||||||
|
self.on_renew_begin(device_id)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = json.loads(msg.payload.decode())
|
payload = json.loads(msg.payload.decode())
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
log.warning("malformed payload from %s on %s: %s", device_id, msg.topic, exc)
|
log.warning("malformed payload from %s on %s: %s", device_id, msg.topic, exc)
|
||||||
return
|
return
|
||||||
|
if not isinstance(payload, dict):
|
||||||
|
log.warning("malformed payload from %s on %s: expected a JSON object", device_id, msg.topic)
|
||||||
|
return
|
||||||
|
|
||||||
if kind == "request":
|
if kind == "request":
|
||||||
try:
|
try:
|
||||||
@@ -79,13 +145,29 @@ class MqttWorker:
|
|||||||
elif kind == "renew":
|
elif kind == "renew":
|
||||||
try:
|
try:
|
||||||
csr_pem = payload["csr"]
|
csr_pem = payload["csr"]
|
||||||
timestamp = payload["timestamp"]
|
|
||||||
signature_b64 = payload["signature"]
|
signature_b64 = payload["signature"]
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
log.warning("malformed renewal from %s: missing %s", device_id, exc)
|
log.warning("malformed renewal from %s: missing %s", device_id, exc)
|
||||||
return
|
return
|
||||||
|
if not isinstance(csr_pem, str):
|
||||||
|
log.warning("malformed renewal from %s: csr must be a string", device_id)
|
||||||
|
return
|
||||||
|
nonce = payload.get("nonce")
|
||||||
|
if nonce is None and "timestamp" in payload:
|
||||||
|
log.warning(
|
||||||
|
"renewal from %s uses the old timestamp format, which is no longer "
|
||||||
|
"supported; it will go to manual approval", device_id,
|
||||||
|
)
|
||||||
log.info("renewal request received from %s", device_id)
|
log.info("renewal request received from %s", device_id)
|
||||||
self.on_renew(device_id, csr_pem, timestamp, signature_b64, payload.get("meta", {}))
|
self.on_renew(device_id, csr_pem, nonce, signature_b64, payload.get("meta", {}))
|
||||||
|
|
||||||
|
def publish_challenge(self, device_id: str, nonce: str, expires_in: int):
|
||||||
|
# Deliberately NOT retained: a retained challenge would be handed to
|
||||||
|
# any later subscriber long after it expired.
|
||||||
|
topic = f"{self.topic_prefix}/{device_id}/challenge"
|
||||||
|
payload = json.dumps({"nonce": nonce, "expires_in": expires_in})
|
||||||
|
self.client.publish(topic, payload, qos=1, retain=False)
|
||||||
|
log.info("published renewal challenge for %s (valid %ss)", device_id, expires_in)
|
||||||
|
|
||||||
def publish_issued(self, device_id: str, cert_pem: str, ca_pem: str):
|
def publish_issued(self, device_id: str, cert_pem: str, ca_pem: str):
|
||||||
topic = f"{self.topic_prefix}/{device_id}/issued"
|
topic = f"{self.topic_prefix}/{device_id}/issued"
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
"""Simple JSON-file store for pending requests and issued cert records.
|
"""Simple JSON-file store for pending requests and issued cert records.
|
||||||
|
|
||||||
Keyed by device_id -- the unique per-device identifier from the MQTT
|
Keyed by device_id -- the unique per-device identifier from the MQTT
|
||||||
topic path (cert/enroll/<device_id>/...). CN is deliberately NOT unique
|
topic path (cert/enroll/<device_id>/...).
|
||||||
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.
|
|
||||||
|
|
||||||
A real deployment could swap this for sqlite, but request volume here is
|
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
|
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}
|
return {"pending": {}, "issued": {}, "revoked": {}, "broker_cert": None}
|
||||||
with open(STATE_PATH, "r") as f:
|
with open(STATE_PATH, "r") as f:
|
||||||
state = json.load(f)
|
state = json.load(f)
|
||||||
state.setdefault("broker_cert", None)
|
state.setdefault("broker_cert", None)
|
||||||
state.setdefault("revoked", {})
|
state.setdefault("revoked", {})
|
||||||
return state
|
# 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):
|
def _save(state):
|
||||||
@@ -100,16 +105,21 @@ def set_broker_cert(hostnames: list, not_after: str):
|
|||||||
|
|
||||||
|
|
||||||
def revoke_device(device_id: str, reason: str):
|
def revoke_device(device_id: str, reason: str):
|
||||||
"""Move a device from issued -> revoked. Keeps the issued record too
|
"""Revoke the device's current cert. Revocations are keyed by serial,
|
||||||
(for audit history) but also records it separately so the CRL builder
|
so re-issuing for the same device never un-revokes older certs and a
|
||||||
has a fast list to work from. Returns the serial number, or None if
|
new cert can be revoked later. Returns the serial, or None if the
|
||||||
the device has no issued cert on record."""
|
device has no issued cert or it is already revoked."""
|
||||||
with _lock:
|
with _lock:
|
||||||
state = _load()
|
state = _load()
|
||||||
issued = state["issued"].get(device_id)
|
issued = state["issued"].get(device_id)
|
||||||
if not issued:
|
if not issued:
|
||||||
return None
|
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"],
|
"serial": issued["serial"],
|
||||||
"reason": reason,
|
"reason": reason,
|
||||||
"revoked_at": time.time(),
|
"revoked_at": time.time(),
|
||||||
@@ -117,7 +127,16 @@ def revoke_device(device_id: str, reason: str):
|
|||||||
_save(state)
|
_save(state)
|
||||||
return issued["serial"]
|
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():
|
def list_revoked():
|
||||||
|
"""All revoked certs, keyed by serial (use for building the CRL)."""
|
||||||
with _lock:
|
with _lock:
|
||||||
return _load()["revoked"]
|
return _load()["revoked"]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: "MQTT Certificate Manager"
|
name: "MQTT Certificate Manager"
|
||||||
version: "0.5.0"
|
version: "0.6.1"
|
||||||
slug: "mqtt_cert_manager"
|
slug: "mqtt_cert_manager"
|
||||||
description: "Local CA that issues and manages TLS client certificates for MQTT nodes"
|
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"
|
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/mqtt-cert-manager"
|
||||||
|
|||||||
@@ -1,5 +1,41 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.8.0
|
||||||
|
|
||||||
|
- Improved MQTT discovery
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
## 0.5.5
|
||||||
|
|
||||||
|
- Fixed logging issue
|
||||||
|
|
||||||
|
## 0.5.4
|
||||||
|
|
||||||
|
- Minor bug fix
|
||||||
|
|
||||||
|
## 0.5.1 - 2026-10-11
|
||||||
|
|
||||||
|
- Minor bug fixed
|
||||||
|
|
||||||
## 0.5.0 - 2026-10-11
|
## 0.5.0 - 2026-10-11
|
||||||
|
|
||||||
- Added pre-built docker image
|
- Added pre-built docker image
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Visquitto
|
name: Visquitto
|
||||||
version: "0.5.0"
|
version: "0.8.0"
|
||||||
slug: visquitto
|
slug: visquitto
|
||||||
description: Second private Mosquitto broker for bitopa nodes
|
description: Second private Mosquitto broker for bitopa nodes
|
||||||
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/visquitto"
|
url: "https://gitea.viratak.com/bitopa/virarepo/src/branch/main/visquitto"
|
||||||
|
|||||||
+33
-21
@@ -34,57 +34,53 @@ chmod 600 "$CERTDIR/key.pem"
|
|||||||
|
|
||||||
# ---- Defaults in /config (regenerated at every start) ----
|
# ---- Defaults in /config (regenerated at every start) ----
|
||||||
cat > "$CONFIG/mosquitto.conf" <<EOF
|
cat > "$CONFIG/mosquitto.conf" <<EOF
|
||||||
protocol mqtt
|
$(jq -r '.log_dest[]? | "log_dest \(.)"' /data/options.json)
|
||||||
allow_anonymous false
|
$(jq -r '.log_type[]? | "log_type \(.)"' /data/options.json)
|
||||||
|
|
||||||
log_dest stdout
|
|
||||||
log_type error
|
|
||||||
log_type warning
|
|
||||||
log_type notice
|
|
||||||
log_timestamp_format %Y-%m-%d %H:%M:%S
|
log_timestamp_format %Y-%m-%d %H:%M:%S
|
||||||
|
|
||||||
persistence true
|
persistence true
|
||||||
persistence_location $DATA/
|
persistence_location $DATA/
|
||||||
max_queued_messages 8192
|
max_queued_messages 8192
|
||||||
|
|
||||||
plugin_load acl_file /usr/lib/mosquitto_acl_file.so
|
plugin_load passwd /usr/lib/mosquitto_password_file.so
|
||||||
plugin_load password_file /usr/lib/mosquitto_password_file.so
|
plugin_opt_password_file $PASSWD
|
||||||
|
|
||||||
|
plugin_load acl_plain /usr/lib/mosquitto_acl_file.so
|
||||||
|
plugin_opt_acl_file $DATA/acl_plain
|
||||||
|
|
||||||
|
plugin_load acl_tls /usr/lib/mosquitto_acl_file.so
|
||||||
|
plugin_opt_acl_file $DATA/acl_tls
|
||||||
|
|
||||||
include_dir $SHARE
|
include_dir $SHARE
|
||||||
|
|
||||||
# Plain listener (host port 1993): password users only
|
# Plain listener (host port 1993): password users only
|
||||||
listener 1883
|
listener 1883
|
||||||
protocol mqtt
|
protocol mqtt
|
||||||
plugin_use password_file
|
allow_anonymous false
|
||||||
plugin_opt_password_file $PASSWD
|
plugin_use passwd
|
||||||
plugin_use acl_file
|
plugin_use acl_plain
|
||||||
plugin_opt_acl_file $DATA/acl_plain
|
|
||||||
|
|
||||||
# TLS listener (host port 9993): client certificate required
|
# TLS listener (host port 9993): client certificate required
|
||||||
listener 8883
|
listener 8883
|
||||||
protocol mqtt
|
protocol mqtt
|
||||||
|
allow_anonymous false
|
||||||
cafile $CERTDIR/ca.pem
|
cafile $CERTDIR/ca.pem
|
||||||
certfile $CERTDIR/cert.pem
|
certfile $CERTDIR/cert.pem
|
||||||
keyfile $CERTDIR/key.pem
|
keyfile $CERTDIR/key.pem
|
||||||
tls_version tlsv1.2
|
tls_version tlsv1.2
|
||||||
require_certificate true
|
require_certificate true
|
||||||
use_identity_as_username true
|
use_identity_as_username true
|
||||||
plugin_use password_file
|
plugin_use passwd
|
||||||
plugin_opt_password_file $PASSWD
|
plugin_use acl_tls
|
||||||
plugin_use acl_file
|
|
||||||
plugin_opt_acl_file $DATA/acl_tls
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# plain ACL
|
# plain ACL
|
||||||
echo "# Default ACL for the plain listener: no rules, all access denied" > "$CONFIG/acl_plain"
|
|
||||||
cat > "$CONFIG/acl_plain" <<EOF
|
cat > "$CONFIG/acl_plain" <<EOF
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# Not certified devices
|
# Not certified devices
|
||||||
# ============================================================
|
# ============================================================
|
||||||
user hamqtt
|
user hamqtt
|
||||||
|
|
||||||
# Test topic
|
|
||||||
topic readwrite test
|
|
||||||
# Initial enrollment
|
# Initial enrollment
|
||||||
topic write cert/enroll/+/request
|
topic write cert/enroll/+/request
|
||||||
topic read cert/enroll/+/issued
|
topic read cert/enroll/+/issued
|
||||||
@@ -97,16 +93,32 @@ user viracert
|
|||||||
topic read cert/enroll/+/request
|
topic read cert/enroll/+/request
|
||||||
topic write cert/enroll/+/issued
|
topic write cert/enroll/+/issued
|
||||||
topic read cert/enroll/+/renew
|
topic read cert/enroll/+/renew
|
||||||
|
topic read cert/enroll/+/renew-begin
|
||||||
|
topic write cert/enroll/+/challenge
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# TLS ACL
|
# TLS ACL
|
||||||
echo "# Default ACL for the TLS listener: no rules, all access denied" > "$CONFIG/acl_tls"
|
|
||||||
cat > "$CONFIG/acl_tls" <<EOF
|
cat > "$CONFIG/acl_tls" <<EOF
|
||||||
# Default rule for every certificate client. %u is the certificate CN.
|
# Default rule for every certificate client. %u is the certificate CN.
|
||||||
|
|
||||||
|
# data exchange topic
|
||||||
pattern readwrite clients/%u/#
|
pattern readwrite clients/%u/#
|
||||||
|
# discovery topic
|
||||||
|
pattern write vmqtt/sensor/%u/#
|
||||||
|
pattern write vmqtt/button/%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
|
EOF
|
||||||
|
|
||||||
# ---- User customization in /share (created once, never overwritten) ----
|
# ---- User customization in /share (created once, never overwritten) ----
|
||||||
|
if grep -qE '^\s*(listener|port|bind_address)\b' "$SHARE/mosquitto.conf"; then
|
||||||
|
echo "ERROR: $SHARE/mosquitto.conf must not define listeners (listener/port/bind_address)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -f "$SHARE/mosquitto.conf" ]; then
|
if [ ! -f "$SHARE/mosquitto.conf" ]; then
|
||||||
echo "# Extra global Mosquitto options (loaded with include_dir, before the listeners)" > "$SHARE/mosquitto.conf"
|
echo "# Extra global Mosquitto options (loaded with include_dir, before the listeners)" > "$SHARE/mosquitto.conf"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user