如何在 Node.js Express 服务器上阻止 TLS 1.0 和 TLS 1.1?我正在使用传统的服务器设置脚本:
const app = express();
export const server = app.listen(3000);
我有点困惑为什么我找不到任何相关文档。
通常,您会在其他东西后面运行 Express 服务器,例如 Nginx 代理、AWS 负载均衡器或终止 TLS 的其他软件或硬件。在您的示例中,您根本没有通过 HTTPS 进行侦听,而是在端口 3000 上侦听 HTTP 连接。配置通常在 Node 应用程序外部完成,但如果您确实想在 Node 应用程序中执行此操作,会是这样的:
const express = require('express')
const https = require('https')
const fs = require('fs')
const { options } = require('crypto')
const app = express()
const opts = {
key: fs.readFileSync('/path/to/key.pem'),
cert: fs.readFileSync('/path/to/chain.pem'),
secureOptions: constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1,
}
// other app logic
// Or 443 if you run it as root, which is not recommended;
// instead you should proxy to it.
https.createServer(opts, app).listen(3443)
例如。
const https = require("https");
const https_options = {
pfx: fs.readFileSync(path.join(__dirname, "../ssl/cert.pfx")),
passphrase: "password",
minVersion: "TLSv1.2"
}
server = https.createServer(https_options, app);
minVersion 是实现此目的的最简单方法,如下所述:https://stackoverflow.com/a/62051684/4487632