使用netty的WebSocket的net :: ERR_CERT_COMMON_NAME_INVALID

时间:2018-09-17 18:30:25

标签: netty wss

我有一台具有认证的WSS服务器。 HTTPS Web客户端正尝试连接我的WSS服务器,以便通过此套接字接收数据。客户端获取ERR_CERT_COMMON_NAME_INVALID,netty的处理程序中也不例外。 服务器非常类似于nettty WSS示例,但有一点点变化-我没有使用SelfSignedCertificate,因为我需要使用自己的认证。 这是服务器引导程序的代码:

    private ServerBootstrap b;
private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup;
final SslContext sslCtx;

public NettyWebSocketServer(ServerProperties srvProp, ConcurrentExecutor executor) {
    super(srvProp, executor);
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup(1);

// setExecutorService(workerGroup);

    try {
        if (srvProp.isSsl()) {
            File privateKeyFile = new File("/home/ec2-user/webup/myKey.key");

            File certificateFile = new File("/home/ec2-user/webup/myCert.crt");
            if (privateKeyFile.exists()) {
                System.out.println("private Key File created: " + FileUtil.getFileContent(privateKeyFile));
            }
            if (certificateFile.exists()) {
                System.out.println("certificate File created: " + FileUtil.getFileContent(certificateFile));
            }
            sslCtx = SslContextBuilder.forServer(certificateFile, privateKeyFile).build();
            if (sslCtx != null) {
                System.out.println("SSL context created! isServer=" + sslCtx.isServer());
            }
        } else {
            sslCtx = null;
        }
        b = new ServerBootstrap();

        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(srvProp.isSsl() ?
                        new WssServerInitializer(this, sslCtx) : new WebSocketServerInitializer(this))
                .option(ChannelOption.TCP_NODELAY, true);
    } catch (SSLException e) {
        throw new RuntimeException(e);
    }
}

@Override
public void start() throws InterruptedException {

    try {
        Channel ch = b.bind(/*srvProp.getAddress(),*/ srvProp.getPort()).sync().channel();
        localAddress = ((InetSocketAddress) ch.localAddress()).getAddress().getHostAddress();
        Log.write("Open your web browser and navigate to " +
                (getServerProperties().isSsl() ? "https" : "http") + "://" + srvProp.getAddress() + ":" + srvProp.getPort() + '/');
        System.out.println("\nNettyWebSocketServer started on " + srvProp.getServerShortInfo() + '\n');
        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }

}

0 个答案:

没有答案