2021-04-26 17:29:13 +02:00
|
|
|
include::../description.adoc[]
|
2020-06-30 14:41:58 +02:00
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
2021-04-26 17:29:13 +02:00
|
|
|
``++checkClientTrusted++`` and/or ``++checkServerTrusted++`` custom implementations from ``++X509TrustManager++`` interface accept any certificates:
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,kotlin]
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
2021-04-26 17:29:13 +02:00
|
|
|
// Create a trust manager that does not validate certificate chains
|
2020-06-30 14:41:58 +02:00
|
|
|
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
|
|
|
@Throws(CertificateException::class)
|
2022-07-18 15:49:45 +02:00
|
|
|
override fun checkClientTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) {
|
2021-04-26 17:29:13 +02:00
|
|
|
} // Noncompliant (s4830)
|
2020-06-30 14:41:58 +02:00
|
|
|
|
|
|
|
@Throws(CertificateException::class)
|
2022-07-18 15:49:45 +02:00
|
|
|
override fun checkServerTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) {
|
|
|
|
} // Noncompliant (s4830)
|
2020-06-30 14:41:58 +02:00
|
|
|
|
|
|
|
override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> {
|
|
|
|
return arrayOf()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-04-26 17:29:13 +02:00
|
|
|
// Install the all-trusting trust manager
|
2020-06-30 14:41:58 +02:00
|
|
|
val sslContext = SSLContext.getInstance("SSL")
|
|
|
|
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
2021-04-26 17:29:13 +02:00
|
|
|
By default, when a ``++TrustManager++`` is not set, ``++sslContext++`` will search for a default secure installed security provider:
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,kotlin]
|
2020-06-30 14:41:58 +02:00
|
|
|
----
|
|
|
|
val sslContext = SSLContext.getInstance("SSL")
|
|
|
|
sslContext.init(null, null, java.security.SecureRandom())
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|