/** * Gets the SSL server's keystore. */ private KeyStore getKeystore() throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException { return this.getStore(this.config.getSslKeyStoreType(), this.config.getSslKeyStoreProvider(), this.config.getSslKeyStore(), this.config.getSslKeyStorePassword()); }
/** * Gets the SSL server's truststore. */ protected KeyStore getTrustStore() throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException { String trustStore = this.config.getSslTrustStore(); if (trustStore == null) return null; String truststorePassword = this.config.getSslTrustStorePassword(); if (truststorePassword == null) { truststorePassword = this.config.getSslKeyStorePassword(); } else if (truststorePassword.equals("")) { truststorePassword = null; } String truststoreType = this.config.getSslTrustStoreType(); if (truststoreType == null) { truststoreType = this.config.getSslKeyStoreType(); } String truststoreProvider = this.config.getSslTrustStoreProvider(); if (truststoreProvider == null) { truststoreProvider = this.config.getSslKeyStoreProvider(); } return this.getStore(truststoreType, truststoreProvider, trustStore, truststorePassword); }
/** * Gets the initialized key managers. * * @throws GeneralSecurityException * @throws IOException */ protected KeyManager[] getKeyManagers() throws GeneralSecurityException, IOException { KeyStore ks = this.getKeystore(); String alias = this.config.getSslKeyAlias(); KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.config.getSslCertificateEncodingAlgorithm()); kmf.init(ks, this.config.getSslKeyStorePassword().toCharArray()); KeyManager[] kms = kmf.getKeyManagers(); if (alias != null) { if ("JKS".equals(this.config.getSslKeyStoreType())) { alias = alias.toLowerCase(); } for (int i = 0; i < kms.length; i++) { kms[i] = new JSSEKeyManager((X509KeyManager) kms[i], alias); } } return kms; }
public JSSESocketFactory(SSLConfiguration config) { this.config = config; try { // Create and init SSLContext SSLContext context = SSLContext.getInstance(this.config.getSslProtocol()); KeyManager[] keyManagers = this.getKeyManagers(); TrustManager[] trustManagers = this.getTrustManagers(); context.init(keyManagers, trustManagers, new SecureRandom()); // create proxy this.socketFactory = context.getSocketFactory(); String ciphers = this.config.getSslCiphers(); this.enabledCiphers = (ciphers != null) ? getEnabled(ciphers, this.socketFactory.getSupportedCipherSuites()) : this.socketFactory.getDefaultCipherSuites(); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new IllegalStateException(e); } }
/** * Gets the initialized trust managers. * * @throws GeneralSecurityException * @throws IOException */ protected TrustManager[] getTrustManagers() throws GeneralSecurityException, IOException { KeyStore trustStore = this.getTrustStore(); if (trustStore == null) return null; String algorithm = this.config.getSslTrustAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm); if (this.config.getSslCrlFile() == null) { tmf.init(trustStore); return tmf.getTrustManagers(); } CertPathParameters params = this.getParameters(algorithm, this.config.getSslCrlFile(), trustStore); ManagerFactoryParameters mfp = new CertPathTrustManagerParameters(params); tmf.init(mfp); return tmf.getTrustManagers(); }
/** * Configures the given SSL server socket with the requested cipher suites, protocol versions, and need for client * authentication */ private void initSocket(Socket ssocket) { SSLSocket socket = (SSLSocket) ssocket; if (this.enabledCiphers != null) { socket.setEnabledCipherSuites(this.enabledCiphers); } String[] protocols = getEnabled(this.config.getSslProtocol(), socket.getSupportedProtocols()); if (protocols != null) { socket.setEnabledProtocols(protocols); } } }
/** * Gets the SSL server's truststore. */ protected KeyStore getTrustStore() throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException { String trustStore = this.config.getSslTrustStore(); if (trustStore == null) return null; String truststorePassword = this.config.getSslTrustStorePassword(); if (truststorePassword == null) { truststorePassword = this.config.getSslKeyStorePassword(); } else if (truststorePassword.equals("")) { truststorePassword = null; } String truststoreType = this.config.getSslTrustStoreType(); if (truststoreType == null) { truststoreType = this.config.getSslKeyStoreType(); } String truststoreProvider = this.config.getSslTrustStoreProvider(); if (truststoreProvider == null) { truststoreProvider = this.config.getSslKeyStoreProvider(); } return this.getStore(truststoreType, truststoreProvider, trustStore, truststorePassword); }
/** * Gets the initialized key managers. * * @throws GeneralSecurityException * @throws IOException */ protected KeyManager[] getKeyManagers() throws GeneralSecurityException, IOException { KeyStore ks = this.getKeystore(); String alias = this.config.getSslKeyAlias(); KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.config.getSslCertificateEncodingAlgorithm()); kmf.init(ks, this.config.getSslKeyStorePassword().toCharArray()); KeyManager[] kms = kmf.getKeyManagers(); if (alias != null) { if ("JKS".equals(this.config.getSslKeyStoreType())) { alias = alias.toLowerCase(); } for (int i = 0; i < kms.length; i++) { kms[i] = new JSSEKeyManager((X509KeyManager) kms[i], alias); } } return kms; }
public JSSESocketFactory(SSLConfiguration config) { this.config = config; try { // Create and init SSLContext SSLContext context = SSLContext.getInstance(this.config.getSslProtocol()); KeyManager[] keyManagers = this.getKeyManagers(); TrustManager[] trustManagers = this.getTrustManagers(); context.init(keyManagers, trustManagers, new SecureRandom()); // create proxy this.socketFactory = context.getSocketFactory(); String ciphers = this.config.getSslCiphers(); this.enabledCiphers = (ciphers != null) ? getEnabled(ciphers, this.socketFactory.getSupportedCipherSuites()) : this.socketFactory.getDefaultCipherSuites(); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new IllegalStateException(e); } }
/** * Gets the intialized trust managers. * @throws GeneralSecurityException * @throws IOException */ protected TrustManager[] getTrustManagers() throws GeneralSecurityException, IOException { KeyStore trustStore = this.getTrustStore(); if (trustStore == null) return null; String algorithm = this.config.getSslTrustAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm); if (this.config.getSslCrlFile() == null) { tmf.init(trustStore); return tmf.getTrustManagers(); } CertPathParameters params = this.getParameters(algorithm, this.config.getSslCrlFile(), trustStore); ManagerFactoryParameters mfp = new CertPathTrustManagerParameters(params); tmf.init(mfp); return tmf.getTrustManagers(); }
/** * Configures the given SSL server socket with the requested cipher suites, protocol versions, and need for client * authentication */ private void initSocket(Socket ssocket) { SSLSocket socket = (SSLSocket) ssocket; if (this.enabledCiphers != null) { socket.setEnabledCipherSuites(this.enabledCiphers); } String[] protocols = getEnabled(this.config.getSslProtocol(), socket.getSupportedProtocols()); if (protocols != null) { socket.setEnabledProtocols(protocols); } } }
protected KeyStore getTrustStore() throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException { String trustStore = this.config.getSslTrustStore(); if (trustStore == null) return null; String truststorePassword = this.config.getSslTrustStorePassword(); if (truststorePassword == null) { truststorePassword = this.config.getSslKeyStorePassword(); } else if (truststorePassword.equals("")) { truststorePassword = null; } String truststoreType = this.config.getSslTrustStoreType(); if (truststoreType == null) { truststoreType = this.config.getSslKeyStoreType(); } String truststoreProvider = this.config.getSslTrustStoreProvider(); if (truststoreProvider == null) { truststoreProvider = this.config.getSslKeyStoreProvider(); } return this.getStore(truststoreType, truststoreProvider, trustStore, truststorePassword); }
/** * Gets the SSL server's keystore. */ private KeyStore getKeystore() throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException { return this.getStore(this.config.getSslKeyStoreType(), this.config.getSslKeyStoreProvider(), this.config.getSslKeyStore(), this.config.getSslKeyStorePassword()); }
/** * Gets the initialized key managers. * @throws GeneralSecurityException * @throws IOException */ protected KeyManager[] getKeyManagers() throws GeneralSecurityException, IOException { KeyStore ks = this.getKeystore(); String alias = this.config.getSslKeyAlias(); KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.config.getSslCertificateEncodingAlgorithm()); kmf.init(ks, this.config.getSslKeyStorePassword().toCharArray()); KeyManager[] kms = kmf.getKeyManagers(); if (alias != null) { if ("JKS".equals(this.config.getSslKeyStoreType())) { alias = alias.toLowerCase(); } for (int i = 0; i < kms.length; i++) { kms[i] = new JSSEKeyManager((X509KeyManager) kms[i], alias); } } return kms; }
public JSSESocketFactory(SSLConfiguration config) { this.config = config; try { // Create and init SSLContext SSLContext context = SSLContext.getInstance(this.config.getSslProtocol()); KeyManager[] keyManagers = this.getKeyManagers(); TrustManager[] trustManagers = this.getTrustManagers(); context.init(keyManagers, trustManagers, new SecureRandom()); // create proxy this.socketFactory = context.getSocketFactory(); String ciphers = this.config.getSslCiphers(); this.enabledCiphers = (ciphers != null) ? getEnabled(ciphers, this.socketFactory.getSupportedCipherSuites()) : this.socketFactory.getDefaultCipherSuites(); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new IllegalStateException(e); } }
/** * Gets the initialized trust managers. * * @throws GeneralSecurityException * @throws IOException */ protected TrustManager[] getTrustManagers() throws GeneralSecurityException, IOException { KeyStore trustStore = this.getTrustStore(); if (trustStore == null) return null; String algorithm = this.config.getSslTrustAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm); if (this.config.getSslCrlFile() == null) { tmf.init(trustStore); return tmf.getTrustManagers(); } CertPathParameters params = this.getParameters(algorithm, this.config.getSslCrlFile(), trustStore); ManagerFactoryParameters mfp = new CertPathTrustManagerParameters(params); tmf.init(mfp); return tmf.getTrustManagers(); }
/** * Configures the given SSL server socket with the requested cipher suites, * protocol versions, and need for client authentication */ private void initSocket(Socket ssocket) { SSLSocket socket = (SSLSocket) ssocket; if (this.enabledCiphers != null) { socket.setEnabledCipherSuites(this.enabledCiphers); } String[] protocols = getEnabled(this.config.getSslProtocol(), socket.getSupportedProtocols()); if (protocols != null) { socket.setEnabledProtocols(protocols); } } }
private KeyStore getKeystore() throws IOException, KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException { return this.getStore(this.config.getSslKeyStoreType(), this.config.getSslKeyStoreProvider(), this.config.getSslKeyStore(), this.config.getSslKeyStorePassword()); }