Netty websocket配置wss

录音配置https 导致ws连不上

java 复制代码
@Slf4j
@Component
public class NettyServer {

    /**
     * 启动
     *
     * @throws InterruptedException
     */
    private void start() throws InterruptedException {
        bossGroup = new NioEventLoopGroup();
        workGroup = new NioEventLoopGroup();
        ServerBootstrap bootstrap = new ServerBootstrap();
        // bossGroup辅助客户端的tcp连接请求, workGroup负责与客户端之前的读写操作
        bootstrap.group(bossGroup, workGroup);
        // 设置NIO类型的channel
        bootstrap.channel(NioServerSocketChannel.class);
        // 设置监听端口
        bootstrap.localAddress(new InetSocketAddress(port));
        // 连接到达时会创建一个通道
        bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
               // 添加SSL处理器
                FileInputStream crt = new FileInputStream("/etc/app/ssl/test.xx-zn.com_bundle.crt");
                FileInputStream key = new FileInputStream("/etc/app/ssl/test.xx-zn.com.key");
                SslContext sslContext = SslContextBuilder.forServer(crt, key)
                        .sslProvider(SslProvider.JDK)
                        .build();
                ch.pipeline().addLast(sslContext.newHandler(ch.alloc()));
               
    }

https 和wss用的是同一个域名证书(企鹅),Java 配置WSS ssl处理器,启动程序发现报错

无法找ssl文件的key,发现格式不匹配。下载openssl转 ssl文件中.key 到pkcs8格式

openssl工具下载地址:

Win32/Win64 OpenSSL Installer for Windows - Shining Light Productionsp

配置openssl环境变量,win path 后面加安装目录 D:\zhang\OpenSSL-Win64\bin

打开cmd 执行openssl pkcs8 -topk8 -nocrypt -in 你的.key文件 -out pkcs8.key

备注:ssl证书给的.key文件就是pkcs1格式文件

相关推荐
c&0xff004 分钟前
Flink反压问题
网络·flink
7ACE9 分钟前
Wireshark TS | 接收数据超出接收窗口
网络协议·tcp/ip·wireshark
深圳多奥智能一卡(码、脸)通系统19 分钟前
基于多奥(DAIC)品牌的IC卡电梯门禁系统(梯控)基础配置清单,整合核心硬件、软件及安全组件,确保系统可独立运行并支持未来扩展
网络
googleccsdn38 分钟前
ESNP LAB 笔记:配置MPLS(Part4)
网络·笔记·网络协议
tan180°39 分钟前
Boost搜索引擎 网络库与前端(4)
linux·网络·c++·搜索引擎
Dontla1 小时前
Docker多共享网络配置策略(Docker多网络、Docker networks、Docker Compose网络、Docker网络、Docker共享网络)
网络·docker·容器
LUCIAZZZ2 小时前
HTTPS优化简单总结
网络·网络协议·计算机网络·http·https·操作系统
wanhengidc2 小时前
云手机运行流畅,秒开不卡顿
运维·网络·科技·游戏·智能手机
名誉寒冰3 小时前
TCP 拥塞控制与四次挥手解析
网络·网络协议·tcp/ip
笨小孩@GF 知行合一3 小时前
OSPF实验:外部路由引入
运维·网络·hcip·数通·ospf