You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8106a32
Browse filesBrowse the repository at this point in the historyBrowse files
Device certificates: optional encrypted key with a passphrase hook
- DeviceCertificates(key_passphrase=...): a string, bytes, or a function
called each time the key is loaded. Keys are written encrypted, and a
key stored unencrypted is encrypted when first loaded with one.
- The connection passes it to load_cert_chain. A key that can't be
loaded, e.g. the passphrase isn't available, is retried with backoff,
not treated as the server refusing the certificate.
- docs/connections.md: supplying the passphrase from a systemd
credential (systemd-creds, LoadCredentialEncrypted), and what that
protects with and without a TPM.
Tested on dash.dashio.io: a plain key encrypted on first load, then a
certificate login with it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CLAUDE.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,7 @@ Notes for working on python-dashio, the Python library for the DashIO protocol a
89
89
- The DashConnection takes the certificate from its one device (a second device raises `ValueError`), and makes a new paho client when it changes login: client ID `d-<device_id>` and `tls_set_context` for port 8885, a random client ID for 8883, because the broker refuses `d-` client IDs on password logins.
90
90
- A certificate not yet used to log in (PENDING, or a renewal) is checked first with a TLS handshake and a short read (`_check_certificate()`): with TLS 1.3 the broker refuses a client certificate with an alert after the handshake, which paho only reports as a lost connection. Refused: PENDING falls back to the password for an hour and reports 420; a renewal rolls back to the previous certificate. Unreachable: check again with backoff.
91
91
- On the first certificate login the connection erases its password and `state_callback("CERT")` lets the program erase its copy. A new Dash login from the app (the DASHIO message, when the dashio callback accepts it) calls `reset()`: back to PASSWORD, keys deleted.
92
+
-`key_passphrase` (a string, bytes, or a function called on each load) keeps the keys encrypted (PKCS8 `BestAvailableEncryption`); a plain key is encrypted when first loaded with one. The connection passes it to `load_cert_chain(password=)`. A key that can't be loaded is retried with backoff, never treated as a refusal. The docs recommend a systemd credential (`LoadCredentialEncrypted`) for the passphrase.
92
93
- The DashIO Server CA is bundled as `dashio/certs/dashio-server-ca.crt` (package data). `cryptography` is a dependency.
93
94
-**`DashStore` and history upload (SDU):** a port of the firmware's DashIO Storage Manager (`../zephyr-dashio-tally/port.md`, ESP-IDF port in `../dashesp/components/dashio_dsm`), using sqlite instead of a flash ring buffer.
94
95
-`Device(..., store=DashStore(path))` gives every TimeGraph, EventLog and Map on the device the store (`control._store`). They record into it as well as their ring buffers, and answer the app's history requests from it.
Copy file name to clipboardExpand all lines: docs/connections.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,48 @@ dash.add_device(device)
97
97
- The server's certificate on port 8885 is checked against the DashIO Server CA, which comes with the library.
98
98
-`certificates.state` and `certificates.info()` give the state and the certificate's serial number and expiry. The Dash app can also read them, and provision a certificate, over any connection.
99
99
100
+
#### Encrypting the key
101
+
102
+
By default the private key is protected only by its file's permissions: root, or anyone with the device's disk, can read it. `key_passphrase` keeps it encrypted, with a passphrase from somewhere else:
`key_passphrase` is a string, bytes, or a function returning one, called each time the key is loaded. A trailing newline is ignored. A key already stored unencrypted is encrypted the first time it's loaded with a passphrase. If the passphrase isn't available, the connection logs an error and tries again later, waiting twice as long each time; it doesn't count as the server refusing the certificate. If it's lost, the key can't be used again, and the device needs a new certificate, e.g. by setting its Dash login again from the app.
109
+
110
+
On Linux, run the device as a systemd service (systemd 250 or later, e.g. Raspberry Pi OS Bookworm) and keep the passphrase as an encrypted systemd credential. Make the passphrase and encrypt it:
-**With a TPM** (`systemd-creds has-tpm2`), the credential is sealed to the TPM. Copying the disk to another machine gets neither the passphrase nor the key. Add `--with-key=tpm2` to `systemd-creds encrypt` to refuse to make it without one.
138
+
-**Without a TPM**, as on a Raspberry Pi, it's sealed with a key in `/var/lib/systemd/credential.secret`, readable only by root. The key file can't be used by other users, or from a copy of the program's directory or a backup of it, but someone with root or the whole disk can still decrypt it. Full disk encryption adds to this.
139
+
140
+
Either way, revoking the device in the Dash app cuts off a stolen key.
Copy file name to clipboardExpand all lines: skills/python-dashio/SKILL.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,7 @@ while True:
141
141
-**Receive callbacks can reply:** a callback's returned string is sent back to the app.
142
142
-**Through the Dash server**, control updates are only published while a Dash app is watching the device (`app_timeout`, 120 s by default); replies, alarms and history always go. A device that seems silent with the app closed is working as designed.
143
143
- History for TimeGraph, EventLog and Map: `Device(..., store=dashio.DashStore(path))` keeps it in sqlite and answers the app's history requests. See [storage.md](https://github.com/dashio-connect/python-dashio/blob/master/docs/storage.md).
144
-
-**Device certificates:**`Device(..., certificates=dashio.DeviceCertificates(path, state_callback=...))` logs in to the Dash server on port 8885 with the device's own certificate. The device gets one from the server over its password login, then erases the password once the certificate has worked (state `CERT`; erase the stored copy in `state_callback`). A DashConnection with certificates has one device. See [connections.md](https://github.com/dashio-connect/python-dashio/blob/master/docs/connections.md#device-certificates).
144
+
-**Device certificates:**`Device(..., certificates=dashio.DeviceCertificates(path, state_callback=...))` logs in to the Dash server on port 8885 with the device's own certificate. The device gets one from the server over its password login, then erases the password once the certificate has worked (state `CERT`; erase the stored copy in `state_callback`). A DashConnection with certificates has one device. `key_passphrase=` keeps the key encrypted; on Linux, supply it from a systemd credential. See [connections.md](https://github.com/dashio-connect/python-dashio/blob/master/docs/connections.md#device-certificates).
145
145
- To start a line, track or log again on the device and the Dash server (factory reset, sensor swapped): `control.delete_history()`. For a Map marker that only shows the current position: `map.add_track(dashio.MapTrack("pos", "Here", replace=True))`.
0 commit comments