use of org.mockserver.logging.MockServerLogger in project signers by ConsenSys.
the class HashicorpIntegrationTest method hashicorpVaultReturnsEncryptionKeyOverTls.
@Test
void hashicorpVaultReturnsEncryptionKeyOverTls() throws IOException {
KeyStoreFactory keyStoreFactory = new KeyStoreFactory(new MockServerLogger());
keyStoreFactory.loadOrCreateKeyStore();
HttpsURLConnection.setDefaultSSLSocketFactory(keyStoreFactory.sslContext().getSocketFactory());
final ClientAndServer clientAndServer = new ClientAndServer(0);
clientAndServer.when(request().withPath(".*")).respond(response().withStatusCode(200).withBody("{\"data\":{\"data\":{\"value\":\"" + EXPECTED_KEY_STRING + "\"}}}"));
final Path configFile = createConfigFile(DEFAULT_HOST, clientAndServer.getLocalPort(), ROOT_TOKEN, KEY_PATH, null, TIMEOUT_MILLISECONDS, true, "JKS", keyStoreFactory.keyStoreFileName, KeyStoreFactory.KEY_STORE_PASSWORD);
final HashicorpKeyConfig keyConfig = TomlConfigLoader.fromToml(configFile, null);
final HashicorpConnection connection = factory.create(keyConfig.getConnectionParams());
final String keyFetched = connection.fetchKey(keyConfig.getKeyDefinition());
assertThat(keyFetched).isEqualTo(EXPECTED_KEY_STRING);
}
use of org.mockserver.logging.MockServerLogger in project mockserver by mock-server.
the class X509GeneratorTest method shouldCreateClientCertificateWithDomainsComponentsWithNumbersInSANs.
@Test
public void shouldCreateClientCertificateWithDomainsComponentsWithNumbersInSANs() throws Exception {
// given
X509Generator x509Generator = new X509Generator(new MockServerLogger());
String[] domainNames = { "57bob.com", "bob57.com", "localhost.23foo.com", "127.0.0.1" };
// and - a certificate siging request with SANs
CertificateSigningRequest csr = new CertificateSigningRequest().setCommonName(ROOT_COMMON_NAME).setKeyPairSize(KEY_SIZE);
csr.addSubjectAlternativeNames(domainNames);
// and - and a root keypair
X509AndPrivateKey pemRootKeyPair = x509Generator.generateRootX509AndPrivateKey(csr);
// when - a certificate has been successfully generated
X509AndPrivateKey keyPair = x509Generator.generateLeafX509AndPrivateKey(csr, buildDistinguishedName(ROOT_COMMON_NAME), pemRootKeyPair.getPrivateKey(), x509FromPEM(pemRootKeyPair.getCert()));
X509Certificate x509Certificate = x509FromPEM(keyPair.getCert());
// then - the correct number of SANs should be present
Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
assertEquals(4, subjectAlternativeNames.size());
// and - the correct values are contained in the correct order
List<?> collect = subjectAlternativeNames.stream().map(subjectAlternativeName -> subjectAlternativeName.get(1)).collect(Collectors.toList());
assertThat(collect, containsInAnyOrder(domainNames));
}
use of org.mockserver.logging.MockServerLogger in project mockserver by mock-server.
the class X509GeneratorTest method shouldCreateRootCertificateThatCanBePEMEncodedAndDecoded.
@Test
public void shouldCreateRootCertificateThatCanBePEMEncodedAndDecoded() throws Exception {
// given
X509Generator x509Generator = new X509Generator(new MockServerLogger());
// when - a key pair is generated
X509AndPrivateKey keyPair = x509Generator.generateRootX509AndPrivateKey(csr);
// then - validate pem decoding/encoding of the private key
assertEquals(keyPair.getPrivateKey(), privateKeyToPEM(privateKeyBytesFromPEM(keyPair.getPrivateKey())));
// and - validate pem decoding/encoding of the cert
assertEquals(keyPair.getCert(), certToPEM(certFromPem(keyPair.getCert())));
}
use of org.mockserver.logging.MockServerLogger in project mockserver by mock-server.
the class X509GeneratorTest method shouldCreateRootCertificateWithPositiveSerialNumber.
@Test
public void shouldCreateRootCertificateWithPositiveSerialNumber() throws Exception {
// given
X509Generator x509Generator = new X509Generator(new MockServerLogger());
// when - a key pair is generated
X509AndPrivateKey keyPair = x509Generator.generateRootX509AndPrivateKey(csr);
X509Certificate x509Certificate = x509FromPEM(keyPair.getCert());
assertTrue("The ca cert serial number is non-negative", x509Certificate.getSerialNumber().compareTo(BigInteger.ZERO) > 0);
}
use of org.mockserver.logging.MockServerLogger in project mockserver by mock-server.
the class X509GeneratorTest method shouldCreateClientCertificateWithEmptySANs.
@Test
public void shouldCreateClientCertificateWithEmptySANs() throws Exception {
// given
X509Generator x509Generator = new X509Generator(new MockServerLogger());
// and - a certificate signing request with SANs
CertificateSigningRequest csr = new CertificateSigningRequest().setCommonName(ROOT_COMMON_NAME).setKeyPairSize(KEY_SIZE);
csr.addSubjectAlternativeNames();
// and - and a root keypair
X509AndPrivateKey pemRootKeyPair = x509Generator.generateRootX509AndPrivateKey(csr);
// when - a certificate has been successfully generated
X509AndPrivateKey keyPair = x509Generator.generateLeafX509AndPrivateKey(csr, buildDistinguishedName(ROOT_COMMON_NAME), pemRootKeyPair.getPrivateKey(), x509FromPEM(pemRootKeyPair.getCert()));
X509Certificate x509Certificate = x509FromPEM(keyPair.getCert());
// then - the no SANs should be present
Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
assertNull(subjectAlternativeNames);
}
Aggregations