本文介绍验证新的根证书是否生效的方法。请注意以下方式仅用于测试环境,不要用于生产环境。
抓包验证
将以下内容保存为parse.sh脚本。
#!/bin/bash
PCAP="$1"
tshark -r "$PCAP" -Y "tls.handshake.type==1" -T fields \
-e tcp.stream -e tls.handshake.extensions_server_name 2>/dev/null | sort -u > /tmp/sni.tsv
echo "Stream SNI(请求域名) 证书链CN (叶子→中间→根)"
echo "------ ------------------------------------ -------------------------------------------"
while IFS=$'\t' read -r stream sni; do
cn=$(tshark -r "$PCAP" -Y "tcp.stream==$stream && tls.handshake.type==11" -V 2>/dev/null \
| grep -oE 'id-at-commonName=[^,)]+' \
| sed 's/id-at-commonName=//' \
| awk '!seen[$0]++' \
| tr '\n' '|' | sed 's/|$//')
printf "%-6s %-36s %s\n" "$stream" "$sni" "${cn:-(无Certificate报文)}"
done < /tmp/sni.tsv说明
运行该脚本需要先安装tshark软件。
抓包拿到抓包文件(以file.pcap为例)后,执行如下命令。
sh parse.sh file.pcap如果设备建联成功,且脚本输出如下内容,说明设备使用了PCA根证书(8883端口)。
SNI(请求域名) 证书链CN (叶子→中间→根)
------------------------------------ ------------------------------------
iot-0xxxx5.mqtt.iothub.aliyuncs.com Aliyun|*.iot-as.aliyuncs.com|Aliyun IoT Root CA如果设备建联成功,且脚本输出如下内容,说明设备使用了R46根证书。
SNI(请求域名) 证书链CN (叶子→中间→根)
------------------------------------ ------------------------------------
iot-0xxxxl-x.mqtt.iothub.aliyuncs.com GlobalSign GCC R46 OV TLS CA 2025 GlobalSign GCC R46 OV TLS CA 2025) GlobalSign GCC R46 OV TLS CA 2025)在SDK中增加打印
C语言
4.x
下载带debug信息的core_adapter.c文件,将该文件替换SDK中当前的core/sysdep/core_adapter.c文件。
编译SDK,运行linkSDK的demo。
如果采用的是-x的域名和443端口,则会打印出如下内容,其中CN=GlobalSign Root R46表示已使用新的R46根证书。
establish tcp connection with server(host='iot-06xxxl-x.mqtt.iothub.aliyuncs.com', port=[443])
success to establish tcp, fd=5
local port: 56403
[1786539657.002][LK-1000] establish mbedtls connection with server(host='iot-0xxxxl-x.mqtt.iothub.aliyuncs.com', port=[443])
[1786539657.079][LK-1000] Verified root CA: C=BE, O=GlobalSign nv-sa, CN=GlobalSign Root R46, not_after: 2046-03-20 00:00:00
[1786539657.079][LK-1000] success to establish mbedtls connection, (cost 54859 bytes in total, max used 61859 bytes)如果使用8883端口,则会打印出如下内容,其中2053-07-04 06:36:58表示使用的是PCA证书。
[1786621591.056][LK-0313] MQTT user calls aiot_mqtt_connect api, connect
[1786621591.056][LK-032A] mqtt host: iot-0xxxxl-x.mqtt.iothub.aliyuncs.com
[1786621591.056][LK-0317] user name: 3167xxxxxxxxxxxxxxxxxvZ3z
establish tcp connection with server(host='iot-06xxxxxl-x.mqtt.iothub.aliyuncs.com', port=[8883])
success to establish tcp, fd=5
local port: 60813
[1786621591.210][LK-1000] establish mbedtls connection with server(host='iot-0xxxxl-x.mqtt.iothub.aliyuncs.com', port=[8883])
[1786621591.300][LK-1000] Verified root CA: C=CN, ST=Zhejiang, L=Hangzhou, O=Aliyun IoT, OU=Root CA, CN=Aliyun IoT Root CA, not_after: 2053-07-04 06:36:58
[1786621591.300][LK-1000] success to establish mbedtls connection, (cost 53518 bytes in total, max used 56702 bytes)其他版本:
参考4.x的patch文件进行修改和验证。
该文章对您有帮助吗?