Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate SSL key and csr on device and support installing a certificate via MQTT #15

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mattbnz
Copy link
Contributor

@mattbnz mattbnz commented Sep 7, 2022

I'd like to be able to have new devices self-register for secure MQTT without having to generate and transfer keys/certs off the device and then flash them on via a full filesytem update.

This adds the necessary logic to have the device itself generate a new key and associated CSR which it will submit via MQTT, and then await receipt of a signed certificate via a return MQTT message. How and if the server actually signs/generates the certs and sends it back is left up to the user, as its likely to be highly context specific.

This is step 1 towards providing an improved "first boot with SSL"
experience.
Struggling with stack size here...
Generating a key requires a reasonable number of multi-kb buffers. If we
naively put those on the stack we have to enlarge the stack size for the
MQTT task, which permanently denies other tasks use of that memory, even
though it's going to be almost always unused in the MQTT stack given key
generation is a very rare operation. Allocating these buffers explicitly
on the heap means the memory is free for everything else to use the rest
of the time.
This allows the server to pass back a signed certificate for the
monitor, which will check it is signed by the trusted CA and matches the
private key previously generated by a requestCert/regenerateKey command
and then install it and reboot.

This is fully functional for bootstrapping SSL on a device now, but not
yet production ready - need further support for updating config, etc
first.
@oseiler2
Copy link
Owner

Can you give this branch a try please?
https://github.com/oseiler2/CO2Monitor/tree/feature/csr

@mattbnz
Copy link
Contributor Author

mattbnz commented Sep 19, 2022

What are the changes? It's a bit tedious to get a diff between what's in this pull request and what's in the branch because of the changed filenames, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants