设置安全级别
【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.】