Discussion:
[gnutls-help] TLS-Server with Let’s Encrypt
Mario Lombardo
7 years ago
Permalink
Hi gnutls team,

I’m looking for a way how to use gnutls for a TLS server in combination with Let’s Encrypt. As the validity of those certificates is just a couple of weeks, I would like to replace the current server key by new ones without restarting the server.

The implementation is basically like this:
// create credstore
gnutls_certificate_allocate_credentials(&(ctx->tls_x509_cred));
// load x509 key pair
gtls_returncode = gnutls_certificate_set_x509_key_file(ctx->tls_x509_cred, ctx->config->cert_bundle, ctx->config->key_file, GNUTLS_X509_FMT_PEM);
// install signal handler
signal(SIGUSR1, signal_handler);

Once the signal SIGUSR1 arrives, I would like to re-read x509 stuff.

The only solution I found (yet) is to free the credstore and allocate a new one (then read new keys). This has some downsides, as the server is not working anymore if there is something wrong with the key pair, because I already freed the existing credstore (here ctx->tls_x509_cred). And even this is the only way to proceed…do I need to block any incoming connections in the meantime? How long (in the process of the handshake) is blocking required (in other words: do I need to track if there are existing sockets in the handshake phase or is this safe as long as one handshake try for non-blocking sockets was done)?

Is there any reference code/function to replace a key pair? I had a look into the apache2 module but as it seems, this module does not support a certificate change on reload.

Any hints are welcome.

Thank you.

Mario
Sam Varshavchik
7 years ago
Permalink
...
Instead of gnutls_certificate_free_credentials() your old credential store
first, and then gnutls_certificate_allocate_credentials() a new one and hope
for the best, why don't you try gnutls_certificate_allocate_credentials()
first, and if your endeavor succeeds you can free the old one, and replace
it with the new one.

You are gnutls_certificate_free_credentials() your old credential store
first, right? Because if this is all what you do, that's shown above, then
you must be leaking memory.
Mario Lombardo
7 years ago
Permalink
Hi Sam,

thank you for your message. What about the existing sessions (gnutls_session_t)? Can I call gnutls_credentials_clear() once the handshake is finished and keep the connection for this session established? I believe it is not safe to gnutls_certificate_free_credentials() as long as there are sessions bound to this store, is it?

Or is there any other best practice? Can I set other credentials on an existing session (after handshake)?

Thanks in advance.

Mario
...
Sam Varshavchik
7 years ago
Permalink
Post by Mario Lombardo
Hi Sam,
thank you for your message. What about the existing sessions
(gnutls_session_t)? Can I call gnutls_credentials_clear() once the handshake
is finished and keep the connection for this session established? I believe
it is not safe to gnutls_certificate_free_credentials() as long as there are
sessions bound to this store, is it?
Presuming there are no multiple thread-related issues, I would expect it to
be safe. If the library needs it, for some reason, I expect it to make its
own copy. I find nothing in the public documentation that requires
credential to exist as long as some session that used them, initially, is
still around.
Post by Mario Lombardo
Or is there any other best practice? Can I set other credentials on an
existing session (after handshake)?
You can also take the approach of creating a new context for all new
sessions, and keep the old context, with the old credentials, until all
existing session which use it go away. I don't believe this is necessary,
but this is also one possible way to do it.

Loading...