在 Debian 上“调试 OpenSSL”通常分为几类场景:命令行调试、库/程序调用调试、TLS 连接问题排查、源码/符号级调试。下面按常见需求给你一份实用指南。
openssl version -a
dpkg -l | grep openssl
dpkg -l | grep libssl
确认是系统 OpenSSL 还是自行编译的。
openssl s_client -connect example.com:443 -servername example.com
常用参数:
-debug
-state
-trace
-CAfile /etc/ssl/certs/ca-certificates.crt
-protocol TLSv1.2
-cipher 'ECDHE-RSA-AES256-GCM-SHA384'
示例(看握手过程):
openssl s_client -connect example.com:443 -servername example.com -state -debug
openssl x509 -in cert.pem -text -noout
openssl s_client -connect example.com:443 | openssl x509 -text -noout
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1 -nodes
OpenSSL 支持通过环境变量输出调试信息:
export OPENSSL_TRACE=ALL
export OPENSSL_CONF=/path/to/openssl.cnf
常用:
OPENSSL_TRACE=TLSOPENSSL_TRACE=SSLOPENSSL_TRACE=ENGINE示例:
OPENSSL_TRACE=TLS openssl s_client -connect example.com:443
#include <openssl/err.h>
ERR_print_errors_fp(stderr);
SSL_set_info_callback(ssl, info_callback);
gcc -g -O0 test.c -lssl -lcrypto
gdb ./your_program
run
bt
strace -f openssl s_client -connect example.com:443
ltrace openssl s_client -connect example.com:443
openssl version -d
cat /etc/ssl/openssl.cnf
测试配置是否生效:
openssl ciphers -v
安装调试符号(Debian 12+):
sudo apt install libssl3-dbgsym
或:
deb http://deb.debian.org/debian-debug stable-debug main
| 问题 | 排查 |
|---|---|
| certificate verify failed | s_client -CAfile |
| handshake failure | 看 -state -debug |
| 协议不支持 | -protocol |
| 慢 | 禁用会话恢复测试 |
| 自己程序崩溃 | ERR_print_errors_fp + gdb |
如果你能告诉我:
我可以直接给你“对症”的调试步骤。