Skip to content

Commit 5c3975c

Browse files
committed
fix(Windows): Revert to using the built-in cert provider
1 parent dee1a72 commit 5c3975c

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

common/src/jvmMain/kotlin/com/artemchep/keyguard/crypto/ssl/TrustManager.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ fun OkHttpClient.Builder.installMacOsTrustManager() = installHybridTrustManager
1919
getMacOsTrustManager()
2020
}
2121

22+
fun OkHttpClient.Builder.installWindowsTrustManager() = installHybridTrustManager {
23+
getWindowsTrustManager()
24+
}
25+
2226
private inline fun OkHttpClient.Builder.installHybridTrustManager(
2327
fallback: () -> X509TrustManager = { getDefaultTrustManager() },
2428
primary: () -> X509TrustManager,
@@ -55,6 +59,16 @@ private fun getMacOsTrustManager() = run {
5559
appleTm
5660
}
5761

62+
private fun getWindowsTrustManager() = run {
63+
val winFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
64+
val winKeyStore = KeyStore.getInstance("Windows-MY")
65+
winKeyStore.load(null, null)
66+
winFactory.init(winKeyStore)
67+
val winTm = winFactory.trustManagers
68+
.first { it is X509TrustManager } as X509TrustManager
69+
winTm
70+
}
71+
5872
/**
5973
* A TrustManager that delegates to a primary manager, and falls back
6074
* to a secondary manager if the primary fails validation.
@@ -65,8 +79,10 @@ private class HybridTrustManager(
6579
) : X509TrustManager {
6680
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
6781
try {
82+
println("??? BEFORE")
6883
primary.checkServerTrusted(chain, authType)
6984
} catch (_: CertificateException) {
85+
println("??? CHECK FAILED")
7086
secondary.checkServerTrusted(chain, authType)
7187
}
7288
}

desktopApp/build.gradle.kts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,6 @@ compose.desktop {
101101
jvmArgs(
102102
"-Dapple.awt.application.appearance=system",
103103
)
104-
105-
// Support system Keychain as trust store:
106-
// https://github.com/AChep/keyguard-app/issues/1227
107-
val platformJvmArgs = when {
108-
Os.isFamily(Os.FAMILY_MAC) -> {
109-
// We resort to runtime trust manager:
110-
// - KeychainStore is empty.
111-
// - KeychainStore-ROOT does not exist.
112-
arrayOf(
113-
)
114-
}
115-
Os.isFamily(Os.FAMILY_WINDOWS) -> {
116-
arrayOf(
117-
"-Djavax.net.ssl.trustStore=NONE",
118-
"-Djavax.net.ssl.trustStoreType=Windows-ROOT",
119-
)
120-
}
121-
else -> arrayOf()
122-
}
123-
jvmArgs(*platformJvmArgs)
124-
125104
includeAllModules = true
126105
val formats = listOfNotNull(
127106
TargetFormat.Dmg,

0 commit comments

Comments
 (0)