add canl_cred_save_priv_key() to caNl API,
authorMarcel Poul <marcel.poul@cern.ch>
Thu, 23 Aug 2012 22:15:16 +0000 (22:15 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Thu, 23 Aug 2012 22:15:16 +0000 (22:15 +0000)
pkey_dup can be void

emi.canl.canl-c/src/canl_cred.c
emi.canl.canl-c/src/canl_cred.h
emi.canl.canl-c/src/canl_mech_ssl.h

index 06f1ea6..8a940f7 100644 (file)
@@ -107,7 +107,6 @@ canl_ctx_set_cred(canl_ctx ctx, canl_cred cred)
 {
     glb_ctx *cc = (glb_ctx*) ctx;
     creds *crd = (creds*) cred;
-    int ret = 0;
     mech_glb_ctx *m_ctx = (mech_glb_ctx *)cc->mech_ctx;
 
     if (!ctx)
@@ -130,11 +129,8 @@ canl_ctx_set_cred(canl_ctx ctx, canl_cred cred)
         }
     }
 
-    if (crd->c_key) {
-        if ((ret = pkey_dup(&m_ctx->cert_key->key, crd->c_key))) {
-            return ret;
-        }
-    }
+    if (crd->c_key)
+        pkey_dup(&m_ctx->cert_key->key, crd->c_key);
 
     if (crd->c_cert)
         m_ctx->cert_key->cert = X509_dup(crd->c_cert);
@@ -143,11 +139,10 @@ canl_ctx_set_cred(canl_ctx ctx, canl_cred cred)
     return 0;
 }
 
-int pkey_dup(EVP_PKEY **to, EVP_PKEY *from)
+void pkey_dup(EVP_PKEY **to, EVP_PKEY *from)
 {
     CRYPTO_add(&from->references,1,CRYPTO_LOCK_EVP_PKEY);
     *to = from;
-    return 0;
 }
 
 canl_err_code CANL_CALLCONV
@@ -173,6 +168,27 @@ canl_cred_load_priv_key_file(canl_ctx ctx, canl_cred cred, const char *pkey_file
 }
 
 canl_err_code CANL_CALLCONV
+canl_cred_save_priv_key(canl_ctx ctx, canl_cred cred, EVP_PKEY **pkey)
+{
+    glb_ctx *cc = (glb_ctx*) ctx;
+    creds *crd = (creds*) cred;
+    int ret = 0;
+
+    if (!ctx)
+        return EINVAL;
+
+    if (!cred)
+        return set_error(cc, EINVAL, POSIX_ERROR, "Cred. handler"
+                " not initialized" );
+    if (!pkey)
+        return set_error(cc, EINVAL, POSIX_ERROR, "Invalid private key"
+                " parameter");
+    pkey_dup(pkey, crd->c_key);
+
+    return ret;
+}
+
+canl_err_code CANL_CALLCONV
 canl_cred_load_chain(canl_ctx ctx, canl_cred cred, STACK_OF(X509) *cert_stack)
 {
     glb_ctx *cc = (glb_ctx*) ctx;
index 3cc2917..814d3f0 100644 (file)
@@ -40,6 +40,8 @@ canl_ctx_set_cred(canl_ctx, canl_cred);
 canl_err_code CANL_CALLCONV
 canl_cred_load_priv_key_file(canl_ctx, canl_cred, const char *,
                             canl_password_callback, void *);
+canl_err_code CANL_CALLCONV
+canl_cred_save_priv_key(canl_ctx, canl_cred, EVP_PKEY **);
 
 canl_err_code CANL_CALLCONV
 canl_cred_load_priv_key_pkcs11(canl_ctx, canl_cred, const char *,
index eb13544..cb0e920 100644 (file)
@@ -29,6 +29,6 @@ int do_set_ctx_own_cert_file(glb_ctx *cc, mech_glb_ctx *m_ctx,
 int set_key_file(glb_ctx *cc, EVP_PKEY **to, const char *key);
 int set_cert_file(glb_ctx *cc, X509 **to, const char *cert);
 int set_cert_chain_file(glb_ctx *cc, STACK_OF(X509) **to, const char *cert);
-int pkey_dup(EVP_PKEY **to, EVP_PKEY *from);
+void pkey_dup(EVP_PKEY **to, EVP_PKEY *from);
 
 #endif