< prev index next >

src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/SSLDelegate.java

Print this page

        

@@ -26,12 +26,10 @@
 package jdk.incubator.http;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.SocketChannel;
-import java.util.Arrays;
-import java.util.List;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
 import javax.net.ssl.SSLEngineResult.Status;
 import javax.net.ssl.*;

@@ -39,64 +37,60 @@
 import jdk.incubator.http.internal.common.Utils;
 import static javax.net.ssl.SSLEngineResult.HandshakeStatus.*;
 
 /**
  * Implements the mechanics of SSL by managing an SSLEngine object.
- * One of these is associated with each SSLConnection.
+ * <p>
+ * This class is only used to implement the {@link
+ * AbstractAsyncSSLConnection.SSLConnectionChannel} which is handed of
+ * to RawChannelImpl when creating a WebSocket.
  */
 class SSLDelegate {
 
     final SSLEngine engine;
     final EngineWrapper wrapper;
     final Lock handshaking = new ReentrantLock();
-    final SSLParameters sslParameters;
     final SocketChannel chan;
-    final HttpClientImpl client;
-    final String serverName;
 
-    SSLDelegate(SSLEngine eng, SocketChannel chan, HttpClientImpl client, String sn)
+    SSLDelegate(SSLEngine eng, SocketChannel chan)
     {
         this.engine = eng;
         this.chan = chan;
-        this.client = client;
         this.wrapper = new EngineWrapper(chan, engine);
-        this.sslParameters = engine.getSSLParameters();
-        this.serverName = sn;
     }
 
     // alpn[] may be null
-    SSLDelegate(SocketChannel chan, HttpClientImpl client, String[] alpn, String sn)
-        throws IOException
-    {
-        serverName = sn;
-        SSLContext context = client.sslContext();
-        engine = context.createSSLEngine();
-        engine.setUseClientMode(true);
-        SSLParameters sslp = client.sslParameters()
-                                   .orElseGet(context::getSupportedSSLParameters);
-        sslParameters = Utils.copySSLParameters(sslp);
-        if (sn != null) {
-            SNIHostName sni = new SNIHostName(sn);
-            sslParameters.setServerNames(List.of(sni));
-        }
-        if (alpn != null) {
-            sslParameters.setApplicationProtocols(alpn);
-            Log.logSSL("SSLDelegate: Setting application protocols: {0}" + Arrays.toString(alpn));
-        } else {
-            Log.logSSL("SSLDelegate: No application protocols proposed");
-        }
-        engine.setSSLParameters(sslParameters);
-        wrapper = new EngineWrapper(chan, engine);
-        this.chan = chan;
-        this.client = client;
-    }
-
-    SSLParameters getSSLParameters() {
-        return sslParameters;
-    }
+//    SSLDelegate(SocketChannel chan, HttpClientImpl client, String[] alpn, String sn)
+//        throws IOException
+//    {
+//        serverName = sn;
+//        SSLContext context = client.sslContext();
+//        engine = context.createSSLEngine();
+//        engine.setUseClientMode(true);
+//        SSLParameters sslp = client.sslParameters();
+//        sslParameters = Utils.copySSLParameters(sslp);
+//        if (sn != null) {
+//            SNIHostName sni = new SNIHostName(sn);
+//            sslParameters.setServerNames(List.of(sni));
+//        }
+//        if (alpn != null) {
+//            sslParameters.setApplicationProtocols(alpn);
+//            Log.logSSL("SSLDelegate: Setting application protocols: {0}" + Arrays.toString(alpn));
+//        } else {
+//            Log.logSSL("SSLDelegate: No application protocols proposed");
+//        }
+//        engine.setSSLParameters(sslParameters);
+//        wrapper = new EngineWrapper(chan, engine);
+//        this.chan = chan;
+//        this.client = client;
+//    }
+
+//    SSLParameters getSSLParameters() {
+//        return sslParameters;
+//    }
 
-    private static long countBytes(ByteBuffer[] buffers, int start, int number) {
+    static long countBytes(ByteBuffer[] buffers, int start, int number) {
         long c = 0;
         for (int i=0; i<number; i++) {
             c+= buffers[start+i].remaining();
         }
         return c;

@@ -189,11 +183,12 @@
      */
     class EngineWrapper {
 
         SocketChannel chan;
         SSLEngine engine;
-        Object wrapLock, unwrapLock;
+        final Object wrapLock;
+        final Object unwrapLock;
         ByteBuffer unwrap_src, wrap_dst;
         boolean closed = false;
         int u_remaining; // the number of bytes left in unwrap_src after an unwrap()
 
         EngineWrapper (SocketChannel chan, SSLEngine engine) {

@@ -203,12 +198,12 @@
             unwrapLock = new Object();
             unwrap_src = allocate(BufType.PACKET);
             wrap_dst = allocate(BufType.PACKET);
         }
 
-        void close () throws IOException {
-        }
+//        void close () throws IOException {
+//        }
 
         WrapperResult wrapAndSend(ByteBuffer src, boolean ignoreClose)
             throws IOException
         {
             ByteBuffer[] buffers = new ByteBuffer[1];

@@ -318,15 +313,15 @@
             u_remaining = unwrap_src.remaining();
             return r;
         }
     }
 
-    WrapperResult sendData (ByteBuffer src) throws IOException {
-        ByteBuffer[] buffers = new ByteBuffer[1];
-        buffers[0] = src;
-        return sendData(buffers, 0, 1);
-    }
+//    WrapperResult sendData (ByteBuffer src) throws IOException {
+//        ByteBuffer[] buffers = new ByteBuffer[1];
+//        buffers[0] = src;
+//        return sendData(buffers, 0, 1);
+//    }
 
     /**
      * send the data in the given ByteBuffer. If a handshake is needed
      * then this is handled within this method. When this call returns,
      * all of the given user data has been sent and any handshake has been

@@ -405,11 +400,11 @@
      * on the wrapper methods being idempotent. eg. if wrapAndSend()
      * is called with no data to send then there must be no problem
      */
     @SuppressWarnings("fallthrough")
     void doHandshake (HandshakeStatus hs_status) throws IOException {
-        boolean wasBlocking = false;
+        boolean wasBlocking;
         try {
             wasBlocking = chan.isBlocking();
             handshaking.lock();
             chan.configureBlocking(true);
             ByteBuffer tmp = allocate(BufType.APPLICATION);

@@ -451,33 +446,33 @@
         } finally {
             handshaking.unlock();
         }
     }
 
-    static void printParams(SSLParameters p) {
-        System.out.println("SSLParameters:");
-        if (p == null) {
-            System.out.println("Null params");
-            return;
-        }
-        for (String cipher : p.getCipherSuites()) {
-                System.out.printf("cipher: %s\n", cipher);
-        }
-        // JDK 8 EXCL START
-        for (String approto : p.getApplicationProtocols()) {
-                System.out.printf("application protocol: %s\n", approto);
-        }
-        // JDK 8 EXCL END
-        for (String protocol : p.getProtocols()) {
-                System.out.printf("protocol: %s\n", protocol);
-        }
-        if (p.getServerNames() != null) {
-            for (SNIServerName sname : p.getServerNames()) {
-                System.out.printf("server name: %s\n", sname.toString());
-            }
-        }
-    }
+//    static void printParams(SSLParameters p) {
+//        System.out.println("SSLParameters:");
+//        if (p == null) {
+//            System.out.println("Null params");
+//            return;
+//        }
+//        for (String cipher : p.getCipherSuites()) {
+//                System.out.printf("cipher: %s\n", cipher);
+//        }
+//        // JDK 8 EXCL START
+//        for (String approto : p.getApplicationProtocols()) {
+//                System.out.printf("application protocol: %s\n", approto);
+//        }
+//        // JDK 8 EXCL END
+//        for (String protocol : p.getProtocols()) {
+//                System.out.printf("protocol: %s\n", protocol);
+//        }
+//        if (p.getServerNames() != null) {
+//            for (SNIServerName sname : p.getServerNames()) {
+//                System.out.printf("server name: %s\n", sname.toString());
+//            }
+//        }
+//    }
 
     String getSessionInfo() {
         StringBuilder sb = new StringBuilder();
         String application = engine.getApplicationProtocol();
         SSLSession sess = engine.getSession();
< prev index next >