public void openConnection() throws IOException {
    try {
      connectionFactory.useSslProtocol();
    } catch (NoSuchAlgorithmException ex) {
      throw new IOException(ex.toString());
    } catch (KeyManagementException ex) {
      throw new IOException(ex.toString());
    }

    if (connection == null) {
      connection = connectionFactory.newConnection();
    }
  }
Beispiel #2
0
  private void setParam() {

    if (anon) {
      try {
        ctx.init(null, null, null);
      } catch (KeyManagementException e) {
        throw new AuthFailureException(e.toString());
      }
    } else {
      try {
        TrustManager[] myTM = new TrustManager[] {new MyX509TrustManager()};
        ctx.init(null, myTM, null);
      } catch (java.security.GeneralSecurityException e) {
        throw new AuthFailureException(e.toString());
      }
    }
    SSLSocketFactory sslfactory = ctx.getSocketFactory();
    engine = ctx.createSSLEngine(client.getServerName(), client.getServerPort());
    engine.setUseClientMode(true);

    if (anon) {
      String[] supported;
      ArrayList<String> enabled = new ArrayList<String>();

      supported = engine.getSupportedCipherSuites();

      for (int i = 0; i < supported.length; i++)
        if (supported[i].matches("TLS_DH_anon.*")) enabled.add(supported[i]);

      engine.setEnabledCipherSuites(enabled.toArray(new String[0]));
    } else {
      engine.setEnabledCipherSuites(engine.getSupportedCipherSuites());
    }

    engine.setEnabledProtocols(new String[] {"SSLv3", "TLSv1"});
  }
Beispiel #3
0
 @Override
 public void listen(String host, int port, int backlog, TLSParams tls) {
   SSLContext ssl = null;
   if (tls != null) {
     try {
       ssl = makeSSLContext(tls);
     } catch (NoSuchAlgorithmException e) {
       throw new EvaluatorException(e.toString());
     } catch (KeyManagementException e) {
       throw new EvaluatorException(e.toString());
     }
   }
   log.debug("About to listen for HTTP on {}:{}", host, port);
   if (ssl != null) {
     log.debug("Using SSLContext " + ssl);
   }
   try {
     server = NettyFactory.get().createServer(port, host, backlog, makePipeline(tls, ssl));
     log.debug("Listening on port {}", port);
   } catch (ChannelException ce) {
     stub.onError(ce.getMessage());
     stub.onClose(null, null);
   }
 }