Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 34050 invoked from network); 9 Aug 2010 16:32:10 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Aug 2010 16:32:10 -0000 Received: (qmail 44349 invoked by uid 500); 9 Aug 2010 16:32:10 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 44263 invoked by uid 500); 9 Aug 2010 16:32:09 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 44256 invoked by uid 99); 9 Aug 2010 16:32:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 16:32:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 16:32:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 624E323889ED; Mon, 9 Aug 2010 16:30:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r983717 - in /harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main: java/org/apache/harmony/xnet/provider/jsse/ native/jsse/shared/ native/jsse/windows/ Date: Mon, 09 Aug 2010 16:30:50 -0000 To: commits@harmony.apache.org From: odeakin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100809163050.624E323889ED@eris.apache.org> Author: odeakin Date: Mon Aug 9 16:30:49 2010 New Revision: 983717 URL: http://svn.apache.org/viewvc?rev=983717&view=rev Log: Making a few changes: - Set callback for random number functions to point to my own stubs (to be replaced later). - Move SSL initialisation to init() method of SSLSocketImpl so parameters can be changed before connection. - Add implementation to change enabled protocols. Added: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/jsse_rand.c (with props) harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/jsse_rand.h (with props) Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslParameters.c harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslParameters.h harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.c harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.h harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/windows/makefile Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java?rev=983717&r1=983716&r2=983717&view=diff ============================================================================== --- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java (original) +++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java Mon Aug 9 16:30:49 2010 @@ -72,8 +72,13 @@ public class SSLParameters { // string representations of available cipher suites private String[] enabledCipherSuiteNames = null; - // protocols available for SSL connection - private String[] enabledProtocols = ProtocolVersion.supportedProtocols; + // protocols suported and those enabled for SSL connection + private static String[] supportedProtocols = new String[] { "SSLv2", "SSLv3", "TLSv1" }; + private static int[] protocolFlags = new int[] { 1, 2, 4 }; // These correspond to the flags used in the natives + + // Enable all protocols by default + private String[] enabledProtocols = supportedProtocols; + private int enabledProtocolsFlags = 7; // TLSv1 & SSLv3 & SSLv2 // if the peer with this parameters tuned to work in client mode private boolean client_mode = true; @@ -84,8 +89,9 @@ public class SSLParameters { // if the peer with this parameters allowed to cteate new SSL session private boolean enable_session_creation = true; + // Native address of the OpenSSL SSL_CTX struct - private static long SSL_CTX = 0; + private long SSL_CTX = 0; static { System.loadLibrary("hyjsse"); @@ -312,10 +318,19 @@ public class SSLParameters { /** * @return the set of enabled protocols */ + protected String[] getSupportedProtocols() { + return supportedProtocols.clone(); + } + + /** + * @return the set of enabled protocols + */ protected String[] getEnabledProtocols() { return enabledProtocols.clone(); } + private static native void setEnabledProtocolsImpl(long context, int flags); + /** * Sets the set of available protocols for use in SSL connection. * @param suites: String[] @@ -324,13 +339,26 @@ public class SSLParameters { if (protocols == null) { throw new IllegalArgumentException("Provided parameter is null"); } + + int flags = 0; + protocolsLoop: for (int i=0; i +#include "jni.h" +#include "openssl/rand.h" + +void randSeed(const void *buf, int num); +int randBytes(unsigned char *buf, int num); +void randCleanup(void); +void randAdd(const void *buf, int num, double entropy); +int randPseudoBytes(unsigned char *buf, int num); +int randStatus(void); + +JavaVM *javaVM; + +RAND_METHOD *getRandMethod(JavaVM *jvm) { + RAND_METHOD *randMethod = malloc(sizeof(RAND_METHOD)); + randMethod->seed = &randSeed; + randMethod->bytes = &randBytes; + randMethod->cleanup = &randCleanup; + randMethod->add = &randAdd; + randMethod->pseudorand = &randPseudoBytes; + randMethod->status = &randStatus; + + javaVM = jvm; + + return randMethod; +} + +void randSeed(const void *buf, int num) { + printf("randSeed with num=%d and javaVM=%p\n", num, javaVM); + + //(*javaVM)->GetEnv(javaVM, (void**)&env, JNI_VERSION_1_4); + + return; +} + +int randBytes(unsigned char *buf, int num) { + int i; + printf("randBytes with num=%d and javaVM=%p\n", num, javaVM); + for (i=0; iGetJavaVM(env, &jvm); + randMethod = getRandMethod(jvm); + RAND_set_rand_method(randMethod); return (jlong)context; } + +JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLParameters_setEnabledProtocolsImpl + (JNIEnv *env, jclass clazz, jlong context, jint flags) +{ + SSL_CTX *ctx = (SSL_CTX*)context; + long options = 0; + long mask = SSL_OP_NO_TLSv1 | SSL_OP_NO_SSLv3 | SSL_OP_NO_SSLv2; + + if (flags & PROTOCOL_TLSv1) { + options |= SSL_OP_NO_TLSv1; + } + if (flags & PROTOCOL_SSLv3) { + options |= SSL_OP_NO_SSLv3; + } + if (flags & PROTOCOL_SSLv2) { + options |= SSL_OP_NO_SSLv2; + } + + // Clearing the options enables the protocol, setting disables + SSL_CTX_clear_options(ctx, options); + SSL_CTX_set_options(ctx, options ^ mask); +} Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslParameters.h URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslParameters.h?rev=983717&r1=983716&r2=983717&view=diff ============================================================================== --- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslParameters.h (original) +++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslParameters.h Mon Aug 9 16:30:49 2010 @@ -17,16 +17,22 @@ #include -#ifndef _CONTEXT_H -#define _CONTEXT_H +#ifndef _SSLPARAMETERS_H +#define _SSLPARAMETERS_H #ifdef __cplusplus extern "C" { #endif +// Protocol flags - these correspond to the flags used in SSLParameters.java +#define PROTOCOL_SSLv2 1 +#define PROTOCOL_SSLv3 2 +#define PROTOCOL_TLSv1 4 + JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLParameters_initialiseContext (JNIEnv *, jclass, jobjectArray, jbyteArray, jbyteArray); - +JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLParameters_setEnabledProtocolsImpl + (JNIEnv *, jclass, jlong, jint); #ifdef __cplusplus } Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.c URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.c?rev=983717&r1=983716&r2=983717&view=diff ============================================================================== --- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.c (original) +++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.c Mon Aug 9 16:30:49 2010 @@ -58,16 +58,18 @@ jlong getFD(JNIEnv * env, jobject fd) { #endif } +JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_initImpl + (JNIEnv *env, jclass clazz, jlong context) { + return (jlong)SSL_new((SSL_CTX*)context); +} -JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslAcceptImpl - (JNIEnv *env, jclass clazz, jlong context, jobject fd) { +JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslAcceptImpl + (JNIEnv *env, jclass clazz, jlong jssl, jobject fd) { jlong socket = getFD(env, fd); - SSL *ssl; + SSL *ssl = (SSL*)jssl; BIO *bio; int ret; - SSL_CTX *ctx = (SSL_CTX*)context; - ssl = SSL_new(ctx); bio = BIO_new_socket((int)socket, BIO_NOCLOSE); SSL_set_bio(ssl, bio, bio); @@ -82,19 +84,15 @@ JNIEXPORT jlong JNICALL Java_org_apache_ jclass exception = (*env)->FindClass(env, "javax/net/ssl/SSLHandshakeException"); (*env)->ThrowNew(env, exception, ERR_reason_error_string(ERR_get_error())); } - - return (jlong)ssl; } -JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslConnectImpl - (JNIEnv *env, jclass clazz, jlong context, jobject fd) { +JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslConnectImpl + (JNIEnv *env, jclass clazz, jlong jssl, jobject fd) { jlong socket = getFD(env, fd); - SSL *ssl; + SSL *ssl = (SSL*)jssl; BIO *bio; int ret; - SSL_CTX *ctx = (SSL_CTX*)context; - ssl = SSL_new(ctx); bio = BIO_new_socket((int)socket, BIO_NOCLOSE); SSL_set_bio(ssl, bio, bio); @@ -109,8 +107,6 @@ JNIEXPORT jlong JNICALL Java_org_apache_ jclass exception = (*env)->FindClass(env, "javax/net/ssl/SSLHandshakeException"); (*env)->ThrowNew(env, exception, ERR_reason_error_string(ERR_get_error())); } - - return (jlong)ssl; } JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_writeAppDataImpl Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.h URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.h?rev=983717&r1=983716&r2=983717&view=diff ============================================================================== --- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.h (original) +++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSocket.h Mon Aug 9 16:30:49 2010 @@ -23,9 +23,11 @@ extern "C" { #endif -JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslAcceptImpl +JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_initImpl + (JNIEnv *, jclass, jlong); +JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslAcceptImpl (JNIEnv *, jclass, jlong, jobject); -JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslConnectImpl +JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslConnectImpl (JNIEnv *, jclass, jlong, jobject); JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_writeAppDataImpl (JNIEnv *, jclass, jlong, jbyteArray, jint, jint); Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/windows/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/windows/makefile?rev=983717&r1=983716&r2=983717&view=diff ============================================================================== --- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/windows/makefile (original) +++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/windows/makefile Mon Aug 9 16:30:49 2010 @@ -28,7 +28,8 @@ HYCFLAGS = $(HYCFLAGS) /I$(SHAREDSUB) /I HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def BUILDFILES = \ - $(SHAREDSUB)jsse_copyright.obj $(SHAREDSUB)sslParameters.obj $(SHAREDSUB)sslSocket.obj + $(SHAREDSUB)jsse_copyright.obj $(SHAREDSUB)sslParameters.obj $(SHAREDSUB)sslSocket.obj \ + $(SHAREDSUB)jsse_rand.obj VIRTFILES = hyjsse.res