Akka HTTP客户端抛出SSLHandshakeException,并且无法找到到所请求目标的有效证书路径

问题描述 投票:1回答:1

我知道这是一个常见问题,但是找不到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))

任何人都可以帮忙吗?

scala akka akka-http
1个回答
0
投票

我找到了一个有效的示例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
    }
© www.soinside.com 2019 - 2024. All rights reserved.