使用 .ca-bundle、.crt 和 .key 文件设置 Akka 服务器的 https 支持



我有一个简单的Akka http服务器,但我必须设置https支持。 我有三个证书文件:.crt,.key和.ca-bundle 在 Akka 文档中,只有 PKCS12 示例。 我该如何处理我拥有的文件?

def initializeWebServer(interface: String,
port: Int) = {
val route : Route =
pathPrefix("secured") {
authenticateOAuth2(realm = "secure site", checkAuthentication){ token =>
concat(
get{
path("hello"){
complete("hello world")
}
}
)
}
}
val bindingFuture = Http().bindAndHandle(route, interface, port.toInt)
CoordinatedShutdown(system).addJvmShutdownHook({
bindingFuture
.flatMap(_.unbind())
})
}
def myUserPassAuthenticator(credentials: Credentials): Option[String] =
credentials match {
case p@Credentials.Provided(id) if p.verify("secret") => Some(id)
case _ => None
}
def checkAuthentication(credentials: Credentials): Option[String] = credentials match {
case p @ Credentials.Provided(token) if p.verify("secret") => Some(token)
case _ => None
}

感谢@Leo C的评论,

  • 将密钥和 crt 转换为 p12 :

    openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt

  • 使用SSL实现解决方案: https://doc.akka.io/docs/akka-http/current/server-side/server-https-support.html

最新更新