Skip to content

Commit 7701e53

Browse files
Potential fix for code scanning alert no. 1: TrustManager that accepts all certificates
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 5095d07 commit 7701e53

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

src/main/java/wtx/woocommerce/api/client/invoker/ApiClient.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,28 +1498,10 @@ private void applySslSettings() {
14981498
TrustManager[] trustManagers;
14991499
HostnameVerifier hostnameVerifier;
15001500
if (!verifyingSsl) {
1501-
trustManagers = new TrustManager[]{
1502-
new X509TrustManager() {
1503-
@Override
1504-
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
1505-
}
1506-
1507-
@Override
1508-
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
1509-
}
1510-
1511-
@Override
1512-
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
1513-
return new java.security.cert.X509Certificate[]{};
1514-
}
1515-
}
1516-
};
1517-
hostnameVerifier = new HostnameVerifier() {
1518-
@Override
1519-
public boolean verify(String hostname, SSLSession session) {
1520-
return true;
1521-
}
1522-
};
1501+
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
1502+
trustManagerFactory.init((KeyStore) null);
1503+
trustManagers = trustManagerFactory.getTrustManagers();
1504+
hostnameVerifier = OkHostnameVerifier.INSTANCE;
15231505
} else {
15241506
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
15251507

0 commit comments

Comments
 (0)