【问题标题】:akka http SSLConfig issues with Hostname verification and cert validation主机名验证和证书验证的 akka http SSLConfig 问题
【发布时间】:2016-01-21 21:06:51
【问题描述】:

我在客户端的 Akka http 配置有一些问题。我正在尝试连接到不提供的服务器: - 公开签署的证书 - 与主机名对应的证书 我没有这个 nginx 的手,所以我无法更改服务器端配置。我只能更改客户端。

在对配置 SSL 进行大量调查后,我发现我需要在 application.conf 中在两个不同级别配置 SSL 选项:

akka.ssl-config.ssl.loose.acceptAnyCertificate=true
akka.ssl-config.loose.disableHostnameVerification = true

ssl-config.loose.acceptAnyCertificate=true
ssl-config.loose.disableHostnameVerification = true

我已经检查了配置是否正常

log-config-on-start = "on" 

问题是我在akka调试级别仍然得到错误(不是很清楚)

[ingestionApiClient-akka.actor.default-dispatcher-13] [akka://ingestionApiClient/user/StreamSupervisor-0/flow-216-1-unknown-operation] closing output

查看wireshark我发现这是证书验证的问题

TLSv1 Record Layer: Alert (Level: Fatal, Description: Certificate Unknown)

我想 JVM 配置覆盖了我所做的一切,所以我也尝试按照这个方法来修改 JVM SSL 配置: Java SSL: how to disable hostname verification

配置 SSLContext 并将其传递给 akka http 没有问题,因为我可以使用

设置默认 HttpsContext
val sc = SSLContext.getInstance("TLS")
*...configuration...*
val customContext =HttpsContext(sc, sslParameters = Some(params))
Http().setDefaultClientHttpsContext(customHttpsContext)

但无论如何我都找不到配置默认主机名验证程序。 Http 类没有像Http().setDefaultHostnameVerifier这样的方法

这就是我连接服务器的方式

val dataIngestFlow = Http().outgoingConnectionTls(config.httpEndpointHost,config.httpEndpointPort)

我怎样才能做到这一点?非常感谢您的帮助

【问题讨论】:

    标签: http ssl ssl-certificate akka hostname


    【解决方案1】:

    我不知道您使用的是哪个版本的akkaakka-http,但您是否尝试将配置字段akka.ssl-config.hostnameVerifierClass 设置为您的HostNameVerifier 接口的具体实现?

    接受所有内容的最简单的验证器如下所示:

    public static class AcceptAllHostNameVerifier implements HostnameVerifier {
      @Override
      public boolean verify(String s, SSLSession sslSession) {
        return true;
      }
    }
    

    【讨论】:

      【解决方案2】:

      我也陷入了类似的issue 并且变得类似errors。使用以下代码,我能够通过:

      val trustStoreConfig = TrustStoreConfig(None, Some("/etc/Project/keystore/my.cer")).withStoreType("PEM")
      val trustManagerConfig = TrustManagerConfig().withTrustStoreConfigs(List(trustStoreConfig))
      
      val badSslConfig = AkkaSSLConfig().mapSettings(s => s.withLoose(s.loose
        .withAcceptAnyCertificate(true)
        .withDisableHostnameVerification(true)
      ).withTrustManagerConfig(trustManagerConfig))
      
      val badCtx = Http().createClientHttpsContext(badSslConfig)
      
      Http().superPool[RequestTracker](badCtx)(httpMat)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-18
        • 1970-01-01
        • 2019-01-26
        • 1970-01-01
        • 2019-03-17
        相关资源
        最近更新 更多