在我的一个项目中,我们将从akka (10.2.9)移到http4s (v0.23.12)。在akka中,我们使用akka.http.scaladsl.Http对象创建http server,该对象在内部为使用AkkaSSLConfig的服务器创建HttpConnectionContext,默认情况下,AkkaSSLConfig在server端也启用了hostNameVerifier,后者根据CN和SAN检查主机名。可以使用此参数禁用此hostNameVerification。
akka.ssl-config.loose.disableHostnameVerification = true当我深入研究这个问题时,我知道hostNameVerification应该在Client端启用,而不是为了避免man in the middle attack。
但是,在从akka迁移到http4s时,我仍然希望保留hostNameVerification的功能。我阅读了http4s 文档,并且我正在使用BlazeServerBuilder,但是我没有找到在server端启用hostNameVerification的任何规定。如何用http4s和scala来实现这一点。
发布于 2022-11-23 14:39:52
为此您可以使用withSslContext。
val sslContext = ???
val sslParams = TLSParameters(endpointIdentificationAlgorithm = Some("https")).toSSLParameters
blazeBuilder.withSslContextAndParameters(sslContext, sslParameters)你可以在这里找到TLSParameters的所有参数,https://github.com/typelevel/fs2/blob/main/io/jvm/src/main/scala/fs2/io/net/tls/TLSParameters.scala
https://stackoverflow.com/questions/74547770
复制相似问题