use of org.apache.qpid.server.model.TrustStore in project qpid-broker-j by apache.
the class FileTrustStoreTest method testUseOfExpiredTrustAnchorAllowed.
public void testUseOfExpiredTrustAnchorAllowed() throws Exception {
Map<String, Object> attributes = new HashMap<>();
attributes.put(FileTrustStore.NAME, "myFileTrustStore");
attributes.put(FileTrustStore.STORE_URL, TestSSLConstants.BROKER_EXPIRED_TRUSTSTORE);
attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.BROKER_TRUSTSTORE_PASSWORD);
TrustStore trustStore = _factory.create(TrustStore.class, attributes, _broker);
TrustManager[] trustManagers = trustStore.getTrustManagers();
assertNotNull(trustManagers);
assertEquals("Unexpected number of trust managers", 1, trustManagers.length);
assertTrue("Unexpected trust manager type", trustManagers[0] instanceof X509TrustManager);
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
KeyStore clientStore = getInitializedKeyStore(TestSSLConstants.EXPIRED_KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD, KeyStore.getDefaultType());
String alias = clientStore.aliases().nextElement();
X509Certificate certificate = (X509Certificate) clientStore.getCertificate(alias);
trustManager.checkClientTrusted(new X509Certificate[] { certificate }, "NULL");
}
use of org.apache.qpid.server.model.TrustStore in project qpid-broker-j by apache.
the class FileTrustStoreTest method testUseOfExpiredTrustAnchorDenied.
public void testUseOfExpiredTrustAnchorDenied() throws Exception {
Map<String, Object> attributes = new HashMap<>();
attributes.put(FileTrustStore.NAME, "myFileTrustStore");
attributes.put(FileTrustStore.STORE_URL, TestSSLConstants.BROKER_EXPIRED_TRUSTSTORE);
attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.BROKER_TRUSTSTORE_PASSWORD);
attributes.put(FileTrustStore.TRUST_ANCHOR_VALIDITY_ENFORCED, true);
TrustStore trustStore = _factory.create(TrustStore.class, attributes, _broker);
TrustManager[] trustManagers = trustStore.getTrustManagers();
assertNotNull(trustManagers);
assertEquals("Unexpected number of trust managers", 1, trustManagers.length);
assertTrue("Unexpected trust manager type", trustManagers[0] instanceof X509TrustManager);
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
KeyStore clientStore = getInitializedKeyStore(TestSSLConstants.EXPIRED_KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD, KeyStore.getDefaultType());
String alias = clientStore.aliases().nextElement();
X509Certificate certificate = (X509Certificate) clientStore.getCertificate(alias);
try {
trustManager.checkClientTrusted(new X509Certificate[] { certificate }, "NULL");
fail("Exception not thrown");
} catch (CertificateException e) {
if (e instanceof CertificateExpiredException || "Certificate expired".equals(e.getMessage())) {
// IBMJSSE2 does not throw CertificateExpiredException, it throws a CertificateException
// PASS
} else {
throw e;
}
}
}
use of org.apache.qpid.server.model.TrustStore in project qpid-broker-j by apache.
the class TrustStoreMessageSourceTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
VirtualHost vhost = mock(VirtualHost.class);
MessageStore messageStore = new TestMemoryMessageStore();
TrustStore trustStore = mock(TrustStore.class);
Certificate certificate = mock(Certificate.class);
_certificates = new Certificate[] { certificate };
when(vhost.getMessageStore()).thenReturn(messageStore);
when(trustStore.getState()).thenReturn(State.ACTIVE);
when(trustStore.getCertificates()).thenReturn(_certificates);
when(certificate.getEncoded()).thenReturn("my certificate".getBytes());
_trustStoreMessageSource = new TrustStoreMessageSource(trustStore, vhost);
}
Aggregations