![](/img/trans.png)
[英]OkHttp3, Retrofit and certificate pinning: how to give an expiration to the pinning
[英]Retrofit with OKHTTP3 certification pinning
我正在使用帶有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都不正確。 有誰能解釋為什么?
要檢查的幾件事情,因為你已經編輯了部件是錯誤是常見的,我無法確定這些是否是你的問題,但是這兩個錯誤都不會導致沒有日志的固定。
1)對於CertificatePinner
hostname
,請確保它只是主機名,例如“www.example.com”,而不是網址“ https://www.example.com ”。
2)對於.setEndpoint("xxxxxxxxxxxx")
,請確保端點為https
,沒有在http
檢查證書,因此沒有日志。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.