Skip to content

Commit c34c569

Browse files
sam-githubtargos
authored andcommittedJan 28, 2019
tls: make ossl 1.1.1 cipher list throw error
Make OpenSSL 1.1.1 error during cipher list setting if it would have errored with OpenSSL 1.1.0. Can be dropped after our OpenSSL fixes this upstream. See: openssl/openssl#7759 PR-URL: #25381 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Shigeki Ohtsu <ohtsu@ohtsu.org> Backport-PR-URL: #25688
1 parent d4ec110 commit c34c569

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed
 

‎src/node_crypto.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,26 @@ void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) {
919919

920920
THROW_AND_RETURN_IF_NOT_STRING(env, args[0], "Ciphers");
921921

922+
// Note: set_ciphersuites() is for TLSv1.3 and was introduced in openssl
923+
// 1.1.1, set_cipher_list() is for TLSv1.2 and earlier.
924+
//
925+
// In openssl 1.1.0, set_cipher_list() would error if it resulted in no
926+
// TLSv1.2 (and earlier) cipher suites, and there is no TLSv1.3 support.
927+
//
928+
// In openssl 1.1.1, set_cipher_list() will not error if it results in no
929+
// TLSv1.2 cipher suites if there are any TLSv1.3 cipher suites, which there
930+
// are by default. There will be an error later, during the handshake, but
931+
// that results in an async error event, rather than a sync error thrown,
932+
// which is a semver-major change for the tls API.
933+
//
934+
// Since we don't currently support TLSv1.3, work around this by removing the
935+
// TLSv1.3 cipher suites, so we get backwards compatible synchronous errors.
922936
const node::Utf8Value ciphers(args.GetIsolate(), args[0]);
923-
if (!SSL_CTX_set_cipher_list(sc->ctx_.get(), *ciphers)) {
937+
if (
938+
#ifdef TLS1_3_VERSION
939+
!SSL_CTX_set_ciphersuites(sc->ctx_.get(), "") ||
940+
#endif
941+
!SSL_CTX_set_cipher_list(sc->ctx_.get(), *ciphers)) {
924942
unsigned long err = ERR_get_error(); // NOLINT(runtime/int)
925943
if (!err) {
926944
return env->ThrowError("Failed to set ciphers");

0 commit comments

Comments
 (0)
Please sign in to comment.