File f = getFileForPath(trustStoreFile);
if (! (f.exists() && f.isFile()))
{
Message message = ERR_FILE_TRUSTMANAGER_NO_SUCH_FILE.get(
String.valueOf(trustStoreFile), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
// Get the trust store type. If none is specified, then use the default
// type.
trustStoreType = configuration.getTrustStoreType();
if (trustStoreType == null)
{
trustStoreType = KeyStore.getDefaultType();
}
try
{
KeyStore.getInstance(trustStoreType);
}
catch (KeyStoreException kse)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, kse);
}
Message message = ERR_FILE_TRUSTMANAGER_INVALID_TYPE.
get(String.valueOf(trustStoreType), String.valueOf(configEntryDN),
getExceptionMessage(kse));
throw new InitializationException(message);
}
// Get the PIN needed to access the contents of the trust store 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. If no PIN is provided, then
// it will be assumed that none is required to access the information in the
// trust store.
String pinProperty = configuration.getTrustStorePinProperty();
if (pinProperty == null)
{
String pinEnVar = configuration.getTrustStorePinEnvironmentVariable();
if (pinEnVar == null)
{
String pinFilePath = configuration.getTrustStorePinFile();
if (pinFilePath == null)
{
String pinStr = configuration.getTrustStorePin();
if (pinStr == null)
{
trustStorePIN = null;
}
else
{
trustStorePIN = pinStr.toCharArray();
}
}
else
{
File pinFile = getFileForPath(pinFilePath);
if (! pinFile.exists())
{
Message message = ERR_FILE_TRUSTMANAGER_PIN_NO_SUCH_FILE.get(
String.valueOf(pinFilePath), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
else
{
String pinStr;
BufferedReader br = null;
try
{
br = new BufferedReader(new FileReader(pinFile));
pinStr = br.readLine();
}
catch (IOException ioe)
{
Message message = ERR_FILE_TRUSTMANAGER_PIN_FILE_CANNOT_READ.
get(String.valueOf(pinFilePath),
String.valueOf(configEntryDN), getExceptionMessage(ioe));
throw new InitializationException(message, ioe);
}
finally
{
try
{
br.close();
} catch (Exception e) {}
}
if (pinStr == null)
{
Message message = ERR_FILE_TRUSTMANAGER_PIN_FILE_EMPTY.get(
String.valueOf(pinFilePath), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
else
{
trustStorePIN = pinStr.toCharArray();
}
}
}
}
else
{
String pinStr = System.getenv(pinEnVar);
if (pinStr == null)
{
Message message = ERR_FILE_TRUSTMANAGER_PIN_ENVAR_NOT_SET.get(
String.valueOf(pinProperty), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
else
{
trustStorePIN = pinStr.toCharArray();
}
}
}
else
{
String pinStr = System.getProperty(pinProperty);
if (pinStr == null)
{
Message message = ERR_FILE_TRUSTMANAGER_PIN_PROPERTY_NOT_SET.get(
String.valueOf(pinProperty), String.valueOf(configEntryDN));
throw new InitializationException(message);
}
else
{
trustStorePIN = pinStr.toCharArray();
}