Ich habe bereits eine .pem- und eine .Key -Dateien, die ich nicht lokal installieren/importieren möchte. Sagen Sie meinem Client einfach, dass er sie verwenden soll. Ist es möglich? Es ist kein selbst signiertes Zertifikat < /p>
Grundsätzlich mache ich in meinem Curl so etwas wie folgt: < /p>
curl --key mykey.key --cert mycert.pem https://someurl.com/my-endpoint
< /code>
Ich habe diese Antwort überprüft. https://github.com/square/okhttp/blob/m ... Trust.java (but might not make sense since I dont get an object of the type I need)
Basically I have my okHttpClient
val okHttpClient = OkHttpClient.Builder()
.sslSocketFactory(?, ?) //here I tried to call sslSocketFactory, trustManager following the example from the CustomTrust.java
.build()
< /code>
Ideen für eine Lösung? />
https://square.github.io/okhttp/https/# ... es-Kt-java
Also habe ich versucht, dies zu tun (Basis auf den OKHTTP-Samples)
private fun trustedCertificatesInputStream(): InputStream {
val comodoRsaCertificationAuthority = (""
+ "-----BEGIN CERTIFICATE-----\n" +
"-----END CERTIFICATE-----")
return Buffer()
.writeUtf8(comodoRsaCertificationAuthority)
.inputStream()
}
val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
fun createClient() : OkHttpClient {
val trustManager: X509TrustManager
val sslSocketFactory: SSLSocketFactory
try {
trustManager = trustManagerForCertificates(trustedCertificatesInputStream())
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, arrayOf(trustManager), null)
sslSocketFactory = sslContext.socketFactory
} catch (e: GeneralSecurityException) {
throw RuntimeException(e)
}
return OkHttpClient.Builder()
.sslSocketFactory(sslSocketFactory, trustManager)
.connectTimeout(45, TimeUnit.SECONDS)
.readTimeout(45, TimeUnit.SECONDS)
.protocols(listOf(Protocol.HTTP_1_1))
.addInterceptor(loggingInterceptor)
.build()
}
@Throws(GeneralSecurityException::class)
private fun trustManagerForCertificates(input: InputStream): X509TrustManager {
val certificateFactory: CertificateFactory = CertificateFactory.getInstance("X.509")
val certificates: Collection = certificateFactory.generateCertificates(input)
val password = "password".toCharArray() // Any password will work.
val keyStore = newEmptyKeyStore(password)
for ((index, certificate) in certificates.withIndex()) {
val certificateAlias = index.toString()
keyStore.setCertificateEntry(certificateAlias, certificate)
}
// Use it to build an X509 trust manager.
val keyManagerFactory: KeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
keyManagerFactory.init(keyStore, password)
val trustManagerFactory: TrustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(keyStore)
val trustManagers: Array = trustManagerFactory.getTrustManagers()
return trustManagers[0]!! as X509TrustManager
}
@Throws(GeneralSecurityException::class)
private fun newEmptyKeyStore(password: CharArray): KeyStore {
return try {
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType())
val inputStream: InputStream? = null // By convention, 'null' creates an empty key store.
keyStore.load(inputStream, password)
keyStore
} catch (e: IOException) {
throw AssertionError(e)
}
}
< /code>
und ich erhalte einen Fehler von < /p>
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
< /code>
Die Suche nach dem Fehler scheint, dass ich die SSL lokal installieren sollte, was ich vermeiden sollte, da ich es auf dem Server nicht so installieren kann. Gibt es eine Möglichkeit, dass ich es funktionieren kann?
Wie füge ich SSL -Zertifikate zur OKHTTP -Mutuellen -TLS -Verbindung hinzu? ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Ich konnte keinen sicheren Kanal für SSL/TLS mit der Behörde 'xxxxx.com' festlegen
by Anonymous » » in C# - 0 Replies
- 12 Views
-
Last post by Anonymous
-
-
-
Wie konfigurieren Sie TLS- und Cipher -Suiten bei Verwendung von SSL -Bündeln?
by Anonymous » » in Java - 0 Replies
- 0 Views
-
Last post by Anonymous
-