Skip to content

Commit

Permalink
Fix #393: defer setting GnuTLS CA trust to ssl_open()
Browse files Browse the repository at this point in the history
As mentioned in #391, setting the CA trust for the OpenSSL backend is
deferred to ssl_open().  This patch defers the GnuTLS CA init in a
similar fashion, allowing a custom user-defined trust file to be set
also when using the GnuTLS backend.

Verified manually with the FreeDNS plugin and three different CA files:

 - /etc/ssl/certs/ca-certificates.crt (everything works, CAFILE1)
 - /etc/ssl/certs/UCA_Global_G2_Root.pem (validation fails, expected)
 - /usr/share/ca-certificates/mozilla/USERTrust_RSA_Certification_Authority.crt (works)

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Oct 2, 2022
1 parent db1b075 commit 0dd3efa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ static int ssl_set_ca_location(void)

/* A user defined CA PEM bundle overrides any built-ins or fall-backs */
if (ca_trust_file) {
logit(LOG_DEBUG, "Using CA PEM bundle: %s", ca_trust_file);
num = gnutls_certificate_set_x509_trust_file(xcred, ca_trust_file, GNUTLS_X509_FMT_PEM);
goto done;
}
Expand Down Expand Up @@ -154,11 +155,6 @@ int ssl_init(void)

/* X509 stuff */
gnutls_certificate_allocate_credentials(&xcred);

/* Try to figure out location of trusted CA certs on system */
if (ssl_set_ca_location())
return RC_HTTPS_NO_TRUSTED_CA_STORE;

gnutls_certificate_set_verify_function(xcred, verify_certificate_callback);

return 0;
Expand Down Expand Up @@ -200,6 +196,10 @@ int ssl_open(http_t *client, char *msg)
if (!client->ssl_enabled)
return tcp_init(&client->tcp, msg);

/* Try to figure out location of trusted CA certs on system */
if (ssl_set_ca_location())
return RC_HTTPS_NO_TRUSTED_CA_STORE;

/* Initialize TLS session */
logit(LOG_INFO, "%s, initiating HTTPS ...", msg);
gnutls_init(&client->ssl, GNUTLS_CLIENT);
Expand Down

0 comments on commit 0dd3efa

Please sign in to comment.