use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.
the class PreemptiveAuthenticationTest method configForClientAuth.
private HttpTestHelper configForClientAuth(final String x500Name) throws Exception {
final KeyCertificatePair clientKeyCertPair = getKeyCertPair(x500Name);
final byte[] clientCertificate = clientKeyCertPair.getCertificate().getEncoded();
final String clientKeyStore = createKeyStoreDataUrl(clientKeyCertPair);
final KeyCertificatePair brokerKeyCertPair = getKeyCertPair(x500Name);
final String brokerKeyStore = createKeyStoreDataUrl(brokerKeyCertPair);
final Deque<BaseAction<Void, Exception>> deleteActions = new ArrayDeque<>();
final Map<String, Object> authAttr = new HashMap<>();
authAttr.put(ExternalAuthenticationManager.TYPE, "External");
authAttr.put(ExternalAuthenticationManager.ATTRIBUTE_USE_FULL_DN, false);
getHelper().submitRequest("authenticationprovider/myexternal", "PUT", authAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("authenticationprovider/myexternal", "DELETE", SC_OK));
final Map<String, Object> keystoreAttr = new HashMap<>();
keystoreAttr.put(FileKeyStore.TYPE, "FileKeyStore");
keystoreAttr.put(FileKeyStore.STORE_URL, brokerKeyStore);
keystoreAttr.put(FileKeyStore.PASSWORD, STORE_PASSWORD);
keystoreAttr.put(FileKeyStore.KEY_STORE_TYPE, KeyStore.getDefaultType());
getHelper().submitRequest("keystore/mykeystore", "PUT", keystoreAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("keystore/mykeystore", "DELETE", SC_OK));
final Map<String, Object> truststoreAttr = new HashMap<>();
truststoreAttr.put(ManagedPeerCertificateTrustStore.TYPE, ManagedPeerCertificateTrustStore.TYPE_NAME);
truststoreAttr.put(ManagedPeerCertificateTrustStore.STORED_CERTIFICATES, Collections.singletonList(Base64.getEncoder().encodeToString(clientCertificate)));
getHelper().submitRequest("truststore/mytruststore", "PUT", truststoreAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("truststore/mytruststore", "DELETE", SC_OK));
final Map<String, Object> portAttr = new HashMap<>();
portAttr.put(Port.TYPE, "HTTP");
portAttr.put(Port.PORT, 0);
portAttr.put(Port.AUTHENTICATION_PROVIDER, "myexternal");
portAttr.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
portAttr.put(Port.NEED_CLIENT_AUTH, true);
portAttr.put(Port.KEY_STORE, "mykeystore");
portAttr.put(Port.TRUST_STORES, Collections.singletonList("mytruststore"));
getHelper().submitRequest("port/myport", "PUT", portAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("port/myport", "DELETE", SC_OK));
Map<String, Object> clientAuthPort = getHelper().getJsonAsMap("port/myport");
int boundPort = Integer.parseInt(String.valueOf(clientAuthPort.get("boundPort")));
assertThat(boundPort, is(greaterThan(0)));
_tearDownActions = deleteActions;
HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null, boundPort);
helper.setTls(true);
helper.setKeyStore(clientKeyStore, STORE_PASSWORD);
return helper;
}
use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.
the class ReadTest method valueFilteredSecureAttributes.
@Test
@HttpRequestConfig(useVirtualHostAsHost = false)
public void valueFilteredSecureAttributes() throws Exception {
final KeyCertificatePair keyCertPair = generateCertKeyPair();
final byte[] privateKey = keyCertPair.getPrivateKey().getEncoded();
final byte[] cert = keyCertPair.getCertificate().getEncoded();
final String privateKeyUrl = DataUrlUtils.getDataUrlForBytes(privateKey);
final String certUrl = DataUrlUtils.getDataUrlForBytes(cert);
final File privateKeyFile = File.createTempFile("foo" + System.currentTimeMillis(), "key");
privateKeyFile.deleteOnExit();
FileUtils.copy(new ByteArrayInputStream(privateKey), privateKeyFile);
Map<String, Object> base = new HashMap<>();
base.put(NonJavaKeyStore.TYPE, "NonJavaKeyStore");
base.put(NonJavaKeyStore.CERTIFICATE_URL, certUrl);
try {
{
final String storeUrl = "keystore/mystoreDataUrl";
final Map<String, Object> attrs = new HashMap<>(base);
attrs.put(NonJavaKeyStore.PRIVATE_KEY_URL, privateKeyUrl);
getHelper().submitRequest(storeUrl, "PUT", attrs, SC_CREATED);
final Map<String, Object> store = getHelper().getJsonAsMap(storeUrl);
assertThat(store.get(NonJavaKeyStore.PRIVATE_KEY_URL), is(equalTo(AbstractConfiguredObject.SECURED_STRING_VALUE)));
getHelper().submitRequest(storeUrl, "DELETE", SC_OK);
}
{
final String privateKeyFileUrl = privateKeyFile.toURI().toString();
final String storeUrl = "keystore/mystoreFileUrl";
final Map<String, Object> attrs = new HashMap<>(base);
attrs.put(NonJavaKeyStore.TYPE, "NonJavaKeyStore");
attrs.put(NonJavaKeyStore.PRIVATE_KEY_URL, privateKeyFileUrl);
getHelper().submitRequest(storeUrl, "PUT", attrs, SC_CREATED);
final Map<String, Object> store = getHelper().getJsonAsMap(String.format("%s?oversize=%d", storeUrl, privateKeyFileUrl.length()));
assertThat(store.get(NonJavaKeyStore.PRIVATE_KEY_URL), is(equalTo(privateKeyFileUrl)));
getHelper().submitRequest(storeUrl, "DELETE", SC_OK);
}
} finally {
privateKeyFile.delete();
}
}
use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.
the class PortTest method updateKeyStoreAndUpdatePortTls.
private File updateKeyStoreAndUpdatePortTls() throws Exception {
final KeyCertificatePair keyCertPair = generateSelfSignedCertificate();
submitKeyStoreAttributes(_keyStoreName, SC_OK, keyCertPair);
updatePortTls();
return createTrustStore(keyCertPair);
}
use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.
the class PortTest method createNewKeyStoreAndSetItOnPort.
private File createNewKeyStoreAndSetItOnPort() throws Exception {
String newKeyStoreName = _keyStoreName + "_2";
final KeyCertificatePair keyCertPair = generateSelfSignedCertificate();
submitKeyStoreAttributes(newKeyStoreName, SC_CREATED, keyCertPair);
getHelper().submitRequest("port/" + _portName, "POST", Collections.<String, Object>singletonMap(Port.KEY_STORE, newKeyStoreName), SC_OK);
updatePortTls();
return createTrustStore(keyCertPair);
}
use of org.apache.qpid.test.utils.tls.KeyCertificatePair in project qpid-broker-j by apache.
the class TlsHelper method getCaKeyCertPair.
public KeyCertificatePair getCaKeyCertPair() {
final PrivateKey privateKey = _caPair.getPrivateKey();
final X509Certificate certificate = _caCertificate;
return new KeyCertificatePair(privateKey, certificate);
}
Aggregations