Search in sources :

Example 21 with IApiConnection

use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.

the class CipherAndProtocolSelectionTest method shouldFailWhenNoValidCipherAllowed.

/**
 * Scenario:
 *   - Only allowed protocol is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenNoValidCipherAllowed() throws Exception {
    String preferredCipher = getPrefferedCipher();
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
    config.put(TLSOptions.TLS_ALLOWEDCIPHERS, preferredCipher);
    jettySslContextFactory.setExcludeCipherSuites(preferredCipher);
    server.start();
    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
    IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {

        @Override
        public void handle(IAsyncResult<IApiConnectionResponse> result) {
            Assert.assertTrue(result.isError());
            System.out.println(result.getError());
            // result.getError().printStackTrace();
            Assert.assertTrue(result.getError().getCause() instanceof javax.net.ssl.SSLHandshakeException);
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 22 with IApiConnection

use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.

the class CipherAndProtocolSelectionTest method getPrefferedCipher.

private String getPrefferedCipher() throws Exception {
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
    config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "changeme");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
    server.start();
    final StringBuilder sbuff = new StringBuilder();
    final CountDownLatch latch = new CountDownLatch(1);
    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
    IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {

        @Override
        public void handle(IAsyncResult<IApiConnectionResponse> result) {
            if (result.isError())
                throw new RuntimeException(result.getError());
            sbuff.append(jettyRequestAttributes.get("javax.servlet.request.cipher_suite"));
            latch.countDown();
        }
    });
    connection.end();
    server.stop();
    latch.await();
    return sbuff.toString();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector)

Example 23 with IApiConnection

use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.

the class CipherAndProtocolSelectionTest method shouldFailWhenRemoteProtocolsAreExcluded.

/**
 * Scenario:
 *   - Only allowed protocol is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenRemoteProtocolsAreExcluded() throws Exception {
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
    config.put(TLSOptions.TLS_DISALLOWEDPROTOCOLS, "SSLv3");
    jettySslContextFactory.setIncludeProtocols("SSLv3");
    jettySslContextFactory.setExcludeProtocols("SSLv1", "SSLv2", "TLSv1", "TLSv2");
    server.start();
    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
    IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {

        @Override
        public void handle(IAsyncResult<IApiConnectionResponse> result) {
            Assert.assertTrue(result.isError());
            System.out.println(result.getError());
            Assert.assertTrue(result.getError() instanceof ConnectorException);
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorException(io.apiman.gateway.engine.beans.exceptions.ConnectorException) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 24 with IApiConnection

use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.

the class CipherAndProtocolSelectionTest method shouldFailWhenAllAvailableProtocolsExcluded.

/**
 * Scenario:
 *   - Only allowed protocol is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenAllAvailableProtocolsExcluded() throws Exception {
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
    config.put(TLSOptions.TLS_ALLOWEDPROTOCOLS, "SSLv3");
    jettySslContextFactory.setExcludeProtocols("SSLv3");
    server.start();
    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
    IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {

        @Override
        public void handle(IAsyncResult<IApiConnectionResponse> result) {
            Assert.assertTrue(result.isError());
            System.out.println(result.getError());
            Assert.assertTrue(result.getError().getCause() instanceof java.net.UnknownServiceException);
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 25 with IApiConnection

use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.

the class StandardTLSTest method shouldSucceedWithValidTLS.

/**
 * Scenario:
 *   - CA inherited trust
 *   - gateway trusts API via CA
 *   - API does not evaluate trust
 */
@Test
public void shouldSucceedWithValidTLS() {
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
    config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
    config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
    config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
    HttpConnectorFactory factory = new HttpConnectorFactory(config);
    IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
    IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {

        @Override
        public void handle(IAsyncResult<IApiConnectionResponse> result) {
            if (result.isError())
                throw new RuntimeException(result.getError());
            Assert.assertTrue(result.isSuccess());
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Aggregations

IApiConnection (io.apiman.gateway.engine.IApiConnection)26 IApiConnector (io.apiman.gateway.engine.IApiConnector)26 ConnectorConfigImpl (io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl)26 HttpConnectorFactory (io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory)26 Test (org.junit.Test)25 IApiConnectionResponse (io.apiman.gateway.engine.IApiConnectionResponse)18 IAsyncResult (io.apiman.gateway.engine.async.IAsyncResult)8 ConnectorException (io.apiman.gateway.engine.beans.exceptions.ConnectorException)6 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 X509Certificate (java.security.cert.X509Certificate)2 CountDownLatch (java.util.concurrent.CountDownLatch)1