どちらも X509TrustManager の同じ実装を持っていますが、「安全でない実装」があるとフラグが付けられ続けていますが、コードは同じです...これを改善する方法についてのヘルプ/ヒントをいただければ幸いです、セキュリティは私の得意分野ではありません。ありがとう
コード:
public void createTrustManager() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
try {
try {
chain[0].checkValidity();
} catch (java.security.cert.CertificateExpiredException e) {
e.printStackTrace();
} catch (java.security.cert.CertificateNotYetValidException e) {
e.printStackTrace();
}
} catch (IllegalArgumentException e) {
try {
throw new IllegalArgumentException("CertificateNotYetValidException");
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
}
}
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
SSLContext sc = null;
try {
sc = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
assert sc != null;
sc.init(null, trustAllCerts, new java.security.SecureRandom());
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession arg1) {
return hostname.equalsIgnoreCase(RestFUL_URLS.DOMAIN) || hostname.equalsIgnoreCase(RestFUL_URLS.DOMAIN) || hostname.equalsIgnoreCase("reports.crashlytics.com") || hostname.equalsIgnoreCase("api.crashlytics.com") || hostname.equalsIgnoreCase("api.pushy.me") || hostname.equalsIgnoreCase("mqtt.pushy.me") || hostname.equalsIgnoreCase("play.google.com" );
}
});
}