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 2007/03/08 12:58:01 UTC
svn commit: r516017 - in /webservices/axis2/trunk/c/rampart: samples/
samples/omxmlsec/ samples/omxmlsec/xmlenc/ src/omxmlsec/ test/omxmlsec/
Author: kaushalye
Date: Thu Mar 8 03:58:00 2007
New Revision: 516017
URL: http://svn.apache.org/viewvc?view=rev&rev=516017
Log:
Adding Symmetric encryption sample for OMXMLSecurity.
Added:
webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/
webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/Makefile.am
webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/enc.c
webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/input.xml (with props)
Modified:
webservices/axis2/trunk/c/rampart/samples/configure.ac
webservices/axis2/trunk/c/rampart/samples/omxmlsec/Makefile.am
webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c
webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c
Modified: webservices/axis2/trunk/c/rampart/samples/configure.ac
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/samples/configure.ac?view=diff&rev=516017&r1=516016&r2=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/samples/configure.ac (original)
+++ webservices/axis2/trunk/c/rampart/samples/configure.ac Thu Mar 8 03:58:00 2007
@@ -88,6 +88,7 @@
client/sec_echo/data/Makefile \
omxmlsec/Makefile \
omxmlsec/xmlsig/Makefile \
+ omxmlsec/xmlenc/Makefile \
keys/Makefile \
keys/ahome/Makefile \
keys/bhome/Makefile \
Modified: webservices/axis2/trunk/c/rampart/samples/omxmlsec/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/samples/omxmlsec/Makefile.am?view=diff&rev=516017&r1=516016&r2=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/samples/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/samples/omxmlsec/Makefile.am Thu Mar 8 03:58:00 2007
@@ -1,2 +1,2 @@
samplesdir=$(prefix)/samples/omxmlsec
-SUBDIRS = xmlsig
+SUBDIRS = xmlsig xmlenc
Added: webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/Makefile.am?view=auto&rev=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/Makefile.am (added)
+++ webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/Makefile.am Thu Mar 8 03:58:00 2007
@@ -0,0 +1,21 @@
+prgbindir=$(prefix)/bin/samples/rampart/omxmlsec/xmlenc
+prgbin_PROGRAMS = enc
+
+enc_SOURCES = enc.c
+
+INCLUDES = -I $(AXIS2C_HOME)/include \
+ -I ../../../include \
+ -I ../../../util/include \
+ -I ../../../axiom/include
+
+enc_LDADD = ../../../src/util/librampart_util.la \
+ ../../../src/omxmlsec/libomxmlsec.la \
+ ../../../src/omxmlsec/openssl/libomopenssl.la \
+ ../../../src/omxmlsec/tokens/liboxstokens.la \
+ ../../../../util/src/libaxis2_util.la \
+ ../../../../axiom/src/om/libaxis2_axiom.la \
+ ../../../../axiom/src/parser/libxml2/libaxis2_libxml2.la \
+ -lxml2
+
+
+EXTRA_DIST = input.xml
Added: webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/enc.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/enc.c?view=auto&rev=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/enc.c (added)
+++ webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/enc.c Thu Mar 8 03:58:00 2007
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_constants.h>
+#include <oxs_utility.h>
+#include <axiom.h>
+#include <axiom_xml_reader.h>
+#include <axis2_env.h>
+#include <oxs_ctx.h>
+#include <oxs_key.h>
+#include <oxs_error.h>
+#include <oxs_encryption.h>
+#include <oxs_xml_encryption.h>
+#include <oxs_token_encrypted_data.h>
+#include <oxs_x509_cert.h>
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+load_sample_xml(const axis2_env_t *env,
+ axiom_node_t* tmpl,
+ axis2_char_t* filename
+ )
+{
+
+ axiom_document_t *doc = NULL;
+ axiom_stax_builder_t *builder = NULL;
+ axiom_xml_reader_t *reader = NULL;
+ /*axiom_xml_writer_t *writer = NULL;*/
+
+ reader = axiom_xml_reader_create_for_file(env, filename, NULL);
+ if (!reader) printf("\n Reader is NULL");
+ builder = axiom_stax_builder_create(env, reader);
+ if (!builder) printf("\n builder is NULL");
+ doc = axiom_document_create(env, NULL, builder);
+ if (!doc) printf("\n doc is NULL");
+ tmpl = AXIOM_DOCUMENT_BUILD_ALL(doc, env);
+
+ /* tmpl = AXIOM_DOCUMENT_GET_ROOT_ELEMENT(doc, env);*/
+ if (!tmpl) printf("\n tmpl is NULL");
+ return tmpl;
+}
+
+
+oxs_key_t *create_key(axis2_env_t *env)
+{
+ oxs_key_t *key = NULL;
+ key = oxs_key_create(env);
+ OXS_KEY_POPULATE(key, env, (unsigned char*)"012345670123456701234567", "session_key", 32, OXS_KEY_USAGE_DECRYPT);
+ return key;
+}
+
+axis2_status_t decrypt(axis2_env_t *env, axis2_char_t *filename)
+{
+ oxs_ctx_t *ctx = NULL;
+ axiom_node_t *tmpl = NULL;
+ axiom_node_t *enc_data_node = NULL;
+ axiom_node_t *decrypted_node = NULL;
+ oxs_key_t *key = NULL;
+
+ tmpl = load_sample_xml(env , tmpl, filename);
+ axis2_status_t temp_status = AXIS2_FAILURE;
+ axis2_char_t *serialized_data = NULL;
+ FILE *outf;
+
+ /*Create key*/
+ key = create_key(env);
+
+ /*Create ctx*/
+ ctx = oxs_ctx_create(env);
+ OXS_CTX_SET_KEY(ctx, env, key);
+
+ /*Get the EncryptedData node*/
+ enc_data_node = AXIOM_NODE_GET_FIRST_CHILD(tmpl, env);
+ temp_status = oxs_xml_enc_decrypt_node(env, ctx, enc_data_node, &decrypted_node);
+
+ if (temp_status){
+ printf("\nooxs_xml_enc_decrypt_node SUCCESS\n");
+ }else{
+ printf("\noxs_xml_enc_decrypt_node FAILURE\n");
+ }
+ serialized_data = AXIOM_NODE_TO_STRING(tmpl, env);
+ outf = fopen("decrypted-result.xml", "wb");
+ fwrite(serialized_data, 1, AXIS2_STRLEN(serialized_data), outf);
+ fclose(outf);
+ return AXIS2_SUCCESS;
+}
+
+int main(int argc, char *argv[])
+{
+ axis2_env_t *env = NULL;
+ 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 = axis2_env_create_all("enc.log", AXIS2_LOG_LEVEL_TRACE);
+ printf("--Testing started--------------------------------------------\n");
+
+ if (argc > 1)
+ filename = argv[1];
+
+ tmpl = load_sample_xml(env , tmpl, filename);
+
+ if (tmpl)
+ {
+ printf("load_sample_xml SUCCESS\n");
+ }
+ else
+ {
+ printf("load_sample_xml FAILED");
+ return -1;
+ }
+ /*Create key*/
+ key = create_key(env);
+
+ /*Create ctx*/
+ ctx = oxs_ctx_create(env);
+ OXS_CTX_SET_KEY(ctx, env, key);
+
+ /*Set algorithm*/
+ OXS_CTX_SET_ENC_MTD_ALGORITHM(ctx, env, OXS_HREF_DES3_CBC);
+
+ /*Get the node to be encrypted*/
+ enc_node = AXIOM_NODE_GET_FIRST_CHILD(tmpl, env);
+
+ /*Create a reference to encrypted node*/
+ id = oxs_util_generate_id(env, OXS_ENCDATA_ID);
+ enc_data_node = oxs_token_build_encrypted_data_element(env, tmpl, OXS_TYPE_ENC_ELEMENT, id);
+ /*Encrypt***************************************************/
+
+ temp_status = oxs_xml_enc_encrypt_node(env, ctx, enc_node, &enc_data_node);
+
+ if (temp_status)
+ {
+ printf("\noxs_enc_encrypt_template SUCCESS\n");
+ }
+ else
+ {
+ printf("\noxs_enc_encrypt_template FAILURE\n");
+ }
+
+ encrypted_result = AXIOM_NODE_TO_STRING(tmpl, env) ;
+ /*printf("Final template is\n %s ", encrypted_result);*/
+
+ outf = fopen("result.xml", "wb");
+ fwrite(encrypted_result, 1, AXIS2_STRLEN(encrypted_result), outf);
+ fclose(outf);
+ /*Decrypt**********************************************/
+ /*decrypt(env, "result.xml");*/
+ return 0;
+}
Added: webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/input.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/input.xml?view=auto&rev=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/input.xml (added)
+++ webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/input.xml Thu Mar 8 03:58:00 2007
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Foo xmlns="urn:omxmlsec">
+ <Bar>
+ Sample text
+ </Bar>
+</Foo>
Propchange: webservices/axis2/trunk/c/rampart/samples/omxmlsec/xmlenc/input.xml
------------------------------------------------------------------------------
svn:executable = *
Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c?view=diff&rev=516017&r1=516016&r2=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c Thu Mar 8 03:58:00 2007
@@ -242,8 +242,9 @@
/*TODO : Cannonicalize <SignedInfo>*/
c14n_algo = oxs_sign_ctx_get_c14n_mtd(sign_ctx, env);
doc = axiom_node_get_document(signed_info_node, env);
- oxs_c14n_apply(env, doc, AXIS2_FALSE, &c14nized, AXIS2_TRUE, NULL, signed_info_node);
-
+
+ /*oxs_c14n_apply(env, doc, AXIS2_FALSE, &c14nized, AXIS2_TRUE, NULL, signed_info_node); */
+ oxs_c14n_apply_algo(env, doc, &c14nized, NULL, signed_info_node, c14n_algo);
AXIS2_LOG_INFO(env->log, "[oxs][xml_sig] C14N (sig)= %s ", c14nized );
/*Then serialize <SignedInfo>*/
@@ -624,8 +625,9 @@
doc = axiom_node_get_document(signed_info_node, env);
AXIS2_LOG_INFO(env->log, "[oxs][xml_sig] C14N (verif1)= %s ", axiom_node_to_string(signed_info_node, env) );
- oxs_c14n_apply(env, doc, AXIS2_FALSE, &content, AXIS2_TRUE, NULL, signed_info_node);
-
+ /* oxs_c14n_apply(env, doc, AXIS2_FALSE, &content, AXIS2_TRUE, NULL, signed_info_node);*/
+ oxs_c14n_apply_algo(env, doc, &content, NULL, signed_info_node, c14n_mtd);
+
AXIS2_LOG_INFO(env->log, "[oxs][xml_sig] C14N (verif2)= %s ", content );
/*In the final step we Verify*/
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=516017&r1=516016&r2=516017
==============================================================================
--- webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c (original)
+++ webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c Thu Mar 8 03:58:00 2007
@@ -99,7 +99,7 @@
/*We need C14N transform*/
tr = oxs_transforms_factory_produce_transform(env, OXS_HREF_TRANSFORM_XML_EXC_C14N);
axis2_array_list_add(tr_list, env, tr);
- /*oxs_sign_part_set_transforms(sign_part, env, tr_list);*/
+ oxs_sign_part_set_transforms(sign_part, env, tr_list);
/*We need to sign this node add an ID to it*/
node = axiom_node_get_first_element(tmpl, env);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org