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
56 changes: 34 additions & 22 deletions deps/ncrypto/ncrypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,19 +777,25 @@ bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
// Note that the preferred name syntax (see RFCs 5280 and 1034) with
// wildcards is a subset of what we consider "safe", so spec-compliant DNS
// names will never need to be escaped.
PrintAltName(out, reinterpret_cast<const char*>(name->data), name->length);
PrintAltName(out,
reinterpret_cast<const char*>(ASN1_STRING_get0_data(name)),
ASN1_STRING_length(name));
} else if (gen->type == GEN_EMAIL) {
ASN1_IA5STRING* name = gen->d.rfc822Name;
BIO_write(out.get(), "email:", 6);
PrintAltName(out, reinterpret_cast<const char*>(name->data), name->length);
PrintAltName(out,
reinterpret_cast<const char*>(ASN1_STRING_get0_data(name)),
ASN1_STRING_length(name));
} else if (gen->type == GEN_URI) {
ASN1_IA5STRING* name = gen->d.uniformResourceIdentifier;
BIO_write(out.get(), "URI:", 4);
// The set of "safe" names was designed to include just about any URI,
// with a few exceptions, most notably URIs that contains commas (see
// RFC 2396). In other words, most legitimate URIs will not require
// escaping.
PrintAltName(out, reinterpret_cast<const char*>(name->data), name->length);
PrintAltName(out,
reinterpret_cast<const char*>(ASN1_STRING_get0_data(name)),
ASN1_STRING_length(name));
} else if (gen->type == GEN_DIRNAME) {
// Earlier versions of Node.js used X509_NAME_oneline to print the X509_NAME
// object. The format was non standard and should be avoided. The use of
Expand Down Expand Up @@ -822,17 +828,18 @@ bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
} else if (gen->type == GEN_IPADD) {
BIO_printf(out.get(), "IP Address:");
const ASN1_OCTET_STRING* ip = gen->d.ip;
const unsigned char* b = ip->data;
if (ip->length == 4) {
const unsigned char* b = ASN1_STRING_get0_data(ip);
int ip_len = ASN1_STRING_length(ip);
if (ip_len == 4) {
BIO_printf(out.get(), "%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
} else if (ip->length == 16) {
} else if (ip_len == 16) {
for (unsigned int j = 0; j < 8; j++) {
uint16_t pair = (b[2 * j] << 8) | b[2 * j + 1];
BIO_printf(out.get(), (j == 0) ? "%X" : ":%X", pair);
}
} else {
#if OPENSSL_VERSION_MAJOR >= 3
BIO_printf(out.get(), "<invalid length=%d>", ip->length);
BIO_printf(out.get(), "<invalid length=%d>", ip_len);
#else
BIO_printf(out.get(), "<invalid>");
#endif
Expand Down Expand Up @@ -882,15 +889,15 @@ bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
if (unicode) {
auto name = gen->d.otherName->value->value.utf8string;
PrintAltName(out,
reinterpret_cast<const char*>(name->data),
name->length,
reinterpret_cast<const char*>(ASN1_STRING_get0_data(name)),
ASN1_STRING_length(name),
AltNameOption::UTF8,
prefix);
} else {
auto name = gen->d.otherName->value->value.ia5string;
PrintAltName(out,
reinterpret_cast<const char*>(name->data),
name->length,
reinterpret_cast<const char*>(ASN1_STRING_get0_data(name)),
ASN1_STRING_length(name),
AltNameOption::NONE,
prefix);
}
Expand All @@ -911,11 +918,14 @@ bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
}
} // namespace

bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext) {
auto ret = OBJ_obj2nid(X509_EXTENSION_get_object(ext));
bool SafeX509SubjectAltNamePrint(const BIOPointer& out,
const X509_EXTENSION* ext) {
// const_cast needed for OpenSSL < 4.0 which lacks const-correctness
auto* mext = const_cast<X509_EXTENSION*>(ext);
auto ret = OBJ_obj2nid(X509_EXTENSION_get_object(mext));
if (ret != NID_subject_alt_name) return false;

GENERAL_NAMES* names = static_cast<GENERAL_NAMES*>(X509V3_EXT_d2i(ext));
GENERAL_NAMES* names = static_cast<GENERAL_NAMES*>(X509V3_EXT_d2i(mext));
if (names == nullptr) return false;

bool ok = true;
Expand All @@ -934,12 +944,14 @@ bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext) {
return ok;
}

bool SafeX509InfoAccessPrint(const BIOPointer& out, X509_EXTENSION* ext) {
auto ret = OBJ_obj2nid(X509_EXTENSION_get_object(ext));
bool SafeX509InfoAccessPrint(const BIOPointer& out, const X509_EXTENSION* ext) {
// const_cast needed for OpenSSL < 4.0 which lacks const-correctness
auto* mext = const_cast<X509_EXTENSION*>(ext);
auto ret = OBJ_obj2nid(X509_EXTENSION_get_object(mext));
if (ret != NID_info_access) return false;

AUTHORITY_INFO_ACCESS* descs =
static_cast<AUTHORITY_INFO_ACCESS*>(X509V3_EXT_d2i(ext));
static_cast<AUTHORITY_INFO_ACCESS*>(X509V3_EXT_d2i(mext));
if (descs == nullptr) return false;

bool ok = true;
Expand Down Expand Up @@ -1083,7 +1095,7 @@ BIOPointer X509View::getValidFrom() const {
if (cert_ == nullptr) return {};
BIOPointer bio(BIO_new(BIO_s_mem()));
if (!bio) return {};
ASN1_TIME_print(bio.get(), X509_get_notBefore(cert_));
ASN1_TIME_print(bio.get(), X509_get0_notBefore(cert_));
return bio;
}

Expand All @@ -1092,7 +1104,7 @@ BIOPointer X509View::getValidTo() const {
if (cert_ == nullptr) return {};
BIOPointer bio(BIO_new(BIO_s_mem()));
if (!bio) return {};
ASN1_TIME_print(bio.get(), X509_get_notAfter(cert_));
ASN1_TIME_print(bio.get(), X509_get0_notAfter(cert_));
return bio;
}

Expand Down Expand Up @@ -4643,12 +4655,12 @@ bool X509Name::Iterator::operator!=(const Iterator& other) const {
std::pair<std::string, std::string> X509Name::Iterator::operator*() const {
if (loc_ == name_.total_) return {{}, {}};

X509_NAME_ENTRY* entry = X509_NAME_get_entry(name_, loc_);
const X509_NAME_ENTRY* entry = X509_NAME_get_entry(name_, loc_);
if (entry == nullptr) [[unlikely]]
return {{}, {}};

ASN1_OBJECT* name = X509_NAME_ENTRY_get_object(entry);
ASN1_STRING* value = X509_NAME_ENTRY_get_data(entry);
const ASN1_OBJECT* name = X509_NAME_ENTRY_get_object(entry);
const ASN1_STRING* value = X509_NAME_ENTRY_get_data(entry);

if (name == nullptr || value == nullptr) [[unlikely]] {
return {{}, {}};
Expand Down
5 changes: 3 additions & 2 deletions deps/ncrypto/ncrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,9 @@ int NoPasswordCallback(char* buf, int size, int rwflag, void* u);

int PasswordCallback(char* buf, int size, int rwflag, void* u);

bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext);
bool SafeX509InfoAccessPrint(const BIOPointer& out, X509_EXTENSION* ext);
bool SafeX509SubjectAltNamePrint(const BIOPointer& out,
const X509_EXTENSION* ext);
bool SafeX509InfoAccessPrint(const BIOPointer& out, const X509_EXTENSION* ext);

// ============================================================================
// SPKAC
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-tls-client-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ connect({
}, common.mustCall((err, pair, cleanup) => {
assert.strictEqual(pair.server.err.code,
'ERR_SSL_PEER_DID_NOT_RETURN_A_CERTIFICATE');
const expectedErr = hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
const expectedErr = hasOpenSSL(4, 0) ?
'ERR_SSL_TLS_ALERT_HANDSHAKE_FAILURE' : hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
assert.strictEqual(pair.client.err.code,
expectedErr);
return cleanup();
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-tls-empty-sni-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const server = tls.createServer(options, (c) => {
}, common.mustNotCall());

c.on('error', common.mustCall((err) => {
const expectedErr = hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
const expectedErr = hasOpenSSL(4, 0) ?
'ERR_SSL_TLS_ALERT_HANDSHAKE_FAILURE' : hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
assert.strictEqual(err.code, expectedErr);
}));
}));
5 changes: 3 additions & 2 deletions test/parallel/test-tls-psk-circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ test({ psk: USERS.UserA, identity: 'UserA' }, { minVersion: 'TLSv1.3' });
test({ psk: USERS.UserB, identity: 'UserB' });
test({ psk: USERS.UserB, identity: 'UserB' }, { minVersion: 'TLSv1.3' });
// Unrecognized user should fail handshake
const expectedHandshakeErr = hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
const expectedHandshakeErr = hasOpenSSL(4, 0) ?
'ERR_SSL_TLS_ALERT_HANDSHAKE_FAILURE' : hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
test({ psk: USERS.UserB, identity: 'UserC' }, {}, expectedHandshakeErr);
// Recognized user but incorrect secret should fail handshake
const expectedIllegalParameterErr = hasOpenSSL(3, 4) ? 'ERR_SSL_TLSV1_ALERT_DECRYPT_ERROR' :
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tls-set-ciphers.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ function test(cciphers, sciphers, cipher, cerr, serr, options) {
const U = undefined;

let expectedTLSAlertError = 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
if (hasOpenSSL(3, 2)) {
if (hasOpenSSL(4, 0)) {
expectedTLSAlertError = 'ERR_SSL_TLS_ALERT_HANDSHAKE_FAILURE';
} else if (hasOpenSSL(3, 2)) {
expectedTLSAlertError = 'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE';
}

Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-tls-set-sigalgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ test('RSA-PSS+SHA256:RSA-PSS+SHA512:ECDSA+SHA256',
['RSA-PSS+SHA256', 'ECDSA+SHA256']);

// Do not have shared sigalgs.
const handshakeErr = hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
const handshakeErr = hasOpenSSL(4, 0) ?
'ERR_SSL_TLS_ALERT_HANDSHAKE_FAILURE' : hasOpenSSL(3, 2) ?
'ERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE' : 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE';
test('RSA-PSS+SHA384', 'ECDSA+SHA256',
undefined, handshakeErr,
'ERR_SSL_NO_SHARED_SIGNATURE_ALGORITHMS');
Expand Down
Loading