harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r987613 - in /harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main: java/org/apache/harmony/xnet/provider/jsse/ native/jsse/shared/ native/jsse/unix/
Date Fri, 20 Aug 2010 19:39:00 GMT
Author: odeakin
Date: Fri Aug 20 19:39:00 2010
New Revision: 987613

URL: http://svn.apache.org/viewvc?rev=987613&view=rev
Log:
Apply slightly modified x-net-2.patch patch for HARMONY-6627 ([classlib][x-net] Creating a
JSSE provider based on OpenSSL) - I changed some tabs to spaces and implemented available()
using the existing INetworkSystem interface in luni.

Modified:
    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/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
    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/unix/exports.txt

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.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/SSLSocketImpl.java?rev=987613&r1=987612&r2=987613&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java
Fri Aug 20 19:39:00 2010
@@ -17,9 +17,7 @@
 
 package org.apache.harmony.xnet.provider.jsse;
 
-import org.apache.harmony.xnet.provider.jsse.AlertException;
 import org.apache.harmony.xnet.provider.jsse.SSLSocketOutputStream;
-import org.apache.harmony.xnet.provider.jsse.SSLStreamedInput;
 import org.apache.harmony.xnet.provider.jsse.SSLSessionImpl;
 
 import java.io.FileDescriptor;
@@ -33,11 +31,12 @@ import java.net.UnknownHostException;
 import java.util.ArrayList;
 import javax.net.ssl.HandshakeCompletedEvent;
 import javax.net.ssl.HandshakeCompletedListener;
-import javax.net.ssl.SSLEngineResult;
-import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocket;
 
+import org.apache.harmony.luni.platform.INetworkSystem;
+import org.apache.harmony.luni.platform.Platform;
+
 /**
  * SSLSocket implementation.
  * @see javax.net.ssl.SSLSocket class documentation for more information.
@@ -47,6 +46,8 @@ public class SSLSocketImpl extends SSLSo
     // indicates if handshake has been started
     private boolean handshake_started = false;
 
+    protected static INetworkSystem netImpl = Platform.getNetworkSystem();
+
     // application data input stream, this stream is presented by
     // ssl socket as an input stream. Additionaly this object is a
     // place where application data will be stored by record protocol
@@ -594,16 +595,10 @@ public class SSLSocketImpl extends SSLSo
     }
 
     // -----------------------------------------------------------------
+ 
+    private native int readAppDataImpl(long ssl, byte[] data, int off, int len);
 
-    private native byte needAppDataImpl(long ssl);
-
-    /**
-     * This method is called by SSLSocketInputStream class
-     * when client application tryes to read application data from
-     * the stream, but there is no data in its underlying buffer.
-     * @throws  IOException
-     */
-    protected byte needAppData() throws IOException {
+    protected int readAppData(byte[] data, int off, int len) throws IOException {
         if (!handshake_started) {
             startHandshake();
         }
@@ -612,14 +607,13 @@ public class SSLSocketImpl extends SSLSo
             logger.println("SSLSocket.needAppData..");
         }
 
-        byte data = needAppDataImpl(SSL);
-        if (data == -1) {
-            appDataIS.setEnd();
-        }
-        return data;
+        return readAppDataImpl(SSL, data, off, len);
     }
-
-
+  
+    protected int available() throws IOException {
+        return netImpl.availableStream(impl.getFileDescriptor());
+    }
+    
     private native void writeAppDataImpl(long SSL, byte[] data, int offset, int len);
     /**
      * This method is called by SSLSocketOutputStream when client application

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.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/SSLSocketInputStream.java?rev=987613&r1=987612&r2=987613&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
Fri Aug 20 19:39:00 2010
@@ -17,12 +17,10 @@
 
 package org.apache.harmony.xnet.provider.jsse;
 
-import org.apache.harmony.xnet.provider.jsse.AlertException;
 import org.apache.harmony.xnet.provider.jsse.SSLSocketImpl;
 
 import java.io.IOException;
 import java.io.InputStream;
-import javax.net.ssl.SSLException;
 
 /**
  * This class provides input data stream functionality
@@ -32,27 +30,9 @@ import javax.net.ssl.SSLException;
 public final class SSLSocketInputStream
         extends InputStream {
 
-    // The size of the internal data buffer.
-    // It should not be less than maximum data chunk enclosed
-    // in one ssl packet.
-    private int size = SSLRecordProtocol.MAX_DATA_LENGTH;
-
-    // Internal buffer accumulating the received application data
-    private byte[] buffer = new byte[size];
-
-    // position of the next byte to read from the buffer
-    private int pos;
-
-    // position of the last byte to read + 1
-    private int end;
-
     // the ssl socket owning the stream
     private final SSLSocketImpl owner;
-
-    // the flag indicating that the end of the (owner's) input stream
-    // has been reached
-    private boolean end_reached = false;
-
+    
     /**
      * Creates the application data input stream for specified socket.
      * @param   owner the socket which will provide this input stream
@@ -62,18 +42,7 @@ public final class SSLSocketInputStream
         this.owner = owner;
     }
 
-    // The helper delivering the application data from the record layer
-    protected Adapter dataPoint = new Adapter();
-
-    /**
-     * Tells to the stream that the end of the income data has
-     * been reached.
-     */
-    protected void setEnd() {
-        end_reached = true;
-    }
-
-    // ------------------ InputStream implementetion -------------------
+    // ------------------ InputStream implementation -------------------
 
     /**
      * Returns the number of bytes available for reading without blocking.
@@ -82,7 +51,7 @@ public final class SSLSocketInputStream
      */
     @Override
     public int available() throws IOException {
-        return end - pos;
+        return owner.available();
     }
 
     /**
@@ -91,7 +60,6 @@ public final class SSLSocketInputStream
      */
     @Override
     public void close() throws IOException {
-        buffer = null;
     }
 
     /**
@@ -103,19 +71,15 @@ public final class SSLSocketInputStream
      */
     @Override
     public int read() throws IOException {
-        if (buffer == null) {
-            throw new IOException("Stream was closed.");
+        byte[] data = new byte[1];
+        int ret = read(data, 0, 1);
+        if (ret == 1) {
+            return (data[0] & 0xFF);
+        } else if (ret == 0) {
+            return -1;
+        } else {
+            throw new IOException();
         }
-        while (pos == end) {
-            if (end_reached) {
-                return -1;
-            }
-            // If there is no data in the buffer
-            // - will block untill the data will be provided by
-            // record layer
-            buffer[end++] = owner.needAppData();
-        }
-        return buffer[pos++];
     }
 
     /**
@@ -133,16 +97,7 @@ public final class SSLSocketInputStream
      */
     @Override
     public int read(byte[] b, int off, int len) throws IOException {
-        int read_b;
-        int i = 0;
-        do {
-            if ((read_b = read()) == -1) {
-                return (i == 0) ? -1 : i;
-            }
-            b[off+i] = (byte) read_b;
-            i++;
-        } while ((available() != 0) && (i<len));
-        return i;
+        return owner.readAppData(b, off, len);
     }
 
     /**
@@ -161,40 +116,5 @@ public final class SSLSocketInputStream
         }
         return i;
     }
-
-    // The helper class devivering the application data from the record layer
-    // to this input stream.
-    // It 'adapts' the InputStream interface to Appendable, which is used for
-    // transmition of income data from the record protocol to its clients.
-    private class Adapter implements org.apache.harmony.xnet.provider.jsse.Appendable {
-        /**
-         * Appends the data to the stream.
-         * This method could be implemented in the outer class
-         * itself, but it could be insecure.
-         */
-        public void append(byte[] src) {
-            int length = src.length;
-            if (size - (end - pos) < length) {
-                // If the size of the buffer is greater than or equals to
-                // SSLRecordProtocol.MAX_DATA_LENGTH this situation will
-                // happen iff:
-                // 1. the length of received data fragment is greater
-                // than allowed by the spec
-                // 2. it is rehandhaking stage and we have got several
-                // extra app data messages.
-                // In any case it is better to throw alert exception.
-                throw new AlertException(AlertProtocol.INTERNAL_ERROR,
-                        new SSLException("Could not accept income app data."));
-            }
-            if (end + length > size) {
-                // move the content of the buffer to the beginnig
-                System.arraycopy(buffer, pos, buffer, 0, end-pos);
-                end -= pos;
-                pos = 0;
-            }
-            System.arraycopy(src, 0, buffer, end, length);
-            end = end + length;
-        }
-    }
 }
 

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=987613&r1=987612&r2=987613&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
Fri Aug 20 19:39:00 2010
@@ -128,21 +128,24 @@ JNIEXPORT void JNICALL Java_org_apache_h
     free(buffer);
 }
 
-JNIEXPORT jbyte JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_needAppDataImpl
-  (JNIEnv *env, jclass clazz, jlong jssl) {
+JNIEXPORT jint JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_readAppDataImpl
+  (JNIEnv *env, jclass clazz, jlong jssl, jbyteArray data, jint offset, jint len) {
     SSL *ssl = jlong2addr(SSL, jssl);
     int ret;
-    jbyte data;
 
-    ret = SSL_read(ssl, (void *)&data, 1);
+    jbyte *buffer = (jbyte*) malloc(len * sizeof(jbyte*));
+
+    ret = SSL_read(ssl, (void *)buffer, (int)len);
     if (ret == -1) {
         // The socket has been closed
         jclass exception = (*env)->FindClass(env, "java/net/SocketException");
         (*env)->ThrowNew(env, exception, "Connection was reset");
         return -1;
     }
-
-    return data;
+    
+    (*env)->SetByteArrayRegion(env, data, offset, ret, buffer);
+    free(buffer);
+    return ret;
 }
 
 JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_closeImpl

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=987613&r1=987612&r2=987613&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
Fri Aug 20 19:39:00 2010
@@ -31,8 +31,8 @@ JNIEXPORT void JNICALL Java_org_apache_h
   (JNIEnv *, jclass, jlong, jobject);
 JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_writeAppDataImpl
   (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
-JNIEXPORT jbyte JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_needAppDataImpl
-  (JNIEnv *, jclass, jlong);
+JNIEXPORT jint JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_readAppDataImpl
+  (JNIEnv *, jclass, jlong, jbyteArray, jint, jint);
 JNIEXPORT void JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_closeImpl
   (JNIEnv *, jclass, jlong);
 

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=987613&r1=987612&r2=987613&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
Fri Aug 20 19:39:00 2010
@@ -8,6 +8,6 @@ Java_org_apache_harmony_xnet_provider_js
 Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslAcceptImpl
 Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_sslConnectImpl
 Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_writeAppDataImpl
-Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_needAppDataImpl
+Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_readAppDataImpl
 Java_org_apache_harmony_xnet_provider_jsse_SSLSocketImpl_closeImpl
 Java_org_apache_harmony_xnet_provider_jsse_SSLEngineImpl_initImpl



Mime
View raw message