[client random] refactor use

* use sizeof() instead of define length
* use settings getter/setter
This commit is contained in:
akallabeth
2023-01-28 12:57:17 +01:00
committed by akallabeth
parent 54e5ff1e75
commit 31695c94a1
3 changed files with 25 additions and 26 deletions

View File

@@ -718,13 +718,9 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp)
return FALSE;
/* encrypt client random */
free(settings->ClientRandom);
settings->ClientRandomLength = CLIENT_RANDOM_LENGTH;
settings->ClientRandom = malloc(settings->ClientRandomLength);
if (!settings->ClientRandom)
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ClientRandom, NULL,
CLIENT_RANDOM_LENGTH))
return FALSE;
winpr_RAND(settings->ClientRandom, settings->ClientRandomLength);
WINPR_ASSERT(settings->RdpServerCertificate);
@@ -843,7 +839,7 @@ static BOOL rdp_update_client_random(rdpSettings* settings, const BYTE* crypt_ra
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_ClientRandom, NULL, length))
return FALSE;
BYTE* client_random = freerdp_settings_get_pointer(settings, FreeRDP_ClientRandom);
BYTE* client_random = freerdp_settings_get_pointer_writable(settings, FreeRDP_ClientRandom);
WINPR_ASSERT(client_random);
return crypto_rsa_private_decrypt(crypt_random, crypt_random_len - 8, rsa, client_random,
length) > 0;

View File

@@ -153,7 +153,7 @@ static char* rdp_info_package_flags_description(UINT32 flags)
static BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp)
{
BYTE ClientRandom[32] = { 0 };
BYTE ClientRandom[CLIENT_RANDOM_LENGTH] = { 0 };
BYTE AutoReconnectRandom[32] = { 0 };
ARC_SC_PRIVATE_PACKET* serverCookie;
ARC_CS_PRIVATE_PACKET* clientCookie;
@@ -167,18 +167,17 @@ static BOOL rdp_compute_client_auto_reconnect_cookie(rdpRdp* rdp)
clientCookie->cbLen = 28;
clientCookie->version = serverCookie->version;
clientCookie->logonId = serverCookie->logonId;
ZeroMemory(clientCookie->securityVerifier, 16);
ZeroMemory(AutoReconnectRandom, sizeof(AutoReconnectRandom));
CopyMemory(AutoReconnectRandom, serverCookie->arcRandomBits, 16);
ZeroMemory(ClientRandom, sizeof(ClientRandom));
ZeroMemory(clientCookie->securityVerifier, sizeof(clientCookie->securityVerifier));
CopyMemory(AutoReconnectRandom, serverCookie->arcRandomBits,
sizeof(serverCookie->arcRandomBits));
if (settings->SelectedProtocol == PROTOCOL_RDP)
CopyMemory(ClientRandom, settings->ClientRandom, settings->ClientRandomLength);
/* SecurityVerifier = HMAC_MD5(AutoReconnectRandom, ClientRandom) */
if (!winpr_HMAC(WINPR_MD_MD5, AutoReconnectRandom, 16, ClientRandom, 32,
clientCookie->securityVerifier, 16))
if (!winpr_HMAC(WINPR_MD_MD5, AutoReconnectRandom, 16, ClientRandom, sizeof(ClientRandom),
clientCookie->securityVerifier, sizeof(clientCookie->securityVerifier)))
return FALSE;
return TRUE;

View File

@@ -1001,9 +1001,9 @@ void license_generate_randoms(rdpLicense* license)
WINPR_ASSERT(license);
#ifdef LICENSE_NULL_CLIENT_RANDOM
ZeroMemory(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
ZeroMemory(license->ClientRandom, sizeof(license->ClientRandom)); /* ClientRandom */
#else
winpr_RAND(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
winpr_RAND(license->ClientRandom, sizeof(license->ClientRandom)); /* ClientRandom */
#endif
winpr_RAND(license->ServerRandom, SERVER_RANDOM_LENGTH); /* ServerRandom */
@@ -1043,7 +1043,7 @@ static BOOL license_generate_keys(rdpLicense* license)
license->LicensingEncryptionKey); /* LicensingEncryptionKey */
#ifdef WITH_DEBUG_LICENSE
WLog_DBG(TAG, "ClientRandom:");
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, CLIENT_RANDOM_LENGTH);
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, sizeof(license->ClientRandom));
WLog_DBG(TAG, "ServerRandom:");
winpr_HexDump(TAG, WLOG_DEBUG, license->ServerRandom, SERVER_RANDOM_LENGTH);
WLog_DBG(TAG, "PremasterSecret:");
@@ -1680,7 +1680,8 @@ BOOL license_send_license_info(rdpLicense* license, const LICENSE_BLOB* calBlob,
if (!s)
return FALSE;
if (!license_check_stream_capacity(s, 8 + CLIENT_RANDOM_LENGTH, "license info::ClientRandom"))
if (!license_check_stream_capacity(s, 8 + sizeof(license->ClientRandom),
"license info::ClientRandom"))
return FALSE;
Stream_Write_UINT32(s,
@@ -1688,7 +1689,7 @@ BOOL license_send_license_info(rdpLicense* license, const LICENSE_BLOB* calBlob,
Stream_Write_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
/* ClientRandom (32 bytes) */
Stream_Write(s, license->ClientRandom, CLIENT_RANDOM_LENGTH);
Stream_Write(s, license->ClientRandom, sizeof(license->ClientRandom));
/* Licensing Binary Blob with EncryptedPreMasterSecret: */
if (!license_write_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
@@ -1742,7 +1743,7 @@ BOOL license_read_license_info(rdpLicense* license, wStream* s)
const rdpCertInfo* info = &license->certificate->cert_info;
/* ClientRandom (32 bytes) */
if (!license_check_stream_length(s, 8 + CLIENT_RANDOM_LENGTH, "license info"))
if (!license_check_stream_length(s, 8 + sizeof(license->ClientRandom), "license info"))
goto error;
Stream_Read_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
@@ -1751,7 +1752,7 @@ BOOL license_read_license_info(rdpLicense* license, wStream* s)
Stream_Read_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
/* ClientRandom (32 bytes) */
Stream_Read(s, license->ClientRandom, CLIENT_RANDOM_LENGTH);
Stream_Read(s, license->ClientRandom, sizeof(license->ClientRandom));
/* Licensing Binary Blob with EncryptedPreMasterSecret: */
if (!license_read_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
@@ -2197,13 +2198,14 @@ BOOL license_write_new_license_request_packet(const rdpLicense* license, wStream
WINPR_ASSERT(license);
WINPR_ASSERT(license->certificate);
if (!license_check_stream_capacity(s, 8 + CLIENT_RANDOM_LENGTH, "License Request"))
if (!license_check_stream_capacity(s, 8 + sizeof(license->ClientRandom), "License Request"))
return FALSE;
Stream_Write_UINT32(s,
license->PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
Stream_Write_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
Stream_Write(s, license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom (32 bytes) */
Stream_Write(s, license->ClientRandom,
sizeof(license->ClientRandom)); /* ClientRandom (32 bytes) */
if (/* EncryptedPremasterSecret */
!license_write_encrypted_premaster_secret_blob(
@@ -2219,7 +2221,7 @@ BOOL license_write_new_license_request_packet(const rdpLicense* license, wStream
#ifdef WITH_DEBUG_LICENSE
WLog_DBG(TAG, "PreferredKeyExchangeAlg: 0x%08" PRIX32 "", license->PreferredKeyExchangeAlg);
WLog_DBG(TAG, "ClientRandom:");
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, CLIENT_RANDOM_LENGTH);
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, sizeof(license->ClientRandom));
WLog_DBG(TAG, "EncryptedPremasterSecret");
winpr_HexDump(TAG, WLOG_DEBUG, license->EncryptedPremasterSecret->data,
license->EncryptedPremasterSecret->length);
@@ -2238,7 +2240,8 @@ BOOL license_read_new_license_request_packet(rdpLicense* license, wStream* s)
WINPR_ASSERT(license);
WINPR_ASSERT(license->certificate);
if (!license_check_stream_length(s, 8ull + CLIENT_RANDOM_LENGTH, "new license request"))
if (!license_check_stream_length(s, 8ull + sizeof(license->ClientRandom),
"new license request"))
return FALSE;
Stream_Read_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
@@ -2246,7 +2249,8 @@ BOOL license_read_new_license_request_packet(rdpLicense* license, wStream* s)
return FALSE;
Stream_Read_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
Stream_Read(s, license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom (32 bytes) */
Stream_Read(s, license->ClientRandom,
sizeof(license->ClientRandom)); /* ClientRandom (32 bytes) */
/* EncryptedPremasterSecret */
if (!license_read_encrypted_premaster_secret_blob(