use of java.security.KeyStore in project camel by apache.
the class SignatureTests method testProvideCertificateInHeader.
@Test
public void testProvideCertificateInHeader() throws Exception {
setupMock();
Exchange unsigned = getMandatoryEndpoint("direct:signature-property").createExchange();
unsigned.getIn().setBody(payload);
// create a keypair
KeyStore keystore = loadKeystore();
Certificate certificate = keystore.getCertificate("bob");
PrivateKey pk = (PrivateKey) keystore.getKey("bob", "letmein".toCharArray());
// sign with the private key
unsigned.getIn().setHeader(SIGNATURE_PRIVATE_KEY, pk);
template.send("direct:headerkey-sign", unsigned);
// verify with the public key
Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange();
signed.getIn().copyFrom(unsigned.getOut());
signed.getIn().setHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, certificate);
template.send("direct:headerkey-verify", signed);
assertMockEndpointsSatisfied();
}
use of java.security.KeyStore in project camel by apache.
the class SigningProcessor method getKeyPassword.
protected char[] getKeyPassword(Exchange exchange) throws Exception {
KeyStore keystore = config.getKeystore();
char[] password = null;
if (keystore != null) {
password = exchange.getIn().getHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, char[].class);
if (password == null) {
password = config.getPassword();
}
}
return password;
}
use of java.security.KeyStore in project camel by apache.
the class AbstractJsseParametersTest method createPropertiesPlaceholderAwareContext.
protected CamelContext createPropertiesPlaceholderAwareContext() throws Exception {
Properties supplementalProperties = new Properties();
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
SecureRandom sr = null;
try {
sr = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
// Ignore
}
SSLContext sslc = SSLContext.getInstance("TLS");
sslc.init(null, null, null);
SSLSocket socket = (SSLSocket) sslc.getSocketFactory().createSocket();
supplementalProperties.setProperty("keyStoreParameters.type", KeyStore.getDefaultType());
supplementalProperties.setProperty("keyStoreParameters.provider", ks.getProvider().getName());
supplementalProperties.setProperty("keyManagersParameters.algorithm", KeyManagerFactory.getDefaultAlgorithm());
supplementalProperties.setProperty("keyManagersParameters.provider", kmf.getProvider().getName());
supplementalProperties.setProperty("trustManagersParameters.algorithm", TrustManagerFactory.getDefaultAlgorithm());
supplementalProperties.setProperty("trustManagersParameters.provider", tmf.getProvider().getName());
if (sr != null) {
supplementalProperties.setProperty("secureRandomParameters.algorithm", "SHA1PRNG");
supplementalProperties.setProperty("secureRandomParameters.provider", sr.getProvider().getName());
}
supplementalProperties.setProperty("sslContextParameters.provider", sslc.getProvider().getName());
supplementalProperties.setProperty("cipherSuite.0", socket.getSupportedCipherSuites()[0]);
// Have to skip this guy because he doesn't work with TLS as the SSLContext protocol
String ssp = "";
for (String protocol : socket.getSupportedProtocols()) {
if (!"SSLv2Hello".equals(protocol)) {
ssp = protocol;
break;
}
}
supplementalProperties.setProperty("secureSocketProtocol.0", ssp);
return this.createPropertiesPlaceholderAwareContext(supplementalProperties);
}
use of java.security.KeyStore in project camel by apache.
the class KeyStoreParametersTest method testExplicitType.
public void testExplicitType() throws Exception {
KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
ksp.setType("jks");
KeyStore ks = ksp.createKeyStore();
assertNotNull(ks.getCertificate("server"));
}
use of java.security.KeyStore in project camel by apache.
the class KeyStoreParametersTest method testValidParameters.
public void testValidParameters() throws GeneralSecurityException, IOException, URISyntaxException {
KeyStoreParameters ksp = this.createMinimalKeyStoreParameters();
KeyStore ks = ksp.createKeyStore();
assertNotNull(ks.getCertificate("server"));
URL resourceUrl = this.getClass().getResource("/org/apache/camel/util/jsse/localhost.ks");
ksp.setResource(resourceUrl.toExternalForm());
ks = ksp.createKeyStore();
assertNotNull(ks.getCertificate("server"));
resourceUrl = this.getClass().getResource("/org/apache/camel/util/jsse/localhost.ks");
File file = new File(resourceUrl.toURI());
ksp.setResource(file.getAbsolutePath());
ks = ksp.createKeyStore();
assertNotNull(ks.getCertificate("server"));
}
Aggregations