Author: shankar
Date: Thu Oct 30 22:08:21 2008
New Revision: 709349
URL: http://svn.apache.org/viewvc?rev=709349&view=rev
Log:
memory leak fix
Modified:
webservices/rampart/trunk/c/ides/sample/client/client.vcproj
webservices/rampart/trunk/c/include/oxs_key.h
webservices/rampart/trunk/c/include/oxs_key_mgr.h
webservices/rampart/trunk/c/src/omxmlsec/key.c
webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c
webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c
webservices/rampart/trunk/c/src/omxmlsec/x509_cert.c
webservices/rampart/trunk/c/src/util/rampart_context.c
webservices/rampart/trunk/c/src/util/rampart_sec_header_processor.c
Modified: webservices/rampart/trunk/c/ides/sample/client/client.vcproj
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/ides/sample/client/client.vcproj?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/ides/sample/client/client.vcproj (original)
+++ webservices/rampart/trunk/c/ides/sample/client/client.vcproj Thu Oct 30
22:08:21 2008
@@ -68,6 +68,7 @@
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
+ FixedBaseAddress="1"
/>
<Tool
Name="VCALinkTool"
Modified: webservices/rampart/trunk/c/include/oxs_key.h
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/include/oxs_key.h?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/include/oxs_key.h (original)
+++ webservices/rampart/trunk/c/include/oxs_key.h Thu Oct 30 22:08:21 2008
@@ -263,6 +263,7 @@
AXIS2_EXTERN oxs_key_t *AXIS2_CALL
oxs_key_create(const axutil_env_t *env);
+ /* once the key_sha is given, ownership is assumed */
AXIS2_EXTERN axis2_status_t AXIS2_CALL
oxs_key_set_key_sha(
oxs_key_t *key,
Modified: webservices/rampart/trunk/c/include/oxs_key_mgr.h
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/include/oxs_key_mgr.h?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/include/oxs_key_mgr.h (original)
+++ webservices/rampart/trunk/c/include/oxs_key_mgr.h Thu Oct 30 22:08:21 2008
@@ -55,6 +55,7 @@
OXS_KEY_MGR_FORMAT_PKCS12
}oxs_key_mgr_format_t;
+#if 0
/**
* Loads keys/certificates from a keystore or a PEm file depending on
information available in the @ctx
* @ctx pointer to the OMXMLSec asymmetric encryption context struct
@@ -67,6 +68,9 @@
oxs_key_mgr_t *key_mgr,
const axutil_env_t *env,
oxs_asym_ctx_t *ctx);
+
+#endif
+
/**
* Loads a private key from a string buffer @pem_buf which of PEM format.
* -----BEGIN RSA PRIVATE KEY-----
Modified: webservices/rampart/trunk/c/src/omxmlsec/key.c
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/key.c?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/key.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/key.c Thu Oct 30 22:08:21 2008
@@ -160,12 +160,12 @@
AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
AXIS2_PARAM_CHECK(env->error, key_sha, AXIS2_FAILURE);
- if (key->key_sha)
+ if(key->key_sha)
{
AXIS2_FREE(env->allocator, key->key_sha);
key->key_sha = NULL;
}
- key->key_sha = axutil_strdup(env, key_sha);
+ key->key_sha = key_sha;
return AXIS2_SUCCESS;
}
Modified: webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c Thu Oct 30 22:08:21 2008
@@ -129,6 +129,19 @@
}
key_mgr->receiver_certificate = NULL;
}
+ /*if(key_mgr->prv_key)
+ {
+ if(key_mgr->prv_key_type== AXIS2_KEY_TYPE_PEM)
+ {
+ AXIS2_FREE(env->allocator, key_mgr->prv_key);
+ }
+ else
+ {
+ openssl_pkey_free(key_mgr->prv_key, env);
+ }
+ key_mgr->receiver_certificate = NULL;
+ }*/
+
AXIS2_FREE(env->allocator, key_mgr);
}
return AXIS2_SUCCESS;
@@ -156,11 +169,7 @@
const axutil_env_t *env,
axis2_char_t *password)
{
- if (key_mgr->prv_key_password)
- {
- AXIS2_FREE(env->allocator, key_mgr->prv_key_password);
- }
- key_mgr->prv_key_password = axutil_strdup(env, password);
+ key_mgr->prv_key_password = password;
return AXIS2_SUCCESS;
}
@@ -194,11 +203,7 @@
const axutil_env_t *env,
axis2_char_t *file_name)
{
- if (key_mgr->private_key_file)
- {
- AXIS2_FREE(env->allocator, key_mgr->private_key_file);
- }
- key_mgr->private_key_file = axutil_strdup(env, file_name);
+ key_mgr->private_key_file = file_name;
return AXIS2_SUCCESS;
}
@@ -208,11 +213,7 @@
const axutil_env_t *env,
axis2_char_t *file_name)
{
- if (key_mgr->certificate_file)
- {
- AXIS2_FREE(env->allocator, key_mgr->certificate_file);
- }
- key_mgr->certificate_file = axutil_strdup(env, file_name);
+ key_mgr->certificate_file = file_name;
return AXIS2_SUCCESS;
}
@@ -222,11 +223,7 @@
const axutil_env_t *env,
axis2_char_t *file_name)
{
- if (key_mgr->reciever_certificate_file)
- {
- AXIS2_FREE(env->allocator, key_mgr->reciever_certificate_file);
- }
- key_mgr->reciever_certificate_file = axutil_strdup(env, file_name);
+ key_mgr->reciever_certificate_file = file_name;
return AXIS2_SUCCESS;
}
@@ -300,8 +297,7 @@
return NULL;
}
- key_mgr->certificate = cert;
- return key_mgr->certificate;
+ return cert;
}
AXIS2_EXTERN axis2_key_type_t AXIS2_CALL
@@ -327,42 +323,45 @@
{
if(key_mgr->prv_key_type == AXIS2_KEY_TYPE_PEM)
{
- prvkey = oxs_key_mgr_load_private_key_from_string(
- env, (axis2_char_t *)key_buf, NULL);
+ 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,
- "[oxs][key_mgr] Can't load the key from buffer");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[oxs]Can't load the
key from buffer");
return NULL;
}
+ /*key_mgr->prv_key = prvkey;
+ key_mgr->prv_key_type = AXIS2_KEY_TYPE_CERT;
+ }
+ else if(key_mgr->prv_key_type == AXIS2_KEY_TYPE_CERT)
+ {
+ prvkey = key_buf;*/
}
else
{
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
- "[rampart][rampart_signature] Key file type
unknown.");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[oxs] Private
key type is unknown.");
return NULL;
}
}
else
{ /*Buffer is null load from the file*/
- prv_key_file = axutil_strdup(env,
oxs_key_mgr_get_private_key_file(key_mgr, env));
+ prv_key_file = key_mgr->private_key_file;
/*Get the password to retrieve the key from key store*/
- password = axutil_strdup(env,
oxs_key_mgr_get_prv_key_password(key_mgr, env));
+ password = key_mgr->prv_key_password;
if(prv_key_file)
{
- if(oxs_util_get_format_by_file_extension(env, prv_key_file)
- ==OXS_ASYM_CTX_FORMAT_PEM)
+ 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);
+ 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][key_mgr] Cannot load the
private key from file.");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "[oxs]Cannot load the private key from file.");
return NULL;
}
+ /*key_mgr->prv_key = prvkey;
+ key_mgr->prv_key_type = AXIS2_KEY_TYPE_CERT;*/
}
}
else
@@ -440,6 +439,8 @@
if(key_mgr->reciever_certificate_file)
{
oxs_cert =
oxs_key_mgr_load_x509_cert_from_pem_file(env,
key_mgr->reciever_certificate_file);
+ key_mgr->receiver_certificate = oxs_cert;
+ key_mgr->receiver_certificate_type = AXIS2_KEY_TYPE_CERT;
}
else if(key_mgr->key_store)
{
@@ -563,6 +564,8 @@
key_mgr->key_store = key_store;
return AXIS2_SUCCESS;
}
+
+#if 0
/**
* Loads the key
* 1. If the key buffer is specified, Take that as the source.
@@ -760,6 +763,7 @@
/********************************************************************************************/
/*These are new set of functions that break-up the complex logic in
oxs_key_mgr_load_key()*/
+#endif
AXIS2_EXTERN openssl_pkey_t* AXIS2_CALL
oxs_key_mgr_load_private_key_from_string(const axutil_env_t *env,
@@ -887,7 +891,6 @@
openssl_x509_load_from_pem(env, filename, &cert);
oxs_cert = oxs_key_mgr_convert_to_x509(env, cert);
-
return oxs_cert;
}
Modified: webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c Thu Oct 30 22:08:21
2008
@@ -228,21 +228,24 @@
AXIS2_EXTERN int AXIS2_CALL
-openssl_x509_get_serial(const axutil_env_t *env,
- X509 *cert)
+openssl_x509_get_serial(
+ const axutil_env_t *env,
+ X509 *cert)
{
axis2_char_t *serial = NULL;
int no = 0;
+
/*WARN: Do not use the serial number without converting it to the
integer.*/
serial = (axis2_char_t*)i2s_ASN1_INTEGER(NULL,
X509_get_serialNumber(cert));
- if(serial){
+ if(serial)
+ {
no = atoi(serial);
-
- /*AXIS2_FREE(env->allocator, serial);
- free(serial); */
+ OPENSSL_free(serial);
serial = NULL;
return no;
- }else{
+ }
+ else
+ {
return -1;
}
}
Modified: webservices/rampart/trunk/c/src/omxmlsec/x509_cert.c
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/x509_cert.c?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/x509_cert.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/x509_cert.c Thu Oct 30 22:08:21
2008
@@ -129,6 +129,7 @@
oxs_x509_cert_set_date(to, env, x509_cert->date);
oxs_x509_cert_set_hash(to, env, x509_cert->hash);
oxs_x509_cert_set_data(to, env, x509_cert->data);
+ openssl_pkey_increment_ref(x509_cert->public_key, env);
oxs_x509_cert_set_public_key(to, env, x509_cert->public_key);
oxs_x509_cert_set_common_name(to, env, x509_cert->common_name);
@@ -319,7 +320,6 @@
const axutil_env_t *env,
openssl_pkey_t *public_key)
{
- openssl_pkey_increment_ref(public_key, env);
if(x509_cert->public_key)
{
openssl_pkey_free(x509_cert->public_key, env);
Modified: webservices/rampart/trunk/c/src/util/rampart_context.c
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_context.c?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_context.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_context.c Thu Oct 30 22:08:21
2008
@@ -359,10 +359,15 @@
}
/* Free receiver certificate we found when processing incoming
security header */
- if(rampart_context->receiver_cert &&
rampart_context->found_cert_in_shp)
+ /*if(rampart_context->receiver_cert &&
rampart_context->found_cert_in_shp)
{
oxs_x509_cert_free(rampart_context->receiver_cert, env);
rampart_context->receiver_cert = NULL;
+ }*/
+
+ if(rampart_context->key_mgr)
+ {
+ oxs_key_mgr_free(rampart_context->key_mgr, env);
}
AXIS2_FREE(env->allocator,rampart_context);
Modified: webservices/rampart/trunk/c/src/util/rampart_sec_header_processor.c
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_sec_header_processor.c?rev=709349&r1=709348&r2=709349&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_sec_header_processor.c
(original)
+++ webservices/rampart/trunk/c/src/util/rampart_sec_header_processor.c Thu Oct
30 22:08:21 2008
@@ -747,7 +747,7 @@
axis2_char_t *enc_sym_algo_in_pol = NULL;
openssl_pkey_t *open_prvkey = NULL;
int i = 0;
- void *key_buf = NULL;
+ /*void *key_buf = NULL;*/
axis2_char_t *prv_key_file = NULL;
/*Get EncryptedData references */
@@ -791,7 +791,7 @@
asym_ctx = oxs_asym_ctx_create(env);
oxs_asym_ctx_set_algorithm(asym_ctx, env, enc_asym_algo);
- key_buf = rampart_context_get_prv_key(rampart_context, env);
+ /* key_buf = rampart_context_get_prv_key(rampart_context, env);
if(key_buf)
{
axis2_key_type_t type = 0;
@@ -801,7 +801,7 @@
oxs_key_mgr_set_format(key_mgr, env,
OXS_KEY_MGR_FORMAT_PEM);
oxs_key_mgr_set_pem_buf(key_mgr, env, key_buf);
}
- }
+ } */
oxs_asym_ctx_set_operation(asym_ctx, env,
OXS_ASYM_CTX_OPERATION_PRV_DECRYPT);
prv_key_file = rampart_context_get_private_key_file(rampart_context,
env);
oxs_key_mgr_set_format(key_mgr, env,
oxs_util_get_format_by_file_extension(env, prv_key_file));