Search in sources :

Example 11 with KeyCertificatePair

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

the class TrustManagerTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    final KeyCertificatePair caPair = TlsResourceBuilder.createKeyPairAndRootCA(DN_CA);
    final KeyPair keyPair1 = TlsResourceBuilder.createRSAKeyPair();
    final KeyPair keyPair2 = TlsResourceBuilder.createRSAKeyPair();
    final KeyCertificatePair untrustedKeyCertPair = TlsResourceBuilder.createSelfSigned(DN_UNTRUSTED);
    _ca = caPair.getCertificate();
    _app1 = TlsResourceBuilder.createCertificateForClientAuthorization(keyPair1, caPair, DN_APP1);
    _app2 = TlsResourceBuilder.createCertificateForClientAuthorization(keyPair2, caPair, DN_APP2);
    _untrusted = untrustedKeyCertPair.getCertificate();
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) KeyPair(java.security.KeyPair) BeforeClass(org.junit.BeforeClass)

Example 12 with KeyCertificatePair

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

the class FileTrustStoreTest method generateTrustStoreAndCrlAsDataUrl.

private StoreAndCrl<String> generateTrustStoreAndCrlAsDataUrl() 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 String trustStoreAsDataUrl = TLS_RESOURCE.createKeyStoreAsDataUrl(new CertificateEntry(CERTIFICATE_ALIAS_A, keyCertPair1.getCertificate()), new CertificateEntry(CERTIFICATE_ALIAS_B, keyCertPair2.getCertificate()));
    final String crlAsDataUrl = TLS_RESOURCE.createCrlAsDataUrl(caPair, keyCertPair2.getCertificate());
    return new StoreAndCrl<>(trustStoreAsDataUrl, crlAsDataUrl, caPair);
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) CertificateEntry(org.apache.qpid.test.utils.tls.CertificateEntry)

Example 13 with KeyCertificatePair

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

the class FileTrustStoreTest method testCreatePeersOnlyTrustStoreFromFile_Success.

@Test
public void testCreatePeersOnlyTrustStoreFromFile_Success() throws Exception {
    final KeyCertificatePair keyPairAndRootCA = TlsResourceBuilder.createKeyPairAndRootCA(DN_CA);
    final Path keyStoreFile = TLS_RESOURCE.createTrustStore(DN_FOO, keyPairAndRootCA);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(FileTrustStore.NAME, NAME);
    attributes.put(FileTrustStore.STORE_URL, keyStoreFile.toFile().getAbsolutePath());
    attributes.put(FileTrustStore.PASSWORD, TLS_RESOURCE.getSecret());
    attributes.put(FileTrustStore.PEERS_ONLY, true);
    attributes.put(FileTrustStore.TRUST_STORE_TYPE, TLS_RESOURCE.getKeyStoreType());
    final FileTrustStore<?> fileTrustStore = createFileTrustStore(attributes);
    TrustManager[] trustManagers = fileTrustStore.getTrustManagers();
    assertNotNull(trustManagers);
    assertEquals("Unexpected number of trust managers", 1, trustManagers.length);
    assertNotNull("Trust manager unexpected null", trustManagers[0]);
    final boolean condition = trustManagers[0] instanceof QpidPeersOnlyTrustManager;
    assertTrue("Trust manager unexpected null", condition);
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) Path(java.nio.file.Path) HashMap(java.util.HashMap) QpidPeersOnlyTrustManager(org.apache.qpid.server.transport.network.security.ssl.QpidPeersOnlyTrustManager) TrustManager(javax.net.ssl.TrustManager) QpidPeersOnlyTrustManager(org.apache.qpid.server.transport.network.security.ssl.QpidPeersOnlyTrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) Test(org.junit.Test)

Example 14 with KeyCertificatePair

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

the class NonJavaKeyStoreTest method testCreationOfKeyStoreWithNonMatchingPrivateKeyAndCertificate.

@Test
public void testCreationOfKeyStoreWithNonMatchingPrivateKeyAndCertificate() throws Exception {
    final KeyCertificatePair keyCertPair2 = generateSelfSignedCertificate();
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(NonJavaKeyStore.NAME, NAME);
    attributes.put(NonJavaKeyStore.PRIVATE_KEY_URL, getPrivateKeyAsDataUrl(_keyCertPair.getPrivateKey()));
    attributes.put(NonJavaKeyStore.CERTIFICATE_URL, getCertificateAsDataUrl(keyCertPair2.getCertificate()));
    attributes.put(NonJavaKeyStore.TYPE, NON_JAVA_KEY_STORE);
    KeyStoreTestHelper.checkExceptionThrownDuringKeyStoreCreation(FACTORY, BROKER, KeyStore.class, attributes, "Private key does not match certificate");
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with KeyCertificatePair

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

the class SiteSpecificTrustStoreTest method setUpSiteSpecificTrustStore.

@Before
public void setUpSiteSpecificTrustStore() throws Exception {
    int connectTimeout = Integer.getInteger("SiteSpecificTrustStoreTest.connectTimeout", 1000);
    int readTimeout = Integer.getInteger("SiteSpecificTrustStoreTest.readTimeout", 1000);
    setTestSystemProperty(SiteSpecificTrustStore.TRUST_STORE_SITE_SPECIFIC_CONNECT_TIMEOUT, String.valueOf(connectTimeout));
    setTestSystemProperty(SiteSpecificTrustStore.TRUST_STORE_SITE_SPECIFIC_READ_TIMEOUT, String.valueOf(readTimeout));
    _caKeyCertPair = TlsResourceBuilder.createKeyPairAndRootCA(EXPECTED_ISSUER);
    _keyCertPair = TlsResourceBuilder.createKeyPairAndCertificate(EXPECTED_SUBJECT, _caKeyCertPair);
    final KeyCertificatePair keyCertPair2 = TlsResourceBuilder.createKeyPairAndCertificate(DN_BAR, _caKeyCertPair);
    _clrUrl = TLS_RESOURCE.createCrlAsDataUrl(_caKeyCertPair, keyCertPair2.getCertificate());
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) Before(org.junit.Before)

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