Scala 禁用akka http客户端中的SSL安全
我必须对似乎没有经过验证的SSL证书的api进行https调用。我仍然希望使用akka Http的Scala 禁用akka http客户端中的SSL安全,scala,ssl,akka-http,Scala,Ssl,Akka Http,我必须对似乎没有经过验证的SSL证书的api进行https调用。我仍然希望使用akka Http的Http().singleRequest方法调用api 但是,当我打电话时,会出现以下错误: javax.net.ssl.SSLHandshakeException: General SSLEngine problem 当我用curl打电话时,我 curl failed to verify the legitimacy of the server and therefore could not e
Http().singleRequest
方法调用api
但是,当我打电话时,会出现以下错误:
javax.net.ssl.SSLHandshakeException: General SSLEngine problem
当我用curl打电话时,我
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it.
但是,如果我有标志——unsecure
,则使用curl的调用可以工作
在akka http中,我尝试了以下方法:
val badSslConfig = AkkaSSLConfig().mapSettings(
s => s.withLoose(
s.loose
.withAcceptAnyCertificate(true)
.withAllowLegacyHelloMessages(Some(true))
.withAllowUnsafeRenegotiation(Some(true))
.withAllowWeakCiphers(true)
.withAllowWeakProtocols(true)
.withDisableHostnameVerification(true)
.withDisableSNI(true)
)
)
val badCtx = Http().createClientHttpsContext(badSslConfig)
Http()
.singleRequest(
HttpRequest(
HttpMethods.POST,
uri = Uri("https://..."),
protocol = HttpProtocols.`HTTP/1.1`
),
connectionContext = badCtx
)
但我还是犯了同样的错误
我应该如何解决该问题
PS:我理解(考虑到akka http文档中的许多警告),这是我在生产中不应该做的事情,但我希望这个解决方法现在能起作用……我不久前也遇到过类似的问题,就我记忆所及,它与此有关。解决这个问题的方法是拥有自己的SSLContext实现,它可以接受任何东西。实现非常简单,示例可以在上面链接的问题的最后一条注释中找到。
使用DisablesNI
不是一个好主意。这与证书验证完全无关,但禁止在TLS握手中发送主机名。未能发送主机名将导致需要SNI的站点出现错误-现在有很多站点(像Cloudflare和其他CDN后面的所有站点)。啊,对了。我认为让更多的东西失去功能并不会带来伤害,但我理解这种担心。我删除了这句话,但它仍然保留了相同的问题…事实上,它就像一个魅力!以下是指向代码段的直接链接,以供参考: