You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by da...@apache.org on 2006/07/27 09:54:27 UTC

svn commit: r425996 - in /webservices/axis2/trunk/c/rampart/src: Makefile.am omxmlsec/Makefile.am omxmlsec/enc_engine.c omxmlsec/key.c omxmlsec/openssl/cipher_ctx.c omxmlsec/openssl/crypt.c omxmlsec/oxs_enc.c

Author: damitha
Date: Thu Jul 27 00:54:26 2006
New Revision: 425996

URL: http://svn.apache.org/viewvc?rev=425996&view=rev
Log:
Applying patch for omxmlsec

Added:
    webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/key.c
Modified:
    webservices/axis2/trunk/c/rampart/src/Makefile.am
    webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/oxs_enc.c

Modified: webservices/axis2/trunk/c/rampart/src/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/Makefile.am?rev=425996&r1=425995&r2=425996&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/src/Makefile.am Thu Jul 27 00:54:26 2006
@@ -1 +1 @@
-SUBDIRS = handlers util core data
+SUBDIRS = handlers util core data omxmlsec

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am?rev=425996&r1=425995&r2=425996&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am Thu Jul 27 00:54:26 2006
@@ -1,7 +1,7 @@
 SUBDIRS = openssl
 noinst_LTLIBRARIES = libomxmlsec.la
-#libomxmlsec_la_SOURCES = ctx.c enc.c transforms.c  buffer.c errors.c
-libomxmlsec_la_SOURCES = buffer.c error.c axis2_utils.c axiom.c \
+
+libomxmlsec_la_SOURCES = ctx.c  enc_engine.c buffer.c key.c error.c axis2_utils.c axiom.c \
                         token_encrypted_type.c token_encryption_method.c token_cipher_value.c \
                         token_cipher_data.c token_key_name.c token_key_info.c token_binary_security_token.c \
                         token_reference_list.c token_data_reference.c

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c?rev=425996&view=auto
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c Thu Jul 27 00:54:26 2006
@@ -0,0 +1,273 @@
+/*
+ *   Copyright 2003-2004 The Apache Software Foundation.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ */
+
+#include <axis2_qname.h>
+#include <axiom_namespace.h>
+#include <axiom_node.h>
+#include <stdio.h>
+#include <axis2_util.h>
+#include <oxs_constants.h>
+#include <oxs_ctx.h>
+#include <oxs_error.h>
+#include <oxs_buffer.h>
+#include <oxs_enc_engine.h>
+#include <openssl_cipher_ctx.h>
+#include <openssl_crypt.h>
+#include <openssl_constants.h>
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_enc_encrypt(const axis2_env_t *env, 
+                enc_ctx_ptr enc_ctx,
+                oxs_buffer_ptr input,
+                axis2_char_t* key,
+                oxs_buffer_ptr result)
+{
+    unsigned char *out_main_buf;
+    openssl_evp_block_cipher_ctx_ptr bc_ctx = NULL;
+    axis2_char_t* iv =  "12345678";   
+    int ret;
+ 
+    bc_ctx = openssl_evp_block_cipher_ctx_create(env);
+    if(!bc_ctx) return (-1);
+    
+    /*Set the key*/
+    bc_ctx->key = AXIS2_STRDUP(key, env);
+    bc_ctx->key_initialized = 1;
+    /*Set the IV*/
+    bc_ctx->iv =  AXIS2_STRDUP(iv, env);
+
+    /*TODO: Get the cipher by giving the algoritm attribute */
+    ret =  openssl_evp_block_cipher_ctx_init(env, bc_ctx,
+                            OPENSSL_ENCRYPT, (unsigned char*)OPENSSL_EVP_aes_128_cbc);
+    
+    if(ret < 0) return AXIS2_FAILURE;
+    ret = openssl_block_cipher_crypt(env, bc_ctx,
+                                         input->data,  &out_main_buf, OPENSSL_ENCRYPT);
+    if(ret < 0) return AXIS2_FAILURE;
+   
+#if 0 
+    FILE *outf;
+    outf = fopen("outbuf", "wb");
+    fwrite(out_main_buf, 1, ret, outf);
+#endif
+    
+    oxs_buffer_set_size(env, result, ret);
+    result->data = out_main_buf;
+    
+    return AXIS2_SUCCESS;
+}
+
+/*We expect user to provide a template as below*/
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_enc_encrypt_template(const axis2_env_t *env,
+                        axiom_node_t* template, 
+                        axis2_char_t* data,
+                        enc_ctx_ptr enc_ctx
+                        )
+{
+    axis2_status_t  ret =  AXIS2_FAILURE;
+    oxs_buffer_ptr input = NULL;
+    oxs_buffer_ptr result = NULL;
+    axis2_char_t *key = NULL;
+   
+       
+    /*Populate enc_ctx*/
+    enc_ctx->operation = oxs_operation_encrypt;
+    
+    ret = oxs_enc_cipher_data_node_read(env, enc_ctx, template);
+    if(ret != AXIS2_SUCCESS){
+        return ret;
+    }
+    
+    /*We've populated the context*/
+    
+    /*Create the input buffer*/
+    input = oxs_string_to_buffer(env, data);
+    
+    result = oxs_create_buffer(env, ret);
+    
+    /*TODO: Obtain the key*/
+    key = "0123456789012345";
+    key = enc_ctx->key->data;
+
+    oxs_enc_encrypt(env, enc_ctx, input, key, result ); 
+    
+    printf("Encrypted Result = %s\n", oxs_buffer_to_string(env, result));
+     
+    return ret;
+    
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_enc_cipher_data_node_read(const axis2_env_t *env, 
+                                enc_ctx_ptr enc_ctx, axiom_node_t* node)
+{
+    axiom_node_t* cur = NULL;
+    axiom_element_t *ele = NULL;
+    int ret;
+    /*We've a cipher data node here.
+     The child element is either a CipherReference or a CipherValue element*/
+
+    cur = AXIOM_NODE_GET_FIRST_CHILD(node, env); 
+    if(!cur){        
+        return AXIS2_FAILURE;
+    }
+    if( oxs_axiom_check_node_name(env, cur, OXS_NodeCipherValue, OXS_EncNs )){
+        /*Got a cipher value*/
+        if(enc_ctx->operation == oxs_operation_decrypt)
+        {   
+            enc_ctx->cipher_value_node = cur;
+        } 
+    }else if(oxs_axiom_check_node_name(env, cur, OXS_NodeCipherReference, OXS_EncNs )){
+        /*Got a cipher reference*/
+        /*TODO : Support Cipher references*/
+    }
+
+    return AXIS2_SUCCESS;    
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_enc_encryption_data_node_read(const axis2_env_t *env,
+            enc_ctx_ptr enc_ctx, axiom_node_t* node)
+{
+    axiom_node_t* cur = NULL;
+    axiom_element_t *ele = NULL;
+    int ret;
+
+    if(!(enc_ctx->operation == oxs_operation_encrypt) || (enc_ctx->operation == oxs_operation_decrypt)) return (-1);
+
+    switch(enc_ctx->mode) {
+    case enc_ctx_mode_encrypted_data:
+        if(!(oxs_axiom_check_node_name(env, node, OXS_NodeEncryptedData, OXS_EncNs )))
+        {
+            return AXIS2_FAILURE;
+        }
+        break;
+    case enc_ctx_mode_encrypted_key:
+        if(!(oxs_axiom_check_node_name(env, node, OXS_NodeEncryptedKey, OXS_EncNs)))
+        {
+             return AXIS2_FAILURE;
+        }
+        break;
+    }
+
+    
+    ele = AXIOM_NODE_GET_DATA_ELEMENT(node, env);
+    if(!ele) return AXIS2_FAILURE;
+
+    enc_ctx->id = AXIOM_ELEMENT_GET_ATTRIBUTE_VALUE_BY_NAME(ele, env, OXS_AttrId);
+    enc_ctx->type = AXIOM_ELEMENT_GET_ATTRIBUTE_VALUE_BY_NAME(ele, env, OXS_AttrType);
+    enc_ctx->mime_type = AXIOM_ELEMENT_GET_ATTRIBUTE_VALUE_BY_NAME(ele, env, OXS_AttrMimeType);
+    enc_ctx->encoding = AXIOM_ELEMENT_GET_ATTRIBUTE_VALUE_BY_NAME(ele, env, OXS_AttrEncoding);
+    if(enc_ctx->mode == enc_ctx_mode_encrypted_key) {
+        enc_ctx->recipient = AXIOM_ELEMENT_GET_ATTRIBUTE_VALUE_BY_NAME(ele, env, OXS_AttrRecipient);
+    }
+    
+    cur = AXIOM_NODE_GET_NEXT_SIBLING(node, env);
+
+    /* first node is optional EncryptionMethod, we'll read it later */
+    if((cur != NULL) && (oxs_axiom_check_node_name(env, cur, OXS_NodeEncryptionMethod, OXS_EncNs))) {
+        enc_ctx->enc_method_node = cur;
+        cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
+    }
+
+    /* next node is optional KeyInfo, we'll process it later */
+    if((cur != NULL) && (  oxs_axiom_check_node_name(env, cur, OXS_NodeKeyInfo, OXS_DSigNs))) {
+    enc_ctx->key_info_node = cur;
+        cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
+    }
+
+
+    /* next is required CipherData node */
+    if((cur == NULL) || (!oxs_axiom_check_node_name(env, cur, OXS_NodeCipherData, OXS_EncNs))) {
+        return AXIS2_FAILURE;
+    }
+
+    /*TODO ret = xmlSecEncCtxCipherDataNodeRead(enc_ctx, cur);*/
+    ret = oxs_enc_cipher_data_node_read(env, enc_ctx, cur);
+    if(ret < 0) {
+        return AXIS2_FAILURE;
+    }
+    cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
+
+    /* next is optional EncryptionProperties node (we simply ignore it) */
+    if((cur != NULL) && (oxs_axiom_check_node_name(env, cur, OXS_NodeEncryptionProperties, OXS_EncNs))) {
+        cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
+    }
+
+    /* there are more possible nodes for the <EncryptedKey> node */
+    if(enc_ctx->mode == enc_ctx_mode_encrypted_key) {
+    /* next is optional ReferenceList node (we simply ignore it) */
+        if((cur != NULL) && (oxs_axiom_check_node_name(env, cur, OXS_NodeReferenceList, OXS_EncNs))) {
+        cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
+    }
+
+    /* next is optional CarriedKeyName node (we simply ignore it) */
+    if((cur != NULL) && (oxs_axiom_check_node_name(env, cur, OXS_NodeCarriedKeyName, OXS_EncNs))) {
+        enc_ctx->carriedKeyName = xmlNodeGetContent(cur);
+        if(enc_ctx->carriedKeyName == NULL) {
+            return AXIS2_FAILURE;
+        }
+        /* TODO: decode the name? */
+        cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
+    }
+    }
+
+    /* if there is something left than it's an error */
+    if( cur != NULL) return AXIS2_FAILURE;
+
+    
+    /* now read the encryption method node */
+    /*if(enc_ctx->enc_method_node != NULL) {*/
+        /*TODO xmlSecTransformCtxNodeRead*/
+        /*enc_ctx->encMethod = oxs_transform_ctx_node_read(&(enc_ctx->transformCtx), enc_ctx->encMethodNode,
+                        xmlSecTransformUsageEncryptionMethod);
+        */
+    /*if(enc_ctx->encMethod == NULL) {
+        return(-1);
+    }
+    } else if(enc_ctx->defEncMethodId != xmlSecTransformIdUnknown) {
+    enc_ctx->encMethod = xmlSecTransformCtxCreateAndAppend(&(enc_ctx->transformCtx),
+                                  enc_ctx->defEncMethodId);
+    if(enc_ctx->encMethod == NULL) {
+            xmlSecError(XMLSEC_ERRORS_HERE,
+            NULL,
+            "xmlSecTransformCtxAppend",
+            XMLSEC_ERRORS_R_XMLSEC_FAILED,
+            XMLSEC_ERRORS_NO_MESSAGE);
+        return(-1);
+    }
+    } else {
+    xmlSecError(XMLSEC_ERRORS_HERE,
+            NULL,
+            NULL,
+            XMLSEC_ERRORS_R_INVALID_DATA,
+            "encryption method not specified");
+    return(-1);
+    }
+    enc_ctx->encMethod->operation = enc_ctx->operation;
+
+*/
+
+return AXIS2_SUCCESS;
+
+}
+
+
+
+
+

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/key.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/key.c?rev=425996&view=auto
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/key.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/key.c Thu Jul 27 00:54:26 2006
@@ -0,0 +1,58 @@
+/*
+ *   Copyright 2003-2004 The Apache Software Foundation.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ */
+
+#include <stdio.h>
+#include <axis2_util.h>
+#include <oxs_key.h>
+#include <oxs_buffer.h>
+
+
+AXIS2_EXTERN oxs_key_ptr AXIS2_CALL
+oxs_key_create_key(const axis2_env_t *env,
+                    unsigned char *data,
+                    int size,
+                    int usage
+                    )
+{
+    oxs_key_ptr key = NULL;
+    key = (oxs_buffer_ptr)AXIS2_MALLOC(env->allocator,sizeof(oxs_key)); 
+    
+    key->data = data;
+    key->size = size;
+    key->usage = usage;
+    
+    return key;
+
+}
+
+
+
+AXIS2_EXTERN oxs_key_ptr AXIS2_CALL
+oxs_key_read_from_file(const axis2_env_t *env,
+                        axis2_char_t *file_name)
+{
+    oxs_buffer_ptr buf = NULL;
+    oxs_key_ptr key = NULL;
+    int ret;
+    
+    buf = oxs_create_buffer(env, OXS_KEY_DEFAULT_SIZE);
+    ret = oxs_buffer_read_file(env, buf, file_name);
+    
+    key = oxs_key_create_key(env, buf->data, buf->size, OXS_KEY_USAGE_NONE);
+    return key; 
+    
+}
+

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c?rev=425996&r1=425995&r2=425996&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c Thu Jul 27 00:54:26 2006
@@ -17,6 +17,8 @@
 #include <stdio.h>
 #include <axis2_util.h>
 #include <openssl_cipher_ctx.h>
+#include <openssl_constants.h>
+#include <oxs_error.h>
 #include <openssl/evp.h>
 #include <openssl/rand.h>
 
@@ -33,24 +35,38 @@
 AXIS2_EXTERN int  AXIS2_CALL  
 openssl_evp_block_cipher_ctx_init(const axis2_env_t *env,
                              openssl_evp_block_cipher_ctx_ptr bc_ctx,
-                             oxs_buffer_ptr in,
-                             oxs_buffer_ptr out,
                              int encrypt,
                              const unsigned char* cipher_name)
 {
+    
     int iv_len;
     int ret;
 
+    
     /*If bc_ctx is NULL create a new one*/
     if(!bc_ctx){
         bc_ctx = openssl_evp_block_cipher_ctx_create(env);
         if(!bc_ctx) return (-1); 
     }    
-
+    printf("\nCreating cipher ctx for %s", cipher_name);
     /*Set the cipher. TODO Support more ciphers later*/
-    bc_ctx->cipher = EVP_des_ede3_cbc(); 
+    if(AXIS2_STRCMP((char*)cipher_name, (char*)OPENSSL_EVP_des_ede3_cbc ))
+    {
+        bc_ctx->cipher = EVP_des_ede3_cbc();         
+    }else if(AXIS2_STRCMP((char*)cipher_name, (char*)OPENSSL_EVP_aes_128_cbc ))
+    {
+        bc_ctx->cipher = EVP_aes_128_cbc(); 
+    }else if(AXIS2_STRCMP((char*)cipher_name, (char*)OPENSSL_EVP_aes_128_cbc ))
+    {
+        bc_ctx->cipher = EVP_aes_192_cbc();
+    }else if(AXIS2_STRCMP((char*)cipher_name, (char*)OPENSSL_EVP_aes_128_cbc ))
+    {
+        bc_ctx->cipher = EVP_aes_256_cbc();
+    }else{
+        return (-1);
+    }
 
-    /*Sets the IV if not set. Well..How we convay this IV to decrypt*/
+    /*Sets the IV if not set. Well..How we convey this IV to decrypt*/
     if(!(bc_ctx->iv)){
         iv_len = EVP_CIPHER_iv_length(bc_ctx->cipher);
         ret = RAND_bytes(bc_ctx->iv, iv_len);
@@ -63,7 +79,18 @@
 
     /*Key supposed to be set before this */
     if(!bc_ctx->key) return (-1);
-        
+       
+    /*Check if key and IV sizes are not applicable for the cipher*/
+    if(EVP_CIPHER_key_length(bc_ctx->cipher) != strlen(bc_ctx->cipher) ){
+        printf("Key size is not applicable for the cipher\n");
+        return (-1);
+    }  
+
+    if(EVP_CIPHER_iv_length(bc_ctx->cipher) != strlen(bc_ctx->iv) ){
+        printf("IV size is not applicable for the cipher\n");
+        return (-1);
+    }  
+
     /*Init ctx*/    
     EVP_CIPHER_CTX_init(&(bc_ctx->cipher_ctx));
     

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c?rev=425996&r1=425995&r2=425996&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c Thu Jul 27 00:54:26 2006
@@ -21,70 +21,99 @@
 #include <openssl_crypt.h>
 #include <openssl/rand.h>
 
+#define BUFSIZE 64
+
 /**
 * @param do_encrypt should be set to 1 for encryption, 0 for decryption and -1 to
 * leave the value unchanged 
 */
-AXIS2_EXTERN int AXIS2_CALL  openssl_block_cipher_crypt(axis2_env_t *env, 
+AXIS2_EXTERN int AXIS2_CALL  openssl_block_cipher_crypt(const axis2_env_t *env, 
     openssl_evp_block_cipher_ctx_ptr bc_ctx, 
-    oxs_buffer_ptr in_buf, 
-    oxs_buffer_ptr out_buf, 
+    unsigned char *in_main_buf, 
+    unsigned char **out_main_buf, 
     int do_encrypt)
 {
-    EVP_CIPHER_CTX evp_ctx ;
-    evp_ctx = bc_ctx->cipher_ctx;
+    EVP_CIPHER_CTX ctx ;
+    ctx = bc_ctx->cipher_ctx;
+
+        unsigned char inbuf[BUFSIZE + 1 ], outbuf[BUFSIZE + EVP_MAX_BLOCK_LENGTH]; /*EVP_MAX_BLOCK_LENGTH = 32 in evp.h*/
+        unsigned char *tempbuf, *tempbuf2 ;
+        int inlen, outlen, i, in_main_len, out_buf_index;
+        int ret;
+
+        i = 0;
+        out_buf_index = 0;
+
+
+        for(;;)
+        {
+                memset(inbuf,0 ,BUFSIZE);/*Reset memory for the inbuf*/
+                memcpy(inbuf, in_main_buf + (i * BUFSIZE) , BUFSIZE );/*Copy the first block to the inbuf*/
+                inbuf[BUFSIZE] = '\0';
+
+                in_main_len = strlen((const char*)in_main_buf);
+                /*inlen = strlen(inbuf);*/
+
+                if(in_main_len <= i*BUFSIZE) break; /*Finish!!! */
+
+                /*If we are in the last block, set inlen according to the in_main_len */
+                if(in_main_len <= (i+1)*BUFSIZE)
+                {
+                    inlen = in_main_len - (i*BUFSIZE);
+                }else{
+                    inlen = BUFSIZE;
+                }
+
+                
+                if(do_encrypt == 1){
+                    printf("\nEncrypting block[%d] %s", inlen, inbuf);
+                }
+
+                memset(outbuf,0 ,BUFSIZE + EVP_MAX_BLOCK_LENGTH);/*Reset memory for the outbuf*/
+                if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen))
+                {
+                        /* Error */
+                        EVP_CIPHER_CTX_cleanup(&ctx);
+                        printf("\nERROR: EVP_CIPHER_CTX_cleanup");
+                        return (-1);
+                }
+                /*TODO: Write the encrypted block to the tempbuf*/
+                tempbuf2 = malloc(out_buf_index + outlen);
+                if(i>0){/*Skip for the i=0 step*/
+                    memcpy(tempbuf2, tempbuf, out_buf_index);
+                    /*free tempbuf*/
+                    free(tempbuf);
+                }
+                memcpy(tempbuf2 + out_buf_index, outbuf, outlen);
+                tempbuf = tempbuf2; /*Assign new tempbuf2 to the old one*/
+                out_buf_index = out_buf_index + outlen;/*Update the writing position of the tempbuf*/
+
+                i++;
+        }/*End of for loop*/
 
-    unsigned char *tempbuf;
-    int insize, outsize, block_len;
-    int outlen = 0;     
-
-    if(!bc_ctx->ctx_initialized){
-        return (-1); /* Ctx should be initialized by now*/
-    }
-    
-    block_len = EVP_CIPHER_block_size(bc_ctx->cipher);
-
-    /* loop until we dont have any data left in the input buffer */
-    for(;;)
-    {
-        insize = in_buf->size;
-
-        if(insize <= 0) break;/*No More Data!!! Quit loop*/
-
-        outsize = out_buf->size;
-        oxs_buffer_set_max_size(env, out_buf, outsize + insize + block_len);
-    
-        tempbuf = out_buf->data + outsize;
- 
-        if(!EVP_CipherUpdate(&(bc_ctx->cipher_ctx), tempbuf, &outlen, in_buf->data, insize))
+        ret = EVP_CipherFinal_ex(&ctx, outbuf, &outlen);
+        if(!ret)
         {
-            /* Error!!! Do the cleanup */
-            EVP_CIPHER_CTX_cleanup(&(bc_ctx->cipher_ctx));
-            return -1;
+                /* Error */
+                EVP_CIPHER_CTX_cleanup(&ctx);
+                printf("\nERROR:EVP_CipherFinal_ex--- EVP_CIPHER_CTX_cleanup");
+                return (-1);
         }
-    
-        /*set the correct size of the output buffer*/
-        oxs_buffer_set_size(env, out_buf, outsize + outlen );
-        printf("\noxs_buffer_set_size= %d", outsize + outlen );
-
-        /*remove the processed data from the input*/
-        oxs_buffer_remove_head(env, in_buf, insize);
-
-     }/*End of For loop*/
-
-     if(!EVP_CipherFinal_ex(&(bc_ctx->cipher_ctx), tempbuf, &outsize))
-     {
-        /* Error */
-        EVP_CIPHER_CTX_cleanup(&(bc_ctx->cipher_ctx));
-        return -1;
-     }
-     /*Now set out_buf data*/
-     out_buf->data = tempbuf;
-     oxs_buffer_set_size(env, out_buf, outsize + outlen );
-
-     EVP_CIPHER_CTX_cleanup(&(bc_ctx->cipher_ctx));
-     
-     return 1;
+        /*Alright now we need to write the last drop*/
+        tempbuf2 = malloc(out_buf_index + outlen);
+        memcpy(tempbuf2, tempbuf, out_buf_index);
+        /*free tempbuf*/
+        free(tempbuf);
+        memcpy(tempbuf2 + out_buf_index, outbuf, outlen);
+        tempbuf = tempbuf2; /*Assign new tempbuf2 to the old one*/
+        out_buf_index = out_buf_index + outlen;/*Update the writing position of the tempbuf*/
+
+        EVP_CIPHER_CTX_cleanup(&ctx);
+
+        /*Assign the temp buf to the out_main_buf*/
+        *out_main_buf = tempbuf;
+        free(tempbuf2);
+        return out_buf_index;    
 
 }
 

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/oxs_enc.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/oxs_enc.c?rev=425996&r1=425995&r2=425996&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/oxs_enc.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/oxs_enc.c Thu Jul 27 00:54:26 2006
@@ -26,7 +26,7 @@
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
 oxs_enc_binary_encrypt(const axis2_env_t *env,
-                        enc_ctx_t* ctx,
+                        enc_ctx_ptr ctx,
                         axiom_node_t* tmpl,
                         axis2_char_t* data)
 {
@@ -50,7 +50,7 @@
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
 oxs_enc_xml_encrypt(const axis2_env_t *env,
-                        enc_ctx_t* ctx,
+                        enc_ctx_ptr ctx,
                         axiom_node_t* tmpl,
                         axiom_node_t* node)
 {
@@ -61,7 +61,7 @@
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
 oxs_enc_populate_ctx(const axis2_env_t *env,
-                    enc_ctx_t* ctx,
+                    enc_ctx_ptr ctx,
                     axiom_node_t* tmpl_node)
 {
     axiom_element_t *enc_data_ele = NULL, *enc_method_ele = NULL, *key_info_ele = NULL ;



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org