X509Util implements Closeable, AutoCloseable { public static X509KeyManager createKeyManager( String keyStoreLocation, String keyStorePassword, String keyStoreTypeProp) throws KeyManagerException { if (keyStorePassword == null) { keyStorePassword = ""; } try { KeyStoreFileType storeFileType = KeyStoreFileType.fromPropertyValueOrFileName( keyStoreTypeProp, keyStoreLocation); KeyStore ks = FileKeyStoreLoaderBuilderProvider .getBuilderForKeyStoreFileType(storeFileType) .setKeyStorePath(keyStoreLocation) .setKeyStorePassword(keyStorePassword) .build() .loadKeyStore(); KeyManagerFactory kmf = KeyManagerFactory.getInstance("PKIX"); kmf.init(ks, keyStorePassword.toCharArray()); for (KeyManager km : kmf.getKeyManagers()) { if (km instanceof X509KeyManager) { return (X509KeyManager) km; } } throw new KeyManagerException("Couldn't find X509KeyManager"); } catch (IOException | GeneralSecurityException | IllegalArgumentException e) { throw new KeyManagerException(e); } } X509Util();  X509Util(ZKConfig zkConfig); String getSslProtocolProperty(); String getSslEnabledProtocolsProperty(); String getCipherSuitesProperty(); String getSslKeystoreLocationProperty(); String getSslCipherSuitesProperty(); String getSslKeystorePasswdProperty(); String getSslKeystoreTypeProperty(); String getSslTruststoreLocationProperty(); String getSslTruststorePasswdProperty(); String getSslTruststoreTypeProperty(); String getSslHostnameVerificationEnabledProperty(); String getSslCrlEnabledProperty(); String getSslOcspEnabledProperty(); String getSslClientAuthProperty(); String getSslHandshakeDetectionTimeoutMillisProperty(); SSLContext getDefaultSSLContext(); SSLContext createSSLContext(ZKConfig config); SSLContextAndOptions getDefaultSSLContextAndOptions(); int getSslHandshakeTimeoutMillis(); SSLContextAndOptions createSSLContextAndOptions(ZKConfig config); static X509KeyManager createKeyManager(
            String keyStoreLocation,
            String keyStorePassword,
            String keyStoreTypeProp); static X509TrustManager createTrustManager(
            String trustStoreLocation,
            String trustStorePassword,
            String trustStoreTypeProp,
            boolean crlEnabled,
            boolean ocspEnabled,
            final boolean serverHostnameVerificationEnabled,
            final boolean clientHostnameVerificationEnabled); SSLSocket createSSLSocket(); SSLSocket createSSLSocket(Socket socket, byte[] pushbackBytes); SSLServerSocket createSSLServerSocket(); SSLServerSocket createSSLServerSocket(int port); void enableCertFileReloading(); @Override void close(); static final int DEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLIS; }
@Test public void testLoadPEMKeyStore() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), x509TestContext.getKeyStorePassword(), KeyStoreFileType.PEM.getPropertyValue()); }
@Test public void testLoadPEMKeyStoreNullPassword() throws Exception { if (!x509TestContext.getKeyStorePassword().isEmpty()) { return; } X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), null, KeyStoreFileType.PEM.getPropertyValue()); }
@Test public void testLoadPEMKeyStoreAutodetectStoreFileType() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), x509TestContext.getKeyStorePassword(), null ); }
@Test(expected = X509Exception.KeyManagerException.class) public void testLoadPEMKeyStoreWithWrongPassword() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath(), "wrong password", KeyStoreFileType.PEM.getPropertyValue()); }
@Test public void testLoadJKSKeyStore() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getKeyStorePassword(), KeyStoreFileType.JKS.getPropertyValue()); }
@Test public void testLoadJKSKeyStoreNullPassword() throws Exception { if (!x509TestContext.getKeyStorePassword().isEmpty()) { return; } X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), null, KeyStoreFileType.JKS.getPropertyValue()); }
@Test public void testLoadJKSKeyStoreAutodetectStoreFileType() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), x509TestContext.getKeyStorePassword(), null ); }
@Test(expected = X509Exception.KeyManagerException.class) public void testLoadJKSKeyStoreWithWrongPassword() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath(), "wrong password", KeyStoreFileType.JKS.getPropertyValue()); }
@Test public void testLoadPKCS12KeyStore() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(), x509TestContext.getKeyStorePassword(), KeyStoreFileType.PKCS12.getPropertyValue()); }
@Test public void testLoadPKCS12KeyStoreNullPassword() throws Exception { if (!x509TestContext.getKeyStorePassword().isEmpty()) { return; } X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(), null, KeyStoreFileType.PKCS12.getPropertyValue()); }
@Test public void testLoadPKCS12KeyStoreAutodetectStoreFileType() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(), x509TestContext.getKeyStorePassword(), null ); }
@Test(expected = X509Exception.KeyManagerException.class) public void testLoadPKCS12KeyStoreWithWrongPassword() throws Exception { X509KeyManager km = X509Util.createKeyManager( x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath(), "wrong password", KeyStoreFileType.PKCS12.getPropertyValue()); }