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

相关推荐
张小姐的猫几秒前
【Linux】网络编程 —— 多路转接:epoll
linux·运维·网络
曹小强wxx8 分钟前
Flutter 局域网设备发现:UDP 广播 + mDNS 双路合并,以及靠谱的在线判定与断线重连
物联网·网络协议·flutter
睡一觉就好了。10 分钟前
linux网络编程基础
网络
花间相见16 分钟前
【计算基础|网络09】TCP(上):三次握手与四次挥手
网络·网络协议·tcp/ip
wdfk_prog1 小时前
LWIP教程 08:从 `tcp_write()` 到 ACK 清队列——TCP 数据发送、窗口与回调
网络·网络协议·tcp/ip
anew___1 小时前
《从零手写操作系统 (37):网络协议栈基础——Socket接口与TCP状态机》
网络·网络协议·tcp/ip
wdfk_prog1 小时前
LWIP教程 10:从 `tcp_receive()` 到 `ooseq` / SACK——TCP 乱序、重组与选择确认
网络·数据库·tcp/ip
砚凝霜2 小时前
【软考信息安全】第十七章 网络安全应急响应概述与事件处理流程
网络·安全·web安全
在角落发呆2 小时前
一键脚本配置备份方法:从 Shell 脚本到自动备份
网络·windows
星 海2 小时前
自定义报文解析器
网络