Skip to content

Commit bed29a3

Browse files
tniessenFyko
authored andcommitted
tls: use OpenSSL constant for client random size
Avoid magic numbers in the code and use an OpenSSL constant instead. PR-URL: nodejs#44305 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 7fc1502 commit bed29a3

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
@@ -71,16 +71,19 @@ void LogSecret(
7171
const unsigned char* secret,
7272
size_t secretlen) {
7373
auto keylog_cb = SSL_CTX_get_keylog_callback(SSL_get_SSL_CTX(ssl.get()));
74-
unsigned char crandom[32];
74+
// All supported versions of TLS/SSL fix the client random to the same size.
75+
constexpr size_t kTlsClientRandomSize = SSL3_RANDOM_SIZE;
76+
unsigned char crandom[kTlsClientRandomSize];
7577

7678
if (keylog_cb == nullptr ||
77-
SSL_get_client_random(ssl.get(), crandom, 32) != 32) {
79+
SSL_get_client_random(ssl.get(), crandom, kTlsClientRandomSize) !=
80+
kTlsClientRandomSize) {
7881
return;
7982
}
8083

8184
std::string line = name;
82-
line += " " + StringBytes::hex_encode(
83-
reinterpret_cast<const char*>(crandom), 32);
85+
line += " " + StringBytes::hex_encode(reinterpret_cast<const char*>(crandom),
86+
kTlsClientRandomSize);
8487
line += " " + StringBytes::hex_encode(
8588
reinterpret_cast<const char*>(secret), secretlen);
8689
keylog_cb(ssl.get(), line.c_str());

0 commit comments

Comments
 (0)