summaryrefslogtreecommitdiffstats
path: root/dirmngr/http.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2016-04-26 21:57:56 +0200
committerWerner Koch <wk@gnupg.org>2016-04-26 21:57:56 +0200
commitfd765df6a7883c3d841abeb657330a1aab4b7756 (patch)
tree9f267dcc9800f1aa3461948079c767a5fe6d86d4 /dirmngr/http.c
parentgpg: Add OpenPGP card vendor 0x2342. (diff)
downloadgnupg2-fd765df6a7883c3d841abeb657330a1aab4b7756.tar.xz
gnupg2-fd765df6a7883c3d841abeb657330a1aab4b7756.zip
http: Allow to request system defined CAs for TLS.
* dirmngr/http.h (HTTP_FLAG_TRUST_DEF, HTTP_FLAG_TRUST_SYS): New. * dirmngr/http.c (http_session_new): Add arg "flags". * dirmngr/ks-engine-hkp.c (send_request): Use new flag HTTP_FLAG_TRUST_DEF for the new arg of http_session_new. * dirmngr/ks-engine-http.c (ks_http_fetch): Ditto. * dirmngr/t-http.c (main): Ditto. -- Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'dirmngr/http.c')
-rw-r--r--dirmngr/http.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/dirmngr/http.c b/dirmngr/http.c
index aa33917be..f0fcd0d75 100644
--- a/dirmngr/http.c
+++ b/dirmngr/http.c
@@ -560,10 +560,14 @@ http_session_release (http_session_t sess)
/* Create a new session object which is currently used to enable TLS
- support. It may eventually allow reusing existing connections. */
+ * support. It may eventually allow reusing existing connections.
+ * Valid values for FLAGS are:
+ * HTTP_FLAG_TRUST_DEF - Use the CAs set with http_register_tls_ca
+ * HTTP_FLAG_TRUST_SYS - Also use the CAs defined by the system
+ */
gpg_error_t
http_session_new (http_session_t *r_session, const char *tls_priority,
- const char *intended_hostname)
+ const char *intended_hostname, unsigned int flags)
{
gpg_error_t err;
http_session_t sess;
@@ -629,14 +633,34 @@ http_session_new (http_session_t *r_session, const char *tls_priority,
}
/* Add configured certificates to the session. */
- for (sl = tls_ca_certlist; sl; sl = sl->next)
+ if ((flags & HTTP_FLAG_TRUST_DEF))
+ {
+ for (sl = tls_ca_certlist; sl; sl = sl->next)
+ {
+ rc = gnutls_certificate_set_x509_trust_file
+ (sess->certcred, sl->d,
+ (sl->flags & 1)? GNUTLS_X509_FMT_PEM : GNUTLS_X509_FMT_DER);
+ if (rc < 0)
+ log_info ("setting CA from file '%s' failed: %s\n",
+ sl->d, gnutls_strerror (rc));
+ }
+ }
+
+ /* Add system certificates to the session. */
+ if ((flags & HTTP_FLAG_TRUST_SYS))
{
- rc = gnutls_certificate_set_x509_trust_file
- (sess->certcred, sl->d,
- (sl->flags & 1)? GNUTLS_X509_FMT_PEM : GNUTLS_X509_FMT_DER);
+#if GNUTLS_VERSION_NUMBER >= 0x030014
+ static int shown;
+
+ rc = gnutls_certificate_set_x509_system_trust (sess->certcred);
if (rc < 0)
- log_info ("setting CA from file '%s' failed: %s\n",
- sl->d, gnutls_strerror (rc));
+ log_info ("setting system CAs failed: %s\n", gnutls_strerror (rc));
+ else if (!shown)
+ {
+ shown = 1;
+ log_info ("number of system provided CAs: %d\n", rc);
+ }
+#endif /* gnutls >= 3.0.20 */
}
rc = gnutls_init (&sess->tls_session, GNUTLS_CLIENT);