]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Sanity-check loading keys and certs from PEM files
authorNalin Dahyabhai <nalin@redhat.com>
Tue, 9 Oct 2012 17:41:46 +0000 (13:41 -0400)
committerGreg Hudson <ghudson@mit.edu>
Mon, 15 Oct 2012 15:41:10 +0000 (11:41 -0400)
Print a debug message if we're unable to locate the matching private key
for a certificate when we've just loaded both of them from PEM files.

src/plugins/preauth/pkinit/pkinit_crypto_nss.c

index 2f93a86e083d4950f9d3b31e4706632ae7e856b1..1aa5779cd59762d0b8fed6b26f5ccc70c4e5b2bb 100644 (file)
@@ -2402,6 +2402,7 @@ crypto_load_files(krb5_context context,
     CERTCertificate *cert;
     CERTCertList *before, *after;
     CERTCertListNode *anode, *bnode;
+    SECKEYPrivateKey *key;
     CK_ATTRIBUTE attrs[4];
     CK_BBOOL cktrue = CK_TRUE, cktrust;
     CK_OBJECT_CLASS keyclass = CKO_PRIVATE_KEY, certclass = CKO_CERTIFICATE;
@@ -2555,6 +2556,20 @@ crypto_load_files(krb5_context context,
         if (before != NULL) {
             CERT_DestroyCertList(before);
         }
+        if ((keyfile != NULL) && (obj->cert != NULL)) {
+            key = PK11_FindPrivateKeyFromCert(slot, obj->cert,
+                                              crypto_pwcb_prep(id_cryptoctx,
+                                                               context));
+            if (key == NULL) {
+                pkiDebug("%s: no key private found for \"%s\"(%s), "
+                         "even though we just loaded that key?\n",
+                         __FUNCTION__,
+                         obj->cert->nickname ?
+                         obj->cert->nickname : "(no name)",
+                         certfile);
+            } else
+                SECKEY_DestroyPrivateKey(req_cryptoctx->client_dh_privkey);
+        }
     }
 
     /* If we succeeded to this point, or more likely didn't do anything