-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
tls: replace forEach with for #15053
Closed
Closed
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 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 |
---|---|---|
|
@@ -73,50 +73,60 @@ exports.createSecureContext = function createSecureContext(options, context) { | |
|
||
var c = new SecureContext(options.secureProtocol, secureOptions, context); | ||
var i; | ||
var val; | ||
|
||
if (context) return c; | ||
|
||
// NOTE: It's important to add CA before the cert to be able to load | ||
// cert's issuer in C++ code. | ||
if (options.ca) { | ||
if (Array.isArray(options.ca)) { | ||
options.ca.forEach((ca) => { | ||
validateKeyCert(ca, 'ca'); | ||
c.context.addCACert(ca); | ||
}); | ||
var ca = options.ca; | ||
if (ca !== undefined) { | ||
if (Array.isArray(ca)) { | ||
for (i = 0; i < ca.length; ++i) { | ||
val = ca[i]; | ||
validateKeyCert(val, 'ca'); | ||
c.context.addCACert(val); | ||
} | ||
} else { | ||
validateKeyCert(options.ca, 'ca'); | ||
c.context.addCACert(options.ca); | ||
validateKeyCert(ca, 'ca'); | ||
c.context.addCACert(ca); | ||
} | ||
} else { | ||
c.context.addRootCerts(); | ||
} | ||
|
||
if (options.cert) { | ||
if (Array.isArray(options.cert)) { | ||
options.cert.forEach((cert) => { | ||
validateKeyCert(cert, 'cert'); | ||
c.context.setCert(cert); | ||
}); | ||
var cert = options.cert; | ||
if (cert !== undefined) { | ||
if (Array.isArray(cert)) { | ||
for (i = 0; i < cert.length; ++i) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
val = cert[i]; | ||
validateKeyCert(val, 'cert'); | ||
c.context.setCert(val); | ||
} | ||
} else { | ||
validateKeyCert(options.cert, 'cert'); | ||
c.context.setCert(options.cert); | ||
validateKeyCert(cert, 'cert'); | ||
c.context.setCert(cert); | ||
} | ||
} | ||
|
||
// NOTE: It is important to set the key after the cert. | ||
// `ssl_set_pkey` returns `0` when the key does not match the cert, but | ||
// `ssl_set_cert` returns `1` and nullifies the key in the SSL structure | ||
// which leads to the crash later on. | ||
if (options.key) { | ||
if (Array.isArray(options.key)) { | ||
options.key.forEach((k) => { | ||
validateKeyCert(k.pem || k, 'key'); | ||
c.context.setKey(k.pem || k, k.passphrase || options.passphrase); | ||
}); | ||
var key = options.key; | ||
var passphrase = options.passphrase; | ||
if (key !== undefined) { | ||
if (Array.isArray(key)) { | ||
for (i = 0; i < key.length; ++i) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
val = key[i]; | ||
// eslint-disable-next-line eqeqeq | ||
const pem = (val != undefined && val.pem !== undefined ? val.pem : val); | ||
validateKeyCert(pem, 'key'); | ||
c.context.setKey(pem, val.passphrase || passphrase); | ||
} | ||
} else { | ||
validateKeyCert(options.key, 'key'); | ||
c.context.setKey(options.key, options.passphrase); | ||
validateKeyCert(key, 'key'); | ||
c.context.setKey(key, passphrase); | ||
} | ||
} | ||
|
||
|
@@ -152,7 +162,6 @@ exports.createSecureContext = function createSecureContext(options, context) { | |
|
||
if (options.pfx) { | ||
var pfx = options.pfx; | ||
var passphrase = options.passphrase; | ||
|
||
if (!crypto) | ||
crypto = require('crypto'); | ||
|
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.
nit:
i
andval
should be lowered into this scope.