You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rampart-dev@ws.apache.org by su...@apache.org on 2008/04/03 10:08:09 UTC
svn commit: r644210 [3/3] - in /webservices/rampart/scratch/c/pkcs/c:
build/win32/ include/ src/omxmlsec/ src/util/
Modified: webservices/rampart/scratch/c/pkcs/c/src/util/rampart_engine.c
URL: http://svn.apache.org/viewvc/webservices/rampart/scratch/c/pkcs/c/src/util/rampart_engine.c?rev=644210&r1=644209&r2=644210&view=diff
==============================================================================
--- webservices/rampart/scratch/c/pkcs/c/src/util/rampart_engine.c (original)
+++ webservices/rampart/scratch/c/pkcs/c/src/util/rampart_engine.c Thu Apr 3 01:08:02 2008
@@ -52,6 +52,10 @@
const axutil_env_t *env,
rampart_context_t *rampart_context);
+axis2_status_t AXIS2_CALL
+rampart_engine_retrieve_key_mgr_prop_from_policy(
+ rampart_context_t *rampart_context,
+ axutil_env_t *env);
AXIS2_EXTERN rampart_context_t *AXIS2_CALL
@@ -70,6 +74,14 @@
neethi_policy_t *policy = NULL;
axutil_property_t *property = NULL;
void *value = NULL;
+
+ /* Key Manager related */
+ oxs_key_mgr_t *key_mgr = NULL;
+ axis2_char_t *password = NULL;
+ axis2_char_t *enc_user = NULL;
+ password_callback_fn password_function = NULL;
+ rampart_callback_t *password_callback = NULL;
+ void *param = NULL;
is_server_side = axis2_msg_ctx_get_server_side(msg_ctx, env);
@@ -152,6 +164,43 @@
rampart_context = NULL;
return NULL;
}
+
+ /* Retrieve the password for obtaining private keys */
+ enc_user = rampart_context_get_encryption_user(rampart_context, env);
+ if(!enc_user)
+ {
+ enc_user = rampart_context_get_user(rampart_context, env);
+ }
+ if(enc_user)
+ {
+ password_function = rampart_context_get_pwcb_function(rampart_context, env);
+ if(password_function)
+ {
+ password = (*password_function)(env, enc_user, param);
+ }
+ else
+ {
+ password_callback = rampart_context_get_password_callback(
+ rampart_context, env);
+ if(password_callback)
+ {
+ password = rampart_callback_password(env, password_callback, enc_user);
+ }
+ }
+ }
+ key_mgr = oxs_key_mgr_create(env);
+ if (!key_mgr)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "[rampart][engine] Key mgr creation failed.");
+ return AXIS2_FAILURE;
+ }
+ if (password)
+ {
+ oxs_key_mgr_set_prv_key_password(key_mgr, env, password);
+ }
+ rampart_context_set_key_mgr(rampart_context, env, key_mgr);
+ rampart_engine_retrieve_key_mgr_prop_from_policy(rampart_context, env);
}
/*conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx,env);
@@ -394,4 +443,39 @@
rampart_context_set_sct_provider(rampart_context,env,(void*)sct_provider);
}
return status;
+}
+
+axis2_status_t AXIS2_CALL
+rampart_engine_retrieve_key_mgr_prop_from_policy(rampart_context_t *rampart_context,
+ axutil_env_t *env)
+{
+ axis2_char_t *value = NULL;
+ rp_rampart_config_t *config = NULL;
+ oxs_key_mgr_t *key_mgr = NULL;
+ rp_secpolicy_t *secpolicy = NULL;
+ secpolicy = rampart_context_get_secpolicy(rampart_context, env);
+ config = rp_secpolicy_get_rampart_config(secpolicy, env);
+ if (!config)
+ return AXIS2_FAILURE;
+
+ key_mgr = rampart_context_get_key_mgr(rampart_context, env);
+
+ value = rp_rampart_config_get_certificate_file(config, env);
+ if (value)
+ {
+ oxs_key_mgr_set_certificate_file(key_mgr, env, value);
+ }
+
+ value = rp_rampart_config_get_private_key_file(config, env);
+ if (value)
+ {
+ oxs_key_mgr_set_private_key_file(key_mgr, env, value);
+ }
+
+ value = rp_rampart_config_get_receiver_certificate_file(config, env);
+ if (value)
+ {
+ oxs_key_mgr_set_reciever_certificate_file(key_mgr, env, value);
+ }
+ return AXIS2_SUCCESS;
}
Modified: webservices/rampart/scratch/c/pkcs/c/src/util/rampart_signature.c
URL: http://svn.apache.org/viewvc/webservices/rampart/scratch/c/pkcs/c/src/util/rampart_signature.c?rev=644210&r1=644209&r2=644210&view=diff
==============================================================================
--- webservices/rampart/scratch/c/pkcs/c/src/util/rampart_signature.c (original)
+++ webservices/rampart/scratch/c/pkcs/c/src/util/rampart_signature.c Thu Apr 3 01:08:02 2008
@@ -354,106 +354,17 @@
rampart_context_t *rampart_context,
oxs_sign_ctx_t *sign_ctx)
{
- openssl_pkey_t *prvkey = NULL;
- axis2_char_t *prv_key_file = NULL;
- axis2_char_t *password = NULL;
- axis2_char_t *enc_user = NULL;
+ openssl_pkey_t *prvkey = NULL;
+ oxs_key_mgr_t *key_mgr = NULL;
axis2_char_t *asym_sig_algo = NULL;
- password_callback_fn password_function = NULL;
- rampart_callback_t *password_callback = NULL;
- void *key_buf = NULL;
- void *param = NULL;
+
+ key_mgr = rampart_context_get_key_mgr(rampart_context, env);
+ prvkey = oxs_key_mgr_get_prv_key(key_mgr, env);
- /*First check whether the private key is set*/
- key_buf = rampart_context_get_prv_key(rampart_context, env);
- if(key_buf)
+ if (!prvkey)
{
- axis2_key_type_t type = 0;
- type = rampart_context_get_prv_key_type(rampart_context, env);
- if(type == AXIS2_KEY_TYPE_PEM)
- {
- prvkey = oxs_key_mgr_load_private_key_from_string(
- env, (axis2_char_t *)key_buf, NULL);
- if(!prvkey)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature] Can't load the key from buffer");
- return AXIS2_FAILURE;
- }
- }
- }else{ /*Buffer is null load from the file*/
- prv_key_file = rampart_context_get_private_key_file(
- rampart_context, env);
- if(!prv_key_file)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature]Private Key file is not specified.");
- return AXIS2_FAILURE;
- }
-
- /*Get the password to retrieve the key from key store*/
- password = rampart_context_get_prv_key_password(rampart_context, env);
-
- if(!password)
- {
- enc_user = rampart_context_get_encryption_user(rampart_context, env);
-
- if(!enc_user)
- {
- enc_user = rampart_context_get_user(rampart_context, env);
- }
-
- if(enc_user)
- {
- password_function = rampart_context_get_pwcb_function(rampart_context, env);
- if(password_function)
- {
- password = (*password_function)(env, enc_user, param);
- }
- else
- {
- password_callback = rampart_context_get_password_callback(
- rampart_context, env);
- if(!password_callback)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature] Password call back module is not loaded.");
- return AXIS2_FAILURE;
- }
- password = rampart_callback_password(env, password_callback, enc_user);
- }
- }
- }
- if(oxs_util_get_format_by_file_extension(env, prv_key_file) ==
- OXS_ASYM_CTX_FORMAT_PKCS12)
- {
- oxs_x509_cert_t *c = NULL;
- if((oxs_key_mgr_read_pkcs12_key_store(env, prv_key_file,
- password, &c, &prvkey)==AXIS2_FAILURE) || !prvkey)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature] Cannot load the private key from pfx file.");
- return AXIS2_FAILURE;
- }
- }
- else if(oxs_util_get_format_by_file_extension(env, prv_key_file)
- ==OXS_ASYM_CTX_FORMAT_PEM)
- {
- prvkey = oxs_key_mgr_load_private_key_from_pem_file(
- env, prv_key_file, password);
- if(!prvkey)
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature] Cannot load the private key from file.");
- return AXIS2_FAILURE;
- }
- }
- else
- {
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature] Unknown Private key format.");
- return AXIS2_FAILURE;
- }
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "[rampart][rampart_signature]Private key cannot be loaded.");
}
/*Get the asymmetric signature algorithm*/