|
@@ -32,7 +32,6 @@ object RetrofitManager {
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
okHttpClientBuilder.addInterceptor(ChuckerInterceptor(AppContext.getContext()))
|
|
|
}
|
|
|
- setSSLSocketFactory(okHttpClientBuilder)
|
|
|
okHttpClientBuilder.addInterceptor(SwagoInterceptor())
|
|
|
okHttpClientBuilder.retryOnConnectionFailure(true)
|
|
|
okHttpClientBuilder.connectTimeout(30000, TimeUnit.MILLISECONDS)
|
|
@@ -52,28 +51,4 @@ object RetrofitManager {
|
|
|
.client(okHttpClient)
|
|
|
.build()
|
|
|
}
|
|
|
-
|
|
|
- private fun setSSLSocketFactory(okHttpClientBuilder: OkHttpClient.Builder) {
|
|
|
- // 加载 PKCS12 格式的密钥库
|
|
|
- val inputStream: InputStream = AppContext.getContext().assets.open("ssl_crt.p12")
|
|
|
- val keyStore = KeyStore.getInstance("PKCS12")
|
|
|
- val keyStorePassword = "123456" // 密钥库密码
|
|
|
- keyStore.load(inputStream, keyStorePassword.toCharArray())
|
|
|
-
|
|
|
- // 用于从密钥库中获取密钥
|
|
|
- val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
|
|
|
- keyManagerFactory.init(keyStore, keyStorePassword.toCharArray())
|
|
|
-
|
|
|
- val trustManagerFactory =
|
|
|
- TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
|
|
|
- trustManagerFactory.init(keyStore)
|
|
|
-
|
|
|
- // 创建 SSLContext,用于建立安全连接
|
|
|
- val sslContext = SSLContext.getInstance("TLS")
|
|
|
- sslContext.init(keyManagerFactory.keyManagers, trustManagerFactory.trustManagers, null)
|
|
|
- okHttpClientBuilder.sslSocketFactory(
|
|
|
- sslContext.socketFactory ,
|
|
|
- (trustManagerFactory.trustManagers[0] as X509TrustManager
|
|
|
- ))
|
|
|
- }
|
|
|
}
|