Skip to content

Commit

Permalink
#64 Make SSL truststore configuration optional
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Aug 22, 2018
1 parent 469704c commit 44a9c9f
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions app/org/elastic4play/ClientAuthSSLEngineProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ class ClientAuthSSLEngineProvider(serverConfig: ServerConfig, appProvider: Appli
}

def readTrustManagers(): Array[TrustManager] = {
val trustStorePath = Paths.get(config.get[String]("play.server.https.trustStore.path"))
val keyStoreType = config.getOptional[String]("play.server.https.keyStore.type").getOrElse(KeyStore.getDefaultType)
val trustStorePassword = config.getOptional[String]("play.server.https.trustStore.password").getOrElse("").toCharArray
val trustInputStream = Files.newInputStream(trustStorePath)
try {
val keyStore = KeyStore.getInstance(keyStoreType)
keyStore.load(trustInputStream, trustStorePassword)
val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
tmf.init(keyStore)
tmf.getTrustManagers
}
finally {
trustInputStream.close()
}
config.getOptional[String]("play.server.https.trustStore.path")
.map { trustStorePath
val keyStoreType = config.getOptional[String]("play.server.https.keyStore.type").getOrElse(KeyStore.getDefaultType)
val trustStorePassword = config.getOptional[String]("play.server.https.trustStore.password").getOrElse("").toCharArray
val trustInputStream = Files.newInputStream(Paths.get(trustStorePath))
try {
val keyStore = KeyStore.getInstance(keyStoreType)
keyStore.load(trustInputStream, trustStorePassword)
val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
tmf.init(keyStore)
tmf.getTrustManagers
}
finally {
trustInputStream.close()
}
}
.getOrElse(Array.empty)
}

def createSSLContext(applicationProvider: ApplicationProvider): SSLContext = {
Expand Down

0 comments on commit 44a9c9f

Please sign in to comment.