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 sh...@apache.org on 2009/09/09 14:00:58 UTC

svn commit: r812910 - in /webservices/rampart/trunk/c/src: omxmlsec/axiom.c omxmlsec/c14n/c14n.c omxmlsec/encryption.c omxmlsec/utility.c util/rampart_sec_header_processor.c

Author: shankar
Date: Wed Sep  9 12:00:57 2009
New Revision: 812910

URL: http://svn.apache.org/viewvc?rev=812910&view=rev
Log:
improving performance + fixing compilation issues

Modified:
    webservices/rampart/trunk/c/src/omxmlsec/axiom.c
    webservices/rampart/trunk/c/src/omxmlsec/c14n/c14n.c
    webservices/rampart/trunk/c/src/omxmlsec/encryption.c
    webservices/rampart/trunk/c/src/omxmlsec/utility.c
    webservices/rampart/trunk/c/src/util/rampart_sec_header_processor.c

Modified: webservices/rampart/trunk/c/src/omxmlsec/axiom.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/axiom.c?rev=812910&r1=812909&r2=812910&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/axiom.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/axiom.c Wed Sep  9 12:00:57 2009
@@ -396,7 +396,7 @@
     const axutil_env_t *env,  
     axis2_char_t* buffer)
 {
-    return axiom_util_string_to_node(env, buffer);
+    return axiom_node_create_from_buffer(env, buffer);
 }
 
 /**

Modified: webservices/rampart/trunk/c/src/omxmlsec/c14n/c14n.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/c14n/c14n.c?rev=812910&r1=812909&r2=812910&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/c14n/c14n.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/c14n/c14n.c Wed Sep  9 12:00:57 2009
@@ -270,12 +270,6 @@
 /* Function Prototypes */
 
 static axis2_status_t
-c14n_apply_on_node(
-    const axiom_node_t *node,
-    const c14n_ctx_t *ctx
-);
-
-static axis2_status_t
 c14n_apply_on_element(
     const axiom_node_t *node,
     const c14n_ctx_t *ctx
@@ -1065,6 +1059,7 @@
      * */
 }
 
+#if 0
 static axis2_char_t*
 c14n_normalize_text(
     axis2_char_t *text,
@@ -1153,6 +1148,123 @@
     *p++ = '\0';
     return buf;
 }
+#endif
+
+static axis2_char_t*
+c14n_normalize_text(
+    axis2_char_t *text,
+    const c14n_ctx_t *ctx)
+{
+    axis2_char_t *buf = NULL;
+    int index = 0;
+    int bufsz = INIT_BUFFER_SIZE;
+    int original_size = axutil_strlen(text);
+
+    /* TODO:DONE a better buffer implementation */
+
+    /* we need atleast the size of original text. worst case is, each character is replaced with
+     * 5 other characters (all the texts are special character). But these special characters are
+     * rare and will occur less than 10% of the time. Hence we can create a buffer with length
+     * max(INIT_BUFFER_SIZE, strlen(text)*1.5).. This will reduce the number of memcpy needed
+     */
+    if(bufsz < original_size * 1.5)
+        bufsz = original_size * 1.5;
+
+    buf = (axis2_char_t *)AXIS2_MALLOC(ctx->env->allocator, (sizeof(axis2_char_t) * bufsz));
+    if(!buf)
+    {
+        AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return buf;
+    }
+
+    while(original_size > 0)
+    {
+        size_t i = 0;
+        /* scan buffer until the next special character (&, <, >, \x0D) these need to be escaped,
+         * otherwise XML will not be valid*/
+        axis2_char_t *pos = (axis2_char_t*)strpbrk(text, "&<>\x0D");
+        if(pos)
+        {
+            i = pos - text;
+        }
+        else
+        {
+            i = original_size;
+        }
+
+        /* copy everything until the special character */
+        if(i > 0)
+        {
+            if(index + i + 6 > bufsz)
+            {
+                /* not enough space to write remaining characters + (5 character resulting
+                 * from special character + 1 NULL character). So, have to create a new buffer
+                 * and populate */
+                axis2_char_t *temp_buf = NULL;
+
+                bufsz *= 2;
+                temp_buf = (axis2_char_t *)AXIS2_MALLOC(ctx->env->allocator,
+                    sizeof(axis2_char_t) * bufsz);
+                if(!temp_buf)
+                {
+                    AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+                    return buf;
+                }
+                memcpy(temp_buf, buf, index);
+                AXIS2_FREE(ctx->env->allocator, buf);
+                buf = temp_buf;
+            }
+
+            memcpy(buf + index, text, i);
+            text += i;
+            index += i;
+            original_size -= i;
+        }
+
+        /* replace the character with the appropriate sequence */
+        if(original_size > 0)
+        {
+            switch(text[0])
+            {
+                case '&':
+                    buf[index++] = '&';
+                    buf[index++] = 'a';
+                    buf[index++] = 'm';
+                    buf[index++] = 'p';
+                    buf[index++] = ';';
+                    break;
+                case '>':
+                    buf[index++] = '&';
+                    buf[index++] = 'g';
+                    buf[index++] = 't';
+                    buf[index++] = ';';
+                    break;
+                case '<':
+                    buf[index++] = '&';
+                    buf[index++] = 'l';
+                    buf[index++] = 't';
+                    buf[index++] = ';';
+                    break;
+                case '\x0D':
+                    buf[index++] = '&';
+                    buf[index++] = '#';
+                    buf[index++] = 'x';
+                    buf[index++] = 'D';
+                    buf[index++] = ';';
+                    break;
+                default:
+                    ;
+            }
+
+            ++text;
+            --original_size;
+        }
+    }
+
+    buf[index] = '\0';
+    /*printf("buffer [%s]\n", buf);*/
+    return buf;
+}
 
 static axis2_char_t*
 c14n_normalize_attribute(

Modified: webservices/rampart/trunk/c/src/omxmlsec/encryption.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/encryption.c?rev=812910&r1=812909&r2=812910&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/encryption.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/encryption.c Wed Sep  9 12:00:57 2009
@@ -147,8 +147,10 @@
         decoded_buf = oxs_buffer_create(env);
 
         /*First we need to base64 decode*/
-        x = axutil_base64_decode_len((const char*)
-                                      oxs_buffer_get_data(input,env));
+        /*x = axutil_base64_decode_len((const char*)
+                                      oxs_buffer_get_data(input,env));*/
+        /*x = axutil_strlen(oxs_buffer_get_data(input,env)) + 1;*/ /* decoded length will be less than this*/
+        x = oxs_buffer_get_size(input, env) + 1;
         decoded_data = AXIS2_MALLOC(env->allocator, x);
         decoded_len = axutil_base64_decode_binary(decoded_data,
                             (char*)oxs_buffer_get_data(input, env));

Modified: webservices/rampart/trunk/c/src/omxmlsec/utility.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/omxmlsec/utility.c?rev=812910&r1=812909&r2=812910&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/omxmlsec/utility.c (original)
+++ webservices/rampart/trunk/c/src/omxmlsec/utility.c Wed Sep  9 12:00:57 2009
@@ -95,10 +95,10 @@
 oxs_util_get_newline_removed_string(const axutil_env_t *env,
                                     axis2_char_t *input)
 {
-    axis2_char_t *output = NULL;
+    /*axis2_char_t *output = NULL;
     int i = 0;
 
-    output = AXIS2_MALLOC(env->allocator,  axutil_strlen(input)+1);
+    output = AXIS2_MALLOC(env->allocator, axutil_strlen(input) +1);
 
     while(*input!='\0')
     {
@@ -110,5 +110,46 @@
         input++;
     }
     output[i]='\0';
+    return output;*/
+
+    axis2_char_t *output = NULL;
+    int index = 0;
+    int len = axutil_strlen(input);
+
+    output = AXIS2_MALLOC(env->allocator, len +1);
+
+    while(len > 0)
+    {
+        size_t i = 0;
+
+        /* scan buffer until the next newline character and skip it */
+        axis2_char_t *pos = (axis2_char_t*)strchr(input, '\n');
+        if(pos)
+        {
+            i = pos - input;
+        }
+        else
+        {
+            i = len;
+        }
+
+        /* write everything until the special character */
+        if(i > 0)
+        {
+            memcpy(output + index, input, i);
+            input += i;
+            index += i;
+            len -= i;
+        }
+
+        /* skip the new line */
+        if(len > 0)
+        {
+            ++input;
+            --len;
+        }
+    }
+
+    output[index]='\0';
     return output;
 }

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=812910&r1=812909&r2=812910&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 Wed Sep  9 12:00:57 2009
@@ -937,7 +937,7 @@
             oxs_key_t *key_to_decrypt = NULL;
             axis2_char_t *token_type = NULL;
             axis2_char_t *reference_method = NULL;
-            void *cert = NULL;
+            oxs_x509_cert_t *cert = NULL;
 
             /*Get the sesison key*/
             /*key_to_decrypt = rampart_shp_get_key_for_key_info(env, key_info_node, rampart_context, msg_ctx, AXIS2_FALSE);*/
@@ -1916,7 +1916,7 @@
     oxs_key_t *derived_key = NULL;
     axis2_char_t *token_type = NULL;
     axis2_char_t *reference_method = NULL;
-    void *cert = NULL;
+    oxs_x509_cert_t* cert = NULL; 
 
     /* Get the session key. */ 
     /*session_key = rampart_shp_get_key_for_key_info(