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

SSL Certificate renewal #70

Open
JanWielemaker opened this issue Dec 13, 2016 · 4 comments
Open

SSL Certificate renewal #70

JanWielemaker opened this issue Dec 13, 2016 · 4 comments

Comments

@JanWielemaker
Copy link
Member

Just setup a server using LetsEncrypt! Thanks to https://github.com/triska/letswicrypt that wasn't too hard. LetsEncrypt! certificates expire quickly though. Setting up automatic renewal of the certificates themselves isn't too hard, but how to update a (long) running server?

Ideally it would check the modification times of the certifications, but it can't because the LetsEncrypt! certificates are only readable by root and the server long lost the privileges to read them. I see two ways out:

  • Encrypt the private key and only read the password as root. If the key itself and the certificate
    chain are world readable (which is fine AFAIK as long as the private key is encrypted), it should
    be possible to update the SSL context used by the server without restart.
  • On startup read the expiration date from the certificate and commit suicide at some scheduled
    time the day before.
@triska
Copy link
Member

triska commented Dec 14, 2016

I have added instructions to LetSWICrypt that describe how to renew the certificate without root permissions, please have a look. Simply set up a cron job (as a regular user) that renews the certificate if necessary, and restart your server to load the new certificate. This leads to a short downtime every 2 months or so.

Note also that you can use sni_hook/1 to get zero downtime already now (assuming client-side SNI of course): You can fetch the most recent certificate regularly, and supply it in the hook for each request.

In 7.5., I may work on exchanging certificate and key for a running SSL server.

@triska
Copy link
Member

triska commented Dec 26, 2016

The new ssl_add_certificate_key/3 predicate proposed in SWI-Prolog/packages-ssl#86 lets you update the certificate of an already created context.

Pending comments from OpenSSL developers whether this is an officially supported way to update the certificate: openssl/openssl#2147.

If this works as intended, then we only need a hook that provides access to the SSL context of an HTTPS server. Given the context, we can easily update the certificates. Such a hook is necessary in any case, to add further certificates etc., as discussed in #77.

@triska
Copy link
Member

triska commented Dec 28, 2016

All of this is solved in SWI-Prolog/packages-ssl#87, please try it out!

@triska
Copy link
Member

triska commented Jan 8, 2017

This is possible as of SWI-Prolog 7.3.34, and documented in the new section:

Exchanging certificates

You can use the predicates of library(ssl) to detect when it is time to renew a certificate, or rely on Let's Ecrypt to renew it automatically, and then simply use the updated certificate to negotiate new connections.

Remarkably, this can all be implemented in a thread-safe way in SWI-Prolog, although the underlying OpenSSL library is not thread-safe for this use case!

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

No branches or pull requests

2 participants