Skip to content

Insecure flag does not work #12

@robert-farkas-dedalus

Description

@robert-farkas-dedalus

Hi!

I am trying to use the plugin with HTTPS and even if I use the insecure flag with true, I am getting SSLHandshakeException exception:

<executions> <execution> <id>wait-for-environment-to-be-up</id> <goals> <goal>waitfor</goal> </goals> <phase>pre-integration-test</phase> <configuration> <timeoutSeconds>${test.startup.timeoutSeconds}</timeoutSeconds> <checkEveryMillis>2000</checkEveryMillis> <insecure>true</insecure> <checks> <check> <url>https://${env.PROXY_HOST}:18443/health/live</url> </check> </checks> </configuration> </execution> </executions>

Error:

[INFO] >>> Checking https://172.23.125.61:18443/health/live...
[INFO]
[WARNING] https://172.23.125.61:18443/health/live failed (javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target)

I checked the code and modified a little bit which works fine for me, resulting output:
Executing request GET https://172.23.125.61:18443/health/live HTTP/1.1
!!!!!!!!!!!!!!!!!!!!1 finished

Could you please check the code in version 1.4 and use code below if it helps in the fix?

Code:

`import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class HttpClientTest {

@Test
void testUpdateObservation() throws Exception {
    try (CloseableHttpClient httpclient = createAcceptSelfSignedCertificateClient()) {
        HttpGet httpget = new HttpGet("https://172.23.125.61:18443/health/live");
        System.out.println("Executing request " + httpget.getRequestLine());

        httpclient.execute(httpget);
        System.out.println("!!!!!!!!!!!!!!!!!!!!1 finished");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

private CloseableHttpClient createAcceptSelfSignedCertificateClient() {
    try {
        final SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustStrategy() {

            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }

        });
        final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);

        CloseableHttpClient httpclient = HttpClients
                .custom()
                .setSSLSocketFactory(sslsf)
                .build();

        return httpclient;
    } catch (NoSuchAlgorithmException|KeyStoreException|KeyManagementException e) {
        System.out.println("Can not generate the ssl context for self signed certificates. " + e.getMessage());
        return null;
    }
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions