在WebSocket中添加ssl遇到的问题

在WebSocket中添加ssl遇到的问题

[toc]
做个记录

错误日志及解决方案

可以从复制下自己的错误,在网页中找下,看下能不能找到。

// System.setProperty(“javax.net.debug”, “all”);

问题1:javax.net.ssl.SSLHandshakeException: No appropriate protocol

io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

方案:权限问题

过一阵瞎搞,最后才发现是因为jdk1.8版本导致SSL调用权限上有问题。
解决办法:找到jdk 1.8安装目录,找到jdk里面的lib\security 下面有个java.security。找到对应的SSLv3,删除掉,重启项目就好了。(删掉SSLv3就是允许SSL调用)

问题2:protocol_version、 ERR_CERT_COMMON_NAME_INVALID、 ERR_CERT_AUTHORITY_INVALID

Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
io.netty.handler.codec.DecoderException: javax.net.ssl.SSLException: Received fatal alert: protocol_version
Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version

方案:网页客户端需要信任证书

  • ERR_CERT_COMMON_NAME_INVALID
  • ERR_CERT_AUTHORITY_INVALID
  • 解决方案
    1. chrome访问chrome://flags/#show-cert-link
    2. 找到Allow invalid certificates for resources loaded from localhost.
    3. 改成Enabled
  • 解决方案出处 https://jingyan.baidu.com/article/636f38bb64f3c0d6b9461046.html

internal_error

问题3:io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record:

io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record:

方案:

客户端中pipeline.addLast(“ssl”, new SslHandler(sslEngine));

问题4:PKIX path building failed、General SSLEngine problem、unable to find valid certification path to requested target

018-08-17 15:35:55.250 DEBUG io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13 - WebSocket version 13 client handshake key: txOihqp44yIRBkIiOqYQzA==, expected response: cR25d0JOMq6RBX9igrELEfGejKA=
2018-08-17 15:35:55.820 INFO com.lizhaoblog.server.channel.websocket.WebSocketClientHandlerTest - 异常发生
io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: General SSLEngine problem

Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
… 26 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392)
… 32 more

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

方案:

  • 自己生成的证书,没有经过验证,jdk不认可
    • 启动服务器
    • 使用SSLCre请求生成一个jssecacerts
    • 将jssecacerts替换成D:\Program Files\Java\jdk1.8.0_171\jre\lib\security下的cacerts
    • 要记得改名字
      “`

你可能感兴趣的:(java,netty)