I hinzugefügt HTTPPinning der Beispielcode zu OKHTTPClient ist:CertPathValidatorException: Vertrauen Anker für Zertifizierungspfad nicht gefunden
OkHttpClient client = new OkHttpClient();
client.setSslSocketFactory(getPinnedCertSslSocketFactory(context));
private SSLSocketFactory getPinnedCertSslSocketFactory(Context context) {
try {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream incontext.getResources().openRawResource(R.raw.prod_keystore);
trusted.load(in, "[email protected]".toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trusted);
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
return sslContext.getSocketFactory();
} catch (Exception e) {
Log.e("MyApp", e.getMessage(), e);
}
return null;
}
ich die App in Plays und aus dem letzten 1 Jahr auf den Stationen hochgeladen es ist funktioniert gut. aber von der letzten 1 Woche ab wird die unten stehende Frage zu geben und ich OkHttp die Version com.squareup.okhttp: okhttp: 2.7.4
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) at com.squareup.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192) at com.squareup.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149) at com.squareup.okhttp.internal.io.RealConnection.connect(RealConnection.java:112) at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184) at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126) at com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95) at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281) at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224) at com.squareup.okhttp.Call.getResponse(Call.java:286) at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243) at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205) at com.squareup.okhttp.Call.execute(Call.java:80) at com.venkat.good.http.MyHTTPThread.run(MyHTTPThread.java:492) at com.venkat.good.http.MyHTTPThread.run(MyHTTPThread.java:76) at java.lang.Thread.run(Thread.java:818)
von OKHTTP3 mit aufgelöst ich dieses Problem.
String hostname = "yourdomain.com";
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add(hostname, "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
.build();
OkHttpClient client = OkHttpClient.Builder()
.certificatePinner(certificatePinner)
.build();
Request request = new Request.Builder()
.url("https://" + hostname)
.build();
client.newCall(request).execute();
Aber ich möchte wissen, warum die bisherige OkHttp2 Version für einige Tage arbeitet und nach, dass es die Frage aufwirft?
Gibt es eine Chance, dass sich auf der Serverseite etwas geändert hat oder dass das Zertifikat abgelaufen ist? –
Ich habe beim Erstellen der BKS-Datei kein Datum angegeben und die Server-Leute haben nichts an ihrer Seite geändert. – Venkat