Skip to content

Commit c35a071

Browse files
tniessenjuanarbol
authored andcommitted
tls: use OpenSSL constant for client random size
Avoid magic numbers in the code and use an OpenSSL constant instead. PR-URL: #44305 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 2f3502f commit c35a071

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/crypto/crypto_common.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ void LogSecret(
6868
const unsigned char* secret,
6969
size_t secretlen) {
7070
auto keylog_cb = SSL_CTX_get_keylog_callback(SSL_get_SSL_CTX(ssl.get()));
71-
unsigned char crandom[32];
71+
// All supported versions of TLS/SSL fix the client random to the same size.
72+
constexpr size_t kTlsClientRandomSize = SSL3_RANDOM_SIZE;
73+
unsigned char crandom[kTlsClientRandomSize];
7274

7375
if (keylog_cb == nullptr ||
74-
SSL_get_client_random(ssl.get(), crandom, 32) != 32) {
76+
SSL_get_client_random(ssl.get(), crandom, kTlsClientRandomSize) !=
77+
kTlsClientRandomSize) {
7578
return;
7679
}
7780

7881
std::string line = name;
79-
line += " " + StringBytes::hex_encode(
80-
reinterpret_cast<const char*>(crandom), 32);
82+
line += " " + StringBytes::hex_encode(reinterpret_cast<const char*>(crandom),
83+
kTlsClientRandomSize);
8184
line += " " + StringBytes::hex_encode(
8285
reinterpret_cast<const char*>(secret), secretlen);
8386
keylog_cb(ssl.get(), line.c_str());

0 commit comments

Comments
 (0)