【发布时间】:2020-02-12 00:24:21
【问题描述】:
在我的 Android 应用程序中,我需要使用证书固定。我正在使用 Retrofit 和 OkHttp3 来使用 Web 服务,并且我已经定义了证书哈希码的固定。
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add("dummy.com", "sha256/xxxxxxxxxx=")
.build();
OkHttpClient httpClient = new OkHttpClient.Builder()
.certificatePinner(certificatePinner)
.callTimeout(240, TimeUnit.SECONDS)
.readTimeout(240, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.build();
Retrofit retrofitKripton = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(KriptonBinderConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.client(httpClient).build();
我想强制证书固定直到证书到期,之后我只想避免证书固定(这是因为我想避免该应用程序在证书到期后停止工作)。有没有办法告诉OkHpttp3/Retrofit 具有所需的行为?
提前致谢
【问题讨论】:
-
你用的是哪个版本的Android SDK,改造?我正在尝试做同样的事情,但调试工作但在发布时看起来 okhttp/retrofit 有一些问题,但它没有记录问题。
标签: android ssl okhttp certificate-pinning