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/28 08:51:58 UTC

svn commit: r426408 - in /webservices/axis2/trunk/c/rampart/src/omxmlsec: Makefile.am axiom.c cipher.c enc_engine.c error.c openssl/cipher_ctx.c

Author: damitha
Date: Thu Jul 27 23:51:57 2006
New Revision: 426408

URL: http://svn.apache.org/viewvc?rev=426408&view=rev
Log:
Applying patches and adding cipher files

Added:
    webservices/axis2/trunk/c/rampart/src/omxmlsec/cipher.c
Modified:
    webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am
    webservices/axis2/trunk/c/rampart/src/omxmlsec/axiom.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/error.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c

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=426408&r1=426407&r2=426408&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am Thu Jul 27 23:51:57 2006
@@ -1,7 +1,7 @@
 SUBDIRS = openssl
 noinst_LTLIBRARIES = libomxmlsec.la
 
-libomxmlsec_la_SOURCES = ctx.c  enc_engine.c buffer.c key.c error.c axis2_utils.c axiom.c \
+libomxmlsec_la_SOURCES = ctx.c  enc_engine.c buffer.c key.c cipher.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

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/axiom.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/axiom.c?rev=426408&r1=426407&r2=426408&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/axiom.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/axiom.c Thu Jul 27 23:51:57 2006
@@ -38,7 +38,7 @@
 }
 
 
-AXIS2_EXTERN int AXIS2_CALL
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
 oxs_axiom_check_node_name(const axis2_env_t *env, axiom_node_t* node, axis2_char_t* name, axis2_char_t* ns)
 {
     int ret_name, ret_ns;
@@ -58,11 +58,11 @@
     if(ns != NULL){
         ns_str = AXIS2_QNAME_GET_URI(qname, env);    
         ret_ns =  AXIS2_STRCMP(ns_str, ns) ;
-        if(ret_ns<0) return 0;
-        else   return 1;   
+        if(ret_ns<0) return AXIS2_FAILURE;
+        else   return AXIS2_SUCCESS;   
         
     }else{
-        return 1;
+        return AXIS2_SUCCESS;
     }
     
 

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/cipher.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/cipher.c?rev=426408&view=auto
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/cipher.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/cipher.c Thu Jul 27 23:51:57 2006
@@ -0,0 +1,70 @@
+/*
+ *   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_error.h>
+#include <oxs_cipher.h>
+#include <openssl_constants.h>
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_get_cipher(const axis2_env_t *env,
+                     axis2_char_t *url)
+{
+    if(AXIS2_STRCMP(url, (axis2_char_t*)OXS_HrefDes3Cbc)){
+        return OPENSSL_EVP_des_ede3_cbc;
+    }else if(AXIS2_STRCMP(url, (axis2_char_t*)OXS_HrefAes128Cbc)){
+        return OPENSSL_EVP_aes_128_cbc;
+    }else if(AXIS2_STRCMP(url, (axis2_char_t*)OXS_HrefAes192Cbc)){
+        return OPENSSL_EVP_aes_192_cbc;
+    }else if(AXIS2_STRCMP(url, (axis2_char_t*)OXS_HrefAes256Cbc)){
+        return OPENSSL_EVP_aes_256_cbc;
+    }else{
+        oxs_error(ERROR_LOCATION,
+                    OXS_ERROR_UNSUPPORTED_ALGO, "Algorithm not supported");
+        return NULL;
+    }
+
+    return NULL; 
+}
+
+AXIS2_EXTERN int AXIS2_CALL
+oxs_get_cipher_key_size(const axis2_env_t *env,
+                     axis2_char_t *url)
+{
+    int size = 16;
+    axis2_char_t* cipher_name = NULL;
+
+    cipher_name = oxs_get_cipher(env, url);
+    /*TODO*/
+    return size;    
+}
+
+
+AXIS2_EXTERN int AXIS2_CALL
+oxs_get_cipher_iv_size(const axis2_env_t *env,
+                     axis2_char_t *url)
+{
+    int size = 8;
+    axis2_char_t* cipher_name = NULL;
+
+    cipher_name = oxs_get_cipher(env, url);
+    /*TODO*/
+    
+    return size;
+
+}
+

Modified: 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=426408&r1=426407&r2=426408&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/enc_engine.c Thu Jul 27 23:51:57 2006
@@ -24,6 +24,7 @@
 #include <oxs_error.h>
 #include <oxs_buffer.h>
 #include <oxs_enc_engine.h>
+#include <oxs_cipher.h>
 #include <openssl_cipher_ctx.h>
 #include <openssl_crypt.h>
 #include <openssl_constants.h>
@@ -39,6 +40,8 @@
     unsigned char *out_main_buf;
     openssl_evp_block_cipher_ctx_ptr bc_ctx = NULL;
     axis2_char_t* iv =  "12345678";   
+    axis2_char_t* cipher_name =  NULL;   
+
     int ret;
  
     bc_ctx = openssl_evp_block_cipher_ctx_create(env);
@@ -51,10 +54,17 @@
     bc_ctx->iv =  AXIS2_STRDUP(iv, env);
 
     /*TODO: Get the cipher by giving the algoritm attribute */
+    cipher_name = oxs_get_cipher(env, (unsigned char*)enc_ctx->encmtd_algorithm);
+    if(!cipher_name){
+        return AXIS2_FAILURE;
+    } 
+
     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;
+                            OPENSSL_ENCRYPT, cipher_name);
+   
+    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;
@@ -87,8 +97,9 @@
        
     /*Populate enc_ctx*/
     enc_ctx->operation = oxs_operation_encrypt;
-    
-    ret = oxs_enc_cipher_data_node_read(env, enc_ctx, template);
+    enc_ctx->mode = enc_ctx_mode_encrypted_data;
+     
+    ret = oxs_enc_encryption_data_node_read(env, enc_ctx, template);
     if(ret != AXIS2_SUCCESS){
         return ret;
     }
@@ -100,8 +111,6 @@
     
     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 ); 
@@ -114,7 +123,7 @@
 
 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)
+                                enc_ctx_ptr enc_ctx, axiom_node_t* node_cipher_data)
 {
     axiom_node_t* cur = NULL;
     axiom_element_t *ele = NULL;
@@ -122,14 +131,21 @@
     /*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); 
+
+    printf("\n Found node CD %s\n", AXIOM_NODE_TO_STRING(node_cipher_data, env)); 
+    
+    cur = AXIOM_NODE_GET_FIRST_CHILD(node_cipher_data, 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)
-        {   
+        {  
+            printf("\n Found node CV %s\n", AXIOM_NODE_TO_STRING(node_cipher_data, env)); 
             enc_ctx->cipher_value_node = cur;
         } 
     }else if(oxs_axiom_check_node_name(env, cur, OXS_NodeCipherReference, OXS_EncNs )){
@@ -167,45 +183,63 @@
 
     
     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);
+    printf("\n1 Found node %s\n", AXIOM_NODE_TO_STRING(node, env));
+    cur = AXIOM_NODE_GET_FIRST_CHILD(node, env);
 
+    /*TODO remove check*/
+    if(cur == NULL){    
+         printf("Geeeee\n");
+         return AXIS2_FAILURE;
+    }
     /* first node is optional EncryptionMethod, we'll read it later */
     if((cur != NULL) && (oxs_axiom_check_node_name(env, cur, OXS_NodeEncryptionMethod, OXS_EncNs))) {
+    printf("\n2 Found node %s\n", AXIOM_NODE_TO_STRING(cur, env));
         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;
+        printf("\n3 Found node %s\n", AXIOM_NODE_TO_STRING(cur, env));
+        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))) {
+        printf("\n4 Found node %s\n", AXIOM_NODE_TO_STRING(cur, env));
         return AXIS2_FAILURE;
     }
 
-    /*TODO ret = xmlSecEncCtxCipherDataNodeRead(enc_ctx, cur);*/
+
     ret = oxs_enc_cipher_data_node_read(env, enc_ctx, cur);
     if(ret < 0) {
+        printf("\n5 Processing failed %s\n", AXIOM_NODE_TO_STRING(cur, env));
         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))) {
+        printf("\n6 Found node %s\n", AXIOM_NODE_TO_STRING(cur, env));
         cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
     }
 
@@ -213,56 +247,19 @@
     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;
+            printf("\n6 Found node %s\n", AXIOM_NODE_TO_STRING(cur, env));
+            cur = AXIOM_NODE_GET_NEXT_SIBLING(cur, env);
         }
-        /* 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;
-
-*/
+    if(enc_ctx->enc_method_node != NULL) {
+        ele = AXIOM_NODE_GET_DATA_ELEMENT(enc_ctx->enc_method_node, env);
+        enc_ctx->encmtd_algorithm = AXIOM_ELEMENT_GET_ATTRIBUTE_VALUE_BY_NAME(ele, env, OXS_AttrAlgorithm);
 
+    }
+        
 return AXIS2_SUCCESS;
 
 }

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/error.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/error.c?rev=426408&r1=426407&r2=426408&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/error.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/error.c Thu Jul 27 23:51:57 2006
@@ -19,7 +19,8 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <time.h>
-
+#include <axis2_log_default.h>
+#include <platforms/axis2_platform_auto_sense.h>
 /*Table to map error codes with the error message*/
 #define OXS_ERRORS_MAX_NUMBER 64
 static oxs_error_description oxs_errors_table[OXS_ERRORS_MAX_NUMBER] = {
@@ -70,9 +71,16 @@
   	    int code, const char* msg, ...) 
 {
     const char* error_msg = NULL;
+    char value[AXIS2_LEN_VALUE+1];
+    va_list ap;
     
     error_msg = oxs_errors_get_msg_by_code(code);	    
     /*TODO Log instead of printf*/
-    printf("\nERROR [%s:%d in %s] %s , %s\n", file, line, func, error_msg, msg);
-    
+
+    va_start(ap, msg);
+    AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, msg, ap);
+    va_end(ap);
+   
+ 
+    printf("\nERROR [%s:%d in %s] %s , %s\n", file, line, func, error_msg, value);
 }

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=426408&r1=426407&r2=426408&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 23:51:57 2006
@@ -23,6 +23,8 @@
 #include <openssl/rand.h>
 
 
+
+
 AXIS2_EXTERN openssl_evp_block_cipher_ctx_ptr AXIS2_CALL
 openssl_evp_block_cipher_ctx_create(const axis2_env_t *env)
 {



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