本文整理汇总了Scala中javax.net.ssl.KeyManagerFactory类的典型用法代码示例。如果您正苦于以下问题:Scala KeyManagerFactory类的具体用法?Scala KeyManagerFactory怎么用?Scala KeyManagerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KeyManagerFactory类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: WebserverApp
//设置package包名称以及导入依赖的类
import java.security.KeyStore
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
import com.twitter.finagle.Http
import com.twitter.util.Await
import io.circe.generic.auto._
import io.finch._
import io.finch.circe._
object WebserverApp extends App {
def getSSLContext: SSLContext = {
// Create and initialize the SSLContext with key material
val passphrase = "sample".toCharArray()
val trustPassphrase = "sample".toCharArray()
// First initialize the key and trust material
val ksKeys = KeyStore.getInstance("JKS")
val keystoreResource = this.getClass.getClassLoader.getResourceAsStream("sample-keystore.jks")
ksKeys.load(keystoreResource, passphrase)
val ksTrust = KeyStore.getInstance("JKS")
val trustStoreResource = this.getClass.getClassLoader.getResourceAsStream("sample-keystore.jks")
ksTrust.load(trustStoreResource, trustPassphrase)
// KeyManagers decide which key material to us
val kmf = KeyManagerFactory.getInstance("SunX509")
kmf.init(ksKeys, passphrase)
// TrustManagers decide whether to allow connections
val tmf = TrustManagerFactory.getInstance("SunX509")
tmf.init(ksTrust)
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(kmf.getKeyManagers, tmf.getTrustManagers, null)
sslContext
}
def sample: Endpoint[String] =
get("sample") {
Ok("Was it a TLS connection?... probably not")
}
val routes = sample
val server = Http.server
.withTransport.tls(getSSLContext)
.serve(s":38082", routes.handle {
case e: Exception =>
InternalServerError(e)
}.toService)
println("Server running on :38082")
Await.result(server)
}
开发者ID:nicojs,项目名称:poc-finch-tls,代码行数:54,代码来源:WebserverApp.scala
示例2: sslContext
//设置package包名称以及导入依赖的类
package org.packtpublishing.security
import java.security.{SecureRandom, KeyStore}
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
import spray.io.ServerSSLEngineProvider
import resource._
trait SslSupport {
val random = SecureRandom.getInstance("SHA1PRNG")
val keyStoreLocation = "/spray-book-catalog.jks"
val keyStorePassword = "passw0rd"
implicit def sslContext: SSLContext = {
val keyStore = KeyStore.getInstance("jks")
for (jks <- managed(getClass.getResourceAsStream(keyStoreLocation))) {
keyStore.load(jks, keyStorePassword.toCharArray)
}
val keyManagerFactory = KeyManagerFactory.getInstance("SunX509")
keyManagerFactory.init(keyStore, keyStorePassword.toCharArray)
val trustManagerFactory = TrustManagerFactory.getInstance("SunX509")
trustManagerFactory.init(keyStore)
val context = SSLContext.getInstance("TLS")
context.init(keyManagerFactory.getKeyManagers, trustManagerFactory.getTrustManagers, random)
context
}
implicit def sslEngineProvider: ServerSSLEngineProvider = {
ServerSSLEngineProvider { engine =>
engine.setEnabledProtocols(Array("TLSv1", "TLSv1.1", "TLSv1.2"))
engine
}
}
}
开发者ID:allansene,项目名称:spray-scala-akka-book-catalog,代码行数:39,代码来源:SslSupport.scala
示例3: BlazeServerConfig
//设置package包名称以及导入依赖的类
package korolev.blazeServer
import java.net.InetAddress
import java.security.KeyStore
import javax.net.ssl.{KeyManagerFactory, SSLContext}
import org.http4s.blaze.util.BogusKeystore
import scala.concurrent.ExecutionContextExecutorService
case class BlazeServerConfig(
port: Int = 8080,
host: String = InetAddress.getLoopbackAddress.getHostAddress,
sslContext: Option[SSLContext] = None,
bufferSize: Int = 8 * 1024,
maxRequestBodySize: Int = 8 * 1024 * 1024,
maxRequestHeaderSize: Int = 10 * 1024,
doNotBlockCurrentThread: Boolean = false
)(
// Trampoline
implicit val executionContext: ExecutionContextExecutorService
)
object BlazeServerConfig {
def bogusSslContext: SSLContext = {
val ksStream = BogusKeystore.asInputStream()
assert(ksStream != null)
val ks = KeyStore.getInstance("JKS")
ks.load(ksStream, BogusKeystore.getKeyStorePassword)
val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
kmf.init(ks, BogusKeystore.getCertificatePassword)
val context = SSLContext.getInstance("SSL")
context.init(kmf.getKeyManagers, null, null)
context
}
}
开发者ID:fomkin,项目名称:korolev,代码行数:39,代码来源:BlazeServerConfig.scala
示例4: sslFile
//设置package包名称以及导入依赖的类
package console
import java.security._
import java.io.{InputStream, FileInputStream, File}
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
import akka.http.scaladsl.{ConnectionContext, HttpsConnectionContext}
trait SslSupport {
val algorithm = "SunX509"
def sslFile: String
private def create(in: InputStream, keyPass: String, storePass: String) = {
val keyStore = KeyStore.getInstance("JKS")
keyStore.load(in, storePass.toCharArray)
val keyManagerFactory = KeyManagerFactory.getInstance(algorithm)
keyManagerFactory.init(keyStore, keyPass.toCharArray)
val tmf = TrustManagerFactory.getInstance(algorithm)
(tmf init keyStore)
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagerFactory.getKeyManagers, tmf.getTrustManagers, new SecureRandom)
(ConnectionContext https sslContext)
}
def https(keyPass: String, storePass: String): HttpsConnectionContext = {
val file = new File("./" + sslFile)
if(file.exists) create(new FileInputStream(file), keyPass, storePass)
else {
resource.managed(getClass.getResourceAsStream("/"+ sslFile))
.map { in => create(in, keyPass, storePass) }
.opt
.fold(throw new Exception("jks file hasn't been found"))(identity)
}
}
}
开发者ID:haghard,项目名称:akka-cluster-console,代码行数:40,代码来源:SslSupport.scala
示例5: SSLConfiguration
//设置package包名称以及导入依赖的类
package com.biosimilarity.evaluator.spray
import java.io.InputStream
import java.security.{KeyStore, SecureRandom}
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
import com.biosimilarity.evaluator.distribution.EvalConfigWrapper
import com.biosimilarity.evaluator.util._
import spray.io.{SSLContextProvider, ServerSSLEngineProvider}
object SSLConfiguration extends Serializable {
private def sslContext: SSLContext = {
val keystoreResource: InputStream = resourceStream("keystore.jks")
try {
val storepass: String = EvalConfigWrapper.readString("storepass")
val keypass: String = EvalConfigWrapper.readString("keypass")
val keyStore: KeyStore = KeyStore.getInstance("jks")
val keyManagerFactory: KeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
val trustManagerFactory: TrustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
val context: SSLContext = SSLContext.getInstance("TLS")
keyStore.load(keystoreResource, storepass.toCharArray)
keyManagerFactory.init(keyStore, keypass.toCharArray)
trustManagerFactory.init(keyStore)
context.init(keyManagerFactory.getKeyManagers, trustManagerFactory.getTrustManagers, new SecureRandom)
context
} finally {
keystoreResource.close()
}
}
def sslEngineProvider: ServerSSLEngineProvider = ServerSSLEngineProvider(identity)(SSLContextProvider.forContext(sslContext))
}
开发者ID:synereo,项目名称:synereo,代码行数:34,代码来源:SSLConfiguration.scala
示例6: SSLUtil
//设置package包名称以及导入依赖的类
package org.hyperscala.util
import java.io.File
import java.nio.file.Files
import java.security.KeyStore
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
object SSLUtil {
def createSSLContext(keyStoreFile: File, password: String): SSLContext = {
val passwordChars = password.toCharArray
val keyStore = KeyStore.getInstance("JKS")
assert(keyStoreFile.exists(), s"No keystore file was found at the location: ${keyStoreFile.getAbsolutePath}")
val keyStoreInput = Files.newInputStream(keyStoreFile.toPath)
keyStore.load(keyStoreInput, passwordChars)
val keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm)
keyManagerFactory.init(keyStore, passwordChars)
val keyManagers = keyManagerFactory.getKeyManagers
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
trustManagerFactory.init(keyStore)
val trustManagers = trustManagerFactory.getTrustManagers
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagers, trustManagers, null)
sslContext
}
}
开发者ID:outr,项目名称:hyperscala,代码行数:30,代码来源:SSLUtil.scala
示例7: create
//设置package包名称以及导入依赖的类
package linguistic
import java.security._
import java.io.{InputStream, FileInputStream, File}
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
import akka.http.scaladsl.{ConnectionContext, HttpsConnectionContext}
trait SslSupport {
val algorithm = "SunX509"
private def create(in: InputStream, keyPass: String, storePass: String) = {
val keyStore = KeyStore.getInstance("JKS")
keyStore.load(in, storePass.toCharArray)
val keyManagerFactory = KeyManagerFactory.getInstance(algorithm)
keyManagerFactory.init(keyStore, keyPass.toCharArray)
val tmf = TrustManagerFactory.getInstance(algorithm)
(tmf init keyStore)
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagerFactory.getKeyManagers, tmf.getTrustManagers, new SecureRandom)
(ConnectionContext https sslContext)
}
def https(keyPass: String, storePass: String): HttpsConnectionContext = {
val file = new File("./linguistic.jks")
if(file.exists) {
create(new FileInputStream(file), keyPass, storePass)
} else {
resource.managed(getClass.getResourceAsStream("/linguistic.jks")).map { in =>
create(in, keyPass, storePass)
}.opt.fold(throw new Exception("jks hasn't been found"))(identity)
}
}
}
开发者ID:haghard,项目名称:linguistic,代码行数:40,代码来源:SslSupport.scala
注:本文中的javax.net.ssl.KeyManagerFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论