Search in sources :

Example 16 with KeyCertificatePair

use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.

the class NonJavaTrustStoreTest method testCreationOfTrustStoreWithoutCRL.

@Test
public void testCreationOfTrustStoreWithoutCRL() throws Exception {
    final KeyCertificatePair keyCertPair = TlsResourceBuilder.createSelfSigned(DN_FOO);
    final Path certificateFile = TLS_RESOURCE.saveCertificateAsPem(keyCertPair.getCertificate());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(NonJavaTrustStore.NAME, NAME);
    attributes.put(NonJavaTrustStore.CERTIFICATES_URL, certificateFile.toFile().getAbsolutePath());
    attributes.put(NonJavaTrustStore.TYPE, NON_JAVA_TRUST_STORE);
    attributes.put(NonJavaTrustStore.CERTIFICATE_REVOCATION_CHECK_ENABLED, false);
    TrustStore<?> trustStore = createTestTrustStore(attributes);
    TrustManager[] trustManagers = trustStore.getTrustManagers();
    assertNotNull(trustManagers);
    assertEquals("Unexpected number of trust managers", 1, trustManagers.length);
    assertNotNull("Trust manager unexpected null", trustManagers[0]);
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) Path(java.nio.file.Path) HashMap(java.util.HashMap) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) Test(org.junit.Test)

Example 17 with KeyCertificatePair

use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.

the class NonJavaTrustStoreTest method testCreationOfTrustStoreFromValidCertificate_MissingCrlFile.

@Test
public void testCreationOfTrustStoreFromValidCertificate_MissingCrlFile() throws Exception {
    final KeyCertificatePair keyCertPair = TlsResourceBuilder.createSelfSigned(DN_FOO);
    final Path certificateFile = TLS_RESOURCE.saveCertificateAsPem(keyCertPair.getCertificate());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(NonJavaTrustStore.NAME, NAME);
    attributes.put(NonJavaTrustStore.CERTIFICATES_URL, certificateFile.toFile().getAbsolutePath());
    attributes.put(NonJavaTrustStore.TYPE, NON_JAVA_TRUST_STORE);
    attributes.put(NonJavaTrustStore.CERTIFICATE_REVOCATION_CHECK_ENABLED, true);
    attributes.put(NonJavaTrustStore.CERTIFICATE_REVOCATION_LIST_URL, NOT_A_CRL);
    KeyStoreTestHelper.checkExceptionThrownDuringKeyStoreCreation(FACTORY, BROKER, TrustStore.class, attributes, String.format("Unable to load certificate revocation list '%s' for truststore '%s'", NOT_A_CRL, NAME));
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) Path(java.nio.file.Path) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 18 with KeyCertificatePair

use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.

the class NonJavaTrustStoreTest method generateCertificateAndCrl.

private CertificateAndCrl<File> generateCertificateAndCrl() throws Exception {
    final KeyCertificatePair caPair = TlsResourceBuilder.createKeyPairAndRootCA(DN_CA);
    final KeyCertificatePair keyCertPair1 = TlsResourceBuilder.createKeyPairAndCertificate(DN_FOO, caPair);
    final KeyCertificatePair keyCertPair2 = TlsResourceBuilder.createKeyPairAndCertificate(DN_BAR, caPair);
    final Path clrFile = TLS_RESOURCE.createCrl(caPair, keyCertPair1.getCertificate(), keyCertPair2.getCertificate());
    final Path caCertificateFile = TLS_RESOURCE.saveCertificateAsPem(caPair.getCertificate());
    return new CertificateAndCrl<>(caCertificateFile.toFile(), clrFile.toFile(), caPair);
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) Path(java.nio.file.Path)

Aggregations

KeyCertificatePair (org.apache.qpid.test.utils.tls.KeyCertificatePair)18 HashMap (java.util.HashMap)8 Path (java.nio.file.Path)7 Test (org.junit.Test)7 CertificateEntry (org.apache.qpid.test.utils.tls.CertificateEntry)4 X509Certificate (java.security.cert.X509Certificate)3 TrustManager (javax.net.ssl.TrustManager)3 X509TrustManager (javax.net.ssl.X509TrustManager)3 KeyPair (java.security.KeyPair)2 Before (org.junit.Before)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 PrivateKey (java.security.PrivateKey)1 CertificateException (java.security.cert.CertificateException)1 CertificateExpiredException (java.security.cert.CertificateExpiredException)1 Instant (java.time.Instant)1 ArrayDeque (java.util.ArrayDeque)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1