我知道这是一个常见问题,但是找不到Akka http客户端的快速解决方案。我使用Akka http客户端向一些内部https端点发出请求,并且我想禁用SSL,如下所示:
val badSslConfig = AkkaSSLConfig().mapSettings(s => s.withLoose(s.loose.withDisableHostnameVerification(true).withAcceptAnyCertificate(true).withDisableSNI(true)))
val badCtx: HttpsConnectionContext = Http().createClientHttpsContext(badSslConfig)
// or http.setDefaultClientHttpsContext(badCtx)
http.singleRequest(HttpRequest(...), badCtx) .map { ... }
但是它总是抛出异常:
Future(Failure(javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target))
任何人都可以帮忙吗?
我找到了一个有效的示例here。
val sslContext = {
val permissiveTrustManager: TrustManager = new X509TrustManager() {
override def checkClientTrusted(chain: Array[X509Certificate], authType: String): Unit = {}
override def checkServerTrusted(chain: Array[X509Certificate], authType: String): Unit = {}
override def getAcceptedIssuers(): Array[X509Certificate] = Array.empty
}
val ctx = SSLContext.getInstance("TLS")
ctx.init(Array.empty, Array(permissiveTrustManager), new SecureRandom())
ctx
}