test/sun/net/www/protocol/https/NewImpl/ComHostnameVerifier.java

Print this page




 169                 out.flush();
 170              } catch (IOException ie) {
 171                 ie.printStackTrace();
 172                 return;
 173              }
 174 
 175         } catch (Exception e) {
 176              e.printStackTrace();
 177              // write out error response
 178              out.writeBytes("HTTP/1.0 400 " + e.getMessage() + "\r\n");
 179              out.writeBytes("Content-Type: text/html\r\n\r\n");
 180              out.flush();
 181         } finally {
 182              // close the socket
 183              System.out.println("Server closing socket");
 184              sslSocket.close();
 185              serverReady = false;
 186         }
 187     }
 188 











 189     /*
 190      * Define the client side of the test.
 191      *
 192      * If the server prematurely exits, serverReady will be set to true
 193      * to avoid infinite hangs.
 194      */
 195     void doClientSide() throws Exception {
 196         /*
 197          * Wait for server to get started.
 198          */
 199         while (!serverReady) {
 200             Thread.sleep(50);
 201         }
 202 
 203         System.setProperty("java.protocol.handler.pkgs",
 204             "com.sun.net.ssl.internal.www.protocol");
 205 
 206         System.setProperty("https.cipherSuites",
 207                 "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
 208 
 209         // use the default hostname verifier
 210 
 211         URL url = new URL("https://" + "localhost:" + serverPort +
 212                                 "/etc/hosts");
 213         URLConnection urlc = url.openConnection();
 214 
 215         if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
 216             throw new Exception(
 217                 "URLConnection ! instanceof " +
 218                 "com.sun.net.ssl.HttpsURLConnection");
 219         }
 220 
 221         BufferedReader in = null;
 222         try {
 223             in = new BufferedReader(new InputStreamReader(
 224                                urlc.getInputStream()));




 169                 out.flush();
 170              } catch (IOException ie) {
 171                 ie.printStackTrace();
 172                 return;
 173              }
 174 
 175         } catch (Exception e) {
 176              e.printStackTrace();
 177              // write out error response
 178              out.writeBytes("HTTP/1.0 400 " + e.getMessage() + "\r\n");
 179              out.writeBytes("Content-Type: text/html\r\n\r\n");
 180              out.flush();
 181         } finally {
 182              // close the socket
 183              System.out.println("Server closing socket");
 184              sslSocket.close();
 185              serverReady = false;
 186         }
 187     }
 188 
 189     private static class ComSunHTTPSHandlerFactory implements URLStreamHandlerFactory {
 190         private static String SUPPORTED_PROTOCOL = "https";
 191 
 192         public URLStreamHandler createURLStreamHandler(String protocol) {
 193             if (!protocol.equalsIgnoreCase(SUPPORTED_PROTOCOL))
 194                 return null;
 195 
 196             return new com.sun.net.ssl.internal.www.protocol.https.Handler();
 197         }
 198     }
 199 
 200     /*
 201      * Define the client side of the test.
 202      *
 203      * If the server prematurely exits, serverReady will be set to true
 204      * to avoid infinite hangs.
 205      */
 206     void doClientSide() throws Exception {
 207         /*
 208          * Wait for server to get started.
 209          */
 210         while (!serverReady) {
 211             Thread.sleep(50);
 212         }
 213 
 214         URL.addURLStreamHandlerFactory(new ComSunHTTPSHandlerFactory());

 215 
 216         System.setProperty("https.cipherSuites",
 217                 "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
 218 
 219         // use the default hostname verifier
 220 
 221         URL url = new URL("https://" + "localhost:" + serverPort +
 222                                 "/etc/hosts");
 223         URLConnection urlc = url.openConnection();
 224 
 225         if (!(urlc instanceof com.sun.net.ssl.HttpsURLConnection)) {
 226             throw new Exception(
 227                 "URLConnection ! instanceof " +
 228                 "com.sun.net.ssl.HttpsURLConnection");
 229         }
 230 
 231         BufferedReader in = null;
 232         try {
 233             in = new BufferedReader(new InputStreamReader(
 234                                urlc.getInputStream()));