首页 > 解决方案 > 测试 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 中?还有其他解决方案吗?

标签: javassltestingvert.xvertx-verticle

解决方案


推荐阅读