netty wss证书验证失败

简介: netty wss证书验证失败

出现这个


Caused by: javax.net.ssl.SSLHandshakeException: no cipher suites in common
可能是证书路径,或者证书有问题
我再重构系统的时候碰到了这个问题ws的时候没问题,wss的时候证书验证不通过。
但是老版本的可以正常跑,搞了一两天发现是加载证书的时候路径有问题
%% Initialized:  [Session-1, SSL_NULL_WITH_NULL_NULL]
nioEventLoopGroup-9-1, fatal error: 40: no cipher suites in common
javax.net.ssl.SSLHandshakeException: no cipher suites in common
%% Invalidated:  [Session-1, SSL_NULL_WITH_NULL_NULL]
nioEventLoopGroup-9-1, SEND TLSv1.2 ALERT:  fatal, description = handshake_failure
nioEventLoopGroup-9-1, WRITE: TLSv1.2 Alert, length = 2
nioEventLoopGroup-9-1, fatal: engine already closed.  Rethrowing javax.net.ssl.SSLHandshakeException: no cipher suites in common
[Raw write]: length = 7
SSL_NULL_WITH_NULL_NULL 这个主要是匹配加密算法的
复制代码


运行参数可以打印网络连接的过程和数据


-Djavax.net.debug=all
复制代码


ssl的流程还是复杂的,可以简单的看下里面的主要信息

服务端日志


如果打印的日志如果没有下面这个,可能是证书加载的路径有问题
*** ServerHello, TLSv1.2
复制代码


客户端的协议


*** ClientHello, TLSv1.2
复制代码


网络异常,图片无法展示
|


证书生成工具 mkcert


mkcert -p12-file keystore.p12 -pkcs12 -client 192.168.0.103 127.0.0.1 localhost
复制代码


或者 keytool


注意指定这里的RSA算法
keytool -genkey -keysize 2048 -validity 365 -keyalg RSA -keypass changeit -storepass changeit -keystore wss.jks
复制代码


查看web请求的协议


网络异常,图片无法展示
|


wss的证书加载


SSLContext sslContext = SslUtil.createSSLContext("PKCS12",
        ResourceUtils.getFile("classpath:keystore.p12").getPath(), "changeit"); // SSLEngine engine =
    sslContext.createSSLEngine();
    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setNeedClientAuth(false);
    sslEngine.setUseClientMode(false);
    logger.info(sslContext.getProtocol());
    logger.info("支持的协议: " + Arrays.asList(sslEngine.getSupportedProtocols()));
    logger.info("启用的协议: " + Arrays.asList(sslEngine.getEnabledProtocols()));
    logger.info("支持的加密套件: " + Arrays.asList(sslEngine.getSupportedCipherSuites()));
    logger.info("启用的加密套件: " + Arrays.asList(sslEngine.getEnabledCipherSuites()));
    pipeline.addFirst(new SslHandler(sslEngine));
复制代码


public class SslUtil {
    private static volatile SSLContext sslContext = null;
    public static SSLContext createSSLContext(String type ,String path ,String password) throws Exception {
        if(null == sslContext){
            synchronized (SslUtil.class) {
                if(null == sslContext){
                    // 支持JKS、PKCS12
                    KeyStore ks = KeyStore.getInstance(type);
                    // 证书存放地址
                    InputStream ksInputStream = new FileInputStream(path);
                    //InputStream ksInputStream = SslUtil.class.getClass().getClassLoader().getResourceAsStream("keystore.p12");
                    ks.load(ksInputStream, password.toCharArray());
                    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    kmf.init(ks, password.toCharArray());
                    sslContext = SSLContext.getInstance("TLSv1.2");
                    sslContext.init(kmf.getKeyManagers(), null, null);
                }
            }
        }
        return sslContext;
    }
}


相关文章
|
3月前
|
算法 数据安全/隐私保护
客户端验证 证书解析
客户端验证 证书解析
51 7
|
3月前
|
数据安全/隐私保护 C++
c++实现http客户端和服务端的开源库以及Base64加密密码
c++实现http客户端和服务端的开源库以及Base64加密密码
|
移动开发 安全 网络协议
手把手教你为基于Netty的IM生成自签名SSL/TLS证书
本文要分享的是如何使用OpenSSL生成在基于Netty的IM中真正可用的SSL/TLS证书,内容包括:证书的创建、创建过程中的注意点,以及在Server端、Android端、iOS端、Java桌面端、H5端使用证书的代码范例。
402 0
手把手教你为基于Netty的IM生成自签名SSL/TLS证书
|
网络协议 安全 前端开发
netty系列之: 在netty中使用 tls 协议请求 DNS 服务器
在前面的文章中我们讲过了如何在netty中构造客户端分别使用tcp和udp协议向DNS服务器请求消息。在请求的过程中并没有进行消息的加密,所以这种请求是不安全的。 那么有同学会问了,就是请求解析一个域名的IP地址而已,还需要安全通讯吗?
RestTemplate调用https接口跳过证书验证
RestTemplate调用https接口跳过证书验证
585 0
|
Web App开发 网络安全 数据安全/隐私保护
如何让服务端同时支持WebSocket和SSL加密的WebSocket(即同时支持ws和wss)?
要服务端同时支持ws与wss并不容易,其难点主要在于:wss通道必须在TCP连接刚建立时(收发消息前)就要先进行SSL加密,否则,后续的通信将无法正常进行。如此一来,当TCP连接刚建立时,服务器就无法具体分辨哪个是ws客户端哪个是wss客户端。那怎么办了?
5554 0
netty系列之:自建客户端和HTTP服务器交互
netty系列之:自建客户端和HTTP服务器交互
|
Java 网络安全
netty系列之:让TLS支持http2
netty系列之:让TLS支持http2
|
存储 移动开发 缓存
netty系列之:搭建HTTP上传文件服务器
netty系列之:搭建HTTP上传文件服务器
|
安全 数据安全/隐私保护
探讨Netty获取并检查Websocket握手请求的两种方式
探讨Netty获取并检查Websocket握手请求的两种方式