From: Marcel Poul Date: Thu, 23 Aug 2012 22:15:16 +0000 (+0000) Subject: add canl_cred_save_priv_key() to caNl API, X-Git-Tag: glite-jobid-api-c_R_2_2_2_1~10 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=7790e937cf2df2635bcb75551adc51ce9b33829f;p=jra1mw.git add canl_cred_save_priv_key() to caNl API, pkey_dup can be void --- diff --git a/emi.canl.canl-c/src/canl_cred.c b/emi.canl.canl-c/src/canl_cred.c index 06f1ea6..8a940f7 100644 --- a/emi.canl.canl-c/src/canl_cred.c +++ b/emi.canl.canl-c/src/canl_cred.c @@ -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; diff --git a/emi.canl.canl-c/src/canl_cred.h b/emi.canl.canl-c/src/canl_cred.h index 3cc2917..814d3f0 100644 --- a/emi.canl.canl-c/src/canl_cred.h +++ b/emi.canl.canl-c/src/canl_cred.h @@ -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 *, diff --git a/emi.canl.canl-c/src/canl_mech_ssl.h b/emi.canl.canl-c/src/canl_mech_ssl.h index eb13544..cb0e920 100644 --- a/emi.canl.canl-c/src/canl_mech_ssl.h +++ b/emi.canl.canl-c/src/canl_mech_ssl.h @@ -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