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.
src: fix CAs missing from secure contexts
Adds CAs from NODE_EXTRA_CA_CERTS to root_certs_vector in node_crypto.cc so that the extra certificates are always added to SecureContext instances. tls.rootCertificates restored to previous behavior of returning built-in Node.js certificates when --openssl-use-def-ca-store CLI option is set. Fixes: nodejs#32229 Fixes: nodejs#32010 Refs: nodejs#32075
- Loading branch information
1 parent
498415b
commit 1b0f50b
Showing
4 changed files
with
177 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,55 @@ | ||
'use strict'; | ||
|
||
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 { fork } = require('child_process'); | ||
|
||
if (process.env.CHILD) { | ||
const copts = { | ||
port: process.env.PORT, | ||
checkServerIdentity: common.mustCall() | ||
}; | ||
|
||
// New secure contexts have the well-known root CAs. | ||
copts.secureContext = tls.createSecureContext(); | ||
|
||
// Explicit calls to addCACert() add to the root certificates, | ||
// instead of replacing, so connection still succeeds. | ||
copts.secureContext.context.addCACert( | ||
fixtures.readKey('ca1-cert.pem') | ||
); | ||
|
||
const client = tls.connect(copts, common.mustCall(() => { | ||
client.end('hi'); | ||
})); | ||
|
||
return; | ||
} | ||
|
||
const options = { | ||
key: fixtures.readKey('agent3-key.pem'), | ||
cert: fixtures.readKey('agent3-cert.pem') | ||
}; | ||
|
||
const server = tls.createServer(options, common.mustCall((socket) => { | ||
socket.end('bye'); | ||
server.close(); | ||
})).listen(0, common.mustCall(() => { | ||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
PORT: server.address().port, | ||
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca2-cert.pem') | ||
}); | ||
|
||
fork(__filename, { env }).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,47 @@ | ||
'use strict'; | ||
|
||
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 { fork } = require('child_process'); | ||
|
||
if (process.env.CHILD) { | ||
const copts = { | ||
port: process.env.PORT, | ||
checkServerIdentity: common.mustCall(), | ||
crl: fixtures.readKey('ca2-crl.pem') | ||
}; | ||
|
||
const client = tls.connect(copts, common.mustCall(() => { | ||
client.end('hi'); | ||
})); | ||
|
||
return; | ||
} | ||
|
||
const options = { | ||
key: fixtures.readKey('agent3-key.pem'), | ||
cert: fixtures.readKey('agent3-cert.pem') | ||
}; | ||
|
||
const server = tls.createServer(options, common.mustCall((socket) => { | ||
socket.end('bye'); | ||
server.close(); | ||
})).listen(0, common.mustCall(() => { | ||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
PORT: server.address().port, | ||
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca2-cert.pem') | ||
}); | ||
|
||
fork(__filename, { env }).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,48 @@ | ||
'use strict'; | ||
|
||
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 { fork } = require('child_process'); | ||
|
||
if (process.env.CHILD) { | ||
const copts = { | ||
port: process.env.PORT, | ||
checkServerIdentity: common.mustCall(), | ||
pfx: fixtures.readKey('agent1.pfx'), | ||
passphrase: 'sample' | ||
}; | ||
|
||
const client = tls.connect(copts, common.mustCall(() => { | ||
client.end('hi'); | ||
})); | ||
|
||
return; | ||
} | ||
|
||
const options = { | ||
key: fixtures.readKey('agent3-key.pem'), | ||
cert: fixtures.readKey('agent3-cert.pem') | ||
}; | ||
|
||
const server = tls.createServer(options, common.mustCall((socket) => { | ||
socket.end('bye'); | ||
server.close(); | ||
})).listen(0, common.mustCall(() => { | ||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
PORT: server.address().port, | ||
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca2-cert.pem') | ||
}); | ||
|
||
fork(__filename, { env }).on('exit', common.mustCall((status) => { | ||
// Client did not succeed in connecting | ||
assert.strictEqual(status, 0); | ||
})); | ||
})); |