测试网站是否支持使用Java的相互SSL

问题描述 投票:0回答:1

我需要编写一个Cucumber Test案例,以验证网站是否支持Java 2路SSL。在无数次阅读了不同的文章和答案后,我不确定如何准确地做到这一点。我已经为测试用例的客户端生成了一个自签名证书,并将其添加到请求中,但是我不确定如何确切地验证所访问的网站是否支持2路SSL。到目前为止,这是我的代码,以至于我无法在线使用不同的答案和文章。

        org.apache.log4j.BasicConfigurator.configure();

        try {
            String CERT_PASSWORD = "somePass";

            KeyStore identityKeyStore = KeyStore.getInstance("jks");
            FileInputStream identityKeyStoreFile = new FileInputStream(new File(System.getProperty("user.dir") + "/src/main/resources/files-for-testcases/ultimate.jks"));
            identityKeyStore.load(identityKeyStoreFile, CERT_PASSWORD.toCharArray());


            SSLContext sslContext = SSLContexts.custom()
                    // load identity keystore
                    .loadKeyMaterial(identityKeyStore, CERT_PASSWORD.toCharArray(), (aliases, socket) -> "bddsecurity")
                    .build();

            SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
                    new String[]{"TLSv1.2", "TLSv1.1"},
                    null,
                    SSLConnectionSocketFactory.getDefaultHostnameVerifier());

            CloseableHttpClient client = HttpClients.custom()
                    .setSSLSocketFactory(sslConnectionSocketFactory)
                    .build();

            // Call a SSL-endpoint
            return callEndPoint (client, url);
        } catch (Exception ex) {
            System.out.println("Boom, we failed: " + ex);
            ex.printStackTrace();
        }
        return 404;
    }

    private static int callEndPoint (CloseableHttpClient aHTTPClient, String aEndPointURL) {

        try {
            HttpGet httpGet = new HttpGet(aEndPointURL);

            LOG.info("**GET** request Url: " + httpGet.getURI());

            HttpResponse response = aHTTPClient.execute(httpGet);

            int responseCode = response.getStatusLine().getStatusCode();
            LOG.info("Response Code: " + responseCode);
            return responseCode;
        } catch (Exception ex) {
            System.out.println("Boom, we failed: " + ex);
            ex.printStackTrace();
        }
        return 404;
    }
java security ssl testing certificate
1个回答
0
投票

所以只是为了更新,问题出在我的服务器上,它与没有证书的连接正常。并非如此,然后我的应用程序抛出了一个错误,但是诊断很简单,现在一切都很好。

© www.soinside.com 2019 - 2024. All rights reserved.