try {
File f = getFileForPath(keyStoreFile);
if (!(f.exists() && f.isFile())) {
Message message = ERR_FILE_KEYMANAGER_NO_SUCH_FILE.get(
String.valueOf(keyStoreFile), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
} catch (SecurityException e) {
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = ERR_FILE_KEYMANAGER_CANNOT_DETERMINE_FILE.get(
String.valueOf(configEntryDN), getExceptionMessage(e));
throw new InitializationException(message, e);
}
// Get the keystore type. If none is specified, then use the
// default type.
if (configuration.getKeyStoreType() != null) {
try {
KeyStore.getInstance(configuration.getKeyStoreType());
keyStoreType = configuration.getKeyStoreType();
} catch (KeyStoreException kse) {
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, kse);
}
Message message = ERR_FILE_KEYMANAGER_INVALID_TYPE.
get(String.valueOf(configuration.getKeyStoreType()),
String.valueOf(configEntryDN), getExceptionMessage(kse));
throw new InitializationException(message);
}
} else {
keyStoreType = KeyStore.getDefaultType();
}
// Get the PIN needed to access the contents of the keystore file.
//
// We will offer several places to look for the PIN, and we will
// do so in the following order:
//
// - In a specified Java property
// - In a specified environment variable
// - In a specified file on the server filesystem.
// - As the value of a configuration attribute.
//
// In any case, the PIN must be in the clear.
keyStorePIN = null;
if (configuration.getKeyStorePinProperty() != null) {
String propertyName = configuration.getKeyStorePinProperty();
String pinStr = System.getProperty(propertyName);
if (pinStr == null) {
Message message = ERR_FILE_KEYMANAGER_PIN_PROPERTY_NOT_SET.get(
String.valueOf(propertyName), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
keyStorePIN = pinStr.toCharArray();
} else if (configuration.getKeyStorePinEnvironmentVariable() != null) {
String enVarName = configuration
.getKeyStorePinEnvironmentVariable();
String pinStr = System.getenv(enVarName);
if (pinStr == null) {
Message message = ERR_FILE_KEYMANAGER_PIN_ENVAR_NOT_SET.get(
String.valueOf(enVarName), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
keyStorePIN = pinStr.toCharArray();
} else if (configuration.getKeyStorePinFile() != null) {
String fileName = configuration.getKeyStorePinFile();
File pinFile = getFileForPath(fileName);
if (!pinFile.exists()) {
Message message = ERR_FILE_KEYMANAGER_PIN_NO_SUCH_FILE.get(
String.valueOf(fileName), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
String pinStr;
try {
BufferedReader br = new BufferedReader(
new FileReader(pinFile));
pinStr = br.readLine();
br.close();
} catch (IOException ioe) {
Message message = ERR_FILE_KEYMANAGER_PIN_FILE_CANNOT_READ.
get(String.valueOf(fileName), String.valueOf(configEntryDN),
getExceptionMessage(ioe));
throw new InitializationException(message, ioe);
}
if (pinStr == null) {
Message message = ERR_FILE_KEYMANAGER_PIN_FILE_EMPTY.get(
String.valueOf(fileName), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
keyStorePIN = pinStr.toCharArray();
} else if (configuration.getKeyStorePin() != null) {
keyStorePIN = configuration.getKeyStorePin().toCharArray();