1. 更新OpenSSL至最新版本
保持OpenSSL为最新稳定版本是安全基础,新版本通常修复已知漏洞(如心脏出血漏洞)。通过包管理器更新:
sudo apt update && sudo apt upgrade openssl # Debian/Ubuntu
sudo yum update openssl # RHEL/CentOS
2. 配置安全的SSL/TLS协议与密码套件
禁用不安全的SSLv2、SSLv3及早期TLS版本(如TLS 1.0/1.1),仅启用TLS 1.2及以上;选择强密码套件,避免弱算法(如MD5、RC4)。编辑OpenSSL主配置文件(通常位于/etc/ssl/openssl.cnf),添加/修改以下内容:
[system_default_sect]
MinProtocol = TLSv1.2
CipherString = HIGH:!aNULL:!MD5:!RC4:!DES:!3DES:!CAMELLIA:@STRENGTH
3. 强化私钥管理
私钥是SSL/TLS安全核心,需严格保护:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -aes256
600,所有者为root:chmod 600 /path/to/private.key
chown root:root /path/to/private.key
4. 启用OCSP Stapling
OCSP Stapling可减少客户端验证证书的时间,降低中间人攻击风险。在Web服务器(如Nginx/Apache)中启用:
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
SSLUseStapling on
SSLStaplingCache "shmcb:/var/run/ocsp(128000)"
5. 配置HSTS(HTTP Strict Transport Security)
强制浏览器仅通过HTTPS访问网站,防止SSL剥离攻击。在Web服务器配置中添加:
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
6. 定期审计与监控
/var/log/syslog、/var/log/openssl.log):tail -f /var/log/syslog | grep openssl
sslscan、nmap等工具定期检查配置漏洞:sudo apt install sslscan
sslscan --tls-version all yourdomain.com
7. 限制访问权限
/etc/ssl/openssl.cnf)权限设为644,所有者为root:chmod 644 /etc/ssl/openssl.cnf
chown root:root /etc/ssl/openssl.cnf
ufw、iptables)限制对OpenSSL相关端口(如443)的访问,仅允许可信IP。8. 证书生命周期管理
[ca]
crl_extensions = crl_ext
default_crl_days = 30
[crl_ext]
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign