@@ -83,7 +83,7 @@ function validateKeyOrCertOption(name, value) {
8383
8484function setKey ( context , key , passphrase , name ) {
8585validateKeyOrCertOption ( `${ name } .key` , key ) ;
86- if ( passphrase != null )
86+ if ( passphrase !== undefined && passphrase !== null )
8787validateString ( passphrase , `${ name } .passphrase` ) ;
8888context . setKey ( key , passphrase ) ;
8989}
@@ -160,16 +160,20 @@ function configSecureContext(context, options = {}, name = 'options') {
160160if ( ArrayIsArray ( key ) ) {
161161for ( let i = 0 ; i < key . length ; ++ i ) {
162162const 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 ) ;
166170}
167171} else {
168172setKey ( context , key , passphrase , name ) ;
169173}
170174}
171175
172- if ( sigalgs !== undefined ) {
176+ if ( sigalgs !== undefined && sigalgs !== null ) {
173177validateString ( sigalgs , `${ name } .sigalgs` ) ;
174178
175179if ( sigalgs === '' )
@@ -178,8 +182,8 @@ function configSecureContext(context, options = {}, name = 'options') {
178182context . setSigalgs ( sigalgs ) ;
179183}
180184
181- if ( privateKeyIdentifier !== undefined ) {
182- if ( privateKeyEngine === undefined ) {
185+ if ( privateKeyIdentifier !== undefined && privateKeyIdentifier !== null ) {
186+ if ( privateKeyEngine === undefined || privateKeyEngine === null ) {
183187// Engine is required when privateKeyIdentifier is present
184188throw new ERR_INVALID_ARG_VALUE ( `${ name } .privateKeyEngine` ,
185189privateKeyEngine ) ;
@@ -198,16 +202,16 @@ function configSecureContext(context, options = {}, name = 'options') {
198202throw new ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED ( ) ;
199203} else if ( typeof privateKeyIdentifier !== 'string' ) {
200204throw new ERR_INVALID_ARG_TYPE ( `${ name } .privateKeyIdentifier` ,
201- [ 'string' , 'undefined' ] ,
205+ [ 'string' , 'null' , ' undefined'] ,
202206privateKeyIdentifier ) ;
203207} else {
204208throw new ERR_INVALID_ARG_TYPE ( `${ name } .privateKeyEngine` ,
205- [ 'string' , 'undefined' ] ,
209+ [ 'string' , 'null' , ' undefined'] ,
206210privateKeyEngine ) ;
207211}
208212}
209213
210- if ( ciphers != null )
214+ if ( ciphers !== undefined && ciphers !== null )
211215validateString ( ciphers , `${ name } .ciphers` ) ;
212216
213217// Work around an OpenSSL API quirk. cipherList is for TLSv1.2 and below,
@@ -237,14 +241,14 @@ function configSecureContext(context, options = {}, name = 'options') {
237241validateString ( ecdhCurve , `${ name } .ecdhCurve` ) ;
238242context . setECDHCurve ( ecdhCurve ) ;
239243
240- if ( dhparam !== undefined ) {
244+ if ( dhparam !== undefined && dhparam !== null ) {
241245validateKeyOrCertOption ( `${ name } .dhparam` , dhparam ) ;
242246const warning = context . setDHParam ( dhparam ) ;
243247if ( warning )
244248process . emitWarning ( warning , 'SecurityWarning' ) ;
245249}
246250
247- if ( crl !== undefined ) {
251+ if ( crl !== undefined && crl !== null ) {
248252if ( ArrayIsArray ( crl ) ) {
249253for ( const val of crl ) {
250254validateKeyOrCertOption ( `${ name } .crl` , val ) ;
@@ -256,17 +260,17 @@ function configSecureContext(context, options = {}, name = 'options') {
256260}
257261}
258262
259- if ( sessionIdContext !== undefined ) {
263+ if ( sessionIdContext !== undefined && sessionIdContext !== null ) {
260264validateString ( sessionIdContext , `${ name } .sessionIdContext` ) ;
261265context . setSessionIdContext ( sessionIdContext ) ;
262266}
263267
264- if ( pfx !== undefined ) {
268+ if ( pfx !== undefined && pfx !== null ) {
265269if ( ArrayIsArray ( pfx ) ) {
266270ArrayPrototypeForEach ( pfx , ( val ) => {
267271const raw = val . buf ? val . buf : val ;
268272const pass = val . passphrase || passphrase ;
269- if ( pass !== undefined ) {
273+ if ( pass !== undefined && pass !== null ) {
270274context . loadPKCS12 ( toBuf ( raw ) , toBuf ( pass ) ) ;
271275} else {
272276context . loadPKCS12 ( toBuf ( raw ) ) ;
@@ -284,13 +288,13 @@ function configSecureContext(context, options = {}, name = 'options') {
284288throw new ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED ( ) ;
285289else
286290context . setClientCertEngine ( clientCertEngine ) ;
287- } else if ( clientCertEngine !== undefined ) {
291+ } else if ( clientCertEngine !== undefined && clientCertEngine !== null ) {
288292throw new ERR_INVALID_ARG_TYPE ( `${ name } .clientCertEngine` ,
289293[ 'string' , 'null' , 'undefined' ] ,
290294clientCertEngine ) ;
291295}
292296
293- if ( ticketKeys !== undefined ) {
297+ if ( ticketKeys !== undefined && ticketKeys !== null ) {
294298if ( ! isArrayBufferView ( ticketKeys ) ) {
295299throw new ERR_INVALID_ARG_TYPE (
296300`${ name } .ticketKeys` ,
@@ -306,7 +310,7 @@ function configSecureContext(context, options = {}, name = 'options') {
306310context . setTicketKeys ( ticketKeys ) ;
307311}
308312
309- if ( sessionTimeout !== undefined ) {
313+ if ( sessionTimeout !== undefined && sessionTimeout !== null ) {
310314validateInt32 ( sessionTimeout , `${ name } .sessionTimeout` ) ;
311315context . setSessionTimeout ( sessionTimeout ) ;
312316}
0 commit comments