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格式文件

相关推荐
网硕互联的小客服1 分钟前
CentOS系统如何卸载桌面并以shell 字符界面启动?
运维·服务器·网络·安全
电子科技圈2 小时前
Durin:Aliro标准赋能,打造无缝移动入户体验
人工智能·mcu·物联网·网络协议·智能家居·智能硬件·iot
攻城狮在此2 小时前
华三中小型企业二层组网配置案例一(单ISP+单链路)
网络·华为
REDcker2 小时前
Nagle 算法与 TCP_NODELAY、TCP_CORK 详解
网络·tcp/ip·算法
熬夜的咕噜猫3 小时前
MySQL主从复制与读写分离
网络·数据库·mysql
Chris _data4 小时前
S7-1500 常用工业通信协议详解与对比
运维·服务器·网络
zmj3203245 小时前
ISO/SAE 21434:2021(道路车辆 - 网络安全工程) 汇总
网络·安全·web安全·21434
IP老炮不瞎唠5 小时前
Scrapy 高效采集:优化方案与指南
网络·爬虫·python·scrapy·安全
zmj3203245 小时前
UNR -155 Annex 5提示的威胁及其编号
网络·安全·网络安全
前端摸鱼匠6 小时前
【AI大模型春招面试题14】前馈网络(FFN)在Transformer中的作用?为何其维度通常大于注意力维度?
网络·人工智能·ai·面试·大模型·transformer