libfreerdp-core: license refactoring
This commit is contained in:
parent
1070931479
commit
1b97663de8
@ -316,8 +316,8 @@ void test_license(void)
|
||||
STREAM _s, *s;
|
||||
|
||||
s = &_s;
|
||||
memcpy(license->client_random, client_random, sizeof(client_random));
|
||||
memcpy(license->premaster_secret, premaster_secret, sizeof(premaster_secret));
|
||||
memcpy(license->ClientRandom, client_random, sizeof(client_random));
|
||||
memcpy(license->PremasterSecret, premaster_secret, sizeof(premaster_secret));
|
||||
|
||||
s->data = server_license_request;
|
||||
s->p = s->data + LICENSE_PREAMBLE_LENGTH;
|
||||
@ -327,31 +327,31 @@ void test_license(void)
|
||||
printf("\n");
|
||||
|
||||
printf("client random:\n");
|
||||
winpr_HexDump(license->client_random, 32);
|
||||
winpr_HexDump(license->ClientRandom, 32);
|
||||
printf("\n");
|
||||
|
||||
printf("server random:\n");
|
||||
winpr_HexDump(license->server_random, 32);
|
||||
winpr_HexDump(license->ServerRandom, 32);
|
||||
printf("\n");
|
||||
|
||||
printf("premaster secret:\n");
|
||||
winpr_HexDump(license->premaster_secret, 48);
|
||||
winpr_HexDump(license->PremasterSecret, 48);
|
||||
printf("\n");
|
||||
|
||||
printf("master secret:\n");
|
||||
winpr_HexDump(license->master_secret, 48);
|
||||
winpr_HexDump(license->MasterSecret, 48);
|
||||
printf("\n");
|
||||
|
||||
printf("session key blob:\n");
|
||||
winpr_HexDump(license->session_key_blob, 48);
|
||||
winpr_HexDump(license->SessionKeyBlob, 48);
|
||||
printf("\n");
|
||||
|
||||
printf("licensing encryption key:\n");
|
||||
winpr_HexDump(license->licensing_encryption_key, 16);
|
||||
winpr_HexDump(license->LicensingEncryptionKey, 16);
|
||||
printf("\n");
|
||||
|
||||
printf("mac salt key:\n");
|
||||
winpr_HexDump(license->mac_salt_key, 16);
|
||||
winpr_HexDump(license->MacSaltKey, 16);
|
||||
printf("\n");
|
||||
|
||||
printf("modulus:\n");
|
||||
@ -364,8 +364,8 @@ void test_license(void)
|
||||
printf("\n");
|
||||
|
||||
printf("encrypted premaster secret:\n");
|
||||
winpr_HexDump(license->encrypted_premaster_secret->data,
|
||||
license->encrypted_premaster_secret->length);
|
||||
winpr_HexDump(license->EncryptedPremasterSecret->data,
|
||||
license->EncryptedPremasterSecret->length);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
@ -422,9 +422,9 @@ void test_license_generate_keys(void)
|
||||
STREAM _s, *s;
|
||||
|
||||
s = &_s;
|
||||
memcpy(license->client_random, client_random, sizeof(client_random));
|
||||
memcpy(license->server_random, test_server_random, sizeof(test_server_random));
|
||||
memcpy(license->premaster_secret, premaster_secret, sizeof(premaster_secret));
|
||||
memcpy(license->ClientRandom, client_random, sizeof(client_random));
|
||||
memcpy(license->ServerRandom, test_server_random, sizeof(test_server_random));
|
||||
memcpy(license->PremasterSecret, premaster_secret, sizeof(premaster_secret));
|
||||
memcpy(license->certificate->cert_info.exponent, test_exponent, sizeof(test_exponent));
|
||||
memcpy(license->certificate->cert_info.Modulus, test_modulus, sizeof(test_modulus));
|
||||
license->certificate->cert_info.ModulusLength = sizeof(test_modulus);
|
||||
@ -432,23 +432,23 @@ void test_license_generate_keys(void)
|
||||
license_generate_keys(license);
|
||||
license_encrypt_premaster_secret(license);
|
||||
|
||||
s->data = license->master_secret;
|
||||
s->data = license->MasterSecret;
|
||||
s->p = s->data + sizeof(test_master_secret);
|
||||
ASSERT_STREAM(s, test_master_secret, sizeof(test_master_secret));
|
||||
|
||||
s->data = license->session_key_blob;
|
||||
s->data = license->SessionKeyBlob;
|
||||
s->p = s->data + sizeof(test_session_key_blob);
|
||||
ASSERT_STREAM(s, test_session_key_blob, sizeof(test_session_key_blob));
|
||||
|
||||
s->data = license->mac_salt_key;
|
||||
s->data = license->MacSaltKey;
|
||||
s->p = s->data + sizeof(test_mac_salt_key);
|
||||
ASSERT_STREAM(s, test_mac_salt_key, sizeof(test_mac_salt_key));
|
||||
|
||||
s->data = license->licensing_encryption_key;
|
||||
s->data = license->LicensingEncryptionKey;
|
||||
s->p = s->data + sizeof(test_licensing_encryption_key);
|
||||
ASSERT_STREAM(s, test_licensing_encryption_key, sizeof(test_licensing_encryption_key));
|
||||
|
||||
s->data = license->encrypted_premaster_secret->data;
|
||||
s->data = license->EncryptedPremasterSecret->data;
|
||||
s->p = s->data + sizeof(test_encrypted_premaster_secret);
|
||||
ASSERT_STREAM(s, test_encrypted_premaster_secret, sizeof(test_encrypted_premaster_secret));
|
||||
}
|
||||
@ -458,12 +458,12 @@ void test_license_encrypt_premaster_secret(void)
|
||||
STREAM _s, *s;
|
||||
|
||||
s = &_s;
|
||||
memcpy(license->premaster_secret, premaster_secret, sizeof(premaster_secret));
|
||||
memcpy(license->PremasterSecret, premaster_secret, sizeof(premaster_secret));
|
||||
memcpy(license->certificate->cert_info.exponent, test_exponent, sizeof(test_exponent));
|
||||
memcpy(license->certificate->cert_info.Modulus, test_modulus, sizeof(test_modulus));
|
||||
license->certificate->cert_info.ModulusLength = sizeof(test_modulus);
|
||||
|
||||
s->data = license->encrypted_premaster_secret->data;
|
||||
s->data = license->EncryptedPremasterSecret->data;
|
||||
s->p = s->data + sizeof(test_encrypted_premaster_secret);
|
||||
ASSERT_STREAM(s, test_encrypted_premaster_secret, sizeof(test_encrypted_premaster_secret));
|
||||
}
|
||||
@ -479,20 +479,20 @@ void test_license_decrypt_platform_challenge(void)
|
||||
STREAM _s, *s;
|
||||
|
||||
s = &_s;
|
||||
memcpy(license->licensing_encryption_key, test_licensing_encryption_key,
|
||||
memcpy(license->LicensingEncryptionKey, test_licensing_encryption_key,
|
||||
sizeof(test_licensing_encryption_key));
|
||||
|
||||
license->encrypted_platform_challenge->data =
|
||||
license->EncryptedPlatformChallenge->data =
|
||||
(BYTE*) malloc(sizeof(test_encrypted_platform_challenge));
|
||||
license->encrypted_platform_challenge->length =
|
||||
license->EncryptedPlatformChallenge->length =
|
||||
sizeof(test_encrypted_platform_challenge);
|
||||
|
||||
memcpy(license->encrypted_platform_challenge->data, test_encrypted_platform_challenge,
|
||||
memcpy(license->EncryptedPlatformChallenge->data, test_encrypted_platform_challenge,
|
||||
sizeof(test_encrypted_platform_challenge));
|
||||
|
||||
license_decrypt_platform_challenge(license);
|
||||
|
||||
s->data = license->platform_challenge->data;
|
||||
s->data = license->PlatformChallenge->data;
|
||||
s->p = s->data + sizeof(test_platform_challenge);
|
||||
|
||||
ASSERT_STREAM(s, test_platform_challenge, sizeof(test_platform_challenge));
|
||||
|
@ -28,7 +28,10 @@
|
||||
|
||||
#include "license.h"
|
||||
|
||||
#define LICENSE_NULL_RANDOM 1
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
|
||||
static const char* const LICENSE_MESSAGE_STRINGS[] =
|
||||
{
|
||||
"",
|
||||
@ -72,6 +75,27 @@ static const char* const state_transitions[] =
|
||||
"ST_RESET_PHASE_TO_START",
|
||||
"ST_RESEND_LAST_MESSAGE"
|
||||
};
|
||||
|
||||
void license_print_product_info(PRODUCT_INFO* productInfo)
|
||||
{
|
||||
char* CompanyName = NULL;
|
||||
char* ProductId = NULL;
|
||||
|
||||
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) productInfo->pbCompanyName,
|
||||
productInfo->cbCompanyName / 2, &CompanyName, 0, NULL, NULL);
|
||||
|
||||
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) productInfo->pbProductId,
|
||||
productInfo->cbProductId / 2, &ProductId, 0, NULL, NULL);
|
||||
|
||||
printf("ProductInfo:\n");
|
||||
printf("\tdwVersion: 0x%08X\n", productInfo->dwVersion);
|
||||
printf("\tCompanyName: %s\n", CompanyName);
|
||||
printf("\tProductId: %s\n", ProductId);
|
||||
|
||||
free(CompanyName);
|
||||
free(ProductId);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -87,11 +111,13 @@ static const char* const state_transitions[] =
|
||||
BOOL license_read_preamble(STREAM* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgSize)
|
||||
{
|
||||
/* preamble (4 bytes) */
|
||||
if(stream_get_left(s) < 4)
|
||||
if (stream_get_left(s) < 4)
|
||||
return FALSE;
|
||||
|
||||
stream_read_BYTE(s, *bMsgType); /* bMsgType (1 byte) */
|
||||
stream_read_BYTE(s, *flags); /* flags (1 byte) */
|
||||
stream_read_UINT16(s, *wMsgSize); /* wMsgSize (2 bytes) */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -121,8 +147,10 @@ void license_write_preamble(STREAM* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSiz
|
||||
STREAM* license_send_stream_init(rdpLicense* license)
|
||||
{
|
||||
STREAM* s;
|
||||
|
||||
s = transport_send_stream_init(license->rdp->transport, 4096);
|
||||
stream_seek(s, LICENSE_PACKET_HEADER_MAX_LENGTH);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -147,6 +175,7 @@ BOOL license_send(rdpLicense* license, STREAM* s, BYTE type)
|
||||
|
||||
sec_flags = SEC_LICENSE_PKT;
|
||||
wMsgSize = length - LICENSE_PACKET_HEADER_MAX_LENGTH + 4;
|
||||
|
||||
/**
|
||||
* Using EXTENDED_ERROR_MSG_SUPPORTED here would cause mstsc to crash when
|
||||
* running in server mode! This flag seems to be incorrectly documented.
|
||||
@ -163,6 +192,7 @@ BOOL license_send(rdpLicense* license, STREAM* s, BYTE type)
|
||||
#endif
|
||||
|
||||
stream_set_pos(s, length);
|
||||
|
||||
if (transport_write(license->rdp->transport, s) < 0)
|
||||
return FALSE;
|
||||
|
||||
@ -260,12 +290,12 @@ BOOL license_recv(rdpLicense* license, STREAM* s)
|
||||
|
||||
void license_generate_randoms(rdpLicense* license)
|
||||
{
|
||||
#if 0
|
||||
crypto_nonce(license->client_random, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
||||
crypto_nonce(license->premaster_secret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
||||
#ifdef LICENSE_NULL_RANDOM
|
||||
ZeroMemory(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
||||
ZeroMemory(license->PremasterSecret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
||||
#else
|
||||
memset(license->client_random, 0, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
||||
memset(license->premaster_secret, 0, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
||||
crypto_nonce(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
||||
crypto_nonce(license->PremasterSecret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -276,39 +306,46 @@ void license_generate_randoms(rdpLicense* license)
|
||||
|
||||
void license_generate_keys(rdpLicense* license)
|
||||
{
|
||||
security_master_secret(license->premaster_secret, license->client_random,
|
||||
license->server_random, license->master_secret); /* MasterSecret */
|
||||
security_master_secret(license->PremasterSecret, license->ClientRandom,
|
||||
license->ServerRandom, license->MasterSecret); /* MasterSecret */
|
||||
|
||||
security_session_key_blob(license->master_secret, license->client_random,
|
||||
license->server_random, license->session_key_blob); /* SessionKeyBlob */
|
||||
security_session_key_blob(license->MasterSecret, license->ClientRandom,
|
||||
license->ServerRandom, license->SessionKeyBlob); /* SessionKeyBlob */
|
||||
|
||||
security_mac_salt_key(license->session_key_blob, license->client_random,
|
||||
license->server_random, license->mac_salt_key); /* MacSaltKey */
|
||||
security_mac_salt_key(license->SessionKeyBlob, license->ClientRandom,
|
||||
license->ServerRandom, license->MacSaltKey); /* MacSaltKey */
|
||||
|
||||
security_licensing_encryption_key(license->session_key_blob, license->client_random,
|
||||
license->server_random, license->licensing_encryption_key); /* LicensingEncryptionKey */
|
||||
security_licensing_encryption_key(license->SessionKeyBlob, license->ClientRandom,
|
||||
license->ServerRandom, license->LicensingEncryptionKey); /* LicensingEncryptionKey */
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
printf("ClientRandom:\n");
|
||||
winpr_HexDump(license->client_random, CLIENT_RANDOM_LENGTH);
|
||||
winpr_HexDump(license->ClientRandom, CLIENT_RANDOM_LENGTH);
|
||||
printf("\n");
|
||||
|
||||
printf("ServerRandom:\n");
|
||||
winpr_HexDump(license->server_random, SERVER_RANDOM_LENGTH);
|
||||
winpr_HexDump(license->ServerRandom, SERVER_RANDOM_LENGTH);
|
||||
printf("\n");
|
||||
|
||||
printf("PremasterSecret:\n");
|
||||
winpr_HexDump(license->premaster_secret, PREMASTER_SECRET_LENGTH);
|
||||
winpr_HexDump(license->PremasterSecret, PREMASTER_SECRET_LENGTH);
|
||||
printf("\n");
|
||||
|
||||
printf("MasterSecret:\n");
|
||||
winpr_HexDump(license->master_secret, MASTER_SECRET_LENGTH);
|
||||
winpr_HexDump(license->MasterSecret, MASTER_SECRET_LENGTH);
|
||||
printf("\n");
|
||||
|
||||
printf("SessionKeyBlob:\n");
|
||||
winpr_HexDump(license->session_key_blob, SESSION_KEY_BLOB_LENGTH);
|
||||
winpr_HexDump(license->SessionKeyBlob, SESSION_KEY_BLOB_LENGTH);
|
||||
printf("\n");
|
||||
|
||||
printf("MacSaltKey:\n");
|
||||
winpr_HexDump(license->mac_salt_key, MAC_SALT_KEY_LENGTH);
|
||||
winpr_HexDump(license->MacSaltKey, MAC_SALT_KEY_LENGTH);
|
||||
printf("\n");
|
||||
|
||||
printf("LicensingEncryptionKey:\n");
|
||||
winpr_HexDump(license->licensing_encryption_key, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
winpr_HexDump(license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -322,56 +359,66 @@ void license_generate_hwid(rdpLicense* license)
|
||||
CryptoMd5 md5;
|
||||
BYTE* mac_address;
|
||||
|
||||
memset(license->hwid, 0, HWID_LENGTH);
|
||||
ZeroMemory(license->HardwareId, HWID_LENGTH);
|
||||
mac_address = license->rdp->transport->TcpIn->mac_address;
|
||||
|
||||
md5 = crypto_md5_init();
|
||||
crypto_md5_update(md5, mac_address, 6);
|
||||
crypto_md5_final(md5, &license->hwid[HWID_PLATFORM_ID_LENGTH]);
|
||||
crypto_md5_final(md5, &license->HardwareId[HWID_PLATFORM_ID_LENGTH]);
|
||||
}
|
||||
|
||||
void license_encrypt_premaster_secret(rdpLicense* license)
|
||||
{
|
||||
BYTE* encrypted_premaster_secret;
|
||||
#if 0
|
||||
int key_length;
|
||||
|
||||
#ifdef LICENSE_NULL_RANDOM
|
||||
encrypted_premaster_secret = (BYTE*) malloc(MODULUS_MAX_SIZE);
|
||||
ZeroMemory(encrypted_premaster_secret, MODULUS_MAX_SIZE);
|
||||
|
||||
license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB;
|
||||
license->EncryptedPremasterSecret->length = PREMASTER_SECRET_LENGTH;
|
||||
license->EncryptedPremasterSecret->data = encrypted_premaster_secret;
|
||||
#else
|
||||
BYTE* modulus;
|
||||
BYTE* exponent;
|
||||
int key_length;
|
||||
rdpSettings* settings;
|
||||
rdpCertificate *certificate;
|
||||
|
||||
if (license->server_certificate->length)
|
||||
if (license->ServerCertificate->length)
|
||||
{
|
||||
certificate = license->certificate;
|
||||
}
|
||||
else
|
||||
certificate = license->rdp->settings->server_cert;
|
||||
{
|
||||
settings = license->rdp->settings;
|
||||
certificate = license->certificate;
|
||||
certificate_read_server_certificate(certificate, settings->ServerCertificate, settings->ServerCertificateLength);
|
||||
}
|
||||
|
||||
exponent = certificate->cert_info.exponent;
|
||||
modulus = certificate->cert_info.modulus.data;
|
||||
key_length = certificate->cert_info.modulus.length;
|
||||
modulus = certificate->cert_info.Modulus;
|
||||
key_length = certificate->cert_info.ModulusLength;
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
printf("modulus (%d bits):\n", key_length * 8);
|
||||
printf("Modulus (%d bits):\n", key_length * 8);
|
||||
winpr_HexDump(modulus, key_length);
|
||||
printf("\n");
|
||||
|
||||
printf("exponent:\n");
|
||||
printf("Exponent:\n");
|
||||
winpr_HexDump(exponent, 4);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
encrypted_premaster_secret = (BYTE*) malloc(MODULUS_MAX_SIZE);
|
||||
memset(encrypted_premaster_secret, 0, MODULUS_MAX_SIZE);
|
||||
EncryptedPremasterSecret = (BYTE*) malloc(MODULUS_MAX_SIZE);
|
||||
ZeroMemory(EncryptedPremasterSecret, MODULUS_MAX_SIZE);
|
||||
|
||||
crypto_rsa_public_encrypt(license->premaster_secret, PREMASTER_SECRET_LENGTH,
|
||||
key_length, modulus, exponent, encrypted_premaster_secret);
|
||||
crypto_rsa_public_encrypt(license->PremasterSecret, PREMASTER_SECRET_LENGTH,
|
||||
key_length, modulus, exponent, EncryptedPremasterSecret);
|
||||
|
||||
license->encrypted_premaster_secret->type = BB_RANDOM_BLOB;
|
||||
license->encrypted_premaster_secret->length = PREMASTER_SECRET_LENGTH;
|
||||
license->encrypted_premaster_secret->data = encrypted_premaster_secret;
|
||||
#else
|
||||
encrypted_premaster_secret = (BYTE*) malloc(MODULUS_MAX_SIZE);
|
||||
memset(encrypted_premaster_secret, 0, MODULUS_MAX_SIZE);
|
||||
|
||||
license->encrypted_premaster_secret->type = BB_RANDOM_BLOB;
|
||||
license->encrypted_premaster_secret->length = PREMASTER_SECRET_LENGTH;
|
||||
license->encrypted_premaster_secret->data = encrypted_premaster_secret;
|
||||
license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB;
|
||||
license->EncryptedPremasterSecret->length = PREMASTER_SECRET_LENGTH;
|
||||
license->EncryptedPremasterSecret->data = EncryptedPremasterSecret;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -379,24 +426,23 @@ void license_decrypt_platform_challenge(rdpLicense* license)
|
||||
{
|
||||
CryptoRc4 rc4;
|
||||
|
||||
license->platform_challenge->data =
|
||||
(BYTE*) malloc(license->encrypted_platform_challenge->length);
|
||||
license->platform_challenge->length =
|
||||
license->encrypted_platform_challenge->length;
|
||||
license->PlatformChallenge->data = (BYTE*) malloc(license->EncryptedPlatformChallenge->length);
|
||||
license->PlatformChallenge->length = license->EncryptedPlatformChallenge->length;
|
||||
|
||||
rc4 = crypto_rc4_init(license->licensing_encryption_key, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
rc4 = crypto_rc4_init(license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
|
||||
crypto_rc4(rc4, license->encrypted_platform_challenge->length,
|
||||
license->encrypted_platform_challenge->data,
|
||||
license->platform_challenge->data);
|
||||
crypto_rc4(rc4, license->EncryptedPlatformChallenge->length,
|
||||
license->EncryptedPlatformChallenge->data,
|
||||
license->PlatformChallenge->data);
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
printf("encrypted_platform challenge:\n");
|
||||
winpr_HexDump(license->encrypted_platform_challenge->data,
|
||||
license->encrypted_platform_challenge->length);
|
||||
printf("EncryptedPlatformChallenge:\n");
|
||||
winpr_HexDump(license->EncryptedPlatformChallenge->data, license->EncryptedPlatformChallenge->length);
|
||||
printf("\n");
|
||||
|
||||
printf("platform challenge:\n");
|
||||
winpr_HexDump(license->platform_challenge->data, license->platform_challenge->length);
|
||||
printf("PlatformChallenge:\n");
|
||||
winpr_HexDump(license->PlatformChallenge->data, license->PlatformChallenge->length);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
crypto_rc4_free(rc4);
|
||||
@ -411,19 +457,22 @@ void license_decrypt_platform_challenge(rdpLicense* license)
|
||||
|
||||
BOOL license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo)
|
||||
{
|
||||
if(stream_get_left(s) < 8)
|
||||
if (stream_get_left(s) < 8)
|
||||
return FALSE;
|
||||
|
||||
stream_read_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
|
||||
|
||||
stream_read_UINT32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */
|
||||
if(stream_get_left(s) < productInfo->cbCompanyName + 4)
|
||||
|
||||
if (stream_get_left(s) < productInfo->cbCompanyName + 4)
|
||||
return FALSE;
|
||||
|
||||
productInfo->pbCompanyName = (BYTE*) malloc(productInfo->cbCompanyName);
|
||||
stream_read(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
|
||||
|
||||
stream_read_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
|
||||
if(stream_get_left(s) < productInfo->cbProductId)
|
||||
|
||||
if (stream_get_left(s) < productInfo->cbProductId)
|
||||
{
|
||||
free(productInfo->pbCompanyName);
|
||||
productInfo->pbCompanyName = NULL;
|
||||
@ -432,6 +481,7 @@ BOOL license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo)
|
||||
|
||||
productInfo->pbProductId = (BYTE*) malloc(productInfo->cbProductId);
|
||||
stream_read(s, productInfo->pbProductId, productInfo->cbProductId);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -484,12 +534,13 @@ BOOL license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob)
|
||||
{
|
||||
UINT16 wBlobType;
|
||||
|
||||
if(stream_get_left(s) < 4)
|
||||
if (stream_get_left(s) < 4)
|
||||
return FALSE;
|
||||
|
||||
stream_read_UINT16(s, wBlobType); /* wBlobType (2 bytes) */
|
||||
stream_read_UINT16(s, blob->length); /* wBlobLen (2 bytes) */
|
||||
|
||||
if(stream_get_left(s) < blob->length)
|
||||
if (stream_get_left(s) < blob->length)
|
||||
return FALSE;
|
||||
|
||||
/*
|
||||
@ -585,8 +636,9 @@ BOOL license_read_scope_list(STREAM* s, SCOPE_LIST* scopeList)
|
||||
UINT32 i;
|
||||
UINT32 scopeCount;
|
||||
|
||||
if(stream_get_left(s) < 4)
|
||||
if (stream_get_left(s) < 4)
|
||||
return FALSE;
|
||||
|
||||
stream_read_UINT32(s, scopeCount); /* ScopeCount (4 bytes) */
|
||||
|
||||
scopeList->count = scopeCount;
|
||||
@ -596,9 +648,11 @@ BOOL license_read_scope_list(STREAM* s, SCOPE_LIST* scopeList)
|
||||
for (i = 0; i < scopeCount; i++)
|
||||
{
|
||||
scopeList->array[i].type = BB_SCOPE_BLOB;
|
||||
if(!license_read_binary_blob(s, &scopeList->array[i]))
|
||||
|
||||
if (!license_read_binary_blob(s, &scopeList->array[i]))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -641,7 +695,7 @@ void license_free_scope_list(SCOPE_LIST* scopeList)
|
||||
free(scopeList->array[i].data);
|
||||
}
|
||||
|
||||
free(scopeList->array) ;
|
||||
free(scopeList->array);
|
||||
free(scopeList);
|
||||
}
|
||||
|
||||
@ -658,33 +712,42 @@ BOOL license_read_license_request_packet(rdpLicense* license, STREAM* s)
|
||||
if (stream_get_left(s) < 32)
|
||||
return FALSE;
|
||||
|
||||
stream_read(s, license->server_random, 32);
|
||||
stream_read(s, license->ServerRandom, 32);
|
||||
|
||||
/* ProductInfo */
|
||||
if (!license_read_product_info(s, license->product_info))
|
||||
if (!license_read_product_info(s, license->ProductInfo))
|
||||
return FALSE;
|
||||
|
||||
/* KeyExchangeList */
|
||||
if (!license_read_binary_blob(s, license->key_exchange_list))
|
||||
if (!license_read_binary_blob(s, license->KeyExchangeList))
|
||||
return FALSE;
|
||||
|
||||
/* ServerCertificate */
|
||||
if (!license_read_binary_blob(s, license->server_certificate))
|
||||
if (!license_read_binary_blob(s, license->ServerCertificate))
|
||||
return FALSE;
|
||||
|
||||
/* ScopeList */
|
||||
if (!license_read_scope_list(s, license->scope_list))
|
||||
if (!license_read_scope_list(s, license->ScopeList))
|
||||
return FALSE;
|
||||
|
||||
/* Parse Server Certificate */
|
||||
if (!certificate_read_server_certificate(license->certificate,
|
||||
license->server_certificate->data, license->server_certificate->length) < 0)
|
||||
license->ServerCertificate->data, license->ServerCertificate->length) < 0)
|
||||
return FALSE;
|
||||
|
||||
license_generate_keys(license);
|
||||
license_generate_hwid(license);
|
||||
license_encrypt_premaster_secret(license);
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
printf("ServerRandom:\n");
|
||||
winpr_HexDump(license->ServerRandom, 32);
|
||||
printf("\n");
|
||||
|
||||
license_print_product_info(license->ProductInfo);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -705,9 +768,9 @@ BOOL license_read_platform_challenge_packet(rdpLicense* license, STREAM* s)
|
||||
stream_seek(s, 4); /* ConnectFlags, Reserved (4 bytes) */
|
||||
|
||||
/* EncryptedPlatformChallenge */
|
||||
license->encrypted_platform_challenge->type = BB_ANY_BLOB;
|
||||
license_read_binary_blob(s, license->encrypted_platform_challenge);
|
||||
license->encrypted_platform_challenge->type = BB_ENCRYPTED_DATA_BLOB;
|
||||
license->EncryptedPlatformChallenge->type = BB_ANY_BLOB;
|
||||
license_read_binary_blob(s, license->EncryptedPlatformChallenge);
|
||||
license->EncryptedPlatformChallenge->type = BB_ENCRYPTED_DATA_BLOB;
|
||||
|
||||
/* MACData (16 bytes) */
|
||||
if (!stream_skip(s, 16))
|
||||
@ -762,7 +825,7 @@ BOOL license_read_error_alert_packet(rdpLicense* license, STREAM* s)
|
||||
stream_read_UINT32(s, dwErrorCode); /* dwErrorCode (4 bytes) */
|
||||
stream_read_UINT32(s, dwStateTransition); /* dwStateTransition (4 bytes) */
|
||||
|
||||
if (!license_read_binary_blob(s, license->error_info)) /* bbErrorInfo */
|
||||
if (!license_read_binary_blob(s, license->ErrorInfo)) /* bbErrorInfo */
|
||||
return FALSE;
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
@ -825,10 +888,10 @@ void license_write_new_license_request_packet(rdpLicense* license, STREAM* s)
|
||||
{
|
||||
stream_write_UINT32(s, KEY_EXCHANGE_ALG_RSA); /* PreferredKeyExchangeAlg (4 bytes) */
|
||||
license_write_platform_id(license, s); /* PlatformId (4 bytes) */
|
||||
stream_write(s, license->client_random, 32); /* ClientRandom (32 bytes) */
|
||||
license_write_padded_binary_blob(s, license->encrypted_premaster_secret); /* EncryptedPremasterSecret */
|
||||
license_write_binary_blob(s, license->client_user_name); /* ClientUserName */
|
||||
license_write_binary_blob(s, license->client_machine_name); /* ClientMachineName */
|
||||
stream_write(s, license->ClientRandom, 32); /* ClientRandom (32 bytes) */
|
||||
license_write_padded_binary_blob(s, license->EncryptedPremasterSecret); /* EncryptedPremasterSecret */
|
||||
license_write_binary_blob(s, license->ClientUserName); /* ClientUserName */
|
||||
license_write_binary_blob(s, license->ClientMachineName); /* ClientMachineName */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -849,21 +912,21 @@ void license_send_new_license_request_packet(rdpLicense* license)
|
||||
else
|
||||
username = "username";
|
||||
|
||||
license->client_user_name->data = (BYTE*) username;
|
||||
license->client_user_name->length = strlen(username) + 1;
|
||||
license->ClientUserName->data = (BYTE*) username;
|
||||
license->ClientUserName->length = strlen(username) + 1;
|
||||
|
||||
license->client_machine_name->data = (BYTE*) license->rdp->settings->ClientHostname;
|
||||
license->client_machine_name->length = strlen(license->rdp->settings->ClientHostname) + 1;
|
||||
license->ClientMachineName->data = (BYTE*) license->rdp->settings->ClientHostname;
|
||||
license->ClientMachineName->length = strlen(license->rdp->settings->ClientHostname) + 1;
|
||||
|
||||
license_write_new_license_request_packet(license, s);
|
||||
|
||||
license_send(license, s, NEW_LICENSE_REQUEST);
|
||||
|
||||
license->client_user_name->data = NULL;
|
||||
license->client_user_name->length = 0;
|
||||
license->ClientUserName->data = NULL;
|
||||
license->ClientUserName->length = 0;
|
||||
|
||||
license->client_machine_name->data = NULL;
|
||||
license->client_machine_name->length = 0;
|
||||
license->ClientMachineName->data = NULL;
|
||||
license->ClientMachineName->length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -876,14 +939,9 @@ void license_send_new_license_request_packet(rdpLicense* license)
|
||||
|
||||
void license_write_platform_challenge_response_packet(rdpLicense* license, STREAM* s, BYTE* mac_data)
|
||||
{
|
||||
/* EncryptedPlatformChallengeResponse */
|
||||
license_write_binary_blob(s, license->encrypted_platform_challenge);
|
||||
|
||||
/* EncryptedHWID */
|
||||
license_write_binary_blob(s, license->encrypted_hwid);
|
||||
|
||||
/* MACData */
|
||||
stream_write(s, mac_data, 16);
|
||||
license_write_binary_blob(s, license->EncryptedPlatformChallenge); /* EncryptedPlatformChallengeResponse */
|
||||
license_write_binary_blob(s, license->EncryptedHardwareId); /* EncryptedHWID */
|
||||
stream_write(s, mac_data, 16); /* MACData */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -903,33 +961,36 @@ void license_send_platform_challenge_response_packet(rdpLicense* license)
|
||||
s = license_send_stream_init(license);
|
||||
DEBUG_LICENSE("Sending Platform Challenge Response Packet");
|
||||
|
||||
license->encrypted_platform_challenge->type = BB_DATA_BLOB;
|
||||
length = license->platform_challenge->length + HWID_LENGTH;
|
||||
license->EncryptedPlatformChallenge->type = BB_DATA_BLOB;
|
||||
length = license->PlatformChallenge->length + HWID_LENGTH;
|
||||
buffer = (BYTE*) malloc(length);
|
||||
memcpy(buffer, license->platform_challenge->data, license->platform_challenge->length);
|
||||
memcpy(&buffer[license->platform_challenge->length], license->hwid, HWID_LENGTH);
|
||||
security_mac_data(license->mac_salt_key, buffer, length, mac_data);
|
||||
memcpy(buffer, license->PlatformChallenge->data, license->PlatformChallenge->length);
|
||||
memcpy(&buffer[license->PlatformChallenge->length], license->HardwareId, HWID_LENGTH);
|
||||
security_mac_data(license->MacSaltKey, buffer, length, mac_data);
|
||||
free(buffer);
|
||||
|
||||
buffer = (BYTE*) malloc(HWID_LENGTH);
|
||||
rc4 = crypto_rc4_init(license->licensing_encryption_key, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
crypto_rc4(rc4, HWID_LENGTH, license->hwid, buffer);
|
||||
rc4 = crypto_rc4_init(license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
||||
crypto_rc4(rc4, HWID_LENGTH, license->HardwareId, buffer);
|
||||
crypto_rc4_free(rc4);
|
||||
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
printf("Licensing Encryption Key:\n");
|
||||
winpr_HexDump(license->licensing_encryption_key, 16);
|
||||
winpr_HexDump(license->LicensingEncryptionKey, 16);
|
||||
printf("\n");
|
||||
|
||||
printf("HardwareID:\n");
|
||||
winpr_HexDump(license->hwid, 20);
|
||||
winpr_HexDump(license->HardwareId, 20);
|
||||
printf("\n");
|
||||
|
||||
printf("Encrypted HardwareID:\n");
|
||||
winpr_HexDump(buffer, 20);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
license->encrypted_hwid->type = BB_DATA_BLOB;
|
||||
license->encrypted_hwid->data = buffer;
|
||||
license->encrypted_hwid->length = HWID_LENGTH;
|
||||
license->EncryptedHardwareId->type = BB_DATA_BLOB;
|
||||
license->EncryptedHardwareId->data = buffer;
|
||||
license->EncryptedHardwareId->length = HWID_LENGTH;
|
||||
|
||||
license_write_platform_challenge_response_packet(license, s, mac_data);
|
||||
|
||||
@ -951,7 +1012,7 @@ BOOL license_send_valid_client_error_packet(rdpLicense* license)
|
||||
stream_write_UINT32(s, STATUS_VALID_CLIENT); /* dwErrorCode */
|
||||
stream_write_UINT32(s, ST_NO_TRANSITION); /* dwStateTransition */
|
||||
|
||||
license_write_binary_blob(s, license->error_info);
|
||||
license_write_binary_blob(s, license->ErrorInfo);
|
||||
|
||||
return license_send(license, s, ERROR_ALERT);
|
||||
}
|
||||
@ -975,17 +1036,17 @@ rdpLicense* license_new(rdpRdp* rdp)
|
||||
license->rdp = rdp;
|
||||
license->state = LICENSE_STATE_AWAIT;
|
||||
license->certificate = certificate_new();
|
||||
license->product_info = license_new_product_info();
|
||||
license->error_info = license_new_binary_blob(BB_ERROR_BLOB);
|
||||
license->key_exchange_list = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB);
|
||||
license->server_certificate = license_new_binary_blob(BB_CERTIFICATE_BLOB);
|
||||
license->client_user_name = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB);
|
||||
license->client_machine_name = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB);
|
||||
license->platform_challenge = license_new_binary_blob(BB_ANY_BLOB);
|
||||
license->encrypted_platform_challenge = license_new_binary_blob(BB_ANY_BLOB);
|
||||
license->encrypted_premaster_secret = license_new_binary_blob(BB_ANY_BLOB);
|
||||
license->encrypted_hwid = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB);
|
||||
license->scope_list = license_new_scope_list();
|
||||
license->ProductInfo = license_new_product_info();
|
||||
license->ErrorInfo = license_new_binary_blob(BB_ERROR_BLOB);
|
||||
license->KeyExchangeList = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB);
|
||||
license->ServerCertificate = license_new_binary_blob(BB_CERTIFICATE_BLOB);
|
||||
license->ClientUserName = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB);
|
||||
license->ClientMachineName = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB);
|
||||
license->PlatformChallenge = license_new_binary_blob(BB_ANY_BLOB);
|
||||
license->EncryptedPlatformChallenge = license_new_binary_blob(BB_ANY_BLOB);
|
||||
license->EncryptedPremasterSecret = license_new_binary_blob(BB_ANY_BLOB);
|
||||
license->EncryptedHardwareId = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB);
|
||||
license->ScopeList = license_new_scope_list();
|
||||
license_generate_randoms(license);
|
||||
}
|
||||
|
||||
@ -1002,18 +1063,17 @@ void license_free(rdpLicense* license)
|
||||
if (license != NULL)
|
||||
{
|
||||
certificate_free(license->certificate);
|
||||
license_free_product_info(license->product_info);
|
||||
license_free_binary_blob(license->error_info);
|
||||
license_free_binary_blob(license->key_exchange_list);
|
||||
license_free_binary_blob(license->server_certificate);
|
||||
license_free_binary_blob(license->client_user_name);
|
||||
license_free_binary_blob(license->client_machine_name);
|
||||
license_free_binary_blob(license->platform_challenge);
|
||||
license_free_binary_blob(license->encrypted_platform_challenge);
|
||||
license_free_binary_blob(license->encrypted_premaster_secret);
|
||||
license_free_binary_blob(license->encrypted_hwid);
|
||||
license_free_scope_list(license->scope_list);
|
||||
license_free_product_info(license->ProductInfo);
|
||||
license_free_binary_blob(license->ErrorInfo);
|
||||
license_free_binary_blob(license->KeyExchangeList);
|
||||
license_free_binary_blob(license->ServerCertificate);
|
||||
license_free_binary_blob(license->ClientUserName);
|
||||
license_free_binary_blob(license->ClientMachineName);
|
||||
license_free_binary_blob(license->PlatformChallenge);
|
||||
license_free_binary_blob(license->EncryptedPlatformChallenge);
|
||||
license_free_binary_blob(license->EncryptedPremasterSecret);
|
||||
license_free_binary_blob(license->EncryptedHardwareId);
|
||||
license_free_scope_list(license->ScopeList);
|
||||
free(license);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,27 +133,27 @@ struct rdp_license
|
||||
LICENSE_STATE state;
|
||||
struct rdp_rdp* rdp;
|
||||
struct rdp_certificate* certificate;
|
||||
BYTE hwid[HWID_LENGTH];
|
||||
BYTE modulus[MODULUS_MAX_SIZE];
|
||||
BYTE exponent[EXPONENT_MAX_SIZE];
|
||||
BYTE client_random[CLIENT_RANDOM_LENGTH];
|
||||
BYTE server_random[SERVER_RANDOM_LENGTH];
|
||||
BYTE master_secret[MASTER_SECRET_LENGTH];
|
||||
BYTE premaster_secret[PREMASTER_SECRET_LENGTH];
|
||||
BYTE session_key_blob[SESSION_KEY_BLOB_LENGTH];
|
||||
BYTE mac_salt_key[MAC_SALT_KEY_LENGTH];
|
||||
BYTE licensing_encryption_key[LICENSING_ENCRYPTION_KEY_LENGTH];
|
||||
PRODUCT_INFO* product_info;
|
||||
LICENSE_BLOB* error_info;
|
||||
LICENSE_BLOB* key_exchange_list;
|
||||
LICENSE_BLOB* server_certificate;
|
||||
LICENSE_BLOB* client_user_name;
|
||||
LICENSE_BLOB* client_machine_name;
|
||||
LICENSE_BLOB* platform_challenge;
|
||||
LICENSE_BLOB* encrypted_premaster_secret;
|
||||
LICENSE_BLOB* encrypted_platform_challenge;
|
||||
LICENSE_BLOB* encrypted_hwid;
|
||||
SCOPE_LIST* scope_list;
|
||||
BYTE HardwareId[HWID_LENGTH];
|
||||
BYTE Modulus[MODULUS_MAX_SIZE];
|
||||
BYTE Exponent[EXPONENT_MAX_SIZE];
|
||||
BYTE ClientRandom[CLIENT_RANDOM_LENGTH];
|
||||
BYTE ServerRandom[SERVER_RANDOM_LENGTH];
|
||||
BYTE MasterSecret[MASTER_SECRET_LENGTH];
|
||||
BYTE PremasterSecret[PREMASTER_SECRET_LENGTH];
|
||||
BYTE SessionKeyBlob[SESSION_KEY_BLOB_LENGTH];
|
||||
BYTE MacSaltKey[MAC_SALT_KEY_LENGTH];
|
||||
BYTE LicensingEncryptionKey[LICENSING_ENCRYPTION_KEY_LENGTH];
|
||||
PRODUCT_INFO* ProductInfo;
|
||||
LICENSE_BLOB* ErrorInfo;
|
||||
LICENSE_BLOB* KeyExchangeList;
|
||||
LICENSE_BLOB* ServerCertificate;
|
||||
LICENSE_BLOB* ClientUserName;
|
||||
LICENSE_BLOB* ClientMachineName;
|
||||
LICENSE_BLOB* PlatformChallenge;
|
||||
LICENSE_BLOB* EncryptedPremasterSecret;
|
||||
LICENSE_BLOB* EncryptedPlatformChallenge;
|
||||
LICENSE_BLOB* EncryptedHardwareId;
|
||||
SCOPE_LIST* ScopeList;
|
||||
};
|
||||
|
||||
BOOL license_recv(rdpLicense* license, STREAM* s);
|
||||
|
Loading…
Reference in New Issue
Block a user