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
|
|
|
|
*
|
2013-02-05 10:07:34 +04:00
|
|
|
* Copyright 2011-2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2014-04-02 16:17:39 +04:00
|
|
|
* Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
|
2011-07-12 04:46:03 +04:00
|
|
|
*
|
|
|
|
* 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>
|
2016-02-24 18:46:25 +03:00
|
|
|
#include <winpr/crypto.h>
|
2014-08-19 20:26:39 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
|
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"
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.license")
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2013-08-08 02:28:31 +04:00
|
|
|
/* #define LICENSE_NULL_CLIENT_RANDOM 1 */
|
|
|
|
/* #define LICENSE_NULL_PREMASTER_SECRET 1 */
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
static wStream* license_send_stream_init(rdpLicense* license);
|
|
|
|
|
|
|
|
static void license_generate_randoms(rdpLicense* license);
|
|
|
|
static BOOL license_generate_keys(rdpLicense* license);
|
|
|
|
static BOOL license_generate_hwid(rdpLicense* license);
|
|
|
|
static BOOL license_encrypt_premaster_secret(rdpLicense* license);
|
|
|
|
static BOOL license_decrypt_platform_challenge(rdpLicense* license);
|
|
|
|
|
|
|
|
static LICENSE_PRODUCT_INFO* license_new_product_info(void);
|
|
|
|
static void license_free_product_info(LICENSE_PRODUCT_INFO* productInfo);
|
|
|
|
static BOOL license_read_product_info(wStream* s, LICENSE_PRODUCT_INFO* productInfo);
|
|
|
|
|
|
|
|
static LICENSE_BLOB* license_new_binary_blob(UINT16 type);
|
|
|
|
static void license_free_binary_blob(LICENSE_BLOB* blob);
|
|
|
|
static BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob);
|
|
|
|
static BOOL license_write_binary_blob(wStream* s, LICENSE_BLOB* blob);
|
|
|
|
|
|
|
|
static SCOPE_LIST* license_new_scope_list(void);
|
|
|
|
static void license_free_scope_list(SCOPE_LIST* scopeList);
|
|
|
|
static BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList);
|
|
|
|
|
|
|
|
static BOOL license_read_license_request_packet(rdpLicense* license, wStream* s);
|
|
|
|
static BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s);
|
|
|
|
static void license_read_new_license_packet(rdpLicense* license, wStream* s);
|
|
|
|
static void license_read_upgrade_license_packet(rdpLicense* license, wStream* s);
|
|
|
|
static BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s);
|
|
|
|
|
|
|
|
static BOOL license_write_new_license_request_packet(rdpLicense* license, wStream* s);
|
|
|
|
static BOOL license_send_new_license_request_packet(rdpLicense* license);
|
|
|
|
|
|
|
|
static BOOL license_write_platform_challenge_response_packet(
|
|
|
|
rdpLicense* license, wStream* s, BYTE* mac_data);
|
|
|
|
static BOOL license_send_platform_challenge_response_packet(rdpLicense* license);
|
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
static const char* const LICENSE_MESSAGE_STRINGS[] =
|
2011-08-08 07:59:28 +04:00
|
|
|
{
|
2014-08-19 20:26:39 +04:00
|
|
|
"",
|
|
|
|
"License Request",
|
|
|
|
"Platform Challenge",
|
|
|
|
"New License",
|
|
|
|
"Upgrade License",
|
|
|
|
"", "", "", "", "", "",
|
|
|
|
"", "", "", "", "", "",
|
|
|
|
"",
|
|
|
|
"License Info",
|
|
|
|
"New License Request",
|
|
|
|
"",
|
|
|
|
"Platform Challenge Response",
|
|
|
|
"", "", "", "", "", "", "", "", "",
|
|
|
|
"Error Alert"
|
2011-08-08 07:59:28 +04:00
|
|
|
};
|
|
|
|
|
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"
|
|
|
|
};
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
static void license_print_product_info(LICENSE_PRODUCT_INFO* productInfo)
|
2013-02-05 08:57:04 +04:00
|
|
|
{
|
|
|
|
char* CompanyName = NULL;
|
|
|
|
char* ProductId = NULL;
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) productInfo->pbCompanyName,
|
2018-10-02 14:18:13 +03:00
|
|
|
productInfo->cbCompanyName / 2, &CompanyName, 0, NULL, NULL);
|
2013-02-05 08:57:04 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) productInfo->pbProductId,
|
2018-10-02 14:18:13 +03:00
|
|
|
productInfo->cbProductId / 2, &ProductId, 0, NULL, NULL);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "ProductInfo:");
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, "\tdwVersion: 0x%08"PRIX32"", productInfo->dwVersion);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "\tCompanyName: %s", CompanyName);
|
|
|
|
WLog_INFO(TAG, "\tProductId: %s", ProductId);
|
2013-02-05 08:57:04 +04:00
|
|
|
free(CompanyName);
|
|
|
|
free(ProductId);
|
|
|
|
}
|
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
static void license_print_scope_list(SCOPE_LIST* scopeList)
|
2013-02-05 09:19:57 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
LICENSE_BLOB* scope;
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, "ScopeList (%"PRIu32"):", scopeList->count);
|
2013-02-05 09:19:57 +04:00
|
|
|
|
|
|
|
for (index = 0; index < scopeList->count; index++)
|
|
|
|
{
|
|
|
|
scope = &scopeList->array[index];
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "\t%s", (char*) scope->data);
|
2013-02-05 09:19:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2013-01-12 17:49:01 +04:00
|
|
|
* @return if the operation completed successfully
|
2011-07-12 09:16:59 +04:00
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_preamble(wStream* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgSize)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
|
|
|
/* preamble (4 bytes) */
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, *bMsgType); /* bMsgType (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, *flags); /* flags (1 byte) */
|
|
|
|
Stream_Read_UINT16(s, *wMsgSize); /* wMsgSize (2 bytes) */
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
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
|
|
|
|
*/
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL license_write_preamble(wStream* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSize)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/* preamble (4 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, bMsgType); /* bMsgType (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, flags); /* flags (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, wMsgSize); /* wMsgSize (2 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
return TRUE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize a license packet stream.\n
|
|
|
|
* @param license license module
|
|
|
|
* @return stream
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* license_send_stream_init(rdpLicense* license)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2015-01-12 13:31:18 +03:00
|
|
|
BOOL do_crypt = license->rdp->do_crypt;
|
2014-04-02 16:17:39 +04:00
|
|
|
license->rdp->sec_flags = SEC_LICENSE_PKT;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-01-12 13:31:18 +03:00
|
|
|
/**
|
|
|
|
* Encryption of licensing packets is optional even if the rdp security
|
|
|
|
* layer is used. If the peer has not indicated that it is capable of
|
|
|
|
* processing encrypted licensing packets (rdp->do_crypt_license) we turn
|
|
|
|
* off encryption (via rdp->do_crypt) before initializing the rdp stream
|
|
|
|
* and reenable it afterwards.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (do_crypt)
|
|
|
|
{
|
2014-08-19 20:26:39 +04:00
|
|
|
license->rdp->sec_flags |= SEC_LICENSE_ENCRYPT_CS;
|
2015-01-12 13:31:18 +03:00
|
|
|
license->rdp->do_crypt = license->rdp->do_crypt_license;
|
|
|
|
}
|
2014-04-02 16:17:39 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
s = rdp_send_stream_init(license->rdp);
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
2014-04-02 16:17:39 +04:00
|
|
|
|
2015-01-12 13:31:18 +03:00
|
|
|
license->rdp->do_crypt = do_crypt;
|
2014-04-02 16:17:39 +04:00
|
|
|
license->PacketHeaderLength = Stream_GetPosition(s);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
|
|
|
if (!Stream_SafeSeek(s, LICENSE_PREAMBLE_LENGTH))
|
|
|
|
goto fail;
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
return s;
|
2018-10-02 14:18:13 +03:00
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return NULL;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an RDP licensing packet.\n
|
|
|
|
* @msdn{cc240479}
|
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL license_send(rdpLicense* license, BYTE type)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
BOOL rc = FALSE;
|
2017-12-11 12:25:21 +03:00
|
|
|
size_t length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags;
|
|
|
|
UINT16 wMsgSize;
|
2018-10-02 14:18:13 +03:00
|
|
|
rdpRdp* rdp;
|
|
|
|
wStream* s = license_send_stream_init(license);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!license || !license->rdp)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rdp = license->rdp;
|
2011-08-08 22:51:03 +04:00
|
|
|
DEBUG_LICENSE("Sending %s Packet", LICENSE_MESSAGE_STRINGS[type & 0x1F]);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case NEW_LICENSE_REQUEST:
|
|
|
|
if (!license_write_new_license_request_packet(license, s))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLATFORM_CHALLENGE_RESPONSE:
|
|
|
|
{
|
|
|
|
BYTE mac_data[16];
|
|
|
|
size_t length = license->PlatformChallenge->length + HWID_LENGTH;
|
|
|
|
BYTE* buffer = (BYTE*) malloc(length);
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
CopyMemory(buffer, license->PlatformChallenge->data, license->PlatformChallenge->length);
|
|
|
|
CopyMemory(&buffer[license->PlatformChallenge->length], license->HardwareId, HWID_LENGTH);
|
|
|
|
rc = security_mac_data(license->MacSaltKey, buffer, length, mac_data);
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!license_write_platform_challenge_response_packet(license, s, mac_data))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERROR_ALERT:
|
|
|
|
{
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 8))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, STATUS_VALID_CLIENT); /* dwErrorCode */
|
|
|
|
Stream_Write_UINT32(s, ST_NO_TRANSITION); /* dwStateTransition */
|
|
|
|
|
|
|
|
if (!license_write_binary_blob(s, license->ErrorInfo))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
length = Stream_GetPosition(s);
|
2014-04-02 16:17:39 +04:00
|
|
|
wMsgSize = length - license->PacketHeaderLength;
|
|
|
|
Stream_SetPosition(s, license->PacketHeaderLength);
|
2013-09-06 02:53:55 +04:00
|
|
|
flags = PREAMBLE_VERSION_3_0;
|
|
|
|
|
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.
|
|
|
|
*/
|
2013-09-06 02:53:55 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (!rdp->settings->ServerMode)
|
2013-09-06 02:53:55 +04:00
|
|
|
flags |= EXTENDED_ERROR_MSG_SUPPORTED;
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
if (!license_write_preamble(s, type, flags, wMsgSize))
|
|
|
|
goto fail;
|
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2018-10-02 14:18:13 +03:00
|
|
|
WLog_DBG(TAG, "Sending %s Packet, length %"PRIu16"", LICENSE_MESSAGE_STRINGS[type & 0x1F],
|
|
|
|
wMsgSize);
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Pointer(s) - LICENSE_PREAMBLE_LENGTH, wMsgSize);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, length);
|
2018-10-02 14:18:13 +03:00
|
|
|
rc = rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID);
|
2014-04-02 16:17:39 +04:00
|
|
|
rdp->sec_flags = 0;
|
2018-10-02 14:18:13 +03:00
|
|
|
return rc;
|
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
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
|
2013-01-12 17:49:01 +04:00
|
|
|
* @return if the operation completed successfully
|
2011-07-12 04:46:03 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-05 00:52:29 +04:00
|
|
|
int license_recv(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags;
|
|
|
|
BYTE bMsgType;
|
|
|
|
UINT16 wMsgSize;
|
2013-02-05 01:39:05 +04:00
|
|
|
UINT16 length;
|
|
|
|
UINT16 channelId;
|
2016-12-02 12:46:43 +03:00
|
|
|
UINT16 securityFlags = 0;
|
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))
|
|
|
|
{
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_ERR(TAG, "Incorrect RDP header.");
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
2011-08-22 11:03:58 +04:00
|
|
|
}
|
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
if (!rdp_read_security_header(s, &securityFlags, &length))
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
2013-01-25 22:47:56 +04:00
|
|
|
|
2013-02-05 01:39:05 +04:00
|
|
|
if (securityFlags & SEC_ENCRYPT)
|
|
|
|
{
|
2017-05-29 11:50:22 +03:00
|
|
|
if (!rdp_decrypt(license->rdp, s, length, securityFlags))
|
2013-02-05 01:39:05 +04:00
|
|
|
{
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_ERR(TAG, "rdp_decrypt failed");
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
2013-02-05 01:39:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(securityFlags & SEC_LICENSE_PKT))
|
2011-08-22 11:03:58 +04:00
|
|
|
{
|
2013-11-05 00:52:29 +04:00
|
|
|
int status;
|
|
|
|
|
2013-02-05 01:39:05 +04:00
|
|
|
if (!(securityFlags & SEC_ENCRYPT))
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Rewind(s, RDP_SECURITY_HEADER_LENGTH);
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-11-05 00:52:29 +04:00
|
|
|
status = rdp_recv_out_of_sequence_pdu(license->rdp, s);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-11-05 00:52:29 +04:00
|
|
|
if (status < 0)
|
2011-09-03 05:34:51 +04:00
|
|
|
{
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_ERR(TAG, "unexpected license packet.");
|
2013-11-05 00:52:29 +04:00
|
|
|
return status;
|
2011-09-03 05:34:51 +04:00
|
|
|
}
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-11-05 00:52:29 +04:00
|
|
|
return 0;
|
2011-08-22 11:03:58 +04:00
|
|
|
}
|
|
|
|
|
2013-01-25 22:47:56 +04:00
|
|
|
if (!license_read_preamble(s, &bMsgType, &flags, &wMsgSize)) /* preamble (4 bytes) */
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
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:
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!license_read_license_request_packet(license, s))
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!license_send_new_license_request_packet(license))
|
|
|
|
return -1;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
break;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
case PLATFORM_CHALLENGE:
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!license_read_platform_challenge_packet(license, s))
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
if (!license_send_platform_challenge_response_packet(license))
|
|
|
|
return -1;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
break;
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
case NEW_LICENSE:
|
|
|
|
license_read_new_license_packet(license, s);
|
|
|
|
break;
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
case UPGRADE_LICENSE:
|
|
|
|
license_read_upgrade_license_packet(license, s);
|
|
|
|
break;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
case ERROR_ALERT:
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!license_read_error_alert_packet(license, s))
|
2013-11-05 00:52:29 +04:00
|
|
|
return -1;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
break;
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "invalid bMsgType:%"PRIu8"", 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
|
|
|
|
2013-11-05 00:52:29 +04:00
|
|
|
return 0;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
2011-07-13 19:40:19 +04:00
|
|
|
void license_generate_randoms(rdpLicense* license)
|
|
|
|
{
|
2013-02-05 08:57:04 +04:00
|
|
|
ZeroMemory(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
|
|
|
ZeroMemory(license->PremasterSecret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
2013-02-05 18:46:25 +04:00
|
|
|
#ifndef LICENSE_NULL_CLIENT_RANDOM
|
2016-02-28 00:39:45 +03:00
|
|
|
winpr_RAND(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
|
2013-02-05 18:46:25 +04:00
|
|
|
#endif
|
|
|
|
#ifndef LICENSE_NULL_PREMASTER_SECRET
|
2016-02-28 00:39:45 +03:00
|
|
|
winpr_RAND(license->PremasterSecret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
|
2011-08-08 20:57:19 +04:00
|
|
|
#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
|
|
|
|
*/
|
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL license_generate_keys(rdpLicense* license)
|
2011-07-12 09:57:09 +04:00
|
|
|
{
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL ret;
|
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
if (
|
2018-10-02 14:18:13 +03:00
|
|
|
/* MasterSecret */
|
|
|
|
!security_master_secret(license->PremasterSecret, license->ClientRandom,
|
|
|
|
license->ServerRandom, license->MasterSecret) ||
|
|
|
|
/* SessionKeyBlob */
|
|
|
|
!security_session_key_blob(license->MasterSecret, license->ClientRandom,
|
|
|
|
license->ServerRandom, license->SessionKeyBlob))
|
2015-04-01 12:11:37 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
security_mac_salt_key(license->SessionKeyBlob, license->ClientRandom,
|
2018-10-02 14:18:13 +03:00
|
|
|
license->ServerRandom, license->MacSaltKey); /* MacSaltKey */
|
2015-04-01 12:38:53 +03:00
|
|
|
ret = security_licensing_encryption_key(license->SessionKeyBlob, license->ClientRandom,
|
2018-10-02 14:18:13 +03:00
|
|
|
license->ServerRandom, license->LicensingEncryptionKey); /* LicensingEncryptionKey */
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "ClientRandom:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, CLIENT_RANDOM_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "ServerRandom:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ServerRandom, SERVER_RANDOM_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "PremasterSecret:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->PremasterSecret, PREMASTER_SECRET_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "MasterSecret:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->MasterSecret, MASTER_SECRET_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "SessionKeyBlob:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->SessionKeyBlob, SESSION_KEY_BLOB_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "MacSaltKey:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->MacSaltKey, MAC_SALT_KEY_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "LicensingEncryptionKey:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2015-04-01 12:38:53 +03:00
|
|
|
return ret;
|
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
|
|
|
|
*/
|
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL license_generate_hwid(rdpLicense* license)
|
2011-07-12 10:53:26 +04:00
|
|
|
{
|
2015-02-11 19:57:02 +03:00
|
|
|
BYTE macAddress[6];
|
|
|
|
ZeroMemory(macAddress, sizeof(macAddress));
|
2013-02-05 08:57:04 +04:00
|
|
|
ZeroMemory(license->HardwareId, HWID_LENGTH);
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2017-04-08 00:54:08 +03:00
|
|
|
/* Allow FIPS override for use of MD5 here, really this does not have to be MD5 as we are just taking a MD5 hash of the 6 bytes of 0's(macAddress) */
|
|
|
|
/* and filling in the Data1-Data4 fields of the CLIENT_HARDWARE_ID structure(from MS-RDPELE section 2.2.2.3.1). This is for RDP licensing packets */
|
|
|
|
/* which will already be encrypted under FIPS, so the use of MD5 here is not for sensitive data protection. */
|
2018-10-02 14:18:13 +03:00
|
|
|
if (!winpr_Digest_Allow_FIPS(WINPR_MD_MD5, macAddress, sizeof(macAddress),
|
|
|
|
&license->HardwareId[HWID_PLATFORM_ID_LENGTH], WINPR_MD5_DIGEST_LENGTH))
|
2016-02-24 23:45:09 +03:00
|
|
|
return FALSE;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
return TRUE;
|
2011-07-12 10:53:26 +04:00
|
|
|
}
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_get_server_rsa_public_key(rdpLicense* license)
|
2011-07-15 09:11:09 +04:00
|
|
|
{
|
2013-02-05 18:30:53 +04:00
|
|
|
BYTE* Exponent;
|
|
|
|
BYTE* Modulus;
|
|
|
|
int ModulusLength;
|
2015-02-11 19:57:02 +03:00
|
|
|
rdpSettings* settings = license->rdp->settings;
|
2011-07-15 09:11:09 +04:00
|
|
|
|
2013-02-05 19:02:06 +04:00
|
|
|
if (license->ServerCertificate->length < 1)
|
2013-02-05 08:57:04 +04:00
|
|
|
{
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!certificate_read_server_certificate(license->certificate,
|
2018-10-02 14:18:13 +03:00
|
|
|
settings->ServerCertificate, settings->ServerCertificateLength))
|
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
}
|
2011-09-17 00:37:20 +04:00
|
|
|
|
2013-02-05 19:02:06 +04:00
|
|
|
Exponent = license->certificate->cert_info.exponent;
|
|
|
|
Modulus = license->certificate->cert_info.Modulus;
|
|
|
|
ModulusLength = license->certificate->cert_info.ModulusLength;
|
2013-02-05 18:30:53 +04:00
|
|
|
CopyMemory(license->Exponent, Exponent, 4);
|
|
|
|
license->ModulusLength = ModulusLength;
|
|
|
|
license->Modulus = (BYTE*) malloc(ModulusLength);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!license->Modulus)
|
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-02-11 19:57:02 +03:00
|
|
|
CopyMemory(license->Modulus, Modulus, ModulusLength);
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
2013-02-05 19:02:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL license_encrypt_premaster_secret(rdpLicense* license)
|
2013-02-05 19:02:06 +04:00
|
|
|
{
|
|
|
|
BYTE* EncryptedPremasterSecret;
|
2015-04-01 12:38:53 +03:00
|
|
|
|
|
|
|
if (!license_get_server_rsa_public_key(license))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "Modulus (%"PRIu32" bits):", license->ModulusLength * 8);
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->Modulus, license->ModulusLength);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "Exponent:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->Exponent, 4);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2015-02-11 19:57:02 +03:00
|
|
|
EncryptedPremasterSecret = (BYTE*) calloc(1, license->ModulusLength);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
if (!EncryptedPremasterSecret)
|
|
|
|
return FALSE;
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2013-08-08 02:28:31 +04:00
|
|
|
license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB;
|
|
|
|
license->EncryptedPremasterSecret->length = PREMASTER_SECRET_LENGTH;
|
2013-02-05 18:46:25 +04:00
|
|
|
#ifndef LICENSE_NULL_PREMASTER_SECRET
|
2013-08-08 02:28:31 +04:00
|
|
|
license->EncryptedPremasterSecret->length =
|
2018-10-02 14:18:13 +03:00
|
|
|
crypto_rsa_public_encrypt(license->PremasterSecret, PREMASTER_SECRET_LENGTH,
|
|
|
|
license->ModulusLength, license->Modulus, license->Exponent, EncryptedPremasterSecret);
|
2013-02-05 18:46:25 +04:00
|
|
|
#endif
|
2013-02-05 08:57:04 +04:00
|
|
|
license->EncryptedPremasterSecret->data = EncryptedPremasterSecret;
|
2015-04-01 12:11:37 +03:00
|
|
|
return TRUE;
|
2011-07-15 09:11:09 +04:00
|
|
|
}
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_decrypt_platform_challenge(rdpLicense* license)
|
2011-07-15 09:11:09 +04:00
|
|
|
{
|
2016-02-28 13:12:17 +03:00
|
|
|
BOOL rc;
|
|
|
|
WINPR_RC4_CTX* rc4;
|
2018-10-02 14:18:13 +03:00
|
|
|
license->PlatformChallenge->data = (BYTE*)malloc(license->EncryptedPlatformChallenge->length);
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!license->PlatformChallenge->data)
|
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
license->PlatformChallenge->length = license->EncryptedPlatformChallenge->length;
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2017-04-08 00:54:08 +03:00
|
|
|
/* Allow FIPS override for use of RC4 here, this is only used for decrypting the MACData field of the */
|
|
|
|
/* Server Platform Challenge packet (from MS-RDPELE section 2.2.2.4). This is for RDP licensing packets */
|
|
|
|
/* which will already be encrypted under FIPS, so the use of RC4 here is not for sensitive data protection. */
|
|
|
|
if ((rc4 = winpr_RC4_New_Allow_FIPS(license->LicensingEncryptionKey,
|
2018-10-02 14:18:13 +03:00
|
|
|
LICENSING_ENCRYPTION_KEY_LENGTH)) == NULL)
|
2017-05-29 11:50:22 +03:00
|
|
|
{
|
|
|
|
free(license->PlatformChallenge->data);
|
|
|
|
license->PlatformChallenge->data = NULL;
|
|
|
|
license->PlatformChallenge->length = 0;
|
2016-02-28 13:12:17 +03:00
|
|
|
return FALSE;
|
2017-05-29 11:50:22 +03:00
|
|
|
}
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
rc = winpr_RC4_Update(rc4, license->EncryptedPlatformChallenge->length,
|
|
|
|
license->EncryptedPlatformChallenge->data,
|
|
|
|
license->PlatformChallenge->data);
|
2016-02-28 13:12:17 +03:00
|
|
|
winpr_RC4_Free(rc4);
|
|
|
|
return rc;
|
2011-07-15 09:11:09 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2014-02-17 03:02:50 +04:00
|
|
|
BOOL license_read_product_info(wStream* s, LICENSE_PRODUCT_INFO* productInfo)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
/* Name must be >0, but there is no upper limit defined, use UINT32_MAX */
|
|
|
|
if ((productInfo->cbCompanyName < 2) || (productInfo->cbCompanyName % 2 != 0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < productInfo->cbCompanyName)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
productInfo->pbProductId = NULL;
|
2012-10-09 11:01:37 +04:00
|
|
|
productInfo->pbCompanyName = (BYTE*) malloc(productInfo->cbCompanyName);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!productInfo->pbCompanyName)
|
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
|
2017-05-29 11:50:22 +03:00
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
|
|
|
goto out_fail;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
if ((productInfo->cbProductId < 2) || (productInfo->cbProductId % 2 != 0))
|
|
|
|
goto out_fail;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < productInfo->cbProductId)
|
2015-06-16 16:42:07 +03:00
|
|
|
goto out_fail;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
productInfo->pbProductId = (BYTE*) malloc(productInfo->cbProductId);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!productInfo->pbProductId)
|
|
|
|
goto out_fail;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, productInfo->pbProductId, productInfo->cbProductId);
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2015-06-16 16:42:07 +03:00
|
|
|
out_fail:
|
|
|
|
free(productInfo->pbCompanyName);
|
2017-05-29 11:50:22 +03:00
|
|
|
free(productInfo->pbProductId);
|
2015-06-16 16:42:07 +03:00
|
|
|
productInfo->pbCompanyName = NULL;
|
2017-05-29 11:50:22 +03:00
|
|
|
productInfo->pbProductId = NULL;
|
2015-06-16 16:42:07 +03:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
2014-02-17 03:02:50 +04:00
|
|
|
* Allocate New Product Information (LICENSE_PRODUCT_INFO).\n
|
2011-07-12 09:16:59 +04:00
|
|
|
* @msdn{cc241915}
|
|
|
|
* @return new product information
|
|
|
|
*/
|
|
|
|
|
2014-02-17 03:02:50 +04:00
|
|
|
LICENSE_PRODUCT_INFO* license_new_product_info()
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2014-02-17 03:02:50 +04:00
|
|
|
LICENSE_PRODUCT_INFO* productInfo;
|
|
|
|
productInfo = (LICENSE_PRODUCT_INFO*) malloc(sizeof(LICENSE_PRODUCT_INFO));
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!productInfo)
|
|
|
|
return NULL;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-17 03:02:50 +04:00
|
|
|
* Free Product Information (LICENSE_PRODUCT_INFO).\n
|
2011-07-12 09:16:59 +04:00
|
|
|
* @msdn{cc241915}
|
|
|
|
* @param productInfo product information
|
|
|
|
*/
|
|
|
|
|
2014-02-17 03:02:50 +04:00
|
|
|
void license_free_product_info(LICENSE_PRODUCT_INFO* productInfo)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
if (productInfo)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(productInfo->pbCompanyName);
|
|
|
|
free(productInfo->pbProductId);
|
2015-05-11 10:07:39 +03: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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wBlobType;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2013-05-09 00:09:16 +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
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < blob->length)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2011-09-17 00:37:20 +04:00
|
|
|
/*
|
2014-08-19 20:26:39 +04:00
|
|
|
* Server can choose to not send data by setting length to 0.
|
|
|
|
* If so, it may not bother to set the type, so shortcut the warning
|
|
|
|
*/
|
2013-02-05 10:07:34 +04:00
|
|
|
if ((blob->type != BB_ANY_BLOB) && (blob->length == 0))
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2013-02-05 10:07:34 +04:00
|
|
|
if ((blob->type != wBlobType) && (blob->type != BB_ANY_BLOB))
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
WLog_ERR(TAG, "license binary blob type (0x%"PRIx16") does not match expected type (0x%"PRIx16").",
|
|
|
|
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);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!blob->data)
|
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, blob->data, blob->length); /* blobData */
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_write_binary_blob(wStream* s, LICENSE_BLOB* blob)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blob->length + 4))
|
2018-10-02 14:18:13 +03:00
|
|
|
{
|
|
|
|
Stream_Release(s);
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
}
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2013-05-09 00:09:16 +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)
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, blob->data, blob->length); /* blobData */
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
static BOOL license_write_encrypted_premaster_secret_blob(wStream* s, LICENSE_BLOB* blob,
|
|
|
|
UINT32 ModulusLength)
|
2011-07-15 09:11:09 +04:00
|
|
|
{
|
2013-02-05 18:30:53 +04:00
|
|
|
UINT32 length;
|
|
|
|
length = ModulusLength + 8;
|
|
|
|
|
|
|
|
if (blob->length > ModulusLength)
|
|
|
|
{
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_ERR(TAG, "license_write_encrypted_premaster_secret_blob: invalid blob");
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
2013-02-05 18:30:53 +04:00
|
|
|
}
|
2011-09-19 19:44:13 +04:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, length + 4))
|
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, length); /* wBlobLen (2 bytes) */
|
2011-07-15 09:11:09 +04:00
|
|
|
|
|
|
|
if (blob->length > 0)
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, blob->data, blob->length); /* blobData */
|
2011-07-15 09:11:09 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Zero(s, length - blob->length);
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
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;
|
2015-06-16 16:42:07 +03:00
|
|
|
blob = (LICENSE_BLOB*) calloc(1, sizeof(LICENSE_BLOB));
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (blob)
|
|
|
|
blob->type = type;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
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)
|
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
if (blob)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(blob->data);
|
2015-05-11 10:07:39 +03: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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 i;
|
|
|
|
UINT32 scopeCount;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, scopeCount); /* ScopeCount (4 bytes) */
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2014-01-08 19:12:51 +04:00
|
|
|
if (scopeCount > Stream_GetRemainingLength(s) / 4) /* every blob is at least 4 bytes */
|
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
scopeList->count = scopeCount;
|
2017-05-30 11:46:43 +03:00
|
|
|
scopeList->array = (LICENSE_BLOB*) calloc(scopeCount, sizeof(LICENSE_BLOB));
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!scopeList->array)
|
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ScopeArray */
|
|
|
|
for (i = 0; i < scopeCount; i++)
|
|
|
|
{
|
|
|
|
scopeList->array[i].type = BB_SCOPE_BLOB;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
|
|
|
if (!license_read_binary_blob(s, &scopeList->array[i]))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
return (SCOPE_LIST*) calloc(1, sizeof(SCOPE_LIST));
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!scopeList)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
free(scopeList->array);
|
2012-10-09 07:21:26 +04:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_license_request_packet(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
|
|
|
/* ServerRandom (32 bytes) */
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 32)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-01-25 22:47:56 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, license->ServerRandom, 32);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ProductInfo */
|
2013-02-05 08:57:04 +04:00
|
|
|
if (!license_read_product_info(s, license->ProductInfo))
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* KeyExchangeList */
|
2013-02-05 08:57:04 +04:00
|
|
|
if (!license_read_binary_blob(s, license->KeyExchangeList))
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ServerCertificate */
|
2013-02-05 08:57:04 +04:00
|
|
|
if (!license_read_binary_blob(s, license->ServerCertificate))
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* ScopeList */
|
2013-02-05 08:57:04 +04:00
|
|
|
if (!license_read_scope_list(s, license->ScopeList))
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2011-07-13 02:18:24 +04:00
|
|
|
|
|
|
|
/* Parse Server Certificate */
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!certificate_read_server_certificate(license->certificate,
|
2018-10-02 14:18:13 +03:00
|
|
|
license->ServerCertificate->data, license->ServerCertificate->length))
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2011-07-13 18:21:12 +04:00
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
if (!license_generate_keys(license) || !license_generate_hwid(license) ||
|
2018-10-02 14:18:13 +03:00
|
|
|
!license_encrypt_premaster_secret(license))
|
2015-04-01 12:11:37 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "ServerRandom:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ServerRandom, 32);
|
2013-02-05 08:57:04 +04:00
|
|
|
license_print_product_info(license->ProductInfo);
|
2013-02-05 09:19:57 +04:00
|
|
|
license_print_scope_list(license->ScopeList);
|
2013-02-05 08:57:04 +04:00
|
|
|
#endif
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2013-02-05 09:19:57 +04:00
|
|
|
BYTE MacData[16];
|
|
|
|
UINT32 ConnectFlags = 0;
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Receiving Platform Challenge Packet");
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, ConnectFlags); /* ConnectFlags, Reserved (4 bytes) */
|
2011-07-12 09:57:09 +04:00
|
|
|
/* EncryptedPlatformChallenge */
|
2013-02-05 08:57:04 +04:00
|
|
|
license->EncryptedPlatformChallenge->type = BB_ANY_BLOB;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
if (!license_read_binary_blob(s, license->EncryptedPlatformChallenge))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
license->EncryptedPlatformChallenge->type = BB_ENCRYPTED_DATA_BLOB;
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-13 18:21:12 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, MacData, 16); /* MACData (16 bytes) */
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-04-07 22:06:53 +03:00
|
|
|
if (!license_decrypt_platform_challenge(license))
|
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "ConnectFlags: 0x%08"PRIX32"", ConnectFlags);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "EncryptedPlatformChallenge:");
|
2018-10-02 14:18:13 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->EncryptedPlatformChallenge->data,
|
|
|
|
license->EncryptedPlatformChallenge->length);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "PlatformChallenge:");
|
2018-10-02 14:18:13 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->PlatformChallenge->data,
|
|
|
|
license->PlatformChallenge->length);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "MacData:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, MacData, 16);
|
2013-02-05 09:19:57 +04:00
|
|
|
#endif
|
2015-04-07 22:06:53 +03:00
|
|
|
return TRUE;
|
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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void license_read_new_license_packet(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void license_read_upgrade_license_packet(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
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
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwErrorCode;
|
|
|
|
UINT32 dwStateTransition;
|
2011-07-15 10:02:09 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, dwErrorCode); /* dwErrorCode (4 bytes) */
|
|
|
|
Stream_Read_UINT32(s, dwStateTransition); /* dwStateTransition (4 bytes) */
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
if (!license_read_binary_blob(s, license->ErrorInfo)) /* bbErrorInfo */
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-15 10:02:09 +04:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "dwErrorCode: %s, dwStateTransition: %s",
|
2018-10-02 14:18:13 +03:00
|
|
|
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;
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2011-07-15 10:02:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (dwStateTransition)
|
|
|
|
{
|
|
|
|
case ST_TOTAL_ABORT:
|
|
|
|
license->state = LICENSE_STATE_ABORTED;
|
|
|
|
break;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
case ST_NO_TRANSITION:
|
|
|
|
license->state = LICENSE_STATE_COMPLETED;
|
|
|
|
break;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
case ST_RESET_PHASE_TO_START:
|
|
|
|
license->state = LICENSE_STATE_AWAIT;
|
|
|
|
break;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
case ST_RESEND_LAST_MESSAGE:
|
|
|
|
break;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Write a NEW_LICENSE_REQUEST packet.\n
|
|
|
|
* @msdn{cc241918}
|
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_write_new_license_request_packet(rdpLicense* license, wStream* s)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2013-02-05 10:07:34 +04:00
|
|
|
UINT32 PlatformId;
|
|
|
|
UINT32 PreferredKeyExchangeAlg = KEY_EXCHANGE_ALG_RSA;
|
|
|
|
PlatformId = CLIENT_OS_ID_WINNT_POST_52 | CLIENT_IMAGE_ID_MICROSOFT;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, PlatformId); /* PlatformId (4 bytes) */
|
|
|
|
Stream_Write(s, license->ClientRandom, 32); /* ClientRandom (32 bytes) */
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
/* EncryptedPremasterSecret */
|
|
|
|
if (!license_write_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
|
|
|
|
license->ModulusLength) ||
|
|
|
|
/* ClientUserName */
|
|
|
|
!license_write_binary_blob(s, license->ClientUserName) ||
|
|
|
|
/* ClientMachineName */
|
|
|
|
!license_write_binary_blob(s, license->ClientMachineName))
|
2015-04-01 12:38:53 +03:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
Stream_Release(s);
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-05 10:07:34 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "PreferredKeyExchangeAlg: 0x%08"PRIX32"", PreferredKeyExchangeAlg);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "ClientRandom:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, 32);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "EncryptedPremasterSecret");
|
2018-10-02 14:18:13 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->EncryptedPremasterSecret->data,
|
|
|
|
license->EncryptedPremasterSecret->length);
|
|
|
|
WLog_DBG(TAG, "ClientUserName (%"PRIu16"): %s", license->ClientUserName->length,
|
|
|
|
(char*) license->ClientUserName->data);
|
|
|
|
WLog_DBG(TAG, "ClientMachineName (%"PRIu16"): %s", license->ClientMachineName->length,
|
|
|
|
(char*) license->ClientMachineName->data);
|
2013-02-05 10:07:34 +04:00
|
|
|
#endif
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a NEW_LICENSE_REQUEST packet.\n
|
|
|
|
* @msdn{cc241918}
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_send_new_license_request_packet(rdpLicense* license)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2011-10-05 03:06:39 +04:00
|
|
|
char* username;
|
2013-02-05 10:07:34 +04:00
|
|
|
DEBUG_LICENSE("Sending New License Packet");
|
2011-07-12 09:16:59 +04:00
|
|
|
|
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";
|
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
license->ClientUserName->data = (BYTE*) username;
|
|
|
|
license->ClientUserName->length = strlen(username) + 1;
|
|
|
|
license->ClientMachineName->data = (BYTE*) license->rdp->settings->ClientHostname;
|
|
|
|
license->ClientMachineName->length = strlen(license->rdp->settings->ClientHostname) + 1;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
|
|
|
if (!license_send(license, NEW_LICENSE_REQUEST))
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
license->ClientUserName->data = NULL;
|
|
|
|
license->ClientUserName->length = 0;
|
|
|
|
license->ClientMachineName->data = NULL;
|
|
|
|
license->ClientMachineName->length = 0;
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
2011-07-12 09:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
BOOL license_write_platform_challenge_response_packet(rdpLicense* license, wStream* s,
|
|
|
|
BYTE* macData)
|
2011-07-12 09:57:09 +04:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
if (!license_write_binary_blob(s, license->EncryptedPlatformChallenge) ||
|
|
|
|
/* EncryptedPlatformChallengeResponse */
|
|
|
|
!license_write_binary_blob(s, license->EncryptedHardwareId) || /* EncryptedHWID */
|
|
|
|
!Stream_EnsureRemainingCapacity(s, 16))
|
2015-04-01 12:38:53 +03:00
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
Stream_Release(s);
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, macData, 16); /* MACData */
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
2011-07-12 09:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send Client Challenge Response Packet.\n
|
|
|
|
* @msdn{cc241922}
|
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL license_send_platform_challenge_response_packet(rdpLicense* license)
|
2011-07-12 09:57:09 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* buffer;
|
2016-02-28 13:12:17 +03:00
|
|
|
WINPR_RC4_CTX* rc4;
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL status;
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Sending Platform Challenge Response Packet");
|
2013-02-05 08:57:04 +04:00
|
|
|
license->EncryptedPlatformChallenge->type = BB_DATA_BLOB;
|
2017-04-08 00:54:08 +03:00
|
|
|
/* Allow FIPS override for use of RC4 here, this is only used for encrypting the EncryptedHWID field of the */
|
|
|
|
/* Client Platform Challenge Response packet (from MS-RDPELE section 2.2.2.5). This is for RDP licensing packets */
|
|
|
|
/* which will already be encrypted under FIPS, so the use of RC4 here is not for sensitive data protection. */
|
|
|
|
rc4 = winpr_RC4_New_Allow_FIPS(license->LicensingEncryptionKey,
|
2018-10-02 14:18:13 +03:00
|
|
|
LICENSING_ENCRYPTION_KEY_LENGTH);
|
|
|
|
|
2016-02-29 11:00:02 +03:00
|
|
|
if (!rc4)
|
2016-02-28 13:12:17 +03:00
|
|
|
return FALSE;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2015-04-07 22:06:53 +03:00
|
|
|
buffer = (BYTE*) malloc(HWID_LENGTH);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-04-07 22:06:53 +03:00
|
|
|
if (!buffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-02-28 13:12:17 +03:00
|
|
|
status = winpr_RC4_Update(rc4, HWID_LENGTH, license->HardwareId, buffer);
|
|
|
|
winpr_RC4_Free(rc4);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2016-02-28 13:12:17 +03:00
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-02-24 19:04:03 +03:00
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
license->EncryptedHardwareId->type = BB_DATA_BLOB;
|
|
|
|
license->EncryptedHardwareId->data = buffer;
|
|
|
|
license->EncryptedHardwareId->length = HWID_LENGTH;
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "LicensingEncryptionKey:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->LicensingEncryptionKey, 16);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "HardwareId:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->HardwareId, HWID_LENGTH);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "EncryptedHardwareId:");
|
2014-08-19 20:26:39 +04:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->EncryptedHardwareId->data, HWID_LENGTH);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2018-10-02 14:18:13 +03:00
|
|
|
return license_send(license, 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
|
|
|
{
|
2018-10-02 14:18:13 +03:00
|
|
|
wStream* s = license_send_stream_init(license);
|
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-05 10:07:34 +04:00
|
|
|
DEBUG_LICENSE("Sending Error Alert Packet");
|
2018-10-02 14:18:13 +03:00
|
|
|
return license_send(license, ERROR_ALERT);
|
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;
|
2015-06-16 16:42:07 +03:00
|
|
|
license = (rdpLicense*) calloc(1, sizeof(rdpLicense));
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!license)
|
|
|
|
return NULL;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
license->rdp = rdp;
|
|
|
|
license->state = LICENSE_STATE_AWAIT;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->certificate = certificate_new()))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ProductInfo = license_new_product_info()))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ErrorInfo = license_new_binary_blob(BB_ERROR_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->KeyExchangeList = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ServerCertificate = license_new_binary_blob(BB_CERTIFICATE_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ClientUserName = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ClientMachineName = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->PlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->EncryptedPlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->EncryptedPremasterSecret = license_new_binary_blob(BB_ANY_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->EncryptedHardwareId = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
|
|
|
|
goto out_error;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ScopeList = license_new_scope_list()))
|
|
|
|
goto out_error;
|
|
|
|
|
|
|
|
license_generate_randoms(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
return license;
|
2015-06-16 16:42:07 +03:00
|
|
|
out_error:
|
|
|
|
license_free(license);
|
|
|
|
return NULL;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free license module.
|
|
|
|
* @param license license module to be freed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_free(rdpLicense* license)
|
|
|
|
{
|
2013-02-05 09:19:57 +04:00
|
|
|
if (license)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2013-02-05 18:30:53 +04:00
|
|
|
free(license->Modulus);
|
2011-07-13 02:18:24 +04:00
|
|
|
certificate_free(license->certificate);
|
2013-02-05 08:57:04 +04:00
|
|
|
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);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
}
|