You are viewing a plain text version of this content. The canonical link for it is here.
Posted to juice-svn@xml.apache.org by bl...@apache.org on 2006/02/21 10:49:06 UTC
svn commit: r379402 - /incubator/juice/native/src/
Author: blautenb
Date: Tue Feb 21 01:49:03 2006
New Revision: 379402
URL: http://svn.apache.org/viewcvs?rev=379402&view=rev
Log:
Get the correct %$# versions into the repo
Added:
incubator/juice/native/src/SecureRandomOpenSSL.c
incubator/juice/native/src/org_apache_security_juice_provider_SecureRandomOpenSSL.h
Modified:
incubator/juice/native/src/InitializeOpenSSL.c
incubator/juice/native/src/JCEBlockCipherOpenSSL.c
incubator/juice/native/src/JCERSACipherOpenSSL.c
incubator/juice/native/src/JDKDSASignerOpenSSL.c
incubator/juice/native/src/JDKMessageDigestOpenSSL.c
incubator/juice/native/src/Makefile.am
incubator/juice/native/src/org_apache_security_juice_provider_InitializeOpenSSL.h
Modified: incubator/juice/native/src/InitializeOpenSSL.c
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/InitializeOpenSSL.c?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/InitializeOpenSSL.c (original)
+++ incubator/juice/native/src/InitializeOpenSSL.c Tue Feb 21 01:49:03 2006
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2002-2006 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
+ * imitations under the License.
+ */
+
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/err.h>
@@ -6,58 +22,25 @@
#include <jni.h>
#include "org_apache_security_juice_provider_InitializeOpenSSL.h"
-/*
- * Variable use throughout this module to access the Java lock and unlock
- * methods.
- */
-
-static jmethodID lockMethod = 0;
-static jmethodID unlockMethod = 0;
-static jobject javaInitializeObject = 0;
-static JNIEnv *envGlobal = 0;
-
-void java_locking_callback(int mode, int type, char *file, int line);
-
-/*
- * Class: org_apache_security_juice_provider_InitializeOpenSSL
- * Method: getNumLocks
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_apache_security_juice_provider_InitializeOpenSSL_getNumLocks
-(JNIEnv *env, jobject jobj) {
-
- int numLocks = 0;
- jclass clazz = 0;
-
- numLocks = CRYPTO_num_locks();
-
- clazz = (*env)->GetObjectClass(env, jobj);
- if (clazz == 0) {
- return -1;
- }
-
- lockMethod = (*env)->GetMethodID(env, clazz, "setLock", "(I)V");
- unlockMethod = (*env)->GetMethodID(env, clazz, "clearLock", "(I)V");
-
- if (lockMethod == 0 && unlockMethod == 0) {
- return -2;
- }
-
- /*
- * create a global reference to the InitializeOpenSSL instance to lock it in memory
- */
- javaInitializeObject = (*env)->NewGlobalRef(env, jobj);
- if (javaInitializeObject == 0) {
- return -3;
- }
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-// CRYPTO_set_id_callback((unsigned long (*)())java_thread_id);
- CRYPTO_set_locking_callback((void (*)())java_locking_callback);
- envGlobal = env;
- return numLocks;
-}
+#ifdef OPENSSL_SYS_WIN32
+#include <windows.h>
+#endif
+#if defined SOLARIS && !defined HAVE_LIBPTHREAD
+#include <synch.h>
+#include <thread.h>
+#endif
+#if defined HAVE_LIBPTHREAD && !defined SOLARIS
+#include <pthread.h>
+#endif
+static void thread_setup(void);
+static void thread_cleanup(void);
+static void my_locking_callback(int, int, const char *, int);
/*
* Class: org_apache_security_juice_provider_InitializeOpenSSL
@@ -67,36 +50,200 @@
JNIEXPORT jint JNICALL Java_org_apache_security_juice_provider_InitializeOpenSSL_initializeOpenSSL
(JNIEnv *env, jobject jobj) {
- (*envGlobal)->CallVoidMethod(envGlobal, javaInitializeObject, lockMethod, -1);
- (*envGlobal)->CallVoidMethod(envGlobal, javaInitializeObject, unlockMethod, -1);
+ thread_setup();
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
return 1;
}
-void java_locking_callback(int mode, int type, char *file,
- int line) {
+
+#ifdef OPENSSL_SYS_WIN32
+
+static HANDLE *lock_cs;
+
+static void thread_setup(void)
+ {
+ int i;
+
+ lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(HANDLE));
+ for (i=0; i<CRYPTO_num_locks(); i++)
+ {
+ lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
+ }
+
+ CRYPTO_set_locking_callback((void (*)(int,int,const char *,int))my_locking_callback);
+ /* id callback defined */
+ }
+
+static void thread_cleanup(void)
+ {
+ int i;
+
+ CRYPTO_set_locking_callback(NULL);
+ for (i=0; i<CRYPTO_num_locks(); i++)
+ CloseHandle(lock_cs[i]);
+ OPENSSL_free(lock_cs);
+ }
+
+static void my_locking_callback(int mode, int type, const char *file, int line)
+ {
+ if (mode & CRYPTO_LOCK)
+ {
+ WaitForSingleObject(lock_cs[type],INFINITE);
+ }
+ else
+ {
+ ReleaseMutex(lock_cs[type]);
+ }
+ }
+
+#endif /* OPENSSL_SYS_WIN32 */
+
+
+#if defined SOLARIS && !defined HAVE_LIBPTHREAD
+
+static mutex_t *lock_cs;
+static long *lock_count;
+
+static void thread_setup(void)
+ {
+ int i;
+
+ lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(mutex_t));
+ lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
+ for (i=0; i<CRYPTO_num_locks(); i++)
+ {
+ lock_count[i]=0;
+ /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */
+ mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
+ }
+
+ // CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
+ CRYPTO_set_locking_callback((void (*)(int,int,const char *,int))my_locking_callback);
+ }
+
+static void thread_cleanup(void)
+ {
+ int i;
+
+ CRYPTO_set_locking_callback(NULL);
+
+ fprintf(stderr,"cleanup\n");
+
+ for (i=0; i<CRYPTO_num_locks(); i++)
+ {
+ /* rwlock_destroy(&(lock_cs[i])); */
+ mutex_destroy(&(lock_cs[i]));
+ fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
+ }
+ OPENSSL_free(lock_cs);
+ OPENSSL_free(lock_count);
+
+ fprintf(stderr,"done cleanup\n");
+
+ }
+
+static void my_locking_callback(int mode, int type, const char *file, int line)
+ {
#ifdef undef
- fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
- CRYPTO_thread_id(),
- (mode&CRYPTO_LOCK)?"l":"u",
- (type&CRYPTO_READ)?"r":"w",file,line);
-#endif
- if (mode & CRYPTO_LOCK) {
- (*envGlobal)->CallVoidMethod(envGlobal, javaInitializeObject, lockMethod, type);
- }
- else {
- (*envGlobal)->CallVoidMethod(envGlobal, javaInitializeObject, unlockMethod, type);
- }
-}
+ fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
+ CRYPTO_thread_id(),
+ (mode&CRYPTO_LOCK)?"l":"u",
+ (type&CRYPTO_READ)?"r":"w",file,line);
+#endif
-unsigned long java_thread_id(void) {
- unsigned long ret;
+ /*
+ if (CRYPTO_LOCK_SSL_CERT == type)
+ fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
+ CRYPTO_thread_id(),
+ mode,file,line);
+ */
+ if (mode & CRYPTO_LOCK)
+ {
+ mutex_lock(&(lock_cs[type]));
+ lock_count[type]++;
+ }
+ else
+ {
+ mutex_unlock(&(lock_cs[type]));
+ }
+ }
+
+static unsigned long solaris_thread_id(void)
+ {
+ unsigned long ret;
+
+ ret=(unsigned long)thr_self();
+ return(ret);
+ }
+#endif /* SOLARIS */
+
+
+#if defined HAVE_LIBPTHREAD && !defined SOLARIS
+
+static pthread_mutex_t *lock_cs;
+static long *lock_count;
+
+static void thread_setup(void)
+ {
+ int i;
+
+ lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
+ lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
+ for (i=0; i<CRYPTO_num_locks(); i++)
+ {
+ lock_count[i]=0;
+ pthread_mutex_init(&(lock_cs[i]),NULL);
+ }
+
+ // CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
+ CRYPTO_set_locking_callback((void (*)())my_locking_callback);
+ }
+
+static void thread_cleanup(void)
+ {
+ int i;
+
+ CRYPTO_set_locking_callback(NULL);
+ fprintf(stderr,"cleanup\n");
+ for (i=0; i<CRYPTO_num_locks(); i++)
+ {
+ pthread_mutex_destroy(&(lock_cs[i]));
+ fprintf(stderr,"%8ld:%s\n",lock_count[i],
+ CRYPTO_get_lock_name(i));
+ }
+ OPENSSL_free(lock_cs);
+ OPENSSL_free(lock_count);
+
+ fprintf(stderr,"done cleanup\n");
+ }
+
+static void my_locking_callback(int mode, int type, const char *file,
+ int line)
+ {
+#ifdef undef
+ fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
+ CRYPTO_thread_id(),
+ (mode&CRYPTO_LOCK)?"l":"u",
+ (type&CRYPTO_READ)?"r":"w",file,line);
+#endif
+ if (mode & CRYPTO_LOCK)
+ {
+ pthread_mutex_lock(&(lock_cs[type]));
+ lock_count[type]++;
+ }
+ else
+ {
+ pthread_mutex_unlock(&(lock_cs[type]));
+ }
+ }
+
+static unsigned long pthreads_thread_id(void)
+ {
+ unsigned long ret;
+
+ ret=(unsigned long)pthread_self();
+ return(ret);
+ }
-/*
- * This could probably be done via Thread.currentThread() and convert the Thread reference
- * to a long - needs to be evaluated.
- */
-// ret=(unsigned long)pthread_self();
- return(ret);
-}
+#endif /* LIBPTHREAD && !SOLARIS */
Modified: incubator/juice/native/src/JCEBlockCipherOpenSSL.c
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/JCEBlockCipherOpenSSL.c?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/JCEBlockCipherOpenSSL.c (original)
+++ incubator/juice/native/src/JCEBlockCipherOpenSSL.c Tue Feb 21 01:49:03 2006
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2002-2006 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
+ * imitations under the License.
+ */
+
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/err.h>
@@ -7,7 +23,12 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
+#endif
+
+/* Definitions for specialised final functions that use 10126 padding */
+
+int EVP_EncryptFinal_ex_ISO10126(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
+int EVP_DecryptFinal_ex_ISO10126(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
void hexdump1(FILE *f,const char *title,const unsigned char *s,int l) {
int n=0;
@@ -40,50 +61,50 @@
c=EVP_get_cipherbyname(algo);
if(!c) {
- fprintf(stderr,"Algorithm not found %s\n", algo);
- return 0L;
+ fprintf(stderr,"Algorithm not found %s\n", algo);
+ return 0L;
}
(*env)->ReleaseStringUTFChars(env, algoName, algo);
if(klen != c->key_len) {
- fprintf(stderr,"Key length doesn't match, got %d expected %d\n",klen,
- c->key_len);
- return 0;
+ fprintf(stderr,"Key length doesn't match, got %d expected %d\n",klen,
+ c->key_len);
+ return 0;
}
ctx = malloc(sizeof (EVP_CIPHER_CTX));
EVP_CIPHER_CTX_init(ctx);
if (ivlen > 0) {
- jbyte *keyBytes = (*env)->GetByteArrayElements(env, key, 0);
- jbyte *ivBytes = (*env)->GetByteArrayElements(env, iv, 0);
- ret = EVP_CipherInit_ex(ctx, c, NULL, keyBytes, ivBytes, encrypt);
- (*env)->ReleaseByteArrayElements(env, iv, ivBytes, 0);
- (*env)->ReleaseByteArrayElements(env, key, keyBytes, 0);
-
- if (pad == org_apache_security_juice_provider_JCEBlockCipherOpenSSL_NOPAD) {
- ctx->flags |= EVP_CIPH_NO_PADDING;
- }
-
- if(ret == 0) {
- fprintf(stderr,"EncryptInit failed\n");
- ERR_print_errors_fp(stderr);
- EVP_CIPHER_CTX_cleanup(ctx);
- free(ctx);
- return 0;
- }
+ jbyte *keyBytes = (*env)->GetByteArrayElements(env, key, 0);
+ jbyte *ivBytes = (*env)->GetByteArrayElements(env, iv, 0);
+ ret = EVP_CipherInit_ex(ctx, c, NULL, keyBytes, ivBytes, encrypt);
+ (*env)->ReleaseByteArrayElements(env, iv, ivBytes, 0);
+ (*env)->ReleaseByteArrayElements(env, key, keyBytes, 0);
+
+ if (pad == org_apache_security_juice_provider_JCEBlockCipherOpenSSL_NOPAD) {
+ ctx->flags |= EVP_CIPH_NO_PADDING;
+ }
+
+ if(ret == 0) {
+ fprintf(stderr,"EncryptInit failed\n");
+ ERR_print_errors_fp(stderr);
+ EVP_CIPHER_CTX_cleanup(ctx);
+ free(ctx);
+ return 0;
+ }
}
else {
- jbyte *keyBytes = (*env)->GetByteArrayElements(env, key, 0);
- ret = EVP_CipherInit_ex(ctx, c, NULL, key, 0, encrypt);
- (*env)->ReleaseByteArrayElements(env, key, keyBytes, 0);
- if(ret == 0) {
- fprintf(stderr,"EncryptInit failed\n");
- ERR_print_errors_fp(stderr);
- EVP_CIPHER_CTX_cleanup(ctx);
- free(ctx);
- return 0;
- }
+ jbyte *keyBytes = (*env)->GetByteArrayElements(env, key, 0);
+ ret = EVP_CipherInit_ex(ctx, c, NULL, keyBytes, 0, encrypt);
+ (*env)->ReleaseByteArrayElements(env, key, keyBytes, 0);
+ if(ret == 0) {
+ fprintf(stderr,"EncryptInit failed\n");
+ ERR_print_errors_fp(stderr);
+ EVP_CIPHER_CTX_cleanup(ctx);
+ free(ctx);
+ return 0;
+ }
}
return (unsigned long)ctx;
}
@@ -144,20 +165,20 @@
outBytes = (*env)->GetByteArrayElements(env, output, 0);
if (ctx->encrypt) {
- if (pad == org_apache_security_juice_provider_JCEBlockCipherOpenSSL_ISO10126) {
- ret = EVP_EncryptFinal_ex_ISO10126(ctx, outBytes+outOff, &outLen);
- }
- else {
- ret = EVP_EncryptFinal_ex(ctx, outBytes+outOff, &outLen);
- }
+ if (pad == org_apache_security_juice_provider_JCEBlockCipherOpenSSL_ISO10126) {
+ ret = EVP_EncryptFinal_ex_ISO10126(ctx, outBytes+outOff, &outLen);
+ }
+ else {
+ ret = EVP_EncryptFinal_ex(ctx, outBytes+outOff, &outLen);
+ }
}
else {
- if (pad == org_apache_security_juice_provider_JCEBlockCipherOpenSSL_ISO10126) {
- ret = EVP_DecryptFinal_ex_ISO10126(ctx, outBytes+outOff, &outLen);
- }
- else {
- ret = EVP_DecryptFinal_ex(ctx, outBytes+outOff, &outLen);
- }
+ if (pad == org_apache_security_juice_provider_JCEBlockCipherOpenSSL_ISO10126) {
+ ret = EVP_DecryptFinal_ex_ISO10126(ctx, outBytes+outOff, &outLen);
+ }
+ else {
+ ret = EVP_DecryptFinal_ex(ctx, outBytes+outOff, &outLen);
+ }
}
(*env)->ReleaseByteArrayElements(env, output, outBytes, 0);
@@ -166,39 +187,36 @@
free(ctx);
if(ret == 0) {
- fprintf(stderr,"Do final failed\n");
- ERR_print_errors_fp(stderr);
- return -1;
+ fprintf(stderr,"Do final failed\n");
+ ERR_print_errors_fp(stderr);
+ return -1;
}
return outLen;
}
int EVP_EncryptFinal_ex_ISO10126(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
{
- int n,ret;
- unsigned int i, b, bl;
+ int n, ret;
+ unsigned int b, bl;
b=ctx->cipher->block_size;
OPENSSL_assert(b <= sizeof ctx->buf);
- if (b == 1)
- {
- *outl=0;
- return 1;
+ if (b == 1) {
+ *outl=0;
+ return 1;
}
bl=ctx->buf_len;
- if (ctx->flags & EVP_CIPH_NO_PADDING)
- {
- if(bl)
- {
+ if (ctx->flags & EVP_CIPH_NO_PADDING) {
+ if(bl) {
#ifdef EVP_F_EVP_ENCRYPTFINAL_EX
- EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
+ EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
#else
- EVPerr(EVP_F_EVP_ENCRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
+ EVPerr(EVP_F_EVP_ENCRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
#endif
- return 0;
- }
- *outl = 0;
- return 1;
+ return 0;
+ }
+ *outl = 0;
+ return 1;
}
n=b-bl;
@@ -208,7 +226,7 @@
if(ret)
- *outl=b;
+ *outl=b;
return ret;
}
@@ -221,49 +239,44 @@
*outl=0;
b=ctx->cipher->block_size;
- if (ctx->flags & EVP_CIPH_NO_PADDING)
- {
- if(ctx->buf_len)
- {
+ if (ctx->flags & EVP_CIPH_NO_PADDING) {
+ if(ctx->buf_len) {
#ifdef EVP_F_EVP_DECRYPTFINAL_EX
- EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
+ EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
#else
- EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
+ EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
#endif
- return 0;
- }
- *outl = 0;
- return 1;
+ return 0;
+ }
+ *outl = 0;
+ return 1;
}
- if (b > 1)
- {
- if (ctx->buf_len || !ctx->final_used)
- {
+ if (b > 1) {
+ if (ctx->buf_len || !ctx->final_used) {
#ifdef EVP_F_EVP_DECRYPTFINAL_EX
- EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
+ EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
#else
- EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
+ EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
#endif
- return(0);
- }
- OPENSSL_assert(b <= sizeof ctx->final);
- n=ctx->final[b-1];
- if (n > (int)b)
- {
+ return(0);
+ }
+ OPENSSL_assert(b <= sizeof ctx->final);
+ n=ctx->final[b-1];
+ if (n > (int)b) {
#ifdef EVP_F_EVP_DECRYPTFINAL_EX
- EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
+ EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
#else
- EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
+ EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
#endif
- return(0);
- }
- n=ctx->cipher->block_size-n;
- for (i=0; i<n; i++)
- out[i]=ctx->final[i];
- *outl=n;
+ return(0);
+ }
+ n=ctx->cipher->block_size-n;
+ for (i=0; i<n; i++)
+ out[i]=ctx->final[i];
+ *outl=n;
}
else
- *outl=0;
+ *outl=0;
return(1);
}
Modified: incubator/juice/native/src/JCERSACipherOpenSSL.c
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/JCERSACipherOpenSSL.c?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/JCERSACipherOpenSSL.c (original)
+++ incubator/juice/native/src/JCERSACipherOpenSSL.c Tue Feb 21 01:49:03 2006
@@ -1,7 +1,24 @@
+/*
+ * Copyright 2002-2006 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
+ * imitations under the License.
+ */
+
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/bn.h>
+#include <openssl/err.h>
#include <jni.h>
#include "org_apache_security_juice_provider_JCERSACipherOpenSSL.h"
@@ -29,59 +46,59 @@
RSA *key = RSA_new();
if (n == NULL) {
- fprintf(stderr, "Mandatory parameter n is NULL\n");
- return 0L;
+ fprintf(stderr, "Mandatory parameter n is NULL\n");
+ return 0L;
}
else {
- nb = (*env)->GetByteArrayElements(env, n, 0);
- key->n = BN_bin2bn(nb, nlen, NULL);
- (*env)->ReleaseByteArrayElements(env, n, nb, 0);
+ nb = (*env)->GetByteArrayElements(env, n, 0);
+ key->n = BN_bin2bn(nb, nlen, NULL);
+ (*env)->ReleaseByteArrayElements(env, n, nb, 0);
}
if (e == NULL) {
- fprintf(stderr, "Mandatory parameter e is NULL\n");
- return 0L;
+ fprintf(stderr, "Mandatory parameter e is NULL\n");
+ return 0L;
}
else {
- eb = (*env)->GetByteArrayElements(env, e, 0);
- key->e = BN_bin2bn(eb, elen, NULL);
- (*env)->ReleaseByteArrayElements(env, e, eb, 0);
+ eb = (*env)->GetByteArrayElements(env, e, 0);
+ key->e = BN_bin2bn(eb, elen, NULL);
+ (*env)->ReleaseByteArrayElements(env, e, eb, 0);
}
if (d != NULL) {
- db = (*env)->GetByteArrayElements(env, d, 0);
- key->d = BN_bin2bn(db, dlen, NULL);
- (*env)->ReleaseByteArrayElements(env, d, db, 0);
+ db = (*env)->GetByteArrayElements(env, d, 0);
+ key->d = BN_bin2bn(db, dlen, NULL);
+ (*env)->ReleaseByteArrayElements(env, d, db, 0);
}
if (p != NULL) {
- pb = (*env)->GetByteArrayElements(env, p, 0);
- key->p = BN_bin2bn(pb, plen, NULL);
- (*env)->ReleaseByteArrayElements(env, p, pb, 0);
+ pb = (*env)->GetByteArrayElements(env, p, 0);
+ key->p = BN_bin2bn(pb, plen, NULL);
+ (*env)->ReleaseByteArrayElements(env, p, pb, 0);
}
if (q != NULL) {
- qb = (*env)->GetByteArrayElements(env, q, 0);
- key->q = BN_bin2bn(qb, qlen, NULL);
- (*env)->ReleaseByteArrayElements(env, q, qb, 0);
+ qb = (*env)->GetByteArrayElements(env, q, 0);
+ key->q = BN_bin2bn(qb, qlen, NULL);
+ (*env)->ReleaseByteArrayElements(env, q, qb, 0);
}
if (dmp1 != NULL) {
- dmp1b = (*env)->GetByteArrayElements(env, dmp1, 0);
- key->dmp1 = BN_bin2bn(dmp1b, dmp1len, NULL);
- (*env)->ReleaseByteArrayElements(env, dmp1, dmp1b, 0);
+ dmp1b = (*env)->GetByteArrayElements(env, dmp1, 0);
+ key->dmp1 = BN_bin2bn(dmp1b, dmp1len, NULL);
+ (*env)->ReleaseByteArrayElements(env, dmp1, dmp1b, 0);
}
if (dmq1 != NULL) {
- dmq1b = (*env)->GetByteArrayElements(env, dmq1, 0);
- key->dmq1 = BN_bin2bn(dmq1b, dmq1len, NULL);
- (*env)->ReleaseByteArrayElements(env, dmq1, dmq1b, 0);
+ dmq1b = (*env)->GetByteArrayElements(env, dmq1, 0);
+ key->dmq1 = BN_bin2bn(dmq1b, dmq1len, NULL);
+ (*env)->ReleaseByteArrayElements(env, dmq1, dmq1b, 0);
}
if (iqmp != NULL) {
- iqmpb = (*env)->GetByteArrayElements(env, iqmp, 0);
- key->iqmp = BN_bin2bn(iqmpb, iqmplen, NULL);
- (*env)->ReleaseByteArrayElements(env, iqmp, iqmpb, 0);
+ iqmpb = (*env)->GetByteArrayElements(env, iqmp, 0);
+ key->iqmp = BN_bin2bn(iqmpb, iqmplen, NULL);
+ (*env)->ReleaseByteArrayElements(env, iqmp, iqmpb, 0);
}
// if (d != NULL && RSA_check_key(key) > 0) {
Modified: incubator/juice/native/src/JDKDSASignerOpenSSL.c
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/JDKDSASignerOpenSSL.c?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/JDKDSASignerOpenSSL.c (original)
+++ incubator/juice/native/src/JDKDSASignerOpenSSL.c Tue Feb 21 01:49:03 2006
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2002-2006 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
+ * imitations under the License.
+ */
+
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/dsa.h>
@@ -26,52 +42,52 @@
DSA *key = DSA_new();
if (p == NULL) {
- fprintf(stderr, "Mandatory parameter p is NULL\n");
- return 0L;
+ fprintf(stderr, "Mandatory parameter p is NULL\n");
+ return 0L;
}
else {
- pb = (*env)->GetByteArrayElements(env, p, 0);
- key->p = BN_bin2bn(pb, plen, NULL);
- (*env)->ReleaseByteArrayElements(env, p, pb, 0);
+ pb = (*env)->GetByteArrayElements(env, p, 0);
+ key->p = BN_bin2bn(pb, plen, NULL);
+ (*env)->ReleaseByteArrayElements(env, p, pb, 0);
}
if (q == NULL) {
- fprintf(stderr, "Mandatory parameter q is NULL\n");
- return 0L;
+ fprintf(stderr, "Mandatory parameter q is NULL\n");
+ return 0L;
}
else {
- qb = (*env)->GetByteArrayElements(env, q, 0);
- key->q = BN_bin2bn(qb, qlen, NULL);
- (*env)->ReleaseByteArrayElements(env, q, qb, 0);
+ qb = (*env)->GetByteArrayElements(env, q, 0);
+ key->q = BN_bin2bn(qb, qlen, NULL);
+ (*env)->ReleaseByteArrayElements(env, q, qb, 0);
}
if (g == NULL) {
- fprintf(stderr, "Mandatory parameter g is NULL\n");
- return 0L;
+ fprintf(stderr, "Mandatory parameter g is NULL\n");
+ return 0L;
}
else {
- gb = (*env)->GetByteArrayElements(env, g, 0);
- key->g = BN_bin2bn(gb, glen, NULL);
- (*env)->ReleaseByteArrayElements(env, g, gb, 0);
+ gb = (*env)->GetByteArrayElements(env, g, 0);
+ key->g = BN_bin2bn(gb, glen, NULL);
+ (*env)->ReleaseByteArrayElements(env, g, gb, 0);
}
if (x == NULL && y == NULL) {
- fprintf(stderr, "Public and private key parts are NULL\n");
- return 0L;
+ fprintf(stderr, "Public and private key parts are NULL\n");
+ return 0L;
}
// public key
if (y != NULL) {
- yb = (*env)->GetByteArrayElements(env, y, 0);
- key->pub_key = BN_bin2bn(yb, ylen, NULL);
- (*env)->ReleaseByteArrayElements(env, y, yb, 0);
+ yb = (*env)->GetByteArrayElements(env, y, 0);
+ key->pub_key = BN_bin2bn(yb, ylen, NULL);
+ (*env)->ReleaseByteArrayElements(env, y, yb, 0);
}
// private key
if (x != NULL) {
- xb = (*env)->GetByteArrayElements(env, x, 0);
- key->priv_key = BN_bin2bn(xb, xlen, NULL);
- (*env)->ReleaseByteArrayElements(env, x, xb, 0);
+ xb = (*env)->GetByteArrayElements(env, x, 0);
+ key->priv_key = BN_bin2bn(xb, xlen, NULL);
+ (*env)->ReleaseByteArrayElements(env, x, xb, 0);
}
return (unsigned long)key;
}
Modified: incubator/juice/native/src/JDKMessageDigestOpenSSL.c
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/JDKMessageDigestOpenSSL.c?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/JDKMessageDigestOpenSSL.c (original)
+++ incubator/juice/native/src/JDKMessageDigestOpenSSL.c Tue Feb 21 01:49:03 2006
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2002-2006 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
+ * imitations under the License.
+ */
+
#include <stdio.h>
#include <openssl/evp.h>
+#include <openssl/err.h>
#include <jni.h>
#include "org_apache_security_juice_provider_JDKMessageDigestOpenSSL.h"
@@ -24,9 +41,9 @@
digest = EVP_get_digestbyname(str);
if(!digest) {
- fprintf(stderr,"Digest algorithm not found %s\n", str);
- (*env)->ReleaseStringUTFChars(env, digestName, str);
- return 0L;
+ fprintf(stderr,"Digest algorithm not found %s\n", str);
+ (*env)->ReleaseStringUTFChars(env, digestName, str);
+ return 0L;
}
(*env)->ReleaseStringUTFChars(env, digestName, str);
@@ -63,9 +80,9 @@
(*env)->ReleaseByteArrayElements(env, data, inBytes, 0);
if (ret == 0) {
- fprintf(stderr,"Digesting bytes failed\n");
- ERR_print_errors_fp(stderr);
- return -1;
+ fprintf(stderr,"Digesting bytes failed\n");
+ ERR_print_errors_fp(stderr);
+ return -1;
}
return length;
}
@@ -91,8 +108,8 @@
ret = EVP_DigestFinal_ex(ctx, outBytes, NULL);
(*env)->ReleaseByteArrayElements(env, hashOut, outBytes, 0);
if (ret == 0) {
- fprintf(stderr,"Finalizing bytes failed\n");
- ERR_print_errors_fp(stderr);
+ fprintf(stderr,"Finalizing bytes failed\n");
+ ERR_print_errors_fp(stderr);
return -1;
}
return EVP_MD_CTX_size(ctx);
Modified: incubator/juice/native/src/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/Makefile.am?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/Makefile.am (original)
+++ incubator/juice/native/src/Makefile.am Tue Feb 21 01:49:03 2006
@@ -10,13 +10,15 @@
org_apache_security_juice_provider_JCEBlockCipherOpenSSL.h \
org_apache_security_juice_provider_JCERSACipherOpenSSL.h \
org_apache_security_juice_provider_JDKDSASignerOpenSSL.h \
- org_apache_security_juice_provider_JDKMessageDigestOpenSSL.h
+ org_apache_security_juice_provider_JDKMessageDigestOpenSSL.h \
+ org_apache_security_juice_provider_SecureRandomOpenSSL.h
libopenSSL4Java_la_SOURCES = InitializeOpenSSL.c \
JCEBlockCipherOpenSSL.c \
JCERSACipherOpenSSL.c \
JDKDSASignerOpenSSL.c \
- JDKMessageDigestOpenSSL.c
+ JDKMessageDigestOpenSSL.c \
+ SecureRandomOpenSSL.c
Added: incubator/juice/native/src/SecureRandomOpenSSL.c
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/SecureRandomOpenSSL.c?rev=379402&view=auto
==============================================================================
--- incubator/juice/native/src/SecureRandomOpenSSL.c (added)
+++ incubator/juice/native/src/SecureRandomOpenSSL.c Tue Feb 21 01:49:03 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2002-2006 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
+ * imitations under the License.
+ */
+
+#include <openssl/rand.h>
+#include <jni.h>
+#include "org_apache_security_juice_provider_SecureRandomOpenSSL.h"
+
+/*
+ * Class: org_apache_security_juice_provider_SecureRandomOpenSSL
+ * Method: getBytes
+ * Signature: ([BI)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_security_juice_provider_SecureRandomOpenSSL_getBytes
+ (JNIEnv *env, jobject jobj, jbyteArray out, jint length) {
+
+ jbyte *holderBytes = (*env)->GetByteArrayElements(env, out, 0);
+ if(!RAND_bytes(holderBytes, length)) {
+ //throws an exception
+ return -1;
+ }
+ (*env)->ReleaseByteArrayElements(env, out, holderBytes, 0);
+ return 0;
+}
+
+/*
+ * Class: org_apache_security_juice_provider_SecureRandomOpenSSL
+ * Method: setSeed
+ * Signature: ([BI)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_security_juice_provider_SecureRandomOpenSSL_setSeed
+ (JNIEnv *env, jobject jobj, jbyteArray seed, jint length) {
+
+ jbyte *holderBytes = (*env)->GetByteArrayElements(env, seed, 0);
+ RAND_seed(holderBytes, length);
+ (*env)->ReleaseByteArrayElements(env, seed, holderBytes, 0);
+
+}
Modified: incubator/juice/native/src/org_apache_security_juice_provider_InitializeOpenSSL.h
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/org_apache_security_juice_provider_InitializeOpenSSL.h?rev=379402&r1=379401&r2=379402&view=diff
==============================================================================
--- incubator/juice/native/src/org_apache_security_juice_provider_InitializeOpenSSL.h (original)
+++ incubator/juice/native/src/org_apache_security_juice_provider_InitializeOpenSSL.h Tue Feb 21 01:49:03 2006
@@ -12,14 +12,6 @@
/* Inaccessible static: synchObject */
/*
* Class: org_apache_security_juice_provider_InitializeOpenSSL
- * Method: getNumLocks
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_apache_security_juice_provider_InitializeOpenSSL_getNumLocks
- (JNIEnv *, jobject);
-
-/*
- * Class: org_apache_security_juice_provider_InitializeOpenSSL
* Method: initializeOpenSSL
* Signature: ()I
*/
Added: incubator/juice/native/src/org_apache_security_juice_provider_SecureRandomOpenSSL.h
URL: http://svn.apache.org/viewcvs/incubator/juice/native/src/org_apache_security_juice_provider_SecureRandomOpenSSL.h?rev=379402&view=auto
==============================================================================
--- incubator/juice/native/src/org_apache_security_juice_provider_SecureRandomOpenSSL.h (added)
+++ incubator/juice/native/src/org_apache_security_juice_provider_SecureRandomOpenSSL.h Tue Feb 21 01:49:03 2006
@@ -0,0 +1,33 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_apache_security_juice_provider_SecureRandom */
+
+#ifndef _Included_org_apache_security_juice_provider_SecureRandom
+#define _Included_org_apache_security_juice_provider_SecureRandom
+#ifdef __cplusplus
+extern "C" {
+#endif
+/* Inaccessible static: log */
+/* Inaccessible static: openSSL4Ready */
+/* Inaccessible static: openSSLLoaded */
+/* Inaccessible static: class_000240 */
+/*
+ * Class: org_apache_security_juice_provider_SecureRandom
+ * Method: getBytes
+ * Signature: ([BI)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_security_juice_provider_SecureRandom_getBytes
+ (JNIEnv *, jobject, jbyteArray, jint);
+
+/*
+ * Class: org_apache_security_juice_provider_SecureRandom
+ * Method: setSeed
+ * Signature: ([BI)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_security_juice_provider_SecureRandom_setSeed
+ (JNIEnv *, jobject, jbyteArray, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: juice-svn-unsubscribe@xml.apache.org
For additional commands, e-mail: juice-svn-help@xml.apache.org