首页 > 解决方案 > CertPathValidatorException:找不到证书路径的信任锚。在 android 中更新 gradle 和 gradle 插件后

问题描述

我尝试通过此代码检查 SSL(并成功运行):

OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder();
CertificatePinner certificatePinner = new CertificatePinner.Builder()
        .add("example.com", "sha256/S4AbJNGvyS57nzJwv8sPMUML8VHSqH1vbiBftdPcErI=")
        .build();
OkHttpClient client1 = httpBuilder
        .certificatePinner(certificatePinner)
        .build();
Retrofit retrofit1 = new Retrofit.Builder()
        .client(client1)
        .baseUrl("https://example.com/").addConverterFactory(GsonConverterFactory.create()).build();
samaniumRestApi2 userClient = retrofit1.create(samaniumRestApi2.class);
Call<Object> call = userClient.maintenanceMode(requestmaintenanceModeCheck);
call.enqueue(xxxxxxxxxxxxx);

我通过将基本网址更改为:

https://example.com:448/

或者

https://subdomain.example.com/

错误是:

CertPathValidatorException: Trust anchor for certification path not found.

请救救我

标签: javaandroid-studiogradleretrofit2gradle-plugin

解决方案


这意味着证书是为www.example.com颁发的,因此无法信任whatever.example.com - 此服务器需要适当的签名证书


推荐阅读