akka http SSLConfig与主机名验证和证书验证有关

时间:2016-01-21 21:06:52

标签: http ssl ssl-certificate akka hostname

我在客户端遇到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)

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

2 个答案:

答案 0 :(得分:0)

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

接受一切的最简单的验证者如下所示:

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

答案 1 :(得分:0)

我也陷入了类似的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)