public class KeystoreManager extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
KeystoreManager.KeytoolExecutor |
Modifier and Type | Field and Description |
---|---|
protected PEFileLayout |
_fileLayout |
static String |
CERTIFICATE_ALIAS |
static String |
DEFAULT_MASTER_PASSWORD |
static String |
INSTANCE_SECURE_ADMIN_ALIAS |
Constructor and Description |
---|
KeystoreManager() |
Modifier and Type | Method and Description |
---|---|
void |
addKeyPair(File keyStore,
String storeType,
char[] storePw,
PrivateKey privKey,
Certificate[] certChain,
String alias)
Adds/updates a keypair to a keystore.
|
void |
addKeyPair(File keyStore,
String storeType,
char[] storePw,
PrivateKey privKey,
char[] keyPw,
Certificate[] certChain,
String alias)
Adds/updates a keypair to a keystore.
|
void |
changeKeyPassword(File keyStore,
String storeType,
char[] storePw,
String alias,
char[] oldKeyPw,
char[] newKeyPw)
Changes a private key's password.
|
void |
changeKeyStorePassword(File keyStore,
String storeType,
char[] oldPw,
char[] newPw)
Changes the keystore's password and all contained keys'.
|
void |
changeKeyStorePassword(File keyStore,
String storeType,
char[] oldPw,
char[] newPw,
boolean changeKeyPasswords)
Changes the keystore's password and all contained keys'.
|
protected void |
changeKeyStorePassword(String oldPassword,
String newPassword,
File keystore)
Changes the keystore password
|
protected void |
changeS1ASAliasPassword(RepositoryConfig config,
String storePassword,
String oldKeyPassword,
String newKeyPassword)
Changes the key password for the default cert whose alias is s1as.
|
protected void |
changeSSLCertificateDatabasePassword(RepositoryConfig config,
String oldPassword,
String newPassword)
Changes the password of the keystore, truststore and the key password of the s1as alias.
|
protected void |
chmod(String args,
File file) |
protected void |
copyCertificates(File keyStore,
File trustStore,
DomainConfig config,
String masterPassword)
Copy certain certificates from the keystore into the truststore.
|
protected void |
copyCertificatesFromJdk(File trustStore,
String masterPassword)
Copies all non-expired certificates from the currently used JDK to the Payara trust store.
|
protected void |
createKeyStore(File keystore,
RepositoryConfig config,
String masterPassword)
Create the default SSL key store using keytool to generate a self signed certificate.
|
protected void |
enforcePasswordComplexity(char[] pw,
String msgId)
Throws an IllegalArgumentException if the password's complexity does not meet requirements
|
protected static String |
getCertificateDN(RepositoryConfig cfg,
String CNSuffix) |
static String |
getDASCertDN(RepositoryConfig cfg) |
protected PEFileLayout |
getFileLayout(RepositoryConfig config) |
static String |
getInstanceCertDN(RepositoryConfig cfg) |
protected Map<String,Certificate> |
getValidCertificateAliases(KeyStore keyStore,
String keyStorePassword) |
KeyStore |
openKeyStore(File source,
String storeType,
char[] pw)
Loads a (JKS or PKCS#12) keystore.
|
Collection<? extends Certificate> |
readPemCertificateChain(File pemFile)
Reads X509 certificate(s) from the provided files
|
PrivateKey |
readPlainPKCS8PrivateKey(File keyFile)
Reads an unencrypted, PKCS#8 formattted and base64 encoded RSA private key from the given File
|
PrivateKey |
readPlainPKCS8PrivateKey(InputStream is,
String algo)
Reads an unencrypted, PKCS#8 formattted and base64 encoded private key from the given InputStream using the specified
algo
|
void |
saveKeyStore(KeyStore keyStore,
File dest,
char[] pw)
Saves the (modified) keystore.
|
public static final String CERTIFICATE_ALIAS
public static final String INSTANCE_SECURE_ADMIN_ALIAS
public static final String DEFAULT_MASTER_PASSWORD
protected PEFileLayout _fileLayout
protected static String getCertificateDN(RepositoryConfig cfg, String CNSuffix)
protected PEFileLayout getFileLayout(RepositoryConfig config)
protected void createKeyStore(File keystore, RepositoryConfig config, String masterPassword) throws RepositoryException
keystore
- config
- masterPassword
- RepositoryException
protected void copyCertificates(File keyStore, File trustStore, DomainConfig config, String masterPassword) throws DomainException
keyStore
- keystore to copy fromtrustStore
- the truststore to copy toconfig
- the domain's configurationmasterPassword
- the master password for the truststoreDomainException
- if an error occuredprotected void copyCertificatesFromJdk(File trustStore, String masterPassword) throws RepositoryException
trustStore
- the trust store to copy the certificates to.masterPassword
- the password to the trust store.RepositoryException
- if an error occured a RepositoryException
will wrap the original exceptionprotected Map<String,Certificate> getValidCertificateAliases(KeyStore keyStore, String keyStorePassword) throws RepositoryException
RepositoryException
protected void enforcePasswordComplexity(char[] pw, String msgId)
pw
- msgId
- public KeyStore openKeyStore(File source, String storeType, char[] pw) throws KeyStoreException
source
- the path of the file to be opened and loaded into the keystorestoreType
- the type of the keystore to be readpw
- the keystore passwordKeyStoreException
public void saveKeyStore(KeyStore keyStore, File dest, char[] pw) throws KeyStoreException
keyStore
- the keystore to be writtendest
- path of the file the keystore is to be written topw
- keystore passwordKeyStoreException
public void addKeyPair(File keyStore, String storeType, char[] storePw, PrivateKey privKey, Certificate[] certChain, String alias) throws KeyStoreException
keyStore
- the keystore. Must not be null.storeType
- the type of the keystore (JKS or PKCS#12)storePw
- the keystore password. Since glassfish requires that keystore and key passwords are identical, this is
also used as password for the private keyprivKey
- the private key to be added to the storecertChain
- chain of certificatesalias
- the alis of the key to be used inside the keystoreKeyStoreException
- in case of problemspublic void addKeyPair(File keyStore, String storeType, char[] storePw, PrivateKey privKey, char[] keyPw, Certificate[] certChain, String alias) throws KeyStoreException
NOTE: Glassfish expects the keystore and key passwords to be identical. For this reason prefer using
addKeyPair(java.io.File, java.lang.String, char[], java.security.PrivateKey, java.security.cert.Certificate[], java.lang.String)
instead
keyStore
- the keystore. Must not be null.storeType
- the type of the keystore (JKS or PKCS#12).storePw
- the keystore passwordprivKey
- the private key to be added to the storekeyPw
- the private key's password.certChain
- chain of certificatesalias
- the alis of the key to be used inside the keystoreKeyStoreException
- in case of problemsprotected void changeKeyStorePassword(String oldPassword, String newPassword, File keystore) throws RepositoryException
oldPassword
- the old keystore passwordnewPassword
- the new keystore passwordkeystore
- the keystore whose password is to be changed.RepositoryException
public void changeKeyStorePassword(File keyStore, String storeType, char[] oldPw, char[] newPw) throws KeyStoreException
This method DOES NOT use the keytool, but manipulates the given file directly from JAVA.
keyStore
- the destination keystore - may be null for an in-memory keystorestoreType
- the type of the keystore (JKS or PKCS#12)oldPw
- the old passwordnewPw
- the new passwordKeyStoreException
- in case of problemspublic void changeKeyStorePassword(File keyStore, String storeType, char[] oldPw, char[] newPw, boolean changeKeyPasswords) throws KeyStoreException
NOTE: Glassfish expects the keystore and key passwords to be identical. For this reason prefer using
changeKeyStorePassword(java.io.File, java.lang.String, char[], char[])
instead
This method DOES NOT use the keytool, but manipulates the given file directly from JAVA.
keyStore
- the destination keystore - may be null for an in-memory keystorestoreType
- the type of the keystore (JKS or PKCS#12)oldPw
- the old passwordnewPw
- the new passwordchangeKeyPasswords
- if true, all the keys contained in the keystore will have their passwords set to newStorePw
as wellKeyStoreException
- in case of problemspublic void changeKeyPassword(File keyStore, String storeType, char[] storePw, String alias, char[] oldKeyPw, char[] newKeyPw) throws KeyStoreException
NOTE: Glassfish expects the keystore and key passwords to be identical. For this reason prefer using
changeKeyStorePassword(java.io.File, java.lang.String, char[], char[])
instead
keyStore
- the path of the keystore where the key with alias is to be modifiedstoreType
- - either "JKS" or "PKCS12"storePw
- - must not be nullalias
- the alias of the key to be changedoldKeyPw
- the old passwordnewKeyPw
- the new passwordKeyStoreException
- in case of problemspublic PrivateKey readPlainPKCS8PrivateKey(File keyFile) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException
keyFile
- the file containing the private keyIOException
InvalidKeySpecException
NoSuchAlgorithmException
public PrivateKey readPlainPKCS8PrivateKey(InputStream is, String algo) throws InvalidKeySpecException, NoSuchAlgorithmException
is
- the input stream containing the private keyalgo
- the algorithm used for the private keyUncheckedIOException
- if there is an error with the InputStream
InvalidKeySpecException
- if the key used was not a valid with the algorithmNoSuchAlgorithmException
- if no provider exists for the specified algorithmpublic Collection<? extends Certificate> readPemCertificateChain(File pemFile) throws KeyStoreException
pemFile
- path to the PEM (or .cer) file containing the X.509 certificateKeyStoreException
- in case of problemsprotected void changeS1ASAliasPassword(RepositoryConfig config, String storePassword, String oldKeyPassword, String newKeyPassword) throws RepositoryException
config
- storePassword
- the keystore passwordoldKeyPassword
- the old password for the s1as aliasnewKeyPassword
- the new password for the s1as aliasRepositoryException
protected void changeSSLCertificateDatabasePassword(RepositoryConfig config, String oldPassword, String newPassword) throws RepositoryException
config
- the configuration with details of the truststore location and master passwordoldPassword
- the previous passwordnewPassword
- the new passwordRepositoryException
protected void chmod(String args, File file) throws IOException
IOException
public static String getDASCertDN(RepositoryConfig cfg)
public static String getInstanceCertDN(RepositoryConfig cfg)
Copyright © 2019. All rights reserved.