forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: load NODE_EXTRA_CA_CERTS at startup
This commit makes node load extra certificates at startup instead of first use. PR-URL: nodejs#23354 Fixes: nodejs#20434 Refs: nodejs#20432 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
Showing
3 changed files
with
96 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
// Flags: --expose-internals | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const tls = require('tls'); | ||
const fixtures = require('../common/fixtures'); | ||
const { internalBinding } = require('internal/test/binding'); | ||
const binding = internalBinding('crypto'); | ||
|
||
const { fork } = require('child_process'); | ||
|
||
// This test ensures that extra certificates are loaded at startup. | ||
if (process.argv[2] !== 'child') { | ||
if (process.env.CHILD_USE_EXTRA_CA_CERTS === 'yes') { | ||
assert.strictEqual(binding.isExtraRootCertsFileLoaded(), true); | ||
} else if (process.env.CHILD_USE_EXTRA_CA_CERTS === 'no') { | ||
assert.strictEqual(binding.isExtraRootCertsFileLoaded(), false); | ||
tls.createServer({}); | ||
assert.strictEqual(binding.isExtraRootCertsFileLoaded(), false); | ||
} | ||
} else { | ||
const NODE_EXTRA_CA_CERTS = fixtures.path('keys', 'ca1-cert.pem'); | ||
const extendsEnv = (obj) => Object.assign({}, process.env, obj); | ||
|
||
[ | ||
extendsEnv({ CHILD_USE_EXTRA_CA_CERTS: 'yes', NODE_EXTRA_CA_CERTS }), | ||
extendsEnv({ CHILD_USE_EXTRA_CA_CERTS: 'no' }), | ||
].forEach((processEnv) => { | ||
fork(__filename, ['child'], { env: processEnv }) | ||
.on('exit', common.mustCall((status) => { | ||
// client did not succeed in connecting | ||
assert.strictEqual(status, 0); | ||
})); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
const { fork } = require('child_process'); | ||
|
||
// This test ensures that trying to load extra certs won't throw even when | ||
// there is no crypto support, i.e., built with "./configure --without-ssl". | ||
if (process.argv[2] === 'child') { | ||
// exit | ||
} else { | ||
const NODE_EXTRA_CA_CERTS = fixtures.path('keys', 'ca1-cert.pem'); | ||
|
||
fork( | ||
__filename, | ||
['child'], | ||
{ env: Object.assign({}, process.env, { NODE_EXTRA_CA_CERTS }) }, | ||
).on('exit', common.mustCall(function(status) { | ||
// client did not succeed in connecting | ||
assert.strictEqual(status, 0); | ||
})); | ||
} |