From 0233cd30e6777f0b4655028aca0ab9d697801248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 20 Aug 2022 11:23:50 +0000 Subject: [PATCH] tls: use OpenSSL constant for client random size Avoid magic numbers in the code and use an OpenSSL constant instead. --- src/crypto/crypto_common.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index eab144cfdf663b..e47044be506a13 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -71,16 +71,19 @@ void LogSecret( const unsigned char* secret, size_t secretlen) { auto keylog_cb = SSL_CTX_get_keylog_callback(SSL_get_SSL_CTX(ssl.get())); - unsigned char crandom[32]; + // All supported versions of TLS/SSL fix the client random to the same size. + constexpr size_t kTlsClientRandomSize = SSL3_RANDOM_SIZE; + unsigned char crandom[kTlsClientRandomSize]; if (keylog_cb == nullptr || - SSL_get_client_random(ssl.get(), crandom, 32) != 32) { + SSL_get_client_random(ssl.get(), crandom, kTlsClientRandomSize) != + kTlsClientRandomSize) { return; } std::string line = name; - line += " " + StringBytes::hex_encode( - reinterpret_cast(crandom), 32); + line += " " + StringBytes::hex_encode(reinterpret_cast(crandom), + kTlsClientRandomSize); line += " " + StringBytes::hex_encode( reinterpret_cast(secret), secretlen); keylog_cb(ssl.get(), line.c_str());