# MQTT Certificate Manager (Home Assistant add-on) Issues and manages TLS client certificates for MQTT nodes from a local, self-signed CA — no external CA or internet dependency. ## How it works 0. On first boot, the add-on also issues a TLS **server** certificate for the broker itself (signed by the same local CA) and writes it — plus the CA cert — into Home Assistant's shared `/ssl` folder. Open the add-on's "Broker TLS certificate" section for the exact `certfile` / `keyfile` / `cafile` values to paste into the Mosquitto add-on's config, then set `require_certificate: true` there and restart Mosquitto. The `broker_hostnames` option (comma-separated) controls what hostnames/IPs the cert is valid for — add your LAN hostname or static IP here if devices reach the broker by something other than `core-mosquitto`. 1. A node generates its own key pair + CSR and publishes it over MQTT. 2. The add-on picks it up and lists it as a pending request in its web UI (available as a Home Assistant sidebar panel via ingress). 3. You review and click Approve. 4. The add-on's local CA signs the cert and publishes it (+ the CA cert) back to the node over a retained MQTT topic. 5. The node installs the cert and reconnects to the broker over mTLS. 6. If you later revoke a device's cert from the UI, the add-on rewrites the CRL at `/ssl/mqtt-cert-manager-crl.pem` and clears the device's retained MQTT cert. Point Mosquitto's `crlfile` option at that file — it's only reloaded on **restart**, not live, so a revocation doesn't take effect until Mosquitto restarts. Full device-side wire protocol: see `DEVICE_PROTOCOL.md`. ## Installing this application 1. Add [virarepo repository](https://gitea.viratak.com/bitopa/virarepo) in applications section 2. Look for this project, and click install ## Offline Installing this application 1. Copy this folder into your Home Assistant add-ons repository (or add it as a local add-on under `/addons/mqtt_cert_manager` on HAOS). 2. In Settings → Add-ons → Add-on store → ⋮ → Repositories, add your repo if it's not local, then install "MQTT Certificate Manager". 3. Configure the options (mqtt_host defaults to `core-mosquitto`, which is correct if you're using the official Mosquitto broker add-on). 4. Start the add-on and open it from the sidebar. ## What's included in this scaffold - `config.yaml` / `build.yaml` — add-on manifest, current (2026) HA base image convention. **Double check `build.yaml` against https://github.com/home-assistant/docker-base if your Supervisor version is very new or old** — base image tags do change. - `app/ca.py` — root CA generation + CSR signing (RSA-4096 root, 20-year validity; issued certs default to 825 days, matching common CT/browser practice, though these are just client certs so it's a soft ceiling you control via the `cert_validity_days` option). - `app/mqtt_worker.py` — subscribes for requests, publishes issued/rejected. - `app/store.py` — flat JSON store for pending/issued state in `/data`. - `app/main.py` + `app/templates`, `app/static` — Flask app and the approve/reject UI. ## Access control The web UI and its `/api/*` endpoints have **no login of their own**. They rely entirely on two things, both required together: 1. `config.yaml` has no `ports:` entry, so Supervisor never exposes port 8099 to your LAN or host — the only path in is Supervisor's ingress proxy, which requires an authenticated Home Assistant session. 2. `main.py` rejects any request whose source IP isn't Supervisor's fixed internal proxy address (`172.30.32.2`), per HA's own guidance for ingress-only add-ons. Without this, any other add-on on the same internal Docker network could call `/api/approve/...` directly and bypass HA login entirely. If you ever add a `ports:` mapping for direct access (e.g. for local testing outside HA), you must add real authentication first — the IP guard alone won't help once the port is exposed to the LAN. ## Known gaps to close before production use - **Mosquitto still requires a username/password per device even with a client cert.** The official Mosquitto add-on's auth plugin doesn't reliably support `use_identity_as_username` (cert-only auth) — you'll need to give each device MQTT login credentials in addition to its cert. The cert still buys you encryption + mutual authentication; it just isn't a full substitute for a password on this particular broker add-on. - **Auto-renewal exists, but only for cert holders in good standing.** Within `renewal_window_days` of expiry, a device can renew without a human clicking Approve — but only by signing a proof-of-possession message with its *current* private key (see `DEVICE_PROTOCOL.md` §5). Anything that fails that check (wrong key, revoked, too early, stale timestamp, never enrolled before) falls back to the normal manual queue rather than being silently issued or silently dropped. - **Revocation requires a Mosquitto restart to take effect.** CRL support is in (`/api/revoke`, `write_crl()`), but there's no push mechanism to restart Mosquitto automatically — you have to do it yourself after revoking. No OCSP either; CRL-only. - **No shared enrollment secret.** The human-approval step is the only gate on the bootstrap channel right now; see the security note in DEVICE_PROTOCOL.md if you want an extra layer. - I haven't built or run this against a live Supervisor — treat it as a solid, working starting point rather than a tested release. The Python logic (CA, signing, MQTT topics) is self-contained and testable outside Home Assistant if you want to validate it first with a local Mosquitto broker.