| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4079fc4 commit a11ff31
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,7 @@ function validateKeyOrCertOption(name, value) { | |||
| 83 | 83 | ||
| 84 | 84 | function setKey(context, key, passphrase, name) { | |
| 85 | 85 | validateKeyOrCertOption(`${name}.key`, key); | |
| 86 | - if (passphrase != null) | ||
| 86 | + if (passphrase !== undefined && passphrase !== null) | ||
| 87 | 87 | validateString(passphrase, `${name}.passphrase`); | |
| 88 | 88 | context.setKey(key, passphrase); | |
| 89 | 89 | } | |
@@ -160,16 +160,20 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 160 | 160 | if (ArrayIsArray(key)) { | |
| 161 | 161 | for (let i = 0; i < key.length; ++i) { | |
| 162 | 162 | const val = key[i]; | |
| 163 | - // eslint-disable-next-line eqeqeq | ||
| 164 | - const pem = (val != undefined && val.pem !== undefined ? val.pem : val); | ||
| 165 | - setKey(context, pem, val.passphrase || passphrase, name); | ||
| 163 | + const pem = ( | ||
| 164 | + val !== undefined && val !== null && | ||
| 165 | + val.pem !== undefined ? val.pem : val); | ||
| 166 | + const pass = ( | ||
| 167 | + val !== undefined && val !== null && | ||
| 168 | + val.passphrase !== undefined ? val.passphrase : passphrase); | ||
| 169 | + setKey(context, pem, pass, name); | ||
| 166 | 170 | } | |
| 167 | 171 | } else { | |
| 168 | 172 | setKey(context, key, passphrase, name); | |
| 169 | 173 | } | |
| 170 | 174 | } | |
| 171 | 175 | ||
| 172 | - if (sigalgs !== undefined) { | ||
| 176 | + if (sigalgs !== undefined && sigalgs !== null) { | ||
| 173 | 177 | validateString(sigalgs, `${name}.sigalgs`); | |
| 174 | 178 | ||
| 175 | 179 | if (sigalgs === '') | |
@@ -178,8 +182,8 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 178 | 182 | context.setSigalgs(sigalgs); | |
| 179 | 183 | } | |
| 180 | 184 | ||
| 181 | - if (privateKeyIdentifier !== undefined) { | ||
| 182 | - if (privateKeyEngine === undefined) { | ||
| 185 | + if (privateKeyIdentifier !== undefined && privateKeyIdentifier !== null) { | ||
| 186 | + if (privateKeyEngine === undefined || privateKeyEngine === null) { | ||
| 183 | 187 | // Engine is required when privateKeyIdentifier is present | |
| 184 | 188 | throw new ERR_INVALID_ARG_VALUE(`${name}.privateKeyEngine`, | |
| 185 | 189 | privateKeyEngine); | |
@@ -198,16 +202,16 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 198 | 202 | throw new ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED(); | |
| 199 | 203 | } else if (typeof privateKeyIdentifier !== 'string') { | |
| 200 | 204 | throw new ERR_INVALID_ARG_TYPE(`${name}.privateKeyIdentifier`, | |
| 201 | - ['string', 'undefined'], | ||
| 205 | + ['string', 'null', 'undefined'], | ||
| 202 | 206 | privateKeyIdentifier); | |
| 203 | 207 | } else { | |
| 204 | 208 | throw new ERR_INVALID_ARG_TYPE(`${name}.privateKeyEngine`, | |
| 205 | - ['string', 'undefined'], | ||
| 209 | + ['string', 'null', 'undefined'], | ||
| 206 | 210 | privateKeyEngine); | |
| 207 | 211 | } | |
| 208 | 212 | } | |
| 209 | 213 | ||
| 210 | - if (ciphers != null) | ||
| 214 | + if (ciphers !== undefined && ciphers !== null) | ||
| 211 | 215 | validateString(ciphers, `${name}.ciphers`); | |
| 212 | 216 | ||
| 213 | 217 | // Work around an OpenSSL API quirk. cipherList is for TLSv1.2 and below, | |
@@ -237,14 +241,14 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 237 | 241 | validateString(ecdhCurve, `${name}.ecdhCurve`); | |
| 238 | 242 | context.setECDHCurve(ecdhCurve); | |
| 239 | 243 | ||
| 240 | - if (dhparam !== undefined) { | ||
| 244 | + if (dhparam !== undefined && dhparam !== null) { | ||
| 241 | 245 | validateKeyOrCertOption(`${name}.dhparam`, dhparam); | |
| 242 | 246 | const warning = context.setDHParam(dhparam); | |
| 243 | 247 | if (warning) | |
| 244 | 248 | process.emitWarning(warning, 'SecurityWarning'); | |
| 245 | 249 | } | |
| 246 | 250 | ||
| 247 | - if (crl !== undefined) { | ||
| 251 | + if (crl !== undefined && crl !== null) { | ||
| 248 | 252 | if (ArrayIsArray(crl)) { | |
| 249 | 253 | for (const val of crl) { | |
| 250 | 254 | validateKeyOrCertOption(`${name}.crl`, val); | |
@@ -256,17 +260,17 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 256 | 260 | } | |
| 257 | 261 | } | |
| 258 | 262 | ||
| 259 | - if (sessionIdContext !== undefined) { | ||
| 263 | + if (sessionIdContext !== undefined && sessionIdContext !== null) { | ||
| 260 | 264 | validateString(sessionIdContext, `${name}.sessionIdContext`); | |
| 261 | 265 | context.setSessionIdContext(sessionIdContext); | |
| 262 | 266 | } | |
| 263 | 267 | ||
| 264 | - if (pfx !== undefined) { | ||
| 268 | + if (pfx !== undefined && pfx !== null) { | ||
| 265 | 269 | if (ArrayIsArray(pfx)) { | |
| 266 | 270 | ArrayPrototypeForEach(pfx, (val) => { | |
| 267 | 271 | const raw = val.buf ? val.buf : val; | |
| 268 | 272 | const pass = val.passphrase || passphrase; | |
| 269 | - if (pass !== undefined) { | ||
| 273 | + if (pass !== undefined && pass !== null) { | ||
| 270 | 274 | context.loadPKCS12(toBuf(raw), toBuf(pass)); | |
| 271 | 275 | } else { | |
| 272 | 276 | context.loadPKCS12(toBuf(raw)); | |
@@ -284,13 +288,13 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 284 | 288 | throw new ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED(); | |
| 285 | 289 | else | |
| 286 | 290 | context.setClientCertEngine(clientCertEngine); | |
| 287 | - } else if (clientCertEngine !== undefined) { | ||
| 291 | + } else if (clientCertEngine !== undefined && clientCertEngine !== null) { | ||
| 288 | 292 | throw new ERR_INVALID_ARG_TYPE(`${name}.clientCertEngine`, | |
| 289 | 293 | ['string', 'null', 'undefined'], | |
| 290 | 294 | clientCertEngine); | |
| 291 | 295 | } | |
| 292 | 296 | ||
| 293 | - if (ticketKeys !== undefined) { | ||
| 297 | + if (ticketKeys !== undefined && ticketKeys !== null) { | ||
| 294 | 298 | if (!isArrayBufferView(ticketKeys)) { | |
| 295 | 299 | throw new ERR_INVALID_ARG_TYPE( | |
| 296 | 300 | `${name}.ticketKeys`, | |
@@ -306,7 +310,7 @@ function configSecureContext(context, options = {}, name = 'options') { | |||
| 306 | 310 | context.setTicketKeys(ticketKeys); | |
| 307 | 311 | } | |
| 308 | 312 | ||
| 309 | - if (sessionTimeout !== undefined) { | ||
| 313 | + if (sessionTimeout !== undefined && sessionTimeout !== null) { | ||
| 310 | 314 | validateInt32(sessionTimeout, `${name}.sessionTimeout`); | |
| 311 | 315 | context.setSessionTimeout(sessionTimeout); | |
| 312 | 316 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,3 +23,31 @@ connect({ | |||
| 23 | 23 | assert.ifError(err); | |
| 24 | 24 | return cleanup(); | |
| 25 | 25 | }); | |
| 26 | + | ||
| 27 | + connect({ | ||
| 28 | + client: { | ||
| 29 | + servername: 'agent1', | ||
| 30 | + secureContext: tls.createSecureContext({ | ||
| 31 | + ca: keys.agent1.ca, | ||
| 32 | + ciphers: null, | ||
| 33 | + clientCertEngine: null, | ||
| 34 | + crl: null, | ||
| 35 | + dhparam: null, | ||
| 36 | + passphrase: null, | ||
| 37 | + pfx: null, | ||
| 38 | + privateKeyIdentifier: null, | ||
| 39 | + privateKeyEngine: null, | ||
| 40 | + sessionIdContext: null, | ||
| 41 | + sessionTimeout: null, | ||
| 42 | + sigalgs: null, | ||
| 43 | + ticketKeys: null, | ||
| 44 | + }), | ||
| 45 | + }, | ||
| 46 | + server: { | ||
| 47 | + cert: keys.agent1.cert, | ||
| 48 | + key: keys.agent1.key, | ||
| 49 | + }, | ||
| 50 | + }, function(err, pair, cleanup) { | ||
| 51 | + assert.ifError(err); | ||
| 52 | + return cleanup(); | ||
| 53 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments