gpt4 book ai didi

scala - Spray HTTPS Inbound 在接收到 peer 的 close_notify 之前关闭

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:09 25 4
gpt4 key购买 nike

目前,我正在使用 Spray i/o 通过 Scala 实现 Web 服务。希望使用 SSL 来保护我的请求。但是我在配置 SSL 时遇到了困难。当启动 https 调用时,会抛出与握手相关的错误

 fatal error: 80: Inbound closed before receiving peer's close_notify: possible truncation attack?
javax.net.ssl.SSLException: Inbound closed before receiving peer's close_notify: possible truncation attack?

使用这个创建了一个证书

keytool -genkey -keyalg RSA -alias mykey  -dname "CN=dev.site.com,OU=app" -keystore keystore.jks -storepass pas -validity 365

像这样创建了一个 ssl trait

trait SSLConfiguration {

implicit def sslContext: SSLContext = {
val keystore = keystore.jks
val password = pas

val keyStore = KeyStore.getInstance("jks")
val in = getClass.getClassLoader.getResourceAsStream(keystore)
require(in != null, "Bad java key storage file: " + keystore)
keyStore.load(in, password.toCharArray)

val keyManagerFactory = KeyManagerFactory.getInstance("SunX509")
keyManagerFactory.init(keyStore, password.toCharArray)
val trustManagerFactory = TrustManagerFactory.getInstance("SunX509")
trustManagerFactory.init(keyStore)
val context = SSLContext.getInstance("TLS")
context.init(keyManagerFactory.getKeyManagers, trustManagerFactory.getTrustManagers, new SecureRandom)
context
}

implicit def sslEngineProvider: ServerSSLEngineProvider = {
ServerSSLEngineProvider { engine =>
engine.setEnabledCipherSuites(Array("TLS_RSA_WITH_AES_256_CBC_SHA"))
engine.setEnabledProtocols(Array("SSLv3", "TLSv1"))
engine
}
}
}

设置我的 Boot 以使用该特征。

   object Boot extends App with SSLConfiguration 
//bind to io interface. set ssl engine providor
IO(Http) ! Http.Bind(service, interface = interface, port)(sslEngineProvider)
}

最佳答案

您是否在配置文件中启用了 SSL?

spray.can {
server {
ssl-encryption = on
}
}

我试过你的代码并稍作修改,它在我的笔记本电脑上运行。我全删了 隐式 def sslEngineProvider并使用默认的 IO(HTTP)! Http.Bind(服务,接口(interface)=“0.0.0.0”,端口= 8080)。你把你的 keystore 文件放在项目的资源文件夹(project/src/main/resources)?

关于scala - Spray HTTPS Inbound 在接收到 peer 的 close_notify 之前关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30058511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com