harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r999394 - in /harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main: java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java native/jsse/shared/sslEngine.c native/jsse/shared/sslEngine.h native/jsse/unix/exports.txt
Date Tue, 21 Sep 2010 13:12:22 GMT
Author: odeakin
Date: Tue Sep 21 13:12:22 2010
New Revision: 999394

URL: http://svn.apache.org/viewvc?rev=999394&view=rev
Log:
Some slight behaviour changes, mainly for exception cases. This helps a couple of the failing
tests get a little further.

Modified:
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.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/SSLEngineImpl.java?rev=999394&r1=999393&r2=999394&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
Tue Sep 21 13:12:22 2010
@@ -48,6 +48,11 @@ public class SSLEngineImpl extends SSLEn
     // indicates if engine was shut down (it means that
     // all cleaning work had been done and the engine is not operable)
     private boolean engine_was_shutdown = false;
+    // indicates if close_notify alert had been sent to another peer
+    private boolean close_notify_was_sent = false;
+    // indicates if close_notify alert had been received from another peer
+    private boolean close_notify_was_received = false;
+    private boolean need_alert_wrap = false;
 
     // active session object
     private SSLSessionImpl session;
@@ -76,7 +81,7 @@ public class SSLEngineImpl extends SSLEn
     private static native HandshakeStatus acceptImpl(long ssl);
     private static native SSLEngineResult wrapImpl(long sslEngineAddress,
             long src_address, int src_len, long dst_address, int dst_len);
-    private static native SSLEngineResult unwrapImpl(long sslEngineAddress,
+    private static native SSLEngineResult unwrapImpl(long ssl, long sslEngineAddress,
             long src_address, int src_len, long dst_address, int dst_len);
     
     /**
@@ -117,6 +122,11 @@ public class SSLEngineImpl extends SSLEn
         if (!peer_mode_was_set) {
             throw new IllegalStateException("Client/Server mode was not set");
         }
+
+        if (!getEnableSessionCreation()) {
+            handshakeStatus = HandshakeStatus.NOT_HANDSHAKING;
+            throw new SSLException("New session creation is disabled");
+        }
         // TODO: need to repeat connect/accept if status was waiting on wrap/unwrap previously?
         if (!handshake_started) {
             handshake_started = true;
@@ -141,6 +151,7 @@ public class SSLEngineImpl extends SSLEn
         }
     }
 
+    private static native void shutdownImpl(long SSL);
     private static native void closeInboundImpl(long SSLEngineAddress);
 
     /**
@@ -158,18 +169,26 @@ public class SSLEngineImpl extends SSLEn
             return;
         }
         isInboundDone = true;
-
-        closeInboundImpl(SSLEngineAddress);
-
         engine_was_closed = true;
-        if (!handshake_started) {
+        if (handshake_started) {
+            if (!close_notify_was_received) {
+                if (session != null) {
+                    session.invalidate();
+                }
+                if (!close_notify_was_sent) {
+                    shutdownImpl(SSL);
+                    close_notify_was_sent = true;
+                }
+                need_alert_wrap = true;
+                throw new SSLException("Inbound is closed before close_notify alert has been
received.");                
+            }
+            closeInboundImpl(SSLEngineAddress);
+        } else {
             // engine is closing before initial handshake has been made
             shutdown();
         }
     }
 
-    private static native void closeOutboundImpl(long SSLEngineAddress);
-
     /**
      * Closes outbound operations of this engine
      * @see javax.net.ssl.SSLEngine#closeOutbound() method documentation
@@ -184,14 +203,19 @@ public class SSLEngineImpl extends SSLEn
             return;
         }
         isOutboundDone = true;
-        
-        closeOutboundImpl(SSLEngineAddress);
-
-        if (!handshake_started) {
+        engine_was_closed = true;
+        if (handshake_started) {
+            if (!close_notify_was_sent) {
+                if (!close_notify_was_sent) {
+                    shutdownImpl(SSL);
+                    close_notify_was_sent = true;
+                }
+                need_alert_wrap = true;
+            }
+        } else {
             // engine is closing before initial handshake has been made
             shutdown();
         }
-        engine_was_closed = true;
     }
 
     /**
@@ -367,6 +391,13 @@ public class SSLEngineImpl extends SSLEn
             // initial handshake has not been started yet
             return HandshakeStatus.NOT_HANDSHAKING;
         }
+        if (need_alert_wrap) {
+            return HandshakeStatus.NEED_WRAP;
+        }
+        if (close_notify_was_sent && !close_notify_was_received) {
+            // waiting for "close_notify" response
+            return HandshakeStatus.NEED_UNWRAP;
+        }
         return handshakeStatus;
     }
     
@@ -452,7 +483,7 @@ public class SSLEngineImpl extends SSLEn
             dst_address = AddressUtil.getDirectBufferAddress(dst_temp_buffer);
         }
         
-        SSLEngineResult result = unwrapImpl(SSLEngineAddress, src_address, src_length, dst_address,
dst_length);
+        SSLEngineResult result = unwrapImpl(SSL, SSLEngineAddress, src_address, src_length,
dst_address, dst_length);
         
         // update the buffers contents and positions
         src.position(src.position() + result.bytesConsumed());
@@ -512,6 +543,10 @@ public class SSLEngineImpl extends SSLEn
         if (!handshake_started) {
             beginHandshake();
         }
+
+        if (need_alert_wrap) {
+            need_alert_wrap = false;
+        }
         
         // get direct addresses to the buffers
         // only use the first buffer at the moment
@@ -562,8 +597,8 @@ public class SSLEngineImpl extends SSLEn
 
         return result;
     }
-    
-    // Shutdownes the engine and makes all cleanup work.
+
+    // Shutdown the engine and makes all cleanup work.
     private void shutdown() {
         engine_was_closed = true;
         engine_was_shutdown = true;

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c?rev=999394&r1=999393&r2=999394&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.c
Tue Sep 21 13:12:22 2010
@@ -193,7 +193,7 @@ JNIEXPORT jobject JNICALL Java_org_apach
 }
 
 JNIEXPORT jobject JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl
-  (JNIEnv *env, jclass clazz, jlong jsslengine, jlong src_address, int src_len, 
+  (JNIEnv *env, jclass clazz, jlong jssl, jlong jsslengine, jlong src_address, int src_len,

   jlong dst_address, int dst_len) {
     _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
     BIO *bio = sslengine->bio;
@@ -218,8 +218,11 @@ JNIEXPORT jobject JNICALL Java_org_apach
     }
     
     // read output data
-    read_result = BIO_read(bio, dst_buffer, dst_len);
+    //read_result = BIO_read(bio, dst_buffer, dst_len);
+    read_result = SSL_read(ssl, dst_buffer, dst_len);
     
+    // TODO: Check for  SSL_RECEIVED_SHUTDOWN
+
     if (read_result > 0) {
         // wrote some data so must not be handshaking
         handshake_state = handshake_not_handshaking;
@@ -254,14 +257,31 @@ JNIEXPORT jobject JNICALL Java_org_apach
     return result;  
 }
 
+void shutdownImpl(JNIEnv *env, SSL *ssl) {
+    int ret = SSL_shutdown(ssl);
+    if (ret == -1) {
+        jclass exception = (*env)->FindClass(env, "javax/net/ssl/SSLException");
+        (*env)->ThrowNew(env, exception, ERR_reason_error_string(ERR_get_error()));
+    }
+
+    if (ret == 0) {
+        ret = SSL_shutdown(ssl);
+        if (((ret == -1) && (SSL_get_error(ssl, ret) != SSL_ERROR_WANT_READ)) ||
(ret == 0)) {
+            jclass exception = (*env)->FindClass(env, "javax/net/ssl/SSLException");
+            (*env)->ThrowNew(env, exception, ERR_reason_error_string(ERR_get_error()));
+        }
+    }
+}
+
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_shutdownImpl
+  (JNIEnv *env, jclass clazz, jlong jssl) {
+    SSL *ssl = jlong2addr(SSL, jssl);
+    shutdownImpl(env, ssl);
+}
+
 JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
   (JNIEnv *env, jclass clazz, jlong jsslengine) {
     _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
     BIO_shutdown_wr(sslengine->bio_io);
 }
 
-JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl
-  (JNIEnv *env, jclass clazz, jlong jsslengine) {
-    _sslengine *sslengine = jlong2addr(_sslengine, jsslengine);
-    BIO_shutdown_wr(sslengine->bio);
-}

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h?rev=999394&r1=999393&r2=999394&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslEngine.h
Tue Sep 21 13:12:22 2010
@@ -34,10 +34,10 @@ JNIEXPORT jobject JNICALL Java_org_apach
 JNIEXPORT jobject JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_wrapImpl
   (JNIEnv *, jclass, jlong, jlong, int, jlong, int);
 JNIEXPORT jobject JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl
-  (JNIEnv *, jclass, jlong, jlong, int, jlong, int);
-JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
+  (JNIEnv *, jclass, jlong, jlong, jlong, int, jlong, int);
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_shutdownImpl
   (JNIEnv *, jclass, jlong);
-JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl
+JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
   (JNIEnv *, jclass, jlong);
 
 #ifdef __cplusplus

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt?rev=999394&r1=999393&r2=999394&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/unix/exports.txt
Tue Sep 21 13:12:22 2010
@@ -21,4 +21,4 @@ Java_org_apache_harmony_xnet_provider_js
 Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_wrapImpl
 Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_unwrapImpl
 Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeInboundImpl
-Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_closeOutboundImpl
+Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_shutdownImpl



Mime
View raw message