Added: webservices/rampart/tags/c/0.90/test/omxmlsec/test.c URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/omxmlsec/test.c?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/omxmlsec/test.c (added) +++ webservices/rampart/tags/c/0.90/test/omxmlsec/test.c Thu Sep 6 03:48:44 2007 @@ -0,0 +1,248 @@ +/* + * 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 <oxs_axiom.h> +#include <axiom.h> +#include <axiom_xml_reader.h> +#include <axutil_env.h> +#include <oxs_ctx.h> +#include <oxs_key.h> +#include <oxs_key_mgr.h> +#include <openssl_pkey.h> +#include <oxs_error.h> +#include <oxs_transform.h> +#include <oxs_transforms_factory.h> +#include <oxs_xml_signature.h> +#include <oxs_sign_ctx.h> +#include <oxs_sign_part.h> +#include <oxs_xml_key_processor.h> +#include <oxs_xml_key_info_builder.h> + +AXIS2_EXTERN axiom_node_t* AXIS2_CALL +load_sample_xml(const axutil_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; +} + +axis2_status_t sign(axutil_env_t *env, + axis2_char_t *filename, + openssl_pkey_t *prvkey , + oxs_x509_cert_t *cert) +{ + axis2_char_t *signed_result = NULL; + axis2_char_t *signed_filename = "result-sign.xml"; + axiom_node_t *node = NULL; + axiom_node_t *tmpl = NULL; + oxs_sign_part_t *sign_part = NULL; + oxs_sign_ctx_t *sign_ctx = NULL; + oxs_transform_t *tr = NULL; + axutil_array_list_t *sign_parts = NULL; + axutil_array_list_t *tr_list = NULL; + axis2_char_t *id = NULL; + axis2_status_t status = AXIS2_FAILURE; + FILE *outf; + + tmpl = load_sample_xml(env , tmpl, filename); + + if (tmpl) + { + printf("load_sample_xml SUCCESS\n"); + } + else + { + printf("load_sample_xml FAILED"); + return -1; + } + + /*Sign specific*/ + sign_part = oxs_sign_part_create(env); + + tr_list = axutil_array_list_create(env, 1); + /*We need C14N transform*/ + tr = oxs_transforms_factory_produce_transform(env, OXS_HREF_TRANSFORM_XML_EXC_C14N); + axutil_array_list_add(tr_list, env, tr); + 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); + id = /*"Sig-ID-EFG";*/ oxs_util_generate_id(env,(axis2_char_t*)OXS_SIG_ID); + oxs_axiom_add_attribute(env, node, OXS_WSU, OXS_WSSE_XMLNS, OXS_ATTR_ID, id); + status = oxs_sign_part_set_node(sign_part, env,node); + + status = oxs_sign_part_set_digest_mtd(sign_part, env, OXS_HREF_SHA1); + + sign_parts = axutil_array_list_create(env, 1); + axutil_array_list_add(sign_parts, env, sign_part); + sign_ctx = oxs_sign_ctx_create(env); + if(sign_ctx){ + axiom_node_t *sig_node = NULL; + + oxs_sign_ctx_set_private_key(sign_ctx, env, prvkey); + oxs_sign_ctx_set_certificate(sign_ctx, env, cert); + /*Set sig algo*/ + oxs_sign_ctx_set_sign_mtd_algo(sign_ctx, env, OXS_HREF_RSA_SHA1); + /*Set C14N method*/ + oxs_sign_ctx_set_c14n_mtd(sign_ctx, env, OXS_HREF_XML_EXC_C14N); + /*Set sig parts*/ + oxs_sign_ctx_set_sign_parts(sign_ctx, env, sign_parts); + /*Set the operation*/ + oxs_sign_ctx_set_operation(sign_ctx, env, OXS_SIGN_OPERATION_SIGN); + /*Sign*/ + oxs_xml_sig_sign(env, sign_ctx, tmpl, &sig_node); + /*Finally build KeyInfo*/ + oxs_xml_key_info_build(env, sig_node, cert, OXS_KIBP_X509DATA_X509CERTIFICATE); + }else{ + printf("Sign ctx creation failed"); + } + signed_result = axiom_node_to_string(tmpl, env) ; + + outf = fopen(signed_filename, "wb"); + fwrite(signed_result, 1, axutil_strlen(signed_result), outf); + + return AXIS2_SUCCESS; + +} + +axis2_status_t verify(axutil_env_t *env, + axis2_char_t *filename, + openssl_pkey_t *prvkey , + oxs_x509_cert_t *cert) +{ + oxs_sign_ctx_t *sign_ctx = NULL; + axiom_node_t *tmpl = NULL; + axis2_status_t status = AXIS2_FAILURE; + + tmpl = load_sample_xml(env , tmpl, filename); + printf("File : \n%s\n", axiom_node_to_string(tmpl, env)); + sign_ctx = oxs_sign_ctx_create(env); + if(sign_ctx){ + axiom_node_t *sig_node = NULL; + /*Set the operation*/ + oxs_sign_ctx_set_operation(sign_ctx, env, OXS_SIGN_OPERATION_VERIFY); + + sig_node = oxs_axiom_get_first_child_node_by_name(env, tmpl, + OXS_NODE_SIGNATURE, OXS_DSIG_NS, OXS_DS ); + if(!sig_node){ + printf("Verification : Cannot find ds:Signature node\n"); + return AXIS2_FAILURE; + } + + /**If the certificate is not given check key information*/ + if(!cert){ + axiom_node_t *ki_node = NULL; + axiom_node_t *x509_node = NULL; + ki_node = oxs_axiom_get_first_child_node_by_name(env, sig_node, OXS_NODE_KEY_INFO, OXS_DSIG_NS, OXS_DS); + x509_node = oxs_axiom_get_first_child_node_by_name(env, ki_node, OXS_NODE_X509_DATA, OXS_DSIG_NS, OXS_DS); + + cert = oxs_x509_cert_create(env); + printf("No certificate is given. Fetching certificate from the KeyInfo\n"); + status = oxs_xml_key_process_X509Data(env, x509_node, cert); + if(AXIS2_FAILURE == status){ + printf("Error reading KeyInfo\n"); + return AXIS2_FAILURE; + } + } + + + /*Set certificate*/ + if(cert){ + oxs_sign_ctx_set_certificate(sign_ctx, env, cert); + }else{ + printf("Certificate is NULL\n"); + return AXIS2_FAILURE; + } + /*Verify*/ + status = oxs_xml_sig_verify(env, sign_ctx, sig_node, tmpl); + if(AXIS2_SUCCESS != status){ + printf("\nSignature Failed :-(\n"); + }else{ + printf("\nSignature Verified :-)\n"); + } + } + + return status; +} + +int main(int argc, char *argv[]) +{ + axutil_env_t *env = NULL; + axis2_char_t *filename = NULL; + axis2_char_t *certfile = NULL; + axis2_char_t *prvkeyfile = NULL; + axis2_char_t *operation = NULL; + openssl_pkey_t *prvkey = NULL; + oxs_x509_cert_t *cert = NULL; + + + if (argc > 2){ + filename = argv[1]; + operation = argv[2]; + certfile = argv[3]; + prvkeyfile = argv[4]; + }else{ + printf("Usage ./test inputfile operation[S/V] certificate prvkey \n"); + return -1; + } + + env = axutil_env_create_all("./oxs.log", AXIS2_LOG_LEVEL_TRACE); + printf("--Testing started--------------------------------------------\n"); + + /*Load private key*/ + prvkey = oxs_key_mgr_load_private_key_from_pem_file(env, prvkeyfile, ""); + if(!prvkey){ + printf("Cannot load private key"); + } + + /*Load certificate*/ + cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, certfile); + if(!cert){ + printf("Cannot load certificate"); + } + + if(0 == axutil_strcmp(operation, "S")){ + sign(env, filename, prvkey, cert); + }else{ + verify(env, filename, prvkey, cert); + } + + printf("\nDONE\n"); + return 0; +}
Added: webservices/rampart/tags/c/0.90/test/openssl/Makefile.am URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/Makefile.am?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/Makefile.am (added) +++ webservices/rampart/tags/c/0.90/test/openssl/Makefile.am Thu Sep 6 03:48:44 2007 @@ -0,0 +1,4 @@ +SUBDIRS = sign + + + Added: webservices/rampart/tags/c/0.90/test/openssl/block_cipher_test.c URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/block_cipher_test.c?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/block_cipher_test.c (added) +++ webservices/rampart/tags/c/0.90/test/openssl/block_cipher_test.c Thu Sep 6 03:48:44 2007 @@ -0,0 +1,195 @@ +/* + * 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 <axutil_env.h> +#include <oxs_buffer.h> +#include <oxs_error.h> +#include <openssl_cipher_ctx.h> +#include <openssl_crypt.h> +#include <openssl_constants.h> +#include <oxs_axutil_utils.h> + + + +axutil_env_t *test_init() +{ + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + axutil_error_t *error = (axutil_error_t*)axis2_error_create(allocator); + axutil_env_t *env = axutil_env_create_with_error(allocator, error); + return env; +} +#if 0 +int decrypt(axutil_env_t *env, oxs_buffer_ptr in, unsigned char *key, unsigned char *iv) +{ + openssl_evp_block_cipher_ctx_ptr bc_ctx = NULL; + oxs_buffer_ptr out = NULL; + oxs_buffer_ptr decoded_buf = NULL; + int ret; + + printf("--Decrypt started--------------------------------------------\n"); + + out = oxs_create_buffer(env, OXS_BUFFER_INITIAL_SIZE); + + bc_ctx = openssl_evp_block_cipher_ctx_create(env); + if (!bc_ctx) return(-1); + + /*Set the key*/ + bc_ctx->key = key; + bc_ctx->key_initialized = 1; + + /*Set the IV*/ + bc_ctx->iv = iv; + + ret = openssl_evp_block_cipher_ctx_init(env, bc_ctx, OPENSSL_DECRYPT, (unsigned char*)OPENSSL_EVP_aes_128_cbc); + if (ret < 0) + { + return -1; + } + + /*Now Decode */ + decoded_buf = oxs_base64_decode(env, in); + if (!decoded_buf) return -1; + + ret = openssl_block_cipher_crypt(env, bc_ctx, decoded_buf, out, OPENSSL_DECRYPT); + if (ret < 0) + { + return -1; + } + + printf("\nOut Size =\n %d ", out->size); + printf("\nOut Data =\n %s ", out->data); + + return (0); +} +#endif +int main() +{ + FILE *outf; + /*FILE *outf2; + oxs_buffer_ptr encoded_buf = NULL; + oxs_buffer_ptr out = NULL; + */ + axutil_env_t *env = NULL; + oxs_buffer_ptr in = NULL; + axis2_char_t *plain_text = NULL; + unsigned char *out_main_buf = NULL , *out_main_buf2 = NULL; + + unsigned char key[EVP_MAX_KEY_LENGTH] = "012345670123456701234567"; + unsigned char iv[EVP_MAX_IV_LENGTH] = "01234567"; + + unsigned char *cipher_name = NULL; + + openssl_evp_block_cipher_ctx_ptr bc1_ctx = NULL; + openssl_evp_block_cipher_ctx_ptr bc2_ctx = NULL; + int ret, encrypted_len, decrypted_len; + + + env = test_init(); + printf("--Testing started Openssl Block Cipher--------------------------------------------\n"); +#if 0 + plain_text = "Upon successful completion, fread() returns the number of ...END" + "Upon successful completion, fread() returns the number of ...END"; + /*"This is an additional block :)";*/ + +#else + + plain_text = "PLAINTEXT"; +#endif + in = oxs_string_to_buffer(env, plain_text); + + cipher_name = (unsigned char*)OPENSSL_EVP_des_ede3_cbc; + + bc1_ctx = openssl_evp_block_cipher_ctx_create(env); + if (!bc1_ctx) return(-1); + /*Set the key*/ + bc1_ctx->key = key; /*axutil_strdup(key, env);*/ + bc1_ctx->key_initialized = 1; + /*Set the IV*/ + bc1_ctx->iv = axutil_strdup(env, iv); + ret = openssl_evp_block_cipher_ctx_init(env, bc1_ctx, + OPENSSL_ENCRYPT, cipher_name); + if (ret < 0) + { + printf("openssl_evp_block_cipher_ctx_init failed\n"); + return -1; + } + + ret = openssl_block_cipher_crypt(env, bc1_ctx, + in->data, strlen((char*)in->data), &out_main_buf, OPENSSL_ENCRYPT); + if (ret < 0) + { + printf("openssl_block_cipher_crypt OPENSSL_ENCRYPT failed\n"); + return -1; + } + encrypted_len = ret; + + printf("\nEncrypted data size =%d \n ", ret); + outf = fopen("outbuf", "wb"); + fwrite(out_main_buf, 1, ret, outf); + + /* out = oxs_create_buffer(env, ret);*/ + + /*********************Decrypt***********************/ + bc2_ctx = openssl_evp_block_cipher_ctx_create(env); + if (!bc2_ctx) return(-1); + /*Set the key*/ + bc2_ctx->key = key; /*axutil_strdup(key, env);*/ + bc2_ctx->key_initialized = 1; + /*Set the IV*/ + bc2_ctx->iv = axutil_strdup(env, iv); + ret = openssl_evp_block_cipher_ctx_init(env, bc2_ctx, + OPENSSL_DECRYPT, cipher_name); + if (ret < 0) + { + printf("openssl_evp_block_cipher_ctx_init failed\n"); + return -1; + } + + ret = openssl_block_cipher_crypt(env, bc2_ctx, + out_main_buf, encrypted_len, &out_main_buf, OPENSSL_DECRYPT); + + if (ret < 0) + { + printf("openssl_block_cipher_crypt OPENSSL_DECRYPT failed\n"); + return -1; + } + decrypted_len = ret; + + printf("\nDecrypted data[%d] %s\n ", ret, out_main_buf2); + + +#if 0 + /*Now Encode */ + encoded_buf = oxs_base64_encode(env, out); + + if (!encoded_buf) return -1; + + + printf("\nencrypted_encoded_buf Size =\n %d ", encoded_buf->size); + printf("\nencrypted_encoded_buf Data =\n %s ", encoded_buf->data); + + /*Now we need to decrypt*/ + /*===============================================================*/ + + ret = decrypt(env, encoded_buf, key, iv); + if (ret < 0) return -1; +#endif + return (0); +} Added: webservices/rampart/tags/c/0.90/test/openssl/deskey.bin URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/deskey.bin?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/deskey.bin (added) +++ webservices/rampart/tags/c/0.90/test/openssl/deskey.bin Thu Sep 6 03:48:44 2007 @@ -0,0 +1 @@ +0123456701234567 Added: webservices/rampart/tags/c/0.90/test/openssl/rsa/Makefile.am URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/rsa/Makefile.am?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/rsa/Makefile.am (added) +++ webservices/rampart/tags/c/0.90/test/openssl/rsa/Makefile.am Thu Sep 6 03:48:44 2007 @@ -0,0 +1,20 @@ +TESTS = test +noinst_PROGRAMS = test +SUBDIRS = + +AM_CFLAGS = -g -O2 -pthread + +#test_SOURCES = des_test.c +test_SOURCES = test_rsa.c + +INCLUDES = -I$(top_builddir)/include \ + @UTILINC@ \ + @AXIOMINC@ + +test_LDADD = $(top_builddir)/src/util/librampart_util.la \ + $(top_builddir)/src/omxmlsec/libomxmlsec.la \ + $(top_builddir)/src/omxmlsec/openssl/libomopenssl.la \ + -laxis2_util \ + -laxis2_axiom \ + -laxis2_libxml2 \ + -lxml2 Added: webservices/rampart/tags/c/0.90/test/openssl/rsa/rsakey.pem URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/rsa/rsakey.pem?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/rsa/rsakey.pem (added) +++ webservices/rampart/tags/c/0.90/test/openssl/rsa/rsakey.pem Thu Sep 6 03:48:44 2007 @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQDC5sM/WS61ejcjwy67l+TviK7o03g3KdJ6ZCktIKMADQOkARbg ++KTPs33qcn3djqtcD4l+u/+JMKShVRD6Td7ELmeVuYcrPZWSrfH/gyD394bJE2gC +HEMBj9UJ9xMRagcsqUouDt/UV5I/4KeMMpc0igTO4Wo7SSYEVzIscBUXtwIDAQAB +AoGAB7z1v4wg6J+jlM3pCxWqxz/cAe5zdW05qBZV9C65igT6QgaxC9mTYZO0yhwl +lyhU8WDEir2YFbBSuP0RoX55+6pGP23I4wG0cEujZ2OZ8W0vNCwFL0gp15cLUxL2 +8xVrJ24o1k4xVf6P85wLkfNeFTR3DqssIEMbu++pxiaIVKECQQDkK4pAASencmJa +SzjECJxGiG+jpVEKwRFLHgvAKmdb8aY7n/awJchH/i92WmpE5C2Fc4xNRf3wo6VO +Zjfgzsu5AkEA2qxuQDtcE1a+MQyaX7oA3mLEKcXon0T2rLeSWupuM0AkHCzTs8R1 +JZ9DYSI8mOMuHxsV448kblnuJY3LNRsW7wJATZGfxnKeEIcKeLfp7Hsg5bmsem3R +R16rimYEiKfhy5gzc0HGk8vEcvUvHYVPa2xHLX9Cy2JoGk8H+8c0Z/DlwQJAQ8fS +3MIJhk0K4vU/HJDxF/2RREl+E3Ay7dJw4RFtWyF0j+8tJ7mrfh/hqMgN9G3mq+mf +XUvPRQ1HDgjnheyBrQJBAMS4TJlJ65ZC0yLtmcrBh8mWzW47qRjrqdybL2YNQvLw +RskEXwTc127gJeOwiQFAfNyQzlN4do/fzcDztmiMgbI= +-----END RSA PRIVATE KEY----- Added: webservices/rampart/tags/c/0.90/test/openssl/rsa/rsapub.pem URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/rsa/rsapub.pem?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/rsa/rsapub.pem (added) +++ webservices/rampart/tags/c/0.90/test/openssl/rsa/rsapub.pem Thu Sep 6 03:48:44 2007 @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC5sM/WS61ejcjwy67l+TviK7o +03g3KdJ6ZCktIKMADQOkARbg+KTPs33qcn3djqtcD4l+u/+JMKShVRD6Td7ELmeV +uYcrPZWSrfH/gyD394bJE2gCHEMBj9UJ9xMRagcsqUouDt/UV5I/4KeMMpc0igTO +4Wo7SSYEVzIscBUXtwIDAQAB +-----END PUBLIC KEY----- Added: webservices/rampart/tags/c/0.90/test/openssl/rsa/test_rsa.c URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/rsa/test_rsa.c?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/rsa/test_rsa.c (added) +++ webservices/rampart/tags/c/0.90/test/openssl/rsa/test_rsa.c Thu Sep 6 03:48:44 2007 @@ -0,0 +1,101 @@ +/* + * 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 <axutil_env.h> +#include <oxs_buffer.h> +#include <oxs_error.h> +#include <openssl_rsa.h> +#include <openssl_digest.h> +#include <openssl_constants.h> +#include <oxs_axutil_utils.h> + +axutil_env_t *test_init() +{ + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + axutil_error_t *error = (axutil_error_t*)axis2_error_create(allocator); + axutil_env_t *env = axutil_env_create_with_error(allocator, error); + return env; +} + +int md5(){ + axutil_env_t *env = NULL; + axis2_char_t *plaintext = NULL; + + env = test_init(); + plaintxt = (unsigned char *)"We will we will rock ya..."; + + openssl_md5(env, plaintxt , axutil_strlen(plaintxt)); + printf("Finish md5() \n"); + return 0; +} + +int encdec() +{ + axutil_env_t *env = NULL; + evp_pkey_ptr pubk, prvk = NULL; + unsigned char *plaintxt = NULL, *encrypted = NULL, *decrypted = NULL; + oxs_buffer_ptr randkey = NULL; + int ret; + + + env = test_init(); + plaintxt = (unsigned char *)"We will we will rock ya..."; + + /******************/ + /* ret = generate_random_key(env, randkey, 24 ); + if(ret < 0 ){ + printf("Error generating random key \n"); + return ret; + }else{ + printf("Generated random key is %s", randkey->data); + }*/ + /******************/ + + + pubk = evp_pkey_load(env, "rsapub.pem", ""); + ret = openssl_rsa_pub_encrypt(env, pubk, plaintxt, &encrypted); + if (ret < 0) + { + printf("Encryption error \n"); + return ret; + } + + printf("Encrypted text = [%d]\n", ret); + + prvk = evp_pkey_load(env, "rsakey.pem", ""); + ret = openssl_rsa_prv_decrypt(env, prvk, encrypted, &decrypted); + if (ret < 0) + { + printf("Decryption error \n"); + return ret; + } + printf("Decrypted text = [%d]\n%s\n", ret, decrypted); + return 0; +} + + + + +int main() +{ +/* return encdec();*/ + return md5(); + +} Added: webservices/rampart/tags/c/0.90/test/openssl/sign/Makefile.am URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/sign/Makefile.am?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/sign/Makefile.am (added) +++ webservices/rampart/tags/c/0.90/test/openssl/sign/Makefile.am Thu Sep 6 03:48:44 2007 @@ -0,0 +1,23 @@ +TESTS = test +noinst_PROGRAMS = test +SUBDIRS = + +AM_CFLAGS = -g -pthread + +#test_SOURCES = des_test.c +test_SOURCES = test.c + + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../include \ + @AXIS2INC@ + +test_LDADD = $(top_builddir)/src/util/librampart_util.la \ + $(top_builddir)/src/omxmlsec/libomxmlsec.la \ + $(top_builddir)/src/omxmlsec/openssl/libomopenssl.la \ + $(top_builddir)/src/omxmlsec/tokens/liboxstokens.la \ + ${AXIS2C_HOME}/lib/libaxis2_parser.la \ + ${AXIS2C_HOME}/lib/libaxis2_axiom.la \ + ${AXIS2C_HOME}/lib/libaxutil.la \ + -lxml2 + Added: webservices/rampart/tags/c/0.90/test/openssl/sign/cert.pem URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/sign/cert.pem?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/sign/cert.pem (added) +++ webservices/rampart/tags/c/0.90/test/openssl/sign/cert.pem Thu Sep 6 03:48:44 2007 @@ -0,0 +1,62 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: + dc:83:fa:3c:1e:93:11:ae + Signature Algorithm: sha1WithRSAEncryption + Issuer: C=SL, ST=WP, O=WS, OU=C, CN=Kaushalye/[EMAIL PROTECTED] + Validity + Not Before: Dec 6 10:27:18 2006 GMT + Not After : Dec 6 10:27:18 2007 GMT + Subject: C=SL, ST=WP, L=Katubedda, O=WS, OU=C, CN=Aaa/[EMAIL PROTECTED] + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (1024 bit) + Modulus (1024 bit): + 00:c7:e1:d8:5c:ef:16:dd:5d:05:95:c8:16:7c:2f: + f5:13:15:b4:7a:0c:c8:fb:95:c8:03:db:3d:a8:41: + 5d:70:75:ce:27:15:e2:a3:ef:87:24:38:5a:ee:72: + ea:70:c2:45:44:b5:dd:46:ca:51:60:15:ac:51:c3: + 59:af:a8:17:85:af:cd:77:74:87:b2:4b:ab:13:e0: + 00:82:2f:2a:d0:6b:12:7d:09:dc:52:dc:16:10:58: + 46:38:74:c7:cf:98:96:e3:58:ce:8a:c8:31:fa:77: + 6c:69:65:dc:a1:4c:38:e7:b0:9e:dc:64:06:ae:aa: + 13:90:23:62:84:14:c0:9e:31 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + 67:B7:BC:8C:22:29:1E:17:58:C6:43:91:A6:FB:82:E7:11:77:62:D6 + X509v3 Authority Key Identifier: + keyid:D7:27:10:74:4B:F8:2F:44:0B:BC:C7:9E:04:EF:22:5B:15:18:21:CC + + Signature Algorithm: sha1WithRSAEncryption + 4d:36:00:f0:51:10:44:72:73:5f:09:e4:fe:ad:f4:5b:a0:48: + 5f:50:50:d7:bb:bb:2a:98:b3:b7:d7:54:9e:57:6d:d2:cd:de: + d5:d5:30:4d:c7:03:09:b4:7d:d8:72:17:f7:c6:e8:72:69:89: + b9:bc:91:5a:a8:c8:9e:ee:76:0b:c2:ae:c2:65:59:94:5b:fe: + a2:30:bf:aa:49:25:b1:42:bc:6d:c4:0a:99:aa:2d:17:14:d8: + 8d:19:cd:75:22:84:51:22:55:4e:e1:9e:50:1f:c6:c2:57:e1: + 4b:58:87:d5:73:c1:69:fd:25:dd:3d:50:ee:0e:9f:6a:9a:13: + 52:45 +-----BEGIN CERTIFICATE----- +MIICzjCCAjegAwIBAgIJANyD+jwekxGuMA0GCSqGSIb3DQEBBQUAMGUxCzAJBgNV +BAYTAlNMMQswCQYDVQQIEwJXUDELMAkGA1UEChMCV1MxCjAIBgNVBAsTAUMxEjAQ +BgNVBAMTCUthdXNoYWx5ZTEcMBoGCSqGSIb3DQEJARYNa2F1c0B3c28yLmNvbTAe +Fw0wNjEyMDYxMDI3MThaFw0wNzEyMDYxMDI3MThaMHAxCzAJBgNVBAYTAlNMMQsw +CQYDVQQIEwJXUDESMBAGA1UEBxMJS2F0dWJlZGRhMQswCQYDVQQKEwJXUzEKMAgG +A1UECxMBQzEMMAoGA1UEAxMDQWFhMRkwFwYJKoZIhvcNAQkBFgphYWFAd3MuY29t +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDH4dhc7xbdXQWVyBZ8L/UTFbR6 +DMj7lcgD2z2oQV1wdc4nFeKj74ckOFrucupwwkVEtd1GylFgFaxRw1mvqBeFr813 +dIeyS6sT4ACCLyrQaxJ9CdxS3BYQWEY4dMfPmJbjWM6KyDH6d2xpZdyhTDjnsJ7c +ZAauqhOQI2KEFMCeMQIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQf +Fh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUZ7e8jCIp +HhdYxkORpvuC5xF3YtYwHwYDVR0jBBgwFoAU1ycQdEv4L0QLvMeeBO8iWxUYIcww +DQYJKoZIhvcNAQEFBQADgYEATTYA8FEQRHJzXwnk/q30W6BIX1BQ17u7Kpizt9dU +nldt0s3e1dUwTccDCbR92HIX98bocmmJubyRWqjInu52C8KuwmVZlFv+ojC/qkkl +sUK8bcQKmaotFxTYjRnNdSKEUSJVTuGeUB/GwlfhS1iH1XPBaf0l3T1Q7g6fapoT +UkU= +-----END CERTIFICATE----- Added: webservices/rampart/tags/c/0.90/test/openssl/sign/key.pem URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/sign/key.pem?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/sign/key.pem (added) +++ webservices/rampart/tags/c/0.90/test/openssl/sign/key.pem Thu Sep 6 03:48:44 2007 @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICWwIBAAKBgQDH4dhc7xbdXQWVyBZ8L/UTFbR6DMj7lcgD2z2oQV1wdc4nFeKj +74ckOFrucupwwkVEtd1GylFgFaxRw1mvqBeFr813dIeyS6sT4ACCLyrQaxJ9CdxS +3BYQWEY4dMfPmJbjWM6KyDH6d2xpZdyhTDjnsJ7cZAauqhOQI2KEFMCeMQIDAQAB +AoGAQIrSvJ+PeIdTCFyFtjAeKL13e3mpZGOnJGek7zG8JFZF7SUJ+/maX726zwhY +X3S7vUYkX3lw8V/ONtCnoyrZ/QQBqvUPUGg2XJI+NDYDrc3RR9YHTBFiYt791iXX +2/hpQJV7Fj2K40AxAgcDmOmsjhMROhc52cERXNUTvqo+sIECQQD+WbS0NQL4kcRZ +kELonmCHNAFA+vYvfB82RCspctNbfoZUAUPn/BMWTf9jZms89mDGfzaWKP5xd9aB +Hi7sTp4JAkEAyS204Q36vnbDh5Dzz5YkJNFTdgyrLTBIQ5r4ax+K1i6V/Mwq07Zw +SCvdDaTiBHOSaVJSHE38iwZZxUsWAs6I6QJADGFlcFgcOukte4aQGy6KWEppvTX6 +Abmy8ztCNpRGQW/ZLgGZwpL8gtttEPONSLxdXYwXpht8tx00LbjAY/Q3sQJAHqEg +2ur/9COs3WUKWd6oHhrotB51qWmidviPPfANeVKab2S+WIF8UuCqxTsHVloqPnLU +IY8WFiyfWlR2Q3MikQJASXg8KPM8C8Jp17iBbF5f09V18iA1fAbQSaLk3Lcbp1/h +0VsiOHjW05LvI8zIHMX2Ops7qAjxixK1T/2ec9qhuQ== +-----END RSA PRIVATE KEY----- Added: webservices/rampart/tags/c/0.90/test/openssl/sign/test.c URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/openssl/sign/test.c?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/openssl/sign/test.c (added) +++ webservices/rampart/tags/c/0.90/test/openssl/sign/test.c Thu Sep 6 03:48:44 2007 @@ -0,0 +1,177 @@ +/* + * 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 <axutil_env.h> +#include <oxs_buffer.h> +#include <oxs_error.h> +#include <oxs_key_mgr.h> +#include <openssl_sign.h> +#include <openssl_digest.h> +#include <openssl_constants.h> +#include <openssl_pkey.h> +#include <oxs_axis2_utils.h> +#include <oxs_x509_cert.h> + +#include <oxs_utility.h> +#include <oxs_axiom.h> +#include <axiom.h> +#include <axiom_xml_reader.h> +#include <axutil_env.h> +#include <oxs_ctx.h> +#include <oxs_key.h> +#include <oxs_key_mgr.h> +#include <openssl_pkey.h> +#include <oxs_error.h> +#include <oxs_transform.h> +#include <oxs_transforms_factory.h> +#include <oxs_xml_signature.h> +#include <oxs_sign_ctx.h> +#include <oxs_sign_part.h> +#include <oxs_xml_key_processor.h> +#include <oxs_xml_key_info_builder.h> + +axiom_node_t* +load_sample_xml(const axutil_env_t *env, + 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;*/ + axiom_node_t *tmpl = 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; +} + +axis2_char_t * +c14n(axutil_env_t *env, axis2_char_t* filename) +{ + axiom_document_t *doc = NULL; + axis2_char_t *algo = NULL; + axis2_char_t *c14nized = NULL; + axiom_node_t *input = NULL; + FILE *outf = NULL; + + input = load_sample_xml(env, filename); + doc = axiom_node_get_document(input, env); + algo = OXS_HREF_TRANSFORM_XML_EXC_C14N; + oxs_c14n_apply_algo(env, doc, &c14nized, NULL, (axiom_node_t*)input, algo); + outf = fopen("c14n.txt", "w"); + fwrite(c14nized, 1, strlen(c14nized), outf); + return c14nized; +} + +axis2_char_t* digest(axutil_env_t *env, axis2_char_t *in){ + axis2_char_t *dg = NULL; + FILE *outf = NULL; + + dg = openssl_sha1(env, in, strlen(in)); + outf = fopen("digest.txt", "w"); + fwrite(dg, 1, strlen(dg), outf); + printf("DIGEST = %s", dg); + return dg; +} + +int main() +{ + axutil_env_t *env = NULL; + axis2_status_t status = AXIS2_FAILURE; + oxs_buffer_t *inbuf = NULL; + oxs_buffer_t *outbuf = NULL; + openssl_pkey_t *prvkey = NULL; + openssl_pkey_t *pubkey = NULL; + oxs_x509_cert_t *cert = NULL; + char *data = "Winners in good times and survivors in hard times"; + int len = -1; + + env = axutil_env_create_all("./openssl.log", AXIS2_LOG_LEVEL_TRACE); +#if 0 + /*new code*/ + { + axis2_char_t *c14op = NULL; + axis2_char_t *digestop = NULL; + /*FILE *inf = NULL;*/ + /*c14op = c14n(env, "input.xml");*/ + /*inf = fopen("c14n.txt", "r"); + c14op = malloc(2000); + fread(c14op, 1, 1999, inf);*/ + c14op = "<soapenv:Body xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"Id-26953436\"><example1:echo xmlns:example1=\"http://example1.org/example1\"><example1:Text>Testing Rampart with WS-SecPolicy</example1:Text></example1:echo></soapenv:Body>"; + digestop = digest(env, c14op); + return 0; + } + /*eof new code*/ +#endif + /*Load private key*/ + prvkey = oxs_key_mgr_load_private_key_from_pem_file(env, "key.pem", ""); + if(!prvkey){ + printf("Cannot load private key"); + return 0; + } + + /*Load certificate*/ + cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, "cert.pem"); + if(!cert){ + printf("Cannot load certificate"); + return 0; + } + + inbuf = oxs_buffer_create(env); + oxs_buffer_populate(inbuf, env, (unsigned char *)data, strlen(data)); + + outbuf = oxs_buffer_create(env); + + /*Sign*/ + printf("Signing\n"); + len = openssl_sig_sign(env, prvkey, inbuf, outbuf); + if(len < 0 ){ + printf("Signing failed\n"); + return 0; + }else{ + printf("Signing OK. Sig len = %d\n", len); + } + + + /*Verify*/ + printf("Verifying\n"); + pubkey = oxs_x509_cert_get_public_key(cert, env); + + status = openssl_sig_verify(env, pubkey, inbuf, outbuf); + if(AXIS2_SUCCESS != status){ + printf("Sign verification failed\n"); + }else{ + printf("Sign verification success\n"); + + } + + + return 0; +} Added: webservices/rampart/tags/c/0.90/test/util/Makefile.am URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/util/Makefile.am?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/util/Makefile.am (added) +++ webservices/rampart/tags/c/0.90/test/util/Makefile.am Thu Sep 6 03:48:44 2007 @@ -0,0 +1,18 @@ +TESTS = test_sha test_util +bin_PROGRAMS = test_sha test_util +SUBDIRS = +AM_CFLAGS = -g -O2 -pthread +test_sha_SOURCES = test_sha.c +test_util_SOURCES = test_util.c + + +test_sha_LDADD = $(top_builddir)/src/util/librampart_util.la\ + -laxis2_util + +test_util_LDADD = $(top_builddir)/src/util/librampart_util.la\ + -laxis2_util + + +INCLUDES = -I$(top_builddir)/include \ + @UTILINC@ + Added: webservices/rampart/tags/c/0.90/test/util/test_sha.c URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/util/test_sha.c?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/util/test_sha.c (added) +++ webservices/rampart/tags/c/0.90/test/util/test_sha.c Thu Sep 6 03:48:44 2007 @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <rampart_util.h> +#include <rampart_crypto_util.h> +#include <axis2_util.h> +#include <axutil_base64.h> + +axutil_env_t *test_init() +{ + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + axutil_error_t *error = (axutil_error_t*)axis2_error_create(allocator); + axutil_env_t *env = axutil_env_create_with_error(allocator, error); + return env; +} + +int main() +{ + axis2_char_t* hash = NULL; + axutil_env_t *env = NULL; + axis2_char_t* nonce = NULL; + axis2_char_t* created = NULL; + + env = test_init(); + + printf("--Testing started--------------------------------------------\n"); + printf("\n--Testing hash-----------------------------------------------\n"); + + hash = rampart_crypto_sha1(env, "WScqanjCEAC4mQoBE07sAQ==", "2003-07-16T01:24:32Z", "IloveDogs"); + if (!hash) + { + printf("No hash generated :( ...\n"); + } + printf("Hash = %s", hash); +#if 0 + /*encode Base64*/ + axis2_char_t* encodedStr = NULL; + + + encodedStr = AXIS2_MALLOC(env->allocator, 20); + axutil_base64_encode_binary(encodedStr, hash, 20); + + printf("Hash = %s \n", encodedStr); +#endif + printf("\n----Testing nonce------------------------------------------\n"); + nonce = rampart_generate_nonce(env); + printf("NONCE: %s", nonce); + + printf("\n----Testing created----------------------------------------\n"); + created = rampart_generate_time(env, 300); + printf("CREATED: %s", created); + printf("\n----End of testings----------------------------------------\n"); + return 0; +} + + Added: webservices/rampart/tags/c/0.90/test/util/test_util.c URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/test/util/test_util.c?rev=573215&view=auto ============================================================================== --- webservices/rampart/tags/c/0.90/test/util/test_util.c (added) +++ webservices/rampart/tags/c/0.90/test/util/test_util.c Thu Sep 6 03:48:44 2007 @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <rampart_util.h> +#include <rampart_crypto_util.h> +#include <axis2_util.h> +#include <axutil_base64.h> +#include <axutil_date_time.h> + +axutil_env_t *test_init() +{ + axutil_allocator_t *allocator = axutil_allocator_init(NULL); + axutil_error_t *error = (axutil_error_t*)axis2_error_create(allocator); + axutil_env_t *env = axutil_env_create_with_error(allocator, error); + return env; +} + +int main() +{ + axis2_char_t* date_str1 = "2007-08-21T12:14:42Z"; + axis2_char_t* date_str2 = "2006-08-21T12:15:42Z"; + axutil_env_t *env = NULL; + axis2_status_t status = AXIS2_FAILURE; + + env = test_init(); + + printf("--Testing started--------------------------------------------\n"); + + + status = rampart_compare_date_time(env, date_str1, date_str2); + printf("Status = %d", status); + + printf("\n----End of testings----------------------------------------\n"); + return 0; +} + +
