Search in sources :

Example 6 with IApiConnector

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

the class CipherAndProtocolSelectionTest method shouldNotUseDisallowedCipher.

/**
 * Scenario:
 *   - Should not use a disallowed cipher in the exchange
 * @throws Exception any exception
 */
@Test
public void shouldNotUseDisallowedCipher() throws Exception {
    final 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_DISALLOWEDCIPHERS, 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) {
            if (result.isError())
                throw new RuntimeException(result.getError());
            Assert.assertTrue(result.isSuccess());
            Assert.assertFalse(jettyRequestAttributes.get("javax.servlet.request.cipher_suite").equals(""));
            Assert.assertFalse(jettyRequestAttributes.get("javax.servlet.request.cipher_suite").equals(preferredCipher));
        }
    });
    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 7 with IApiConnector

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

the class CipherAndProtocolSelectionTest method shouldFailWhenRemoteCiphersAreExcluded.

/**
 * Scenario:
 *   - Only allowed protocol is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenRemoteCiphersAreExcluded() 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_DISALLOWEDCIPHERS, preferredCipher);
    jettySslContextFactory.setIncludeCipherSuites(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());
            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 8 with IApiConnector

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

the class CipherAndProtocolSelectionTest method shouldFailWhenNoValidProtocolAllowed.

/**
 * Scenario:
 *   - Only allowed cipher is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenNoValidProtocolAllowed() 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());
            // result.getError().printStackTrace();
            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 9 with IApiConnector

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

the class StandardTLSTest method shouldFailWithNoSettings.

/**
 * Scenario:
 *   - No settings whatsoever.
 *   - Will fail, as defaults are relatively safe,
 *     and API certificate will not be recognised.
 */
@Test
public void shouldFailWithNoSettings() {
    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());
        }
    });
    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 10 with IApiConnector

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

the class StandardTLSTest method shouldFailWhenCANotTrusted.

/**
 * Scenario:
 *   - CA is only in API trust store, missing from gateway trust store
 *   - Gateway does not trust API, as it does not trust CA
 *   - API trusts gateway via CA
 */
@Test
public void shouldFailWhenCANotTrusted() {
    // Keystore does not trust the root CA API is signed with.
    config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_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) {
            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)

Aggregations

IApiConnector (io.apiman.gateway.engine.IApiConnector)29 IApiConnection (io.apiman.gateway.engine.IApiConnection)26 ConnectorConfigImpl (io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl)26 HttpConnectorFactory (io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory)26 Test (org.junit.Test)26 IApiConnectionResponse (io.apiman.gateway.engine.IApiConnectionResponse)19 IAsyncResult (io.apiman.gateway.engine.async.IAsyncResult)9 ConnectorException (io.apiman.gateway.engine.beans.exceptions.ConnectorException)6 IConnectorConfig (io.apiman.gateway.engine.IConnectorConfig)2 IEngineResult (io.apiman.gateway.engine.IEngineResult)2 IAsyncResultHandler (io.apiman.gateway.engine.async.IAsyncResultHandler)2 ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)2 IApimanBuffer (io.apiman.gateway.engine.io.IApimanBuffer)2 ISignalWriteStream (io.apiman.gateway.engine.io.ISignalWriteStream)2 IConnectorInterceptor (io.apiman.gateway.engine.policy.IConnectorInterceptor)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 X509Certificate (java.security.cert.X509Certificate)2 IApiRequestExecutor (io.apiman.gateway.engine.IApiRequestExecutor)1 IConnectorFactory (io.apiman.gateway.engine.IConnectorFactory)1