I’m new to Kotlin. I’m trying to permit an Https connection, using the Trust Manager. My domain is self-signed, so I saved the certificate into the project res/raw folder. Trying to build up certificate, I wanted to use the (***) instruction, which is not resolved. I refer to API 28, Android Studio 3.4.2, Kotlin plugin version 1.3.41. Would anybody help me please?
// Load CAs from an InputStream
val cf: CertificateFactory = CertificateFactory.getInstance("X.509")
*** val caInput : InputStream = Resources.openRawResource(R.raw.srvca3)
val ca: X509Certificate = caInput.use {
cf.generateCertificate(it) as X509Certificate
}
val keyStoreType = KeyStore.getDefaultType()
val keyStore = KeyStore.getInstance(keyStoreType).apply {
load(null, null)
setCertificateEntry("ca", ca)
}
// Create a TrustManager that trusts the CAs inputStream our KeyStore
val tmfAlgorithm: String = TrustManagerFactory.getDefaultAlgorithm()
val tmf: TrustManagerFactory = TrustManagerFactory.getInstance(tmfAlgorithm).apply {
init(keyStore)
}