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 ka...@apache.org on 2007/09/03 07:31:36 UTC

svn commit: r572235 - in /webservices/rampart/trunk/c: include/ samples/secpolicy/ src/omxmlsec/ src/omxmlsec/openssl/ src/omxmlsec/tokens/ src/util/

Author: kaushalye
Date: Sun Sep  2 22:31:34 2007
New Revision: 572235

URL: http://svn.apache.org/viewvc?rev=572235&view=rev
Log:
Memory leak fix
Doumentation updates
Code cleanings

Modified:
    webservices/rampart/trunk/c/include/openssl_digest.h
    webservices/rampart/trunk/c/include/openssl_x509.h
    webservices/rampart/trunk/c/include/oxs_utility.h
    webservices/rampart/trunk/c/samples/secpolicy/run_all.sh
    webservices/rampart/trunk/c/src/omxmlsec/axiom.c
    webservices/rampart/trunk/c/src/omxmlsec/encryption.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/signature.c
    webservices/rampart/trunk/c/src/omxmlsec/tokens/token_encrypted_data.c
    webservices/rampart/trunk/c/src/omxmlsec/xml_encryption.c
    webservices/rampart/trunk/c/src/omxmlsec/xml_signature.c
    webservices/rampart/trunk/c/src/util/rampart_handler_util.c

Modified: webservices/rampart/trunk/c/include/openssl_digest.h
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/include/openssl_digest.h?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/include/openssl_digest.h (original)
+++ webservices/rampart/trunk/c/include/openssl_digest.h Sun Sep  2 22:31:34 2007
@@ -38,7 +38,8 @@
 
 
     /**
-    * Calculate the digest of the input
+    * Calculate the digest of the input.
+    * Caller MUST free memory
     * @return calculated digest
     */
     AXIS2_EXTERN axis2_char_t *AXIS2_CALL

Modified: webservices/rampart/trunk/c/include/openssl_x509.h
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/include/openssl_x509.h?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/include/openssl_x509.h (original)
+++ webservices/rampart/trunk/c/include/openssl_x509.h Sun Sep  2 22:31:34 2007
@@ -84,6 +84,7 @@
                                   axis2_char_t *password,
                                   X509 **cert);
 
+    /*Caller MUST free */
     AXIS2_EXTERN axis2_char_t *AXIS2_CALL
     openssl_x509_get_cert_data(const axutil_env_t *env,
                                X509 *cert);

Modified: webservices/rampart/trunk/c/include/oxs_utility.h
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/include/oxs_utility.h?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/include/oxs_utility.h (original)
+++ webservices/rampart/trunk/c/include/oxs_utility.h Sun Sep  2 22:31:34 2007
@@ -36,6 +36,7 @@
     /**
      * Generates an id for an element.
      * Specially used in xml encryption and signature references.
+     * Caller must free memory
      * @param env pointer to environment struct
      * @param prefix the prefix of the id. For ex: EncDataID-1u343yrcarwqe
      * @return the generated id
@@ -57,6 +58,7 @@
 
     /**
      * Given string and returns new lined removed string
+     * Caller MUST free memory
      * @param env pointer to environment struct
      * @param input a pointer to the string which has \n s.
      * return the newline removed buffer.

Modified: webservices/rampart/trunk/c/samples/secpolicy/run_all.sh
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/samples/secpolicy/run_all.sh?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/samples/secpolicy/run_all.sh (original)
+++ webservices/rampart/trunk/c/samples/secpolicy/run_all.sh Sun Sep  2 22:31:34 2007
@@ -2,7 +2,7 @@
 _SCEN="scenario"
 _SMPL_DIR="$PWD"
 _PORT=9090
-_SLEEP=4
+_SLEEP=1
 #You may change these to scenarios u need to run
 _LST="1 2 3 4 5"
 

Modified: webservices/rampart/trunk/c/src/omxmlsec/axiom.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/axiom.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/axiom.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/axiom.c Sun Sep  2 22:31:34 2007
@@ -234,11 +234,18 @@
                 this_attr_ns_uri = "";
             }
             if(0 == axutil_strcmp(local_name, this_attr_name) && 0 == axutil_strcmp(ns_uri, this_attr_ns_uri)){
+                axis2_char_t *found_val = NULL;
                 /*Got it !!!*/
+                found_val = axiom_attribute_get_value(om_attr, env);
                 axutil_hash_free(attr_list, env);
                 attr_list = NULL;
-                return axiom_attribute_get_value(om_attr, env);
+                axiom_attribute_free(om_attr, env);
+                om_attr = NULL;
+
+                return found_val;
             }
+            axiom_attribute_free(om_attr, env);
+            om_attr = NULL;
         }
     }
     axutil_hash_free(attr_list, env);

Modified: webservices/rampart/trunk/c/src/omxmlsec/encryption.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/encryption.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/encryption.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/encryption.c Sun Sep  2 22:31:34 2007
@@ -120,7 +120,7 @@
         }
 
         /*Attach the result to the result buf*/
-        ret = oxs_buffer_populate(result, env, (unsigned char*)axutil_strdup(env, encoded_str), encodedlen);
+        ret = oxs_buffer_populate(result, env, (unsigned char*)encoded_str, encodedlen);
 
         /*Free*/
         oxs_buffer_free(output, env);

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=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/key_mgr.c Sun Sep  2 22:31:34 2007
@@ -133,12 +133,15 @@
     
     /*If the X509 certificate is available, populate oxs_x509_cert*/
     if(cert){
-
+        axis2_char_t *x509_cert_data = NULL;
+        
+        x509_cert_data = openssl_x509_get_cert_data(env, cert);
+        
         /*Create certificate*/
         oxs_cert = oxs_x509_cert_create(env);
-    
+
         /*And populate it*/
-        oxs_x509_cert_set_data(oxs_cert, env, openssl_x509_get_cert_data(env, cert));
+        oxs_x509_cert_set_data(oxs_cert, env, x509_cert_data);
         oxs_x509_cert_set_date(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_VALID_TO ,cert));
         oxs_x509_cert_set_issuer(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_ISSUER ,cert));
         oxs_x509_cert_set_subject(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_SUBJECT ,cert));
@@ -156,6 +159,9 @@
         /*Set the x509 certificate to the asym ctx*/
         oxs_asym_ctx_set_certificate(ctx, env, oxs_cert);
 
+        AXIS2_FREE(env->allocator, x509_cert_data);
+        x509_cert_data = NULL;
+    
         X509_free(cert);
         cert = NULL;
 
@@ -229,10 +235,13 @@
     if(cert){
         EVP_PKEY *pubkey = NULL;
         openssl_pkey_t *open_pubkey = NULL;
+        axis2_char_t *x509_cert_data = NULL;
+        
+        x509_cert_data = openssl_x509_get_cert_data(env, cert);
 
         /*Create X509 certificate*/
         oxs_cert = oxs_x509_cert_create(env);
-        oxs_x509_cert_set_data(oxs_cert, env, openssl_x509_get_cert_data(env, cert));
+        oxs_x509_cert_set_data(oxs_cert, env, x509_cert_data);
         oxs_x509_cert_set_date(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_VALID_TO ,cert));
         oxs_x509_cert_set_issuer(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_ISSUER ,cert));
         oxs_x509_cert_set_subject(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_SUBJECT ,cert));
@@ -250,6 +259,9 @@
         /*Set the public key to the x509 certificate*/
         oxs_x509_cert_set_public_key(oxs_cert, env, open_pubkey);
    
+        /*Free*/
+        AXIS2_FREE(env->allocator, x509_cert_data);
+        x509_cert_data = NULL;
         /*Free the certificate*/
         X509_free(cert);
         cert = NULL;

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=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/openssl/x509.c Sun Sep  2 22:31:34 2007
@@ -61,7 +61,11 @@
     decode_len = axutil_base64_decode_len(formatted_buf );
     buff = AXIS2_MALLOC(env->allocator, decode_len);
     ilen = axutil_strlen(formatted_buf);
-    decoded_len = axutil_base64_decode_binary(buff,formatted_buf);
+    decoded_len = axutil_base64_decode_binary(buff, formatted_buf);
+
+    AXIS2_FREE(env->allocator, formatted_buf);
+    formatted_buf = NULL;
+
     if (decoded_len < 0)
     {
         oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT, "axutil_base64_decode_binary failed");

Modified: webservices/rampart/trunk/c/src/omxmlsec/signature.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/signature.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/signature.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/signature.c Sun Sep  2 22:31:34 2007
@@ -57,7 +57,7 @@
     encodedlen = axutil_base64_encode_len(signedlen);
     encoded_str = AXIS2_MALLOC(env->allocator, encodedlen);
     ret = axutil_base64_encode(encoded_str, (const char *)oxs_buffer_get_data(signed_result_buf, env), signedlen);
-    status = oxs_buffer_populate(output, env, (unsigned char*)axutil_strdup(env, encoded_str), encodedlen);
+    status = oxs_buffer_populate(output, env, (unsigned char*)encoded_str, encodedlen);
 
     /*Free signed_result_buf*/
     oxs_buffer_free(signed_result_buf, env);

Modified: webservices/rampart/trunk/c/src/omxmlsec/tokens/token_encrypted_data.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/tokens/token_encrypted_data.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/tokens/token_encrypted_data.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/tokens/token_encrypted_data.c Sun Sep  2 22:31:34 2007
@@ -36,7 +36,6 @@
     axiom_attribute_t *type_attr = NULL;
     axiom_attribute_t *id_attr = NULL;
     axiom_namespace_t *ns_obj = NULL;
-    axiom_namespace_t *wsu_ns_obj = NULL;
     int ret;
 
     ns_obj = axiom_namespace_create(env, OXS_ENC_NS,
@@ -56,7 +55,6 @@
         ret = axiom_element_add_attribute(encrypted_data_ele, env, type_attr, encrypted_data_node);
     }
 
-    wsu_ns_obj = axiom_namespace_create(env, OXS_WSU_XMLNS, OXS_WSU);
 
 
     if(!id){

Modified: webservices/rampart/trunk/c/src/omxmlsec/xml_encryption.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/xml_encryption.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/xml_encryption.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/xml_encryption.c Sun Sep  2 22:31:34 2007
@@ -397,6 +397,9 @@
     oxs_buffer_free(input_buf, env);
     input_buf = NULL;
 
+    AXIS2_FREE(env->allocator, new_cipher_val);
+    new_cipher_val = NULL;
+    
     return status;
 }
 
@@ -533,6 +536,10 @@
     oxs_buffer_free(input_buf, env);
     input_buf = NULL;
 
+    AXIS2_FREE(env->allocator, new_cipher_val);
+    new_cipher_val = NULL;
+    
+    
     if(AXIS2_FAILURE == status){
         return AXIS2_FAILURE;
     }

Modified: webservices/rampart/trunk/c/src/omxmlsec/xml_signature.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/xml_signature.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/xml_signature.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/xml_signature.c Sun Sep  2 22:31:34 2007
@@ -143,6 +143,9 @@
     ref_id = axutil_stracat(env, "#", id);/* <ds:Reference URI="#id">*/
     reference_node = oxs_token_build_ds_reference_element(env, parent ,NULL, ref_id, NULL);
 
+    AXIS2_FREE(env->allocator, ref_id);
+    ref_id = NULL;
+
     /*Get transforms if any*/
     transforms = oxs_sign_part_get_transforms(sign_part, env);
     /*Get the digest method*/
@@ -170,6 +173,10 @@
     digest_mtd_node = oxs_token_build_digest_method_element(env, reference_node, digest_mtd);
     digest_value_node = oxs_token_build_digest_value_element(env, reference_node, digest);
 
+    /*Free*/
+    AXIS2_FREE(env->allocator, digest);
+    digest = NULL;
+ 
     return AXIS2_SUCCESS;
 }
 /**
@@ -239,12 +246,17 @@
     axiom_node_t *c14n_mtd_node = NULL;
     axis2_char_t *sign_algo = NULL;
     axis2_char_t *c14n_algo = NULL;
+    axis2_char_t *sig_id = NULL;
     axutil_array_list_t *sign_parts = NULL;
     axis2_status_t status = AXIS2_FAILURE;
     int i=0;
 
     /*Construct the <Signature> element*/
-    signature_node = oxs_token_build_signature_element(env, parent,  oxs_util_generate_id(env,OXS_SIG_ID));
+    sig_id = oxs_util_generate_id(env, OXS_SIG_ID);
+    signature_node = oxs_token_build_signature_element(env, parent, sig_id);
+
+    AXIS2_FREE(env->allocator, sig_id);
+    sig_id = NULL;
 
     /*Construct the <SignedInfo>  */
     signed_info_node = oxs_token_build_signed_info_element(env, signature_node);
@@ -493,6 +505,9 @@
         }
         oxs_sign_ctx_set_sig_val(sign_ctx, env, newline_removed);
 
+        /*We can free newline_removed string as sign_ctx duplicates it*/
+        AXIS2_FREE(env->allocator, newline_removed);
+        newline_removed = NULL;
     }else{
         /*Error the node should be the ds:SignatureValue*/
         oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Cannot find <ds:SignatureValue> " );
@@ -627,6 +642,10 @@
 
     /*In the final step we Verify*/
     status = oxs_sig_verify(env, sign_ctx, content , signature_val);
+
+    AXIS2_FREE(env->allocator, content);
+    content = NULL;
+
     if(AXIS2_FAILURE == status){
         oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Signature is not valid " );
         return AXIS2_FAILURE;

Modified: webservices/rampart/trunk/c/src/util/rampart_handler_util.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/util/rampart_handler_util.c?rev=572235&r1=572234&r2=572235&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/util/rampart_handler_util.c (original)
+++ webservices/rampart/trunk/c/src/util/rampart_handler_util.c Sun Sep  2 22:31:34 2007
@@ -106,17 +106,11 @@
                            axiom_soap_header_t *soap_header
                           )
 {
-    axutil_array_list_t *sec_headers = NULL;
-    axis2_char_t *sec_ns_str = NULL;
     axutil_hash_index_t *hash_index =  NULL;
     axutil_hash_t *header_block_ht = NULL;
     axiom_element_t *header_block_ele = NULL;
     axiom_node_t *header_block_node = NULL;
 
-    sec_headers = axiom_soap_header_get_header_blocks_with_namespace_uri(soap_header, env, RAMPART_WSSE_XMLNS);
-    if (sec_headers)
-    {
-        sec_ns_str = axutil_strdup(env, RAMPART_WSSE_XMLNS);
 
         header_block_ht = axiom_soap_header_get_all_header_blocks(soap_header, env);
         if (!header_block_ht)
@@ -145,7 +139,7 @@
             }
 
         }/*End of for*/
-    }
+
     return header_block_node;
 
 }