|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: L5 Session ยท Build flags: PC_ENABLE_SSH
A server's host key is what proves to a client that it is really talking to this device: the server signs the key exchange with it, and the client checks that signature against the key it trusts (its known_hosts). This example shows the two ways to give the server a host key, both starting from a key pair you generate on your workstation - never a key committed in the repo.
Use the bundled generator (needs openssl and ssh-keygen):
Each run prints a .pub line. Trust it on your client:
The private key is not committed and never leaves your machine. Keep it secret; anyone with it can impersonate your server.
**1 - at compile time (default).** The 32-byte Ed25519 seed from host_key.h is compiled into the firmware and installed in one call:
Simplest to get running; the key ships inside the image. Good for a fleet you flash yourself.
**2 - as a runtime service (NVS).** The RSA key lives in the device's NVS (namespace ssh_host_key, key priv_der). Write it once, then every boot just loads its public half - the private key is read per-signature into a stack buffer and wiped, so it is never held in RAM:
This keeps the key out of the firmware image and lets you rotate it without a rebuild (a provisioning portal, a factory step, an OTA-delivered blob). See docs/SSH.md "Host key provisioning".
The sketch has an inline public demo seed so it builds out of the box. It authenticates nothing. Generating a key in step 1 writes
host_key.h, which the sketch picks up automatically (__has_include) and uses instead - it is git-ignored so your private key never lands in a commit.
PC_ENABLE_SSH must reach the library build, so pass it as a build flag:
Then connect (the demo accepts password auth for admin):
If your client warns about a changed host key, it is because you regenerated the key in step 1 - update the known_hosts line to the new .pub.