streamlined file loading labels
[strongswan.git] / src / pluto / certs.c
index 902a1f5..129b58c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "library.h"
 #include "asn1/asn1.h"
+#include "credentials/certificates/certificate.h"
 
 #include "constants.h"
 #include "defs.h"
@@ -141,7 +142,11 @@ private_key_t* load_private_key(char* filename, prompt_pass_t *pass,
                                                                 BUILD_FROM_FILE, path, BUILD_END);
                
        }
-       if (key == NULL)
+       if (key)
+       {
+               plog("  loaded private key from '%s'", filename);
+       }
+       else
        {
                plog("  syntax error in private key file");
        }
@@ -155,13 +160,14 @@ bool load_cert(char *filename, const char *label, cert_t *out)
 {
        cert_t *cert;
 
-       cert = lib->creds->create(lib->creds, CRED_PLUTO_CERT, CRED_TYPE_CERTIFICATE,
+       cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_PLUTO_CERT,
                                                          BUILD_FROM_FILE, filename, BUILD_END);
        if (cert)
        {
-               /* As the API passes an empty cert_t, the CRED_TYPE_CERTIFICATE 
-                * returns a statically allocated cert to copy. */
+               /* the API passes an empty cert_t, we move over and free the built one */
+               plog("  loaded %s certificate from '%s'", label, filename);
                *out = *cert;
+               free(cert);
                return TRUE;
        }
        return FALSE;
@@ -174,7 +180,7 @@ bool load_host_cert(char *filename, cert_t *cert)
 {
        char *path = concatenate_paths(HOST_CERT_PATH, filename);
 
-       return load_cert(path, "host cert", cert);
+       return load_cert(path, "host", cert);
 }
 
 /**
@@ -184,7 +190,7 @@ bool load_ca_cert(char *filename, cert_t *cert)
 {
        char *path = concatenate_paths(CA_CERT_PATH, filename);
 
-       return load_cert(path, "CA cert", cert);
+       return load_cert(path, "CA", cert);
 }
 
 /**