| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3366e60 commit 8e2076a
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3600,6 +3600,18 @@ If `value` equals `'0'`, certificate validation is disabled for TLS connections. | |||
| 3600 | 3600 | This makes TLS, and HTTPS by extension, insecure. The use of this environment | |
| 3601 | 3601 | variable is strongly discouraged. | |
| 3602 | 3602 | ||
| 3603 | + ### `NODE_USE_SYSTEM_CA=1` | ||
| 3604 | + | ||
| 3605 | + <!-- YAML | ||
| 3606 | + added: REPLACEME | ||
| 3607 | + --> | ||
| 3608 | + | ||
| 3609 | + Node.js uses the trusted CA certificates present in the system store along with | ||
| 3610 | + the `--use-bundled-ca` option and the `NODE_EXTRA_CA_CERTS` environment variable. | ||
| 3611 | + | ||
| 3612 | + This can also be enabled using the [`--use-system-ca`][] command-line flag. | ||
| 3613 | + When both are set, `--use-system-ca` takes precedence. | ||
| 3614 | + | ||
| 3603 | 3615 | ### `NODE_V8_COVERAGE=dir` | |
| 3604 | 3616 | ||
| 3605 | 3617 | When set, Node.js will begin outputting [V8 JavaScript code coverage][] and | |
@@ -3933,6 +3945,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12 | |||
| 3933 | 3945 | [`--print`]: #-p---print-script | |
| 3934 | 3946 | [`--redirect-warnings`]: #--redirect-warningsfile | |
| 3935 | 3947 | [`--require`]: #-r---require-module | |
| 3948 | + [`--use-system-ca`]: #--use-system-ca | ||
| 3936 | 3949 | [`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage | |
| 3937 | 3950 | [`Atomics.wait()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait | |
| 3938 | 3951 | [`Buffer`]: buffer.md#class-buffer | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -809,6 +809,12 @@ When set to | |||
| 809 | 809 | .Ar 0 , | |
| 810 | 810 | TLS certificate validation is disabled. | |
| 811 | 811 | . | |
| 812 | + .It Ev NODE_USE_SYSTEM_CA | ||
| 813 | + Similar to | ||
| 814 | + .Fl -use-system-ca . | ||
| 815 | + Use the trusted CA certificates present in the system store, in addition to the certificates in the | ||
| 816 | + bundled Mozilla CA store and certificates from `NODE_EXTRA_CA_CERTS`. | ||
| 817 | + . | ||
| 812 | 818 | .It Ev NODE_V8_COVERAGE Ar dir | |
| 813 | 819 | When set, Node.js writes JavaScript code coverage information to | |
| 814 | 820 | .Ar dir . | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -912,6 +912,15 @@ static ExitCode InitializeNodeWithArgsInternal( | |||
| 912 | 912 | // default value. | |
| 913 | 913 | V8::SetFlagsFromString("--rehash-snapshot"); | |
| 914 | 914 | ||
| 915 | + #if HAVE_OPENSSL | ||
| 916 | + // TODO(joyeecheung): make this a per-env option and move the normalization | ||
| 917 | + // into HandleEnvOptions. | ||
| 918 | + std::string use_system_ca; | ||
| 919 | + if (credentials::SafeGetenv("NODE_USE_SYSTEM_CA", &use_system_ca) && | ||
| 920 | + use_system_ca == "1") { | ||
| 921 | + per_process::cli_options->use_system_ca = true; | ||
| 922 | + } | ||
| 923 | + #endif // HAVE_OPENSSL | ||
| 915 | 924 | HandleEnvOptions(per_process::cli_options->per_isolate->per_env); | |
| 916 | 925 | ||
| 917 | 926 | std::string node_options; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // This tests that NODE_USE_SYSTEM_CA environment variable works the same | ||
| 3 | + // as --use-system-ca flag by comparing certificate counts. | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + if (!common.hasCrypto) common.skip('missing crypto'); | ||
| 7 | + | ||
| 8 | + const tls = require('tls'); | ||
| 9 | + const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
| 10 | + | ||
| 11 | + const systemCerts = tls.getCACertificates('system'); | ||
| 12 | + if (systemCerts.length === 0) { | ||
| 13 | + common.skip('no system certificates available'); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + const { child: { stdout: expectedLength } } = spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 17 | + '--use-system-ca', | ||
| 18 | + '-p', | ||
| 19 | + `tls.getCACertificates('default').length`, | ||
| 20 | + ], { | ||
| 21 | + env: { ...process.env, NODE_USE_SYSTEM_CA: '0' }, | ||
| 22 | + }); | ||
| 23 | + | ||
| 24 | + spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 25 | + '-p', | ||
| 26 | + `assert.strictEqual(tls.getCACertificates('default').length, ${expectedLength.toString()})`, | ||
| 27 | + ], { | ||
| 28 | + env: { ...process.env, NODE_USE_SYSTEM_CA: '1' }, | ||
| 29 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,56 @@ | |||
| 1 | + // Env: NODE_USE_SYSTEM_CA=1 | ||
| 2 | + // Same as test-native-root-certs.mjs, just testing the environment variable instead of the flag. | ||
| 3 | + | ||
| 4 | + import * as common from '../common/index.mjs'; | ||
| 5 | + import assert from 'node:assert/strict'; | ||
| 6 | + import https from 'node:https'; | ||
| 7 | + import fixtures from '../common/fixtures.js'; | ||
| 8 | + import { it, beforeEach, afterEach, describe } from 'node:test'; | ||
| 9 | + import { once } from 'events'; | ||
| 10 | + | ||
| 11 | + if (!common.hasCrypto) { | ||
| 12 | + common.skip('requires crypto'); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + // To run this test, the system needs to be configured to trust | ||
| 16 | + // the CA certificate first (which needs an interactive GUI approval, e.g. TouchID): | ||
| 17 | + // see the README.md in this folder for instructions on how to do this. | ||
| 18 | + const handleRequest = (req, res) => { | ||
| 19 | + const path = req.url; | ||
| 20 | + switch (path) { | ||
| 21 | + case '/hello-world': | ||
| 22 | + res.writeHead(200); | ||
| 23 | + res.end('hello world\n'); | ||
| 24 | + break; | ||
| 25 | + default: | ||
| 26 | + assert(false, `Unexpected path: ${path}`); | ||
| 27 | + } | ||
| 28 | + }; | ||
| 29 | + | ||
| 30 | + describe('use-system-ca', function() { | ||
| 31 | + | ||
| 32 | + async function setupServer(key, cert) { | ||
| 33 | + const theServer = https.createServer({ | ||
| 34 | + key: fixtures.readKey(key), | ||
| 35 | + cert: fixtures.readKey(cert), | ||
| 36 | + }, handleRequest); | ||
| 37 | + theServer.listen(0); | ||
| 38 | + await once(theServer, 'listening'); | ||
| 39 | + | ||
| 40 | + return theServer; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + let server; | ||
| 44 | + | ||
| 45 | + beforeEach(async function() { | ||
| 46 | + server = await setupServer('agent8-key.pem', 'agent8-cert.pem'); | ||
| 47 | + }); | ||
| 48 | + | ||
| 49 | + it('trusts a valid root certificate', async function() { | ||
| 50 | + await fetch(`https://localhost:${server.address().port}/hello-world`); | ||
| 51 | + }); | ||
| 52 | + | ||
| 53 | + afterEach(async function() { | ||
| 54 | + server?.close(); | ||
| 55 | + }); | ||
| 56 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments