/*
* 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 2013 ForgeRock AS
*/
/**
* This class provides SSL connection related utility functions.
*/
public class SSLConnectionFactory
{
/**
* The tracer object for the debug logger.
*/
/**
* Constructor for the SSL connection factory.
*/
public SSLConnectionFactory()
{
}
/**
* Initialize the connection factory by creating the key and
* trust managers for the SSL connection.
*
* @param trustAll Indicates whether to blindly trust all
* certificates.
* @param keyStorePath The path to the key store file.
* @param keyStorePassword The PIN to use to access the key store
* contents.
* @param clientAlias The alias to use for the client certificate.
* @param trustStorePath The path to the trust store file.
* @param trustStorePassword The PIN to use to access the trust store
* contents.
*
* @throws SSLConnectionException If a problem occurs while initializing the
* connection factory.
*/
throws SSLConnectionException
{
try
{
if(trustAll)
{
new BlindTrustManagerProvider();
} else if (trustStorePath == null) {
} else
{
{
trustManagers[i] =
tmpTrustManagers[i]);
}
}
if(keyStorePath != null)
{
if (clientAlias != null)
{
}
}
} catch(Exception e)
{
throw new SSLConnectionException(
}
}
/**
* Create the SSL socket connection to the specified host.
*
* @param hostName The address of the system to which the connection
* should be established.
* @param portNumber The port number to which the connection should be
* established.
*
* @return The SSL socket established to the specified host.
*
* @throws SSLConnectionException If a problem occurs while performing SSL
* negotiation.
*
* @throws IOException If a problem occurs while attempting to communicate
* with the server.
*/
throws SSLConnectionException, IOException
{
if(sslSocketFactory == null)
{
throw new SSLConnectionException(
}
}
/**
* Create the SSL socket connection to the specified host.
*
* @param host
* The address of the system to which the connection should be
* established.
* @param portNumber
* The port number to which the connection should be established.
* @return The SSL socket established to the specified host.
* @throws SSLConnectionException
* If a problem occurs while performing SSL negotiation.
* @throws IOException
* If a problem occurs while attempting to communicate with the
* server.
*/
throws SSLConnectionException, IOException
{
if (sslSocketFactory == null)
{
.get());
}
}
/**
* Create the SSL socket connection to the specified host layered over
* an existing socket.
*
* @param s The socket to use for the existing connection.
* @param hostName The address of the system to which the connection
* should be established.
* @param portNumber The port number to which the connection should be
* established.
* @param autoClose Indicates whether the underlying connection should be
* automatically closed when the SSL session is ended.
*
* @return The SSL socket established to the specified host.
*
* @throws SSLConnectionException If a problem occurs while performing SSL
* negotiation.
*
* @throws IOException If a problem occurs while attempting to communicate
* with the server.
*/
boolean autoClose)
throws SSLConnectionException, IOException
{
if(sslSocketFactory == null)
{
throw new SSLConnectionException(
}
}
/**
* Retrieves a set of <CODE>KeyManager</CODE> objects that may be used for
* interactions requiring access to a key manager.
*
* @param keyStoreType The key store type to use with the specified file.
* @param provider The provider to use when accessing the key store.
* @param keyStoreFile The path to the file containing the key store data.
* @param keyStorePass The PIN needed to access the key store contents.
*
* @return A set of <CODE>KeyManager</CODE> objects that may be used for
* interactions requiring access to a key manager.
*
* @throws KeyStoreException If a problem occurs while interacting with the
* key store.
*
* @throws SSLConnectionException If a problem occurs while trying to load
* key store file.
*/
{
if(keyStoreFile == null)
{
// Lookup the file name through the JDK property.
keyStoreFile = getKeyStore();
}
if(keyStorePass == null)
{
// Lookup the keystore PIN through the JDK property.
}
{
} else
{
}
char[] keyStorePIN = null;
if(keyStorePass != null)
{
}
try
{
inputStream.close();
} catch(Exception e)
{
if (debugEnabled())
{
}
throw new SSLConnectionException(
}
try
{
return keyManagerFactory.getKeyManagers();
{
if (debugEnabled())
{
}
throw new SSLConnectionException(
}
}
/**
* Retrieves a set of <CODE>TrustManager</CODE> objects that may be used for
* interactions requiring access to a trust manager.
*
* @param trustStoreType The trust store type to use with the specified
* file.
* @param provider The provider to use when accessing the trust store.
* @param trustStoreFile The path to the file containing the trust store
* data.
* @param trustStorePass The PIN needed to access the trust store contents.
*
* @return A set of <CODE>TrustManager</CODE> objects that may be used for
* interactions requiring access to a trust manager.
*
* @throws KeyStoreException If a problem occurs while interacting with the
* trust store.
*
* @throws SSLConnectionException If a problem occurs while trying to load
* trust store file.
*/
{
if(trustStoreFile == null)
{
// No trust store file available.
if(trustStoreFile == null)
{
return null;
}
}
if(trustStorePass == null)
{
}
{
} else
{
}
char[] trustStorePIN = null;
if(trustStorePass != null)
{
}
try
{
inputStream.close();
} catch(Exception e)
{
if (debugEnabled())
{
}
throw new SSLConnectionException(
}
try
{
return trustManagerFactory.getTrustManagers();
{
if (debugEnabled())
{
}
throw new SSLConnectionException(
}
}
/**
* Read the KeyStore PIN from the JSSE system property.
*
* @return The PIN that should be used to access the key store.
*/
{
}
/**
* Read the TrustStore PIN from the JSSE system property.
*
* @return The PIN that should be used to access the trust store.
*/
{
}
/**
* Read the KeyStore from the JSSE system property.
*
* @return The path to the key store file.
*/
{
}
/**
* Read the TrustStore from the JSSE system property.
*
* @return The path to the trust store file.
*/
{
}
}