Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions deps/ncrypto/ncrypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4958,8 +4958,10 @@ std::optional<uint32_t> SSLPointer::verifyPeerCertificate() const {
// Allow no-cert for PSK authentication in TLS1.2 and lower.
// In TLS1.3 check that session was reused because TLS1.3 PSK
// looks like session resumption.
if (SSL_CIPHER_get_auth_nid(curr_cipher) == NID_auth_psk ||
(SSL_SESSION_get_protocol_version(sess) == TLS1_3_VERSION &&
if ((curr_cipher != nullptr &&
SSL_CIPHER_get_auth_nid(curr_cipher) == NID_auth_psk) ||
(sess != nullptr &&
SSL_SESSION_get_protocol_version(sess) == TLS1_3_VERSION &&
SSL_session_reused(get()))) {
return X509_V_OK;
}
Expand Down
47 changes: 47 additions & 0 deletions test/parallel/test-tls-emit-secure-before-handshake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('node:assert');
const net = require('node:net');
const tls = require('node:tls');

for (const rejectUnauthorized of [false, undefined]) {
const server = net.createServer((socket) => {
socket.resume();
});

server.listen(0, '127.0.0.1', common.mustCall(() => {
const options = {
host: '127.0.0.1',
port: server.address().port,
};
if (rejectUnauthorized === false)
options.rejectUnauthorized = false;
const socket = tls.connect(options);

socket.on('connect', common.mustCall(() => {
// A premature secure event must report a missing certificate even when
// neither a cipher nor a session has been established yet.
socket.emit('secure');
assert.strictEqual(socket.authorized, false);
assert.strictEqual(socket.authorizationError,
'UNABLE_TO_GET_ISSUER_CERT');
}));

if (rejectUnauthorized === false) {
socket.on('error', common.mustNotCall());
socket.on('secureConnect', common.mustCall(() => socket.destroy()));
} else {
socket.on('secureConnect', common.mustNotCall());
socket.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'UNABLE_TO_GET_ISSUER_CERT');
}));
}

socket.on('close', common.mustCall(() => {
server.close(common.mustCall());
}));
}));
}
Loading