2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-12 04:46:03 +04:00
|
|
|
* RDP Licensing
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-09-03 05:34:51 +04:00
|
|
|
#include "redirection.h"
|
2012-02-17 09:58:30 +04:00
|
|
|
#include "certificate.h"
|
2011-09-03 05:34:51 +04:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
#include "license.h"
|
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
|
|
|
static const char* const LICENSE_MESSAGE_STRINGS[] =
|
2011-08-08 07:59:28 +04:00
|
|
|
{
|
|
|
|
"",
|
|
|
|
"License Request",
|
|
|
|
"Platform Challenge",
|
|
|
|
"New License",
|
|
|
|
"Upgrade License",
|
|
|
|
"", "", "", "", "", "",
|
|
|
|
"", "", "", "", "", "",
|
|
|
|
"",
|
|
|
|
"License Info",
|
|
|
|
"New License Request",
|
|
|
|
"",
|
|
|
|
"Platform Challenge Response",
|
|
|
|
"", "", "", "", "", "", "", "", "",
|
|
|
|
"Error Alert"
|
|
|
|
};
|
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
static const char* const error_codes[] =
|
2011-07-15 10:02:09 +04:00
|
|
|
{
|
|
|
|
"ERR_UNKNOWN",
|
|
|
|
"ERR_INVALID_SERVER_CERTIFICATE",
|
|
|
|
"ERR_NO_LICENSE",
|
|
|
|
"ERR_INVALID_MAC",
|
|
|
|
"ERR_INVALID_SCOPE",
|
|
|
|
"ERR_UNKNOWN",
|
|
|
|
"ERR_NO_LICENSE_SERVER",
|
|
|
|
"STATUS_VALID_CLIENT",
|
|
|
|
"ERR_INVALID_CLIENT",
|
|
|
|
"ERR_UNKNOWN",
|
|
|
|
"ERR_UNKNOWN",
|
|
|
|
"ERR_INVALID_PRODUCT_ID",
|
|
|
|
"ERR_INVALID_MESSAGE_LENGTH"
|
|
|
|
};
|
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
static const char* const state_transitions[] =
|
2011-07-15 10:02:09 +04:00
|
|
|
{
|
|
|
|
"ST_UNKNOWN",
|
|
|
|
"ST_TOTAL_ABORT",
|
|
|
|
"ST_NO_TRANSITION",
|
|
|
|
"ST_RESET_PHASE_TO_START",
|
|
|
|
"ST_RESEND_LAST_MESSAGE"
|
|
|
|
};
|
2011-11-30 05:15:50 +04:00
|
|
|
#endif
|
2011-07-15 10:02:09 +04:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Read a licensing preamble.\n
|
|
|
|
* @msdn{cc240480}
|
|
|
|
* @param s stream
|
|
|
|
* @param bMsgType license message type
|
|
|
|
* @param flags message flags
|
|
|
|
* @param wMsgSize message size
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void license_read_preamble(STREAM* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgSize)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
|
|
|
/* preamble (4 bytes) */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, *bMsgType); /* bMsgType (1 byte) */
|
|
|
|
stream_read_BYTE(s, *flags); /* flags (1 byte) */
|
|
|
|
stream_read_UINT16(s, *wMsgSize); /* wMsgSize (2 bytes) */
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a licensing preamble.\n
|
|
|
|
* @msdn{cc240480}
|
|
|
|
* @param s stream
|
|
|
|
* @param bMsgType license message type
|
|
|
|
* @param flags message flags
|
|
|
|
* @param wMsgSize message size
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void license_write_preamble(STREAM* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSize)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
|
|
|
/* preamble (4 bytes) */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, bMsgType); /* bMsgType (1 byte) */
|
|
|
|
stream_write_BYTE(s, flags); /* flags (1 byte) */
|
|
|
|
stream_write_UINT16(s, wMsgSize); /* wMsgSize (2 bytes) */
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize a license packet stream.\n
|
|
|
|
* @param license license module
|
|
|
|
* @return stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
STREAM* license_send_stream_init(rdpLicense* license)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
s = transport_send_stream_init(license->rdp->transport, 4096);
|
2012-01-25 14:12:37 +04:00
|
|
|
stream_seek(s, LICENSE_PACKET_HEADER_MAX_LENGTH);
|
2011-07-12 09:16:59 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an RDP licensing packet.\n
|
|
|
|
* @msdn{cc240479}
|
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL license_send(rdpLicense* license, STREAM* s, BYTE type)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
|
|
|
int length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags;
|
|
|
|
UINT16 wMsgSize;
|
|
|
|
UINT16 sec_flags;
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
DEBUG_LICENSE("Sending %s Packet", LICENSE_MESSAGE_STRINGS[type & 0x1F]);
|
2011-08-08 07:59:28 +04:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
length = stream_get_length(s);
|
|
|
|
stream_set_pos(s, 0);
|
|
|
|
|
|
|
|
sec_flags = SEC_LICENSE_PKT;
|
2012-01-25 14:12:37 +04:00
|
|
|
wMsgSize = length - LICENSE_PACKET_HEADER_MAX_LENGTH + 4;
|
2011-08-21 06:57:01 +04:00
|
|
|
/**
|
|
|
|
* Using EXTENDED_ERROR_MSG_SUPPORTED here would cause mstsc to crash when
|
|
|
|
* running in server mode! This flag seems to be incorrectly documented.
|
|
|
|
*/
|
|
|
|
flags = PREAMBLE_VERSION_3_0;
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2011-08-03 08:34:55 +04:00
|
|
|
rdp_write_header(license->rdp, s, length, MCS_GLOBAL_CHANNEL_ID);
|
2011-07-12 09:16:59 +04:00
|
|
|
rdp_write_security_header(s, sec_flags);
|
2011-07-15 10:02:09 +04:00
|
|
|
license_write_preamble(s, type, flags, wMsgSize);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2011-08-08 20:57:19 +04:00
|
|
|
printf("Sending %s Packet, length %d\n", LICENSE_MESSAGE_STRINGS[type & 0x1F], wMsgSize);
|
|
|
|
freerdp_hexdump(s->p - 4, wMsgSize);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2011-08-08 20:57:19 +04:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
stream_set_pos(s, length);
|
2011-08-22 11:03:58 +04:00
|
|
|
if (transport_write(license->rdp->transport, s) < 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
|
|
|
* Receive an RDP licensing packet.\n
|
|
|
|
* @msdn{cc240479}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL license_recv(rdpLicense* license, STREAM* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 length;
|
|
|
|
UINT16 channelId;
|
|
|
|
UINT16 sec_flags;
|
|
|
|
BYTE flags;
|
|
|
|
BYTE bMsgType;
|
|
|
|
UINT16 wMsgSize;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
if (!rdp_read_header(license->rdp, s, &length, &channelId))
|
|
|
|
{
|
|
|
|
printf("Incorrect RDP header.\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-22 11:03:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rdp_read_security_header(s, &sec_flags);
|
|
|
|
if (!(sec_flags & SEC_LICENSE_PKT))
|
|
|
|
{
|
2011-09-03 05:34:51 +04:00
|
|
|
stream_rewind(s, RDP_SECURITY_HEADER_LENGTH);
|
2012-10-09 10:31:28 +04:00
|
|
|
if (rdp_recv_out_of_sequence_pdu(license->rdp, s) != TRUE)
|
2011-09-03 05:34:51 +04:00
|
|
|
{
|
|
|
|
printf("Unexpected license packet.\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-03 05:34:51 +04:00
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-22 11:03:58 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
license_read_preamble(s, &bMsgType, &flags, &wMsgSize); /* preamble (4 bytes) */
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2011-08-08 07:59:28 +04:00
|
|
|
DEBUG_LICENSE("Receiving %s Packet", LICENSE_MESSAGE_STRINGS[bMsgType & 0x1F]);
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
switch (bMsgType)
|
|
|
|
{
|
|
|
|
case LICENSE_REQUEST:
|
|
|
|
license_read_license_request_packet(license, s);
|
2011-07-12 09:16:59 +04:00
|
|
|
license_send_new_license_request_packet(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLATFORM_CHALLENGE:
|
|
|
|
license_read_platform_challenge_packet(license, s);
|
2011-07-12 09:57:09 +04:00
|
|
|
license_send_platform_challenge_response_packet(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NEW_LICENSE:
|
|
|
|
license_read_new_license_packet(license, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UPGRADE_LICENSE:
|
|
|
|
license_read_upgrade_license_packet(license, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERROR_ALERT:
|
|
|
|
license_read_error_alert_packet(license, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("invalid bMsgType:%d\n", bMsgType);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
2011-07-13 19:40:19 +04:00
|
|
|
void license_generate_randoms(rdpLicense* license)
|
|
|
|
{
|
2011-08-08 20:57:19 +04:00
|
|
|
#if 0
|
2011-07-13 19:40:19 +04:00
|
|
|
crypto_nonce(license->client_random, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
|
|
|
crypto_nonce(license->premaster_secret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
2011-08-08 20:57:19 +04:00
|
|
|
#else
|
|
|
|
memset(license->client_random, 0, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
|
|
|
memset(license->premaster_secret, 0, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
|
|
|
#endif
|
2011-07-13 19:40:19 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:57:09 +04:00
|
|
|
/**
|
|
|
|
* Generate License Cryptographic Keys.
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_generate_keys(rdpLicense* license)
|
|
|
|
{
|
2011-07-12 23:10:43 +04:00
|
|
|
security_master_secret(license->premaster_secret, license->client_random,
|
|
|
|
license->server_random, license->master_secret); /* MasterSecret */
|
|
|
|
|
|
|
|
security_session_key_blob(license->master_secret, license->client_random,
|
|
|
|
license->server_random, license->session_key_blob); /* SessionKeyBlob */
|
|
|
|
|
|
|
|
security_mac_salt_key(license->session_key_blob, license->client_random,
|
|
|
|
license->server_random, license->mac_salt_key); /* MacSaltKey */
|
|
|
|
|
|
|
|
security_licensing_encryption_key(license->session_key_blob, license->client_random,
|
|
|
|
license->server_random, license->licensing_encryption_key); /* LicensingEncryptionKey */
|
2011-08-08 20:57:19 +04:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2011-08-08 20:57:19 +04:00
|
|
|
printf("ClientRandom:\n");
|
|
|
|
freerdp_hexdump(license->client_random, CLIENT_RANDOM_LENGTH);
|
|
|
|
|
|
|
|
printf("ServerRandom:\n");
|
|
|
|
freerdp_hexdump(license->server_random, SERVER_RANDOM_LENGTH);
|
|
|
|
|
|
|
|
printf("PremasterSecret:\n");
|
|
|
|
freerdp_hexdump(license->premaster_secret, PREMASTER_SECRET_LENGTH);
|
|
|
|
|
|
|
|
printf("MasterSecret:\n");
|
|
|
|
freerdp_hexdump(license->master_secret, MASTER_SECRET_LENGTH);
|
|
|
|
|
|
|
|
printf("SessionKeyBlob:\n");
|
2011-08-25 00:54:32 +04:00
|
|
|
freerdp_hexdump(license->session_key_blob, SESSION_KEY_BLOB_LENGTH);
|
2011-08-08 20:57:19 +04:00
|
|
|
|
|
|
|
printf("MacSaltKey:\n");
|
|
|
|
freerdp_hexdump(license->mac_salt_key, MAC_SALT_KEY_LENGTH);
|
|
|
|
|
|
|
|
printf("LicensingEncryptionKey:\n");
|
|
|
|
freerdp_hexdump(license->licensing_encryption_key, LICENSING_ENCRYPTION_KEY_LENGTH);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2011-07-12 09:57:09 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 10:53:26 +04:00
|
|
|
/**
|
|
|
|
* Generate Unique Hardware Identifier (CLIENT_HARDWARE_ID).\n
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_generate_hwid(rdpLicense* license)
|
|
|
|
{
|
|
|
|
CryptoMd5 md5;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* mac_address;
|
2011-07-12 10:53:26 +04:00
|
|
|
|
2011-07-12 23:10:43 +04:00
|
|
|
memset(license->hwid, 0, HWID_LENGTH);
|
2012-11-15 05:46:51 +04:00
|
|
|
mac_address = license->rdp->transport->TcpIn->mac_address;
|
2011-07-12 10:53:26 +04:00
|
|
|
|
|
|
|
md5 = crypto_md5_init();
|
|
|
|
crypto_md5_update(md5, mac_address, 6);
|
2011-07-12 23:10:43 +04:00
|
|
|
crypto_md5_final(md5, &license->hwid[HWID_PLATFORM_ID_LENGTH]);
|
2011-07-12 10:53:26 +04:00
|
|
|
}
|
|
|
|
|
2011-07-15 09:11:09 +04:00
|
|
|
void license_encrypt_premaster_secret(rdpLicense* license)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* encrypted_premaster_secret;
|
2011-09-17 00:37:20 +04:00
|
|
|
#if 0
|
2011-07-15 09:11:09 +04:00
|
|
|
int key_length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* modulus;
|
|
|
|
BYTE* exponent;
|
2011-09-17 00:37:20 +04:00
|
|
|
rdpCertificate *certificate;
|
2011-07-15 09:11:09 +04:00
|
|
|
|
2011-09-17 00:37:20 +04:00
|
|
|
if (license->server_certificate->length)
|
|
|
|
certificate = license->certificate;
|
|
|
|
else
|
|
|
|
certificate = license->rdp->settings->server_cert;
|
|
|
|
|
|
|
|
exponent = certificate->cert_info.exponent;
|
|
|
|
modulus = certificate->cert_info.modulus.data;
|
|
|
|
key_length = certificate->cert_info.modulus.length;
|
2011-07-15 09:11:09 +04:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2011-08-08 20:57:19 +04:00
|
|
|
printf("modulus (%d bits):\n", key_length * 8);
|
|
|
|
freerdp_hexdump(modulus, key_length);
|
|
|
|
|
|
|
|
printf("exponent:\n");
|
|
|
|
freerdp_hexdump(exponent, 4);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2011-08-08 20:57:19 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
encrypted_premaster_secret = (BYTE*) malloc(MODULUS_MAX_SIZE);
|
2011-07-15 09:11:09 +04:00
|
|
|
memset(encrypted_premaster_secret, 0, MODULUS_MAX_SIZE);
|
|
|
|
|
2012-01-19 07:40:29 +04:00
|
|
|
crypto_rsa_public_encrypt(license->premaster_secret, PREMASTER_SECRET_LENGTH,
|
2011-07-15 09:11:09 +04:00
|
|
|
key_length, modulus, exponent, encrypted_premaster_secret);
|
|
|
|
|
2011-09-19 19:44:13 +04:00
|
|
|
license->encrypted_premaster_secret->type = BB_RANDOM_BLOB;
|
2011-07-15 09:11:09 +04:00
|
|
|
license->encrypted_premaster_secret->length = PREMASTER_SECRET_LENGTH;
|
|
|
|
license->encrypted_premaster_secret->data = encrypted_premaster_secret;
|
2011-08-08 20:57:19 +04:00
|
|
|
#else
|
2012-10-09 11:01:37 +04:00
|
|
|
encrypted_premaster_secret = (BYTE*) malloc(MODULUS_MAX_SIZE);
|
2011-08-08 20:57:19 +04:00
|
|
|
memset(encrypted_premaster_secret, 0, MODULUS_MAX_SIZE);
|
|
|
|
|
2011-09-19 19:44:13 +04:00
|
|
|
license->encrypted_premaster_secret->type = BB_RANDOM_BLOB;
|
|
|
|
license->encrypted_premaster_secret->length = PREMASTER_SECRET_LENGTH;
|
2011-08-08 20:57:19 +04:00
|
|
|
license->encrypted_premaster_secret->data = encrypted_premaster_secret;
|
|
|
|
#endif
|
2011-07-15 09:11:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void license_decrypt_platform_challenge(rdpLicense* license)
|
|
|
|
{
|
|
|
|
CryptoRc4 rc4;
|
|
|
|
|
|
|
|
license->platform_challenge->data =
|
2012-10-09 11:01:37 +04:00
|
|
|
(BYTE*) malloc(license->encrypted_platform_challenge->length);
|
2011-07-15 09:11:09 +04:00
|
|
|
license->platform_challenge->length =
|
|
|
|
license->encrypted_platform_challenge->length;
|
|
|
|
|
|
|
|
rc4 = crypto_rc4_init(license->licensing_encryption_key, LICENSING_ENCRYPTION_KEY_LENGTH);
|
|
|
|
|
|
|
|
crypto_rc4(rc4, license->encrypted_platform_challenge->length,
|
|
|
|
license->encrypted_platform_challenge->data,
|
|
|
|
license->platform_challenge->data);
|
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2011-07-15 09:11:09 +04:00
|
|
|
printf("encrypted_platform challenge:\n");
|
|
|
|
freerdp_hexdump(license->encrypted_platform_challenge->data,
|
|
|
|
license->encrypted_platform_challenge->length);
|
|
|
|
|
|
|
|
printf("platform challenge:\n");
|
|
|
|
freerdp_hexdump(license->platform_challenge->data, license->platform_challenge->length);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
crypto_rc4_free(rc4);
|
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2011-07-12 09:16:59 +04:00
|
|
|
* Read Product Information (PRODUCT_INFO).\n
|
|
|
|
* @msdn{cc241915}
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param productInfo product information
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
productInfo->pbCompanyName = (BYTE*) malloc(productInfo->cbCompanyName);
|
2011-07-12 04:46:03 +04:00
|
|
|
stream_read(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
productInfo->pbProductId = (BYTE*) malloc(productInfo->cbProductId);
|
2011-07-12 04:46:03 +04:00
|
|
|
stream_read(s, productInfo->pbProductId, productInfo->cbProductId);
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Allocate New Product Information (PRODUCT_INFO).\n
|
|
|
|
* @msdn{cc241915}
|
|
|
|
* @return new product information
|
|
|
|
*/
|
|
|
|
|
|
|
|
PRODUCT_INFO* license_new_product_info()
|
|
|
|
{
|
|
|
|
PRODUCT_INFO* productInfo;
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
productInfo = (PRODUCT_INFO*) malloc(sizeof(PRODUCT_INFO));
|
2011-07-12 09:16:59 +04:00
|
|
|
|
|
|
|
productInfo->dwVersion = 0;
|
|
|
|
productInfo->cbCompanyName = 0;
|
|
|
|
productInfo->pbCompanyName = NULL;
|
|
|
|
productInfo->cbProductId = 0;
|
|
|
|
productInfo->pbProductId = NULL;
|
|
|
|
|
|
|
|
return productInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free Product Information (PRODUCT_INFO).\n
|
|
|
|
* @msdn{cc241915}
|
|
|
|
* @param productInfo product information
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_free_product_info(PRODUCT_INFO* productInfo)
|
|
|
|
{
|
|
|
|
if (productInfo->pbCompanyName != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(productInfo->pbCompanyName);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
|
|
|
if (productInfo->pbProductId != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(productInfo->pbProductId);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(productInfo);
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read License Binary Blob (LICENSE_BINARY_BLOB).\n
|
|
|
|
* @msdn{cc240481}
|
|
|
|
* @param s stream
|
|
|
|
* @param blob license binary blob
|
|
|
|
*/
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
void license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wBlobType;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, wBlobType); /* wBlobType (2 bytes) */
|
|
|
|
stream_read_UINT16(s, blob->length); /* wBlobLen (2 bytes) */
|
2011-09-17 00:37:20 +04:00
|
|
|
|
|
|
|
/*
|
2011-10-08 20:39:35 +04:00
|
|
|
* Server can choose to not send data by setting len to 0.
|
2011-09-17 00:37:20 +04:00
|
|
|
* If so, it may not bother to set the type, so shortcut the warning
|
|
|
|
*/
|
2011-10-08 20:39:35 +04:00
|
|
|
if (blob->type != BB_ANY_BLOB && blob->length == 0)
|
2011-09-17 00:37:20 +04:00
|
|
|
return;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
if (blob->type != wBlobType && blob->type != BB_ANY_BLOB)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2011-09-17 00:37:20 +04:00
|
|
|
printf("license binary blob type (%x) does not match expected type (%x).\n", wBlobType, blob->type);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
blob->type = wBlobType;
|
2012-10-09 11:01:37 +04:00
|
|
|
blob->data = (BYTE*) malloc(blob->length);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
stream_read(s, blob->data, blob->length); /* blobData */
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Write License Binary Blob (LICENSE_BINARY_BLOB).\n
|
|
|
|
* @msdn{cc240481}
|
|
|
|
* @param s stream
|
|
|
|
* @param blob license binary blob
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_write_binary_blob(STREAM* s, LICENSE_BLOB* blob)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
|
|
|
|
stream_write_UINT16(s, blob->length); /* wBlobLen (2 bytes) */
|
2011-07-12 09:16:59 +04:00
|
|
|
|
|
|
|
if (blob->length > 0)
|
|
|
|
stream_write(s, blob->data, blob->length); /* blobData */
|
|
|
|
}
|
|
|
|
|
2011-07-15 09:11:09 +04:00
|
|
|
void license_write_padded_binary_blob(STREAM* s, LICENSE_BLOB* blob)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 pad_len;
|
2011-09-19 19:44:13 +04:00
|
|
|
|
|
|
|
pad_len = 72 % blob->length;
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
|
|
|
|
stream_write_UINT16(s, blob->length + pad_len); /* wBlobLen (2 bytes) */
|
2011-07-15 09:11:09 +04:00
|
|
|
|
|
|
|
if (blob->length > 0)
|
|
|
|
stream_write(s, blob->data, blob->length); /* blobData */
|
|
|
|
|
2011-09-19 19:44:13 +04:00
|
|
|
stream_write_zero(s, pad_len);
|
2011-07-15 09:11:09 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Allocate New License Binary Blob (LICENSE_BINARY_BLOB).\n
|
|
|
|
* @msdn{cc240481}
|
|
|
|
* @return new license binary blob
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
LICENSE_BLOB* license_new_binary_blob(UINT16 type)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
|
|
|
LICENSE_BLOB* blob;
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
blob = (LICENSE_BLOB*) malloc(sizeof(LICENSE_BLOB));
|
2011-07-12 09:16:59 +04:00
|
|
|
blob->type = type;
|
|
|
|
blob->length = 0;
|
|
|
|
blob->data = NULL;
|
|
|
|
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free License Binary Blob (LICENSE_BINARY_BLOB).\n
|
|
|
|
* @msdn{cc240481}
|
|
|
|
* @param blob license binary blob
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_free_binary_blob(LICENSE_BLOB* blob)
|
|
|
|
{
|
|
|
|
if (blob->data != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(blob->data);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(blob);
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read License Scope List (SCOPE_LIST).\n
|
|
|
|
* @msdn{cc241916}
|
|
|
|
* @param s stream
|
|
|
|
* @param scopeList scope list
|
|
|
|
*/
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
void license_read_scope_list(STREAM* s, SCOPE_LIST* scopeList)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 i;
|
|
|
|
UINT32 scopeCount;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, scopeCount); /* ScopeCount (4 bytes) */
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
scopeList->count = scopeCount;
|
2012-10-09 07:21:26 +04:00
|
|
|
scopeList->array = (LICENSE_BLOB*) malloc(sizeof(LICENSE_BLOB) * scopeCount);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ScopeArray */
|
|
|
|
for (i = 0; i < scopeCount; i++)
|
|
|
|
{
|
|
|
|
scopeList->array[i].type = BB_SCOPE_BLOB;
|
|
|
|
license_read_binary_blob(s, &scopeList->array[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Allocate New License Scope List (SCOPE_LIST).\n
|
|
|
|
* @msdn{cc241916}
|
|
|
|
* @return new scope list
|
|
|
|
*/
|
|
|
|
|
|
|
|
SCOPE_LIST* license_new_scope_list()
|
|
|
|
{
|
|
|
|
SCOPE_LIST* scopeList;
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
scopeList = (SCOPE_LIST*) malloc(sizeof(SCOPE_LIST));
|
2011-07-12 09:16:59 +04:00
|
|
|
scopeList->count = 0;
|
|
|
|
scopeList->array = NULL;
|
|
|
|
|
|
|
|
return scopeList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free License Scope List (SCOPE_LIST).\n
|
|
|
|
* @msdn{cc241916}
|
|
|
|
* @param scopeList scope list
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_free_scope_list(SCOPE_LIST* scopeList)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 i;
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2012-05-16 17:29:35 +04:00
|
|
|
/*
|
|
|
|
* We must NOT call license_free_binary_blob() on each scopelist->array[i] element,
|
2012-10-09 07:21:26 +04:00
|
|
|
* because scopelist->array was allocated at once, by a single call to malloc. The elements
|
2012-05-16 17:29:35 +04:00
|
|
|
* it contains cannot be deallocated separately then.
|
|
|
|
* To make things clean, we must deallocate each scopelist->array[].data,
|
2012-10-09 07:21:26 +04:00
|
|
|
* and finish by deallocating scopelist->array with a single call to free().
|
2012-05-16 17:29:35 +04:00
|
|
|
*/
|
2011-07-12 09:16:59 +04:00
|
|
|
for (i = 0; i < scopeList->count; i++)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(scopeList->array[i].data);
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(scopeList->array) ;
|
|
|
|
free(scopeList);
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
|
|
|
* Read a LICENSE_REQUEST packet.\n
|
|
|
|
* @msdn{cc241914}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_read_license_request_packet(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
|
|
|
/* ServerRandom (32 bytes) */
|
|
|
|
stream_read(s, license->server_random, 32);
|
|
|
|
|
|
|
|
/* ProductInfo */
|
2011-07-12 09:16:59 +04:00
|
|
|
license_read_product_info(s, license->product_info);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* KeyExchangeList */
|
2011-07-12 09:16:59 +04:00
|
|
|
license_read_binary_blob(s, license->key_exchange_list);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ServerCertificate */
|
2011-07-12 09:16:59 +04:00
|
|
|
license_read_binary_blob(s, license->server_certificate);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ScopeList */
|
2011-07-12 09:16:59 +04:00
|
|
|
license_read_scope_list(s, license->scope_list);
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
/* Parse Server Certificate */
|
|
|
|
certificate_read_server_certificate(license->certificate,
|
|
|
|
license->server_certificate->data, license->server_certificate->length);
|
2011-07-13 18:21:12 +04:00
|
|
|
|
|
|
|
license_generate_keys(license);
|
|
|
|
license_generate_hwid(license);
|
2011-07-15 09:11:09 +04:00
|
|
|
license_encrypt_premaster_secret(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a PLATFORM_CHALLENGE packet.\n
|
|
|
|
* @msdn{cc241921}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_read_platform_challenge_packet(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Receiving Platform Challenge Packet");
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2011-07-12 09:57:09 +04:00
|
|
|
stream_seek(s, 4); /* ConnectFlags, Reserved (4 bytes) */
|
|
|
|
|
|
|
|
/* EncryptedPlatformChallenge */
|
2011-07-13 19:40:19 +04:00
|
|
|
license->encrypted_platform_challenge->type = BB_ANY_BLOB;
|
2011-07-13 18:21:12 +04:00
|
|
|
license_read_binary_blob(s, license->encrypted_platform_challenge);
|
2011-07-13 19:40:19 +04:00
|
|
|
license->encrypted_platform_challenge->type = BB_ENCRYPTED_DATA_BLOB;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2011-07-12 09:57:09 +04:00
|
|
|
/* MACData (16 bytes) */
|
2011-07-13 18:21:12 +04:00
|
|
|
stream_seek(s, 16);
|
|
|
|
|
2011-07-15 09:11:09 +04:00
|
|
|
license_decrypt_platform_challenge(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a NEW_LICENSE packet.\n
|
|
|
|
* @msdn{cc241926}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_read_new_license_packet(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Receiving New License Packet");
|
2011-08-08 22:32:18 +04:00
|
|
|
license->state = LICENSE_STATE_COMPLETED;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read an UPGRADE_LICENSE packet.\n
|
|
|
|
* @msdn{cc241924}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_read_upgrade_license_packet(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Receiving Upgrade License Packet");
|
2011-08-08 22:32:18 +04:00
|
|
|
license->state = LICENSE_STATE_COMPLETED;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read an ERROR_ALERT packet.\n
|
|
|
|
* @msdn{cc240482}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_read_error_alert_packet(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwErrorCode;
|
|
|
|
UINT32 dwStateTransition;
|
2011-07-15 10:02:09 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, dwErrorCode); /* dwErrorCode (4 bytes) */
|
|
|
|
stream_read_UINT32(s, dwStateTransition); /* dwStateTransition (4 bytes) */
|
2011-07-15 10:02:09 +04:00
|
|
|
license_read_binary_blob(s, license->error_info); /* bbErrorInfo */
|
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2011-07-15 10:02:09 +04:00
|
|
|
printf("dwErrorCode: %s, dwStateTransition: %s\n",
|
|
|
|
error_codes[dwErrorCode], state_transitions[dwStateTransition]);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2011-07-15 10:02:09 +04:00
|
|
|
|
|
|
|
if (dwErrorCode == STATUS_VALID_CLIENT)
|
|
|
|
{
|
|
|
|
license->state = LICENSE_STATE_COMPLETED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dwStateTransition)
|
|
|
|
{
|
|
|
|
case ST_TOTAL_ABORT:
|
|
|
|
license->state = LICENSE_STATE_ABORTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_NO_TRANSITION:
|
|
|
|
license->state = LICENSE_STATE_COMPLETED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_RESET_PHASE_TO_START:
|
|
|
|
license->state = LICENSE_STATE_AWAIT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_RESEND_LAST_MESSAGE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Write Platform ID.\n
|
|
|
|
* @msdn{cc241918}
|
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_write_platform_id(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 0); /* Client Operating System Version */
|
|
|
|
stream_write_BYTE(s, 0); /* Independent Software Vendor (ISV) */
|
|
|
|
stream_write_UINT16(s, 0); /* Client Software Build */
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a NEW_LICENSE_REQUEST packet.\n
|
|
|
|
* @msdn{cc241918}
|
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_write_new_license_request_packet(rdpLicense* license, STREAM* s)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, KEY_EXCHANGE_ALG_RSA); /* PreferredKeyExchangeAlg (4 bytes) */
|
2011-07-12 09:16:59 +04:00
|
|
|
license_write_platform_id(license, s); /* PlatformId (4 bytes) */
|
|
|
|
stream_write(s, license->client_random, 32); /* ClientRandom (32 bytes) */
|
2011-07-15 09:11:09 +04:00
|
|
|
license_write_padded_binary_blob(s, license->encrypted_premaster_secret); /* EncryptedPremasterSecret */
|
2011-07-12 09:16:59 +04:00
|
|
|
license_write_binary_blob(s, license->client_user_name); /* ClientUserName */
|
|
|
|
license_write_binary_blob(s, license->client_machine_name); /* ClientMachineName */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a NEW_LICENSE_REQUEST packet.\n
|
|
|
|
* @msdn{cc241918}
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_send_new_license_request_packet(rdpLicense* license)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-10-05 03:06:39 +04:00
|
|
|
char* username;
|
2011-07-12 09:16:59 +04:00
|
|
|
|
|
|
|
s = license_send_stream_init(license);
|
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (license->rdp->settings->Username != NULL)
|
|
|
|
username = license->rdp->settings->Username;
|
2011-10-05 03:06:39 +04:00
|
|
|
else
|
|
|
|
username = "username";
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
license->client_user_name->data = (BYTE*) username;
|
2011-10-05 03:06:39 +04:00
|
|
|
license->client_user_name->length = strlen(username) + 1;
|
2011-07-12 09:57:09 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
license->client_machine_name->data = (BYTE*) license->rdp->settings->ClientHostname;
|
|
|
|
license->client_machine_name->length = strlen(license->rdp->settings->ClientHostname) + 1;
|
2011-07-12 09:57:09 +04:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
license_write_new_license_request_packet(license, s);
|
|
|
|
|
|
|
|
license_send(license, s, NEW_LICENSE_REQUEST);
|
2011-07-12 09:57:09 +04:00
|
|
|
|
|
|
|
license->client_user_name->data = NULL;
|
|
|
|
license->client_user_name->length = 0;
|
|
|
|
|
|
|
|
license->client_machine_name->data = NULL;
|
|
|
|
license->client_machine_name->length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write Client Challenge Response Packet.\n
|
|
|
|
* @msdn{cc241922}
|
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
2011-07-13 18:21:12 +04:00
|
|
|
* @param mac_data signature
|
2011-07-12 09:57:09 +04:00
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void license_write_platform_challenge_response_packet(rdpLicense* license, STREAM* s, BYTE* mac_data)
|
2011-07-12 09:57:09 +04:00
|
|
|
{
|
|
|
|
/* EncryptedPlatformChallengeResponse */
|
2011-07-13 18:21:12 +04:00
|
|
|
license_write_binary_blob(s, license->encrypted_platform_challenge);
|
2011-07-12 09:57:09 +04:00
|
|
|
|
|
|
|
/* EncryptedHWID */
|
2011-07-13 18:21:12 +04:00
|
|
|
license_write_binary_blob(s, license->encrypted_hwid);
|
2011-07-12 09:57:09 +04:00
|
|
|
|
|
|
|
/* MACData */
|
2011-07-13 18:21:12 +04:00
|
|
|
stream_write(s, mac_data, 16);
|
2011-07-12 09:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send Client Challenge Response Packet.\n
|
|
|
|
* @msdn{cc241922}
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_send_platform_challenge_response_packet(rdpLicense* license)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-07-13 18:21:12 +04:00
|
|
|
int length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* buffer;
|
2011-07-13 18:21:12 +04:00
|
|
|
CryptoRc4 rc4;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE mac_data[16];
|
2011-07-12 09:57:09 +04:00
|
|
|
|
|
|
|
s = license_send_stream_init(license);
|
|
|
|
DEBUG_LICENSE("Sending Platform Challenge Response Packet");
|
|
|
|
|
2011-08-08 20:57:19 +04:00
|
|
|
license->encrypted_platform_challenge->type = BB_DATA_BLOB;
|
|
|
|
length = license->platform_challenge->length + HWID_LENGTH;
|
2012-10-09 11:01:37 +04:00
|
|
|
buffer = (BYTE*) malloc(length);
|
2011-08-08 20:57:19 +04:00
|
|
|
memcpy(buffer, license->platform_challenge->data, license->platform_challenge->length);
|
|
|
|
memcpy(&buffer[license->platform_challenge->length], license->hwid, HWID_LENGTH);
|
2011-07-13 18:21:12 +04:00
|
|
|
security_mac_data(license->mac_salt_key, buffer, length, mac_data);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(buffer);
|
2011-07-13 18:21:12 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
buffer = (BYTE*) malloc(HWID_LENGTH);
|
2011-07-13 18:21:12 +04:00
|
|
|
rc4 = crypto_rc4_init(license->licensing_encryption_key, LICENSING_ENCRYPTION_KEY_LENGTH);
|
|
|
|
crypto_rc4(rc4, HWID_LENGTH, license->hwid, buffer);
|
2012-02-02 03:42:20 +04:00
|
|
|
crypto_rc4_free(rc4);
|
2011-07-13 18:21:12 +04:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2011-08-08 20:57:19 +04:00
|
|
|
printf("Licensing Encryption Key:\n");
|
|
|
|
freerdp_hexdump(license->licensing_encryption_key, 16);
|
|
|
|
|
|
|
|
printf("HardwareID:\n");
|
|
|
|
freerdp_hexdump(license->hwid, 20);
|
|
|
|
|
|
|
|
printf("Encrypted HardwareID:\n");
|
|
|
|
freerdp_hexdump(buffer, 20);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2011-08-08 20:57:19 +04:00
|
|
|
|
|
|
|
license->encrypted_hwid->type = BB_DATA_BLOB;
|
2011-07-13 18:21:12 +04:00
|
|
|
license->encrypted_hwid->data = buffer;
|
|
|
|
license->encrypted_hwid->length = HWID_LENGTH;
|
|
|
|
|
|
|
|
license_write_platform_challenge_response_packet(license, s, mac_data);
|
2011-07-12 09:57:09 +04:00
|
|
|
|
|
|
|
license_send(license, s, PLATFORM_CHALLENGE_RESPONSE);
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2011-08-20 17:41:40 +04:00
|
|
|
/**
|
|
|
|
* Send Server License Error - Valid Client Packet.\n
|
|
|
|
* @msdn{cc241922}
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL license_send_valid_client_error_packet(rdpLicense* license)
|
2011-08-20 17:41:40 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
|
|
|
|
s = license_send_stream_init(license);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, STATUS_VALID_CLIENT); /* dwErrorCode */
|
|
|
|
stream_write_UINT32(s, ST_NO_TRANSITION); /* dwStateTransition */
|
2011-08-20 17:41:40 +04:00
|
|
|
|
|
|
|
license_write_binary_blob(s, license->error_info);
|
|
|
|
|
|
|
|
license_send(license, s, ERROR_ALERT);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-20 17:41:40 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
|
|
|
* Instantiate new license module.
|
2011-07-13 02:18:24 +04:00
|
|
|
* @param rdp RDP module
|
2011-07-12 04:46:03 +04:00
|
|
|
* @return new license module
|
|
|
|
*/
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
rdpLicense* license_new(rdpRdp* rdp)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
|
|
|
rdpLicense* license;
|
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
license = (rdpLicense*) malloc(sizeof(rdpLicense));
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
if (license != NULL)
|
|
|
|
{
|
2012-11-22 04:22:41 +04:00
|
|
|
ZeroMemory(license, sizeof(rdpLicense));
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
license->rdp = rdp;
|
2011-07-15 10:02:09 +04:00
|
|
|
license->state = LICENSE_STATE_AWAIT;
|
2011-09-05 22:02:52 +04:00
|
|
|
//license->certificate = certificate_new(rdp);
|
|
|
|
license->certificate = certificate_new();
|
2011-07-12 09:16:59 +04:00
|
|
|
license->product_info = license_new_product_info();
|
2011-07-15 10:02:09 +04:00
|
|
|
license->error_info = license_new_binary_blob(BB_ERROR_BLOB);
|
2011-07-12 09:16:59 +04:00
|
|
|
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);
|
2011-07-15 09:11:09 +04:00
|
|
|
license->platform_challenge = license_new_binary_blob(BB_ANY_BLOB);
|
2011-07-13 05:43:52 +04:00
|
|
|
license->encrypted_platform_challenge = license_new_binary_blob(BB_ANY_BLOB);
|
2011-07-15 09:11:09 +04:00
|
|
|
license->encrypted_premaster_secret = license_new_binary_blob(BB_ANY_BLOB);
|
2011-07-13 18:21:12 +04:00
|
|
|
license->encrypted_hwid = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB);
|
2011-07-12 09:16:59 +04:00
|
|
|
license->scope_list = license_new_scope_list();
|
2011-07-13 19:40:19 +04:00
|
|
|
license_generate_randoms(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return license;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free license module.
|
|
|
|
* @param license license module to be freed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_free(rdpLicense* license)
|
|
|
|
{
|
|
|
|
if (license != NULL)
|
|
|
|
{
|
2011-07-13 02:18:24 +04:00
|
|
|
certificate_free(license->certificate);
|
2011-07-12 09:16:59 +04:00
|
|
|
license_free_product_info(license->product_info);
|
2011-07-15 10:02:09 +04:00
|
|
|
license_free_binary_blob(license->error_info);
|
2011-07-12 09:16:59 +04:00
|
|
|
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);
|
2011-07-15 09:11:09 +04:00
|
|
|
license_free_binary_blob(license->platform_challenge);
|
2011-07-13 05:43:52 +04:00
|
|
|
license_free_binary_blob(license->encrypted_platform_challenge);
|
2011-07-15 09:11:09 +04:00
|
|
|
license_free_binary_blob(license->encrypted_premaster_secret);
|
2011-07-13 18:21:12 +04:00
|
|
|
license_free_binary_blob(license->encrypted_hwid);
|
2011-07-12 09:16:59 +04:00
|
|
|
license_free_scope_list(license->scope_list);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|