From: David Woodhouse Date: Sun, 10 Jun 2012 20:15:14 +0000 (+0100) Subject: GnuTLS: Fix build with GnuTLS 2.12 and PKCS#11 X-Git-Tag: v3.99~48 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=08f481b7a0d60486f2283bb138df480e0cbb65d9;p=users%2Fdwmw2%2Fopenconnect.git GnuTLS: Fix build with GnuTLS 2.12 and PKCS#11 Signed-off-by: David Woodhouse --- diff --git a/gnutls.c b/gnutls.c index 3d020609..e26a66ca 100644 --- a/gnutls.c +++ b/gnutls.c @@ -51,6 +51,9 @@ static P11KitPin *pin_callback(const char *pin_source, P11KitUri *pin_uri, const char *pin_description, P11KitPinFlags flags, void *_vpninfo); +#if GNUTLS_VERSION_MAJOR >= 3 +#define HAVE_P11KIT_AND_GNUTLS_3 +#endif #endif #include "openconnect-internal.h" @@ -476,6 +479,24 @@ static int load_certificate(struct openconnect_info *vpninfo) /* Load certificate(s) first... */ #ifdef HAVE_P11KIT +#ifndef HAVE_P11KIT_AND_GNUTLS_3 + if (key_is_p11) { + /* With GnuTLS 2.12 we can't *see* the key so we can't + do the expiry check or fill in intermediate CAs. */ + err = gnutls_certificate_set_x509_key_file(vpninfo->https_cred, + cert_url, key_url, + GNUTLS_X509_FMT_PEM); + if (err) { + vpn_progress(vpninfo, PRG_ERR, + _("Error loading PKCS#11 certificate: %s\n"), + gnutls_strerror(err)); + ret = -EIO; + goto out; + } + ret = 0; + goto out; + } +#endif if (cert_is_p11) { vpn_progress(vpninfo, PRG_TRACE, _("Using PKCS#11 certificate %s\n"), cert_url); @@ -561,10 +582,10 @@ static int load_certificate(struct openconnect_info *vpninfo) nr_extra_certs = err; err = 0; - - /* Now we have the certificate(s) and we're looking for the private key... */ -#ifdef HAVE_P11KIT + goto got_certs; got_certs: + /* Now we have the certificate(s) and we're looking for the private key... */ +#ifdef HAVE_P11KIT_AND_GNUTLS_3 if (key_is_p11) { gnutls_pkcs11_privkey_t p11key = NULL; @@ -824,7 +845,7 @@ static int load_certificate(struct openconnect_info *vpninfo) _("Adding supporting CA '%s'\n"), name); } -#ifdef HAVE_P11KIT +#ifdef HAVE_P11KIT_AND_GNUTLS_3 if (pkey) { /* Ug. If we got a gnutls_privkey_t from PKCS#11 rather than the gnutls_x509_privkey_t that we get from PEM or PKCS#12 files, then