You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ka...@apache.org on 2007/02/09 13:01:27 UTC
svn commit: r505263 - in /webservices/axis2/trunk/c/rampart: include/
src/omxmlsec/ test/omxmlsec/
Author: kaushalye
Date: Fri Feb 9 04:01:25 2007
New Revision: 505263
URL: http://svn.apache.org/viewvc?view=rev&rev=505263
Log:
Adding XML Signature support in OMXMLSecurity
Added:
webservices/axis2/trunk/c/rampart/include/oxs_signature.h
webservices/axis2/trunk/c/rampart/src/omxmlsec/signature.c
Modified:
webservices/axis2/trunk/c/rampart/include/oxs_sign_ctx.h
webservices/axis2/trunk/c/rampart/include/oxs_token_signature.h
webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am
webservices/axis2/trunk/c/rampart/src/omxmlsec/key_mgr.c
webservices/axis2/trunk/c/rampart/src/omxmlsec/sign_ctx.c
webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c
webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c
Modified: webservices/axis2/trunk/c/rampart/include/oxs_sign_ctx.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/include/oxs_sign_ctx.h?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/include/oxs_sign_ctx.h (original)
+++ webservices/axis2/trunk/c/rampart/include/oxs_sign_ctx.h Fri Feb 9 04:01:25 2007
@@ -27,6 +27,8 @@
#include <axis2_defines.h>
#include <axis2_env.h>
#include <axiom_node.h>
+#include <oxs_x509_cert.h>
+#include <openssl_pkey.h>
#ifdef __cplusplus
extern "C"
@@ -62,6 +64,21 @@
const oxs_sign_ctx_t *sign_ctx,
const axis2_env_t *env);
+oxs_x509_cert_t *AXIS2_CALL
+oxs_sign_ctx_get_certificate(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env);
+
+openssl_pkey_t *AXIS2_CALL
+oxs_sign_ctx_get_private_key(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env);
+
+openssl_pkey_t *AXIS2_CALL
+oxs_sign_ctx_get_public_key(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env);
+
/**********************Setter functions******************************************/
axis2_status_t AXIS2_CALL
oxs_sign_ctx_set_sign_mtd_algo(
@@ -81,6 +98,23 @@
const axis2_env_t *env,
axis2_array_list_t *sign_parts);
+axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_certificate(
+ oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env,
+ oxs_x509_cert_t *certificate);
+
+axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_private_key(
+ oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env,
+ openssl_pkey_t *prv_key);
+
+axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_public_key(
+ oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env,
+ openssl_pkey_t *pub_key);
/** @} */
Added: webservices/axis2/trunk/c/rampart/include/oxs_signature.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/include/oxs_signature.h?view=auto&rev=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/include/oxs_signature.h (added)
+++ webservices/axis2/trunk/c/rampart/include/oxs_signature.h Fri Feb 9 04:01:25 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#ifndef OXS_SIGNATURE_H
+#define OXS_SIGNATURE_H
+
+
+/**
+ * @file oxs_signature.h
+ * @brief Does the XML Signature for OMXMLSecurity
+ */
+
+#include <axis2_defines.h>
+#include <oxs_ctx.h>
+#include <axis2_env.h>
+#include <axiom_node.h>
+#include <axiom_element.h>
+#include <axis2_qname.h>
+#include <oxs_sign_ctx.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/**
+ * Sign
+ */
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sig_sign(const axis2_env_t *env,
+ oxs_sign_ctx_t *sign_ctx,
+ oxs_buffer_t *input,
+ oxs_buffer_t *output);
+
+
+/** @} */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OXS_SIGNATURE_H */
Modified: webservices/axis2/trunk/c/rampart/include/oxs_token_signature.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/include/oxs_token_signature.h?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/include/oxs_token_signature.h (original)
+++ webservices/axis2/trunk/c/rampart/include/oxs_token_signature.h Fri Feb 9 04:01:25 2007
@@ -15,8 +15,8 @@
* limitations under the License.
*/
-#ifndef OXS_SIGNATURE_H
-#define OXS_SIGNATURE_H
+#ifndef OXS_TOKEN_SIGNATURE_H
+#define OXS_TOKEN_SIGNATURE_H
/**
@@ -48,4 +48,4 @@
}
#endif
-#endif /* OXS_SIGNATURE_H */
+#endif /* OXS_TOKEN_SIGNATURE_H */
Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am Fri Feb 9 04:01:25 2007
@@ -4,7 +4,7 @@
libomxmlsec_la_SOURCES = ctx.c buffer.c key.c cipher.c error.c axis2_utils.c axiom.c \
iv.c xml_encryption.c encryption.c\
utility.c asym_ctx.c x509_cert.c key_mgr.c sign_part.c sign_ctx.c \
- xml_signature.c
+ xml_signature.c signature.c
libomxmlsec_la_LIBADD = -lssl\
Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/key_mgr.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/key_mgr.c?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/key_mgr.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/key_mgr.c Fri Feb 9 04:01:25 2007
@@ -21,6 +21,11 @@
#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 axis2_env_t *env,
oxs_asym_ctx_t *ctx,
Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/sign_ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/sign_ctx.c?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/sign_ctx.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/sign_ctx.c Fri Feb 9 04:01:25 2007
@@ -25,10 +25,14 @@
axis2_char_t *sign_mtd_algo;
axis2_char_t *c14n_mtd ;
axis2_array_list_t *sign_parts;
- /*TODO: key*/
+ oxs_x509_cert_t *certificate ;
+ openssl_pkey_t *prv_key ;
+ openssl_pkey_t *pub_key ;
};
/*Public functions*/
+
+
axis2_char_t *AXIS2_CALL
oxs_sign_ctx_get_sign_mtd_algo(
const oxs_sign_ctx_t *sign_ctx,
@@ -54,6 +58,73 @@
return sign_ctx->sign_parts;
}
+oxs_x509_cert_t *AXIS2_CALL
+oxs_sign_ctx_get_certificate(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env)
+{
+ return sign_ctx->certificate ;
+}
+
+openssl_pkey_t *AXIS2_CALL
+oxs_sign_ctx_get_private_key(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env)
+{
+ return sign_ctx->prv_key ;
+}
+
+openssl_pkey_t *AXIS2_CALL
+oxs_sign_ctx_get_public_key(
+ const oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env)
+{
+ return sign_ctx->pub_key ;
+}
+
+
+axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_certificate(
+ oxs_sign_ctx_t *sign_ctx,
+ const axis2_env_t *env,
+ oxs_x509_cert_t *certificate)
+{
+ if (sign_ctx->certificate )
+ {
+ sign_ctx->certificate = NULL;
+ }
+ sign_ctx->certificate = certificate;
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_sign_ctx_set_private_key(
+ oxs_sign_ctx_t *sign_ctx,
+ const axis2_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_status_t AXIS2_CALL
+oxs_sign_ctx_set_public_key(
+ oxs_sign_ctx_t *sign_ctx,
+ const axis2_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_status_t AXIS2_CALL
oxs_sign_ctx_set_sign_mtd_algo(
oxs_sign_ctx_t *sign_ctx,
@@ -93,6 +164,9 @@
const axis2_env_t *env,
axis2_array_list_t *sign_parts)
{
+ if(sign_ctx->sign_parts){
+ sign_ctx->sign_parts = NULL;
+ }
sign_ctx->sign_parts = sign_parts;
return AXIS2_SUCCESS;
}
@@ -114,7 +188,10 @@
sign_ctx->sign_mtd_algo= NULL;
sign_ctx->c14n_mtd = NULL;
sign_ctx->sign_parts = NULL;
-
+ sign_ctx->certificate = NULL;
+ sign_ctx->prv_key = NULL;
+ sign_ctx->pub_key = NULL;
+
return sign_ctx;
}
@@ -139,6 +216,9 @@
}
sign_ctx->sign_parts = NULL;
+ sign_ctx->certificate = NULL;
+ sign_ctx->prv_key = NULL;
+ sign_ctx->pub_key = NULL;
AXIS2_FREE(env->allocator, sign_ctx);
sign_ctx = NULL;
Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/signature.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/signature.c?view=auto&rev=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/signature.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/signature.c Fri Feb 9 04:01:25 2007
@@ -0,0 +1,48 @@
+/*
+ * 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_digest.h>
+/*Private functions*/
+
+
+
+/*Public functions*/
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_sig_sign(const axis2_env_t *env,
+ oxs_sign_ctx_t *sign_ctx,
+ oxs_buffer_t *input,
+ oxs_buffer_t *output)
+{
+ /*Get the content*/
+
+ /*Make the digest*/
+
+ /*Sign*/
+
+ return AXIS2_SUCCESS;
+}
+
Modified: webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/xml_signature.c Fri Feb 9 04:01:25 2007
@@ -25,6 +25,8 @@
#include <openssl_digest.h>
#include <oxs_sign_ctx.h>
#include <oxs_sign_part.h>
+#include <oxs_xml_signature.h>
+#include <oxs_signature.h>
#include <oxs_token_ds_reference.h>
#include <oxs_token_digest_method.h>
#include <oxs_token_digest_value.h>
@@ -40,7 +42,7 @@
/*parent is ds:SignedInfo*/
static axis2_status_t
-rampart_xml_sig_build_reference(const axis2_env_t *env,
+oxs_xml_sig_build_reference(const axis2_env_t *env,
axiom_node_t *parent,
oxs_sign_part_t *sign_part)
{
@@ -76,7 +78,7 @@
}
/*Serialize node*/
serialized_node = AXIOM_NODE_TO_STRING(node, env);
-
+ printf("serialized_node %s\n", serialized_node);
/*Make digest.*/
digest_mtd = oxs_sign_part_get_digest_mtd(sign_part, env);
digest = openssl_sha1(env, serialized_node, axis2_strlen(serialized_node));
@@ -87,27 +89,37 @@
return AXIS2_SUCCESS;
}
-
+/**
+ * C14N -> Serialize -> Sign the <SignedInfo> element
+ */
static axis2_status_t
-rampart_xml_sig_sign_signed_info(const axis2_env_t *env,
+oxs_xml_sig_sign_signed_info(const axis2_env_t *env,
axiom_node_t *signature_node,
axiom_node_t *signed_info_node,
oxs_sign_ctx_t *sign_ctx)
{
axis2_char_t *signature_val = "FAKE_SIG_VAL(734dwe93721fd8y2==";
axis2_char_t *serialized_signed_info = NULL;
- axis2_char_t *sign_algo = NULL;
axis2_char_t *c14n_algo = NULL;
axiom_node_t *signature_val_node = NULL;
+ oxs_buffer_t *input_buf = NULL;
+ oxs_buffer_t *output_buf = NULL;
+ axis2_status_t status = AXIS2_FAILURE;
/*TODO : Cannonicalize <SignedInfo>*/
c14n_algo = oxs_sign_ctx_get_c14n_mtd(sign_ctx, env);
/*Then serialize <SignedInfo>*/
serialized_signed_info = AXIOM_NODE_TO_STRING(signed_info_node, env);
-
+ printf("serialized_signed_info %s\n",serialized_signed_info);
+
+ /*Make the input and out put buffers*/
+ input_buf = oxs_buffer_create(env);
+ output_buf = oxs_buffer_create(env);
+
+ OXS_BUFFER_POPULATE(input_buf, env, (unsigned char *)serialized_signed_info, axis2_strlen(serialized_signed_info));
/*Then sign... NOTE: The signature process includes making the digest. e.g. rsa-sha1 => RSA(SHA-1(contents))*/
- sign_algo = oxs_sign_ctx_get_sign_mtd_algo(sign_ctx, env);
+ status = oxs_sig_sign(env, sign_ctx, input_buf, output_buf);
/*Sign the data using the private key*/
signature_val = "MC0CFFrVLtRlk=";
@@ -157,11 +169,11 @@
/*TODO Get ith sign_part*/
sign_part = (oxs_sign_part_t*)axis2_array_list_get(sign_parts, env, i);
/*Create <ds:Reference> elements */
- rampart_xml_sig_build_reference(env, signed_info_node, sign_part);
+ oxs_xml_sig_build_reference(env, signed_info_node, sign_part);
}
/*At this point we have a complete <SignedInfo> node. Now we need to sign it*/
- rampart_xml_sig_sign_signed_info(env, signature_node, signed_info_node, sign_ctx);
+ oxs_xml_sig_sign_signed_info(env, signature_node, signed_info_node, sign_ctx);
return AXIS2_SUCCESS;
Modified: webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c?view=diff&rev=505263&r1=505262&r2=505263
==============================================================================
--- webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c (original)
+++ webservices/axis2/trunk/c/rampart/test/omxmlsec/test.c Fri Feb 9 04:01:25 2007
@@ -97,7 +97,7 @@
/*Sign specific*/
sign_part = oxs_sign_part_create(env);
status = AXIS2_FAILURE;
- status = oxs_sign_part_set_node(sign_part, env, AXIOM_NODE_GET_FIRST_CHILD(tmpl, env));
+ status = oxs_sign_part_set_node(sign_part, env, axiom_node_get_first_element(tmpl, env));
sign_parts = axis2_array_list_create(env, 1);
axis2_array_list_add(sign_parts, env, sign_part);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org