示例#1
0
 private SSLEngine makeSSLEngine(TLSParams p, SSLContext ctx) {
   SSLEngine eng = ctx.createSSLEngine();
   if (p.getCiphers() != null) {
     eng.setEnabledCipherSuites(p.getCiphers().toArray(new String[p.getCiphers().size()]));
   }
   if (p.isClientAuthRequired()) {
     eng.setNeedClientAuth(true);
   } else if (p.isClientAuthRequested()) {
     eng.setWantClientAuth(true);
   }
   eng.setUseClientMode(false);
   return eng;
 }
示例#2
0
  private SSLContext makeSSLContext(TLSParams p)
      throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext ctx = SSLContext.getInstance("TLS");
    KeyManager[] kms = null;
    TrustManager[] tms = null;
    X509CRL crl = null;

    if (p.getKeyStore() != null) {
      kms = makeKeyStore(p.getKeyStore(), p.getPassphrase());
    }
    if (p.getTrustStore() != null) {
      tms = makeTrustStore(p.getTrustStore());
    }
    if (p.getCrl() != null) {
      crl = makeCRL(p.getCrl());
    }

    if ((tms != null) && (crl != null)) {
      tms[0] = new CompositeTrustManager((X509TrustManager) tms[0], crl);
    }

    ctx.init(kms, tms, null);
    return ctx;
  }