libwebsockets
Lightweight C library for HTML5 websockets
|
lws-acme-client is a protcol plugin for libwebsockets that implements an ACME client able to communicate with let's encrypt and other certificate providers.
It implements tls-sni-01
challenge, and is able to provision tls certificates "from thin air" that are accepted by all the major browsers. It also manages re-requesting the certificate when it only has two weeks left to run.
It works with both the OpenSSL and mbedTLS backends.
You need to:
After that the plugin will sort everything else out.
Notice that the "host-ssl-cert"
and "host-ssl-key"
entries have the same meaning as usual, they point to your certificate and private key. However because the ACME plugin can provision these, you should also mark the vhost with "ignore-missing-cert" : "1"
, so lwsws will ignore what will initially be missing certificate / keys on that vhost, and will set about creating the necessary certs and keys instead of erroring out.
You must make sure the directories mentioned here exist, lws doesn't create them for you. They should be 0700 root:root, even if you drop lws privileges.
If you are implementing support in code, this corresponds to making sure the vhost creating info.options
has the LWS_SERVER_OPTION_IGNORE_MISSING_CERT
bit set.
Similarly, in code, the each of the per-vhost options shown above can be provided in a linked-list of structs at vhost creation time. See ./test-apps/test-server-v2.0.c
for example code for providing pvos.
This is where the plugin will store the auth keys it generated.
Where the plugin will store the certificate file. Should match host-ssl-cert
that the vhost wants to use.
The path should include at least one 0700 root:root directory.
Where the plugin will store the certificate keys. Again it should match host-ssl-key
the vhost is trying to use.
The path should include at least one 0700 root:root directory.
This defines the URL of the certification server you will get your certificates from. For let's encrypt, they have a "practice" one
and they have a "real" one
the main difference is the CA certificate for the real one is in most browsers already, but the staging one's CA certificate isn't. The staging server will also let you abuse it more in terms of repeated testing etc.
It's recommended you confirm expected operation with the staging directory-url, and then switch to the "real" URL.
Your server DNS name, like "libwebsockets.org". The remote ACME server will use this to find your server to perform the SNI challenges.
The contact email address for the certificate.
These are not included in the cert by letsencrypt
Two-letter country code for the certificate
State "or province" for the certificate
Locality for the certificate
Your company name
The lws-acme-client
plugin is able to provision and update your certificate and keys in an entirely root-only storage environment, even though lws runs as a different uid / gid with no privileges to access the storage dir.
It does this by opening and holding two WRONLY fds on "update paths" inside the root directory structure for each cert and key it manages; these are the normal cert and key paths with .upd
appended. If during the time the server is up the certs become within two weeks of expiry, the lws-acme-client
plugin will negotiate new certs and write them to the file descriptors.
Next time the server starts, if it sees .upd
cert and keys, it will back up the old ones and copy them into place as the new ones, before dropping privs.
To also handle the long-uptime server case, lws will update the vhost with the new certs using in-memory temporary copies of the cert and key after updating the cert.
In this way the cert and key live in root-only storage but the vhost is kept up to date dynamically with any cert changes as well.
In the case you have multiple vhosts using of the same cert, just attach the lws-acme-client
plugin to one instance. When the cert updates, all the vhosts are informed and vhosts using the same filepath to access the cert will be able to update their cert.
You will need to remove the auth keys when switching from OpenSSL to mbedTLS. They will be regenerated automatically. It's the file at this path: