You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ka...@apache.org on 2006/11/09 13:41:30 UTC

svn commit: r472881 - in /webservices/axis2/trunk/c/rampart: include/oxs_constants.h include/oxs_util.h src/omxmlsec/Makefile.am src/omxmlsec/encryption.c src/omxmlsec/util.c src/omxmlsec/xml_encryption.c test/omxmlsec/Makefile.am test/omxmlsec/test.c

Author: kaushalye
Date: Thu Nov  9 04:41:29 2006
New Revision: 472881

URL: http://svn.apache.org/viewvc?view=rev&rev=472881
Log:
Adding util for omxmlsec and comititng changes made in test.

Added:
    webservices/axis2/trunk/c/rampart/include/oxs_util.h
    webservices/axis2/trunk/c/rampart/src/omxmlsec/util.c
Modified:
    webservices/axis2/trunk/c/rampart/include/oxs_constants.h
    webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am
    webservices/axis2/trunk/c/rampart/src/omxmlsec/encryption.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_encryption.c
    webservices/axis2/trunk/c/rampart/test/omxmlsec/Makefile.am
    webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c

Modified: webservices/axis2/trunk/c/rampart/include/oxs_constants.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/include/oxs_constants.h?view=diff&rev=472881&r1=472880&r2=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/include/oxs_constants.h (original)
+++ webservices/axis2/trunk/c/rampart/include/oxs_constants.h Thu Nov  9 04:41:29 2006
@@ -35,7 +35,9 @@
 #define OXS_WSSE "wsse"
 
 
-
+/*ID Prefixes*/
+#define OXS_ENCDATA_ID "EncDataID"
+#define OXS_ENCKEY_ID "EncKeyID"
 
 /* Global namespaces *******************/
 

Added: webservices/axis2/trunk/c/rampart/include/oxs_util.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/include/oxs_util.h?view=auto&rev=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/include/oxs_util.h (added)
+++ webservices/axis2/trunk/c/rampart/include/oxs_util.h Thu Nov  9 04:41:29 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2005 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.
+ */
+
+#ifndef OXS_UTIL_H
+#define OXS_UTIL_H
+
+
+/**
+  * @file oxs_util.h
+  * @brief 
+  */
+
+#include <axis2_defines.h>
+#include <axis2_env.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* Generates an id for an element.
+ * Specially used in xml encryption and signature references.
+ * */
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_util_generate_id(const axis2_env_t *env,
+        axis2_char_t *prefix);
+
+
+/** @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif                          /* OXS_UTIL_H */

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?view=diff&rev=472881&r1=472880&r2=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am Thu Nov  9 04:41:29 2006
@@ -4,7 +4,8 @@
 libomxmlsec_la_SOURCES = ctx.c  enc_engine.c buffer.c key.c cipher.c error.c axis2_utils.c axiom.c \
                         token_encrypted_data.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 token_encrypted_key.c iv.c xml_encryption.c encryption.c
+                        token_reference_list.c token_data_reference.c token_encrypted_key.c iv.c xml_encryption.c encryption.c\
+						util.c
 
 libomxmlsec_la_LIBADD  = -lssl\
 			../../../util/src/libaxis2_util.la \

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/encryption.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/encryption.c?view=diff&rev=472881&r1=472880&r2=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/encryption.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/encryption.c Thu Nov  9 04:41:29 2006
@@ -116,19 +116,17 @@
         /*Free*/
         AXIS2_FREE(env->allocator, encoded_str);
         encoded_str = NULL;
-        AXIS2_FREE(env->allocator, out_main_buf);
-        out_main_buf = NULL;    
 
     /*DECRYPTION*/
     }else if(OXS_CTX_GET_OPERATION(enc_ctx, env) == OXS_CTX_OPERATION_DECRYPT){
-        unsigned char *decoded_data = NULL;
+        unsigned char *decoded_data = NULL;/*Can be binary*/
         unsigned char *out_main_buf = NULL;
         int decoded_len = -1;
         int enclen = -1;
 
         /*First we need to base64 decode*/
-        decoded_data = AXIS2_MALLOC(env->allocator, axis2_base64_decode_len((char*)(OXS_CTX_GET_INPUT_DATA(enc_ctx, env))));
-        decoded_len = axis2_base64_decode_binary(decoded_data, (char*)(OXS_CTX_GET_INPUT_DATA(enc_ctx, env)) );
+        decoded_data = AXIS2_MALLOC(env->allocator, axis2_base64_decode_len((char*)OXS_BUFFER_GET_DATA(input, env)));
+        decoded_len = axis2_base64_decode_binary(decoded_data, (char*)OXS_BUFFER_GET_DATA(input, env) );
         if (decoded_len < 0)
         {
             oxs_error(ERROR_LOCATION, OXS_ERROR_DECRYPT_FAILED,
@@ -142,8 +140,6 @@
         /*Free*/
         AXIS2_FREE(env->allocator, decoded_data);
         decoded_data = NULL;
-        AXIS2_FREE(env->allocator, out_main_buf);
-        out_main_buf = NULL;
 
     }else{
         oxs_error(ERROR_LOCATION, OXS_ERROR_INVALID_DATA,

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/util.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/util.c?view=auto&rev=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/util.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/util.c Thu Nov  9 04:41:29 2006
@@ -0,0 +1,39 @@
+/*
+ *   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_util.h>
+#include <oxs_error.h>
+
+/* Generates an id for an element.
+ * Specially used in xml encryption and signature references.
+ * */
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_util_generate_id(const axis2_env_t *env,
+        axis2_char_t *prefix)
+{
+    axis2_char_t *id = NULL;
+    char _id[50];
+    axis2_char_t *random ;
+
+    random =  AXIS2_STRNDUP(axis2_uuid_gen(env),18, env);
+    sprintf(_id, "%s-%s",prefix,random);
+    id = (axis2_char_t*)strdup(_id);
+    return id;
+    
+}
+

Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_encryption.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_encryption.c?view=diff&rev=472881&r1=472880&r2=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_encryption.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_encryption.c Thu Nov  9 04:41:29 2006
@@ -56,6 +56,10 @@
     /*We call encrypt_data*/
     ret = oxs_xml_enc_encrypt_data(env, enc_ctx, serialized_buf, enc_type_node); 
     
+    /*Remove the node from the parent*/
+    if(AXIS2_SUCCESS == ret){
+        AXIOM_NODE_DETACH(node, env);
+    }
     /*Free*/
     OXS_BUFFER_FREE(serialized_buf, env); 
 
@@ -69,7 +73,9 @@
                             axiom_node_t *enc_type_node,
                             axiom_node_t **decrypted_node)
 {
+
     
+
     return AXIS2_SUCCESS;
 }
 
@@ -94,7 +100,7 @@
     sym_key = OXS_CTX_GET_KEY(enc_ctx, env);
 
     /*Set the operation to encrypt*/
-    OXS_CTX_SET_OPERATION(enc_ctx, env, OXS_CTX_OPERATION_DECRYPT);
+    OXS_CTX_SET_OPERATION(enc_ctx, env, OXS_CTX_OPERATION_ENCRYPT);
 
     /*Create an empty buffer for encrypted data*/
     result_buf = oxs_buffer_create(env);
@@ -106,7 +112,6 @@
     cd_node = oxs_token_build_cipher_data_element(env, *enc_type_node);
     cv_node = oxs_token_build_cipher_value_element(env, cd_node, (axis2_char_t*)OXS_BUFFER_GET_DATA(result_buf, env));
 
-    /*Replace the node with enc_type_node*/
     /*Free buffers*/
     OXS_BUFFER_FREE(result_buf, env); 
 

Modified: webservices/axis2/trunk/c/rampart/test/omxmlsec/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/test/omxmlsec/Makefile.am?view=diff&rev=472881&r1=472880&r2=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/test/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/test/omxmlsec/Makefile.am Thu Nov  9 04:41:29 2006
@@ -1,8 +1,7 @@
 TESTS = test_oxs
 bin_PROGRAMS = test_oxs
-SUBDIRS =
 
-AM_CFLAGS = -g -O2 -pthread
+#AM_CFLAGS = -g -O2 -pthread
 
 test_oxs_SOURCES =  test.c
 

Modified: webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c?view=diff&rev=472881&r1=472880&r2=472881
==============================================================================
--- webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c (original)
+++ webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c Thu Nov  9 04:41:29 2006
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <axis2_util.h>
 #include <oxs_constants.h>
+#include <oxs_util.h>
 #include <axiom.h>
 #include <axiom_xml_reader.h>
 #include <axis2_env.h>
@@ -64,14 +65,14 @@
 
 int main(int argc, char *argv[])
 {
-    oxs_error(ERROR_LOCATION, OXS_ERROR_DEFAULT, "Api danne neee %d", 13);
     axis2_env_t *env = NULL;
-    axis2_char_t *filename = "a.xml";
+    axis2_char_t *filename = "input.xml";
     oxs_ctx_t *ctx = NULL;
     oxs_key_t *key = NULL;
     axis2_status_t temp_status = AXIS2_FAILURE;
     axiom_node_t *tmpl = NULL, *enc_node = NULL, *enc_data_node = NULL;
     axis2_char_t *encrypted_result = NULL;
+    axis2_char_t *id = NULL;
     FILE *outf;
 
     env = test_init();
@@ -100,13 +101,15 @@
     OXS_CTX_SET_KEY(ctx, env, key);
 
     /*Set algorithm*/
-    OXS_CTX_SET_ENC_MTD_ALGORITHM(ctx, env, OXS_HrefAes128Cbc);
+    OXS_CTX_SET_ENC_MTD_ALGORITHM(ctx, env, OXS_HrefAes256Cbc);
 
     /*Get the node to be encrypted*/
     enc_node = AXIOM_NODE_GET_FIRST_CHILD(tmpl, env);
 
     /*Create a reference to encrypted node*/
-    enc_data_node =  oxs_token_build_encrypted_data_element(env, tmpl, "xml-element", "id"); 
+    id =  oxs_util_generate_id(env, OXS_ENCDATA_ID);
+    printf("ID=%s\n",id);
+    enc_data_node =  oxs_token_build_encrypted_data_element(env, tmpl, OXS_TypeEncElement, id); 
     /*Encrypt***************************************************/
 
     temp_status = oxs_xml_enc_encrypt_node(env, ctx,  enc_node, &enc_data_node);
@@ -121,7 +124,7 @@
     }
 
     encrypted_result = AXIOM_NODE_TO_STRING(tmpl, env) ;
-    printf("Final template is\n %s  ", encrypted_result);
+    /*printf("Final template is\n %s  ", encrypted_result);*/
 
     outf = fopen("result.xml", "wb");
     fwrite(encrypted_result, 1, AXIS2_STRLEN(encrypted_result), outf);



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