use of com.unboundid.util.DebugType in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodingAllJVMDefaultCertificates.
/**
* Tests to verify that all of the certificates in the JVM-default trust store
* can be decoded without error.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDecodingAllJVMDefaultCertificates() throws Exception {
final KeyStore keyStore = CryptoHelper.getKeyStore("JKS");
final File caCertsFile = JVMDefaultTrustManager.getInstance().getCACertsFile();
try (FileInputStream inputStream = new FileInputStream(caCertsFile)) {
keyStore.load(inputStream, null);
}
final boolean enabledBeforeStarting = Debug.debugEnabled();
final Set<DebugType> debugTypesBeforeStarting = Debug.getDebugTypes();
final Logger logger = Debug.getLogger();
final Level levelBeforeStarting = logger.getLevel();
final boolean useParentHandlersBeforeStarting = logger.getUseParentHandlers();
final TestLogHandler testLogHandler = new TestLogHandler();
try {
Debug.setEnabled(true, EnumSet.allOf(DebugType.class));
logger.setUseParentHandlers(false);
testLogHandler.setFilter(null);
testLogHandler.setLevel(Level.ALL);
logger.addHandler(testLogHandler);
final Enumeration<String> aliasEnumeration = keyStore.aliases();
while (aliasEnumeration.hasMoreElements()) {
final String alias = aliasEnumeration.nextElement();
final KeyStore.Entry entry = keyStore.getEntry(alias, null);
if (entry instanceof KeyStore.TrustedCertificateEntry) {
final KeyStore.TrustedCertificateEntry tce = (KeyStore.TrustedCertificateEntry) entry;
new X509Certificate(tce.getTrustedCertificate().getEncoded());
} else if (entry instanceof KeyStore.PrivateKeyEntry) {
final KeyStore.PrivateKeyEntry pke = (KeyStore.PrivateKeyEntry) entry;
for (final Certificate c : pke.getCertificateChain()) {
new X509Certificate(c.getEncoded());
}
}
}
} finally {
logger.removeHandler(testLogHandler);
Debug.setEnabled(enabledBeforeStarting, debugTypesBeforeStarting);
logger.setLevel(levelBeforeStarting);
logger.setUseParentHandlers(useParentHandlersBeforeStarting);
}
assertEquals(testLogHandler.getMessageCount(), 0, testLogHandler.getMessagesString());
}
Aggregations