@@ -148,6 +148,31 @@ function configSecureContext(context, options = kEmptyObject, name = 'options')
148148 ticketKeys,
149149 } = options ;
150150
151+ // Set the cipher list and cipher suite before anything else because
152+ // @SECLEVEL =<n> changes the security level and that affects subsequent
153+ // operations.
154+ if ( ciphers !== undefined && ciphers !== null )
155+ validateString ( ciphers , `${ name } .ciphers` ) ;
156+
157+ // Work around an OpenSSL API quirk. cipherList is for TLSv1.2 and below,
158+ // cipherSuites is for TLSv1.3 (and presumably any later versions). TLSv1.3
159+ // cipher suites all have a standard name format beginning with TLS_, so split
160+ // the ciphers and pass them to the appropriate API.
161+ const {
162+ cipherList,
163+ cipherSuites,
164+ } = processCiphers ( ciphers , `${ name } .ciphers` ) ;
165+
166+ if ( cipherSuites !== '' )
167+ context . setCipherSuites ( cipherSuites ) ;
168+ context . setCiphers ( cipherList ) ;
169+
170+ if ( cipherList === '' &&
171+ context . getMinProto ( ) < TLS1_3_VERSION &&
172+ context . getMaxProto ( ) > TLS1_2_VERSION ) {
173+ context . setMinProto ( TLS1_3_VERSION ) ;
174+ }
175+
151176 // Add CA before the cert to be able to load cert's issuer in C++ code.
152177 // NOTE(@jasnell): ca, cert, and key are permitted to be falsy, so do not
153178 // change the checks to !== undefined checks.
@@ -218,28 +243,6 @@ function configSecureContext(context, options = kEmptyObject, name = 'options')
218243 }
219244 }
220245
221- if ( ciphers !== undefined && ciphers !== null )
222- validateString ( ciphers , `${ name } .ciphers` ) ;
223-
224- // Work around an OpenSSL API quirk. cipherList is for TLSv1.2 and below,
225- // cipherSuites is for TLSv1.3 (and presumably any later versions). TLSv1.3
226- // cipher suites all have a standard name format beginning with TLS_, so split
227- // the ciphers and pass them to the appropriate API.
228- const {
229- cipherList,
230- cipherSuites,
231- } = processCiphers ( ciphers , `${ name } .ciphers` ) ;
232-
233- if ( cipherSuites !== '' )
234- context . setCipherSuites ( cipherSuites ) ;
235- context . setCiphers ( cipherList ) ;
236-
237- if ( cipherList === '' &&
238- context . getMinProto ( ) < TLS1_3_VERSION &&
239- context . getMaxProto ( ) > TLS1_2_VERSION ) {
240- context . setMinProto ( TLS1_3_VERSION ) ;
241- }
242-
243246 validateString ( ecdhCurve , `${ name } .ecdhCurve` ) ;
244247 context . setECDHCurve ( ecdhCurve ) ;
245248
0 commit comments