我有一个简单的Akka http服务器,但是我必须设置https支持。 我有三个证书文件:.crt,.key和.ca-bundle 在Akka doc中,只有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
}
答案 0 :(得分:1)
感谢@Leo C的评论,
将密钥和crt转换为p12:
openssl pkcs12-导出-out server.p12 -inkey server.key -in server.crt
使用SSL解决方案的实现: https://doc.akka.io/docs/akka-http/current/server-side/server-https-support.html