You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rampart-dev@ws.apache.org by pi...@apache.org on 2007/09/06 12:49:17 UTC
svn commit: r573215 [12/22] - in /webservices/rampart/tags/c/0.90: ./ build/
build/linux/ build/win32/ include/ samples/ samples/authn_provider/
samples/callback/ samples/callback/htpasswd_callback/ samples/client/
samples/client/sec_echo/ samples/clie...
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/rsa.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/rsa.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/rsa.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/rsa.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,199 @@
+/*
+ * 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 <openssl_rsa.h>
+#include <openssl/rand.h>
+#include <openssl/evp.h>
+#include <openssl/pem.h>
+#include <openssl/bio.h>
+#include <openssl/rand.h>
+#include <oxs_buffer.h>
+#include <oxs_error.h>
+
+/**
+struct _evp_pkey{
+ EVP_PKEY *key;
+ unsigned char *name;
+ int size;
+ int type;
+}
+*/
+
+int AXIS2_CALL
+openssl_rsa_pub_encrypt(
+ const axutil_env_t *env,
+ const openssl_pkey_t *pkey,
+ const axis2_char_t *padding,
+ oxs_buffer_t *in,
+ oxs_buffer_t *out)
+{
+ unsigned char *encrypted = NULL;
+ int ret;
+ EVP_PKEY *key = NULL;
+ int pad = RSA_PKCS1_PADDING;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ key = (EVP_PKEY *)openssl_pkey_get_key(pkey, env);
+ if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_OAEP_PADDING ) ){
+ pad = RSA_PKCS1_OAEP_PADDING;
+ }else if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_PADDING ) ){
+ pad = RSA_PKCS1_PADDING;
+ }
+
+ encrypted = AXIS2_MALLOC(env->allocator, RSA_size(key->pkey.rsa));
+ ret = RSA_public_encrypt(oxs_buffer_get_size(in, env),
+ oxs_buffer_get_data(in, env),
+ encrypted,
+ key->pkey.rsa ,
+ pad);
+
+ if (ret < 0)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_OPENSSL_FUNC_FAILED,
+ "RSA encryption failed");
+ return (-1);
+ }
+ oxs_buffer_populate(out, env, encrypted, ret);
+ return ret;
+}
+
+int AXIS2_CALL
+openssl_rsa_pub_decrypt(
+ const axutil_env_t *env,
+ const openssl_pkey_t *pkey,
+ const axis2_char_t *padding,
+ oxs_buffer_t *in,
+ oxs_buffer_t *out)
+{
+ unsigned char *decrypted = NULL;
+ int ret;
+ EVP_PKEY *key = NULL;
+ int pad = RSA_PKCS1_PADDING;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ key = (EVP_PKEY *)openssl_pkey_get_key(pkey, env);
+ if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_OAEP_PADDING ) ){
+ pad = RSA_PKCS1_OAEP_PADDING;
+ }else if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_PADDING ) ){
+ pad = RSA_PKCS1_PADDING;
+ }
+
+ decrypted = AXIS2_MALLOC(env->allocator, RSA_size(key->pkey.rsa));
+ ret = RSA_public_decrypt(oxs_buffer_get_size(in, env),
+ oxs_buffer_get_data(in, env),
+ decrypted,
+ key->pkey.rsa ,
+ pad);
+
+ if (ret < 0)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_OPENSSL_FUNC_FAILED,
+ "PUBKEY decrypt (signature verification) failed");
+ return (-1);
+ }
+ oxs_buffer_populate(out, env, decrypted, ret);
+ return ret;
+}
+
+
+int AXIS2_CALL
+openssl_rsa_prv_decrypt(
+ const axutil_env_t *env,
+ const openssl_pkey_t *pkey,
+ const axis2_char_t *padding,
+ oxs_buffer_t *in,
+ oxs_buffer_t *out)
+{
+ unsigned char *decrypted = NULL;
+ int ret;
+ EVP_PKEY *key = NULL;
+ int pad = RSA_PKCS1_PADDING;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ key = (EVP_PKEY *)openssl_pkey_get_key(pkey, env);
+
+ /*Set padding. This is the only diff btwn RSA-v1.5 and RSA-OAEP*/
+ if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_OAEP_PADDING ) ){
+ pad = RSA_PKCS1_OAEP_PADDING;
+ }else if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_PADDING ) ){
+ pad = RSA_PKCS1_PADDING;
+ }
+
+ decrypted = AXIS2_MALLOC(env->allocator, RSA_size(key->pkey.rsa));
+ ret = RSA_private_decrypt(RSA_size(key->pkey.rsa),
+ oxs_buffer_get_data(in, env),
+ decrypted,
+ key->pkey.rsa,
+ pad);
+
+ if (ret < 0)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_OPENSSL_FUNC_FAILED,
+ "RSA decryption failed");
+ return (-1);
+ }
+ oxs_buffer_populate(out, env, decrypted, ret);
+ return ret;
+}
+
+int AXIS2_CALL
+openssl_rsa_prv_encrypt(
+ const axutil_env_t *env,
+ const openssl_pkey_t *pkey,
+ const axis2_char_t *padding,
+ oxs_buffer_t *in,
+ oxs_buffer_t *out)
+{
+ unsigned char *encrypted = NULL;
+ int ret;
+ EVP_PKEY *key = NULL;
+ int pad = RSA_PKCS1_PADDING;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ /*Get the private key*/
+ key = (EVP_PKEY *)openssl_pkey_get_key(pkey, env);
+
+ /*Set padding. This is the only diff btwn RSA-v1.5 and RSA-OAEP*/
+ if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_OAEP_PADDING ) ){
+ pad = RSA_PKCS1_OAEP_PADDING;
+ }else if(0 == axutil_strcmp(padding, OPENSSL_RSA_PKCS1_PADDING ) ){
+ pad = RSA_PKCS1_PADDING;
+ }
+
+ encrypted = AXIS2_MALLOC(env->allocator, RSA_size(key->pkey.rsa));
+ ret = RSA_private_encrypt(RSA_size(key->pkey.rsa),
+ oxs_buffer_get_data(in, env),
+ encrypted,
+ key->pkey.rsa,
+ pad);
+
+ if (ret < 0)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_OPENSSL_FUNC_FAILED,
+ "RSA private encryption(Signing) failed. Error code %d: %s",ERR_get_error(), ERR_reason_error_string(ERR_get_error()));
+ return (-1);
+ }
+ oxs_buffer_populate(out, env, encrypted, ret);
+ return ret;
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/sign.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/sign.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/sign.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/sign.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,137 @@
+/*
+ * 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_buffer.h>
+#include <oxs_key.h>
+#include <oxs_error.h>
+#include <openssl_cipher_ctx.h>
+#include <openssl_sign.h>
+#include <openssl_pkey.h>
+#include <openssl/evp.h>
+#include <openssl/x509.h>
+#include <openssl/err.h>
+#include <openssl/pem.h>
+#include <openssl/ssl.h>
+#include <openssl/bio.h>
+
+#define BUFSIZE 64
+
+AXIS2_EXTERN int AXIS2_CALL
+openssl_sig_sign(const axutil_env_t *env,
+ openssl_pkey_t *prvkey,
+ oxs_buffer_t *input_buf,
+ oxs_buffer_t *output_buf)
+{
+ unsigned char sig_buf[4096]; /*Enough for the signature*/
+ unsigned int sig_len;
+ const EVP_MD* digest;
+ EVP_MD_CTX md_ctx;
+ EVP_PKEY* pkey = NULL;
+ int err, ret;
+ /*Get the key*/
+ /*open_pkey = oxs_sign_ctx_get_private_key(sign_ctx, env);*/
+ pkey = openssl_pkey_get_key(prvkey, env);
+ if(!pkey){
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIGN_FAILED,"Cannot load the private key" );
+ }
+
+ /*TODO: Set the digest according to the signature method*/
+ digest = EVP_sha1();
+
+ /*MD Ctx init*/
+ EVP_MD_CTX_init(&md_ctx);
+
+ /*Sign init*/
+ ret = EVP_SignInit(&md_ctx, digest);
+ AXIS2_LOG_INFO(env->log, "[openssl][sig] Signing content %s", oxs_buffer_get_data(input_buf, env) );
+ EVP_SignUpdate (&md_ctx, oxs_buffer_get_data(input_buf, env), oxs_buffer_get_size(input_buf, env));
+ sig_len = sizeof(sig_buf);
+ err = EVP_SignFinal (&md_ctx,
+ sig_buf,
+ &sig_len,
+ pkey);
+ if (err != 1) {
+ ERR_print_errors_fp (stderr);
+ }
+ /*Fill the output buffer*/
+ oxs_buffer_populate(output_buf, env, sig_buf, sig_len);
+
+ return sig_len;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_sig_verify(const axutil_env_t *env,
+ openssl_pkey_t *pubkey,
+ oxs_buffer_t *input_buf,
+ oxs_buffer_t *sig_buf)
+{
+ axis2_status_t status = AXIS2_FAILURE;
+ const EVP_MD* digest;
+ EVP_MD_CTX md_ctx;
+ EVP_PKEY* pkey = NULL;
+ int ret;
+
+ /*Get the publickey*/
+ /*cert = oxs_sign_ctx_get_certificate(sign_ctx, env);
+ open_pubkey = oxs_x509_cert_get_public_key(cert, env);*/
+ pkey = openssl_pkey_get_key(pubkey, env);
+ if(!pkey){
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Cannot load the public key" );
+ }
+ /*TODO Set the digest according to the signature method*/
+ digest = EVP_sha1();
+
+ /*Init MD Ctx*/
+ EVP_MD_CTX_init(&md_ctx);
+
+ /*Intialize verification*/
+ ret = EVP_VerifyInit(&md_ctx, digest);
+ if(ret != 1) {
+ /*Error*/
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"EVP_VerifyInit failed" );
+ return AXIS2_FAILURE;
+ }
+ ret = EVP_VerifyUpdate(&md_ctx, oxs_buffer_get_data(input_buf, env), oxs_buffer_get_size(input_buf, env));
+ if(ret != 1) {
+ /*Error*/
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"EVP_VerifyUpdate failed" );
+ return AXIS2_FAILURE;
+ }
+
+ ret = EVP_VerifyFinal(&md_ctx, oxs_buffer_get_data(sig_buf, env),
+ oxs_buffer_get_size(sig_buf, env),
+ pkey);
+ if(ret == 0){
+ /*Error. Signature verification FAILED */
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Signature verification FAILED." );
+ status = AXIS2_FAILURE;
+ }else if(ret < 0){
+ /*Erorr. Some other error*/
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Error occured while verifying the signature." );
+ status = AXIS2_FAILURE;
+ }else{
+ /*SUCCESS. Det ar bra :-)*/
+ AXIS2_LOG_INFO(env->log, "[openssl][sig] Signature verification SUCCESS " );
+ status = AXIS2_SUCCESS;
+ }
+
+ return status;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/util.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/util.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/util.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/util.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,145 @@
+/*
+ * 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 <openssl_util.h>
+#include <openssl_constants.h>
+#include <openssl_cipher_property.h>
+#include <openssl_util.h>
+#include <oxs_error.h>
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+generate_random_data(const axutil_env_t *env, oxs_buffer_t *buffer, int size)
+{
+ axis2_status_t status = AXIS2_FAILURE;
+ int ret;
+ unsigned char temp_buffer[1024];
+
+ ret = RAND_bytes(temp_buffer, size);
+ if (ret < 0)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_DEFAULT, "RAND_bytes failed %d", size);
+ return AXIS2_FAILURE;
+ }
+ /*Encoding make it easier to handle random data*/
+#if 0
+ int encodedlen;
+ axis2_char_t *encoded_str = NULL;
+
+ encodedlen = axutil_base64_encode_len(size);
+ encoded_str = AXIS2_MALLOC(env->allocator, encodedlen);
+ ret = axutil_base64_encode(encoded_str, (const char *)temp_buffer, size);
+ status = oxs_buffer_populate(buffer, env, (unsigned char*)encoded_str, size);
+ AXIS2_FREE(env->allocator, encoded_str);
+ encoded_str = NULL;
+#else
+ status = oxs_buffer_populate(buffer, env, (unsigned char*)temp_buffer, size);
+
+#endif
+ return AXIS2_SUCCESS;
+}
+
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_populate_cipher_property(const axutil_env_t *env, openssl_cipher_property_t *cprop)
+{
+ EVP_CIPHER* cipher;
+ EVP_CIPHER_CTX ctx;
+ axis2_char_t* cipher_name = NULL;
+
+ if (!cprop)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+ "openssl_cipher_property is NULL");
+
+ return AXIS2_FAILURE;
+
+ }
+
+ cipher_name = openssl_cipher_property_get_name(cprop, env);
+ if (!cipher_name)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+ "openssl_cipher_property name is NULL");
+
+ return AXIS2_FAILURE;
+
+ }
+
+ cipher = (EVP_CIPHER*)openssl_get_evp_cipher_by_name(env, cipher_name);
+ if (!cipher)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+ "openssl_get_evp_cipher_by_name failed");
+
+ return AXIS2_FAILURE;
+ }
+ /*Initialize a cipher ctx*/
+ EVP_CIPHER_CTX_init(&ctx);
+ EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, NULL, -1);
+
+ openssl_cipher_property_set_cipher(cprop, env, cipher);
+ openssl_cipher_property_set_key_size(cprop, env, EVP_CIPHER_CTX_key_length(&ctx));
+ openssl_cipher_property_set_block_size(cprop, env, EVP_CIPHER_CTX_block_size(&ctx));
+ openssl_cipher_property_set_iv_size(cprop, env, EVP_CIPHER_CTX_iv_length(&ctx));
+
+ /*free ctx*/
+ EVP_CIPHER_CTX_cleanup(&ctx);
+
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN EVP_CIPHER* AXIS2_CALL
+openssl_get_evp_cipher_by_name(const axutil_env_t *env, axis2_char_t *cipher_name)
+{
+ EVP_CIPHER* cipher = NULL;
+
+ if (0 == axutil_strcmp((char*)cipher_name, (char*)OPENSSL_EVP_des_ede3_cbc))
+ {
+ cipher = (EVP_CIPHER*) EVP_des_ede3_cbc();
+
+ }
+ else if (0 == axutil_strcmp((char*)cipher_name, (char*)OPENSSL_EVP_aes_128_cbc))
+ {
+ cipher = (EVP_CIPHER*)EVP_aes_128_cbc();
+
+ }
+ else if (0 == axutil_strcmp((char*)cipher_name, (char*)OPENSSL_EVP_aes_192_cbc))
+ {
+ cipher = (EVP_CIPHER*)EVP_aes_192_cbc();
+
+ }
+ else if (0 == axutil_strcmp((char*)cipher_name, (char*)OPENSSL_EVP_aes_256_cbc))
+ {
+ cipher = (EVP_CIPHER*)EVP_aes_256_cbc();
+
+ }
+ else
+ {
+ return NULL;
+ }
+
+ return cipher;
+}
+
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/x509.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/x509.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/x509.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/x509.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,417 @@
+/*
+ * 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 <openssl_rsa.h>
+#include <openssl/rand.h>
+#include <openssl/evp.h>
+#include <openssl/pem.h>
+#include <openssl/bio.h>
+#include <openssl/rand.h>
+#include <oxs_buffer.h>
+#include <oxs_error.h>
+#include <openssl_pkcs12.h>
+#include <openssl_x509.h>
+#include <oxs_utility.h>
+
+/*Usefull when we have BinarySecurityTokn*/
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_x509_load_from_buffer(const axutil_env_t *env,
+ axis2_char_t *b64_encoded_buf,
+ X509 **cert)
+{
+ unsigned char *buff = NULL;
+ BIO *mem = NULL;
+ int ilen = 0;
+ axis2_char_t *formatted_buf = NULL;
+ axis2_char_t *buf_to_format = NULL;
+ int decode_len = 0;
+ int decoded_len = -1;
+
+ /*We should remove new lines here.*/
+ buf_to_format = (axis2_char_t*)axutil_strdup(env, b64_encoded_buf);
+ if(buf_to_format)
+ {
+ formatted_buf = oxs_util_get_newline_removed_string(env,buf_to_format);
+ AXIS2_FREE(env->allocator,buf_to_format);
+ buf_to_format = NULL;
+ }
+ else
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_DECRYPT_FAILED,
+ "New line removed buffer creation failed.");
+ return AXIS2_FAILURE;
+ }
+ /*First we need to base64 decode*/
+ /* EVP_ENCODE_CTX ctx;*/
+ /* int len = 0;*/
+ /* int ret = 0;*/
+
+ decode_len = axutil_base64_decode_len(formatted_buf );
+ buff = AXIS2_MALLOC(env->allocator, decode_len);
+
+ ilen = axutil_strlen(formatted_buf);
+
+ decoded_len = axutil_base64_decode_binary(buff,formatted_buf);
+ if (decoded_len < 0)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_DECRYPT_FAILED,
+ "axutil_base64_decode_binary failed");
+ return AXIS2_FAILURE;
+ }
+
+ /* EVP_DecodeInit(&ctx);
+ EVP_DecodeUpdate(&ctx, (unsigned char*)buff, &len,
+ (unsigned char*)b64_encoded_buf, ilen);
+ EVP_DecodeFinal(&ctx, (unsigned char*)buff, &ret);
+ ret += len;
+ */
+ if ((mem = BIO_new_mem_buf(buff, ilen)) == NULL)
+ {
+ /*oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+ "BIO memeory allocation failure");*/
+ return AXIS2_FAILURE;
+ }
+
+ *cert = d2i_X509_bio(mem, NULL);
+ /*Free*/
+ BIO_free(mem);
+ mem = NULL;
+ AXIS2_FREE(env->allocator, buff);
+ buff = NULL;
+
+ if (*cert == NULL){
+ /*oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+ "Certificate is NULL");*/
+ return AXIS2_FAILURE;
+ }
+
+ return AXIS2_SUCCESS;
+
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_x509_load_from_pem(const axutil_env_t *env,
+ axis2_char_t *filename,
+ X509 **cert)
+{
+ BIO *in;
+
+ if ((in=BIO_new_file(filename,"r")) == NULL)
+ {
+ /*oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+ "Error reading the file %s", filename);*/
+ return AXIS2_FAILURE;
+ }
+ /*Read certificate*/
+ PEM_read_bio_X509(in, cert,NULL,NULL);
+ if(!*cert)
+ {
+ return AXIS2_FAILURE;
+ }
+
+ if (-1 == BIO_reset(in) ){
+ return AXIS2_FAILURE;
+ }
+
+ if (-1 == BIO_free(in) ){
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_x509_load_from_pkcs12(const axutil_env_t *env,
+ axis2_char_t *filename,
+ axis2_char_t *password,
+ X509 **cert,
+ EVP_PKEY **pkey,
+ STACK_OF(X509) **ca)
+{
+ PKCS12 *p12 = NULL;
+ axis2_status_t status = AXIS2_FAILURE;
+
+ /*Load*/
+ status = openssl_pkcs12_load(env, filename, &p12);
+ if(AXIS2_FAILURE == status){
+ return AXIS2_FAILURE;
+ }
+ /*Parse*/
+ status = openssl_pkcs12_parse(env, password, p12, pkey,
+ cert,
+ ca);
+ if(AXIS2_FAILURE == status){
+ return AXIS2_FAILURE;
+ }
+ /*Free*/
+ status = openssl_pkcs12_free(env, p12);
+ if(AXIS2_FAILURE == status){
+ return AXIS2_FAILURE;
+ }
+
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_x509_load_certificate(const axutil_env_t *env,
+ openssl_x509_format_t format,
+ axis2_char_t *filename,
+ axis2_char_t *password,
+ X509 **cert)
+{
+ axis2_status_t status = AXIS2_FAILURE;
+
+ if(OPENSSL_X509_FORMAT_PEM == format){
+ /*Load from PEM*/
+ status = openssl_x509_load_from_pem(env, filename, cert);
+ if(AXIS2_FAILURE == status){
+ return AXIS2_FAILURE;
+ }
+ }else if(OPENSSL_X509_FORMAT_PKCS12 == format){
+ /*Load from PKCS12*/
+ EVP_PKEY *pkey = NULL;
+ STACK_OF(X509) *ca = NULL;
+ status = openssl_x509_load_from_pkcs12(env, filename, password, cert, &pkey, &ca);
+ if(AXIS2_FAILURE == status){
+ return AXIS2_FAILURE;
+ }
+ }else if(OPENSSL_X509_FORMAT_DER == format){
+ /*Load from DER*/
+
+ }else{
+ /*Unspported*/
+ }
+ return AXIS2_SUCCESS;
+}
+
+
+/*
+ * Here we take data in btwn
+ -----BEGIN CERTIFICATE-----
+ -----END CERTIFICATE-----
+ */
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+openssl_x509_get_cert_data(const axutil_env_t *env,
+ X509 *cert)
+{
+ axis2_char_t *unformatted = NULL;
+ axis2_char_t *core_tail = NULL;
+ axis2_char_t *core = NULL;
+ axis2_char_t *res = NULL;
+ axis2_char_t *buffer = NULL;
+
+ unformatted = openssl_x509_get_info(env, OPENSSL_X509_INFO_DATA_CERT, cert);
+ core_tail = axutil_strstr(unformatted, "\n");
+ res = axutil_strstr(core_tail,"-----END");
+ res[0] = '\0';
+ core = (axis2_char_t*)axutil_strdup(env, core_tail);
+ if(core)
+ {
+ buffer = oxs_util_get_newline_removed_string(env,core);
+ AXIS2_FREE(env->allocator,core);
+ core = NULL;
+ return buffer;
+ }
+ else
+ return NULL;
+}
+
+
+AXIS2_EXTERN int AXIS2_CALL
+openssl_x509_get_serial(const axutil_env_t *env,
+ X509 *cert)
+{
+ axis2_char_t *serial = NULL;
+ int no = 0;
+ /*WARN: Do not use the serial number without converting it to the integer.*/
+ serial = (axis2_char_t*)i2s_ASN1_INTEGER(NULL, X509_get_serialNumber(cert));
+ no = atoi(serial);
+
+ return no;
+}
+
+AXIS2_EXTERN unsigned long AXIS2_CALL
+openssl_x509_get_subject_name_hash(const axutil_env_t *env,
+ X509 *cert)
+{
+ unsigned long l = 0;
+ l=X509_subject_name_hash(cert);
+ return l;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_x509_get_pubkey(const axutil_env_t *env,
+ X509 *cert,
+ EVP_PKEY **pubkey)
+{
+ *pubkey = X509_get_pubkey(cert);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+openssl_x509_get_subject_key_identifier(const axutil_env_t *env,
+ X509 *cert)
+{
+ X509_EXTENSION *ext;
+ ASN1_OCTET_STRING *keyId = NULL;
+ int index = 0;
+ EVP_ENCODE_CTX ctx;
+ int len, ret;
+ char buf[1000];
+ char output[100];
+ axis2_char_t *ski = NULL;
+
+ /*Get ext by ID*/
+ index = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
+ if (index < 0) {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+ "The extenension index of NID_subject_key_identifier is not valid");
+ return NULL;
+ }
+ /*Get the extension*/
+ ext = X509_get_ext(cert, index);
+ if (ext == NULL) {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+ "The extension for NID_subject_key_identifier is NULL");
+ return NULL;
+ }
+ /*Subject Key Identifier*/
+ keyId = (ASN1_OCTET_STRING *)X509V3_EXT_d2i(ext);
+ if (keyId == NULL) {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+ "The SubjectKeyIdentifier is NULL");
+ return NULL;
+ }
+ memcpy(buf, keyId->data, keyId->length);
+ buf[keyId->length] = 0;
+
+ EVP_EncodeInit(&ctx);
+ EVP_EncodeUpdate(&ctx, (unsigned char*)output, &len, (unsigned char*)buf, keyId->length);
+ EVP_EncodeFinal(&ctx, (unsigned char*)(output+len), &ret);
+
+ ret += len;
+ ski = axutil_strdup(env, output);
+ return ski;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+openssl_x509_get_info(const axutil_env_t *env,
+ openssl_x509_info_type_t type,
+ X509 *cert)
+{
+ BIO *out = NULL;
+ unsigned char *data= NULL;
+ axis2_char_t *result = NULL;
+ int n = 0;
+
+ out = BIO_new(BIO_s_mem());
+ if(OPENSSL_X509_INFO_SUBJECT==type){
+ X509_NAME_print_ex(out, X509_get_subject_name(cert), 0, 0);
+ }else if(OPENSSL_X509_INFO_ISSUER == type){
+ X509_NAME_print_ex(out, X509_get_issuer_name(cert), 0, 0);
+ }else if(OPENSSL_X509_INFO_VALID_FROM == type){
+ ASN1_TIME_print(out, X509_get_notBefore(cert));
+ }else if(OPENSSL_X509_INFO_VALID_TO == type){
+ ASN1_TIME_print(out, X509_get_notAfter(cert));
+ }else if(OPENSSL_X509_INFO_DATA_CERT == type){
+ if(!PEM_write_bio_X509_AUX(out, cert)){
+ return NULL;
+ }
+ }else if(OPENSSL_X509_INFO_FINGER == type){
+ int j = 0;
+ const EVP_MD *digest = NULL;
+ unsigned char md[EVP_MAX_MD_SIZE];
+ unsigned int _n = 0;
+
+ digest = EVP_sha1();/*If we use EVP_md5(); here we can get the digest from md5. */
+ if(X509_digest(cert,digest,md,&_n))
+ {
+ BIO_printf(out, "%s:", OBJ_nid2sn(EVP_MD_type(digest)));
+ for (j=0; j<(int)_n; j++)
+ {
+ BIO_printf (out, "%02X",md[j]);
+ if (j+1 != (int)_n) BIO_printf(out,":");
+ }
+ }
+ }else if(OPENSSL_X509_INFO_SIGNATURE == type){
+ int i = 0;
+ unsigned char *s = NULL;
+
+ n=cert->signature->length;
+ s=cert->signature->data;
+ for (i=0; i<n; i++)
+ {
+ if ( ((i%18) == 0) && (i!=0) ) BIO_printf(out,"\n");
+ BIO_printf(out,"%02x%s",s[i], (((i+1)%18) == 0)?"":":");
+ }
+
+ }else if(OPENSSL_X509_INFO_VERSION == type){
+ long l = 0.0;
+
+ l = X509_get_version(cert);
+ BIO_printf (out,"%lu (0x%lx)",l+1,l);
+ }else if(OPENSSL_X509_INFO_PUBKEY == type){
+ EVP_PKEY *pkey = NULL;
+
+ pkey=X509_get_pubkey(cert);
+ if (pkey != NULL)
+ {
+ if (pkey->type == EVP_PKEY_RSA){
+ RSA_print(out,pkey->pkey.rsa,0);
+ }else if (pkey->type == EVP_PKEY_DSA){
+ DSA_print(out,pkey->pkey.dsa,0);
+ }
+ EVP_PKEY_free(pkey);
+ }
+ }else if(OPENSSL_X509_INFO_PUBKEY_ALGO == type){
+ X509_CINF *ci = NULL;
+
+ ci = cert->cert_info;
+ i2a_ASN1_OBJECT(out, ci->key->algor->algorithm);
+ }
+ n = BIO_get_mem_data(out, &data);
+ result = axutil_strndup( env, data, n);
+ BIO_free(out);
+ out = NULL;
+
+ return result;
+}
+
+AXIS2_EXTERN void AXIS2_CALL
+openssl_x509_print(const axutil_env_t *env,
+ X509 *cert)
+{
+ printf("\n*************START PRINTING*****************\n");
+ printf("OPENSSL_X509_INFO_SUBJECT : %s\n", openssl_x509_get_info(env, OPENSSL_X509_INFO_SUBJECT,cert));
+ printf("OPENSSL_X509_INFO_ISSUER : %s\n", openssl_x509_get_info(env,OPENSSL_X509_INFO_ISSUER ,cert));
+ printf("OPENSSL_X509_INFO_VALID_FROM : %s\n", openssl_x509_get_info(env, OPENSSL_X509_INFO_VALID_FROM,cert));
+ printf("OPENSSL_X509_INFO_VALID_TO : %s\n", openssl_x509_get_info(env,OPENSSL_X509_INFO_VALID_TO ,cert));
+ printf("OPENSSL_X509_INFO_FINGER : %s\n", openssl_x509_get_info(env,OPENSSL_X509_INFO_FINGER ,cert));
+ printf("OPENSSL_X509_INFO_SIGNATURE : %s\n", openssl_x509_get_info(env, OPENSSL_X509_INFO_SIGNATURE,cert));
+ printf("OPENSSL_X509_INFO_VERSION : %s\n", openssl_x509_get_info(env,OPENSSL_X509_INFO_VERSION ,cert));
+ printf("OPENSSL_X509_INFO_PUBKEY : %s\n", openssl_x509_get_info(env,OPENSSL_X509_INFO_PUBKEY ,cert));
+ printf("OPENSSL_X509_INFO_PUBKEY_ALGO : %s\n", openssl_x509_get_info(env,OPENSSL_X509_INFO_PUBKEY_ALGO ,cert));
+ printf("SERIAL : %u\n", openssl_x509_get_serial(env,cert));
+ printf("PUBKEY : %s\n", openssl_x509_get_cert_data(env,cert));
+
+ printf("\n*************END PRINTING********************\n");
+
+
+}
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/sign_ctx.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/sign_ctx.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/sign_ctx.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/sign_ctx.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,291 @@
+/*
+ * 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_sign_ctx.h>
+#include <oxs_error.h>
+
+struct oxs_sign_ctx_t
+{
+ axis2_char_t *sign_mtd_algo;
+ axis2_char_t *c14n_mtd ;
+ axis2_char_t *sig_val ;
+ axutil_array_list_t *sign_parts;
+ oxs_x509_cert_t *certificate ;
+ openssl_pkey_t *prv_key ;
+ openssl_pkey_t *pub_key ;
+ oxs_sign_operation_t operation;
+};
+
+/*Public functions*/
+
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_sign_ctx_get_sign_mtd_algo(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->sign_mtd_algo;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_sign_ctx_get_c14n_mtd(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->c14n_mtd;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_sign_ctx_get_sig_val(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->sig_val;
+}
+
+
+AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
+oxs_sign_ctx_get_sign_parts(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->sign_parts;
+}
+
+AXIS2_EXTERN oxs_x509_cert_t *AXIS2_CALL
+oxs_sign_ctx_get_certificate(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->certificate ;
+}
+
+AXIS2_EXTERN openssl_pkey_t *AXIS2_CALL
+oxs_sign_ctx_get_private_key(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->prv_key ;
+}
+
+AXIS2_EXTERN openssl_pkey_t *AXIS2_CALL
+oxs_sign_ctx_get_public_key(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ /*If the public key is set then use it. Else get the public key from the certificate.*/
+ if(sign_ctx->pub_key){
+ AXIS2_LOG_INFO(env->log, "[oxs][sign_ctx] Public key is available directly");
+ return sign_ctx->pub_key ;
+ }else if(sign_ctx->certificate){
+ AXIS2_LOG_INFO(env->log, "[oxs][sign_ctx] Public key is not available directly. Extracting the certificate");
+ return oxs_x509_cert_get_public_key(sign_ctx->certificate, env);
+ }else{
+ AXIS2_LOG_INFO(env->log, "[oxs][sign_ctx] Public key is available neither in the ctx nor in the certificate");
+ return NULL;
+ }
+}
+
+AXIS2_EXTERN oxs_sign_operation_t AXIS2_CALL
+oxs_sign_ctx_get_operation(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+ return sign_ctx->operation;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_certificate(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ oxs_x509_cert_t *certificate)
+{
+ if (sign_ctx->certificate )
+ {
+ sign_ctx->certificate = NULL;
+ }
+ sign_ctx->certificate = certificate;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_private_key(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ openssl_pkey_t *prv_key)
+{
+ if (sign_ctx->prv_key )
+ {
+ sign_ctx->prv_key = NULL;
+ }
+ sign_ctx->prv_key = prv_key;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_public_key(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ openssl_pkey_t *pub_key)
+{
+ if (sign_ctx->pub_key )
+ {
+ sign_ctx->pub_key = NULL;
+ }
+ sign_ctx->pub_key = pub_key;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_sign_mtd_algo(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ axis2_char_t *sign_mtd_algo)
+{
+
+ if (sign_ctx->sign_mtd_algo)
+ {
+ AXIS2_FREE(env->allocator, sign_ctx->sign_mtd_algo);
+ sign_ctx->sign_mtd_algo = NULL;
+ }
+ sign_ctx->sign_mtd_algo = axutil_strdup(env,sign_mtd_algo);
+ return AXIS2_SUCCESS;
+}
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_c14n_mtd(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ axis2_char_t *c14n_mtd)
+{
+
+ if (sign_ctx->c14n_mtd)
+ {
+ AXIS2_FREE(env->allocator, sign_ctx->c14n_mtd);
+ sign_ctx->c14n_mtd = NULL;
+ }
+ sign_ctx->c14n_mtd = axutil_strdup(env, c14n_mtd);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_sig_val(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ axis2_char_t *sig_val)
+{
+
+ if (sign_ctx->sig_val)
+ {
+ AXIS2_FREE(env->allocator, sign_ctx->sig_val);
+ sign_ctx->sig_val = NULL;
+ }
+ sign_ctx->sig_val = axutil_strdup(env, sig_val);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_sign_parts(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ axutil_array_list_t *sign_parts)
+{
+ if(sign_ctx->sign_parts){
+ sign_ctx->sign_parts = NULL;
+ }
+ sign_ctx->sign_parts = sign_parts;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_operation(
+ oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env,
+ oxs_sign_operation_t operation
+)
+{
+ sign_ctx->operation = operation;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN oxs_sign_ctx_t *AXIS2_CALL
+oxs_sign_ctx_create(const axutil_env_t *env)
+{
+ oxs_sign_ctx_t *sign_ctx = NULL;
+
+ AXIS2_ENV_CHECK(env, NULL);
+
+ sign_ctx = AXIS2_MALLOC(env->allocator, sizeof(oxs_sign_ctx_t));
+ if (!sign_ctx)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ sign_ctx->sign_mtd_algo= NULL;
+ sign_ctx->c14n_mtd = NULL;
+ sign_ctx->sig_val = NULL;
+ sign_ctx->sign_parts = NULL;
+ sign_ctx->certificate = NULL;
+ sign_ctx->prv_key = NULL;
+ sign_ctx->pub_key = NULL;
+ sign_ctx->operation = OXS_SIGN_OPERATION_NONE;
+ return sign_ctx;
+}
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_ctx_free(oxs_sign_ctx_t *sign_ctx,
+ const axutil_env_t *env)
+{
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ if (sign_ctx->sign_mtd_algo)
+ {
+ AXIS2_FREE(env->allocator, sign_ctx->sign_mtd_algo);
+ sign_ctx->sign_mtd_algo = NULL;
+ }
+
+ if (sign_ctx->c14n_mtd)
+ {
+ AXIS2_FREE(env->allocator, sign_ctx->c14n_mtd);
+ sign_ctx->c14n_mtd = NULL;
+ }
+
+ if (sign_ctx->sig_val)
+ {
+ AXIS2_FREE(env->allocator, sign_ctx->sig_val);
+ sign_ctx->sig_val = NULL;
+ }
+
+ sign_ctx->sign_parts = NULL;
+ sign_ctx->certificate = NULL;
+ sign_ctx->prv_key = NULL;
+ sign_ctx->pub_key = NULL;
+ sign_ctx->operation = OXS_SIGN_OPERATION_NONE;
+
+ AXIS2_FREE(env->allocator, sign_ctx);
+ sign_ctx = NULL;
+
+ return AXIS2_SUCCESS;
+}
+
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/sign_part.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/sign_part.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/sign_part.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/sign_part.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,206 @@
+/*
+ * 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_sign_part.h>
+#include <oxs_error.h>
+
+struct oxs_sign_part_t
+{
+ axis2_char_t *id;
+ axis2_char_t *digest_mtd;
+ axis2_char_t *digest_val;
+ axiom_node_t *node ; /*Shallow copies*/
+ axutil_array_list_t *transforms; /*Shallow copies*/
+};
+
+
+/*Public functions*/
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_sign_part_get_id(
+ const oxs_sign_part_t *sign_part,
+ const axutil_env_t *env)
+{
+ return sign_part->id;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_sign_part_get_digest_mtd(
+ const oxs_sign_part_t *sign_part,
+ const axutil_env_t *env)
+{
+ return sign_part->digest_mtd;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_sign_part_get_digest_val(
+ const oxs_sign_part_t *sign_part,
+ const axutil_env_t *env)
+{
+ return sign_part->digest_val;
+}
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+oxs_sign_part_get_node(
+ const oxs_sign_part_t *sign_part,
+ const axutil_env_t *env)
+{
+ return sign_part->node;
+}
+
+AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
+oxs_sign_part_get_transforms(
+ const oxs_sign_part_t *sign_part,
+ const axutil_env_t *env)
+{
+ return sign_part->transforms;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_part_set_id(
+ oxs_sign_part_t *sign_part,
+ const axutil_env_t *env,
+ axis2_char_t *id)
+{
+
+ if (sign_part->id)
+ {
+ AXIS2_FREE(env->allocator, sign_part->id);
+ sign_part->id = NULL;
+ }
+ sign_part->id = axutil_strdup(env, id);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_part_set_digest_mtd(
+ oxs_sign_part_t *sign_part,
+ const axutil_env_t *env,
+ axis2_char_t *digest_mtd)
+{
+
+ if (sign_part->digest_mtd)
+ {
+ AXIS2_FREE(env->allocator, sign_part->digest_mtd);
+ sign_part->digest_mtd = NULL;
+ }
+ sign_part->digest_mtd = axutil_strdup(env, digest_mtd);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_part_set_digest_val(
+ oxs_sign_part_t *sign_part,
+ const axutil_env_t *env,
+ axis2_char_t *digest_val)
+{
+
+ if (sign_part->digest_val)
+ {
+ AXIS2_FREE(env->allocator, sign_part->digest_val);
+ sign_part->digest_val = NULL;
+ }
+ sign_part->digest_val = axutil_strdup(env, digest_val);
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_part_set_node(
+ oxs_sign_part_t *sign_part,
+ const axutil_env_t *env,
+ axiom_node_t *node)
+{
+ if(sign_part->node){
+ sign_part->node = NULL;
+ }
+ sign_part->node = node;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_part_set_transforms(
+ oxs_sign_part_t *sign_part,
+ const axutil_env_t *env,
+ axutil_array_list_t *transforms)
+{
+ if(sign_part->transforms){
+ sign_part->transforms = NULL;
+ }
+ sign_part->transforms = transforms;
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN oxs_sign_part_t *AXIS2_CALL
+oxs_sign_part_create(const axutil_env_t *env)
+{
+ oxs_sign_part_t *sign_part = NULL;
+
+ AXIS2_ENV_CHECK(env, NULL);
+
+ sign_part = AXIS2_MALLOC(env->allocator, sizeof(oxs_sign_part_t));
+ if (!sign_part)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ sign_part->id= NULL;
+ sign_part->digest_mtd = NULL;
+ sign_part->digest_val = NULL;
+ sign_part->node = NULL;
+ sign_part->transforms = NULL;
+
+ return sign_part;
+}
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sign_part_free(oxs_sign_part_t *sign_part,
+ const axutil_env_t *env)
+{
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ if (sign_part->id)
+ {
+ AXIS2_FREE(env->allocator, sign_part->id);
+ sign_part->id = NULL;
+ }
+
+ if (sign_part->digest_mtd)
+ {
+ AXIS2_FREE(env->allocator, sign_part->digest_mtd);
+ sign_part->digest_mtd = NULL;
+ }
+
+ if (sign_part->digest_val)
+ {
+ AXIS2_FREE(env->allocator, sign_part->digest_val);
+ sign_part->digest_val = NULL;
+ }
+
+ sign_part->node = NULL;
+ sign_part->transforms = NULL;
+
+ AXIS2_FREE(env->allocator, sign_part);
+ sign_part = NULL;
+
+ return AXIS2_SUCCESS;
+}
+
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/signature.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/signature.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/signature.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/signature.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,153 @@
+/*
+ * 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_error.h>
+#include <oxs_buffer.h>
+#include <oxs_cipher.h>
+#include <oxs_sign_ctx.h>
+#include <oxs_signature.h>
+#include <oxs_buffer.h>
+#include <openssl_rsa.h>
+#include <openssl_sign.h>
+#include <openssl_digest.h>
+
+/*Private functions*/
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sig_sign_rsa_sha1(const axutil_env_t *env,
+ oxs_sign_ctx_t *sign_ctx,
+ oxs_buffer_t *input,
+ oxs_buffer_t *output)
+{
+ axis2_char_t *encoded_str = NULL;
+ axis2_status_t status = AXIS2_FAILURE;
+ oxs_buffer_t *signed_result_buf = NULL;
+ openssl_pkey_t *prvkey = NULL;
+ int signedlen = -1, encodedlen = -1, ret = -1;
+
+ /*Create output buffer to store signed data*/
+ signed_result_buf = oxs_buffer_create(env);
+
+ /*Sign */
+ prvkey = oxs_sign_ctx_get_private_key(sign_ctx, env);
+ signedlen = openssl_sig_sign(env, prvkey, input, signed_result_buf);
+ if(signedlen < 0){
+ /*Error*/
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIGN_FAILED,
+ "Signature failed. The length of signature is %d", signedlen);
+ }
+
+ /*Base64 encode*/
+ encodedlen = axutil_base64_encode_len(signedlen);
+ encoded_str = AXIS2_MALLOC(env->allocator, encodedlen);
+ ret = axutil_base64_encode(encoded_str, (const char *)oxs_buffer_get_data(signed_result_buf, env), signedlen);
+ status = oxs_buffer_populate(output, env, (unsigned char*)axutil_strdup(env, encoded_str), encodedlen);
+
+ /*Free signed_result_buf*/
+
+ return AXIS2_SUCCESS;
+}
+
+
+/*Public functions*/
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sig_sign(const axutil_env_t *env,
+ oxs_sign_ctx_t *sign_ctx,
+ oxs_buffer_t *input,
+ oxs_buffer_t *output)
+{
+ axis2_char_t *sign_algo = NULL;
+
+
+ /*Get algo*/
+ sign_algo = oxs_sign_ctx_get_sign_mtd_algo(sign_ctx, env);
+
+ /*Prepare content and sign*/
+ if(0==(axutil_strcmp(sign_algo, OXS_HREF_RSA_SHA1))){
+ oxs_sig_sign_rsa_sha1(env, sign_ctx, input, output);
+ }else if(0==(axutil_strcmp(sign_algo, OXS_HREF_DSA_SHA1))){
+ /*Error we do not support*/
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+ "Cannot support cipher %s", sign_algo);
+ return AXIS2_FAILURE;
+ }else{
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+ "Cannot support cipher %s", sign_algo);
+ return AXIS2_FAILURE;
+ }
+
+
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sig_verify(const axutil_env_t *env,
+ oxs_sign_ctx_t *sign_ctx,
+ axis2_char_t *content,
+ axis2_char_t *signature)
+{
+ axis2_status_t status = AXIS2_FAILURE;
+ oxs_buffer_t *in_buf = NULL;
+ oxs_buffer_t *sig_buf = NULL;
+ openssl_pkey_t *pubkey = NULL;
+
+ unsigned char* decoded_data = NULL;
+ int decoded_len = -1;
+ int ret = -1;
+
+ /*Base64 decode the signature value and create the sig buffer*/
+ /*Allocate enough space*/
+ decoded_data = AXIS2_MALLOC(env->allocator, axutil_base64_decode_len(signature));
+ decoded_len = axutil_base64_decode_binary(decoded_data, signature );
+ if (decoded_len < 0)
+ {
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,
+ "axutil_base64_decode_binary failed");
+ return AXIS2_FAILURE;
+ }
+
+ /*Create the signature buffer*/
+ sig_buf = oxs_buffer_create(env);
+ ret = oxs_buffer_populate(sig_buf, env, decoded_data, decoded_len);
+
+ /*Create the input buffer*/
+ in_buf = oxs_buffer_create(env);
+ status = oxs_buffer_populate(in_buf, env, (unsigned char*)content, axutil_strlen(content));
+
+ /*Get the public key. See.. this method is trickey. It might take the public key from the certificate, only if
+ * the public key is not available directly*/
+ pubkey = oxs_sign_ctx_get_public_key(sign_ctx, env);
+ if(!pubkey){
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Cannot obtain the public key.");
+ return AXIS2_FAILURE;
+ }
+
+ /*Call OpenSSL function to verify the signature*/
+ status = openssl_sig_verify(env, pubkey, in_buf, sig_buf);
+ if(AXIS2_SUCCESS != status){
+ /*Error in signature processing*/
+ oxs_error(env, ERROR_LOCATION, OXS_ERROR_SIG_VERIFICATION_FAILED,"Signature verification FAILED.");
+ return AXIS2_FAILURE;
+ }else{
+
+ AXIS2_LOG_INFO(env->log, "[oxs][sig] Signature verification SUCCESS " );
+ return AXIS2_SUCCESS;
+ }
+
+}
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/Makefile.am?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/Makefile.am (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/Makefile.am Thu Sep 6 03:48:44 2007
@@ -0,0 +1,19 @@
+lib_LTLIBRARIES =liboxstokens.la
+
+liboxstokens_la_SOURCES = 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 \
+ token_key_identifier.c token_x509_data.c token_x509_issuer_serial.c\
+ token_x509_issuer_name.c token_x509_serial_number.c token_security_token_reference.c \
+ token_embedded.c token_reference.c token_signature_value.c token_signed_info.c \
+ token_c14n_method.c token_signature_method.c token_digest_method.c token_digest_value.c \
+ token_transform.c token_transforms.c token_signature.c token_ds_reference.c \
+ token_x509_certificate.c
+
+liboxstokens_la_LIBADD = ${AXIS2C_HOME}/lib
+
+INCLUDES = -I$(top_builddir)/include \
+ -I ../../../../util/include \
+ -I ../../../../include \
+ -I ../../../../axiom/include \
+ @AXIS2INC@
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_binary_security_token.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_binary_security_token.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_binary_security_token.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_binary_security_token.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,89 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_binary_security_token.h>
+#include <oxs_utility.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+#include <rampart_constants.h>
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_binary_security_token_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* id,
+ axis2_char_t* encoding_type,
+ axis2_char_t* value_type,
+ axis2_char_t* data)
+{
+ axiom_node_t *binary_security_token_node = NULL;
+ axiom_node_t *first_child_of_parent = NULL;
+ axiom_element_t *binary_security_token_ele = NULL;
+ axiom_attribute_t *encoding_type_att = NULL;
+ axiom_attribute_t *value_type_att = NULL;
+ axiom_attribute_t *id_attr = NULL;
+ int ret;
+ axiom_namespace_t *ns_obj = NULL;
+ axiom_namespace_t *ns = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_WSSE_NS,
+ OXS_WSSE);
+
+ ns = axiom_namespace_create(env,RAMPART_WSU_XMLNS,OXS_WSU);
+
+ binary_security_token_ele = axiom_element_create(env, parent, OXS_NODE_BINARY_SECURITY_TOKEN, ns_obj, &binary_security_token_node);
+ if (!binary_security_token_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating Binary Security Token element");
+ return NULL;
+ }
+
+ /*Binary security token must be added as the first child of the paretn*/
+ binary_security_token_node = axiom_node_detach(binary_security_token_node, env);
+ first_child_of_parent = axiom_node_get_first_element(parent, env);
+ if(first_child_of_parent){
+ /*If there is a child add bst before it*/
+ axiom_node_insert_sibling_before(first_child_of_parent, env, binary_security_token_node);
+ }else{
+ /*If there are no children just add the bst*/
+ axiom_node_add_child(parent, env, binary_security_token_node);
+ }
+ if (!id)
+ {
+ id = oxs_util_generate_id(env,(axis2_char_t*)OXS_CERT_ID);
+ }
+
+
+ id_attr = axiom_attribute_create(env, OXS_ATTR_ID, id,ns);
+ encoding_type_att = axiom_attribute_create(env, OXS_ATTR_ENCODING_TYPE, encoding_type, NULL);
+ value_type_att = axiom_attribute_create(env, OXS_ATTR_VALUE_TYPE, value_type, NULL);
+
+ ret = axiom_element_add_attribute(binary_security_token_ele, env, id_attr, binary_security_token_node);
+ ret = axiom_element_add_attribute(binary_security_token_ele, env, encoding_type_att, binary_security_token_node);
+ ret = axiom_element_add_attribute(binary_security_token_ele, env, value_type_att, binary_security_token_node);
+
+ if(data){
+ ret = axiom_element_set_text(binary_security_token_ele, env, data, binary_security_token_node);
+ }
+
+ return binary_security_token_node;
+
+}
+
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_c14n_method.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_c14n_method.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_c14n_method.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_c14n_method.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,90 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_c14n_method.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_c14n_method_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* algorithm
+ )
+{
+ axiom_node_t *c14n_method_node = NULL;
+ axiom_element_t *c14n_method_ele = NULL;
+ axiom_attribute_t *algo_attr = NULL;
+ int ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_DSIG_NS,
+ OXS_DS);
+
+ c14n_method_ele = axiom_element_create(env, parent, OXS_NODE_CANONICALIZATION_METHOD, ns_obj, &c14n_method_node);
+ if (!c14n_method_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating c14n method element");
+ return NULL;
+ }
+ /*If c14n algorithm is NULL then use the default*/
+ if (!algorithm)
+ {
+ algorithm = (axis2_char_t*)OXS_HREF_XML_EXC_C14N;
+ }
+
+ algo_attr = axiom_attribute_create(env, OXS_ATTR_ALGORITHM, algorithm, NULL);
+
+ ret = axiom_element_add_attribute(c14n_method_ele, env, algo_attr, c14n_method_node);
+
+ return c14n_method_node;
+
+}
+
+
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_token_get_c14n_method(const axutil_env_t *env, axiom_node_t *c14n_mtd_node)
+{
+ axis2_char_t *c14n_mtd = NULL;
+ axiom_element_t *c14n_mtd_ele = NULL;
+
+ if(!c14n_mtd_node){
+ return NULL;
+ }
+
+ c14n_mtd_ele = axiom_node_get_data_element(c14n_mtd_node, env);
+ if (!c14n_mtd_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error retrieving c14n method element");
+ return NULL;
+ }
+
+ c14n_mtd = axiom_element_get_attribute_value_by_name(c14n_mtd_ele, env, OXS_ATTR_ALGORITHM);
+ if((!c14n_mtd) ||(0 == axutil_strcmp("", c14n_mtd))){
+ return NULL;
+ }
+
+ return c14n_mtd;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_data.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_data.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_data.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_data.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,65 @@
+/*
+ * 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 <axiom_element.h>
+#include <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_cipher_data.h>
+#include <oxs_token_cipher_value.h>
+#include <oxs_axiom.h>
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_cipher_data_element(const axutil_env_t *env,
+ axiom_node_t *parent
+ )
+{
+ axiom_node_t *cipher_data_node = NULL;
+ axiom_element_t *cipher_data_ele = NULL;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_ENC_NS,
+ OXS_XENC);
+
+ cipher_data_ele = axiom_element_create(env, parent, OXS_NODE_CIPHER_DATA, ns_obj, &cipher_data_node);
+ if (!cipher_data_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating cipher data element");
+ return NULL;
+ }
+
+ return cipher_data_node;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_token_get_cipher_value_from_cipher_data(const axutil_env_t *env,
+ axiom_node_t *cd_node)
+{
+ axiom_node_t *cv_node = NULL;
+ axis2_char_t *value = NULL;
+ /*First check direct <CipherValue>*/
+ cv_node = oxs_axiom_get_first_child_node_by_name(env, cd_node, OXS_NODE_CIPHER_VALUE, OXS_ENC_NS, OXS_XENC);
+ if(cv_node){
+ value = oxs_token_get_cipher_value(env, cv_node);
+ }else{
+ /*If not then check for <CipherReference URI?>*/
+ }
+
+ return value;
+}
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_value.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_value.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_value.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_cipher_value.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,67 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_cipher_value.h>
+#include <axiom_element.h>
+#include <oxs_axiom.h>
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_token_get_cipher_value(const axutil_env_t *env,
+ axiom_node_t *cv_node)
+{
+ axis2_char_t *cv = NULL;
+ /*TODO Verification*/
+ cv = (axis2_char_t*)oxs_axiom_get_node_content(env, cv_node);
+ return cv;
+
+}
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_cipher_value_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* cipher_val
+ )
+{
+ axiom_node_t *cipher_value_node = NULL;
+ axiom_element_t *cipher_value_ele = NULL;
+ axis2_status_t ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_ENC_NS,
+ OXS_XENC);
+
+ cipher_value_ele = axiom_element_create(env, parent, OXS_NODE_CIPHER_VALUE, ns_obj, &cipher_value_node);
+ if (!cipher_value_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating cipher value element");
+ return NULL;
+ }
+
+ if (cipher_val)
+ {
+ ret = axiom_element_set_text(cipher_value_ele, env, cipher_val, cipher_value_node);
+ }
+
+ return cipher_value_node;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_data_reference.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_data_reference.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_data_reference.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_data_reference.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,78 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_data_reference.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_data_reference_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t *data_ref)
+{
+ axiom_node_t *data_reference_node = NULL;
+ axiom_element_t *data_reference_ele = NULL;
+ axiom_attribute_t *data_ref_attr = NULL;
+ int ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_ENC_NS,
+ OXS_XENC);
+
+ data_reference_ele = axiom_element_create(env, parent, OXS_NODE_DATA_REFERENCE, ns_obj, &data_reference_node);
+ if (!data_reference_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating data reference element");
+ return NULL;
+ }
+ /*attach empty string*/
+ if (!data_ref)
+ {
+ data_ref = "";
+ }
+
+ data_ref_attr = axiom_attribute_create(env, OXS_ATTR_URI , data_ref, NULL);
+
+ ret = axiom_element_add_attribute(data_reference_ele, env, data_ref_attr, data_reference_node);
+
+ return data_reference_node;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_token_get_data_reference(const axutil_env_t *env, axiom_node_t *data_ref_node)
+{
+ axis2_char_t *data_ref = NULL;
+ axiom_element_t *data_reference_ele = NULL;
+
+ data_reference_ele = axiom_node_get_data_element(data_ref_node, env);
+ if (!data_reference_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error retrieving data reference element");
+ return NULL;
+ }
+
+ data_ref = axiom_element_get_attribute_value_by_name(data_reference_ele, env, OXS_ATTR_URI);
+ return data_ref;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_method.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_method.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_method.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_method.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,90 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_digest_method.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_digest_method_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* algorithm
+ )
+{
+ axiom_node_t *digest_method_node = NULL;
+ axiom_element_t *digest_method_ele = NULL;
+ axiom_attribute_t *algo_attr = NULL;
+ int ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_DSIG_NS,
+ OXS_DS);
+
+ digest_method_ele = axiom_element_create(env, parent, OXS_NODE_DIGEST_METHOD, ns_obj, &digest_method_node);
+ if (!digest_method_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating digest method element");
+ return NULL;
+ }
+ /*If digest algorithm is NULL then use the default*/
+ if (!algorithm)
+ {
+ algorithm = (axis2_char_t*)OXS_HREF_SHA1;
+ }
+
+ algo_attr = axiom_attribute_create(env, OXS_ATTR_ALGORITHM, algorithm, NULL);
+
+ ret = axiom_element_add_attribute(digest_method_ele, env, algo_attr, digest_method_node);
+
+ return digest_method_node;
+
+}
+
+
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_token_get_digest_method(const axutil_env_t *env, axiom_node_t *digest_mtd_node)
+{
+ axis2_char_t *digest_mtd = NULL;
+ axiom_element_t *digest_mtd_ele = NULL;
+
+ if(!digest_mtd_node){
+ return NULL;
+ }
+
+ digest_mtd_ele = axiom_node_get_data_element(digest_mtd_node, env);
+ if (!digest_mtd_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error retrieving digest method element");
+ return NULL;
+ }
+
+ digest_mtd = axiom_element_get_attribute_value_by_name(digest_mtd_ele, env, OXS_ATTR_ALGORITHM);
+ if((!digest_mtd) ||(0 == axutil_strcmp("", digest_mtd))){
+ return NULL;
+ }
+
+ return digest_mtd;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_value.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_value.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_value.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_digest_value.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,67 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_digest_value.h>
+#include <axiom_element.h>
+#include <oxs_axiom.h>
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_token_get_digest_value(const axutil_env_t *env,
+ axiom_node_t *digest_val_node)
+{
+ axis2_char_t *digest_val = NULL;
+ /*TODO Verification*/
+ digest_val = (axis2_char_t*)oxs_axiom_get_node_content(env, digest_val_node);
+ return digest_val;
+
+}
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_digest_value_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* digest_val
+ )
+{
+ axiom_node_t *digest_value_node = NULL;
+ axiom_element_t *digest_value_ele = NULL;
+ axis2_status_t ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_DSIG_NS,
+ OXS_DS);
+
+ digest_value_ele = axiom_element_create(env, parent, OXS_NODE_DIGEST_VALUE, ns_obj, &digest_value_node);
+ if (!digest_value_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating digest value element");
+ return NULL;
+ }
+
+ if (digest_val)
+ {
+ ret = axiom_element_set_text(digest_value_ele, env, digest_val, digest_value_node);
+ }
+
+ return digest_value_node;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_ds_reference.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_ds_reference.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_ds_reference.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_ds_reference.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,88 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_ds_reference.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_ds_reference_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t *id,
+ axis2_char_t *uri,
+ axis2_char_t *type)
+{
+ axiom_node_t *ds_reference_node = NULL;
+ axiom_element_t *ds_reference_ele = NULL;
+ int ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_DSIG_NS,
+ OXS_DS);
+
+ ds_reference_ele = axiom_element_create(env, parent, OXS_NODE_REFERENCE, ns_obj, &ds_reference_node);
+ if (!ds_reference_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating ds:Reference element");
+ return NULL;
+ }
+
+ if(id){
+ axiom_attribute_t *id_attr = NULL;
+ id_attr = axiom_attribute_create(env, OXS_ATTR_ID , id, NULL);
+ ret = axiom_element_add_attribute(ds_reference_ele, env, id_attr, ds_reference_node);
+ }
+
+ if(uri){
+ axiom_attribute_t *uri_attr = NULL;
+ uri_attr = axiom_attribute_create(env, OXS_ATTR_URI , uri, NULL);
+ ret = axiom_element_add_attribute(ds_reference_ele, env, uri_attr, ds_reference_node);
+ }
+
+ if(type){
+ axiom_attribute_t *type_attr = NULL;
+ type_attr = axiom_attribute_create(env, OXS_ATTR_TYPE , type, NULL);
+ ret = axiom_element_add_attribute(ds_reference_ele, env, type_attr, ds_reference_node);
+ }
+
+ return ds_reference_node;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_token_get_ds_reference(const axutil_env_t *env, axiom_node_t *ref_node)
+{
+ axis2_char_t *ref = NULL;
+ axiom_element_t *reference_ele = NULL;
+
+ reference_ele = axiom_node_get_data_element(ref_node, env);
+ if (!reference_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error retrieving data reference element");
+ return NULL;
+ }
+
+ ref = axiom_element_get_attribute_value_by_name(reference_ele, env, OXS_ATTR_URI);
+ return ref;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_embedded.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_embedded.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_embedded.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_embedded.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,83 @@
+/*
+ * 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 <axis2_util.h>
+#include <stdio.h>
+#include <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_embedded.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+#include <oxs_utility.h>
+
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_embedded_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* id)
+{
+ axiom_node_t *embedded_node = NULL;
+ axiom_element_t *embedded_ele = NULL;
+ axiom_attribute_t *id_attr = NULL;
+ int ret;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_WSSE_NS,
+ OXS_WSSE);
+
+ embedded_ele = axiom_element_create(env, parent, OXS_NODE_EMBEDDED, ns_obj, &embedded_node);
+ if (!embedded_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating embedded element");
+ return NULL;
+ }
+ if (!id)
+ {
+ id = oxs_util_generate_id(env,(axis2_char_t*)OXS_EMBEDDED_ID);
+ }
+
+ id_attr = axiom_attribute_create(env, OXS_ATTR_ID, id, NULL);
+
+ ret = axiom_element_add_attribute(embedded_ele, env, id_attr, embedded_node);
+
+ return embedded_node;
+
+}
+
+
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+oxs_token_get_embedded_id(const axutil_env_t *env, axiom_node_t *embedded_node)
+{
+ axis2_char_t *embedded = NULL;
+ axiom_element_t *embedded_ele = NULL;
+
+ embedded_ele = axiom_node_get_data_element(embedded_node, env);
+ if (!embedded_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error retrieving embedded element");
+ return NULL;
+ }
+
+ embedded = axiom_element_get_attribute_value_by_name(embedded_ele, env, OXS_ATTR_ID);
+ return embedded;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_data.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_data.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_data.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_data.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,73 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_encrypted_data.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_encrypted_data_element(const axutil_env_t *env,
+ axiom_node_t *parent,
+ axis2_char_t* type_attribute,
+ axis2_char_t* id
+ )
+{
+ axiom_node_t *encrypted_data_node = NULL;
+ axiom_element_t *encrypted_data_ele = NULL;
+ axiom_attribute_t *type_attr = NULL;
+ axiom_attribute_t *id_attr = NULL;
+ axiom_namespace_t *ns_obj = NULL;
+ int ret;
+
+ ns_obj = axiom_namespace_create(env, OXS_ENC_NS,
+ OXS_XENC);
+
+ encrypted_data_ele = axiom_element_create(env, parent, OXS_NODE_ENCRYPTED_DATA, ns_obj, &encrypted_data_node);
+ if (!encrypted_data_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating encrypted data element");
+ return NULL;
+ }
+
+ if (type_attribute)
+ {
+ type_attr = axiom_attribute_create(env, OXS_ATTR_TYPE, type_attribute, NULL);
+ ret = axiom_element_add_attribute(encrypted_data_ele, env, type_attr, encrypted_data_node);
+ }
+
+ if (id)
+ {
+ id_attr = axiom_attribute_create(env, OXS_ATTR_ID, id, NULL);
+ ret = axiom_element_add_attribute(encrypted_data_ele, env, id_attr, encrypted_data_node);
+ }
+ else
+ {
+ /*TODO Get a unique value for this*/
+ id_attr = axiom_attribute_create(env, OXS_ATTR_ID, "EncDataId-54321", NULL);
+ ret = axiom_element_add_attribute(encrypted_data_ele, env, id_attr, encrypted_data_node);
+ }
+
+ return encrypted_data_node;
+
+}
+
Added: webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_key.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_key.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_key.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/tokens/token_encrypted_key.c Thu Sep 6 03:48:44 2007
@@ -0,0 +1,61 @@
+/*
+ * 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 <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_token_encrypted_key.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+
+/*TODO These names should be changed to oxs_token_build_XXX_node*/
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_build_encrypted_key_element(const axutil_env_t *env,
+ axiom_node_t *parent)
+{
+ axiom_node_t *encrypted_key_node = NULL;
+ axiom_element_t *encrypted_key_ele = NULL;
+ axiom_namespace_t *ns_obj = NULL;
+
+ ns_obj = axiom_namespace_create(env, OXS_ENC_NS,
+ OXS_XENC);
+
+ encrypted_key_ele = axiom_element_create(env, parent, OXS_NODE_ENCRYPTED_KEY, ns_obj, &encrypted_key_node);
+ if (!encrypted_key_ele)
+ {
+ oxs_error(env, ERROR_LOCATION,
+ OXS_ERROR_ELEMENT_FAILED, "Error creating encrypted key element");
+ return NULL;
+ }
+
+
+
+ return encrypted_key_node;
+
+}
+
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_token_get_encrypted_key_node(const axutil_env_t *env,
+ axiom_node_t *parent)
+{
+ axiom_node_t *enc_key_node = NULL;
+
+ /*TODO*/
+ return enc_key_node;
+}