Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions daemon/connect/TlsSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ bool TlsSocket::Start()
return false;
}

if (!m_cipher.empty() && !SSL_set_cipher_list(m_session.get(), m_cipher.c_str()))
if (!SetCipherSuite(m_cipher))
{
ReportError("Could not select cipher for TLS", false);
ReportError("Could not set cipher suite for SSL/TLS connection", false);
Close();
return false;
}
Expand Down Expand Up @@ -213,6 +213,30 @@ bool TlsSocket::Start()
return true;
}

bool TlsSocket::SetCipherSuite(std::string_view cipher)
{
if (cipher.empty())
{
return true;
}

// Try TLS 1.3 ciphers
if (SSL_set_ciphersuites(m_session.get(), cipher.data()))
{
return true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the legacy ciphers are not set, so they have the default value.

For example, when setting Server1.Cipher=TLS_AES_128_GCM_SHA256, I get :

Cipher Suites (28 suites)
    Cipher Suite: TLS_AES_128_GCM_SHA256 (0x1301)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (0xc02c)
    Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030)
    Cipher Suite: TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 (0x009f)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca9)
    Cipher Suite: TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca8)
    Cipher Suite: TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (0xccaa)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (0xc02b)
    Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f)
    Cipher Suite: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 (0x009e)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 (0xc024)
    Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (0xc028)
    Cipher Suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 (0x006b)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 (0xc023)
    Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (0xc027)
    Cipher Suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 (0x0067)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (0xc00a)
    Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (0xc014)
    Cipher Suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA (0x0039)
    Cipher Suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA (0xc009)
    Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (0xc013)
    Cipher Suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA (0x0033)
    Cipher Suite: TLS_RSA_WITH_AES_256_GCM_SHA384 (0x009d)
    Cipher Suite: TLS_RSA_WITH_AES_128_GCM_SHA256 (0x009c)
    Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA256 (0x003d)
    Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA256 (0x003c)
    Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA (0x0035)
    Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA (0x002f)

man SSL_set_ciphersuites has :

Items that are not recognized, because the corresponding ciphers are not compiled in or because they are mistyped, are simply ignored. Failure is only flagged if no ciphers could be collected at all.

So an option could be to always do both calls (and only fail if both return 0).
This would allow a list containing both TLS1.2 and TLS1.3 ciphers, with a small limitation : TLS1.3 ciphers will always be preferred, regardless of the order.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I’ll update the code.
Thanks for the suggestion.

}

ERR_clear_error();

// Try legacy ciphers (TLS 1.2 and below)
if (SSL_set_cipher_list(m_session.get(), cipher.data()))
{
return true;
}

return false;
}

bool TlsSocket::ValidateCert()
{
// verify a server certificate was presented during the negotiation
Expand Down
2 changes: 2 additions & 0 deletions daemon/connect/TlsSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class TlsSocket
static void InitX509Store(std::string_view certStore);
static OpenSSL::X509StorePtr m_X509Store;

bool SetCipherSuite(std::string_view cipher);

SOCKET m_socket;

std::string m_host;
Expand Down