Package org.apache.hadoop.hbase.http.ssl
Class KeyStoreTestUtil
java.lang.Object
org.apache.hadoop.hbase.http.ssl.KeyStoreTestUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanupSSLConfig(org.apache.hadoop.conf.Configuration conf) static org.apache.hadoop.conf.ConfigurationcreateClientSSLConfig(String clientKS, String password, String keyPassword, String trustKS) Creates SSL configuration for a client.private static KeyStoreprivate static KeyStorecreateEmptyKeyStore(String keyStoreType) static voidcreateKeyStore(String filename, String password, String keyPassword, String alias, Key privateKey, Certificate cert) Creates a keystore with a single key and saves it to a file.static voidcreateKeyStore(String filename, String password, String keyPassword, String alias, Key privateKey, Certificate cert, String keystoreType) Creates a keystore with a single key and saves it to a file.static voidcreateKeyStore(String filename, String password, String alias, Key privateKey, Certificate cert) Creates a keystore with a single key and saves it to a file.static org.apache.hadoop.conf.ConfigurationcreateServerSSLConfig(String serverKS, String password, String keyPassword, String trustKS) Creates SSL configuration for a server.private static org.apache.hadoop.conf.ConfigurationcreateSSLConfig(org.apache.hadoop.security.ssl.SSLFactory.Mode mode, String keystore, String password, String keyPassword, String trustKS) Creates SSL configuration.static voidcreateTrustStore(String filename, String password, String alias, Certificate cert) Creates a truststore with a single certificate and saves it to a file.static voidcreateTrustStore(String filename, String password, String alias, Certificate cert, String trustStoreType) Creates a truststore with a single certificate and saves it to a file.static <T extends Certificate>
voidcreateTrustStore(String filename, String password, Map<String, T> certs) static X509CertificategenerateCertificate(String dn, KeyPair pair, int days, String algorithm) Create a self-signed X.509 Certificate.static KeyPairgenerateKeyPair(String algorithm) static StringgetClasspathDir(Class<?> klass) static voidsaveConfig(File file, org.apache.hadoop.conf.Configuration conf) Saves configuration to a file.private static voidsaveKeyStore(KeyStore ks, String filename, String password) static voidsetupSSLConfig(String keystoresDir, String sslConfDir, org.apache.hadoop.conf.Configuration conf, boolean useClientCert) Performs complete setup of SSL configuration in preparation for testing an SSLFactory.
-
Constructor Details
-
KeyStoreTestUtil
private KeyStoreTestUtil()
-
-
Method Details
-
getClasspathDir
- Throws:
Exception
-
generateCertificate
public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm) throws CertificateEncodingException, InvalidKeyException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException Create a self-signed X.509 Certificate.- Parameters:
dn- the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"pair- the KeyPairdays- how many days from now the Certificate is valid foralgorithm- the signing algorithm, eg "SHA1withRSA"- Returns:
- the self-signed certificate
- Throws:
CertificateEncodingExceptionInvalidKeyExceptionIllegalStateExceptionNoSuchProviderExceptionNoSuchAlgorithmExceptionSignatureException
-
generateKeyPair
- Throws:
NoSuchAlgorithmException
-
createEmptyKeyStore
- Throws:
GeneralSecurityExceptionIOException
-
createEmptyKeyStore
private static KeyStore createEmptyKeyStore(String keyStoreType) throws GeneralSecurityException, IOException - Throws:
GeneralSecurityExceptionIOException
-
saveKeyStore
private static void saveKeyStore(KeyStore ks, String filename, String password) throws GeneralSecurityException, IOException - Throws:
GeneralSecurityExceptionIOException
-
createKeyStore
public static void createKeyStore(String filename, String password, String alias, Key privateKey, Certificate cert) throws GeneralSecurityException, IOException Creates a keystore with a single key and saves it to a file. This method will use the same password for the keystore and for the key. This method will always generate a keystore file in JKS format.- Parameters:
filename- String file to savepassword- String store password to set on keystorealias- String alias to use for the keyprivateKey- Key to save in keystorecert- Certificate to use as certificate chain associated to key- Throws:
GeneralSecurityException- for any error with the security APIsIOException- if there is an I/O error saving the file
-
createKeyStore
public static void createKeyStore(String filename, String password, String keyPassword, String alias, Key privateKey, Certificate cert) throws GeneralSecurityException, IOException Creates a keystore with a single key and saves it to a file. This method will always generate a keystore file in JKS format.- Parameters:
filename- String file to savepassword- String store password to set on keystorekeyPassword- String key password to set on keyalias- String alias to use for the keyprivateKey- Key to save in keystorecert- Certificate to use as certificate chain associated to key- Throws:
GeneralSecurityException- for any error with the security APIsIOException- if there is an I/O error saving the file
-
createKeyStore
public static void createKeyStore(String filename, String password, String keyPassword, String alias, Key privateKey, Certificate cert, String keystoreType) throws GeneralSecurityException, IOException Creates a keystore with a single key and saves it to a file.- Parameters:
filename- String file to savepassword- String store password to set on keystorekeyPassword- String key password to set on keyalias- String alias to use for the keyprivateKey- Key to save in keystorecert- Certificate to use as certificate chain associated to keykeystoreType- String keystore file type (e.g. "JKS")- Throws:
GeneralSecurityException- for any error with the security APIsIOException- if there is an I/O error saving the file
-
createTrustStore
public static void createTrustStore(String filename, String password, String alias, Certificate cert) throws GeneralSecurityException, IOException Creates a truststore with a single certificate and saves it to a file. This method uses the default JKS truststore type.- Parameters:
filename- String file to savepassword- String store password to set on truststorealias- String alias to use for the certificatecert- Certificate to add- Throws:
GeneralSecurityException- for any error with the security APIsIOException- if there is an I/O error saving the file
-
createTrustStore
public static void createTrustStore(String filename, String password, String alias, Certificate cert, String trustStoreType) throws GeneralSecurityException, IOException Creates a truststore with a single certificate and saves it to a file.- Parameters:
filename- String file to savepassword- String store password to set on truststorealias- String alias to use for the certificatecert- Certificate to addtrustStoreType- String keystore file type (e.g. "JKS")- Throws:
GeneralSecurityException- for any error with the security APIsIOException- if there is an I/O error saving the file
-
createTrustStore
public static <T extends Certificate> void createTrustStore(String filename, String password, Map<String, T> certs) throws GeneralSecurityException, IOException- Throws:
GeneralSecurityExceptionIOException
-
cleanupSSLConfig
- Throws:
Exception
-
setupSSLConfig
public static void setupSSLConfig(String keystoresDir, String sslConfDir, org.apache.hadoop.conf.Configuration conf, boolean useClientCert) throws Exception Performs complete setup of SSL configuration in preparation for testing an SSLFactory. This includes keys, certs, keystores, truststores, the server SSL configuration file, the client SSL configuration file, and the master configuration file read by the SSLFactory.- Parameters:
keystoresDir- String directory to save keystoressslConfDir- String directory to save SSL configuration filesconf- Configuration master configuration to be used by an SSLFactory, which will be mutated by this methoduseClientCert- boolean true to make the client present a cert in the SSL handshake- Throws:
Exception
-
createClientSSLConfig
public static org.apache.hadoop.conf.Configuration createClientSSLConfig(String clientKS, String password, String keyPassword, String trustKS) Creates SSL configuration for a client.- Parameters:
clientKS- String client keystore filepassword- String store password, or null to avoid setting store passwordkeyPassword- String key password, or null to avoid setting key passwordtrustKS- String truststore file- Returns:
- Configuration for client SSL
-
createServerSSLConfig
public static org.apache.hadoop.conf.Configuration createServerSSLConfig(String serverKS, String password, String keyPassword, String trustKS) throws IOException Creates SSL configuration for a server.- Parameters:
serverKS- String server keystore filepassword- String store password, or null to avoid setting store passwordkeyPassword- String key password, or null to avoid setting key passwordtrustKS- String truststore file- Returns:
- Configuration for server SSL
- Throws:
IOException
-
createSSLConfig
private static org.apache.hadoop.conf.Configuration createSSLConfig(org.apache.hadoop.security.ssl.SSLFactory.Mode mode, String keystore, String password, String keyPassword, String trustKS) Creates SSL configuration.- Parameters:
mode- SSLFactory.Mode mode to configurekeystore- String keystore filepassword- String store password, or null to avoid setting store passwordkeyPassword- String key password, or null to avoid setting key passwordtrustKS- String truststore file- Returns:
- Configuration for SSL
-
saveConfig
public static void saveConfig(File file, org.apache.hadoop.conf.Configuration conf) throws IOException Saves configuration to a file.- Parameters:
file- File to saveconf- Configuration contents to write to file- Throws:
IOException- if there is an I/O error saving the file
-