{
context = SSLContext.getInstance(ConstsIf.PROT_TLS_V1);
} catch (NoSuchAlgorithmException e)
{
throw new ConfigurationException(
"",
"creating SSLContext: ERROR no such algorithm");
}
//Step 2: obtain a key store instance, type is fixed
KeyStore myKeys;
try
{
myKeys = KeyStore.getInstance(ConstsIf.KS_TYPE_JKS);
} catch (KeyStoreException e1)
{
throw new ConfigurationException(
"",
"creating SSLContext: ERROR no such algorithm");
}
InputStream is = null;
char[] keyPassPhrase = null;
if (!isDefaultConfig)
{
//Step 3:obtain password phrase for a keystore
try
{
keyPassPhrase = ((String) m_config.get(KEYSTOREPASS_KEY)).toCharArray();
} catch (Exception epass) {}
//Step 4:obtain input stream for a key store
// - if the config admin set it to type byte[], assume it is a keystore itself
// - else if it is of type string try to interpret this string as an (absolute) path
// to a file
// - else assume that this is a incomplete configruation we got from the CM Admin,
// use the default keystore
// from CM as byte[] ?
if ((keyPassPhrase != null) && (is == null))
{
try
{
is = new ByteArrayInputStream((byte[]) m_config.get(KEYSTORE_KEY));
} catch (Exception eb) {}
}
//from CM as a file pointer ?
if ((keyPassPhrase != null) && (is == null))
{
try
{
is = new FileInputStream((String) m_config.get(KEYSTORE_KEY));
} catch (Exception ef) {}
}
if ((is == null) && m_log.doWarn())
{
m_log.warn("using default, config is invalid: " + m_config.get("service.pid"));
}
}
// Step 3 & 4 executed now if config is bad or we just use the default config
if (is == null)
{
try
{
keyPassPhrase = DEFAULT_PASSPHR_VALUE.toCharArray();
is = getClass().getResourceAsStream(DEFAULT_KEYSTORE_VALUE);
} catch (Exception edef)
{
}
}
// Step 5: load keys into keystore
try
{
myKeys.load(is, keyPassPhrase);
} catch (Exception eload)
{
throw new ConfigurationException(
KEYSTORE_KEY + "," + KEYSTOREPASS_KEY,
"ERROR loading keys !, passphrase " + String.valueOf(keyPassPhrase));
}
//Step 6: create and initialize KeyManagerFactory
KeyManagerFactory kmf;
try
{
kmf = KeyManagerFactory.getInstance(ConstsIf.KM_TYPE_SUN);
} catch (NoSuchAlgorithmException e4)
{
throw new ConfigurationException(
"",
"creating KeyManagerFactory: ERROR no such algorithm");
}
try
{
kmf.init(myKeys, keyPassPhrase);
} catch (Exception e5)
{
throw new ConfigurationException(
"",
"initing kmf: " + e5.getMessage());
}
//Step 7: initialize context with the key manager factory
try
{
context.init(kmf.getKeyManagers(), null, null);
} catch (KeyManagementException e6)
{
throw new ConfigurationException(
"",
"initing SSLContext: " + e6.getMessage());
}
//Step 8: create SSL Server Socket Factory
SSLServerSocketFactory ssl = null;
try
{
ssl = context.getServerSocketFactory();
} catch (Exception e7)
{
throw new ConfigurationException(
"",
"creating SSLServerSocketFactory object: " + e7.getMessage());
}
m_reg = m_bc.registerService(SSLServerSocketFactory.class.getName(),