实战 TLS:检查证书,验证 PFS,构建本地 HTTPS 服务器
发布: (2025年12月23日 GMT+8 12:00)
2 min read
原文: Dev.to
Source: Dev.to

TL;DR
执行三个快速检查:
- 浏览器证书
openssl s_client- DevTools 混合内容扫描
使用 Node.js 示例在本地进行实验。
关注以下内容:
- TLS 1.2 / TLS 1.3
- AEAD 加密套件
- 用于完美前向保密(PFS)的 ECDHE
最小化 HTTPS 服务器(Node.js)
将以下内容保存为 server.js。你需要 key.pem 和 cert.pem(自签名证书在本地测试即可)。
// server.js
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
https.createServer(options, (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('secure chat placeholder\n');
}).listen(8443, () => {
console.log('Listening on https://localhost:8443');
});
创建本地证书(仅用于测试)
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout key.pem \
-out cert.pem \
-days 365 \
-subj "/C=IN/ST=State/L=City/O=Org/CN=localhost"
访问它
node server.js
curl -vkI https://localhost:8443 --insecure
检查生产环境证书(OpenSSL)
openssl s_client -connect example.com:443 -servername example.com