icerockdev / moko-socket-io

MOKO SocketIo by IceRock is Socket.IO implementation Kotlin Multiplatform library
https://moko.icerock.dev/
Apache License 2.0
130 stars 23 forks source link

Keystore (SslSocketFactory) #42

Open JJSarrasin opened 4 months ago

JJSarrasin commented 4 months ago

Hello, Thanks for your lib. Is there a way to use a keystore with it. With the non-kmp lib we were using, we had to pass a okHttpClient like this:

    IO.setDefaultOkHttpWebSocketFactory(okHttpClient)
    IO.setDefaultOkHttpCallFactory(okHttpClient)
    val opts = IO.Options()
    opts.callFactory = okHttpClient
    opts.webSocketFactory = okHttpClient

This okHttpClient contains a keystore:

    val isP12 = context.resources.openRawResource(certResId)
    val keystore = KeyStore.getInstance("PKCS12")
    keystore?.load(isP12, "password")
    isP12.close()

    val okHttpClientBuilder = OkHttpClient.Builder()
    okHttpClientBuilder.sslSocketFactory(SslSettings.getSslContext(keystore)!!.socketFactory, SslSettings.getTrustManager())
    val okHttpClient = okHttpClientBuilder.build()

Is there a way to pass a similar configuration in moko-socket-io lib ?