Package org.apache.zookeeper.common
Class X509Util
- java.lang.Object
- 
- org.apache.zookeeper.common.X509Util
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 - Direct Known Subclasses:
- ClientX509Util,- QuorumX509Util
 
 public abstract class X509Util extends Object implements Closeable, AutoCloseable Utility code for X509 handling Default cipher suites: Performance testing done by Facebook engineers shows that on Intel x86_64 machines, Java9 performs better with GCM and Java8 performs better with CBC, so these seem like reasonable defaults.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classX509Util.ClientAuthEnum specifying the client auth requirement of server-side TLS sockets created by this X509Util.
 - 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLISstatic StringDEFAULT_PROTOCOL
 - 
Constructor SummaryConstructors Constructor Description X509Util()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Disables automatic reloading of the trust store and key store files when they change on disk.static X509KeyManagercreateKeyManager(String keyStoreLocation, String keyStorePassword, String keyStoreTypeProp)Creates a key manager by loading the key store from the given file of the given type, optionally decrypting it using the given password.SSLContextcreateSSLContext(ZKConfig config)SSLContextAndOptionscreateSSLContextAndOptions(ZKConfig config)SSLContextAndOptionscreateSSLContextAndOptionsFromConfig(ZKConfig config)SSLServerSocketcreateSSLServerSocket()SSLServerSocketcreateSSLServerSocket(int port)SSLSocketcreateSSLSocket()SSLSocketcreateSSLSocket(Socket socket, byte[] pushbackBytes)static X509TrustManagercreateTrustManager(String trustStoreLocation, String trustStorePassword, String trustStoreTypeProp, boolean crlEnabled, boolean ocspEnabled, boolean serverHostnameVerificationEnabled, boolean clientHostnameVerificationEnabled, boolean fipsMode)Creates a trust manager by loading the trust store from the given file of the given type, optionally decrypting it using the given password.voidenableCertFileReloading()Enables automatic reloading of the trust store and key store files when they change on disk.StringgetCipherSuitesProperty()protected abstract StringgetConfigPrefix()SSLContextgetDefaultSSLContext()SSLContextAndOptionsgetDefaultSSLContextAndOptions()static booleangetFipsMode(ZKConfig config)StringgetFipsModeProperty()StringgetPasswordFromConfigPropertyOrFile(ZKConfig config, String propertyName, String pathPropertyName)Returns the password specified by the given property or from the file specified by the given path property.StringgetSslCipherSuitesProperty()StringgetSslClientAuthProperty()StringgetSslContextSupplierClassProperty()StringgetSslCrlEnabledProperty()StringgetSslEnabledProtocolsProperty()StringgetSslHandshakeDetectionTimeoutMillisProperty()Returns the config property key that controls the amount of time, in milliseconds, that the first UnifiedServerSocket read operation will block for when trying to detect the client mode (TLS or PLAINTEXT).intgetSslHandshakeTimeoutMillis()Returns the max amount of time, in milliseconds, that the first UnifiedServerSocket read() operation should block for when trying to detect the client mode (TLS or PLAINTEXT).StringgetSslHostnameVerificationEnabledProperty()StringgetSslKeystoreLocationProperty()StringgetSslKeystorePasswdPathProperty()StringgetSslKeystorePasswdProperty()StringgetSslKeystoreTypeProperty()StringgetSslOcspEnabledProperty()StringgetSslProtocolProperty()StringgetSslTruststoreLocationProperty()StringgetSslTruststorePasswdPathProperty()StringgetSslTruststorePasswdProperty()StringgetSslTruststoreTypeProperty()booleanisClientHostnameVerificationEnabled(ZKConfig config)booleanisServerHostnameVerificationEnabled(ZKConfig config)static KeyStoreloadKeyStore(String keyStoreLocation, String keyStorePassword, String keyStoreTypeProp)static KeyStoreloadTrustStore(String trustStoreLocation, String trustStorePassword, String trustStoreTypeProp)protected abstract booleanshouldVerifyClientHostname()
 
- 
- 
- 
Field Detail- 
DEFAULT_PROTOCOLpublic static final String DEFAULT_PROTOCOL - See Also:
- Constant Field Values
 
 - 
DEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLISpublic static final int DEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLIS - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getConfigPrefixprotected abstract String getConfigPrefix() 
 - 
shouldVerifyClientHostnameprotected abstract boolean shouldVerifyClientHostname() 
 - 
getSslProtocolPropertypublic String getSslProtocolProperty() 
 - 
getSslEnabledProtocolsPropertypublic String getSslEnabledProtocolsProperty() 
 - 
getCipherSuitesPropertypublic String getCipherSuitesProperty() 
 - 
getSslKeystoreLocationPropertypublic String getSslKeystoreLocationProperty() 
 - 
getSslCipherSuitesPropertypublic String getSslCipherSuitesProperty() 
 - 
getSslKeystorePasswdPropertypublic String getSslKeystorePasswdProperty() 
 - 
getSslKeystorePasswdPathPropertypublic String getSslKeystorePasswdPathProperty() 
 - 
getSslKeystoreTypePropertypublic String getSslKeystoreTypeProperty() 
 - 
getSslTruststoreLocationPropertypublic String getSslTruststoreLocationProperty() 
 - 
getSslTruststorePasswdPropertypublic String getSslTruststorePasswdProperty() 
 - 
getSslTruststorePasswdPathPropertypublic String getSslTruststorePasswdPathProperty() 
 - 
getSslTruststoreTypePropertypublic String getSslTruststoreTypeProperty() 
 - 
getSslContextSupplierClassPropertypublic String getSslContextSupplierClassProperty() 
 - 
getSslHostnameVerificationEnabledPropertypublic String getSslHostnameVerificationEnabledProperty() 
 - 
getSslCrlEnabledPropertypublic String getSslCrlEnabledProperty() 
 - 
getSslOcspEnabledPropertypublic String getSslOcspEnabledProperty() 
 - 
getSslClientAuthPropertypublic String getSslClientAuthProperty() 
 - 
getSslHandshakeDetectionTimeoutMillisPropertypublic String getSslHandshakeDetectionTimeoutMillisProperty() Returns the config property key that controls the amount of time, in milliseconds, that the first UnifiedServerSocket read operation will block for when trying to detect the client mode (TLS or PLAINTEXT).- Returns:
- the config property key.
 
 - 
getFipsModePropertypublic String getFipsModeProperty() 
 - 
getFipsModepublic static boolean getFipsMode(ZKConfig config) 
 - 
isServerHostnameVerificationEnabledpublic boolean isServerHostnameVerificationEnabled(ZKConfig config) 
 - 
isClientHostnameVerificationEnabledpublic boolean isClientHostnameVerificationEnabled(ZKConfig config) 
 - 
getDefaultSSLContextpublic SSLContext getDefaultSSLContext() throws X509Exception.SSLContextException 
 - 
createSSLContextpublic SSLContext createSSLContext(ZKConfig config) throws X509Exception.SSLContextException 
 - 
getDefaultSSLContextAndOptionspublic SSLContextAndOptions getDefaultSSLContextAndOptions() throws X509Exception.SSLContextException 
 - 
getSslHandshakeTimeoutMillispublic int getSslHandshakeTimeoutMillis() Returns the max amount of time, in milliseconds, that the first UnifiedServerSocket read() operation should block for when trying to detect the client mode (TLS or PLAINTEXT). Defaults toDEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLIS.- Returns:
- the handshake detection timeout, in milliseconds.
 
 - 
createSSLContextAndOptionspublic SSLContextAndOptions createSSLContextAndOptions(ZKConfig config) throws X509Exception.SSLContextException 
 - 
createSSLContextAndOptionsFromConfigpublic SSLContextAndOptions createSSLContextAndOptionsFromConfig(ZKConfig config) throws X509Exception.SSLContextException 
 - 
loadKeyStorepublic static KeyStore loadKeyStore(String keyStoreLocation, String keyStorePassword, String keyStoreTypeProp) throws IOException, GeneralSecurityException - Throws:
- IOException
- GeneralSecurityException
 
 - 
loadTrustStorepublic static KeyStore loadTrustStore(String trustStoreLocation, String trustStorePassword, String trustStoreTypeProp) throws IOException, GeneralSecurityException - Throws:
- IOException
- GeneralSecurityException
 
 - 
getPasswordFromConfigPropertyOrFilepublic String getPasswordFromConfigPropertyOrFile(ZKConfig config, String propertyName, String pathPropertyName) Returns the password specified by the given property or from the file specified by the given path property. If both are specified, the value stored in the file will be returned.- Parameters:
- config- Zookeeper configuration
- propertyName- property name
- pathPropertyName- path property name
- Returns:
- the password value
 
 - 
createKeyManagerpublic static X509KeyManager createKeyManager(String keyStoreLocation, String keyStorePassword, String keyStoreTypeProp) throws X509Exception.KeyManagerException Creates a key manager by loading the key store from the given file of the given type, optionally decrypting it using the given password.- Parameters:
- keyStoreLocation- the location of the key store file.
- keyStorePassword- optional password to decrypt the key store. If empty, assumes the key store is not encrypted.
- keyStoreTypeProp- must be JKS, PEM, PKCS12, BCFKS or null. If null, attempts to autodetect the key store type from the file extension (e.g. .jks / .pem).
- Returns:
- the key manager.
- Throws:
- X509Exception.KeyManagerException- if something goes wrong.
 
 - 
createTrustManagerpublic static X509TrustManager createTrustManager(String trustStoreLocation, String trustStorePassword, String trustStoreTypeProp, boolean crlEnabled, boolean ocspEnabled, boolean serverHostnameVerificationEnabled, boolean clientHostnameVerificationEnabled, boolean fipsMode) throws X509Exception.TrustManagerException Creates a trust manager by loading the trust store from the given file of the given type, optionally decrypting it using the given password.- Parameters:
- trustStoreLocation- the location of the trust store file.
- trustStorePassword- optional password to decrypt the trust store (only applies to JKS trust stores). If empty, assumes the trust store is not encrypted.
- trustStoreTypeProp- must be JKS, PEM, PKCS12, BCFKS or null. If null, attempts to autodetect the trust store type from the file extension (e.g. .jks / .pem).
- crlEnabled- enable CRL (certificate revocation list) checks.
- ocspEnabled- enable OCSP (online certificate status protocol) checks.
- serverHostnameVerificationEnabled- if true, verify hostnames of remote servers that client sockets created by this X509Util connect to.
- clientHostnameVerificationEnabled- if true, verify hostnames of remote clients that server sockets created by this X509Util accept connections from.
- Returns:
- the trust manager.
- Throws:
- X509Exception.TrustManagerException- if something goes wrong.
 
 - 
createSSLSocketpublic SSLSocket createSSLSocket() throws X509Exception, IOException - Throws:
- X509Exception
- IOException
 
 - 
createSSLSocketpublic SSLSocket createSSLSocket(Socket socket, byte[] pushbackBytes) throws X509Exception, IOException - Throws:
- X509Exception
- IOException
 
 - 
createSSLServerSocketpublic SSLServerSocket createSSLServerSocket() throws X509Exception, IOException - Throws:
- X509Exception
- IOException
 
 - 
createSSLServerSocketpublic SSLServerSocket createSSLServerSocket(int port) throws X509Exception, IOException - Throws:
- X509Exception
- IOException
 
 - 
enableCertFileReloadingpublic void enableCertFileReloading() throws IOExceptionEnables automatic reloading of the trust store and key store files when they change on disk.- Throws:
- IOException- if creating the FileChangeWatcher objects fails.
 
 - 
closepublic void close() Disables automatic reloading of the trust store and key store files when they change on disk. Stops background threads and closes WatchService instances.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 
- 
 
-