gpt4 book ai didi

java - 使用 SSL/TLS 和 keystore 配置 Jetty

转载 作者:搜寻专家 更新时间:2023-10-31 20:17:33 24 4
gpt4 key购买 nike

我已经创建了 key 和证书,由根 CA 使用 OpenSSL 签名。我正在尝试使用 server.key 文件作为 keystore 并在代码中执行它:

private fun setupHttps(server : Server, port: Int) {
val https = HttpConfiguration()
https.addCustomizer(SecureRequestCustomizer())

val sslFactory = SslContextFactory()
sslFactory.keyStorePath = Paths.get(System.getProperty("user.dir"), "..", "server.key").toString()
sslFactory.setKeyStorePassword("password")

val sslConnector = ServerConnector(
server,
SslConnectionFactory(sslFactory, "http/1.1"),
HttpConnectionFactory(https)
)

sslConnector.port = port
server.connectors = arrayOf(sslConnector)

但我有这个异常(exception):

Exception in thread "main" java.lang.IllegalStateException: no valid keystore
at org.eclipse.jetty.util.security.CertificateUtils.getKeyStore(CertificateUtils.java:48)
at org.eclipse.jetty.util.ssl.SslContextFactory.loadKeyStore(SslContextFactory.java:998)
at org.eclipse.jetty.util.ssl.SslContextFactory.load(SslContextFactory.java:252)
at org.eclipse.jetty.util.ssl.SslContextFactory.doStart(SslContextFactory.java:219)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.SslConnectionFactory.doStart(SslConnectionFactory.java:72)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:270)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:81)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:431)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at ru.servicesmarket.server.LaunchKt.main(launch.kt:44)

最佳答案

我认为这是您的 keystore 路径/位置的问题。当找不到 keystore 时会抛出此异常,这有点令人困惑。

关于java - 使用 SSL/TLS 和 keystore 配置 Jetty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42453189/

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