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

时间:2019-12-30 15:39:03

标签: scala ssl akka-http

我有一个简单的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
  }

1 个答案:

答案 0 :(得分:1)

感谢@Leo C的评论,