2012-09-14 14:14:43 +00:00
|
|
|
MozNSS: load certificates from certdb, fallback to PEM
|
|
|
|
|
2012-10-11 09:47:24 +00:00
|
|
|
If TLS_CACERT pointed to a PEM file and TLS_CACERTDIR was set to NSS
|
|
|
|
certificate database, the backend assumed that the certificate is always
|
|
|
|
located in the certificate database. This assumption might be wrong.
|
|
|
|
|
|
|
|
This patch makes the library to try to load the certificate from NSS
|
|
|
|
database and fallback to PEM file if unsuccessfull.
|
2012-09-14 14:14:43 +00:00
|
|
|
|
|
|
|
Author: Jan Vcelak <jvcelak@redhat.com>
|
|
|
|
Upstream ITS: #7389
|
|
|
|
Resolves: #857455
|
|
|
|
|
2012-10-11 09:47:24 +00:00
|
|
|
---
|
|
|
|
libraries/libldap/tls_m.c | 33 ++++++++++++++++++++-------------
|
|
|
|
1 file changed, 20 insertions(+), 13 deletions(-)
|
|
|
|
|
2012-09-14 14:14:43 +00:00
|
|
|
diff --git a/libraries/libldap/tls_m.c b/libraries/libldap/tls_m.c
|
2012-10-11 09:47:24 +00:00
|
|
|
index 61d71d4..49a3f8f 100644
|
2012-09-14 14:14:43 +00:00
|
|
|
--- a/libraries/libldap/tls_m.c
|
|
|
|
+++ b/libraries/libldap/tls_m.c
|
2012-10-11 09:47:24 +00:00
|
|
|
@@ -1412,7 +1412,7 @@ tlsm_ctx_load_private_key( tlsm_ctx *ctx )
|
2012-09-14 14:14:43 +00:00
|
|
|
/* prefer unlocked key, then key from opened certdb, then any other */
|
2012-10-11 09:47:24 +00:00
|
|
|
if ( unlocked_key )
|
2012-09-14 14:14:43 +00:00
|
|
|
ctx->tc_private_key = unlocked_key;
|
2012-10-11 09:47:24 +00:00
|
|
|
- else if ( ctx->tc_certdb_slot )
|
2012-09-14 14:14:43 +00:00
|
|
|
+ else if ( ctx->tc_certdb_slot && !ctx->tc_using_pem )
|
2012-10-11 09:47:24 +00:00
|
|
|
ctx->tc_private_key = PK11_FindKeyByDERCert( ctx->tc_certdb_slot, ctx->tc_certificate, pin_arg );
|
2012-09-14 14:14:43 +00:00
|
|
|
else
|
2012-10-11 09:47:24 +00:00
|
|
|
ctx->tc_private_key = PK11_FindKeyByAnyCert( ctx->tc_certificate, pin_arg );
|
|
|
|
@@ -1900,8 +1900,6 @@ tlsm_deferred_init( void *arg )
|
2012-09-14 14:14:43 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
-
|
|
|
|
- ctx->tc_using_pem = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_SetDomesticPolicy();
|
2012-10-11 09:47:24 +00:00
|
|
|
@@ -2354,15 +2352,9 @@ tlsm_deferred_ctx_init( void *arg )
|
2012-09-14 14:14:43 +00:00
|
|
|
|
|
|
|
/* set up our cert and key, if any */
|
|
|
|
if ( lt->lt_certfile ) {
|
|
|
|
- /* if using the PEM module, load the PEM file specified by lt_certfile */
|
|
|
|
- /* otherwise, assume this is the name of a cert already in the db */
|
|
|
|
- if ( ctx->tc_using_pem ) {
|
|
|
|
- /* this sets ctx->tc_certificate to the correct value */
|
|
|
|
- int rc = tlsm_add_cert_from_file( ctx, lt->lt_certfile, PR_FALSE );
|
|
|
|
- if ( rc ) {
|
|
|
|
- return rc;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
+
|
|
|
|
+ /* first search in certdb (lt_certfile is nickname) */
|
|
|
|
+ if ( ctx->tc_certdb ) {
|
|
|
|
char *tmp_certname;
|
|
|
|
|
2012-10-11 09:47:24 +00:00
|
|
|
if ( tlsm_is_tokenname_certnick( lt->lt_certfile )) {
|
|
|
|
@@ -2382,9 +2374,24 @@ tlsm_deferred_ctx_init( void *arg )
|
2012-09-14 14:14:43 +00:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"TLS: error: the certificate '%s' could not be found in the database - error %d:%s.\n",
|
|
|
|
lt->lt_certfile, errcode, PR_ErrorToString( errcode, PR_LANGUAGE_I_DEFAULT ) );
|
|
|
|
- return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ /* fallback to PEM module (lt_certfile is filename) */
|
|
|
|
+ if ( !ctx->tc_certificate && pem_module ) {
|
|
|
|
+ /* this sets ctx->tc_certificate to the correct value */
|
|
|
|
+ if ( !tlsm_add_cert_from_file( ctx, lt->lt_certfile, PR_FALSE ) ) {
|
|
|
|
+ ctx->tc_using_pem = PR_TRUE;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( ctx->tc_certificate ) {
|
|
|
|
+ Debug( LDAP_DEBUG_ANY,
|
|
|
|
+ "TLS: certificate '%s' successfully loaded from %s.\n", lt->lt_certfile,
|
|
|
|
+ ctx->tc_using_pem ? "PEM file" : "moznss database", 0);
|
|
|
|
+ } else {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lt->lt_keyfile ) {
|
|
|
|
--
|
2012-10-11 09:47:24 +00:00
|
|
|
1.7.11.7
|
2012-09-14 14:14:43 +00:00
|
|
|
|