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