设置安全级别
\Setting security levels
要调整 Node.js 应用中的安全级别,你可以在密码字符串中包含 @SECLEVEL=X,其中 X 是所需的安全级别。例如,要在使用默认 OpenSSL 密码列表时将安全级别设置为 0,你可以使用:
\To adjust the security level in your Node.js application, you can include @SECLEVEL=X
within a cipher string, where X is the desired security level. For example,
to set the security level to 0 while using the default OpenSSL cipher list, you could use:
import { createServer, connect } from 'node:tls'; const port = 443; createServer({ ciphers: 'DEFAULT@SECLEVEL=0', minVersion: 'TLSv1' }, function(socket) { console.log('Client connected with protocol:', socket.getProtocol()); socket.end(); this.close(); }) .listen(port, () => { connect(port, { ciphers: 'DEFAULT@SECLEVEL=0', maxVersion: 'TLSv1' }); });const { createServer, connect } = require('node:tls'); const port = 443; createServer({ ciphers: 'DEFAULT@SECLEVEL=0', minVersion: 'TLSv1' }, function(socket) { console.log('Client connected with protocol:', socket.getProtocol()); socket.end(); this.close(); }) .listen(port, () => { connect(port, { ciphers: 'DEFAULT@SECLEVEL=0', maxVersion: 'TLSv1' }); });
此方法将安全级别设置为 0,允许使用旧功能,同时仍利用默认的 OpenSSL 密码。
\This approach sets the security level to 0, allowing the use of legacy features while still leveraging the default OpenSSL ciphers.