File tree Expand file tree Collapse file tree
src/androidMain/kotlin/com/piasy/kmp/socketio/engineio/transports Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,13 +6,28 @@ plugins {
66 alias(libs.plugins.kmp)
77 alias(libs.plugins.vanniktech.mavenPublish)
88 alias(libs.plugins.kover)
9+ alias(libs.plugins.android.library)
910}
1011
1112version = Consts .releaseVersion
1213group = Consts .releaseGroup
1314
15+ android {
16+ namespace = " ${Consts .androidNS} .android"
17+ compileSdk = libs.versions.compileSdk.get().toInt()
18+ defaultConfig {
19+ minSdk = libs.versions.minSdk.get().toInt()
20+ }
21+
22+ compileOptions {
23+ sourceCompatibility = JavaVersion .toVersion(libs.versions.jvm.get().toInt())
24+ targetCompatibility = JavaVersion .toVersion(libs.versions.jvm.get().toInt())
25+ }
26+ }
27+
1428kotlin {
1529 jvm()
30+ androidTarget()
1631
1732 iosArm64()
1833 iosSimulatorArm64()
@@ -69,6 +84,11 @@ kotlin {
6984 api(libs.ktor.client.cio) // cio engine works fine
7085 }
7186 }
87+ androidMain {
88+ dependencies {
89+ api(libs.ktor.client.okhttp)
90+ }
91+ }
7292 jvmTest {
7393 dependencies {
7494 implementation(libs.kotlin.test)
Original file line number Diff line number Diff line change 1+ package com.piasy.kmp.socketio.engineio.transports
2+
3+ import io.ktor.client.HttpClient
4+ import io.ktor.client.HttpClientConfig
5+ import io.ktor.client.engine.okhttp.OkHttp
6+ import java.security.SecureRandom
7+ import java.security.cert.X509Certificate
8+ import javax.net.ssl.SSLContext
9+ import javax.net.ssl.X509TrustManager
10+
11+ actual fun httpClient (
12+ trustAllCerts : Boolean ,
13+ config : HttpClientConfig <* >.() -> Unit
14+ ): HttpClient = HttpClient (OkHttp ) {
15+ if (trustAllCerts) {
16+ val trustManager = object : X509TrustManager {
17+ override fun checkClientTrusted (chain : Array <out X509Certificate >? , authType : String? ) = Unit
18+ override fun checkServerTrusted (chain : Array <out X509Certificate >? , authType : String? ) = Unit
19+ override fun getAcceptedIssuers (): Array <X509Certificate > = emptyArray()
20+ }
21+
22+ val sslContext = SSLContext .getInstance(" TLS" ).apply {
23+ init (null , arrayOf(trustManager), SecureRandom ())
24+ }
25+
26+ engine {
27+ config {
28+ sslSocketFactory(sslContext.socketFactory, trustManager)
29+ hostnameVerifier { _, _ -> true }
30+ }
31+ }
32+ }
33+
34+ config(this )
35+ }
You can’t perform that action at this time.
0 commit comments