Package javax.net.ssl

Examples of javax.net.ssl.SSLContext


        super();
    }

    private static SSLContext createEasySSLContext() {
        try {
            SSLContext context = SSLContext.getInstance("SSL");
            context.init(
              null,
              new TrustManager[] {new EasyX509TrustManager(null)},
              null);
            return context;
        } catch (Exception e) {
View Full Code Here


    * SecurityDomain.
    */
   static SSLContext forDomain(SecurityDomain securityDomain)
      throws IOException
   {
      SSLContext sslCtx = null;
      try
      {
         sslCtx = SSLContext.getInstance("TLS");
         KeyManagerFactory keyMgr = securityDomain.getKeyManagerFactory();
         if( keyMgr == null )
            throw new IOException("KeyManagerFactory is null for security domain: "+securityDomain.getSecurityDomain());
         TrustManagerFactory trustMgr = securityDomain.getTrustManagerFactory();
         TrustManager[] trustMgrs = null;
         if( trustMgr != null )
            trustMgrs = trustMgr.getTrustManagers();
         sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null);
         return sslCtx;
      }
      catch(NoSuchAlgorithmException e)
      {
         log.error("Failed to get SSLContext for TLS algorithm", e);
View Full Code Here

      // Setup the test TrustManagerFactory.
      TrustManagerFactory trustMgr = TrustManagerFactory
          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
      trustMgr.init(keyStore);
      // Setup the test SSLSocketFactory.
      SSLContext sslCtx = SSLContext.getInstance("TLS");
      sslCtx.init(null, trustMgr.getTrustManagers(), null);
      ((HttpsURLConnection) conn).setSSLSocketFactory(sslCtx.getSocketFactory());     
    }
   
    // Connect to the remote HTTP server.
    log.debug("Connecting to URL: " + url);
    byte[] buffer = new byte[1024];
View Full Code Here

   }

   private String initServer() throws Exception
   {
      String httpsURL = null;
      SSLContext sslCtx = null;
      try
      {
         sslCtx = SSLContext.getInstance("TLS");
         ClassLoader loader = getClass().getClassLoader();
         URL keyStoreURL = loader.getResource("tst.keystore");
         if( keyStoreURL == null )
            throw new IOException("Failed to find resource tst.keystore");
         log.debug("Opening KeyStore: "+keyStoreURL);
         KeyStore keyStore = KeyStore.getInstance("JKS");
         InputStream is = keyStoreURL.openStream();
         keyStore.load(is, KEYSTORE_PASSWORD.toCharArray());
         String algorithm = KeyManagerFactory.getDefaultAlgorithm();
         KeyManagerFactory keyMgr = KeyManagerFactory.getInstance(algorithm);
         keyMgr.init(keyStore, KEYSTORE_PASSWORD.toCharArray());
         algorithm = TrustManagerFactory.getDefaultAlgorithm();
         TrustManagerFactory trustMgr = TrustManagerFactory.getInstance(algorithm);
         trustMgr.init(keyStore);
         TrustManager[] trustMgrs = trustMgr.getTrustManagers();
         sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null);
      }
      catch(Exception e)
      {
         log.error("Failed to init SSLContext", e);
         throw new IOException("Failed to get SSLContext for TLS algorithm");
      }

      ServerSocketFactory factory = sslCtx.getServerSocketFactory();
      ServerSocket serverSocket = factory.createServerSocket(0);
      getLog().debug("Created serverSocket: "+serverSocket);
      int port = serverSocket.getLocalPort();
      InetAddress addr = serverSocket.getInetAddress();
      httpsURL = "https://localhost:" + port + '/';
View Full Code Here

                       
                        public void checkServerTrusted(final X509Certificate[] certs, final String authType) { /* NOP */ }
                      }
                    };
                                         
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustAllCerts, null);
    return sslContext;
  }
View Full Code Here

 
  @Test
    public void testSSL() throws Exception {
     
     
      SSLContext sslContext = SSLTestContextFactory.getSSLContext();
     
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

        INonBlockingConnection tcpCon = new NonBlockingConnection("localhost", server.getLocalPort(), sslContext, true);
View Full Code Here

 
  @Test
    public void testHttpClientSSL() throws Exception {
       
       
        SSLContext sslContext = SSLTestContextFactory.getSSLContext();
       
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

       
View Full Code Here

                       
                        public void checkServerTrusted(final X509Certificate[] certs, final String authType) { /* NOP */ }
                      }
                    };
                                         
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustAllCerts, null);
    return sslContext;
  }
View Full Code Here

                       
                        public void checkServerTrusted(final X509Certificate[] certs, final String authType) { /* NOP */ }
                      }
                    };
                                         
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustAllCerts, null);
    return sslContext;
  }
View Full Code Here

                       
                        public void checkServerTrusted(final X509Certificate[] certs, final String authType) { /* NOP */ }
                      }
                    };
                                         
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustAllCerts, null);
    return sslContext;
  }
View Full Code Here

TOP

Related Classes of javax.net.ssl.SSLContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.