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 missing extra ca in secure contexts
Fixes SecureContext missing NODE_EXTRA_CA_CERTS when SecureContext::AddCACert, SecureContext::AddCRL, or SecureContext::LoadPKCS12 are called. Fixes: nodejs#32010
- Loading branch information
Showing
4 changed files
with
183 additions
and
3 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 @@ | ||
// Certs in NODE_EXTRA_CA_CERTS are used for TLS peer validation | ||
|
||
'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(function() { | ||
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(function(s) { | ||
s.end('bye'); | ||
server.close(); | ||
})).listen(0, common.mustCall(function() { | ||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
PORT: this.address().port, | ||
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca2-cert.pem') | ||
}); | ||
|
||
fork(__filename, { env }).on('exit', common.mustCall(function(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,46 @@ | ||
// Certs in NODE_EXTRA_CA_CERTS are used for TLS peer validation | ||
|
||
'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(function() { | ||
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(function(s) { | ||
s.end('bye'); | ||
server.close(); | ||
})).listen(0, common.mustCall(function() { | ||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
PORT: this.address().port, | ||
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca2-cert.pem') | ||
}); | ||
|
||
fork(__filename, { env }).on('exit', common.mustCall(function(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 @@ | ||
// Certs in NODE_EXTRA_CA_CERTS are used for TLS peer validation | ||
|
||
'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(function() { | ||
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(function(s) { | ||
s.end('bye'); | ||
server.close(); | ||
})).listen(0, common.mustCall(function() { | ||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
PORT: this.address().port, | ||
NODE_EXTRA_CA_CERTS: fixtures.path('keys', 'ca2-cert.pem') | ||
}); | ||
|
||
fork(__filename, { env }).on('exit', common.mustCall(function(status) { | ||
// Client did not succeed in connecting | ||
assert.strictEqual(status, 0); | ||
})); | ||
})); |