Skip to content

Commit

Permalink
Fix client certificate-only usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Apr 21, 2024
1 parent 79584c8 commit 60946e4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/main/kotlin/com/github/gotify/api/CertUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal object CertUtils {
)
if (tempKeyManagers.isNotEmpty()) {
keyManagers = tempKeyManagers
customManagers = true
}
}
if (!settings.validateSSL) {
Expand All @@ -75,10 +76,17 @@ internal object CertUtils {
if (customManagers || !settings.validateSSL) {
val context = SSLContext.getInstance("TLS")
context.init(keyManagers, trustManagers, SecureRandom())
builder.sslSocketFactory(
context.socketFactory,
trustManagers!![0] as X509TrustManager
)
if (trustManagers != null) {
// Use custom trust manager
builder.sslSocketFactory(
context.socketFactory,
trustManagers[0] as X509TrustManager
)
} else {
// Fall back to system trust managers
@Suppress("DEPRECATION")
builder.sslSocketFactory(context.socketFactory)
}
}
} catch (e: Exception) {
// We shouldn't have issues since the cert is verified on login.
Expand Down

0 comments on commit 60946e4

Please sign in to comment.