java - 测试 SSL Vertx 服务器和客户端运行状况检查时出错
问题描述
我正在尝试使用 HttpServerOptions 测试已启用 SSL 的 Verticle。这是一个自签名证书。
HttpServerOptions options = new HttpServerOptions();
options.setSsl(true)
.setPemKeyCertOptions(
new PemKeyCertOptions()
.setKeyPath(certKeyPath)
.setCertPath(certPemPath)
);
...
在我的单元测试中,我使用了这段代码,它对 HTTP 连接工作正常
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/")
.ssl(true)
.as(BodyCodec.string())
.send(testContext.succeeding(response -> testContext.verify(() -> {
Assertions.assertEquals(200, response.statusCode());
testContext.completeNow();
})));
因为,我启用了 SSL,所以我尝试使用下面的代码和我自己的自签名证书的路径进行测试。
WebClientOptions options = new WebClientOptions()
.setSsl(true)
.setPemKeyCertOptions(new PemKeyCertOptions()
.setKeyPath("key.pem")
.setCertPath("cert.pem"));
WebClient client = WebClient.create(vertx, options);
但是,我收到了这个错误
javax.net.ssl.SSLHandshakeException: Failed to create SSL connection
at io.vertx.core.net.impl.ChannelProvider$1.userEventTriggered(ChannelProvider.java:129)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:346)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:332)
at io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:324)
at io.netty.handler.ssl.SslHandler.handleUnwrapThrowable(SslHandler.java:1308)
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1289)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1330)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:836)
Caused by: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
我在这里阅读有关此错误的一些线程,似乎我需要将我的证书添加到 JVM,只是想知道,我必须这样做吗?如果是,那么如果我的代码被某人拉取,这将如何工作?他们是否也需要将其添加到他们的 JVM 中?还有其他解决方案吗?
解决方案
推荐阅读
- python - Python 和 Scrapy 缺少一些链接
- scala - 无法以复杂的 json 字符串作为列读入 spark 数据帧
- mysql - INSERT ON DUPLICATE 从另一个表
- javascript - 如何根据另一个下拉菜单选择的条件删除和添加下拉列表值?
- python - 从嵌套列表中删除列表
- python - 如何使用 CSS className 去除 python 中破折号传单周围的气泡
- python - 解决 Anaconda Navigator 的包加载问题
- java - 我收到此错误 com.ctc.wstx.stax.WstxInputFactory cannot be cast to javax.xml.stream.XMLInputFactory
- javascript - 如何使用 Django 模板语言处理 JS 脚本?
- android - [amadeus] 调用 hotelOffers.get api 时出现异常