を見つけていない証明書パスのトラストアンカー私は、サンプルコードをOKHTTPClientするHTTPPinningを追加しましたが、次のとおりです。するCertPathValidatorException:
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;
}
私はそれがある病棟にplaystoreに、最後の1年からアプリをアップロード働く良い。しかし、最後の1週間以降から、それは以下の問題を与えていると私はバージョンcom.squareup.okhttpの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)
をOKHTTP3を使用して、私はこの問題を解決しました。
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();
しかし、私は、以前のOkHttp2バージョンは、いくつかの日のために働き、その後、それは問題を提起する理由を知りたいですか?
サーバー側で何かが変更されたか、証明書が失効する可能性はありますか? –
BKSファイルの作成時に日付を指定していないため、サーバー側の人は何も変更しませんでした。 – Venkat