[英]Retrofit with OKHTTP3 certification pinning
I am using Retrofit 1.9 with OKHTTP3 client and I am trying to add certification pinning. 我正在使用带有OKHTTP3客户端的Retrofit 1.9,我正在尝试添加认证固定。 Below is the relevant code:
以下是相关代码:
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();
Unfortunately it doesn't seem to be working. 不幸的是它似乎没有用。 I don't have the
我没有
"javax.net.ssl.SSLPeerUnverifiedException: Certificate pinning failure!"
exception and even my host or SHA is incorrect. 异常,甚至我的主机或SHA都不正确。 Can anyone explain why?
有谁能解释为什么?
A couple things to check, since you've redacted the parts were mistakes are common, I can't tell for certain if these are you issue, but both mistakes will cause no pinning with no logs. 要检查的几件事情,因为你已经编辑了部件是错误是常见的,我无法确定这些是否是你的问题,但是这两个错误都不会导致没有日志的固定。
1) For hostname
in your CertificatePinner
, make sure it is just the host name, like "www.example.com", and not a url " https://www.example.com ". 1)对于
CertificatePinner
hostname
,请确保它只是主机名,例如“www.example.com”,而不是网址“ https://www.example.com ”。
2) For .setEndpoint("xxxxxxxxxxxx")
, make sure you endpoint is https
, there are no certs checked on http
so no logs. 2)对于
.setEndpoint("xxxxxxxxxxxx")
,请确保端点为https
,没有在http
检查证书,因此没有日志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.