-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
src: fix off-thread cert loading in bundled cert mode #60764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joyeecheung
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
joyeecheung:fix-off-thread-crypto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,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
40
test/parallel/test-tls-off-thread-cert-loading-disabled.js
This file contains hidden or 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'; | ||
| // 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; | ||
| } | ||
| } | ||
| ); |
This file contains hidden or 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,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; | ||
| } | ||
| } | ||
| ); |
This file contains hidden or 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,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; | ||
| } | ||
| } | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a comment to this line?