Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .cpplint
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
set noparent
filter=-build/include_alpha,-build/include_subdir,-build/include_what_you_use,-legal/copyright,-readability/nolint,-readability/braces
filter=-build/c++17,-build/include_alpha,-build/include_subdir,-build/include_what_you_use,-legal/copyright,-readability/nolint,-readability/braces,-whitespace/indent_namespace
linelength=80
5 changes: 4 additions & 1 deletion deps/ncrypto/ncrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ namespace ncrypto {
#define NCRYPTO_STR(x) #x
#define NCRYPTO_REQUIRE(EXPR) \
{ \
if (!(EXPR) { abort(); }) }
if (!(EXPR)) { \
abort(); \
} \
}

#define NCRYPTO_FAIL(MESSAGE) \
do { \
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void StartLoadingCertificatesOffThread(
// loading.
{
Mutex::ScopedLock cli_lock(node::per_process::cli_options_mutex);
if (!per_process::cli_options->ssl_openssl_cert_store) {
if (per_process::cli_options->ssl_openssl_cert_store) {
return;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,9 @@ Maybe<void> Decorate(Environment* env,
#define V(name) case ERR_LIB_##name: lib = #name "_"; break;
const char* lib = "";
const char* prefix = "OSSL_";
switch (ERR_GET_LIB(err)) { OSSL_ERROR_CODES_MAP(V) }
switch (ERR_GET_LIB(err)) { /* NOLINT(whitespace/newline) */
OSSL_ERROR_CODES_MAP(V)
}
#undef V
#undef OSSL_ERROR_CODES_MAP
// Don't generate codes like "ERR_OSSL_SSL_".
Expand Down
2 changes: 2 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void AsyncHooks::push_async_context(

// When this call comes from JS (as a way of increasing the stack size),
// `resource` will be empty, because JS caches these values anyway.
// False positive: https://github.com/cpplint/cpplint/issues/410
// NOLINTNEXTLINE(whitespace/newline)
if (std::visit([](auto* ptr) { return ptr != nullptr; }, resource)) {
native_execution_async_resources_.resize(offset + 1);
// Caveat: This is a v8::Local<>* assignment, we do not keep a v8::Global<>!
Expand Down
2 changes: 2 additions & 0 deletions src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ static bool IsIPAddress(const std::string& host) {
// (other than ::/128) that represent non-routable IPv4 addresses. However,
// this translation assumes that the host is interpreted as an IPv6 address
// in the first place, at which point DNS rebinding should not be an issue.
// False positive: https://github.com/cpplint/cpplint/issues/410
// NOLINTNEXTLINE(whitespace/newline)
if (std::ranges::all_of(ipv6, [](auto b) { return b == 0; })) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/node_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
napi_value exports);
// False positive: https://github.com/cpplint/cpplint/issues/409
// NOLINTNEXTLINE (readability/casting)
typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);

typedef struct napi_callback_scope__* napi_callback_scope;
Expand Down
4 changes: 3 additions & 1 deletion src/quic/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ constexpr std::string to_string(ngtcp2_cc_algo cc_algorithm) {
#define V(name, label) \
case NGTCP2_CC_ALGO_##name: \
return #label;
switch (cc_algorithm) { CC_ALGOS(V) }
switch (cc_algorithm) { /* NOLINT(whitespace/newline) */
CC_ALGOS(V)
}
return "<unknown>";
#undef V
}
Expand Down
10 changes: 10 additions & 0 deletions test/common/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function extractMetadata(cert) {
subject: x509.subject,
};
}
exports.extractMetadata = extractMetadata;

// To compare two certificates, we can just compare serialNumber, issuer,
// and subject like X509_comp(). We can't just compare two strings because
Expand All @@ -219,3 +220,12 @@ exports.includesCert = function includesCert(certs, cert) {
};

exports.TestTLSSocket = TestTLSSocket;

// Dumps certs into a file to pass safely into test/fixtures/list-certs.js
exports.writeCerts = function writeCerts(certs, filename) {
const fs = require('fs');
for (const cert of certs) {
const x509 = new crypto.X509Certificate(cert);
fs.appendFileSync(filename, x509.toString());
}
};
19 changes: 19 additions & 0 deletions test/fixtures/list-certs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const assert = require('assert');
const EXPECTED_CERTS_PATH = process.env.EXPECTED_CERTS_PATH;
let expectedCerts = [];
if (EXPECTED_CERTS_PATH) {
const fs = require('fs');
const file = fs.readFileSync(EXPECTED_CERTS_PATH, 'utf-8');
const expectedCerts = file.split('-----END CERTIFICATE-----\n')
.filter(line => line.trim() !== '')
.map(line => line + '-----END CERTIFICATE-----\n');
}

const tls = require('tls');
const { includesCert, extractMetadata } = require('../common/tls');

const CERTS_TYPE = process.env.CERTS_TYPE || 'default';
const actualCerts = tls.getCACertificates(CERTS_TYPE);
for (const cert of expectedCerts) {
assert(includesCert(actualCerts, cert), 'Expected certificate not found: ' + JSON.stringify(extractMetadata(cert)));
}
40 changes: 40 additions & 0 deletions test/parallel/test-tls-off-thread-cert-loading-disabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
// This tests that when --use-openssl-ca is specified, no off-thread cert loading happens.

const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');
const assert = require('assert');

spawnSyncAndAssert(
process.execPath,
[ '--use-openssl-ca', fixtures.path('list-certs.js') ],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'crypto',
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'fake-startcom-root-cert.pem'),
CERTS_TYPE: 'default',
}
},
{
stderr(output) {
assert.doesNotMatch(
output,
/Started loading bundled root certificates off-thread/
);
assert.doesNotMatch(
output,
/Started loading extra root certificates off-thread/
);
assert.doesNotMatch(
output,
/Started loading system root certificates off-thread/
);
return true;
}
}
);
56 changes: 56 additions & 0 deletions test/parallel/test-tls-off-thread-cert-loading-system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

// This test verifies that system root certificates loading is loaded off-thread if
// --use-system-ca is used.

const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}
const tmpdir = require('../common/tmpdir');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { writeCerts } = require('../common/tls');
const tls = require('tls');

tmpdir.refresh();
writeCerts([
// Check that the extra cert is loaded.
fixtures.readKey('fake-startcom-root-cert.pem'),
// Check that the system certs are loaded.
...tls.getCACertificates('system'),
// Check that the bundled certs are loaded.
...tls.getCACertificates('bundled'),
], tmpdir.resolve('check-cert.pem'));

spawnSyncAndAssert(
process.execPath,
[ '--use-system-ca', '--use-bundled-ca', fixtures.path('list-certs.js') ],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'crypto',
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'fake-startcom-root-cert.pem'),
EXPECTED_CERTS_PATH: tmpdir.resolve('check-cert.pem'),
CERTS_TYPE: 'default',
}
},
{
stderr(output) {
assert.match(
output,
/Started loading bundled root certificates off-thread/
);
assert.match(
output,
/Started loading extra root certificates off-thread/
);
assert.match(
output,
/Started loading system root certificates off-thread/
);
return true;
}
}
);
54 changes: 54 additions & 0 deletions test/parallel/test-tls-off-thread-cert-loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

// This test verifies that when --use-bundled-ca is used (default to true in default builds),
// the loading of extra and bundled root certificates happens off the main thread.

const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}
const tmpdir = require('../common/tmpdir');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { writeCerts } = require('../common/tls');
const tls = require('tls');

tmpdir.refresh();
writeCerts([
// Check that the extra cert is loaded.
fixtures.readKey('fake-startcom-root-cert.pem'),
// Check that the bundled certs are loaded.
...tls.getCACertificates('bundled'),
], tmpdir.resolve('check-cert.pem'));

spawnSyncAndAssert(
process.execPath,
[ '--no-use-system-ca', '--use-bundled-ca', fixtures.path('list-certs.js') ],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'crypto',
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'fake-startcom-root-cert.pem'),
EXPECTED_CERTS_PATH: tmpdir.resolve('check-cert.pem'),
CERTS_TYPE: 'default',
}
},
{
stderr(output) {
assert.match(
output,
/Started loading bundled root certificates off-thread/
);
assert.match(
output,
/Started loading extra root certificates off-thread/
);
assert.doesNotMatch(
output,
/Started loading system root certificates off-thread/
);
return true;
}
}
);
1 change: 1 addition & 0 deletions test/sea/test-single-executable-application-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
} = require('../common/sea');

skipIfSingleExecutableIsNotSupported();
common.skipIfInspectorDisabled();

const configFile = tmpdir.resolve('sea-config.json');
const seaPrepBlob = tmpdir.resolve('sea-prep.blob');
Expand Down
Loading
Loading