Skip to content

Instantly share code, notes, and snippets.

@whytarun
Created October 3, 2023 06:46
Show Gist options
  • Save whytarun/39d992154d625fbc1333be11116a53d2 to your computer and use it in GitHub Desktop.
Save whytarun/39d992154d625fbc1333be11116a53d2 to your computer and use it in GitHub Desktop.
SSL Support
class CertificateHelper @Inject constructor(@ApplicationContext context: Context) {
private val applicationContext = context
fun createTrustManagers(): Array<TrustManager> {
val certificateInputStream = applicationContext.resources.openRawResource(
R.raw.test)
val certificateFactory = CertificateFactory.getInstance("X.509")
val certificate = certificateFactory.generateCertificate(certificateInputStream)
val trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm())
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType())
keyStore.load(null)
keyStore.setCertificateEntry("test", certificate)
trustManagerFactory.init(keyStore)
return trustManagerFactory.trustManagers
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment