Closed punksta closed 8 years ago
Really difficult to tell what action we should take here. Could you make a smaller test case, something that has no dependencies on anything other than OkHttp?
After reading okhttp3/recipes/CustomTrust example fixed! instead of
Builder::setSocketFactory(SocketFactory)
I need use
Builder::sslSocketFactory(
SSLSocketFactory sslSocketFactory, X509TrustManager trustManager)
so I rewrite getSllSocketFactory to
@Throws(CertificateException::class, NoSuchAlgorithmException::class,
IOException::class, KeyManagementException::class, KeyStoreException::class)
private fun initSllFactory(okhttpClientBuilder: OkHttpClient.Builder, context: Context, certResourceId: Int) {
val cf = CertificateFactory.getInstance("X.509")
val cert = context.resources.openRawResource(certResourceId)
val ca: Certificate
try {
ca = cf.generateCertificate(cert)
} finally {
cert.close()
}
val keyStoreType = KeyStore.getDefaultType()
val keyStore = KeyStore.getInstance(keyStoreType)
keyStore.load(null, null)
keyStore.setCertificateEntry("ca", ca)
val tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm()
val tmf: TrustManagerFactory = TrustManagerFactory.getInstance(tmfAlgorithm)
tmf.init(keyStore)
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, tmf.trustManagers, null)
okhttpClientBuilder.sslSocketFactory(sslContext.socketFactory,
tmf.trustManagers.get(0) as X509TrustManager?)
}
What kind of issue is this?
Part of my dagger network module(kotlin)
connection spec:
sdk\libs versions:
I use following command to generate hash of public key. Also I use cert.crt for socketFactory
tested on google emulators for x86 22 and 23 api