diff options
author | Phil Pennock <pdp@exim.org> | 2012-06-24 02:55:29 -0700 |
---|---|---|
committer | Phil Pennock <pdp@exim.org> | 2012-06-24 02:55:29 -0700 |
commit | a5f239e4959d4df6a4a341d8855e14d17399d671 (patch) | |
tree | b146fc0467aa091e862fea4cbb038aaf3318aaa3 /src | |
parent | 585121e2682545b7afa599e039a7a1e2b1804570 (diff) |
Add gnutls_enable_pkcs11 option.
GnuTLS 2.12.0 adds PKCS11 support using p11-kit and by default will
autoload modules, which interoperates badly with GNOME keyring
integration, configured via paths in environment variables, and Exim
invoked by the user (eg, mailq) will then try to load the modules, fail
and spew warnings from the module for a library loaded by a library.
http://www.gnu.org/software/gnutls/manual/gnutls.html#Smart-cards-and-HSMs
documents that to prevent this, explicitly init PKCS11 before calling
gnutls_global_init(). So we do so, unless the admin sets the new
option.
Reported by Andreas Metzler, who confirmed that the added calls fixed
the problem for him.
Diffstat (limited to 'src')
-rw-r--r-- | src/README.UPDATING | 7 | ||||
-rw-r--r-- | src/src/globals.c | 1 | ||||
-rw-r--r-- | src/src/globals.h | 1 | ||||
-rw-r--r-- | src/src/readconf.c | 1 | ||||
-rw-r--r-- | src/src/tls-gnu.c | 27 |
5 files changed, 36 insertions, 1 deletions
diff --git a/src/README.UPDATING b/src/README.UPDATING index d34dec1e1..b7406f43c 100644 --- a/src/README.UPDATING +++ b/src/README.UPDATING @@ -26,6 +26,13 @@ The rest of this document contains information about changes in 4.xx releases that might affect a running system. +Exim version 4.81 +----------------- + + * New option gnutls_enable_pkcs11 defaults false; if you have GnuTLS 2.12.0 + or later and do want PKCS11 modules to be autoloaded, then set this option. + + Exim version 4.80 ----------------- diff --git a/src/src/globals.c b/src/src/globals.c index 97c7166ab..1faf75cda 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -117,6 +117,7 @@ tls_support tls_out = { #ifdef SUPPORT_TLS BOOL gnutls_compat_mode = FALSE; +BOOL gnutls_enable_pkcs11 = FALSE; uschar *gnutls_require_mac = NULL; uschar *gnutls_require_kx = NULL; uschar *gnutls_require_proto = NULL; diff --git a/src/src/globals.h b/src/src/globals.h index e910dbe1b..27c87b141 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -89,6 +89,7 @@ extern tls_support tls_out; #ifdef SUPPORT_TLS extern BOOL gnutls_compat_mode; /* Less security, more compatibility */ +extern BOOL gnutls_enable_pkcs11; /* Let GnuTLS autoload PKCS11 modules */ extern uschar *gnutls_require_mac; /* So some can be avoided */ extern uschar *gnutls_require_kx; /* So some can be avoided */ extern uschar *gnutls_require_proto; /* So some can be avoided */ diff --git a/src/src/readconf.c b/src/src/readconf.c index 750e0d316..087ab5b9b 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -236,6 +236,7 @@ static optionlist optionlist_config[] = { { "gecos_pattern", opt_stringptr, &gecos_pattern }, #ifdef SUPPORT_TLS { "gnutls_compat_mode", opt_bool, &gnutls_compat_mode }, + { "gnutls_enable_pkcs11", opt_bool, &gnutls_enable_pkcs11 }, /* These three gnutls_require_* options stopped working in Exim 4.80 */ { "gnutls_require_kx", opt_stringptr, &gnutls_require_kx }, { "gnutls_require_mac", opt_stringptr, &gnutls_require_mac }, diff --git a/src/src/tls-gnu.c b/src/src/tls-gnu.c index c582af79f..239985767 100644 --- a/src/src/tls-gnu.c +++ b/src/src/tls-gnu.c @@ -39,6 +39,10 @@ require current GnuTLS, then we'll drop support for the ancient libraries). #include <gnutls/x509.h> /* man-page is incorrect, gnutls_rnd() is not in gnutls.h: */ #include <gnutls/crypto.h> +/* needed to disable PKCS11 autoload unless requested */ +#if GNUTLS_VERSION_NUMBER >= 0x020c00 +# include <gnutls/pkcs11.h> +#endif /* GnuTLS 2 vs 3 @@ -172,6 +176,7 @@ before, for now. */ #define HAVE_GNUTLS_SESSION_CHANNEL_BINDING #define HAVE_GNUTLS_SEC_PARAM_CONSTANTS #define HAVE_GNUTLS_RND +#define HAVE_GNUTLS_PKCS11 #endif @@ -911,6 +916,19 @@ if (!exim_gnutls_base_init_done) { DEBUG(D_tls) debug_printf("GnuTLS global init required.\n"); +#ifdef HAVE_GNUTLS_PKCS11 + /* By default, gnutls_global_init will init PKCS11 support in auto mode, + which loads modules from a config file, which sounds good and may be wanted + by some sysadmin, but also means in common configurations that GNOME keyring + environment variables are used and so breaks for users calling mailq. + To prevent this, we init PKCS11 first, which is the documented approach. */ + if (!gnutls_enable_pkcs11) + { + rc = gnutls_pkcs11_init(GNUTLS_PKCS11_FLAG_MANUAL, NULL); + exim_gnutls_err_check(US"gnutls_pkcs11_init"); + } +#endif + rc = gnutls_global_init(); exim_gnutls_err_check(US"gnutls_global_init"); @@ -970,7 +988,7 @@ if (rc != OK) return rc; /* set SNI in client, only */ if (host) { - if (!expand_check(state->tlsp->sni, "tls_out_sni", &state->exp_tls_sni)) + if (!expand_check(state->tlsp->sni, US"tls_out_sni", &state->exp_tls_sni)) return DEFER; if (state->exp_tls_sni && *state->exp_tls_sni) { @@ -1945,6 +1963,13 @@ if (exim_gnutls_base_init_done) log_write(0, LOG_MAIN|LOG_PANIC, "already initialised GnuTLS, Exim developer bug"); +#ifdef HAVE_GNUTLS_PKCS11 +if (!gnutls_enable_pkcs11) + { + rc = gnutls_pkcs11_init(GNUTLS_PKCS11_FLAG_MANUAL, NULL); + validate_check_rc(US"gnutls_pkcs11_init"); + } +#endif rc = gnutls_global_init(); validate_check_rc(US"gnutls_global_init()"); exim_gnutls_base_init_done = TRUE; |