gpt4 book ai didi

android - CertPathValidatorException : Trust anchor for certification path not found

转载 作者:IT老高 更新时间:2023-10-28 23:16:26 24 4
gpt4 key购买 nike

我在OKHTTPClient中添加了HTTPPinning,示例代码为:

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, "venkat@123".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;
}

I uploaded the app into playstore and from the last 1 year on wards it is working good. but from the last 1 week onwards it is giving the below issue and I used OkHttp of 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)

通过使用 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();

But I want to know why the previous OkHttp2 version works for some days and after that it raises the issue?

最佳答案

迟到总比不到好

很高兴您使用 OkHttp3 解决了您的问题。


让我回答你提出的子问题:

这是一个构建系统配置问题,而不是 OkHttp 的问题。每个人都惊讶地看到这样的行为,因为它应该是解决OkHttp3要求的更高版本使用。如果您使用的是 mavenretrofit,则已将修复合并到较新的版本中(OkHttp3 为上述库实现了它)。

关于android - CertPathValidatorException : Trust anchor for certification path not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43797396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com