【问题标题】:Retrofit with OKHTTP3 certification pinning使用 OKHTTP3 证书固定进行改造
【发布时间】:2017-04-29 16:15:49
【问题描述】:

我正在使用带有 OKHTTP3 客户端的 Retrofit 1.9,并且我正在尝试添加认证固定。下面是相关代码:

String hostname = "xxxxxx.xx";

CertificatePinner certificatePinner = new CertificatePinner.Builder()
    .add(hostname, "sha1/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=")
    .build();

OkHttpClient client = new OkHttpClient.Builder()
     .certificatePinner(certificatePinner)
     .build();

return new RestAdapter.Builder()
     .setRequestInterceptor(request -> {
         request.addHeader("CONTENT-TYPE", "application/json");
     })
     .setEndpoint("https://xxxxxxxxxxxx").
     .setClient(new Ok3Client(client))
     .build();

不幸的是,它似乎不起作用。我没有

"javax.net.ssl.SSLPeerUnverifiedException: Certificate pinning failure!"

异常,甚至我的主机或 SHA 都不正确。谁能解释一下为什么?

【问题讨论】:

标签: android ssl retrofit okhttp3 certificate-pinning


【解决方案1】:

有几件事情需要检查,因为你已经编辑了这些部分,所以错误很常见,我不能确定这些是否是你的问题,但是这两个错误都会导致没有固定的没有日志。

1) 对于CertificatePinner 中的hostname,请确保它只是主机名,例如“www.example.com”,而不是网址“https://www.example.com”。
2) 对于.setEndpoint("xxxxxxxxxxxx"),确保您的端点是httpshttp 上没有检查任何证书,所以没有日志。

【讨论】:

    猜你喜欢
    • 2020-02-12
    • 2018-01-19
    • 2018-04-07
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 2022-12-16
    相关资源
    最近更新 更多