SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决

当使用较新版本SpringBoot时,对应的 kafka-client 版本也比较新,如果使用了 2.x 以上的 kafka-client ,并且配置了 kafka ssl 连接方式时,可能会报如下异常:

javax.net.ssl.SSLException: Inbound closed before receiving peer‘s close_notify: possible truncation attack?

.....

org.apache.kafka.common.errors.SslAuthenticationException: SSL handshake failed
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem

.....

Caused by: java.security.cert.CertificateException: No subject alternative names present

.....

2019-10-09 10:12:55.683 DEBUG 23524 --- [           main] o.s.kafka.core.KafkaTemplate             : Failed to send: ProducerRecord

.....

该原因是因为新版本 kafka-client 会校验证书的主机名,配置忽略主机名校验即可。

配置方法主要代码如下:

1 spring:
2   kafka:
3     properties:
4       ssl:
5         endpoint:
6           identification:
7             algorithm: ‘‘

另附SpringBoot 使用 ssl 证书连接 kafka 完整配置如下:

 1 ########## kafka ##########
 2 spring:
 3   kafka:
 4     producer:
 5       batch-size: 16384
 6       retries: 1
 7       buffer-memory: 33554432
 8       bootstrap-servers: 192.168.1.100:9092
 9       value-serializer: org.apache.kafka.common.serialization.StringSerializer
10       key-serializer: org.apache.kafka.common.serialization.StringSerializer
11     consumer:
12       group-id: test-group-001
13       auto-offset-reset: earliest
14       auto-commit-interval: 100
15       bootstrap-servers: 192.168.1.100:9092
16       value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
17       key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
18       enable-auto-commit: true
19     ssl:
20       protocol: SSL
21       trust-store-type: JKS
22       trust-store-location: file:D:/source-files/kafka/kafkatest.client.truststore.test.jks
23       trust-store-password: 123456
24       key-store-type: JKS
25       key-store-location: file:D:/source-files/kafka/kafkatest.client.keystore.test.jks
26       key-store-password: 123456
27       key-password: 123456
28     properties:
29       ssl:
30         endpoint:
31           identification:
32             algorithm: ‘‘
33       security:
34         protocol: SSL

问题解决。

原文地址:https://www.cnblogs.com/moonciki/p/11640883.html

时间: 2024-08-05 02:58:09

SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决的相关文章

java.security.cert.CertificateException: No subject alternative names present

背景:在开发一个项目中,要调用一个webservice服务,之前设置的是http协议,项目中采用jdk自带的wsimport工具生成的客户端代码; 后来,需求变更要求兼容https协议的webservice,开始以为只需要简单的将服务地址的连接改为https就可以了:但不行,总是报错 javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names

JDK安全证书的一个错误消息 No subject alternative names present的解决办法

我使用Java消费某网站一个Restful API时,遇到这个错误: 21:31:16.383 [main] DEBUG org.springframework.web.client.RestTemplate - Created GET request for "https://127.0.0.1:5031/commerce/product" 21:31:16.388 [main] DEBUG org.springframework.web.client.RestTemplate -

关于springboot 连接mysql 数据库报错问题

springboot连接MySQL运行报错: The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zon

PostgreSQL添加新服务器连接时,报错“Server doesn't listen ”,已解决。

PostgreSQL添加新的服务器连接时,报错: 解决方法: 第一步:修改配置文件中连接的服务器列表,添加服务器IP地址(图pg002.png) 配置文件地址:数据库右击属性,打开数据库的安装路径在data文件中找到配置文件pg_hba.conf. 如:D:\Program Files\PostgreSQL\9.4\data\pg_hba.conf 注:只要修改IP路径就可以了,‘/’后面的数字都为32. 第二步:修改配置文件后,启动服务器的服务: 启动服务完成,连接服务器,新服务器就可以正常的

SpringBoot连接Mysql数据库警告:Establishing SSL connection without server's identity verification is not recommend

Java使用mysql-jdbc连接MySQL出现如下警告: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't s

SpringBoot整合Kafka和Storm

前言 本篇文章主要介绍的是SpringBoot整合kafka和storm以及在这过程遇到的一些问题和解决方案. kafka和storm的相关知识 如果你对kafka和storm熟悉的话,这一段可以直接跳过!如果不熟,也可以看看我之前写的博客.一些相关博客如下. kafka 和 storm的环境安装 地址:http://www.panchengming.com/2018/01/26/pancm70/ kafka的相关使用 地址:http://www.panchengming.com/2018/01

kafka启动报错&问题解决

kafka启动报错&问题解决 一早上班,就收到运维同事通知说有一台物理机宕机,导致虚拟机挂了.只得重启kafka服务器. 1.启动 启动zookeeper bin/zkServer.sh start conf/zoo.cfg & 启动kafka bin/kafka-server-start.sh config/server.properties & 2.测试 问题一 kafka启动之后,发现一直打印warn,上图.且在进程中ps -ef| grep kafka,无法看到.很明显ka

springboot连接redis错误 io.lettuce.core.RedisCommandTimeoutException:

springboot连接redis报错 超时连接不上  可以从以下方面排查 1查看自己的配置文件信息,把超时时间不要设置0毫秒 设置5000毫秒 2redis服务长时间不连接就会休眠,也会连接不上 重新启动redis服务<黑窗口> 原文地址:https://www.cnblogs.com/langjunnan/p/10017721.html

springboot的依赖注入报null的问题

最近使用springboot开发项目,使用到了依赖注入,频繁的碰到注入的对象报空指针,错误如下 java.lang.NullPointerException: null at com.mayihc.audit.controller.MaterialNkDetailController.download(MaterialNkDetailController.java:72) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)