Search in sources :

Example 21 with SSLContextParameters

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

the class FileToFtpsImplicitTLSWithClientAuthAndSSLContextParametersTest 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)

Example 22 with SSLContextParameters

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

the class WssProducerTest method defineSSLContextServerParameters.

private static SSLContextParameters defineSSLContextServerParameters() {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource("jsse/localhost.ks");
    ksp.setPassword(PW);
    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword(PW);
    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);
    return sslContextParameters;
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) 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 23 with SSLContextParameters

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

the class HttpComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
    final Map<String, Object> httpClientOptions = new HashMap<>();
    final HttpClientBuilder clientBuilder = createHttpClientBuilder(uri, parameters, httpClientOptions);
    HttpBinding httpBinding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
    HttpContext httpContext = resolveAndRemoveReferenceParameter(parameters, "httpContext", HttpContext.class);
    SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParameters", SSLContextParameters.class);
    if (sslContextParameters == null) {
        sslContextParameters = getSslContextParameters();
    }
    String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
    HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
    UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
    boolean secure = HttpHelper.isSecureConnection(uri) || sslContextParameters != null;
    // need to set scheme on address uri depending on if its secure or not
    String addressUri = (secure ? "https://" : "http://") + remaining;
    addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri);
    URI uriHttpUriAddress = new URI(addressUri);
    // validate http uri that end-user did not duplicate the http part that can be a common error
    int pos = uri.indexOf("//");
    if (pos != -1) {
        String part = uri.substring(pos + 2);
        if (part.startsWith("http:") || part.startsWith("https:")) {
            throw new ResolveEndpointFailedException(uri, "The uri part is not configured correctly. You have duplicated the http(s) protocol.");
        }
    }
    // create the configurer to use for this endpoint
    HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, secure);
    URI endpointUri = URISupport.createRemainingURI(uriHttpUriAddress, httpClientParameters);
    // the endpoint uri should use the component name as scheme, so we need to re-create it once more
    String scheme = ObjectHelper.before(uri, "://");
    endpointUri = URISupport.createRemainingURI(new URI(scheme, endpointUri.getUserInfo(), endpointUri.getHost(), endpointUri.getPort(), endpointUri.getPath(), endpointUri.getQuery(), endpointUri.getFragment()), httpClientParameters);
    // create the endpoint and set the http uri to be null
    String endpointUriString = endpointUri.toString();
    LOG.debug("Creating endpoint uri {}", endpointUriString);
    final HttpClientConnectionManager localConnectionManager = createConnectionManager(parameters, sslContextParameters);
    HttpEndpoint endpoint = new HttpEndpoint(endpointUriString, this, clientBuilder, localConnectionManager, configurer);
    // configure the endpoint with the common configuration from the component
    if (getHttpConfiguration() != null) {
        Map<String, Object> properties = new HashMap<>();
        IntrospectionSupport.getProperties(getHttpConfiguration(), properties, null);
        setProperties(endpoint, properties);
    }
    if (urlRewrite != null) {
        // let CamelContext deal with the lifecycle of the url rewrite
        // this ensures its being shutdown when Camel shutdown etc.
        getCamelContext().addService(urlRewrite);
        endpoint.setUrlRewrite(urlRewrite);
    }
    // configure the endpoint
    setProperties(endpoint, parameters);
    // determine the portnumber (special case: default portnumber)
    //int port = getPort(uriHttpUriAddress);
    // we can not change the port of an URI, we must create a new one with an explicit port value
    URI httpUri = URISupport.createRemainingURI(new URI(uriHttpUriAddress.getScheme(), uriHttpUriAddress.getUserInfo(), uriHttpUriAddress.getHost(), uriHttpUriAddress.getPort(), uriHttpUriAddress.getPath(), uriHttpUriAddress.getQuery(), uriHttpUriAddress.getFragment()), parameters);
    endpoint.setHttpUri(httpUri);
    if (headerFilterStrategy != null) {
        endpoint.setHeaderFilterStrategy(headerFilterStrategy);
    } else {
        setEndpointHeaderFilterStrategy(endpoint);
    }
    endpoint.setBinding(getHttpBinding());
    if (httpBinding != null) {
        endpoint.setBinding(httpBinding);
    }
    if (httpMethodRestrict != null) {
        endpoint.setHttpMethodRestrict(httpMethodRestrict);
    }
    endpoint.setHttpContext(getHttpContext());
    if (httpContext != null) {
        endpoint.setHttpContext(httpContext);
    }
    if (endpoint.getCookieStore() == null) {
        endpoint.setCookieStore(getCookieStore());
    }
    endpoint.setHttpClientOptions(httpClientOptions);
    return endpoint;
}
Also used : HashMap(java.util.HashMap) HttpContext(org.apache.http.protocol.HttpContext) UrlRewrite(org.apache.camel.http.common.UrlRewrite) HeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy) HttpRestHeaderFilterStrategy(org.apache.camel.http.common.HttpRestHeaderFilterStrategy) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) URI(java.net.URI) Endpoint(org.apache.camel.Endpoint) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) HttpBinding(org.apache.camel.http.common.HttpBinding) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager)

Example 24 with SSLContextParameters

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

the class BaseAhcTest method addSslContextParametersToRegistry.

protected void addSslContextParametersToRegistry(JndiRegistry registry) {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource(this.getClass().getClassLoader().getResource("jsse/localhost.ks").toString());
    ksp.setPassword(KEY_STORE_PASSWORD);
    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword(KEY_STORE_PASSWORD);
    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);
    // use SSLv3 to avoid issue with (eg disable TLS)
    // Caused by: javax.net.ssl.SSLException: bad record MAC
    sslContextParameters.setSecureSocketProtocol("SSLv3");
    registry.bind("sslContextParameters", sslContextParameters);
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) 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 25 with SSLContextParameters

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

the class SslContextParametersCometdProducerConsumerTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            KeyStoreParameters ksp = new KeyStoreParameters();
            ksp.setResource("jsse/localhost.ks");
            ksp.setPassword("changeit");
            KeyManagersParameters kmp = new KeyManagersParameters();
            kmp.setKeyPassword("changeit");
            kmp.setKeyStore(ksp);
            TrustManagersParameters tmp = new TrustManagersParameters();
            tmp.setKeyStore(ksp);
            SSLContextParameters sslContextParameters = new SSLContextParameters();
            sslContextParameters.setKeyManagers(kmp);
            sslContextParameters.setTrustManagers(tmp);
            CometdComponent component = (CometdComponent) context.getComponent("cometds");
            component.setSslContextParameters(sslContextParameters);
            from("direct:input").to(uri);
            from(uri).to("mock:test");
        }
    };
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) RouteBuilder(org.apache.camel.builder.RouteBuilder) TrustManagersParameters(org.apache.camel.util.jsse.TrustManagersParameters) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Aggregations

SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)59 KeyStoreParameters (org.apache.camel.util.jsse.KeyStoreParameters)35 KeyManagersParameters (org.apache.camel.util.jsse.KeyManagersParameters)28 TrustManagersParameters (org.apache.camel.util.jsse.TrustManagersParameters)27 JndiRegistry (org.apache.camel.impl.JndiRegistry)19 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 IOException (java.io.IOException)7 GeneralSecurityException (java.security.GeneralSecurityException)7 SSLContextServerParameters (org.apache.camel.util.jsse.SSLContextServerParameters)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 SSLContext (javax.net.ssl.SSLContext)5 Test (org.junit.Test)4 URI (java.net.URI)3 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)3 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)3 HttpClient (org.eclipse.jetty.client.HttpClient)3 JdkSslContext (io.netty.handler.ssl.JdkSslContext)2 URISyntaxException (java.net.URISyntaxException)2 CertificateException (java.security.cert.CertificateException)2 X509Certificate (java.security.cert.X509Certificate)2