我有一个应用程序,它使用 KSOAP2 库通过 https 连接连接到 SOAP Web 服务。
现在我接受所有带有以下代码的证书:
public static void createTrustManager(){
TrustManager[] trustAllCerts = createTrustAllCerts();
// Install the all-trusting trust manager
try{
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
catch (NoSuchAlgorithmException exception){}
catch (KeyManagementException exception){}
}
public static TrustManager[] createTrustAllCerts() {
// Create a trust manager that does not validate certificate chains
X509TrustManager trustManager = createX509TrustManager();
return new TrustManager[]{trustManager};
}
public static X509TrustManager createX509TrustManager() {
X509TrustManager trustManager = new X509TrustManager(){
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) { SSLUtilities.checkClientTrusted = true;}
public void checkServerTrusted(X509Certificate[] certs, String authType) { SSLUtilities.checkServerTrusted = true;}
};
return trustManager;
}
但现在我只需要考虑涉及我拥有的 https 连接的证书。我没有找到如何解决它。有人能帮我吗?