Search in sources :

Example 46 with KeyStoreParameters

use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.

the class NettySSLContextParametersTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource(this.getClass().getClassLoader().getResource("keystore.jks").toString());
    ksp.setPassword("changeit");
    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword("changeit");
    kmp.setKeyStore(ksp);
    TrustManagersParameters tmp = new TrustManagersParameters();
    tmp.setKeyStore(ksp);
    // NOTE: Needed since the client uses a loose trust configuration when no ssl context
    // is provided.  We turn on WANT client-auth to prefer using authentication
    SSLContextServerParameters scsp = new SSLContextServerParameters();
    scsp.setClientAuthentication(ClientAuthentication.WANT.name());
    SSLContextParameters sslContextParameters = new SSLContextParameters();
    sslContextParameters.setKeyManagers(kmp);
    sslContextParameters.setTrustManagers(tmp);
    sslContextParameters.setServerParameters(scsp);
    JndiRegistry registry = super.createRegistry();
    registry.bind("sslContextParameters", sslContextParameters);
    return registry;
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) JndiRegistry(org.apache.camel.impl.JndiRegistry) TrustManagersParameters(org.apache.camel.util.jsse.TrustManagersParameters) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) SSLContextServerParameters(org.apache.camel.util.jsse.SSLContextServerParameters) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 47 with KeyStoreParameters

use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.

the class SalesforceSession method generateJwtAssertion.

String generateJwtAssertion() {
    final long utcPlusWindow = Clock.systemUTC().millis() / 1000 + JWT_CLAIM_WINDOW;
    final StringBuilder claim = new StringBuilder().append("{\"iss\":\"").append(config.getClientId()).append("\",\"sub\":\"").append(config.getUserName()).append("\",\"aud\":\"").append(config.getLoginUrl()).append("\",\"exp\":\"").append(utcPlusWindow).append("\"}");
    final StringBuilder token = new StringBuilder(JWT_HEADER).append('.').append(Base64.getUrlEncoder().encodeToString(claim.toString().getBytes(StandardCharsets.UTF_8)));
    final KeyStoreParameters keyStoreParameters = config.getKeystore();
    keyStoreParameters.setCamelContext(camelContext);
    try {
        final KeyStore keystore = keyStoreParameters.createKeyStore();
        final Enumeration<String> aliases = keystore.aliases();
        String alias = null;
        while (aliases.hasMoreElements()) {
            String tmp = aliases.nextElement();
            if (keystore.isKeyEntry(tmp)) {
                if (alias == null) {
                    alias = tmp;
                } else {
                    throw new IllegalArgumentException("The given keystore `" + keyStoreParameters.getResource() + "` contains more than one key entry, expecting only one");
                }
            }
        }
        PrivateKey key = (PrivateKey) keystore.getKey(alias, keyStoreParameters.getPassword().toCharArray());
        Signature signature = Signature.getInstance(JWT_SIGNATURE_ALGORITHM);
        signature.initSign(key);
        signature.update(token.toString().getBytes(StandardCharsets.UTF_8));
        byte[] signed = signature.sign();
        token.append('.').append(Base64.getUrlEncoder().encodeToString(signed));
    } catch (IOException | GeneralSecurityException e) {
        throw new IllegalStateException(e);
    }
    return token.toString();
}
Also used : PrivateKey(java.security.PrivateKey) GeneralSecurityException(java.security.GeneralSecurityException) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) IOException(java.io.IOException) KeyStore(java.security.KeyStore) Signature(java.security.Signature)

Example 48 with KeyStoreParameters

use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.

the class SalesforceJwtBearerTokenFlowIntegrationTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    final CamelContext camelContext = super.createCamelContext();
    final SalesforceComponent salesforce = new SalesforceComponent();
    final Properties properties = LoginConfigHelper.testLoginProperties();
    salesforce.setClientId(properties.getProperty("clientId"));
    salesforce.setUserName(properties.getProperty("userName"));
    salesforce.setLoginUrl(properties.getProperty("loginUrl"));
    KeyStoreParameters keystore = new KeyStoreParameters();
    keystore.setResource(properties.getProperty("keystore.resource"));
    keystore.setType(properties.getProperty("keystore.type"));
    keystore.setPassword(properties.getProperty("keystore.password"));
    salesforce.setKeystore(keystore);
    camelContext.addComponent("salesforce", salesforce);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Properties(java.util.Properties)

Example 49 with KeyStoreParameters

use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.

the class FileToFtpsExplicitSSLWithClientAuthAndSSLContextParametersTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource("server.jks");
    ksp.setPassword("password");
    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword("password");
    kmp.setKeyStore(ksp);
    TrustManagersParameters tmp = new TrustManagersParameters();
    tmp.setKeyStore(ksp);
    SSLContextParameters sslContextParameters = new SSLContextParameters();
    sslContextParameters.setSecureSocketProtocol("SSL");
    sslContextParameters.setKeyManagers(kmp);
    sslContextParameters.setTrustManagers(tmp);
    JndiRegistry registry = super.createRegistry();
    registry.bind("sslContextParameters", sslContextParameters);
    return registry;
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) JndiRegistry(org.apache.camel.impl.JndiRegistry) TrustManagersParameters(org.apache.camel.util.jsse.TrustManagersParameters) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 50 with KeyStoreParameters

use of org.apache.camel.util.jsse.KeyStoreParameters in project camel by apache.

the class FileToFtpsExplicitTLSWithClientAuthAndSSLContextParametersTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource("server.jks");
    ksp.setPassword("password");
    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword("password");
    kmp.setKeyStore(ksp);
    TrustManagersParameters tmp = new TrustManagersParameters();
    tmp.setKeyStore(ksp);
    SSLContextParameters sslContextParameters = new SSLContextParameters();
    sslContextParameters.setSecureSocketProtocol("TLS");
    sslContextParameters.setKeyManagers(kmp);
    sslContextParameters.setTrustManagers(tmp);
    JndiRegistry registry = super.createRegistry();
    registry.bind("sslContextParameters", sslContextParameters);
    return registry;
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) JndiRegistry(org.apache.camel.impl.JndiRegistry) TrustManagersParameters(org.apache.camel.util.jsse.TrustManagersParameters) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Aggregations

KeyStoreParameters (org.apache.camel.util.jsse.KeyStoreParameters)57 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)31 KeyManagersParameters (org.apache.camel.util.jsse.KeyManagersParameters)25 RouteBuilder (org.apache.camel.builder.RouteBuilder)24 TrustManagersParameters (org.apache.camel.util.jsse.TrustManagersParameters)24 Test (org.junit.Test)21 JndiRegistry (org.apache.camel.impl.JndiRegistry)17 SSLContextServerParameters (org.apache.camel.util.jsse.SSLContextServerParameters)7 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 HashMap (java.util.HashMap)3 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 KeyStore (java.security.KeyStore)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 PrivateKey (java.security.PrivateKey)1 Signature (java.security.Signature)1 Certificate (java.security.cert.Certificate)1