mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Since `common/crypto` already exists, it makes sense to keep crypto-related utilities there. The only exception being common.hasCrypto which is needed up front to determine if tests should be skipped. Eliminate the redundant check in hasFipsCrypto and just use crypto.getFips() directly where needed. PR-URL: https://github.com/nodejs/node/pull/56714 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const { hasOpenSSL } = require('../common/crypto');
|
|
|
|
// This test ensures that `getProtocol` returns the right protocol
|
|
// from a TLS connection
|
|
|
|
const assert = require('assert');
|
|
const tls = require('tls');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const clientConfigs = [
|
|
{
|
|
secureProtocol: 'TLSv1_method',
|
|
version: 'TLSv1',
|
|
ciphers: (hasOpenSSL(3, 1) ? 'DEFAULT:@SECLEVEL=0' : 'DEFAULT')
|
|
}, {
|
|
secureProtocol: 'TLSv1_1_method',
|
|
version: 'TLSv1.1',
|
|
ciphers: (hasOpenSSL(3, 1) ? 'DEFAULT:@SECLEVEL=0' : 'DEFAULT')
|
|
}, {
|
|
secureProtocol: 'TLSv1_2_method',
|
|
version: 'TLSv1.2'
|
|
},
|
|
];
|
|
|
|
const serverConfig = {
|
|
secureProtocol: 'TLS_method',
|
|
ciphers: 'RSA@SECLEVEL=0',
|
|
key: fixtures.readKey('agent2-key.pem'),
|
|
cert: fixtures.readKey('agent2-cert.pem')
|
|
};
|
|
|
|
const server = tls.createServer(serverConfig, common.mustCall(clientConfigs.length))
|
|
.listen(0, common.localhostIPv4, function() {
|
|
let connected = 0;
|
|
for (const v of clientConfigs) {
|
|
tls.connect({
|
|
host: common.localhostIPv4,
|
|
port: server.address().port,
|
|
ciphers: v.ciphers,
|
|
rejectUnauthorized: false,
|
|
secureProtocol: v.secureProtocol
|
|
}, common.mustCall(function() {
|
|
assert.strictEqual(this.getProtocol(), v.version);
|
|
this.on('end', common.mustCall());
|
|
this.on('close', common.mustCall(function() {
|
|
assert.strictEqual(this.getProtocol(), null);
|
|
})).end();
|
|
if (++connected === clientConfigs.length)
|
|
server.close();
|
|
}));
|
|
}
|
|
});
|