-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add customizable accepted CA certificates to SSL config
- Loading branch information
1 parent
90ed4e6
commit f0e8a46
Showing
8 changed files
with
284 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/model/ImportedFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.sunnychung.application.multiplatform.hellohttp.model | ||
|
||
import com.sunnychung.application.multiplatform.hellohttp.annotation.Persisted | ||
import com.sunnychung.application.multiplatform.hellohttp.document.Identifiable | ||
import com.sunnychung.lib.multiplatform.kdatetime.KInstant | ||
import kotlinx.serialization.Serializable | ||
|
||
@Persisted | ||
@Serializable | ||
data class ImportedFile( | ||
override val id: String, | ||
val name: String, | ||
val originalFilename: String, | ||
val createdWhen: KInstant, | ||
val isEnabled: Boolean, | ||
val content: ByteArray, | ||
) : Identifiable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...chung/application/multiplatform/hellohttp/network/util/MultipleTrustCertificateManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.sunnychung.application.multiplatform.hellohttp.network.util | ||
|
||
import java.net.Socket | ||
import java.security.cert.CertificateException | ||
import java.security.cert.X509Certificate | ||
import javax.net.ssl.SSLEngine | ||
import javax.net.ssl.X509ExtendedTrustManager | ||
import javax.net.ssl.X509TrustManager | ||
|
||
class MultipleTrustCertificateManager(private val trustManagers: List<X509TrustManager>) : X509ExtendedTrustManager() { | ||
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?, socket: Socket?) { | ||
checkClientTrusted(chain, authType) | ||
} | ||
|
||
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?, engine: SSLEngine?) { | ||
checkClientTrusted(chain, authType) | ||
} | ||
|
||
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) { | ||
trustManagers.forEachIndexed { index, it -> | ||
try { | ||
it.checkClientTrusted(chain, authType) | ||
} catch (e: CertificateException) { | ||
if (index >= trustManagers.lastIndex) { | ||
throw e | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?, socket: Socket?) { | ||
checkServerTrusted(chain, authType) | ||
} | ||
|
||
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?, engine: SSLEngine?) { | ||
checkServerTrusted(chain, authType) | ||
} | ||
|
||
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) { | ||
trustManagers.forEachIndexed { index, it -> | ||
try { | ||
it.checkServerTrusted(chain, authType) | ||
} catch (e: CertificateException) { | ||
if (index >= trustManagers.lastIndex) { | ||
throw e | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun getAcceptedIssuers(): Array<X509Certificate> { | ||
return trustManagers.map { it.acceptedIssuers } | ||
.fold(mutableListOf<X509Certificate>()) { acc, it -> acc += it; acc } | ||
.toTypedArray() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.