libfreerdp-core: cleanup licensing RSA public key code

This commit is contained in:
Marc-André Moreau 2013-02-05 10:02:06 -05:00
parent 0de89ab4c9
commit 593a9030d3
2 changed files with 22 additions and 27 deletions

View File

@ -385,52 +385,52 @@ void license_generate_hwid(rdpLicense* license)
crypto_md5_final(md5, &license->HardwareId[HWID_PLATFORM_ID_LENGTH]); crypto_md5_final(md5, &license->HardwareId[HWID_PLATFORM_ID_LENGTH]);
} }
void license_encrypt_premaster_secret(rdpLicense* license) void license_get_server_rsa_public_key(rdpLicense* license)
{ {
BYTE* Exponent; BYTE* Exponent;
BYTE* Modulus; BYTE* Modulus;
int ModulusLength; int ModulusLength;
rdpSettings* settings;
rdpCertificate* certificate;
BYTE* EncryptedPremasterSecret;
if (license->ServerCertificate->length) if (license->ServerCertificate->length < 1)
{ {
certificate = license->certificate; certificate_read_server_certificate(license->certificate,
} license->rdp->settings->ServerCertificate,
else license->rdp->settings->ServerCertificateLength);
{
settings = license->rdp->settings;
certificate = license->certificate;
certificate_read_server_certificate(certificate, settings->ServerCertificate, settings->ServerCertificateLength);
} }
Exponent = certificate->cert_info.exponent; Exponent = license->certificate->cert_info.exponent;
Modulus = certificate->cert_info.Modulus; Modulus = license->certificate->cert_info.Modulus;
ModulusLength = certificate->cert_info.ModulusLength; ModulusLength = license->certificate->cert_info.ModulusLength;
CopyMemory(license->Exponent, Exponent, 4); CopyMemory(license->Exponent, Exponent, 4);
license->ModulusLength = ModulusLength; license->ModulusLength = ModulusLength;
license->Modulus = (BYTE*) malloc(ModulusLength); license->Modulus = (BYTE*) malloc(ModulusLength);
ZeroMemory(license->Modulus, ModulusLength); ZeroMemory(license->Modulus, ModulusLength);
}
void license_encrypt_premaster_secret(rdpLicense* license)
{
BYTE* EncryptedPremasterSecret;
license_get_server_rsa_public_key(license);
#ifdef WITH_DEBUG_LICENSE #ifdef WITH_DEBUG_LICENSE
printf("Modulus (%d bits):\n", ModulusLength * 8); printf("Modulus (%d bits):\n", license->ModulusLength * 8);
winpr_HexDump(Modulus, ModulusLength); winpr_HexDump(license->Modulus, license->ModulusLength);
printf("\n"); printf("\n");
printf("Exponent:\n"); printf("Exponent:\n");
winpr_HexDump(Exponent, 4); winpr_HexDump(license->Exponent, 4);
printf("\n"); printf("\n");
#endif #endif
EncryptedPremasterSecret = (BYTE*) malloc(ModulusLength); EncryptedPremasterSecret = (BYTE*) malloc(license->ModulusLength);
ZeroMemory(EncryptedPremasterSecret, ModulusLength); ZeroMemory(EncryptedPremasterSecret, license->ModulusLength);
#ifndef LICENSE_NULL_PREMASTER_SECRET #ifndef LICENSE_NULL_PREMASTER_SECRET
crypto_rsa_public_encrypt(license->PremasterSecret, PREMASTER_SECRET_LENGTH, crypto_rsa_public_encrypt(license->PremasterSecret, PREMASTER_SECRET_LENGTH,
ModulusLength, Modulus, Exponent, EncryptedPremasterSecret); license->ModulusLength, license->Modulus, license->Exponent, EncryptedPremasterSecret);
#endif #endif
license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB; license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB;

View File

@ -146,6 +146,7 @@ void crypto_hmac_free(CryptoHmac hmac)
{ {
if (hmac == NULL) if (hmac == NULL)
return; return;
HMAC_CTX_cleanup(&hmac->hmac_ctx); HMAC_CTX_cleanup(&hmac->hmac_ctx);
free(hmac); free(hmac);
} }
@ -258,37 +259,31 @@ static void crypto_rsa_public(const BYTE* input, int length, UINT32 key_length,
static void crypto_rsa_private(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output) static void crypto_rsa_private(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{ {
crypto_rsa_common(input, length, key_length, modulus, private_exponent, key_length, output); crypto_rsa_common(input, length, key_length, modulus, private_exponent, key_length, output);
} }
void crypto_rsa_public_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* exponent, BYTE* output) void crypto_rsa_public_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* exponent, BYTE* output)
{ {
crypto_rsa_public(input, length, key_length, modulus, exponent, output); crypto_rsa_public(input, length, key_length, modulus, exponent, output);
} }
void crypto_rsa_public_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* exponent, BYTE* output) void crypto_rsa_public_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* exponent, BYTE* output)
{ {
crypto_rsa_public(input, length, key_length, modulus, exponent, output); crypto_rsa_public(input, length, key_length, modulus, exponent, output);
} }
void crypto_rsa_private_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output) void crypto_rsa_private_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{ {
crypto_rsa_private(input, length, key_length, modulus, private_exponent, output); crypto_rsa_private(input, length, key_length, modulus, private_exponent, output);
} }
void crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output) void crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{ {
crypto_rsa_private(input, length, key_length, modulus, private_exponent, output); crypto_rsa_private(input, length, key_length, modulus, private_exponent, output);
} }
void crypto_rsa_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output) void crypto_rsa_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{ {
crypto_rsa_common(input, length, key_length, modulus, private_exponent, key_length, output); crypto_rsa_common(input, length, key_length, modulus, private_exponent, key_length, output);
} }