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 [11/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/cipher.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/cipher.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/cipher.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/cipher.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,129 @@
+/*
+ * 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_error.h>
+#include <oxs_cipher.h>
+#include <openssl_constants.h>
+#include <openssl_util.h>
+
+
+AXIS2_EXTERN openssl_cipher_property_t *AXIS2_CALL
+oxs_get_cipher_property_for_url(const axutil_env_t *env,
+                                axis2_char_t *url)
+{
+    openssl_cipher_property_t *cprop = NULL;
+    axis2_char_t *cipher_name = NULL;
+    axis2_status_t ret = AXIS2_SUCCESS;
+
+    cprop = openssl_cipher_property_create(env);
+    ret = openssl_cipher_property_set_url(cprop, env , url);
+
+    cipher_name = oxs_get_cipher_name_for_url(env, url);
+    if((!cipher_name) || (0 == axutil_strcmp(cipher_name, ""))){
+        oxs_error(env, ERROR_LOCATION,
+                  OXS_ERROR_INVALID_DATA, "Cannot populate cipher property");
+        return NULL;
+    }
+    ret = openssl_cipher_property_set_name(cprop, env , cipher_name);
+
+    ret = openssl_populate_cipher_property(env, cprop);
+    if (ret == AXIS2_FAILURE)
+    {
+        oxs_error(env, ERROR_LOCATION,
+                  OXS_ERROR_INVALID_DATA, "Cannot populate cipher property");
+        return NULL;
+
+    }
+    return cprop;
+}
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_get_cipher_name_for_url(const axutil_env_t *env,
+                            axis2_char_t *url)
+{
+
+    axis2_char_t *cipher_name = NULL;
+
+    if (0 == axutil_strcmp(url, (axis2_char_t*)OXS_HREF_DES3_CBC))
+    {
+        cipher_name = OPENSSL_EVP_des_ede3_cbc;
+
+    }
+    else if (0 == axutil_strcmp(url, (axis2_char_t*)OXS_HREF_AES_128_CBC))
+    {
+        cipher_name = OPENSSL_EVP_aes_128_cbc;
+
+    }
+    else if (0 == axutil_strcmp(url, (axis2_char_t*)OXS_HREF_AES_192_CBC))
+    {
+        cipher_name = OPENSSL_EVP_aes_192_cbc;
+
+    }
+    else if (0 == axutil_strcmp(url, (axis2_char_t*)OXS_HREF_AES_256_CBC))
+    {
+        cipher_name = OPENSSL_EVP_aes_256_cbc;
+
+    }
+    else
+    {
+        oxs_error(env, ERROR_LOCATION,
+                  OXS_ERROR_UNSUPPORTED_ALGO, "Algorithm not supported");
+        return NULL;
+    }
+
+    return cipher_name;
+}
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_get_cipher_url_for_name(const axutil_env_t *env,
+                            axis2_char_t *name)
+{
+
+    axis2_char_t *cipher_url = NULL;
+
+    if (0 == axutil_strcmp(name, (axis2_char_t*)OPENSSL_EVP_des_ede3_cbc))
+    {
+        cipher_url = OXS_HREF_DES3_CBC;
+
+    }
+    else if (0 == axutil_strcmp(name, (axis2_char_t*)OPENSSL_EVP_aes_128_cbc))
+    {
+        cipher_url = OXS_HREF_AES_128_CBC;
+
+    }
+    else if (0 == axutil_strcmp(name, (axis2_char_t*)OPENSSL_EVP_aes_192_cbc))
+    {
+        cipher_url = OXS_HREF_AES_192_CBC;
+
+    }
+    else if (0 == axutil_strcmp(name, (axis2_char_t*)OPENSSL_EVP_aes_256_cbc))
+    {
+        cipher_url = OXS_HREF_AES_256_CBC;
+
+    }
+    else
+    {
+        oxs_error(env, ERROR_LOCATION,
+                  OXS_ERROR_INVALID_DATA, "Name not supported");
+        return NULL;
+    }
+
+    return cipher_url;
+}
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/ctx.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/ctx.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/ctx.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/ctx.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,482 @@
+/*
+ * 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_ctx.h>
+
+
+struct oxs_ctx_t
+{
+    /*Encryption mode*/
+    oxs_ctx_mode_t mode;
+
+    /*transformation type */
+    oxs_ctx_operation_t operation;
+
+    /*key*/
+    oxs_key_t* key;
+
+    /* attributes from EncryptedData or EncryptedKey */
+    axis2_char_t*           id;
+    axis2_char_t*           type;
+    axis2_char_t*           mime_type;
+    axis2_char_t*           encoding;
+    axis2_char_t*           recipient;
+    axis2_char_t*           carried_key_name;
+
+    /*attributes from EncryptionMethod*/
+    axis2_char_t*           enc_mtd_algorithm;
+
+    /*Used  in decryption process to keep the data to be decrypted*/
+    axis2_char_t*           input_data;
+
+};
+
+/******************* function headers ******************************/
+AXIS2_EXTERN oxs_ctx_t *AXIS2_CALL
+oxs_ctx_create(const axutil_env_t *env)
+{
+    oxs_ctx_t *ctx = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+
+    ctx = (oxs_ctx_t*)AXIS2_MALLOC(env->allocator, sizeof(oxs_ctx_t));
+    if (!ctx)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    ctx->mode  = -1;
+    ctx->operation  = -1;
+    ctx->key  = NULL;
+    ctx->id  = NULL;
+    ctx->type  = NULL;
+    ctx->mime_type  = NULL;
+    ctx->encoding  = NULL;
+    ctx->recipient  = NULL;
+    ctx->carried_key_name  = NULL;
+    ctx->enc_mtd_algorithm  = NULL;
+    ctx->input_data  = NULL;
+
+    return ctx;
+}
+
+
+/*public functions*/
+axis2_status_t AXIS2_CALL
+oxs_ctx_free(oxs_ctx_t *ctx,
+             const axutil_env_t *env
+            )
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (ctx->id)
+    {
+        AXIS2_FREE(env->allocator, ctx->id);
+        ctx->id = NULL;
+    }
+
+    if (ctx->type)
+    {
+        AXIS2_FREE(env->allocator, ctx->type);
+        ctx->type = NULL;
+    }
+
+    if (ctx->mime_type)
+    {
+        AXIS2_FREE(env->allocator, ctx->mime_type);
+        ctx->mime_type = NULL;
+    }
+
+    if (ctx->encoding)
+    {
+        AXIS2_FREE(env->allocator, ctx->encoding);
+        ctx->encoding = NULL;
+    }
+
+    if (ctx->recipient)
+    {
+        AXIS2_FREE(env->allocator, ctx->recipient);
+        ctx->recipient = NULL;
+    }
+
+    if (ctx->carried_key_name)
+    {
+        AXIS2_FREE(env->allocator, ctx->carried_key_name);
+        ctx->carried_key_name = NULL;
+    }
+
+    if (ctx->enc_mtd_algorithm)
+    {
+        AXIS2_FREE(env->allocator, ctx->enc_mtd_algorithm);
+        ctx->enc_mtd_algorithm = NULL;
+    }
+
+    if (ctx->input_data)
+    {
+        AXIS2_FREE(env->allocator, ctx->input_data);
+        ctx->input_data = NULL;
+    }
+
+    /*TODO free nodes and key*/
+
+    AXIS2_FREE(env->allocator,  ctx);
+    ctx = NULL;
+
+    return AXIS2_SUCCESS;
+}
+
+oxs_ctx_mode_t AXIS2_CALL
+oxs_ctx_get_mode(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return ctx->mode ;
+}
+
+oxs_ctx_operation_t AXIS2_CALL
+oxs_ctx_get_operation(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return ctx->operation ;
+}
+
+
+oxs_key_t *AXIS2_CALL
+oxs_ctx_get_key(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->key ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_id(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->id ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_type(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->type ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_mime_type(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->mime_type ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_encoding(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->encoding ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_recipient(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->recipient ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_carried_key_name(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->carried_key_name ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_enc_mtd_algorithm(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->enc_mtd_algorithm ;
+}
+
+
+axis2_char_t *AXIS2_CALL
+oxs_ctx_get_input_data(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->input_data ;
+}
+
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_mode(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    oxs_ctx_mode_t mode
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    ctx->mode = mode ;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_operation(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    oxs_ctx_operation_t operation
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    ctx->operation = operation ;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_key(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    oxs_key_t *key
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (ctx->key)
+    {
+        AXIS2_FREE(env->allocator, ctx->key);
+        ctx->key = NULL;
+    }
+    ctx->key = key;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_id(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *id
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, id, AXIS2_FAILURE);
+
+    if (ctx->id)
+    {
+        AXIS2_FREE(env->allocator, ctx->id);
+        ctx->id = NULL;
+    }
+    ctx->id = axutil_strdup(env, id);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_type(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *type
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, type, AXIS2_FAILURE);
+
+    if (ctx->type)
+    {
+        AXIS2_FREE(env->allocator, ctx->type);
+        ctx->type = NULL;
+    }
+    ctx->type = axutil_strdup(env, type);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_mime_type(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *mime_type
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, mime_type, AXIS2_FAILURE);
+
+    if (ctx->mime_type)
+    {
+        AXIS2_FREE(env->allocator, ctx->mime_type);
+        ctx->mime_type = NULL;
+    }
+    ctx->mime_type = axutil_strdup(env, mime_type);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_encoding(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *encoding
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, encoding, AXIS2_FAILURE);
+
+    if (ctx->encoding)
+    {
+        AXIS2_FREE(env->allocator, ctx->encoding);
+        ctx->encoding = NULL;
+    }
+    ctx->encoding = axutil_strdup(env, encoding);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_recipient(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *recipient
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, recipient, AXIS2_FAILURE);
+
+    if (ctx->recipient)
+    {
+        AXIS2_FREE(env->allocator, ctx->recipient);
+        ctx->recipient = NULL;
+    }
+    ctx->recipient = axutil_strdup(env, recipient);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_carried_key_name(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *carried_key_name
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, carried_key_name, AXIS2_FAILURE);
+
+    if (ctx->carried_key_name)
+    {
+        AXIS2_FREE(env->allocator, ctx->carried_key_name);
+        ctx->carried_key_name = NULL;
+    }
+    ctx->carried_key_name = axutil_strdup(env, carried_key_name);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_enc_mtd_algorithm(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *enc_mtd_algorithm
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, enc_mtd_algorithm, AXIS2_FAILURE);
+
+    if (ctx->enc_mtd_algorithm)
+    {
+        AXIS2_FREE(env->allocator, ctx->enc_mtd_algorithm);
+        ctx->enc_mtd_algorithm = NULL;
+    }
+    ctx->enc_mtd_algorithm = axutil_strdup(env, enc_mtd_algorithm);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_ctx_set_input_data(
+    oxs_ctx_t *ctx,
+    const axutil_env_t *env,
+    axis2_char_t *input_data
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, input_data, AXIS2_FAILURE);
+
+    if (ctx->input_data)
+    {
+        AXIS2_FREE(env->allocator, ctx->input_data);
+        ctx->input_data = NULL;
+    }
+    ctx->input_data = axutil_strdup(env, input_data) ;
+
+    return AXIS2_SUCCESS;
+}
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/encryption.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/encryption.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/encryption.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/encryption.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,264 @@
+/*
+ * 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_ctx.h>
+#include <oxs_error.h>
+#include <oxs_buffer.h>
+#include <oxs_encryption.h>
+#include <oxs_cipher.h>
+#include <oxs_iv.h>
+#include <openssl_cipher_ctx.h>
+#include <openssl_crypt.h>
+#include <openssl_constants.h>
+#include <openssl_rsa.h>
+#include <openssl_util.h>
+#include <oxs_key_mgr.h>
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_encryption_symmetric_crypt(const axutil_env_t *env,
+                               oxs_ctx_t * enc_ctx,
+                               oxs_buffer_t *input,
+                               oxs_buffer_t *result)
+{
+    openssl_cipher_ctx_t *oc_ctx = NULL;
+    openssl_cipher_property_t *cprop = NULL;
+    axis2_char_t *iv = NULL;
+    axis2_char_t *cipher_name = NULL;
+    axis2_status_t ret = AXIS2_FAILURE;
+
+    /*Get cipher property*/
+    cprop =  oxs_get_cipher_property_for_url(env, oxs_ctx_get_enc_mtd_algorithm(enc_ctx, env));
+    if(!cprop){
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "Cipher property is NULL");
+        return AXIS2_FAILURE;
+    }
+    /*Get the IV*/
+    iv = axutil_strndup(env,
+              (axis2_char_t*)oxs_iv_generate_for_algo(env,
+                           oxs_ctx_get_enc_mtd_algorithm(enc_ctx, env)),
+                       openssl_cipher_property_get_iv_size(cprop, env));
+
+    /*Create the openssl context*/
+    oc_ctx = openssl_cipher_ctx_create(env);
+    if (!oc_ctx)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "openssl_cipher_ctx_create failed");
+        return AXIS2_FAILURE;
+    }
+
+    /*Set IV*/
+    ret = openssl_cipher_ctx_set_iv(oc_ctx, env, iv);
+
+    /*Set key*/
+    ret = openssl_cipher_ctx_set_key(oc_ctx, env, oxs_ctx_get_key(enc_ctx, env));
+
+    /*Set the cipher*/
+    cipher_name = (axis2_char_t*)openssl_cipher_property_get_name(cprop, env);
+    if (!cipher_name)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "oxs_get_cipher failed");
+
+        return AXIS2_FAILURE;
+    }
+    ret = openssl_cipher_ctx_set_cipher(oc_ctx,
+                                        env,
+                                        (EVP_CIPHER*)openssl_get_evp_cipher_by_name(
+                                            env, (axis2_char_t*)cipher_name)
+                                       );
+
+    /*Now everything is ready for the en/decryption*/
+    /*ENCRYPTION*/
+    if (oxs_ctx_get_operation(enc_ctx, env) == OXS_CTX_OPERATION_ENCRYPT)
+    {
+        axis2_char_t *encoded_str = NULL;
+        int enclen = -1;
+        int encodedlen = -1;
+        oxs_buffer_t *output = NULL;
+
+        output = oxs_buffer_create(env);
+
+        /*Encrypt*/
+        enclen = openssl_bc_crypt(env, oc_ctx, input, output, OPENSSL_ENCRYPT);
+        if(enclen < 0){
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED,
+                      "openssl_block_cipher_crypt FAILED");
+            return AXIS2_FAILURE;
+        }
+
+        encodedlen = axutil_base64_encode_len(enclen);
+        encoded_str = AXIS2_MALLOC(env->allocator, encodedlen);
+        ret = axutil_base64_encode_binary(encoded_str, oxs_buffer_get_data(output, env), enclen);
+        if (ret < 0)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "axutil_base64_encode_binary failed");
+            return AXIS2_FAILURE;
+        }
+
+        /*Attach the result to the result buf*/
+        ret = oxs_buffer_populate(result, env, (unsigned char*)axutil_strdup(env, encoded_str), encodedlen);
+
+        /*Free*/
+        oxs_buffer_free(output, env);
+        output = NULL;
+        AXIS2_FREE(env->allocator, encoded_str);
+        encoded_str = NULL;
+
+        /*DECRYPTION*/
+    }else if(oxs_ctx_get_operation(enc_ctx, env) == OXS_CTX_OPERATION_DECRYPT){
+        unsigned char *decoded_data = NULL;/*Can be binary*/
+        int decoded_len = -1;
+        int enclen = -1;
+        oxs_buffer_t *decoded_buf = NULL;
+
+        decoded_buf = oxs_buffer_create(env);
+
+        /*First we need to base64 decode*/
+        decoded_data = AXIS2_MALLOC(env->allocator, axutil_base64_decode_len((char*)oxs_buffer_get_data(input, env)));
+        decoded_len = axutil_base64_decode_binary(decoded_data, (char*)oxs_buffer_get_data(input, env) );
+        if (decoded_len < 0)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_DECRYPT_FAILED,
+                      "axutil_base64_decode_binary failed");
+            return AXIS2_FAILURE;
+        }
+        /*Populate decoded (input to the crypto function) buffer*/
+        ret = oxs_buffer_populate(decoded_buf, env, decoded_data, decoded_len);
+        /*Then we decrypt*/
+        enclen = openssl_bc_crypt(env, oc_ctx, decoded_buf, result, OPENSSL_DECRYPT);
+
+        if(enclen < 0){
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_DECRYPT_FAILED,
+                      "openssl_block_cipher_crypt FAILED");
+            return AXIS2_FAILURE;
+        }
+        /*Free*/
+        oxs_buffer_free(decoded_buf, env);
+        decoded_buf = NULL;
+        AXIS2_FREE(env->allocator, decoded_data);
+        decoded_data = NULL;
+
+    }else{
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "Invalid operation type %d", oxs_ctx_get_operation(enc_ctx, env));
+        return AXIS2_FAILURE;
+    }
+
+    /*Free*/
+    AXIS2_FREE(env->allocator, iv);
+    iv = NULL;
+    openssl_cipher_ctx_free(oc_ctx, env);
+    oc_ctx = NULL;
+    return AXIS2_SUCCESS;
+}
+
+
+AXIS2_EXTERN  axis2_status_t AXIS2_CALL
+oxs_encryption_asymmetric_crypt(const axutil_env_t *env,
+                                oxs_asym_ctx_t *ctx,
+                                oxs_buffer_t *input,
+                                oxs_buffer_t *result)
+{
+    openssl_pkey_t *pkey = NULL;
+    oxs_asym_ctx_operation_t operation = -1;
+    axis2_status_t status = AXIS2_FAILURE;
+    axis2_char_t *password = NULL;
+    axis2_char_t *algorithm = NULL;
+    axis2_char_t *padding = NULL;
+
+    algorithm = oxs_asym_ctx_get_algorithm(ctx, env);
+    /* We support RSA v1.5 encryption only. If any other algorithm is specified, replace it with the proper one
+    if(0 != (axutil_strcmp(OXS_HREF_RSA_PKCS1, algorithm ))) {
+        oxs_asym_ctx_set_algorithm(ctx, env, OXS_HREF_RSA_PKCS1);
+    }*/
+
+    /*Set the proper padding for the algorithm*/
+    if(0 == (axutil_strcmp(OXS_HREF_RSA_OAEP, algorithm))){
+        padding = OPENSSL_RSA_PKCS1_OAEP_PADDING;
+    }else if(0 == (axutil_strcmp(OXS_HREF_RSA_PKCS1, algorithm))){
+        padding = OPENSSL_RSA_PKCS1_PADDING;
+    }
+
+    /*Load the key using key manager*/
+    password = oxs_asym_ctx_get_password(ctx, env);
+    status = oxs_key_mgr_load_key(env, ctx, password);
+    if(AXIS2_FAILURE == status){
+        return AXIS2_FAILURE;
+    }
+
+    /*Check for the operation and call appropriate method*/
+    operation = oxs_asym_ctx_get_operation(ctx, env);
+    if(   OXS_ASYM_CTX_OPERATION_PUB_ENCRYPT == operation ){
+        axis2_char_t *encoded_str = NULL;
+        oxs_x509_cert_t *x509_cert = NULL;
+        oxs_buffer_t *out_buf = NULL;
+        int enclen = -1;
+        int encodedlen = -1;
+        int ret = -1;
+
+        /*Operation is PUB ENCRYPT; Get the public key from the context*/
+        x509_cert = oxs_asym_ctx_get_certificate(ctx, env);
+        pkey = oxs_x509_cert_get_public_key(x509_cert, env);
+
+        /*Encrypt using the public key. Then base64 encode and populate the buffer */
+        out_buf = oxs_buffer_create(env);
+        enclen = openssl_rsa_pub_encrypt(env, pkey, padding, input, out_buf);
+        encodedlen = axutil_base64_encode_len(enclen);
+        encoded_str = AXIS2_MALLOC(env->allocator, encodedlen);
+        ret = axutil_base64_encode(encoded_str, (const char *)oxs_buffer_get_data(out_buf, env), enclen);
+        status = oxs_buffer_populate(result, env, (unsigned char*)axutil_strdup(env, encoded_str), encodedlen);
+
+        /*Free*/
+        oxs_buffer_free(out_buf, env);
+        out_buf = NULL;
+        AXIS2_FREE(env->allocator, encoded_str);
+        encoded_str = NULL;
+
+    }else if(OXS_ASYM_CTX_OPERATION_PRV_DECRYPT == operation ){
+        unsigned char  *decoded_encrypted_str = NULL;
+        oxs_buffer_t *dec_enc_buf = NULL;
+        int ret = -1;
+        int  declen = -1;
+
+        /*Operation id PRV DECRYPT; Get the private key from the context*/
+        pkey = oxs_asym_ctx_get_private_key(ctx, env);
+        /*Base64 decode first. Then do the decryption and populate the buffer*/
+        decoded_encrypted_str = AXIS2_MALLOC(env->allocator, axutil_base64_decode_len((char*)oxs_buffer_get_data(input, env)));
+        ret = axutil_base64_decode((char*)decoded_encrypted_str, (char*)oxs_buffer_get_data(input, env));
+        dec_enc_buf = oxs_buffer_create(env);
+        oxs_buffer_populate(dec_enc_buf, env, decoded_encrypted_str, ret);
+        declen = openssl_rsa_prv_decrypt(env, pkey, padding,  dec_enc_buf, result);
+
+        /*Free*/
+        AXIS2_FREE(env->allocator, decoded_encrypted_str);
+        decoded_encrypted_str = NULL;
+        oxs_buffer_free(dec_enc_buf, env);
+        dec_enc_buf = NULL;
+
+    }else{
+        /**/
+    }
+
+    return AXIS2_SUCCESS;
+}

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/error.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/error.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/error.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/error.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,96 @@
+/*
+ * 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_error.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <time.h>
+#include <axutil_log_default.h>
+#include <platforms/axutil_platform_auto_sense.h>
+
+/*Table to map error codes with the error message*/
+#define OXS_ERRORS_MAX_NUMBER 64
+static oxs_error_description oxs_errors_table[OXS_ERRORS_MAX_NUMBER] =
+    {
+        {OXS_ERROR_DEFAULT, "oxs defualt error"},
+        {OXS_ERROR_ENCRYPT_FAILED , "encryption failed" },
+        {OXS_ERROR_DECRYPT_FAILED , "decryption failed"},
+        {OXS_ERROR_INVALID_DATA , "invalid data"},
+        {OXS_ERROR_INVALID_SIZE , "invalid size"},
+        {OXS_ERROR_INVALID_FORMAT , "invalid format"},
+        {OXS_ERROR_ELEMENT_FAILED , "element failed"},
+        {OXS_ERROR_TRANSFORM_FAILED , "Transformation failed"},
+        {OXS_ERROR_SIGN_FAILED , "Signing failed"},
+        {OXS_ERROR_SIG_VERIFICATION_FAILED , "Signature verification failed"},
+    };
+
+AXIS2_EXTERN const char* AXIS2_CALL
+oxs_errors_get_msg_by_code(int code)
+{
+    const char* error_msg = NULL;
+    unsigned int i;
+
+    for (i = 0; (i < OXS_ERRORS_MAX_NUMBER) && (oxs_errors_get_msg(i)); ++i)
+    {
+        if (oxs_errors_get_code(i) == code)
+        {
+            error_msg = oxs_errors_get_msg(i);
+            break;
+        }
+    }
+    return error_msg;
+
+}
+
+AXIS2_EXTERN int AXIS2_CALL
+oxs_errors_get_code(unsigned int pos)
+{
+    if (pos < sizeof(oxs_errors_table) / sizeof(oxs_errors_table[0]))
+    {
+        return(oxs_errors_table[pos].code);
+    }
+    return(0);
+}
+
+AXIS2_EXTERN const char* AXIS2_CALL
+oxs_errors_get_msg(unsigned int pos)
+{
+    if (pos < sizeof(oxs_errors_table) / sizeof(oxs_errors_table[0]))
+    {
+        return(oxs_errors_table[pos].message);
+    }
+    return(NULL);
+}
+
+AXIS2_EXTERN void   AXIS2_CALL
+oxs_error(const axutil_env_t *env, const char* file, int line, const char* func,
+          int code, const char* msg, ...)
+{
+    const char* error_msg = NULL;
+    char value[AXIS2_LEN_VALUE+1];
+    va_list ap;
+
+    error_msg = oxs_errors_get_msg_by_code(code);
+
+    va_start(ap, msg);
+    AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, msg, ap);
+    va_end(ap);
+
+    AXIS2_LOG_INFO(env->log, "OXS ERROR [%s:%d in %s] %s , %s", file, line, func, error_msg, value);
+    printf("\nOXS ERROR [%s:%d in %s] %s , %s\n", file, line, func, error_msg, value);
+}

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/iv.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/iv.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/iv.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/iv.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,64 @@
+/*
+ * 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_iv.h>
+#include <oxs_buffer.h>
+#include <oxs_cipher.h>
+#include <oxs_error.h>
+#include <openssl_cipher_property.h>
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_iv_generate_for_algo(const axutil_env_t *env,
+                         axis2_char_t *key_algo)
+{
+    axis2_char_t* iv = NULL;
+    openssl_cipher_property_t *cprop = NULL;
+    int size;
+    cprop =  oxs_get_cipher_property_for_url(env, key_algo);
+    if (!cprop)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED,
+                  "openssl_get_cipher_property failed");
+        return NULL;
+    }
+    size = openssl_cipher_property_get_iv_size(cprop, env);
+
+    /*Here we have predefined IVs in the openssl_constants.
+      Get the correct one using the size*/
+
+    if (size == 8)
+    {
+        iv = OPENSSL_DEFAULT_IV8;
+    }
+    else if (size == 16)
+    {
+        iv = OPENSSL_DEFAULT_IV16;
+    }
+    else if (size == 24)
+    {
+        iv = OPENSSL_DEFAULT_IV24;
+    }
+    else
+    {
+        iv = OXS_IV_DEFAULT;/* i.e. OPENSSL_DEFAULT_IV16. Many ciphers have 16... mmm.. need a better way.. a TODO*/
+    }
+
+    return iv;
+}

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/key.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/key.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/key.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/key.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,237 @@
+/*
+ * 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_key.h>
+#include <oxs_buffer.h>
+#include <oxs_cipher.h>
+#include <oxs_error.h>
+#include <openssl_cipher_property.h>
+#include <openssl_util.h>
+
+struct oxs_key_t
+{
+    oxs_buffer_t *buf;
+    axis2_char_t *name;
+    int           usage;
+};
+
+/******************** end of function headers *****************/
+
+unsigned char *AXIS2_CALL
+oxs_key_get_data(
+    const oxs_key_t *key,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return oxs_buffer_get_data(key->buf, env);
+}
+
+axis2_char_t *AXIS2_CALL
+oxs_key_get_name(
+    const oxs_key_t *key,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return key->name;
+
+}
+
+int AXIS2_CALL
+oxs_key_get_size(
+    const oxs_key_t *key,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return oxs_buffer_get_size(key->buf, env);
+}
+
+int AXIS2_CALL
+oxs_key_get_usage(
+    const oxs_key_t *key,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return key->usage;
+}
+
+
+
+axis2_status_t AXIS2_CALL
+oxs_key_set_name(
+    oxs_key_t *key,
+    const axutil_env_t *env,
+    axis2_char_t *name)
+{
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE);
+
+    if (key->name)
+    {
+        AXIS2_FREE(env->allocator, key->name);
+        key->name = NULL;
+    }
+    key->name = axutil_strdup(env, name);
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+oxs_key_set_usage(
+    oxs_key_t *key,
+    const axutil_env_t *env,
+    int usage)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    key->usage = usage;
+    return AXIS2_SUCCESS;
+
+}
+
+
+
+AXIS2_EXTERN oxs_key_t *AXIS2_CALL
+oxs_key_create(const axutil_env_t *env)
+{
+    oxs_key_t *key = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+
+    key = (oxs_key_t*)AXIS2_MALLOC(env->allocator, sizeof(oxs_key_t));
+
+    if (!key)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    key->buf = NULL;
+    key->name = NULL;
+    key->usage = -1;
+
+    /*additionally we need to create a buffer to keep data*/
+    key->buf = oxs_buffer_create(env);
+
+    return key;
+}
+
+
+axis2_status_t AXIS2_CALL
+oxs_key_free(oxs_key_t *key,
+             const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    oxs_buffer_free(key->buf, env);
+    key->buf = NULL;
+    AXIS2_FREE(env->allocator,  key->name);
+    key->name = NULL;
+
+    AXIS2_FREE(env->allocator,  key);
+    key = NULL;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_key_populate(oxs_key_t *key,
+                 const axutil_env_t *env,
+                 unsigned char *data,
+                 axis2_char_t *name,
+                 int size,
+                 int usage)
+{
+    int ret;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    ret = oxs_key_set_name(key, env, name);
+    ret = oxs_key_set_usage(key, env, usage);
+
+    ret = oxs_buffer_populate(key->buf, env, data, size);
+
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+oxs_key_read_from_file(oxs_key_t *key,
+                       const axutil_env_t *env,
+                       axis2_char_t *file_name)
+{
+    oxs_buffer_t *buf = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+
+    buf = oxs_buffer_create(env);
+    status = oxs_buffer_read_file(buf, env, file_name);
+
+    status = oxs_key_populate(key, env,
+                              oxs_buffer_get_data(buf, env), file_name,
+                              oxs_buffer_get_size(buf, env), OXS_KEY_USAGE_NONE);
+
+    return status;
+
+}
+
+axis2_status_t AXIS2_CALL
+oxs_key_for_algo(oxs_key_t *key,
+                 const axutil_env_t *env,
+                 axis2_char_t *key_algo)
+{
+    oxs_buffer_t *key_buf = NULL;
+    openssl_cipher_property_t * cprop = NULL;
+    axis2_status_t ret = AXIS2_FAILURE;
+    int size;
+    unsigned char *temp_str = NULL;
+    int temp_int = 0;
+
+    cprop = (openssl_cipher_property_t *)oxs_get_cipher_property_for_url(env, key_algo);
+    if (!cprop)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED,
+                  "openssl_get_cipher_property failed");
+        return AXIS2_FAILURE;
+    }
+
+    size = openssl_cipher_property_get_key_size(cprop, env);
+
+    key_buf = oxs_buffer_create(env);
+    /*The actual key generation happens here*/
+    ret = generate_random_data(env, key_buf, size);
+    if (ret == AXIS2_FAILURE)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED,
+                  "generate_random_data failed");
+        return AXIS2_FAILURE;
+    }
+
+    temp_int = oxs_buffer_get_size(key_buf, env);
+    temp_str = oxs_buffer_get_data(key_buf, env);
+
+    ret = oxs_key_populate(key, env,
+                           oxs_buffer_get_data(key_buf, env), NULL,
+                           oxs_buffer_get_size(key_buf, env), OXS_KEY_USAGE_NONE);
+
+    /* Duplicate key data and free key_buf*/
+    return ret;
+}

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/key_mgr.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/key_mgr.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/key_mgr.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/key_mgr.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,296 @@
+/*
+ * 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_error.h>
+#include <oxs_key_mgr.h>
+#include <openssl_pem.h>
+
+
+
+/**
+ * Loads the key
+ * 1. If the key buffer is specified, Take that as the source.
+ * 2. Else if the key file name has specified, Take that as the source.
+ */
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_key_mgr_load_key(const axutil_env_t *env,
+                     oxs_asym_ctx_t *ctx,
+                     axis2_char_t *password)
+{
+    axis2_char_t *filename = NULL;
+    axis2_char_t *pem_buf = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+    openssl_x509_format_t format;
+    openssl_pkey_t *open_prvkey = NULL;
+    openssl_pkey_t *open_pubkey = NULL;
+    oxs_x509_cert_t *oxs_cert = NULL;
+
+    X509 *cert = NULL;
+    STACK_OF(X509) *ca = NULL;
+    EVP_PKEY *prvkey = NULL;
+    EVP_PKEY *pubkey = NULL;
+
+    /*If user has specified the certificate/private key directly we will extract the information from it.
+     * Else we will look for a file name to load the certificate/private key*/
+    pem_buf = oxs_asym_ctx_get_pem_buf(ctx, env);
+    if(pem_buf){
+        if( OXS_ASYM_CTX_OPERATION_PUB_ENCRYPT == oxs_asym_ctx_get_operation(ctx, env) ||
+                OXS_ASYM_CTX_OPERATION_PUB_DECRYPT == oxs_asym_ctx_get_operation(ctx, env)){
+            /*load certificate from buf*/
+            status = openssl_x509_load_from_buffer(env, pem_buf, &cert);
+        }else{
+            /*load private key from buf*/
+            status = openssl_pem_buf_read_pkey(env, pem_buf, password, OPENSSL_PEM_PKEY_TYPE_PRIVATE_KEY, &prvkey);
+            if(status == AXIS2_FAILURE){
+                prvkey = NULL;
+            }
+        }
+    }else{
+        /*pem_buf is NULL. So we have to fetch the key in a file*/
+        /*Get file to be loaded. Can be either in PEM or PKCS12 format*/
+        filename = oxs_asym_ctx_get_file_name(ctx, env);
+        if(!filename){
+            return AXIS2_FAILURE;
+        }
+
+        if(OXS_ASYM_CTX_FORMAT_PEM == oxs_asym_ctx_get_format(ctx, env)){
+            oxs_asym_ctx_operation_t operation ;
+            format = OPENSSL_X509_FORMAT_PEM;
+
+
+            /*First let's check if this is a file containing a certificate*/
+            status = openssl_x509_load_from_pem(env, filename,  &cert);
+
+            if((status == AXIS2_FAILURE) || (!cert)){/*>>*/
+                /*If we cannot get the certificate then the file might contain either a public key or a private key*/
+                /*The type depends on the operation*/
+                operation = oxs_asym_ctx_get_operation(ctx, env);
+
+                if((operation == OXS_ASYM_CTX_OPERATION_PRV_DECRYPT) || (operation == OXS_ASYM_CTX_OPERATION_PRV_ENCRYPT)){
+                    status = openssl_pem_read_pkey(env, filename, password, OPENSSL_PEM_PKEY_TYPE_PRIVATE_KEY, &prvkey);
+                    if(status == AXIS2_FAILURE){
+                        prvkey = NULL;
+                    }
+                } else if((operation == OXS_ASYM_CTX_OPERATION_PUB_DECRYPT) || (operation == OXS_ASYM_CTX_OPERATION_PUB_ENCRYPT)){
+                    status = openssl_pem_read_pkey(env, filename, password, OPENSSL_PEM_PKEY_TYPE_PUBLIC_KEY, &pubkey);
+                    if(status == AXIS2_FAILURE){
+                        pubkey = NULL;
+                    }
+                }
+            }/*>>*/
+        }else if(OXS_ASYM_CTX_FORMAT_PKCS12 == oxs_asym_ctx_get_format(ctx, env)){
+            format = OPENSSL_X509_FORMAT_PKCS12;
+            /*Here we load both key and the certificate*/
+            status = openssl_x509_load_from_pkcs12(env, filename, password, &cert, &prvkey, &ca);
+            if(AXIS2_FAILURE == status){
+                oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+                          "Error reading the certificate");
+                return AXIS2_FAILURE;
+            }
+        }
+
+    }/*end of pem_buf*/
+
+    /*Wht ever the way, right now we should have either the public key or the private key*/
+
+    /*If the prvkey is available, populate the openssl_pkey*/
+    if(prvkey){
+        open_prvkey = openssl_pkey_create(env);
+        openssl_pkey_populate(open_prvkey, env, prvkey, filename, OPENSSL_PKEY_TYPE_PRIVATE_KEY);
+        oxs_asym_ctx_set_private_key(ctx, env, open_prvkey);
+    }
+    /*If the public key is available populate*/
+    if(pubkey){
+        /*This scenario is not recommonded. This will be executed iff the file is a public key file in PEM format*/
+        open_pubkey = openssl_pkey_create(env);
+        openssl_pkey_populate(open_pubkey, env, pubkey, filename, OPENSSL_PKEY_TYPE_PUBLIC_KEY);
+        oxs_cert = oxs_x509_cert_create(env);
+        oxs_x509_cert_set_public_key(oxs_cert, env, open_pubkey);
+        oxs_asym_ctx_set_certificate(ctx, env, oxs_cert);
+    }
+    /*If the X509 certificate is available, populate oxs_x509_cert*/
+    if(cert){
+
+        /*Create certificate*/
+        oxs_cert = oxs_x509_cert_create(env);
+        /*And populate it*/
+        oxs_x509_cert_set_data(oxs_cert, env, openssl_x509_get_cert_data(env, cert));
+        oxs_x509_cert_set_date(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_VALID_TO ,cert));
+        oxs_x509_cert_set_issuer(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_ISSUER ,cert));
+        oxs_x509_cert_set_subject(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_SUBJECT ,cert));
+        oxs_x509_cert_set_fingerprint(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_FINGER,cert));
+        oxs_x509_cert_set_serial_number(oxs_cert, env, openssl_x509_get_serial(env, cert));
+        oxs_x509_cert_set_key_identifier(oxs_cert, env, openssl_x509_get_subject_key_identifier(env, cert));
+
+        /*Additionally we need to set the public key*/
+        openssl_x509_get_pubkey(env, cert, &pubkey);
+        open_pubkey = openssl_pkey_create(env);
+        openssl_pkey_populate(open_pubkey, env, pubkey, openssl_x509_get_info(env, OPENSSL_X509_INFO_FINGER,cert), OPENSSL_PKEY_TYPE_PUBLIC_KEY);
+        /*Set the public key to the x509 certificate*/
+        oxs_x509_cert_set_public_key(oxs_cert, env, open_pubkey);
+        /*Set the x509 certificate to the asym ctx*/
+        oxs_asym_ctx_set_certificate(ctx, env, oxs_cert);
+    }
+    /*If this fails to get anything return failure*/
+    if((!cert) && (!pubkey) && (!prvkey)){
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+                  "Error reading the key");
+        return AXIS2_FAILURE;
+    }
+    return AXIS2_SUCCESS;
+}
+
+/********************************************************************************************/
+/*These are new set of functions that break-up the complex logic in oxs_key_mgr_load_key()*/
+
+AXIS2_EXTERN openssl_pkey_t* AXIS2_CALL
+oxs_key_mgr_load_private_key_from_string(const axutil_env_t *env,
+        axis2_char_t *pem_string, /*in PEM format*/
+        axis2_char_t *password)
+{
+    openssl_pkey_t *open_prvkey = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+    EVP_PKEY *prvkey = NULL;
+
+    /*load private key from buf*/
+    status = openssl_pem_buf_read_pkey(env, pem_string, password, OPENSSL_PEM_PKEY_TYPE_PRIVATE_KEY, &prvkey);
+    /*Populate*/
+    if(prvkey){
+        open_prvkey = openssl_pkey_create(env);
+        openssl_pkey_populate(open_prvkey, env, prvkey, NULL, OPENSSL_PKEY_TYPE_PRIVATE_KEY);
+    }else{
+        return NULL;
+    }
+
+    return open_prvkey;
+}
+
+AXIS2_EXTERN openssl_pkey_t* AXIS2_CALL
+oxs_key_mgr_load_private_key_from_pem_file(const axutil_env_t *env,
+        axis2_char_t *filename,
+        axis2_char_t *password)
+{
+    openssl_pkey_t *open_prvkey = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+    EVP_PKEY *prvkey = NULL;
+
+    /*Read EVP_PKEY*/
+    status = openssl_pem_read_pkey(env, filename, password, OPENSSL_PEM_PKEY_TYPE_PRIVATE_KEY, &prvkey);
+
+    /*Populate*/
+    if(prvkey){
+        open_prvkey = openssl_pkey_create(env);
+        openssl_pkey_populate(open_prvkey, env, prvkey, filename, OPENSSL_PKEY_TYPE_PRIVATE_KEY);
+    }else{
+        return NULL;
+    }
+
+    return open_prvkey;
+}
+
+/*Private function to convert X509* -> oxs_x509_cert_t* */
+static oxs_x509_cert_t*
+oxs_key_mgr_convert_to_x509(const axutil_env_t *env,
+                            X509 *cert)
+{
+    oxs_x509_cert_t *oxs_cert = NULL;
+
+    if(cert){
+        EVP_PKEY *pubkey = NULL;
+        openssl_pkey_t *open_pubkey = NULL;
+
+        oxs_cert = oxs_x509_cert_create(env);
+
+        oxs_x509_cert_set_data(oxs_cert, env, openssl_x509_get_cert_data(env, cert));
+        oxs_x509_cert_set_date(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_VALID_TO ,cert));
+        oxs_x509_cert_set_issuer(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_ISSUER ,cert));
+        oxs_x509_cert_set_subject(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_SUBJECT ,cert));
+        oxs_x509_cert_set_fingerprint(oxs_cert, env, openssl_x509_get_info(env, OPENSSL_X509_INFO_FINGER,cert));
+        oxs_x509_cert_set_serial_number(oxs_cert, env, openssl_x509_get_serial(env, cert));
+        oxs_x509_cert_set_key_identifier(oxs_cert, env, openssl_x509_get_subject_key_identifier(env, cert));
+
+        /*Additionally we need to set the public key*/
+        openssl_x509_get_pubkey(env, cert, &pubkey);
+        open_pubkey = openssl_pkey_create(env);
+        openssl_pkey_populate(open_pubkey, env, pubkey, openssl_x509_get_info(env, OPENSSL_X509_INFO_FINGER,cert), OPENSSL_PKEY_TYPE_PUBLIC_KEY);
+        /*Set the public key to the x509 certificate*/
+        oxs_x509_cert_set_public_key(oxs_cert, env, open_pubkey);
+    }
+
+    return oxs_cert;
+}
+
+AXIS2_EXTERN oxs_x509_cert_t* AXIS2_CALL
+oxs_key_mgr_load_x509_cert_from_pem_file(const axutil_env_t *env,
+        axis2_char_t *filename)
+{
+    X509 *cert = NULL;
+    oxs_x509_cert_t *oxs_cert = NULL;
+    openssl_x509_load_from_pem(env, filename,  &cert);
+
+    oxs_cert = oxs_key_mgr_convert_to_x509(env, cert);
+
+    return oxs_cert;
+}
+
+AXIS2_EXTERN oxs_x509_cert_t* AXIS2_CALL
+oxs_key_mgr_load_x509_cert_from_string(const axutil_env_t *env,
+                                       axis2_char_t *pem_string)
+{
+    X509 *cert = NULL;
+    oxs_x509_cert_t *oxs_cert = NULL;
+    openssl_x509_load_from_buffer(env, pem_string, &cert);
+
+    oxs_cert = oxs_key_mgr_convert_to_x509(env, cert);
+
+    return oxs_cert;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_key_mgr_read_pkcs12_key_store(const axutil_env_t *env,
+                                  axis2_char_t *filename,
+                                  axis2_char_t *password,
+                                  oxs_x509_cert_t **cert,
+                                  openssl_pkey_t **prv_key)
+{
+    X509 *c = NULL;
+    STACK_OF(X509) *ca = NULL;
+    EVP_PKEY *pkey = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+
+    status = openssl_x509_load_from_pkcs12(env, filename, password, &c, &pkey, &ca);
+    if(AXIS2_FAILURE == status){
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+                  "Error reading the PKCS12 Key Store");
+        return AXIS2_FAILURE;
+    }
+    if(*prv_key){
+        if(pkey){
+            *prv_key = openssl_pkey_create(env);
+            openssl_pkey_populate(*prv_key, env, pkey, filename, OPENSSL_PKEY_TYPE_PRIVATE_KEY);
+        }
+    }
+
+    if(*cert){
+        if(c){
+            *cert = oxs_key_mgr_convert_to_x509(env, c);
+        }
+    }
+    return AXIS2_SUCCESS;
+}

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/Makefile.am?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/Makefile.am (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/Makefile.am Thu Sep  6 03:48:44 2007
@@ -0,0 +1,12 @@
+noinst_LTLIBRARIES = libomopenssl.la
+libomopenssl_la_SOURCES = cipher_ctx.c crypt.c rsa.c pkey.c util.c cipher_property.c digest.c x509.c pkcs12.c pem.c sign.c
+
+libomopenssl_la_LIBADD  = -lssl\
+				${AXIS2C_HOME}/include \
+    		-lcrypto
+
+INCLUDES = -I$(top_builddir)/include \
+			-I ../../../../util/include \
+			-I ../../../../include \
+			-I ../../../../axiom/include \
+			@AXIS2INC@

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_ctx.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_ctx.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_ctx.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_ctx.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,215 @@
+/*
+ * 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_cipher_ctx.h>
+#include <openssl_constants.h>
+#include <openssl_cipher_property.h>
+#include <oxs_error.h>
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+#include <openssl_util.h>
+
+
+struct openssl_cipher_ctx_t
+{
+    const EVP_CIPHER*   cipher;
+    oxs_key_t *key;
+    axis2_char_t  *iv;
+    axis2_char_t  *pad;
+};
+
+
+/******************* end of function headers ******************************/
+AXIS2_EXTERN openssl_cipher_ctx_t *AXIS2_CALL
+openssl_cipher_ctx_create(const axutil_env_t *env)
+{
+    openssl_cipher_ctx_t *ctx = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+
+    ctx = (openssl_cipher_ctx_t *)AXIS2_MALLOC(env->allocator, sizeof(openssl_cipher_ctx_t));
+    if (!ctx)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    ctx->cipher  = NULL;
+    ctx->key  = NULL;
+    ctx->iv  = NULL;
+    ctx->pad  = NULL;
+
+    return ctx;
+}
+
+
+/* public functions*/
+axis2_status_t AXIS2_CALL
+openssl_cipher_ctx_free(openssl_cipher_ctx_t *ctx,
+                        const axutil_env_t *env
+                       )
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (ctx->iv)
+    {
+        AXIS2_FREE(env->allocator, ctx->iv);
+        ctx->iv = NULL;
+    }
+
+    if (ctx->pad)
+    {
+        AXIS2_FREE(env->allocator, ctx->pad);
+        ctx->pad = NULL;
+    }
+
+    AXIS2_FREE(env->allocator,  ctx);
+    ctx = NULL;
+
+    return AXIS2_SUCCESS;
+}
+
+const EVP_CIPHER* AXIS2_CALL
+openssl_cipher_ctx_get_cipher(openssl_cipher_ctx_t *ctx,
+                              const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->cipher ;
+}
+
+oxs_key_t *AXIS2_CALL
+openssl_cipher_ctx_get_key(openssl_cipher_ctx_t *ctx,
+                           const axutil_env_t *env
+                          )
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->key ;
+}
+
+axis2_char_t *AXIS2_CALL
+openssl_cipher_ctx_get_iv(openssl_cipher_ctx_t *ctx,
+                          const axutil_env_t *env
+                         )
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->iv ;
+}
+
+axis2_char_t *AXIS2_CALL
+openssl_cipher_ctx_get_pad(openssl_cipher_ctx_t *ctx,
+                           const axutil_env_t *env
+                          )
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return ctx->pad;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_ctx_set_cipher(openssl_cipher_ctx_t *ctx,
+                              const axutil_env_t *env,
+                              const EVP_CIPHER *cipher
+                             )
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    /*if (ctx->cipher){
+        AXIS2_FREE(env->allocator, ctx->cipher);
+        ctx->cipher = NULL;
+    }
+    */
+    ctx->cipher = cipher;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_ctx_set_key(openssl_cipher_ctx_t *ctx,
+                           const axutil_env_t *env,
+                           oxs_key_t *key
+                          )
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, key, AXIS2_FAILURE);
+
+    if (ctx->key)
+    {
+        oxs_key_free(ctx->key, env);
+        ctx->key = NULL;
+    }
+    ctx->key = key ;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_ctx_set_iv(openssl_cipher_ctx_t *ctx,
+                          const axutil_env_t *env,
+                          axis2_char_t *iv
+                         )
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, iv, AXIS2_FAILURE);
+
+    if (ctx->iv)
+    {
+        AXIS2_FREE(env->allocator, ctx->iv);
+        ctx->iv = NULL;
+    }
+    ctx->iv = axutil_strdup(env, iv);
+
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_ctx_set_pad(openssl_cipher_ctx_t *ctx,
+                           const axutil_env_t *env,
+                           axis2_char_t *pad
+                          )
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, pad, AXIS2_FAILURE);
+
+    if (ctx->pad)
+    {
+        AXIS2_FREE(env->allocator, ctx->pad);
+        ctx->pad = NULL;
+    }
+    ctx->pad = axutil_strdup(env, pad);
+
+    return AXIS2_SUCCESS;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_property.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_property.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_property.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/cipher_property.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,249 @@
+/*
+ * 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_cipher_property.h>
+#include <openssl_constants.h>
+#include <oxs_error.h>
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+
+
+struct openssl_cipher_property_t
+{
+    EVP_CIPHER                  *cipher;
+    axis2_char_t                *name;
+    axis2_char_t                *url;
+    int                         key_size;
+    int                         block_size;
+    int                         iv_size;
+};
+
+
+EVP_CIPHER * AXIS2_CALL
+openssl_cipher_property_get_cipher(
+    const openssl_cipher_property_t *cprop,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return cprop->cipher;
+}
+
+axis2_char_t * AXIS2_CALL
+openssl_cipher_property_get_name(
+    const openssl_cipher_property_t *cprop,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return cprop->name;
+}
+
+axis2_char_t * AXIS2_CALL
+openssl_cipher_property_get_url(
+    const openssl_cipher_property_t *cprop,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return cprop->url;
+}
+
+
+int AXIS2_CALL
+openssl_cipher_property_get_key_size(
+    const openssl_cipher_property_t *cprop,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return cprop->key_size;
+}
+
+int AXIS2_CALL
+openssl_cipher_property_get_block_size(
+    const openssl_cipher_property_t *cprop,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return cprop->block_size;
+}
+
+int AXIS2_CALL
+openssl_cipher_property_get_iv_size(
+    const openssl_cipher_property_t *cprop,
+    const axutil_env_t *env)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return cprop->iv_size;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_set_cipher(
+    openssl_cipher_property_t *cprop,
+    const axutil_env_t *env,
+    EVP_CIPHER *cipher)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (cprop->cipher)
+    {
+        AXIS2_FREE(env->allocator, cprop->cipher);
+        cprop->cipher = NULL;
+    }
+    cprop->cipher = cipher;
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_set_name(
+    openssl_cipher_property_t *cprop,
+    const axutil_env_t *env,
+    axis2_char_t *name)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE);
+
+
+    if (cprop->name)
+    {
+        AXIS2_FREE(env->allocator, cprop->name);
+        cprop->name = NULL;
+    }
+    cprop->name = axutil_strdup(env, name);
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_set_url(
+    openssl_cipher_property_t *cprop,
+    const axutil_env_t *env,
+    axis2_char_t *url)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, url, AXIS2_FAILURE);
+
+
+    if (cprop->url)
+    {
+        AXIS2_FREE(env->allocator, cprop->url);
+        cprop->url = NULL;
+    }
+    cprop->url = axutil_strdup(env, url);
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_set_key_size(
+    openssl_cipher_property_t *cprop,
+    const axutil_env_t *env,
+    int   key_size)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    cprop->key_size = key_size;
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_set_block_size(
+    openssl_cipher_property_t *cprop,
+    const axutil_env_t *env,
+    int  block_size)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    cprop->block_size = block_size;
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_set_iv_size(
+    openssl_cipher_property_t *cprop,
+    const axutil_env_t *env,
+    int   iv_size)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    cprop->iv_size = iv_size;
+    return AXIS2_SUCCESS;
+}
+
+
+
+AXIS2_EXTERN openssl_cipher_property_t *AXIS2_CALL
+openssl_cipher_property_create(const axutil_env_t *env)
+{
+    openssl_cipher_property_t *cprop = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+
+    cprop = (openssl_cipher_property_t *)AXIS2_MALLOC(env->allocator, sizeof(openssl_cipher_property_t));
+    if (!cprop)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    cprop->cipher = NULL;
+    cprop->name = NULL;
+    cprop->url = NULL;
+    cprop->key_size = -1;
+    cprop->block_size = -1;
+    cprop->iv_size = -1;
+
+    return cprop;
+}
+
+
+axis2_status_t AXIS2_CALL
+openssl_cipher_property_free(openssl_cipher_property_t * cprop, const axutil_env_t *env)
+{
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+
+    if (cprop->cipher)
+    {
+        AXIS2_FREE(env->allocator, cprop->cipher);
+        cprop->cipher = NULL;
+    }
+
+    if (cprop->name)
+    {
+        AXIS2_FREE(env->allocator, cprop->name);
+        cprop->name = NULL;
+    }
+
+    if (cprop->url)
+    {
+        AXIS2_FREE(env->allocator, cprop->url);
+        cprop->url = NULL;
+    }
+
+    AXIS2_FREE(env->allocator,  cprop);
+    cprop = NULL;
+
+    return AXIS2_SUCCESS;
+}
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/crypt.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/crypt.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/crypt.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/crypt.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_buffer.h>
+#include <oxs_key.h>
+#include <oxs_error.h>
+#include <openssl_cipher_ctx.h>
+#include <openssl_crypt.h>
+#include <openssl/rand.h>
+
+#define BUFSIZE 64
+
+AXIS2_EXTERN int AXIS2_CALL
+openssl_bc_crypt(const axutil_env_t *env,
+                 openssl_cipher_ctx_t *oc_ctx,
+                 oxs_buffer_t *input_buf,
+                 oxs_buffer_t *output_buf,
+                 int encrypt)
+{
+    EVP_CIPHER_CTX ctx ;
+    oxs_key_t *okey = NULL;
+
+    unsigned char iv[EVP_MAX_IV_LENGTH];
+    unsigned char key[EVP_MAX_KEY_LENGTH];
+    int ret =0, iv_length =0, block_length =0;
+    int last = 0;
+    axis2_status_t status = AXIS2_FAILURE;
+
+    /********************************Initialize*****************************************************/
+
+    iv_length = EVP_CIPHER_iv_length(openssl_cipher_ctx_get_cipher(oc_ctx, env));
+
+    /*Get the IV. If encrypt, we need to generate the IV else we need to get it from the input buffer*/
+    if(encrypt){
+        /*Generate IV*/
+        ret = RAND_bytes(iv, iv_length);
+        /*IV to the output*/
+        status = oxs_buffer_append(output_buf, env, iv, iv_length);
+    }else{ /*Decrypt*/
+        /*If data is less than the IV its an error*/
+        if(oxs_buffer_get_size(input_buf, env) < iv_length){
+            return -1;
+        }
+        /*Copy IV from the inbuf to our buffer*/
+        memcpy(iv, oxs_buffer_get_data(input_buf, env), iv_length);
+        /*And remove from input*/
+        status = oxs_buffer_remove_head (input_buf, env, iv_length);
+    }
+    /*Get key*/
+    okey = openssl_cipher_ctx_get_key(oc_ctx, env);
+    memcpy(key,  oxs_key_get_data(okey, env), oxs_key_get_size(okey, env));
+
+    /*Set the IV */
+    ret = EVP_CipherInit(&ctx, (EVP_CIPHER *)openssl_cipher_ctx_get_cipher(oc_ctx, env), key, iv, encrypt);
+#ifndef OXS_OPENSSL_096
+    EVP_CIPHER_CTX_set_padding(&ctx, 0);
+#endif
+
+    /*Get the block length of the cipher*/
+    block_length = EVP_CIPHER_block_size((EVP_CIPHER *)openssl_cipher_ctx_get_cipher(oc_ctx, env));
+
+    /*********************************Update***********************************************************/
+    for(;;){/*Loop untill all the data are encrypted*/
+        unsigned char *out_buf = NULL;
+        int  in_size =0, out_size =0, fixed=0, out_length = 0;
+
+    if (0 == oxs_buffer_get_size(input_buf, env)) {
+            last = 1;
+            break; /*Quit loop if NO DATA!!! */
+        }
+
+        /*If the amnt of data available is greater than the buffer size, we limit it to buffer size */
+        if(oxs_buffer_get_size(input_buf, env) > BUFSIZE){
+            in_size = BUFSIZE;
+        }else{
+            in_size = oxs_buffer_get_size(input_buf, env);
+        }
+
+        out_size = oxs_buffer_get_size(output_buf, env);
+
+        /*Set the output buffer size*/
+        status = oxs_buffer_set_max_size(output_buf, env, out_size + in_size + block_length);
+
+        out_buf = oxs_buffer_get_data(output_buf, env) + out_size;        /*position to write*/
+
+#ifndef OXS_OPENSSL_096
+        /*If decrypt, we copy the final data to the out_buf of size block_length*/
+        if(!ctx.encrypt) {
+            if(ctx.final_used) {
+                memcpy(out_buf, ctx.final, block_length);
+                out_buf += block_length;
+                fixed = 1;
+        }else {
+            fixed = 0;
+        }
+    }
+#endif
+    /* encrypt or decrypt */
+    ret = EVP_CipherUpdate(&ctx, out_buf, &out_length, oxs_buffer_get_data(input_buf, env), in_size);
+
+#ifndef OXS_OPENSSL_096
+        /*If decrypt, we copy data from the out_buf to the ctx.final*/
+        if(!ctx.encrypt) {
+            if (block_length > 1 && !ctx.buf_len) {
+                out_length -= block_length;
+                ctx.final_used = 1;
+                memcpy(ctx.final, &out_buf[out_length], block_length);
+            } else {
+                ctx.final_used = 0;
+            }
+            if (fixed) {
+                out_length += block_length;
+            }
+        }
+#endif
+        /* set correct output buffer size */
+        status = oxs_buffer_set_size(output_buf, env, out_size + out_length);
+        if(AXIS2_FAILURE == status){
+            return -1;
+        }
+        /* remove the processed block from input */
+        status = oxs_buffer_remove_head(input_buf, env, in_size);
+        if(AXIS2_FAILURE == status){
+            return -1;
+        }
+
+    }/*End of for loop*/
+
+    /********************************Finalize*****************************************************/
+
+    /* by now there should be no input */
+    if(last == 1){
+        unsigned char pad[EVP_MAX_BLOCK_LENGTH];
+        unsigned char *out_buf = NULL;
+        int out_size = 0,  out_length = 0, out_length2 = 0;
+
+        out_size = oxs_buffer_get_size(output_buf, env);
+        status = oxs_buffer_set_max_size(output_buf,  env, out_size + 2 * block_length);
+        out_buf = oxs_buffer_get_data(output_buf, env)  + out_size;/*position to write*/
+#ifndef OXS_OPENSSL_096
+        if(encrypt){
+            int pad_length;
+            pad_length = block_length - ctx.buf_len;
+            /* generate random padding */
+            if(pad_length > 1) {
+                ret = RAND_bytes(pad, pad_length - 1);
+            }
+            pad[pad_length - 1] = pad_length;
+            /* write padding */
+            ret = EVP_CipherUpdate(&ctx, out_buf, &out_length, pad, pad_length);
+            out_buf += out_length;
+        }
+#endif
+        /* finalize  */
+        ret = EVP_CipherFinal(&ctx, out_buf, &out_length2);
+#ifndef OXS_OPENSSL_096
+        if(!encrypt){
+            if(block_length > 1) {
+                out_length2 = block_length - ctx.final[block_length - 1];
+                if(out_length2 > 0) {
+                    memcpy(out_buf, ctx.final, out_length2);
+                } else if(out_length2 < 0) {
+                    return(-1);
+                }
+            }
+        }
+#endif
+        /* set correct output buffer size */
+        status = oxs_buffer_set_size(output_buf, env, out_size + out_length + out_length2);
+
+        EVP_CIPHER_CTX_cleanup(&ctx);
+        /*return the length of the outputbuf*/
+        return out_size + out_length + out_length2;
+    }else{
+        return -1;
+    }
+
+}
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/digest.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/digest.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/digest.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/digest.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,66 @@
+/*
+ * 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 <openssl/sha.h>
+#include <openssl/md5.h>
+#include <openssl_digest.h>
+#include <axutil_base64.h>
+#include <axis2_util.h>
+
+#define SIZE_HASH 32
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+openssl_sha1(const axutil_env_t *env,
+             axis2_char_t *input,
+             int length)
+{
+    SHA_CTX c ;
+    unsigned char md[SHA_DIGEST_LENGTH];
+    axis2_char_t* encoded_str = NULL;
+
+    SHA1_Init(&c);
+    SHA1_Update(&c,(unsigned char*)input,length);
+    SHA1_Final(md,&c);
+
+    encoded_str = AXIS2_MALLOC(env->allocator, axutil_base64_encode_len(SIZE_HASH));
+    axutil_base64_encode(encoded_str, (char*)md, SHA_DIGEST_LENGTH);
+
+    /*AXIS2_LOG_INFO(env->log, "[openssl][sha1-output]\n\n%s\n\n", encoded_str);*/
+    return encoded_str;
+}
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+openssl_md5(const axutil_env_t *env,
+            axis2_char_t *input,
+            int length)
+{
+    MD5_CTX ctx;
+    unsigned char md[MD5_DIGEST_LENGTH];
+    axis2_char_t* encoded_str = NULL;
+
+    MD5_Init(&ctx);
+    MD5_Update(&ctx, (unsigned char*)input,length);
+    MD5_Final(md, &ctx);
+
+    encoded_str = AXIS2_MALLOC(env->allocator, MD5_DIGEST_LENGTH);
+    axutil_base64_encode(encoded_str, (char*)md, MD5_DIGEST_LENGTH);
+
+    return encoded_str;
+}
+
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pem.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pem.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pem.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pem.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,120 @@
+/*
+ * 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_pem.h>
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_pem_buf_read_pkey(const axutil_env_t *env,
+                          axis2_char_t *b64_encoded_buf,
+                          axis2_char_t *password,
+                          openssl_pem_pkey_type_t type,
+                          EVP_PKEY **pkey)
+{
+    unsigned char *buff = NULL;
+    BIO *bio = NULL;
+    int ilen = 0;
+
+    /*First we need to base64 decode*/
+    EVP_ENCODE_CTX ctx;
+    int len = 0;
+    int ret = 0;
+    int decode_len = 0;
+
+    decode_len = axutil_base64_decode_len(b64_encoded_buf);
+    buff = AXIS2_MALLOC(env->allocator, decode_len + 1000);
+
+    ilen = axutil_strlen(b64_encoded_buf);
+    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 ((bio = BIO_new_mem_buf(buff, ilen)) == NULL)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+                  "BIO memeory allocation failure");
+        return AXIS2_FAILURE;
+    }
+    /*Load*/
+    if(OPENSSL_PEM_PKEY_TYPE_PUBLIC_KEY == type){
+        *pkey = d2i_PUBKEY_bio(bio, NULL);
+    }else{
+        *pkey = d2i_PrivateKey_bio(bio, NULL);
+    }
+
+    /*Free*/
+    BIO_free(bio);
+    bio = NULL;
+    AXIS2_FREE(env->allocator, buff);
+    buff = NULL;
+
+    if(!*pkey){
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+                  "private key is NULL");
+        return AXIS2_FAILURE;
+    }
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_pem_read_pkey(const axutil_env_t *env,
+                      axis2_char_t *filename,
+                      axis2_char_t *password,
+                      openssl_pem_pkey_type_t type,
+                      EVP_PKEY **pkey)
+{
+    BIO *bio;
+    int ret;
+
+    bio = BIO_new_file(filename, "r");
+
+    if(type == OPENSSL_PEM_PKEY_TYPE_PRIVATE_KEY){
+        *pkey = PEM_read_bio_PrivateKey(bio, NULL, 0 , password);
+    }else if(type == OPENSSL_PEM_PKEY_TYPE_PUBLIC_KEY){
+        *pkey = PEM_read_bio_PUBKEY(bio, NULL, 0 , password);
+    }else{/*Type unknown*/
+        /*Try to read the prv key first*/
+        *pkey = PEM_read_bio_PrivateKey(bio, NULL, 0 , password);
+        if (!*pkey)
+        {
+            /*If prv key is not found then read the public key*/
+            ret  = BIO_reset(bio);
+            *pkey = PEM_read_bio_PUBKEY(bio, NULL, 0 , password);
+        }
+    }
+
+    ret = BIO_reset(bio);
+    ret = BIO_free(bio);
+    bio = NULL;
+    if(!*pkey){
+        return AXIS2_FAILURE;
+    }
+    return AXIS2_SUCCESS;
+}
+
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkcs12.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkcs12.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkcs12.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkcs12.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,80 @@
+/*
+ * 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_error.h>
+#include <openssl_pkcs12.h>
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_pkcs12_load(const axutil_env_t *env,
+                    axis2_char_t *filename,
+                    PKCS12 **p12)
+{
+    FILE *fp = NULL;
+
+    SSLeay_add_all_algorithms();
+    ERR_load_crypto_strings();
+    if (!(fp = fopen(filename, "rb"))) {
+        fprintf(stderr, "Error opening file %s\n", filename);
+        return AXIS2_FAILURE;
+    }
+    /*Load pkcs store*/
+    *p12 = d2i_PKCS12_fp(fp, NULL);
+    fclose (fp);
+
+    if (!p12) {
+        fprintf(stderr, "Error reading PKCS#12 file %s\n", filename);
+        ERR_print_errors_fp(stderr);
+        return AXIS2_FAILURE;
+    }
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_pkcs12_parse(const axutil_env_t *env,
+                     axis2_char_t *password ,
+                     PKCS12 *p12,
+                     EVP_PKEY **prvkey,
+                     X509 **cert,
+                     STACK_OF(X509) **ca)
+{
+    /*Parse the pkcs store*/
+    if (!PKCS12_parse(p12, password, prvkey, cert, ca)) {
+        fprintf(stderr, "Error parsing PKCS#12 file\n");
+        ERR_print_errors_fp(stderr);
+        return AXIS2_FAILURE;
+    }
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+openssl_pkcs12_free(const axutil_env_t *env,
+                    PKCS12 *p12)
+{
+
+    PKCS12_free(p12);
+    return AXIS2_SUCCESS;
+}
+
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkey.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkey.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkey.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/openssl/pkey.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,254 @@
+/*
+ * 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_pkey.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;
+}
+*/
+struct openssl_pkey_t
+{
+    EVP_PKEY *key;
+    axis2_char_t *name;
+    int type;
+};
+
+
+AXIS2_EXTERN openssl_pkey_t *AXIS2_CALL
+openssl_pkey_create(const axutil_env_t *env)
+{
+    openssl_pkey_t * pkey = NULL;
+    AXIS2_ENV_CHECK(env, NULL);
+    pkey = (openssl_pkey_t *)AXIS2_MALLOC(env->allocator, sizeof(openssl_pkey_t));
+    if (!pkey)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    pkey->key   = NULL;
+    pkey->name = NULL ;
+    pkey->type = OPENSSL_PKEY_TYPE_UNKNOWN;
+
+    return pkey;
+}
+
+
+EVP_PKEY *AXIS2_CALL
+openssl_pkey_get_key(
+    const openssl_pkey_t *pkey,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return pkey->key ;
+}
+
+axis2_char_t *AXIS2_CALL
+openssl_pkey_get_name(
+    const openssl_pkey_t *pkey,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return pkey->name ;
+
+}
+int AXIS2_CALL
+openssl_pkey_get_size(
+    const openssl_pkey_t *pkey,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return sizeof(pkey->key) ;
+}
+int AXIS2_CALL
+openssl_pkey_get_type(
+    const openssl_pkey_t *pkey,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return pkey->type ;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_pkey_set_key(
+    openssl_pkey_t *pkey,
+    const axutil_env_t *env,
+    EVP_PKEY *key
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (pkey->key)
+    {
+        AXIS2_FREE(env->allocator, pkey->key);
+        pkey->key = NULL;
+    }
+
+    pkey->key = key;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_pkey_set_name(
+    openssl_pkey_t *pkey,
+    const axutil_env_t *env,
+    axis2_char_t *name
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE);
+    if (pkey->name)
+    {
+        AXIS2_FREE(env->allocator, pkey->name);
+        pkey->name = NULL;
+    }
+
+    pkey->name = axutil_strdup(env, name);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_pkey_set_type(
+    openssl_pkey_t *pkey,
+    const axutil_env_t *env,
+    int type
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    pkey->type = type;
+
+    return AXIS2_SUCCESS;
+
+}
+
+axis2_status_t AXIS2_CALL
+openssl_pkey_load(
+    openssl_pkey_t *pkey,
+    const axutil_env_t *env,
+    axis2_char_t *filename,
+    axis2_char_t *password
+)
+{
+    EVP_PKEY *pk = NULL;
+    BIO *bio;
+    int type = OPENSSL_PKEY_TYPE_UNKNOWN;
+    int ret ;
+    axis2_status_t status = AXIS2_FAILURE;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    bio = BIO_new_file(filename, "rb");
+    /*Try to read the prv key first*/
+    pk = PEM_read_bio_PrivateKey(bio, NULL, 0 , password);
+    if (!pk)
+    {
+        /*If prv key is not found then read the public key*/
+        ret  = BIO_reset(bio);
+        pk = PEM_read_bio_PUBKEY(bio, NULL, 0 , password);
+        if (!pk)
+        {
+            /*If there is no key by now its an error*/
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_ENCRYPT_FAILED,
+                      "Cannot load key from %s", filename);
+
+            return AXIS2_FAILURE;
+        }
+        type = OPENSSL_PKEY_TYPE_PUBLIC_KEY;
+    }
+    else
+    {
+        type = OPENSSL_PKEY_TYPE_PRIVATE_KEY;
+    }
+
+    status = openssl_pkey_populate(pkey, env,  pk, filename, type) ;
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_pkey_populate(
+    openssl_pkey_t *pkey,
+    const axutil_env_t *env,
+    EVP_PKEY *key,
+    axis2_char_t *name,
+    int type
+)
+{
+    axis2_status_t status = AXIS2_FAILURE;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    status = openssl_pkey_set_key(pkey, env, key);
+    status = openssl_pkey_set_name(pkey, env, name);
+    status = openssl_pkey_set_type(pkey, env, type);
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+openssl_pkey_free(
+    openssl_pkey_t *pkey,
+    const axutil_env_t *env
+)
+{
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (pkey->key)
+    {
+        AXIS2_FREE(env->allocator, pkey->key);
+        pkey->key = NULL;
+    }
+    if (pkey->name)
+    {
+        AXIS2_FREE(env->allocator, pkey->name);
+        pkey->name = NULL;
+    }
+
+    AXIS2_FREE(env->allocator, pkey);
+    pkey = NULL;
+
+    return AXIS2_SUCCESS;
+}
+
+
+
+