FileBasedKeyManagerProvider.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* This class defines a key manager provider that will access keys stored in a
* file located on the Directory Server filesystem.
*/
public class FileBasedKeyManagerProvider
{
// The DN of the configuration entry for this key manager provider.
private DN configEntryDN;
// The PIN needed to access the keystore.
private char[] keyStorePIN;
// The configuration for this key manager provider.
// The path to the key store backing file.
private String keyStoreFile;
// The key store type to use.
private String keyStoreType;
/**
* Creates a new instance of this file-based key manager provider. The
* <CODE>initializeKeyManagerProvider</CODE> method must be called on the
* resulting object before it may be used.
*/
public FileBasedKeyManagerProvider()
{
// No implementation is required.
}
/**
* {@inheritDoc}
*/
public void initializeKeyManagerProvider(
throws ConfigException, InitializationException {
// Store the DN of the configuration entry and register as a change
// listener.
// Get the path to the key store file.
try {
throw new InitializationException(ERR_FILE_KEYMANAGER_NO_SUCH_FILE.get(keyStoreFile, configEntryDN));
}
} catch (SecurityException e) {
logger.traceException(e);
throw new InitializationException(message, e);
}
// Get the keystore type. If none is specified, then use the
// default type.
try {
} catch (KeyStoreException kse) {
throw new InitializationException(message);
}
} else {
}
// 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;
throw new InitializationException(message);
}
throw new InitializationException(message);
}
throw new InitializationException(message);
}
try {
new FileReader(pinFile));
} catch (IOException ioe) {
}
throw new InitializationException(message);
}
}
}
/**
* Performs any finalization that may be necessary for this key
* manager provider.
*/
public void finalizeKeyManagerProvider()
{
}
/**
* Retrieves a set of <CODE>KeyManager</CODE> objects that may be used for
* interactions requiring access to a key manager.
*
* @return A set of <CODE>KeyManager</CODE> objects that may be used for
* interactions requiring access to a key manager.
*
* @throws DirectoryException If a problem occurs while attempting to obtain
* the set of key managers.
*/
public KeyManager[] getKeyManagers()
throws DirectoryException
{
try
{
inputStream.close();
}
catch (Exception e)
{
logger.traceException(e);
message, e);
}
try
{
return keyManagerFactory.getKeyManagers();
}
catch (Exception e)
{
logger.traceException(e);
message, e);
}
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationAcceptable(
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
boolean configAcceptable = true;
// Get the path to the key store file.
try
{
{
configAcceptable = false;
}
}
catch (Exception e)
{
logger.traceException(e);
unacceptableReasons.add(ERR_FILE_KEYMANAGER_CANNOT_DETERMINE_FILE.get(cfgEntryDN, getExceptionMessage(e)));
configAcceptable = false;
}
// Get the keystore type. If none is specified, then use the default type.
{
try
{
}
catch (KeyStoreException kse)
{
configAcceptable = false;
}
}
// 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.
// It is acceptable to have no PIN (OPENDJ-18)
{
{
configAcceptable = false;
}
}
{
{
configAcceptable = false;
}
}
{
{
configAcceptable = false;
}
else
{
try {
}
catch (IOException ioe)
{
configAcceptable = false;
}
finally
{
}
{
configAcceptable = false;
}
}
}
{
{
configAcceptable = false;
}
}
return configAcceptable;
}
/**
* {@inheritDoc}
*/
{
// Get the path to the key store file.
try
{
{
}
}
catch (Exception e)
{
logger.traceException(e);
configEntryDN, getExceptionMessage(e)));
}
// Get the keystore type. If none is specified, then use the default type.
{
try
{
}
catch (KeyStoreException kse)
{
}
}
// 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.
{
{
}
else
{
}
}
{
{
}
else
{
}
}
{
{
}
else
{
try {
}
catch (IOException ioe)
{
}
finally
{
}
{
}
else
{
}
}
}
{
}
{
}
return ccr;
}
}