我目前正在重寫X509TrustManager以允許所有的證書作爲臨時的'解決方案'(一個不安全的)。我試圖弄清楚我將如何進行添加,因此只接受一個特定的證書,證明我有問題,直到可以完成適當的修復(此時不在我的手中)。這是當前的代碼。X509TrustManager覆蓋不允許所有證書?
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
}};
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (GeneralSecurityException e) {
System.out.println(e.getStackTrace());
}
爲什麼返回null而不是空數組?規範說返回一個非空數組。 – Jayen 2012-12-13 02:02:15