NodeJs“前向保密”问题

NodeJs " Forward Secrecy" issues

我想在 ssllabs.com 上为我的网站 www.cloudcaptcha.ga 获得 A+ 分数,但收到此警告:'This server does not support Forward Secrecy with the reference browsers. Grade capped to B'

我正在使用带有 http2 服务器模块的 NodeJs v12.6。使用

生成有效的 dhparam

openssl dhparam -outform PEM -out dhparam.pem 2048

但是没有用。

我当前服务器的 secureContextOptions =

{
  ca: fs.readFileSync('chain.pem'),
  cert: fs.readFileSync('fullchain.pem', 'utf8'),
  key: fs.readFileSync('privkey.pem', 'utf8'),
  dhparam: fs.readFileSync('dhparam.pem', 'utf8'),
  rejectUnauthorized: false,
  honorCipherOrder: false,
  allowHTTP1: true,
  ecdhCurve: 'auto',
}

如何解决这个前向保密问题?

前向保密问题可能是禁用的 honorCipherOrder 选项引起的,请尝试启用它。

honorCipherOrder: true

禁用honorCipherOrder时,根据TLS客户端偏好选择握手期间协商的密码套件。 IE 11 / Win Phone 8.1 等 TLS 客户端更喜欢非 FS 密码套件而不是 FS 密码套件。

为了获得 A+ 它也是 required to add the Strict-Transport-Security (HSTS) header 至少 6 个月 max-age 的每个响应:

New grade A+ is introduced for servers with exceptional configurations. At the moment, this grade is awarded to servers with good configuration, no warnings, and HTTP Strict Transport Security support with a max-age of at least 6 months.

max-age 设置为 1 年的 HSTS header 示例:

Strict-Transport-Security: max-age=31536000;

使用本机 node.js 响应 object 您可以使用 response.setHeader:

设置 header
response.setHeader("Strict-Transport-Security", "max-age=31536000");

如果您使用 express,您还可以检查 helmet 或只编写一个简单的中间件,将 header 添加到每个响应中。