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 da...@apache.org on 2006/07/14 11:31:35 UTC

svn commit: r421846 - in /webservices/axis2/trunk/c/rampart/src/omxmlsec: Makefile.am openssl/ openssl/Makefile.am openssl/cipher_ctx.c openssl/crypt.c

Author: damitha
Date: Fri Jul 14 02:31:34 2006
New Revision: 421846

URL: http://svn.apache.org/viewvc?rev=421846&view=rev
Log:
Adding openssl related files of omxmlsec library. Thanks kaushalye for the code.

Added:
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/Makefile.am
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c
    webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c
Modified:
    webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am

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?rev=421846&r1=421845&r2=421846&view=diff
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am (original)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/Makefile.am Fri Jul 14 02:31:34 2006
@@ -1,6 +1,7 @@
 SUBDIRS = openssl
 noinst_LTLIBRARIES = libomxmlsec.la
-libomxmlsec_la_SOURCES = oxs_ctx.c oxs_enc.c 
+#libomxmlsec_la_SOURCES = ctx.c enc.c transforms.c  buffer.c errors.c
+libomxmlsec_la_SOURCES = buffer.c errors.c axis2_utils.c
 
 libomxmlsec_la_LIBADD  = -lssl\
             -laxis2_util \

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/Makefile.am?rev=421846&view=auto
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/Makefile.am (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/Makefile.am Fri Jul 14 02:31:34 2006
@@ -0,0 +1,11 @@
+noinst_LTLIBRARIES = libomopenssl.la
+libomopenssl_la_SOURCES = cipher_ctx.c crypt.c 
+
+libomopenssl_la_LIBADD  = -lssl\
+            -laxis2_util \
+    		-lcrypto \
+            -laxis2_axiom
+
+INCLUDES = -I$(top_builddir)/include \
+			@UTILINC@ \
+            @AXIOMINC@

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c?rev=421846&view=auto
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/cipher_ctx.c Fri Jul 14 02:31:34 2006
@@ -0,0 +1,156 @@
+/*
+ *   Copyright 2003-2004 The Apache Software Foundation.
+ *
+ *   Licensed 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/evp.h>
+#include <openssl/rand.h>
+
+
+AXIS2_EXTERN openssl_evp_block_cipher_ctx_ptr AXIS2_CALL  openssl_evp_block_cipher_ctx_create(const axis2_env_t *env){
+    openssl_evp_block_cipher_ctx_ptr bc_ctx = NULL;
+    bc_ctx = (openssl_evp_block_cipher_ctx_ptr)AXIS2_MALLOC(env->allocator,sizeof(openssl_evp_block_cipher_ctx));
+    
+    return bc_ctx;
+}
+
+AXIS2_EXTERN openssl_evp_block_cipher_ctx_ptr AXIS2_CALL  openssl_evp_block_cipher_ctx_init(const axis2_env_t *env,
+                             openssl_evp_block_cipher_ctx_ptr bc_ctx,
+                             oxs_buffer_ptr in,
+                             oxs_buffer_ptr out,
+                             int encrypt,
+                             const unsigned char* cipher_name
+                             )
+{
+    int ivLen;
+    int ret;
+        
+    bc_ctx->cipher  =  EVP_des_ede3_cbc(); /* Right now we support only this*/
+
+    EVP_CIPHER_CTX_init(&(bc_ctx->cipher_ctx));
+
+    ivLen = EVP_CIPHER_iv_length(bc_ctx->cipher);
+
+    if(encrypt) {
+        /* generate random iv */
+        ret = RAND_bytes(bc_ctx->iv, ivLen);
+        if(ret != 1) {
+            return(-1);
+        }
+
+        /*Write IV to the output */
+        ret = oxs_buffer_append(env, out, bc_ctx->iv, ivLen); 
+
+    }else{
+        /* if we don't have enough data, exit and hope that
+         * we'll have iv next time */
+        
+        /*TODO Decrypt*/
+       return 0;
+    }
+
+    /* set iv */
+    ret = EVP_CipherInit(&(bc_ctx->cipher_ctx), bc_ctx->cipher, bc_ctx->key, bc_ctx->iv, encrypt);
+    if(ret != 1) {
+        return (-1);
+    }
+   
+    bc_ctx->ctxInitialized = 1;
+    
+    return 0;
+}
+#if 0
+AXIS2_EXTERN int AXIS2_CALL  openssl_evp_block_cipher_ctx_update  (const axis2_env_t *env,
+                             openssl_evp_block_cipher_ctx_ptr ctx,
+                             oxs_buffer_ptr in,
+                             oxs_buffer_ptr out,
+                             const unsigned char* cipherName
+                             )
+{
+    int block_len, fixLength = 0, outLen = 0;
+    unsigned int inSize, outSize;
+    unsigned char* outBuf;
+    int ret;
+
+    block_len = EVP_CIPHER_block_size(ctx->cipher);
+
+    inSize = in->size;
+    outSize = out->size;
+
+    if(inSize == 0) {
+        /* wait for more data */
+        return(0);
+    }
+
+    outBuf = out->data + outSize;    
+
+
+    /* encrypt/decrypt */
+    ret = EVP_CipherUpdate(&(ctx->cipherCtx), outBuf, &outLen, in->data, inSize);
+    if(ret != 1) {
+        return (-1);
+    }
+
+
+    out->size = outSize + outLen;
+
+     /* remove the processed block from input */
+    ret = oxs_remove_head(in, inSize);
+    if(ret < 0) return (-1);
+    
+    return (0); 
+
+}
+
+AXIS2_EXTERN int  AXIS2_CALL openssl_evp_block_cipher_ctx_final (const axis2_env_t *env,
+                             openssl_evp_block_cipher_ctx_ptr ctx,
+                             oxs_buffer_ptr out,
+                             const unsigned char* cipherName
+                             )
+{
+    int block_len, outLen = 0, outLen2 = 0;
+    unsigned int outSize;
+    unsigned char* outBuf;
+    int ret;
+
+    block_len = EVP_CIPHER_block_size(ctx->cipher);
+    if(block_len > 0) return (-1);
+
+    outSize = out->size;
+    ret = oxs_buffer_set_max_size(env, out, outSize + 2 * block_len);
+    
+    if(ret < 0) return (-1);
+    
+    outBuf = out->data + outSize;
+
+
+    /* finalize transform */
+    ret = EVP_CipherFinal(&(ctx->cipherCtx), outBuf, &outLen2);
+    if(ret != 1) {
+        return (-1);
+    }
+
+    /* set correct output buffer size */
+    ret = oxs_buffer_set_size(env, out, outSize + outLen + outLen2);
+    if(ret < 0) {
+        return(-1);
+    }
+
+    return(0);
+}
+#endif
+    

Added: webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c?rev=421846&view=auto
==============================================================================
--- webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c (added)
+++ webservices/axis2/trunk/c/rampart/src/omxmlsec/openssl/crypt.c Fri Jul 14 02:31:34 2006
@@ -0,0 +1,88 @@
+/*
+ *   Copyright 2003-2004 The Apache Software Foundation.
+ *
+ *   Licensed 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 <openssl_cipher_ctx.h>
+#include <openssl_crypt.h>
+#include <openssl/rand.h>
+
+
+AXIS2_EXTERN int AXIS2_CALL  openssl_block_cipher_crypt(axis2_env_t *env, 
+    openssl_evp_block_cipher_ctx_ptr bc_ctx, 
+    oxs_buffer_ptr in_buf, 
+    oxs_buffer_ptr out_buf, 
+    int do_encrypt)
+{
+    EVP_CIPHER_CTX evp_ctx ;
+    evp_ctx = bc_ctx->cipher_ctx;
+
+    unsigned char *tempbuf;
+    int insize, outsize, block_len;
+    int outlen = 0;     
+
+    if(!bc_ctx->ctxInitialized){
+        return (-1); /* Ctx should be initialized by now*/
+    }
+    
+    block_len = EVP_CIPHER_block_size(bc_ctx->cipher);
+
+     /* loop until we dont have any data left in the input buffer */
+    for(;;)
+    {
+        insize = in_buf->size;
+
+        if(insize <= 0) break;/*No More Data!!! Quit loop*/
+
+
+        outsize = out_buf->size;
+        oxs_buffer_set_max_size(env, out_buf, outsize + insize + block_len);
+    
+        tempbuf = out_buf->data + outsize;
+ 
+        if(!EVP_CipherUpdate(&(bc_ctx->cipher_ctx), tempbuf, &outlen, in_buf->data, insize))
+        {
+            /* Error!!! Do the cleanup */
+            EVP_CIPHER_CTX_cleanup(&(bc_ctx->cipher_ctx));
+            return -1;
+        }
+    
+        /*set the correct size of the output buffer*/
+        oxs_buffer_set_size(env, out_buf, outsize + outlen );
+        printf("\noxs_buffer_set_size= %d", outsize + outlen );
+
+        /*remove the processed data from the input*/
+        oxs_buffer_remove_head(env, in_buf, insize);
+
+     }/*End of For loop*/
+
+     if(!EVP_CipherFinal_ex(&(bc_ctx->cipher_ctx), tempbuf, &outsize))
+     {
+        /* Error */
+        EVP_CIPHER_CTX_cleanup(&(bc_ctx->cipher_ctx));
+        return -1;
+     }
+     /*Now set out_buf data*/
+     out_buf->data = tempbuf;
+     oxs_buffer_set_size(env, out_buf, outsize + outlen );
+
+     EVP_CIPHER_CTX_cleanup(&(bc_ctx->cipher_ctx));
+     
+     return 1;
+
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org