当前位置: 首页 > news >正文

解决SSL握手失败问题:SSLHandshakeException: Received fatal alert: handshake_failure

1.异常情况

异常情况如下:
在这里插入图片描述

JDK版本中安全机制导致,不同https安全协议不一致,TLS协议版本越高,HTTPS通信的安全性越高,但是相较于低版本TLS协议,高版本TLS协议对浏览器的兼容性较差。我方系统是jdk1.7默认使用TLSV1.0,对方系统是jdk1.8默认使用TLSV1.2,导致出现异常。

JDK与TLS版本情况如图所示:

在这里插入图片描述

2.解决方法

系统做http请求时,手动将TLS版本号改为1.2即可。

2.1http接口解决方法

public class HttpsClient {private static Log logger = LogFactory.getLog(HttpClientUtil.class);private volatile static CloseableHttpClient httpsClient = null;private HttpsClient(){}public static CloseableHttpClient getInstance() throws Exception{if (httpsClient == null ){synchronized (HttpsClient.class){if (httpsClient == null ) {               	httpsClient = createSSLHttpClient();}}}return httpsClient;}private static CloseableHttpClient createSSLHttpClient() {CloseableHttpClient client = null;// 设置ssl兼容协议版本SSLConnectionSocketFactory sslsf = null;try {SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {@Overridepublic boolean isTrusted(X509Certificate[] chain,String authType) throws CertificateException {return true;}}).build();sslsf = new SSLConnectionSocketFactory(sslContext,new String[] { "TLSv1.2" },null,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);javax.net.ssl.SSLSocketFactory factory = sslContext.getSocketFactory();SSLSocket socket = (SSLSocket) factory.createSocket();String[] protocols = socket.getSupportedProtocols();logger.trace("支持的协议:" + Arrays.asList(protocols));client = HttpClients.custom().setSSLSocketFactory(sslsf).build();} catch (Exception e) {logger.error("创建SSLConnectionSocketFactory失败", e);e.printStackTrace();}// 创建httpclientif (client == null) {logger.error("创建支持SSL的HttpClient失败,创建普通的HttpClient");client = HttpClients.createDefault();}return client;}}

2.2 webservice接口解决方法

public String submitToOA(KmReviewParamterForm form) throws Exception {ISysCodeService sysCodeService = (ISysCodeService)SpringBeanUtil.getBean("sysCodeService");WebServiceConfig cfg = WebServiceConfig.getInstance();cfg.setAddress(sysCodeService.getContentByCode("reviewUrl").getFdContent());cfg.setUser(sysCodeService.getContentByCode("reviewFinanceUser").getFdContent());cfg.setPassword(sysCodeService.getContentByCode("reviewFinancePassword").getFdContent());IKmReviewWebserviceService service = (IKmReviewWebserviceService) callService(cfg.getAddress(), cfg.getServiceClass());//2025-07-18 设置TLSv1.2版本 STARTClient client = ClientProxy.getClient(service);HTTPConduit httpConduit = (HTTPConduit) client.getConduit();SSLSocketFactory sslSocketFactory = SSLSocketFactoryBuilder.create().setProtocol("TLSv1.2").build();TLSClientParameters tlsClientParameters = new TLSClientParameters();tlsClientParameters.setSSLSocketFactory(sslSocketFactory);httpConduit.setTlsClientParameters(tlsClientParameters);//2025-07-18 设置TLSv1.2版本 ENDreturn service.addReview(form);}
http://www.dtcms.com/a/410615.html

相关文章:

  • 降级版本Pillow解决freetypefont has no attribute getsize问题
  • 网站设计实例教程wordpress引用文章
  • 基于蜣螂优化的LSTM深度学习网络模型(DBO-LSTM)的一维时间序列预测算法matlab仿真
  • 改进的遗传算法优化的BP神经网络用于电厂数据的异常检测和故障诊断
  • 有什么公司要做推广的网站推广优化软件
  • visual studio 2019配置qt程序
  • 漏标(Missing Mark)问题深度解析
  • OpenAI近日推出了一项名为 ChatGPT Pulse 的全新功能
  • 购物网站后台设计wordpress怎么设置404页面跳转
  • 销售网站免费做珠海品牌型网站建设
  • Lucene 8.7.0 版本中dvd、dvm文件详解
  • Ubuntu 系统上安装 jdk-23_linux-x64_bin.tar.gz
  • o2o网站制作公司广告设计与制作标书
  • 苏州网站推广建设安全达标建设网站
  • 丙烯酸胶粘剂怎么选?先避 3 个坑,再挑靠谱品牌
  • Solidworks练习13-拉伸、拉伸切、筋
  • LeetCode算法日记 - Day 54: 二叉树的所有路径、全排列
  • 人脸模型训练-推理完整过程附代码
  • 洛阳网站排名福州网站建设H5
  • C语言入门教程 | 阶段五:指针与字符串、数组——字符串指针与多级指针
  • 网站已收录的404页面的查询秀山网站建设公司
  • 爱站网站排行榜莱州网站建设制作
  • Tripfery - Travel Tour Booking WordPress Theme Tested
  • 微算法科技(NASDAQ MLGO)使用基于深度学习的物理信息神经网络(PINN),增强区块链IoT网络交易中的入侵检测
  • 前向传播与反向传播:深度学习的双翼引擎
  • 潍坊网站推广浏阳网站定制
  • 银河麒麟V10编译perl-5.42.0,并设置环境变量
  • 做网站去哪好看希岛爱理做品的网站
  • 【Android之路】.sp和界面层次结构
  • 【MacOS】Warp安装使用教程