首页 > 编程语言 >JAVA1.8-SSL错误:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExceptiion

JAVA1.8-SSL错误:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExceptiion

时间:2022-10-06 10:33:35浏览次数:65  
标签:java SSLHandshakeException sun ssl path security javax

问题现象

Java Spring应用发送数据报如下问题。

2022-10-06 10:04:19.068 ERROR 23100 --- [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.chinaxxx.com, port: 443;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.chinaxxx.com, port: 443;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.chinaxxx.com, port: 443;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target] with root cause

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)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:302)
at sun.security.validator.Validator.validate(Validator.java:262)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1596)

解决方法

复制附录代码到文本文件中,改名为InstallCert.java。然后分别执行如下两条命令。

D:\Java\jdk1.8.0_221\bin\javac D:\code\InstallCert.java
java InstallCert smtp.chinaxxx.com:443; 

说明:网址处不需要输入(https://)信息,比如 smtp.chinaxxx.com:443 。

随后服务器会返回认证的主题,发行方,加密方式等信息。

在这里输入1后,回车。

Enter certificate to add to trusted keystore or 'q' to quit: [1] 在code目录下会生成文件jssecacerts,自此认证过程结束。

替换证书

将生成的jssecacerts文件复制到 jdk的相应路径下即可。
windows系统一般需要首先找到jdk安装路径
D:\Java\jdk1.8.0_221\jre\lib\security

如果是Linux系统,需要首先使用 scp 命令 将 jssecacerts 传输至服务器。

如果应用运行在 docker ,jdk通常在这个地方
/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/security/
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/ (和上面其实一样)
替换完后,重启 docker 即可。

标签:java,SSLHandshakeException,sun,ssl,path,security,javax
From: https://www.cnblogs.com/tianyuanblog/p/16757128.html

相关文章

  • git提交报错:fatal: unable to access 'https://github.com/xxxx.git/': OpenSSL SSL_r
    一/现象  二/原因 因为git在拉取或者提交项目时,中间会有git的http和https代理,但是我们本地环境本身就有SSL协议了,所以取消git的https代理即可,不行再取消http的代......
  • D. Bank Security Unification
    D.BankSecurityUnificationhttps://codeforces.ml/group/MKpYqfAQQQ/contest/401639/problem/D题意给你一个数列你可以选择一个子序列(可以不连续)这个序列的贡献......
  • SpringSecurity异常处理器
    原理在SpringSecurity中,在认证或者授权的过程中出现的异常会被ExceptionTranslationFilter捕获到,在ExceptionTranslationFilter中会去判断这异常是认证失败还是授权失败产......
  • Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protoco
    如果出现了标题的错误首先看我的pom.xml里面mysql驱动和druid版本对应和application.yml里面的配置解决方法:这个解决方法很简单,只需要把useSSL=false即可。是不是......
  • 【Spring】SpringSecurity的使用
    4SpringSecurity只需要协助SpringSecurity创建好用户对应的角色和权限组,同时把各个资源所要求的权限信息设定好,剩下的像“登录验证”、"权限验证"等等工作都交给Spring......
  • Windows10 WSL子系统安装CentOS7、OpenSSL-3.0.5 及 Python-3.10.7
    本文版权归博主 惊梦无痕 所有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作。原文地址Linux小白一个,最近打算在Linux环境中学习Python,但又不想安装双系统,最后......
  • security + cloud模板
    前言​​案例地址​​​​镜像地址​​部署当前项目为cloud+security案例模板,要部署cloud项目,将每个模块打成jar包上传到服务器,之后打成镜像打成镜像后启动容器报错:​​no......
  • security单点登录案例
    案例简介前端发送登录请求,登录成功后,将用户信息及该用户所拥有的权限保存到redis数据库中,同时生成token,将token放到cookie中返回给前端;之后前端每次向后端发送请求时,将token......
  • 整合security跨域问题
    publicclassSecurityConfigextendsWebSecurityConfigurerAdapter{@AutowiredprivateUserDetailsServiceuserDetailsService;//动态认证@Override......
  • 启动 Hello Spring Security Boot 应用
    本文章对如何快速启动一个启动HelloSpringSecurityBoot应用进行说明。下载代码在这个项目中,使用的是 spring.io 的项目生成程序,生成的地址为:https://start.sprin......