From af03b31d3652e4eede1f6597e6d20ee96690498d Mon Sep 17 00:00:00 2001 From: Marcel Poul Date: Wed, 18 Jan 2012 21:17:55 +0000 Subject: [PATCH] set lifetime, cert_type, extension to canl_cred --- emi.canl.canl-c/src/canl_cred.c | 50 ++++++++++++++++++++++++++++++++++++----- emi.canl.canl-c/src/canl_cred.h | 4 ++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/emi.canl.canl-c/src/canl_cred.c b/emi.canl.canl-c/src/canl_cred.c index f7977a1..525209c 100644 --- a/emi.canl.canl-c/src/canl_cred.c +++ b/emi.canl.canl-c/src/canl_cred.c @@ -209,21 +209,59 @@ canl_cred_load_cert_file(canl_ctx ctx, canl_cred cred, const char *cert_file) } canl_err_code CANL_CALLCONV -canl_cred_set_lifetime(canl_ctx ctx, canl_cred cred, long lifetime) +canl_cred_set_lifetime(canl_ctx ctx, canl_cred cred, const long lifetime) { - return ENOSYS; + glb_ctx *cc = (glb_ctx*) ctx; + creds *crd = (creds*) cred; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + crd->c_lifetime = lifetime; + return 0; } +/*TODO rather use STACK_OF(X509_EXTENSION) ???*/ canl_err_code CANL_CALLCONV canl_cred_set_extension(canl_ctx ctx, canl_cred cred, X509_EXTENSION *cert_ext) { - return ENOSYS; + glb_ctx *cc = (glb_ctx*) ctx; + creds *crd = (creds*) cred; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + + if (crd->c_cert_ext) { + X509_EXTENSION_free(crd->c_cert_ext); + crd->c_cert_ext = NULL; + } + + crd->c_cert_ext = X509_EXTENSION_dup(cert_ext); + return 0; } canl_err_code CANL_CALLCONV -canl_cred_set_cert_type(canl_ctx ctx, canl_cred cred, enum canl_cert_type cert_type) -{ - return ENOSYS; +canl_cred_set_cert_type(canl_ctx ctx, canl_cred cred, + const enum canl_cert_type cert_type) +{ + glb_ctx *cc = (glb_ctx*) ctx; + creds *crd = (creds*) cred; + + if (!ctx) + return EINVAL; + + if (!cred) + return set_error(cc, EINVAL, posix_error, "Cred. handler" + " not initialized" ); + crd->c_type = cert_type; + return 0; } canl_err_code CANL_CALLCONV diff --git a/emi.canl.canl-c/src/canl_cred.h b/emi.canl.canl-c/src/canl_cred.h index 1bafb71..a73897b 100644 --- a/emi.canl.canl-c/src/canl_cred.h +++ b/emi.canl.canl-c/src/canl_cred.h @@ -70,13 +70,13 @@ canl_err_code CANL_CALLCONV canl_cred_load_cert_pkcs11(canl_ctx, canl_cred, const char *); canl_err_code CANL_CALLCONV -canl_cred_set_lifetime(canl_ctx, canl_cred, long); +canl_cred_set_lifetime(canl_ctx, canl_cred, const long); canl_err_code CANL_CALLCONV canl_cred_set_extension(canl_ctx, canl_cred, X509_EXTENSION *); canl_err_code CANL_CALLCONV -canl_cred_set_cert_type(canl_ctx, canl_cred, enum canl_cert_type); +canl_cred_set_cert_type(canl_ctx, canl_cred, const enum canl_cert_type); canl_err_code CANL_CALLCONV canl_cred_sign_proxy(canl_ctx, canl_cred, canl_cred); -- 1.8.2.3