Skip to content

Commit 3fa0916

Browse files
allow empty lists in SSL_CTX_set_ciphersuites (aws#1511)
MySQL deprecated the usage of weaker ciphers in their test suite. This brought an additional gap to light, where OpenSSL allows the setting of empty strings in the Ciphersuite string configuration. This is known behavior since 1.1.1 and still exists today. I've reconfigured the behavior for `SSL_[CTX]_set_cipher_list` which is our OpenSSL compat layer, but kept the same behavior for `SSL_[CTX]_set_strict_cipher_list`.
1 parent dd247e2 commit 3fa0916

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

include/openssl/ssl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,10 @@ OPENSSL_EXPORT int SSL_CTX_set_strict_cipher_list(SSL_CTX *ctx,
16911691
// |str| as a cipher string. It returns one on success and zero on failure.
16921692
//
16931693
// Prefer to use |SSL_CTX_set_strict_cipher_list|. This function tolerates
1694-
// garbage inputs, unless an empty cipher list results.
1694+
// garbage inputs, unless an empty cipher list results. However, an empty
1695+
// string which also results in an empty cipher list, is allowed. This
1696+
// behavior is strongly advised against and only meant for OpenSSL
1697+
// compatibility.
16951698
//
16961699
// Note: this API only sets the TLSv1.2 and below ciphers.
16971700
// Use |SSL_CTX_set_ciphersuites| to configure TLS 1.3 specific ciphers.
@@ -1711,7 +1714,9 @@ OPENSSL_EXPORT int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str);
17111714
// a cipher string. It returns one on success and zero on failure.
17121715
//
17131716
// Prefer to use |SSL_set_strict_cipher_list|. This function tolerates garbage
1714-
// inputs, unless an empty cipher list results.
1717+
// inputs, unless an empty cipher list results. However, an empty string which
1718+
// also results in an empty cipher list, is allowed. This behavior is strongly
1719+
// advised against and only meant for OpenSSL compatibility.
17151720
OPENSSL_EXPORT int SSL_set_cipher_list(SSL *ssl, const char *str);
17161721

17171722
// SSL_CTX_get_ciphers returns the cipher list for |ctx|, in order of

ssl/ssl_cipher.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,9 +1358,11 @@ bool ssl_create_cipher_list(UniquePtr<SSLCipherPreferenceList> *out_cipher_list,
13581358

13591359
*out_cipher_list = std::move(pref_list);
13601360

1361-
// Configuring an empty cipher list is an error but still updates the
1362-
// output.
1363-
if (sk_SSL_CIPHER_num((*out_cipher_list)->ciphers.get()) == 0) {
1361+
// Configuring an empty cipher list is an error when |strict| is true, but
1362+
// still updates the output. When otherwise, OpenSSL explicitly allows an
1363+
// empty list.
1364+
if ((strict || (*rule_str != '\0')) &&
1365+
sk_SSL_CIPHER_num((*out_cipher_list)->ciphers.get()) == 0) {
13641366
OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
13651367
return false;
13661368
}

ssl/ssl_test.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,6 @@ static const char *kBadRules[] = {
549549
"[+RSA]",
550550
// Unknown directive.
551551
"@BOGUS",
552-
// Empty cipher lists error at SSL_CTX_set_cipher_list.
553-
"",
554552
"BOGUS",
555553
// COMPLEMENTOFDEFAULT is empty.
556554
"COMPLEMENTOFDEFAULT",
@@ -5758,12 +5756,20 @@ TEST(SSLTest, EmptyCipherList) {
57585756
// Initially, the cipher list is not empty.
57595757
EXPECT_NE(0u, sk_SSL_CIPHER_num(SSL_CTX_get_ciphers(ctx.get())));
57605758

5761-
// Configuring the empty cipher list fails.
5762-
EXPECT_FALSE(SSL_CTX_set_cipher_list(ctx.get(), ""));
5763-
ERR_clear_error();
5759+
// Configuring the empty cipher list with |SSL_CTX_set_cipher_list|
5760+
// succeeds.
5761+
EXPECT_TRUE(SSL_CTX_set_cipher_list(ctx.get(), ""));
5762+
// The cipher list is updated to empty.
5763+
EXPECT_EQ(0u, sk_SSL_CIPHER_num(SSL_CTX_get_ciphers(ctx.get())));
5764+
5765+
// Configuring the empty cipher list with |SSL_CTX_set_ciphersuites|
5766+
// also succeeds.
5767+
EXPECT_TRUE(SSL_CTX_set_ciphersuites(ctx.get(), ""));
5768+
EXPECT_EQ(0u, sk_SSL_CIPHER_num(SSL_CTX_get_ciphers(ctx.get())));
57645769

5765-
// Configuring the empty cipher list fails.
5766-
EXPECT_FALSE(SSL_CTX_set_ciphersuites(ctx.get(), ""));
5770+
// Configuring the empty cipher list with |SSL_CTX_set_strict_cipher_list|
5771+
// fails.
5772+
EXPECT_FALSE(SSL_CTX_set_strict_cipher_list(ctx.get(), ""));
57675773
ERR_clear_error();
57685774

57695775
// But the cipher list is still updated to empty.

0 commit comments

Comments
 (0)