From: Nikos Mavrogiannopoulos Date: Mon, 1 Aug 2011 18:39:18 +0000 (+0200) Subject: the deprecated_config_file from 2.12.x was incorporated. X-Git-Tag: gnutls_3_0_1~15^2~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd2e6e3f249056c8caa00b109971727cd40e03a7;p=thirdparty%2Fgnutls.git the deprecated_config_file from 2.12.x was incorporated. --- diff --git a/NEWS b/NEWS index eddafc4670..639fb20b71 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ See the end for copying conditions. * Version 3.0.1 (unreleased) +** libgnutls: The config file at gnutls_pkcs11_init() +is being read if provided. + ** libgnutls: Verify that a certificate liste specified using gnutls_certificate_set_x509_key*(), is sorted according to TLS specification (from subject to issuer). diff --git a/lib/includes/gnutls/pkcs11.h b/lib/includes/gnutls/pkcs11.h index 420674962c..b08d9bf630 100644 --- a/lib/includes/gnutls/pkcs11.h +++ b/lib/includes/gnutls/pkcs11.h @@ -57,7 +57,7 @@ typedef struct gnutls_pkcs11_obj_st *gnutls_pkcs11_obj_t; * load = /lib/yyy-pkcs11.so */ -int gnutls_pkcs11_init (unsigned int flags, void *unused); +int gnutls_pkcs11_init (unsigned int flags, const char *deprecated_config_file); void gnutls_pkcs11_deinit (void); void gnutls_pkcs11_set_token_function (gnutls_pkcs11_token_callback_t fn, void *userdata); diff --git a/lib/pkcs11.c b/lib/pkcs11.c index a547b2f549..6e3df7d853 100644 --- a/lib/pkcs11.c +++ b/lib/pkcs11.c @@ -417,13 +417,15 @@ static int init = 0; /* tries to load modules from /etc/gnutls/pkcs11.conf if it exists */ -static void _pkcs11_compat_init(void) +static void _pkcs11_compat_init(const char* configfile) { FILE *fp; int ret; char line[512]; const char *library; -const char* configfile = "/etc/gnutls/pkcs11.conf"; + + if (configfile == NULL) + configfile = "/etc/gnutls/pkcs11.conf"; fp = fopen (configfile, "r"); if (fp == NULL) @@ -461,10 +463,46 @@ const char* configfile = "/etc/gnutls/pkcs11.conf"; return; } +static int +initialize_automatic_p11_kit (void) +{ + struct ck_function_list **modules; + const char *name; + ck_rv_t rv; + int i, ret; + + rv = p11_kit_initialize_registered (); + if (rv != CKR_OK) + { + gnutls_assert (); + _gnutls_debug_log ("Cannot initialize registered module: %s\n", + p11_kit_strerror (rv)); + return GNUTLS_E_INTERNAL_ERROR; + } + + initialized_registered = 1; + + modules = p11_kit_registered_modules (); + for (i = 0; modules[i] != NULL; i++) + { + name = p11_kit_registered_module_to_name (modules[i]); + ret = pkcs11_add_module (name, modules[i]); + if (ret != 0) + { + gnutls_assert (); + _gnutls_debug_log ("Cannot add registered module: %s\n", name); + } + } + + free (modules); + return 0; +} + /** * gnutls_pkcs11_init: * @flags: %GNUTLS_PKCS11_FLAG_MANUAL or %GNUTLS_PKCS11_FLAG_AUTO - * @unused: unused must be set to NULL + * @deprecated_config_file: either NULL or the location of a deprecated + * configuration file * * This function will initialize the PKCS 11 subsystem in gnutls. It will * read configuration files if %GNUTLS_PKCS11_FLAG_AUTO is used or allow @@ -479,12 +517,9 @@ const char* configfile = "/etc/gnutls/pkcs11.conf"; * negative error value. **/ int -gnutls_pkcs11_init (unsigned int flags, void *unused) +gnutls_pkcs11_init (unsigned int flags, const char *deprecated_config_file) { - struct ck_function_list **modules; - const char *name; - ck_rv_t rv; - int i, ret; + int ret = 0; if (init != 0) { @@ -497,33 +532,14 @@ gnutls_pkcs11_init (unsigned int flags, void *unused) return 0; else if (flags == GNUTLS_PKCS11_FLAG_AUTO) { - rv = p11_kit_initialize_registered (); - if (rv != CKR_OK) - { - gnutls_assert (); - _gnutls_debug_log ("Cannot initialize registered module: %s\n", - p11_kit_strerror (rv)); - return GNUTLS_E_INTERNAL_ERROR; - } + if (deprecated_config_file == NULL) + ret = initialize_automatic_p11_kit (); - initialized_registered = 1; + _pkcs11_compat_init(deprecated_config_file); - modules = p11_kit_registered_modules (); - for (i = 0; modules[i] != NULL; i++) - { - name = p11_kit_registered_module_to_name (modules[i]); - ret = pkcs11_add_module (name, modules[i]); - if (ret != 0) - { - gnutls_assert (); - _gnutls_debug_log ("Cannot add registered module: %s\n", name); - } - } - free (modules); - - _pkcs11_compat_init(); + return ret; } - + return 0; }