Fix client certificate-only usage
This commit is contained in:
@@ -66,6 +66,7 @@ internal object CertUtils {
|
|||||||
)
|
)
|
||||||
if (tempKeyManagers.isNotEmpty()) {
|
if (tempKeyManagers.isNotEmpty()) {
|
||||||
keyManagers = tempKeyManagers
|
keyManagers = tempKeyManagers
|
||||||
|
customManagers = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!settings.validateSSL) {
|
if (!settings.validateSSL) {
|
||||||
@@ -75,10 +76,17 @@ internal object CertUtils {
|
|||||||
if (customManagers || !settings.validateSSL) {
|
if (customManagers || !settings.validateSSL) {
|
||||||
val context = SSLContext.getInstance("TLS")
|
val context = SSLContext.getInstance("TLS")
|
||||||
context.init(keyManagers, trustManagers, SecureRandom())
|
context.init(keyManagers, trustManagers, SecureRandom())
|
||||||
|
if (trustManagers != null) {
|
||||||
|
// Use custom trust manager
|
||||||
builder.sslSocketFactory(
|
builder.sslSocketFactory(
|
||||||
context.socketFactory,
|
context.socketFactory,
|
||||||
trustManagers!![0] as X509TrustManager
|
trustManagers[0] as X509TrustManager
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
// Fall back to system trust managers
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
builder.sslSocketFactory(context.socketFactory)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// We shouldn't have issues since the cert is verified on login.
|
// We shouldn't have issues since the cert is verified on login.
|
||||||
|
|||||||
Reference in New Issue
Block a user