2022-12-09 16:35:03 +03: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>
|
2018-10-31 12:27:31 +03:00
|
|
|
* Copyright 2018 David Fort <contact@hardening-consulting.com>
|
2023-02-09 10:48:11 +03:00
|
|
|
* Copyright 2022,2023 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2022,2023 Thincast Technologies GmbH
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2022-10-06 12:32:08 +03:00
|
|
|
#include <freerdp/license.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-22 04:22:41 +04:00
|
|
|
#include <winpr/crt.h>
|
2022-10-06 12:32:08 +03:00
|
|
|
#include <winpr/assert.h>
|
2016-02-24 18:46:25 +03:00
|
|
|
#include <winpr/crypto.h>
|
2018-10-31 12:27:31 +03:00
|
|
|
#include <winpr/shell.h>
|
|
|
|
#include <winpr/path.h>
|
2021-05-31 12:42:03 +03:00
|
|
|
#include <winpr/file.h>
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2014-08-19 20:26:39 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
|
2023-02-03 13:51:14 +03:00
|
|
|
#include <freerdp/crypto/certificate.h>
|
2011-09-03 05:34:51 +04:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
#include "license.h"
|
|
|
|
|
2023-01-30 14:14:03 +03:00
|
|
|
#include "../crypto/crypto.h"
|
2023-02-03 13:51:14 +03:00
|
|
|
#include "../crypto/certificate.h"
|
2023-01-30 14:14:03 +03:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.license")
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
#if 0
|
2019-11-06 17:24:51 +03:00
|
|
|
#define LICENSE_NULL_CLIENT_RANDOM 1
|
|
|
|
#define LICENSE_NULL_PREMASTER_SECRET 1
|
2018-10-31 12:27:31 +03:00
|
|
|
#endif
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
#define PLATFORM_CHALLENGE_RESPONSE_VERSION 0x0100
|
|
|
|
|
|
|
|
/** @brief Licensing Packet Types */
|
|
|
|
enum LicenseRequestType
|
|
|
|
{
|
|
|
|
LICENSE_REQUEST = 0x01,
|
|
|
|
PLATFORM_CHALLENGE = 0x02,
|
|
|
|
NEW_LICENSE = 0x03,
|
|
|
|
UPGRADE_LICENSE = 0x04,
|
|
|
|
LICENSE_INFO = 0x12,
|
|
|
|
NEW_LICENSE_REQUEST = 0x13,
|
|
|
|
PLATFORM_CHALLENGE_RESPONSE = 0x15,
|
|
|
|
ERROR_ALERT = 0xFF
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LICENSE_PKT_CS_MASK \
|
|
|
|
(LICENSE_INFO | NEW_LICENSE_REQUEST | PLATFORM_CHALLENGE_RESPONSE | ERROR_ALERT)
|
|
|
|
#define LICENSE_PKT_SC_MASK \
|
|
|
|
(LICENSE_REQUEST | PLATFORM_CHALLENGE | NEW_LICENSE | UPGRADE_LICENSE | ERROR_ALERT)
|
|
|
|
#define LICENSE_PKT_MASK (LICENSE_PKT_CS_MASK | LICENSE_PKT_SC_MASK)
|
|
|
|
|
|
|
|
#define LICENSE_PREAMBLE_LENGTH 4
|
|
|
|
|
|
|
|
/* Cryptographic Lengths */
|
|
|
|
|
|
|
|
#define SERVER_RANDOM_LENGTH 32
|
|
|
|
#define MASTER_SECRET_LENGTH 48
|
|
|
|
#define PREMASTER_SECRET_LENGTH 48
|
|
|
|
#define SESSION_KEY_BLOB_LENGTH 48
|
|
|
|
#define MAC_SALT_KEY_LENGTH 16
|
|
|
|
#define LICENSING_ENCRYPTION_KEY_LENGTH 16
|
|
|
|
#define HWID_PLATFORM_ID_LENGTH 4
|
|
|
|
#define HWID_UNIQUE_DATA_LENGTH 16
|
|
|
|
#define HWID_LENGTH 20
|
|
|
|
#define LICENSING_PADDING_SIZE 8
|
|
|
|
|
|
|
|
/* Preamble Flags */
|
|
|
|
|
|
|
|
#define PREAMBLE_VERSION_2_0 0x02
|
|
|
|
#define PREAMBLE_VERSION_3_0 0x03
|
|
|
|
#define LicenseProtocolVersionMask 0x0F
|
|
|
|
#define EXTENDED_ERROR_MSG_SUPPORTED 0x80
|
|
|
|
|
|
|
|
/** @brief binary Blob Types */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BB_ANY_BLOB = 0x0000,
|
|
|
|
BB_DATA_BLOB = 0x0001,
|
|
|
|
BB_RANDOM_BLOB = 0x0002,
|
|
|
|
BB_CERTIFICATE_BLOB = 0x0003,
|
|
|
|
BB_ERROR_BLOB = 0x0004,
|
|
|
|
BB_ENCRYPTED_DATA_BLOB = 0x0009,
|
|
|
|
BB_KEY_EXCHG_ALG_BLOB = 0x000D,
|
|
|
|
BB_SCOPE_BLOB = 0x000E,
|
|
|
|
BB_CLIENT_USER_NAME_BLOB = 0x000F,
|
|
|
|
BB_CLIENT_MACHINE_NAME_BLOB = 0x0010
|
|
|
|
};
|
|
|
|
|
|
|
|
/* License Key Exchange Algorithms */
|
|
|
|
|
|
|
|
#define KEY_EXCHANGE_ALG_RSA 0x00000001
|
|
|
|
|
2022-12-09 16:35:03 +03:00
|
|
|
/** @brief license Error Codes
|
|
|
|
*/
|
2022-10-06 12:32:08 +03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ERR_INVALID_SERVER_CERTIFICATE = 0x00000001,
|
|
|
|
ERR_NO_LICENSE = 0x00000002,
|
|
|
|
ERR_INVALID_MAC = 0x00000003,
|
|
|
|
ERR_INVALID_SCOPE = 0x00000004,
|
|
|
|
ERR_NO_LICENSE_SERVER = 0x00000006,
|
|
|
|
STATUS_VALID_CLIENT = 0x00000007,
|
|
|
|
ERR_INVALID_CLIENT = 0x00000008,
|
|
|
|
ERR_INVALID_PRODUCT_ID = 0x0000000B,
|
|
|
|
ERR_INVALID_MESSAGE_LENGTH = 0x0000000C
|
|
|
|
};
|
|
|
|
|
2022-12-09 16:35:03 +03:00
|
|
|
/** @brief state Transition Codes
|
|
|
|
*/
|
2022-10-06 12:32:08 +03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ST_TOTAL_ABORT = 0x00000001,
|
|
|
|
ST_NO_TRANSITION = 0x00000002,
|
|
|
|
ST_RESET_PHASE_TO_START = 0x00000003,
|
|
|
|
ST_RESEND_LAST_MESSAGE = 0x00000004
|
|
|
|
};
|
|
|
|
|
2022-12-09 16:35:03 +03:00
|
|
|
/** @brief Platform Challenge Types
|
|
|
|
*/
|
2022-10-06 12:32:08 +03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
WIN32_PLATFORM_CHALLENGE_TYPE = 0x0100,
|
|
|
|
WIN16_PLATFORM_CHALLENGE_TYPE = 0x0200,
|
|
|
|
WINCE_PLATFORM_CHALLENGE_TYPE = 0x0300,
|
|
|
|
OTHER_PLATFORM_CHALLENGE_TYPE = 0xFF00
|
|
|
|
};
|
|
|
|
|
2022-12-09 16:35:03 +03:00
|
|
|
/** @brief License Detail Levels
|
|
|
|
*/
|
2022-10-06 12:32:08 +03:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LICENSE_DETAIL_SIMPLE = 0x0001,
|
|
|
|
LICENSE_DETAIL_MODERATE = 0x0002,
|
|
|
|
LICENSE_DETAIL_DETAIL = 0x0003
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PlatformId:
|
|
|
|
*
|
|
|
|
* The most significant byte of the PlatformId field contains the operating system version of the
|
|
|
|
* client. The second most significant byte of the PlatformId field identifies the ISV that provided
|
|
|
|
* the client image. The remaining two bytes in the PlatformId field are used by the ISV to identify
|
|
|
|
* the build number of the operating system.
|
|
|
|
*
|
|
|
|
* 0x04010000:
|
|
|
|
*
|
|
|
|
* CLIENT_OS_ID_WINNT_POST_52 (0x04000000)
|
|
|
|
* CLIENT_IMAGE_ID_MICROSOFT (0x00010000)
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CLIENT_OS_ID_WINNT_351 = 0x01000000,
|
|
|
|
CLIENT_OS_ID_WINNT_40 = 0x02000000,
|
|
|
|
CLIENT_OS_ID_WINNT_50 = 0x03000000,
|
|
|
|
CLIENT_OS_ID_WINNT_POST_52 = 0x04000000,
|
|
|
|
|
|
|
|
CLIENT_IMAGE_ID_MICROSOFT = 0x00010000,
|
|
|
|
CLIENT_IMAGE_ID_CITRIX = 0x00020000,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rdp_license
|
|
|
|
{
|
|
|
|
LICENSE_STATE state;
|
|
|
|
LICENSE_TYPE type;
|
|
|
|
rdpRdp* rdp;
|
|
|
|
rdpCertificate* certificate;
|
|
|
|
BYTE HardwareId[HWID_LENGTH];
|
|
|
|
BYTE ClientRandom[CLIENT_RANDOM_LENGTH];
|
|
|
|
BYTE ServerRandom[SERVER_RANDOM_LENGTH];
|
|
|
|
BYTE MasterSecret[MASTER_SECRET_LENGTH];
|
|
|
|
BYTE PremasterSecret[PREMASTER_SECRET_LENGTH];
|
|
|
|
BYTE SessionKeyBlob[SESSION_KEY_BLOB_LENGTH];
|
|
|
|
BYTE MacSaltKey[MAC_SALT_KEY_LENGTH];
|
|
|
|
BYTE LicensingEncryptionKey[LICENSING_ENCRYPTION_KEY_LENGTH];
|
|
|
|
LICENSE_PRODUCT_INFO* ProductInfo;
|
|
|
|
LICENSE_BLOB* ErrorInfo;
|
|
|
|
LICENSE_BLOB* LicenseInfo; /* Client -> Server */
|
|
|
|
LICENSE_BLOB* KeyExchangeList;
|
|
|
|
LICENSE_BLOB* ServerCertificate;
|
|
|
|
LICENSE_BLOB* ClientUserName;
|
|
|
|
LICENSE_BLOB* ClientMachineName;
|
|
|
|
LICENSE_BLOB* PlatformChallenge;
|
|
|
|
LICENSE_BLOB* EncryptedPremasterSecret;
|
|
|
|
LICENSE_BLOB* EncryptedPlatformChallenge;
|
|
|
|
LICENSE_BLOB* EncryptedPlatformChallengeResponse;
|
|
|
|
LICENSE_BLOB* EncryptedHardwareId;
|
|
|
|
LICENSE_BLOB* EncryptedLicenseInfo;
|
|
|
|
BYTE MACData[LICENSING_ENCRYPTION_KEY_LENGTH];
|
|
|
|
SCOPE_LIST* ScopeList;
|
|
|
|
UINT32 PacketHeaderLength;
|
|
|
|
UINT32 PreferredKeyExchangeAlg;
|
|
|
|
UINT32 PlatformId;
|
|
|
|
UINT16 ClientType;
|
|
|
|
UINT16 LicenseDetailLevel;
|
|
|
|
BOOL update;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL license_send_error_alert(rdpLicense* license, UINT32 dwErrorCode,
|
|
|
|
UINT32 dwStateTransition, const LICENSE_BLOB* info);
|
|
|
|
static BOOL license_set_state(rdpLicense* license, LICENSE_STATE state);
|
|
|
|
static const char* license_get_state_string(LICENSE_STATE state);
|
|
|
|
|
|
|
|
static const char* license_preferred_key_exchange_alg_string(UINT32 alg)
|
|
|
|
{
|
|
|
|
static char buffer[64] = { 0 };
|
|
|
|
const char* name = NULL;
|
|
|
|
|
|
|
|
switch (alg)
|
|
|
|
{
|
|
|
|
case KEY_EXCHANGE_ALG_RSA:
|
|
|
|
name = "KEY_EXCHANGE_ALG_RSA";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
name = "KEY_EXCHANGE_ALG_UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_snprintf(buffer, sizeof(buffer), "%s [0x%08" PRIx32 "]", name, alg);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* license_request_type_string(UINT32 type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LICENSE_REQUEST:
|
|
|
|
return "LICENSE_REQUEST";
|
|
|
|
case PLATFORM_CHALLENGE:
|
|
|
|
return "PLATFORM_CHALLENGE";
|
|
|
|
case NEW_LICENSE:
|
|
|
|
return "NEW_LICENSE";
|
|
|
|
case UPGRADE_LICENSE:
|
|
|
|
return "UPGRADE_LICENSE";
|
|
|
|
case LICENSE_INFO:
|
|
|
|
return "LICENSE_INFO";
|
|
|
|
case NEW_LICENSE_REQUEST:
|
|
|
|
return "NEW_LICENSE_REQUEST";
|
|
|
|
case PLATFORM_CHALLENGE_RESPONSE:
|
|
|
|
return "PLATFORM_CHALLENGE_RESPONSE";
|
|
|
|
case ERROR_ALERT:
|
|
|
|
return "ERROR_ALERT";
|
|
|
|
default:
|
|
|
|
return "LICENSE_REQUEST_TYPE_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* licencse_blob_type_string(UINT16 type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case BB_ANY_BLOB:
|
|
|
|
return "BB_ANY_BLOB";
|
|
|
|
case BB_DATA_BLOB:
|
|
|
|
return "BB_DATA_BLOB";
|
|
|
|
case BB_RANDOM_BLOB:
|
|
|
|
return "BB_RANDOM_BLOB";
|
|
|
|
case BB_CERTIFICATE_BLOB:
|
|
|
|
return "BB_CERTIFICATE_BLOB";
|
|
|
|
case BB_ERROR_BLOB:
|
|
|
|
return "BB_ERROR_BLOB";
|
|
|
|
case BB_ENCRYPTED_DATA_BLOB:
|
|
|
|
return "BB_ENCRYPTED_DATA_BLOB";
|
|
|
|
case BB_KEY_EXCHG_ALG_BLOB:
|
|
|
|
return "BB_KEY_EXCHG_ALG_BLOB";
|
|
|
|
case BB_SCOPE_BLOB:
|
|
|
|
return "BB_SCOPE_BLOB";
|
|
|
|
case BB_CLIENT_USER_NAME_BLOB:
|
|
|
|
return "BB_CLIENT_USER_NAME_BLOB";
|
|
|
|
case BB_CLIENT_MACHINE_NAME_BLOB:
|
|
|
|
return "BB_CLIENT_MACHINE_NAME_BLOB";
|
|
|
|
default:
|
|
|
|
return "BB_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
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 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);
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_read_binary_blob_data(LICENSE_BLOB* blob, UINT32 type, const void* data,
|
|
|
|
size_t length);
|
2017-05-29 11:50:22 +03:00
|
|
|
static BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob);
|
2018-10-31 12:27:31 +03:00
|
|
|
static BOOL license_write_binary_blob(wStream* s, const LICENSE_BLOB* blob);
|
2017-05-29 11:50:22 +03:00
|
|
|
|
|
|
|
static SCOPE_LIST* license_new_scope_list(void);
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_scope_list_resize(SCOPE_LIST* scopeList, UINT32 count);
|
2017-05-29 11:50:22 +03:00
|
|
|
static void license_free_scope_list(SCOPE_LIST* scopeList);
|
|
|
|
static BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList);
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_write_scope_list(wStream* s, const SCOPE_LIST* scopeList);
|
2017-05-29 11:50:22 +03:00
|
|
|
|
|
|
|
static BOOL license_read_license_request_packet(rdpLicense* license, wStream* s);
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_write_license_request_packet(const rdpLicense* license, wStream* s);
|
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
static BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s);
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_send_platform_challenge_packet(rdpLicense* license);
|
2018-10-31 12:27:31 +03:00
|
|
|
static BOOL license_read_new_or_upgrade_license_packet(rdpLicense* license, wStream* s);
|
2017-05-29 11:50:22 +03:00
|
|
|
static BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s);
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_write_new_license_request_packet(const rdpLicense* license, wStream* s);
|
|
|
|
static BOOL license_read_new_license_request_packet(rdpLicense* license, wStream* s);
|
2018-10-31 12:27:31 +03:00
|
|
|
static BOOL license_answer_license_request(rdpLicense* license);
|
2017-05-29 11:50:22 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_send_platform_challenge_response(rdpLicense* license);
|
|
|
|
static BOOL license_read_platform_challenge_response(rdpLicense* license, wStream* s);
|
|
|
|
|
|
|
|
static BOOL license_read_client_platform_challenge_response(rdpLicense* license, wStream* s);
|
|
|
|
static BOOL license_write_client_platform_challenge_response(rdpLicense* license, wStream* s);
|
|
|
|
|
|
|
|
static BOOL license_read_server_upgrade_license(rdpLicense* license, wStream* s);
|
|
|
|
static BOOL license_write_server_upgrade_license(const rdpLicense* license, wStream* s);
|
|
|
|
|
|
|
|
static BOOL license_send_license_info(rdpLicense* license, const LICENSE_BLOB* calBlob,
|
2023-01-28 15:16:39 +03:00
|
|
|
const BYTE* signature, size_t signature_length);
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_read_license_info(rdpLicense* license, wStream* s);
|
2022-11-11 14:26:28 +03:00
|
|
|
static state_run_t license_client_recv(rdpLicense* license, wStream* s);
|
|
|
|
static state_run_t license_server_recv(rdpLicense* license, wStream* s);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
#define PLATFORMID (CLIENT_OS_ID_WINNT_POST_52 | CLIENT_IMAGE_ID_MICROSOFT)
|
2017-05-29 11:50:22 +03:00
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const char* const error_codes[] = { "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" };
|
|
|
|
|
|
|
|
static const char* const state_transitions[] = { "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
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
static void license_print_product_info(const LICENSE_PRODUCT_INFO* productInfo)
|
2013-02-05 08:57:04 +04:00
|
|
|
{
|
|
|
|
char* CompanyName = NULL;
|
|
|
|
char* ProductId = NULL;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(productInfo);
|
2022-10-28 09:09:27 +03:00
|
|
|
WINPR_ASSERT(productInfo->pbCompanyName);
|
|
|
|
WINPR_ASSERT(productInfo->pbProductId);
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2023-01-30 16:37:41 +03:00
|
|
|
CompanyName = ConvertWCharNToUtf8Alloc((const WCHAR*)productInfo->pbCompanyName,
|
2023-01-24 12:44:31 +03:00
|
|
|
productInfo->cbCompanyName / sizeof(WCHAR), NULL);
|
2023-01-30 16:37:41 +03:00
|
|
|
ProductId = ConvertWCharNToUtf8Alloc((const WCHAR*)productInfo->pbProductId,
|
2023-01-24 12:44:31 +03:00
|
|
|
productInfo->cbProductId / sizeof(WCHAR), NULL);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_INFO(TAG, "ProductInfo:");
|
2019-11-06 17:24:51 +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);
|
|
|
|
}
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
static void license_print_scope_list(const SCOPE_LIST* scopeList)
|
2013-02-05 09:19:57 +04:00
|
|
|
{
|
2019-10-16 15:54:05 +03:00
|
|
|
UINT32 index;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(scopeList);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_INFO(TAG, "ScopeList (%" PRIu32 "):", scopeList->count);
|
2013-02-05 09:19:57 +04:00
|
|
|
|
|
|
|
for (index = 0; index < scopeList->count; index++)
|
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
const LICENSE_BLOB* scope;
|
|
|
|
|
|
|
|
WINPR_ASSERT(scopeList->array);
|
|
|
|
scope = scopeList->array[index];
|
|
|
|
WINPR_ASSERT(scope);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_INFO(TAG, "\t%s", (const 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
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
static const char licenseStore[] = "licenses";
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_ensure_state(rdpLicense* license, LICENSE_STATE state, UINT32 msg)
|
|
|
|
{
|
|
|
|
const LICENSE_STATE cstate = license_get_state(license);
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
if (cstate != state)
|
|
|
|
{
|
|
|
|
const char* scstate = license_get_state_string(cstate);
|
|
|
|
const char* sstate = license_get_state_string(state);
|
|
|
|
const char* where = license_request_type_string(msg);
|
|
|
|
|
|
|
|
WLog_WARN(TAG, "Received [%s], but found invalid licensing state %s, expected %s", where,
|
|
|
|
scstate, sstate);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t license_recv(rdpLicense* license, wStream* s)
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
WINPR_ASSERT(license->rdp->settings);
|
|
|
|
|
|
|
|
if (freerdp_settings_get_bool(license->rdp->settings, FreeRDP_ServerMode))
|
|
|
|
return license_server_recv(license, s);
|
|
|
|
else
|
|
|
|
return license_client_recv(license, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL license_check_stream_length(wStream* s, SSIZE_T expect, const char* where)
|
|
|
|
{
|
|
|
|
const size_t remain = Stream_GetRemainingLength(s);
|
|
|
|
|
|
|
|
WINPR_ASSERT(where);
|
|
|
|
|
|
|
|
if (expect < 0)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "invalid %s, expected value %" PRIdz " invalid", where, expect);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2022-12-05 10:58:38 +03:00
|
|
|
if (remain < (size_t)expect)
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "short %s, expected %" PRIdz " bytes, got %" PRIuz, where, expect, remain);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL license_check_stream_capacity(wStream* s, size_t expect, const char* where)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(where);
|
|
|
|
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacityEx(TAG, WLOG_WARN, s, expect, 1, "%s(%s:%" PRIuz ") %s",
|
2023-07-27 10:02:03 +03:00
|
|
|
__func__, __FILE__, (size_t)__LINE__, where))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
2023-01-24 14:19:56 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL computeCalHash(const char* hostname, char* hashStr)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
|
|
|
WINPR_DIGEST_CTX* sha1 = NULL;
|
|
|
|
BOOL ret = FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
BYTE hash[20] = { 0 };
|
2019-02-07 16:22:28 +03:00
|
|
|
size_t i;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(hostname);
|
|
|
|
WINPR_ASSERT(hashStr);
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!(sha1 = winpr_Digest_New()))
|
|
|
|
goto out;
|
|
|
|
if (!winpr_Digest_Init(sha1, WINPR_MD_SHA1))
|
|
|
|
goto out;
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!winpr_Digest_Update(sha1, (const BYTE*)hostname, strlen(hostname)))
|
2018-10-31 12:27:31 +03:00
|
|
|
goto out;
|
|
|
|
if (!winpr_Digest_Final(sha1, hash, sizeof(hash)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(hash); i++, hashStr += 2)
|
|
|
|
sprintf_s(hashStr, 3, "%.2x", hash[i]);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = TRUE;
|
2018-10-31 12:27:31 +03:00
|
|
|
out:
|
|
|
|
winpr_Digest_Free(sha1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL saveCal(const rdpSettings* settings, const BYTE* data, size_t length,
|
|
|
|
const char* hostname)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2022-10-25 14:46:22 +03:00
|
|
|
char hash[41] = { 0 };
|
2019-11-06 17:24:51 +03:00
|
|
|
FILE* fp;
|
|
|
|
char* licenseStorePath = NULL;
|
2022-10-25 14:46:22 +03:00
|
|
|
char filename[MAX_PATH] = { 0 }, filenameNew[MAX_PATH] = { 0 };
|
2018-10-31 12:27:31 +03:00
|
|
|
char *filepath = NULL, *filepathNew = NULL;
|
2022-10-25 14:46:22 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
size_t written;
|
|
|
|
BOOL ret = FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
const char* path = freerdp_settings_get_string(settings, FreeRDP_ConfigPath);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(path);
|
|
|
|
WINPR_ASSERT(data || (length == 0));
|
|
|
|
WINPR_ASSERT(hostname);
|
|
|
|
|
|
|
|
if (!winpr_PathFileExists(path))
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!winpr_PathMakePath(path, 0))
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WLog_ERR(TAG, "error creating directory '%s'", path);
|
2018-10-31 12:27:31 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2022-10-06 12:32:08 +03:00
|
|
|
WLog_INFO(TAG, "creating directory %s", path);
|
2018-10-31 12:27:31 +03:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!(licenseStorePath = GetCombinedPath(path, licenseStore)))
|
2018-10-31 12:27:31 +03:00
|
|
|
goto out;
|
|
|
|
|
2021-05-31 12:42:03 +03:00
|
|
|
if (!winpr_PathFileExists(licenseStorePath))
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2021-05-31 12:42:03 +03:00
|
|
|
if (!winpr_PathMakePath(licenseStorePath, 0))
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "error creating directory '%s'", licenseStorePath);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
WLog_INFO(TAG, "creating directory %s", licenseStorePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!computeCalHash(hostname, hash))
|
|
|
|
goto out;
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(filename, sizeof(filename) - 1, "%s.cal", hash);
|
|
|
|
sprintf_s(filenameNew, sizeof(filenameNew) - 1, "%s.cal.new", hash);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
if (!(filepath = GetCombinedPath(licenseStorePath, filename)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!(filepathNew = GetCombinedPath(licenseStorePath, filenameNew)))
|
|
|
|
goto out;
|
|
|
|
|
2021-05-31 12:42:03 +03:00
|
|
|
fp = winpr_fopen(filepathNew, "wb");
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!fp)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
written = fwrite(data, length, 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if (written != 1)
|
|
|
|
{
|
2022-10-25 14:46:22 +03:00
|
|
|
winpr_DeleteFile(filepathNew);
|
2018-10-31 12:27:31 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-10-25 14:46:22 +03:00
|
|
|
ret = winpr_MoveFileEx(filepathNew, filepath, MOVEFILE_REPLACE_EXISTING);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(filepathNew);
|
|
|
|
free(filepath);
|
|
|
|
free(licenseStorePath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BYTE* loadCalFile(const rdpSettings* settings, const char* hostname, size_t* dataLen)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
|
|
|
char *licenseStorePath = NULL, *calPath = NULL;
|
2022-10-06 12:32:08 +03:00
|
|
|
char calFilename[MAX_PATH] = { 0 };
|
|
|
|
char hash[41] = { 0 };
|
2021-06-16 15:50:14 +03:00
|
|
|
INT64 length;
|
2021-02-07 21:58:32 +03:00
|
|
|
int status;
|
2019-11-06 17:24:51 +03:00
|
|
|
FILE* fp;
|
|
|
|
BYTE* ret = NULL;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
WINPR_ASSERT(hostname);
|
|
|
|
WINPR_ASSERT(dataLen);
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!computeCalHash(hostname, hash))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "loadCalFile: unable to compute hostname hash");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(calFilename, sizeof(calFilename) - 1, "%s.cal", hash);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!(licenseStorePath = GetCombinedPath(
|
|
|
|
freerdp_settings_get_string(settings, FreeRDP_ConfigPath), licenseStore)))
|
2018-10-31 12:27:31 +03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(calPath = GetCombinedPath(licenseStorePath, calFilename)))
|
|
|
|
goto error_path;
|
|
|
|
|
2021-05-31 12:42:03 +03:00
|
|
|
fp = winpr_fopen(calPath, "rb");
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!fp)
|
|
|
|
goto error_open;
|
|
|
|
|
|
|
|
_fseeki64(fp, 0, SEEK_END);
|
|
|
|
length = _ftelli64(fp);
|
|
|
|
_fseeki64(fp, 0, SEEK_SET);
|
2021-06-16 15:50:14 +03:00
|
|
|
if (length < 0)
|
|
|
|
goto error_malloc;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
ret = (BYTE*)malloc((size_t)length);
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!ret)
|
|
|
|
goto error_malloc;
|
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
status = fread(ret, (size_t)length, 1, fp);
|
2018-10-31 12:27:31 +03:00
|
|
|
if (status <= 0)
|
|
|
|
goto error_read;
|
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
*dataLen = (size_t)length;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
free(calPath);
|
|
|
|
free(licenseStorePath);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error_read:
|
|
|
|
free(ret);
|
|
|
|
error_malloc:
|
|
|
|
fclose(fp);
|
|
|
|
error_open:
|
|
|
|
free(calPath);
|
|
|
|
error_path:
|
|
|
|
free(licenseStorePath);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read a licensing preamble.
|
|
|
|
* msdn{cc240480}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL license_read_preamble(wStream* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgSize)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(bMsgType);
|
|
|
|
WINPR_ASSERT(flags);
|
|
|
|
WINPR_ASSERT(wMsgSize);
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/* preamble (4 bytes) */
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_check_stream_length(s, 4, "license preamble"))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, *bMsgType); /* bMsgType (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, *flags); /* flags (1 byte) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, *wMsgSize); /* wMsgSize (2 bytes) */
|
2022-10-06 12:32:08 +03:00
|
|
|
return license_check_stream_length(s, *wMsgSize - 4ll, "license preamble::wMsgSize");
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Write a licensing preamble.
|
|
|
|
* msdn{cc240480}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param bMsgType license message type
|
|
|
|
* @param flags message flags
|
|
|
|
* @param wMsgSize message size
|
2022-12-09 16:35:03 +03:00
|
|
|
* @return if the operation completed successfully
|
2011-07-12 09:16:59 +04:00
|
|
|
*/
|
|
|
|
|
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) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, bMsgType); /* bMsgType (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, flags); /* flags (1 byte) */
|
2013-05-09 00:09:16 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* @brief Initialize a license packet stream.
|
|
|
|
*
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
2022-12-09 16:35:03 +03:00
|
|
|
*
|
|
|
|
* @return stream or NULL
|
2011-07-12 09:16:59 +04:00
|
|
|
*/
|
|
|
|
|
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;
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL do_crypt;
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
|
|
|
|
do_crypt = license->rdp->do_crypt;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
license->rdp->sec_flags = SEC_LICENSE_PKT;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2022-12-09 16:35:03 +03: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-31 12:27:31 +03:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return NULL;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Send an RDP licensing packet.
|
|
|
|
* msdn{cc240479}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
static BOOL license_send(rdpLicense* license, wStream* s, BYTE type)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2017-12-11 12:25:21 +03:00
|
|
|
size_t length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags;
|
|
|
|
UINT16 wMsgSize;
|
2022-10-06 12:32:08 +03:00
|
|
|
rdpRdp* rdp;
|
2018-10-31 12:27:31 +03:00
|
|
|
BOOL ret;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
|
|
|
|
rdp = license->rdp;
|
|
|
|
WINPR_ASSERT(rdp->settings);
|
|
|
|
|
|
|
|
DEBUG_LICENSE("Sending %s Packet", license_request_type_string(type));
|
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
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!license_write_preamble(s, type, flags, wMsgSize))
|
2018-10-31 12:27:31 +03:00
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2022-10-06 12:32:08 +03:00
|
|
|
WLog_DBG(TAG, "Sending %s Packet, length %" PRIu16 "", license_request_type_string(type),
|
2019-11-06 17:24:51 +03:00
|
|
|
wMsgSize);
|
2023-06-14 03:45:12 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_PointerAs(s, char) - 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-31 12:27:31 +03:00
|
|
|
ret = rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID);
|
2014-04-02 16:17:39 +04:00
|
|
|
rdp->sec_flags = 0;
|
2018-10-31 12:27:31 +03:00
|
|
|
return ret;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_read_server_upgrade_license(rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
if (!license_read_binary_blob(s, license->EncryptedLicenseInfo))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_check_stream_length(s, sizeof(license->MACData),
|
|
|
|
"SERVER_UPGRADE_LICENSE::MACData"))
|
|
|
|
return FALSE;
|
|
|
|
Stream_Read(s, license->MACData, sizeof(license->MACData));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_write_server_upgrade_license(const rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
if (!license_write_binary_blob(s, license->EncryptedLicenseInfo))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_check_stream_capacity(s, sizeof(license->MACData),
|
|
|
|
"SERVER_UPGRADE_LICENSE::MACData"))
|
|
|
|
return FALSE;
|
|
|
|
Stream_Write(s, license->MACData, sizeof(license->MACData));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL license_server_send_new_or_upgrade_license(rdpLicense* license, BOOL upgrade)
|
|
|
|
{
|
|
|
|
wStream* s = license_send_stream_init(license);
|
|
|
|
const BYTE type = upgrade ? UPGRADE_LICENSE : NEW_LICENSE;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!license_write_server_upgrade_license(license, s))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return license_send(license, s, type);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Receive an RDP licensing packet.
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
int license_client_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;
|
2022-10-06 12:32:08 +03:00
|
|
|
const size_t length = Stream_GetRemainingLength(s);
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
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) */
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
DEBUG_LICENSE("Receiving %s Packet", license_request_type_string(bMsgType));
|
2011-08-08 07:59:28 +04:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
switch (bMsgType)
|
|
|
|
{
|
|
|
|
case LICENSE_REQUEST:
|
2022-10-06 12:32:08 +03:00
|
|
|
/* Client does not require configuration, so skip this state */
|
|
|
|
if (license_get_state(license) == LICENSE_STATE_INITIAL)
|
|
|
|
license_set_state(license, LICENSE_STATE_CONFIGURED);
|
|
|
|
|
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_CONFIGURED, bMsgType))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!license_read_license_request_packet(license, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!license_answer_license_request(license))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
license_set_state(license, LICENSE_STATE_NEW_REQUEST);
|
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:
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_NEW_REQUEST, bMsgType))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!license_read_platform_challenge_packet(license, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2014-08-19 20:26:39 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_send_platform_challenge_response(license))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2022-10-06 12:32:08 +03:00
|
|
|
license_set_state(license, LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE);
|
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:
|
|
|
|
case UPGRADE_LICENSE:
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE, bMsgType))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!license_read_new_or_upgrade_license_packet(license, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
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 ERROR_ALERT:
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!license_read_error_alert_packet(license, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
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:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid bMsgType:%" PRIu8 "", bMsgType);
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2020-02-20 10:22:19 +03:00
|
|
|
if (!tpkt_ensure_stream_consumed(s, length))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
|
|
|
return STATE_RUN_SUCCESS;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t license_server_recv(rdpLicense* license, wStream* s)
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t rc = STATE_RUN_FAILED;
|
2022-10-06 12:32:08 +03:00
|
|
|
BYTE flags;
|
|
|
|
BYTE bMsgType;
|
|
|
|
UINT16 wMsgSize;
|
|
|
|
const size_t length = Stream_GetRemainingLength(s);
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
if (!license_read_preamble(s, &bMsgType, &flags, &wMsgSize)) /* preamble (4 bytes) */
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
DEBUG_LICENSE("Receiving %s Packet", license_request_type_string(bMsgType));
|
|
|
|
|
|
|
|
switch (bMsgType)
|
|
|
|
{
|
|
|
|
case NEW_LICENSE_REQUEST:
|
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_REQUEST, bMsgType))
|
|
|
|
goto fail;
|
|
|
|
if (!license_read_new_license_request_packet(license, s))
|
|
|
|
goto fail;
|
|
|
|
// TODO: Validate if client is allowed
|
|
|
|
if (!license_send_error_alert(license, ERR_INVALID_MAC, ST_TOTAL_ABORT,
|
|
|
|
license->ErrorInfo))
|
|
|
|
goto fail;
|
|
|
|
if (!license_send_platform_challenge_packet(license))
|
|
|
|
goto fail;
|
|
|
|
license->update = FALSE;
|
|
|
|
if (!license_set_state(license, LICENSE_STATE_PLATFORM_CHALLENGE))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
case LICENSE_INFO:
|
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_REQUEST, bMsgType))
|
|
|
|
goto fail;
|
|
|
|
if (!license_read_license_info(license, s))
|
|
|
|
goto fail;
|
|
|
|
// TODO: Validate license info
|
|
|
|
if (!license_send_platform_challenge_packet(license))
|
|
|
|
goto fail;
|
|
|
|
if (!license_set_state(license, LICENSE_STATE_PLATFORM_CHALLENGE))
|
|
|
|
goto fail;
|
|
|
|
license->update = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLATFORM_CHALLENGE_RESPONSE:
|
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_PLATFORM_CHALLENGE, bMsgType))
|
|
|
|
goto fail;
|
|
|
|
if (!license_read_client_platform_challenge_response(license, s))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
// TODO: validate challenge response
|
|
|
|
if (FALSE)
|
|
|
|
{
|
|
|
|
if (license_send_error_alert(license, ERR_INVALID_CLIENT, ST_TOTAL_ABORT,
|
|
|
|
license->ErrorInfo))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!license_server_send_new_or_upgrade_license(license, license->update))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
license->type = LICENSE_TYPE_ISSUED;
|
|
|
|
license_set_state(license, LICENSE_STATE_COMPLETED);
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
rc = STATE_RUN_CONTINUE; /* License issued, switch state */
|
2022-10-06 12:32:08 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ERROR_ALERT:
|
|
|
|
if (!license_read_error_alert_packet(license, s))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "invalid bMsgType:%" PRIu8 "", bMsgType);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tpkt_ensure_stream_consumed(s, length))
|
|
|
|
goto fail;
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
if (!state_run_success(rc))
|
|
|
|
rc = STATE_RUN_SUCCESS;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
fail:
|
2022-11-11 14:26:28 +03:00
|
|
|
if (state_run_failed(rc))
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
|
|
|
if (flags & EXTENDED_ERROR_MSG_SUPPORTED)
|
|
|
|
license_send_error_alert(license, ERR_INVALID_CLIENT, ST_TOTAL_ABORT, NULL);
|
|
|
|
license_set_state(license, LICENSE_STATE_ABORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-07-13 19:40:19 +04:00
|
|
|
void license_generate_randoms(rdpLicense* license)
|
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
#ifdef LICENSE_NULL_CLIENT_RANDOM
|
2023-01-28 14:57:17 +03:00
|
|
|
ZeroMemory(license->ClientRandom, sizeof(license->ClientRandom)); /* ClientRandom */
|
2018-10-31 12:27:31 +03:00
|
|
|
#else
|
2023-01-30 14:14:03 +03:00
|
|
|
winpr_RAND(license->ClientRandom, sizeof(license->ClientRandom)); /* ClientRandom */
|
2013-02-05 18:46:25 +04:00
|
|
|
#endif
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2023-01-28 15:00:41 +03:00
|
|
|
winpr_RAND(license->ServerRandom, sizeof(license->ServerRandom)); /* ServerRandom */
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
#ifdef LICENSE_NULL_PREMASTER_SECRET
|
2023-01-28 15:02:36 +03:00
|
|
|
ZeroMemory(license->PremasterSecret, sizeof(license->PremasterSecret)); /* PremasterSecret */
|
2018-10-31 12:27:31 +03:00
|
|
|
#else
|
2023-01-28 15:02:36 +03:00
|
|
|
winpr_RAND(license->PremasterSecret, sizeof(license->PremasterSecret)); /* 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
|
|
|
|
*/
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
static BOOL license_generate_keys(rdpLicense* license)
|
2011-07-12 09:57:09 +04:00
|
|
|
{
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL ret;
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
2015-04-01 12:11:37 +03:00
|
|
|
if (
|
2019-11-06 17:24:51 +03:00
|
|
|
/* MasterSecret */
|
2023-01-30 14:14:03 +03:00
|
|
|
!security_master_secret(license->PremasterSecret, sizeof(license->PremasterSecret),
|
|
|
|
license->ClientRandom, sizeof(license->ClientRandom),
|
|
|
|
license->ServerRandom, sizeof(license->ServerRandom),
|
|
|
|
license->MasterSecret, sizeof(license->MasterSecret)) ||
|
2019-11-06 17:24:51 +03:00
|
|
|
/* SessionKeyBlob */
|
2023-01-30 14:14:03 +03:00
|
|
|
!security_session_key_blob(license->MasterSecret, sizeof(license->MasterSecret),
|
|
|
|
license->ClientRandom, sizeof(license->ClientRandom),
|
|
|
|
license->ServerRandom, sizeof(license->ServerRandom),
|
|
|
|
license->SessionKeyBlob, sizeof(license->SessionKeyBlob)))
|
2015-04-01 12:11:37 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-01-30 14:14:03 +03:00
|
|
|
security_mac_salt_key(license->SessionKeyBlob, sizeof(license->SessionKeyBlob),
|
|
|
|
license->ClientRandom, sizeof(license->ClientRandom),
|
|
|
|
license->ServerRandom, sizeof(license->ServerRandom), license->MacSaltKey,
|
|
|
|
sizeof(license->MacSaltKey)); /* MacSaltKey */
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = security_licensing_encryption_key(
|
2023-01-30 14:14:03 +03:00
|
|
|
license->SessionKeyBlob, sizeof(license->SessionKeyBlob), license->ClientRandom,
|
|
|
|
sizeof(license->ClientRandom), license->ServerRandom, sizeof(license->ServerRandom),
|
|
|
|
license->LicensingEncryptionKey,
|
|
|
|
sizeof(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:");
|
2023-01-28 14:57:17 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, sizeof(license->ClientRandom));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "ServerRandom:");
|
2023-01-28 15:00:41 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ServerRandom, sizeof(license->ServerRandom));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "PremasterSecret:");
|
2023-01-28 15:02:36 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->PremasterSecret, sizeof(license->PremasterSecret));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "MasterSecret:");
|
2023-01-28 15:01:41 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->MasterSecret, sizeof(license->MasterSecret));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "SessionKeyBlob:");
|
2023-01-28 15:03:29 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->SessionKeyBlob, sizeof(license->SessionKeyBlob));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "MacSaltKey:");
|
2023-01-28 15:04:08 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->MacSaltKey, sizeof(license->MacSaltKey));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "LicensingEncryptionKey:");
|
2019-11-06 17:24:51 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->LicensingEncryptionKey,
|
2023-01-28 15:16:39 +03:00
|
|
|
sizeof(license->LicensingEncryptionKey));
|
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
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Generate Unique Hardware Identifier (CLIENT_HARDWARE_ID).
|
2011-07-12 10:53:26 +04:00
|
|
|
* @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
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const BYTE* hashTarget;
|
2018-10-31 12:27:31 +03:00
|
|
|
size_t targetLen;
|
2022-10-13 17:25:36 +03:00
|
|
|
BYTE macAddress[6] = { 0 };
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
WINPR_ASSERT(license->rdp->settings);
|
|
|
|
|
2023-01-28 15:18:59 +03:00
|
|
|
ZeroMemory(license->HardwareId, sizeof(license->HardwareId));
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
if (license->rdp->settings->OldLicenseBehaviour)
|
|
|
|
{
|
|
|
|
hashTarget = macAddress;
|
|
|
|
targetLen = sizeof(macAddress);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-14 09:42:49 +03:00
|
|
|
wStream buffer;
|
|
|
|
wStream* s;
|
2019-11-06 17:24:51 +03:00
|
|
|
const char* hostname = license->rdp->settings->ClientHostname;
|
2021-10-14 09:42:49 +03:00
|
|
|
s = Stream_StaticInit(&buffer, license->HardwareId, 4);
|
2022-10-06 12:32:08 +03:00
|
|
|
Stream_Write_UINT32(s, license->PlatformId);
|
2021-10-14 09:42:49 +03:00
|
|
|
Stream_Free(s, TRUE);
|
2018-11-01 13:02:54 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hashTarget = (const BYTE*)hostname;
|
2018-10-31 12:27:31 +03:00
|
|
|
targetLen = strlen(hostname);
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +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-31 12:27:31 +03:00
|
|
|
return winpr_Digest_Allow_FIPS(WINPR_MD_MD5, hashTarget, targetLen,
|
2019-11-06 17:24:51 +03:00
|
|
|
&license->HardwareId[HWID_PLATFORM_ID_LENGTH],
|
|
|
|
WINPR_MD5_DIGEST_LENGTH);
|
2011-07-12 10:53:26 +04:00
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL license_get_server_rsa_public_key(rdpLicense* license)
|
2011-07-15 09:11:09 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->certificate);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
|
|
|
|
settings = license->rdp->settings;
|
|
|
|
WINPR_ASSERT(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
|
|
|
{
|
2023-02-03 13:51:14 +03:00
|
|
|
if (!freerdp_certificate_read_server_cert(license->certificate, settings->ServerCertificate,
|
|
|
|
settings->ServerCertificateLength))
|
2019-11-06 17:24:51 +03:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
}
|
2011-09-17 00:37:20 +04:00
|
|
|
|
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
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
2023-01-28 14:16:16 +03:00
|
|
|
WINPR_ASSERT(license->certificate);
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
if (!license_get_server_rsa_public_key(license))
|
|
|
|
return FALSE;
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license->EncryptedPremasterSecret);
|
2023-02-03 13:51:14 +03:00
|
|
|
|
|
|
|
const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
|
|
|
|
if (!info)
|
|
|
|
return FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2011-08-08 22:51:03 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2023-01-28 14:16:16 +03:00
|
|
|
WLog_DBG(TAG, "Modulus (%" PRIu32 " bits):", info->ModulusLength * 8);
|
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, info->Modulus, info->ModulusLength);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "Exponent:");
|
2023-01-28 14:16:16 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, info->exponent, sizeof(info->exponent));
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2023-01-28 14:16:16 +03:00
|
|
|
EncryptedPremasterSecret = (BYTE*)calloc(1, info->ModulusLength);
|
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;
|
2023-01-28 15:02:36 +03:00
|
|
|
license->EncryptedPremasterSecret->length = sizeof(license->PremasterSecret);
|
2013-02-05 18:46:25 +04:00
|
|
|
#ifndef LICENSE_NULL_PREMASTER_SECRET
|
2021-04-15 16:55:43 +03:00
|
|
|
{
|
2023-01-28 14:42:54 +03:00
|
|
|
const SSIZE_T length =
|
|
|
|
crypto_rsa_public_encrypt(license->PremasterSecret, sizeof(license->PremasterSecret),
|
|
|
|
info, EncryptedPremasterSecret, info->ModulusLength);
|
2021-04-15 16:55:43 +03:00
|
|
|
if ((length < 0) || (length > UINT16_MAX))
|
|
|
|
return FALSE;
|
|
|
|
license->EncryptedPremasterSecret->length = (UINT16)length;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL license_rc4_with_licenseKey(const rdpLicense* license, const BYTE* input, size_t len,
|
|
|
|
LICENSE_BLOB* target)
|
2011-07-15 09:11:09 +04:00
|
|
|
{
|
2016-02-28 13:12:17 +03:00
|
|
|
WINPR_RC4_CTX* rc4;
|
2019-11-06 17:24:51 +03:00
|
|
|
BYTE* buffer = NULL;
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(input || (len == 0));
|
|
|
|
WINPR_ASSERT(target);
|
|
|
|
|
2023-01-28 15:16:39 +03:00
|
|
|
rc4 = winpr_RC4_New_Allow_FIPS(license->LicensingEncryptionKey,
|
|
|
|
sizeof(license->LicensingEncryptionKey));
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!rc4)
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
buffer = (BYTE*)realloc(target->data, len);
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!buffer)
|
|
|
|
goto error_buffer;
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
target->data = buffer;
|
|
|
|
target->length = len;
|
|
|
|
|
|
|
|
if (!winpr_RC4_Update(rc4, len, input, buffer))
|
2018-11-21 17:03:42 +03:00
|
|
|
goto error_buffer;
|
2015-02-11 19:57:02 +03:00
|
|
|
|
2016-02-28 13:12:17 +03:00
|
|
|
winpr_RC4_Free(rc4);
|
2018-10-31 12:27:31 +03:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error_buffer:
|
|
|
|
winpr_RC4_Free(rc4);
|
|
|
|
return FALSE;
|
2011-07-15 09:11:09 +04:00
|
|
|
}
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
/**
|
|
|
|
* Encrypt the input using the license key and MAC the input for a signature
|
|
|
|
*
|
|
|
|
* @param license rdpLicense to get keys and salt from
|
|
|
|
* @param input the input data to encrypt and MAC
|
|
|
|
* @param len size of input
|
|
|
|
* @param target a target LICENSE_BLOB where the encrypted input will be stored
|
|
|
|
* @param mac the signature buffer (16 bytes)
|
|
|
|
* @return if the operation completed successfully
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL license_encrypt_and_MAC(rdpLicense* license, const BYTE* input, size_t len,
|
2023-01-28 15:16:39 +03:00
|
|
|
LICENSE_BLOB* target, BYTE* mac, size_t mac_length)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
2018-10-31 12:27:31 +03:00
|
|
|
return license_rc4_with_licenseKey(license, input, len, target) &&
|
2023-01-28 15:16:39 +03:00
|
|
|
security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), input, len, mac,
|
|
|
|
mac_length);
|
2018-10-31 12:27:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrypt the input using the license key and check the MAC
|
|
|
|
*
|
|
|
|
* @param license rdpLicense to get keys and salt from
|
|
|
|
* @param input the input data to decrypt and MAC
|
|
|
|
* @param len size of input
|
|
|
|
* @param target a target LICENSE_BLOB where the decrypted input will be stored
|
2022-12-09 16:35:03 +03:00
|
|
|
* @param packetMac the signature buffer (16 bytes)
|
|
|
|
*
|
2018-10-31 12:27:31 +03:00
|
|
|
* @return if the operation completed successfully
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL license_decrypt_and_check_MAC(rdpLicense* license, const BYTE* input, size_t len,
|
|
|
|
LICENSE_BLOB* target, const BYTE* packetMac)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2023-01-28 15:16:39 +03:00
|
|
|
BYTE macData[sizeof(license->MACData)] = { 0 };
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(target);
|
|
|
|
|
|
|
|
if (freerdp_settings_get_bool(license->rdp->settings, FreeRDP_TransportDumpReplay))
|
|
|
|
return TRUE;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
return license_rc4_with_licenseKey(license, input, len, target) &&
|
2023-01-28 15:16:39 +03:00
|
|
|
security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), target->data, len,
|
|
|
|
macData, sizeof(macData)) &&
|
2019-11-06 17:24:51 +03:00
|
|
|
(memcmp(packetMac, macData, sizeof(macData)) == 0);
|
2018-10-31 12:27:31 +03:00
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read Product Information (PRODUCT_INFO).
|
|
|
|
* 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
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(productInfo);
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, 8, "license product info::cbCompanyName"))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
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))
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "license product info invalid cbCompanyName %" PRIu32,
|
|
|
|
productInfo->cbCompanyName);
|
2017-05-29 11:50:22 +03:00
|
|
|
return FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
}
|
2017-05-29 11:50:22 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_check_stream_length(s, productInfo->cbCompanyName,
|
|
|
|
"license product info::CompanyName"))
|
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;
|
2019-11-06 17:24:51 +03:00
|
|
|
productInfo->pbCompanyName = (BYTE*)malloc(productInfo->cbCompanyName);
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!productInfo->pbCompanyName)
|
2022-10-06 12:32:08 +03:00
|
|
|
goto out_fail;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
|
2017-05-29 11:50:22 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_check_stream_length(s, 4, "license product info::cbProductId"))
|
2017-05-29 11:50:22 +03:00
|
|
|
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))
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "license product info invalid cbProductId %" PRIu32,
|
|
|
|
productInfo->cbProductId);
|
2017-05-29 11:50:22 +03:00
|
|
|
goto out_fail;
|
2022-10-06 12:32:08 +03:00
|
|
|
}
|
2017-05-29 11:50:22 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_check_stream_length(s, productInfo->cbProductId,
|
|
|
|
"license product info::ProductId"))
|
2015-06-16 16:42:07 +03:00
|
|
|
goto out_fail;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
productInfo->pbProductId = (BYTE*)malloc(productInfo->cbProductId);
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!productInfo->pbProductId)
|
|
|
|
goto out_fail;
|
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;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_write_product_info(wStream* s, const LICENSE_PRODUCT_INFO* productInfo)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(productInfo);
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, 8, "license product info::cbCompanyName"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */
|
|
|
|
|
|
|
|
/* Name must be >0, but there is no upper limit defined, use UINT32_MAX */
|
|
|
|
if ((productInfo->cbCompanyName < 2) || (productInfo->cbCompanyName % 2 != 0) ||
|
|
|
|
!productInfo->pbCompanyName)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "license product info invalid cbCompanyName %" PRIu32,
|
|
|
|
productInfo->cbCompanyName);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, productInfo->cbCompanyName,
|
|
|
|
"license product info::CompanyName"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, 4, "license product info::cbProductId"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
|
|
|
|
|
|
|
|
if ((productInfo->cbProductId < 2) || (productInfo->cbProductId % 2 != 0) ||
|
|
|
|
!productInfo->pbProductId)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "license product info invalid cbProductId %" PRIu32,
|
|
|
|
productInfo->cbProductId);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, productInfo->cbProductId,
|
|
|
|
"license product info::ProductId"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write(s, productInfo->pbProductId, productInfo->cbProductId);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Allocate New Product Information (LICENSE_PRODUCT_INFO).
|
|
|
|
* msdn{cc241915}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @return new product information
|
|
|
|
*/
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
LICENSE_PRODUCT_INFO* license_new_product_info(void)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
LICENSE_PRODUCT_INFO* productInfo =
|
|
|
|
(LICENSE_PRODUCT_INFO*)calloc(1, sizeof(LICENSE_PRODUCT_INFO));
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!productInfo)
|
|
|
|
return NULL;
|
2011-07-12 09:16:59 +04:00
|
|
|
return productInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Free Product Information (LICENSE_PRODUCT_INFO).
|
|
|
|
* msdn{cc241915}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @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
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_read_binary_blob_data(LICENSE_BLOB* blob, UINT32 wBlobType, const void* data,
|
|
|
|
size_t length)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(blob);
|
|
|
|
WINPR_ASSERT(length <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(data || (length == 0));
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
blob->length = (UINT16)length;
|
|
|
|
free(blob->data);
|
|
|
|
blob->data = NULL;
|
2011-09-17 00:37:20 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if ((blob->type != wBlobType) && (blob->type != BB_ANY_BLOB))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "license binary blob::type expected %s, got %s",
|
|
|
|
licencse_blob_type_string(wBlobType), licencse_blob_type_string(blob->type));
|
|
|
|
}
|
2013-01-12 17:49:01 +04:00
|
|
|
|
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))
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WLog_WARN(TAG, "license binary blob::type %s, length=0, skipping.",
|
|
|
|
licencse_blob_type_string(blob->type));
|
|
|
|
return TRUE;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
blob->type = wBlobType;
|
2019-11-06 17:24:51 +03:00
|
|
|
blob->data = (BYTE*)malloc(blob->length);
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!blob->data)
|
|
|
|
return FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
memcpy(blob->data, 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
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read License Binary Blob (LICENSE_BINARY_BLOB).
|
|
|
|
* msdn{cc240481}
|
2022-10-06 12:32:08 +03:00
|
|
|
* @param s stream
|
|
|
|
* @param blob license binary blob
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob)
|
|
|
|
{
|
|
|
|
UINT16 wBlobType;
|
|
|
|
UINT16 length;
|
|
|
|
|
|
|
|
WINPR_ASSERT(blob);
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, 4, "license binary blob::type"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, wBlobType); /* wBlobType (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, length); /* wBlobLen (2 bytes) */
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, length, "license binary blob::length"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!license_read_binary_blob_data(blob, wBlobType, Stream_Pointer(s), length))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return Stream_SafeSeek(s, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Write License Binary Blob (LICENSE_BINARY_BLOB).
|
|
|
|
* msdn{cc240481}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param blob license binary blob
|
|
|
|
*/
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
BOOL license_write_binary_blob(wStream* s, const LICENSE_BLOB* blob)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(blob);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blob->length + 4))
|
2015-04-01 12:38:53 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
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 */
|
2015-04-01 12:38:53 +03:00
|
|
|
return TRUE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL license_write_encrypted_premaster_secret_blob(wStream* s, const LICENSE_BLOB* blob,
|
|
|
|
UINT32 ModulusLength)
|
2011-07-15 09:11:09 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
const UINT32 length = ModulusLength + 8;
|
|
|
|
|
|
|
|
WINPR_ASSERT(blob);
|
2013-02-05 18:30:53 +04:00
|
|
|
|
|
|
|
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;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_read_encrypted_premaster_secret_blob(wStream* s, LICENSE_BLOB* blob,
|
|
|
|
UINT32* ModulusLength)
|
|
|
|
{
|
|
|
|
if (!license_read_binary_blob(s, blob))
|
|
|
|
return FALSE;
|
2023-01-28 15:22:38 +03:00
|
|
|
WINPR_ASSERT(ModulusLength);
|
|
|
|
*ModulusLength = blob->length;
|
2022-10-06 12:32:08 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Allocate New License Binary Blob (LICENSE_BINARY_BLOB).
|
|
|
|
* msdn{cc240481}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @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
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
LICENSE_BLOB* blob = (LICENSE_BLOB*)calloc(1, sizeof(LICENSE_BLOB));
|
2015-06-16 16:42:07 +03:00
|
|
|
if (blob)
|
|
|
|
blob->type = type;
|
2011-07-12 09:16:59 +04:00
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Free License Binary Blob (LICENSE_BINARY_BLOB).
|
|
|
|
* msdn{cc240481}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read License Scope List (SCOPE_LIST).
|
|
|
|
* msdn{cc241916}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @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
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(scopeList);
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, 4, "license scope list"))
|
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
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_check_stream_length(s, scopeCount * 4ull, "license scope list::count"))
|
2014-01-08 19:12:51 +04:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_scope_list_resize(scopeList, scopeCount))
|
2015-06-16 16:42:07 +03:00
|
|
|
return FALSE;
|
2011-07-12 04:46:03 +04:00
|
|
|
/* ScopeArray */
|
|
|
|
for (i = 0; i < scopeCount; i++)
|
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_read_binary_blob(s, scopeList->array[i]))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_write_scope_list(wStream* s, const SCOPE_LIST* scopeList)
|
|
|
|
{
|
|
|
|
UINT32 i;
|
|
|
|
|
|
|
|
WINPR_ASSERT(scopeList);
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, 4, "license scope list"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, scopeList->count); /* ScopeCount (4 bytes) */
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, scopeList->count * 4ull, "license scope list::count"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* ScopeArray */
|
|
|
|
WINPR_ASSERT(scopeList->array || (scopeList->count == 0));
|
|
|
|
for (i = 0; i < scopeList->count; i++)
|
|
|
|
{
|
|
|
|
const LICENSE_BLOB* element = scopeList->array[i];
|
2013-02-05 08:57:04 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_write_binary_blob(s, element))
|
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
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Allocate New License Scope List (SCOPE_LIST).
|
|
|
|
* msdn{cc241916}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @return new scope list
|
|
|
|
*/
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
SCOPE_LIST* license_new_scope_list(void)
|
|
|
|
{
|
|
|
|
SCOPE_LIST* list = calloc(1, sizeof(SCOPE_LIST));
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_scope_list_resize(SCOPE_LIST* scopeList, UINT32 count)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
UINT32 x;
|
|
|
|
|
|
|
|
WINPR_ASSERT(scopeList);
|
|
|
|
WINPR_ASSERT(scopeList->array || (scopeList->count == 0));
|
|
|
|
|
|
|
|
for (x = count; x < scopeList->count; x++)
|
|
|
|
{
|
|
|
|
license_free_binary_blob(scopeList->array[x]);
|
|
|
|
scopeList->array[x] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
LICENSE_BLOB** tmp = realloc(scopeList->array, count * sizeof(LICENSE_BLOB*));
|
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
scopeList->array = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(scopeList->array);
|
|
|
|
scopeList->array = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = scopeList->count; x < count; x++)
|
|
|
|
{
|
|
|
|
LICENSE_BLOB* blob = license_new_binary_blob(BB_SCOPE_BLOB);
|
|
|
|
if (!blob)
|
|
|
|
{
|
|
|
|
scopeList->count = x;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
scopeList->array[x] = blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
scopeList->count = count;
|
|
|
|
return TRUE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Free License Scope List (SCOPE_LIST).
|
|
|
|
* msdn{cc241916}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param scopeList scope list
|
|
|
|
*/
|
|
|
|
|
|
|
|
void license_free_scope_list(SCOPE_LIST* scopeList)
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!scopeList)
|
|
|
|
return;
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
license_scope_list_resize(scopeList, 0);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(scopeList);
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2023-01-28 15:16:39 +03:00
|
|
|
BOOL license_send_license_info(rdpLicense* license, const LICENSE_BLOB* calBlob,
|
|
|
|
const BYTE* signature, size_t signature_length)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
wStream* s = license_send_stream_init(license);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(calBlob);
|
|
|
|
WINPR_ASSERT(signature);
|
2023-01-28 14:16:16 +03:00
|
|
|
WINPR_ASSERT(license->certificate);
|
|
|
|
|
2023-02-03 13:51:14 +03:00
|
|
|
const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-01-28 14:57:17 +03:00
|
|
|
if (!license_check_stream_capacity(s, 8 + sizeof(license->ClientRandom),
|
|
|
|
"license info::ClientRandom"))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
license->PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
/* ClientRandom (32 bytes) */
|
2023-01-28 14:57:17 +03:00
|
|
|
Stream_Write(s, license->ClientRandom, sizeof(license->ClientRandom));
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
/* Licensing Binary Blob with EncryptedPreMasterSecret: */
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!license_write_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
|
2023-01-28 14:16:16 +03:00
|
|
|
info->ModulusLength))
|
2018-10-31 12:27:31 +03:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Licensing Binary Blob with LicenseInfo: */
|
|
|
|
if (!license_write_binary_blob(s, calBlob))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Licensing Binary Blob with EncryptedHWID */
|
|
|
|
if (!license_write_binary_blob(s, license->EncryptedHardwareId))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* MACData */
|
2023-01-28 15:16:39 +03:00
|
|
|
if (!license_check_stream_capacity(s, signature_length, "license info::MACData"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto error;
|
2023-01-28 15:16:39 +03:00
|
|
|
Stream_Write(s, signature, signature_length);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
return license_send(license, s, LICENSE_INFO);
|
|
|
|
|
|
|
|
error:
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
static BOOL license_check_preferred_alg(rdpLicense* license, UINT32 PreferredKeyExchangeAlg,
|
|
|
|
const char* where)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(where);
|
|
|
|
|
|
|
|
if (license->PreferredKeyExchangeAlg != PreferredKeyExchangeAlg)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "%s::PreferredKeyExchangeAlg, expected %s, got %s", where,
|
|
|
|
license_preferred_key_exchange_alg_string(license->PreferredKeyExchangeAlg),
|
|
|
|
license_preferred_key_exchange_alg_string(PreferredKeyExchangeAlg));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_read_license_info(rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
UINT32 PreferredKeyExchangeAlg;
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
2023-01-28 14:16:16 +03:00
|
|
|
WINPR_ASSERT(license->certificate);
|
|
|
|
|
2023-02-03 13:51:14 +03:00
|
|
|
const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
|
|
|
|
if (!info)
|
|
|
|
goto error;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
/* ClientRandom (32 bytes) */
|
2023-01-28 14:57:17 +03:00
|
|
|
if (!license_check_stream_length(s, 8 + sizeof(license->ClientRandom), "license info"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
|
|
|
|
if (!license_check_preferred_alg(license, PreferredKeyExchangeAlg, "license info"))
|
|
|
|
goto error;
|
|
|
|
Stream_Read_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
|
|
|
|
|
|
|
|
/* ClientRandom (32 bytes) */
|
2023-01-28 14:57:17 +03:00
|
|
|
Stream_Read(s, license->ClientRandom, sizeof(license->ClientRandom));
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
/* Licensing Binary Blob with EncryptedPreMasterSecret: */
|
2023-02-03 13:51:14 +03:00
|
|
|
UINT32 ModulusLength = 0;
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_read_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
|
2023-02-03 13:51:14 +03:00
|
|
|
&ModulusLength))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto error;
|
|
|
|
|
2023-02-03 13:51:14 +03:00
|
|
|
if (ModulusLength != info->ModulusLength)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"EncryptedPremasterSecret,::ModulusLength[%" PRIu32
|
|
|
|
"] != rdpCertInfo::ModulusLength[%" PRIu32 "]",
|
|
|
|
ModulusLength, info->ModulusLength);
|
|
|
|
goto error;
|
|
|
|
}
|
2022-10-06 12:32:08 +03:00
|
|
|
/* Licensing Binary Blob with LicenseInfo: */
|
|
|
|
if (!license_read_binary_blob(s, license->LicenseInfo))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Licensing Binary Blob with EncryptedHWID */
|
|
|
|
if (!license_read_binary_blob(s, license->EncryptedHardwareId))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* MACData */
|
2023-01-28 15:16:39 +03:00
|
|
|
if (!license_check_stream_length(s, sizeof(license->MACData), "license info::MACData"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto error;
|
2023-01-28 15:16:39 +03:00
|
|
|
Stream_Read(s, license->MACData, sizeof(license->MACData));
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
rc = TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read a LICENSE_REQUEST packet.
|
|
|
|
* 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
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/* ServerRandom (32 bytes) */
|
2023-01-28 15:00:41 +03:00
|
|
|
if (!license_check_stream_length(s, sizeof(license->ServerRandom), "license request"))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-01-25 22:47:56 +04:00
|
|
|
|
2023-01-28 15:00:41 +03:00
|
|
|
Stream_Read(s, license->ServerRandom, sizeof(license->ServerRandom));
|
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 */
|
2023-02-03 13:51:14 +03:00
|
|
|
if (!freerdp_certificate_read_server_cert(license->certificate,
|
|
|
|
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) ||
|
2019-11-06 17:24:51 +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:");
|
2023-01-28 15:00:41 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ServerRandom, sizeof(license->ServerRandom));
|
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
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_write_license_request_packet(const rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
/* ServerRandom (32 bytes) */
|
2023-01-28 15:00:41 +03:00
|
|
|
if (!license_check_stream_capacity(s, sizeof(license->ServerRandom), "license request"))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
2023-01-28 15:00:41 +03:00
|
|
|
Stream_Write(s, license->ServerRandom, sizeof(license->ServerRandom));
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
/* ProductInfo */
|
|
|
|
if (!license_write_product_info(s, license->ProductInfo))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* KeyExchangeList */
|
|
|
|
if (!license_write_binary_blob(s, license->KeyExchangeList))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* ServerCertificate */
|
|
|
|
if (!license_write_binary_blob(s, license->ServerCertificate))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* ScopeList */
|
|
|
|
if (!license_write_scope_list(s, license->ScopeList))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL license_send_license_request_packet(rdpLicense* license)
|
|
|
|
{
|
|
|
|
wStream* s = license_send_stream_init(license);
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!license_write_license_request_packet(license, s))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return license_send(license, s, LICENSE_REQUEST);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
/*
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read a PLATFORM_CHALLENGE packet.
|
|
|
|
* 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
|
|
|
{
|
2023-01-28 15:16:39 +03:00
|
|
|
BYTE macData[LICENSING_ENCRYPTION_KEY_LENGTH] = { 0 };
|
2013-02-05 09:19:57 +04:00
|
|
|
UINT32 ConnectFlags = 0;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Receiving Platform Challenge Packet");
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!license_check_stream_length(s, 4, "license platform challenge"))
|
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) */
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2011-07-12 09:57:09 +04:00
|
|
|
/* EncryptedPlatformChallenge */
|
2013-02-05 08:57:04 +04:00
|
|
|
license->EncryptedPlatformChallenge->type = BB_ANY_BLOB;
|
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
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
/* MACData (16 bytes) */
|
2023-01-28 15:16:39 +03:00
|
|
|
if (!license_check_stream_length(s, sizeof(macData), "license platform challenge::MAC"))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-07-13 18:21:12 +04:00
|
|
|
|
2023-01-28 15:16:39 +03:00
|
|
|
Stream_Read(s, macData, sizeof(macData));
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!license_decrypt_and_check_MAC(license, license->EncryptedPlatformChallenge->data,
|
2019-11-06 17:24:51 +03:00
|
|
|
license->EncryptedPlatformChallenge->length,
|
|
|
|
license->PlatformChallenge, macData))
|
2015-04-07 22:06:53 +03:00
|
|
|
return FALSE;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2019-11-06 17:24:51 +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,
|
2019-11-06 17:24:51 +03:00
|
|
|
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,
|
2019-11-06 17:24:51 +03:00
|
|
|
license->PlatformChallenge->length);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "MacData:");
|
2023-01-28 15:16:39 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, macData, sizeof(macData));
|
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
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_send_error_alert(rdpLicense* license, UINT32 dwErrorCode, UINT32 dwStateTransition,
|
|
|
|
const LICENSE_BLOB* info)
|
|
|
|
{
|
|
|
|
wStream* s = license_send_stream_init(license);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, 8, "license error alert"))
|
|
|
|
goto fail;
|
|
|
|
Stream_Write_UINT32(s, dwErrorCode);
|
|
|
|
Stream_Write_UINT32(s, dwStateTransition);
|
|
|
|
|
2023-04-24 13:11:50 +03:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
if (!license_write_binary_blob(s, info))
|
|
|
|
goto fail;
|
|
|
|
}
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
return license_send(license, s, ERROR_ALERT);
|
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_send_platform_challenge_packet(rdpLicense* license)
|
|
|
|
{
|
|
|
|
wStream* s = license_send_stream_init(license);
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
DEBUG_LICENSE("Receiving Platform Challenge Packet");
|
|
|
|
|
|
|
|
if (!license_check_stream_capacity(s, 4, "license platform challenge"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
Stream_Zero(s, 4); /* ConnectFlags, Reserved (4 bytes) */
|
|
|
|
|
|
|
|
/* EncryptedPlatformChallenge */
|
|
|
|
if (!license_write_binary_blob(s, license->EncryptedPlatformChallenge))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* MACData (16 bytes) */
|
2023-01-28 15:16:39 +03:00
|
|
|
if (!license_check_stream_length(s, sizeof(license->MACData),
|
2022-10-06 12:32:08 +03:00
|
|
|
"license platform challenge::MAC"))
|
|
|
|
goto fail;
|
|
|
|
|
2023-01-28 15:16:39 +03:00
|
|
|
Stream_Write(s, license->MACData, sizeof(license->MACData));
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
return license_send(license, s, PLATFORM_CHALLENGE);
|
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL license_read_encrypted_blob(const rdpLicense* license, wStream* s, LICENSE_BLOB* target)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2018-10-31 12:27:31 +03:00
|
|
|
UINT16 wBlobType, wBlobLen;
|
2019-11-06 17:24:51 +03:00
|
|
|
BYTE* encryptedData;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(target);
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, 4, "license encrypted blob"))
|
2018-10-31 12:27:31 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, wBlobType);
|
|
|
|
if (wBlobType != BB_ENCRYPTED_DATA_BLOB)
|
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WLog_WARN(
|
2019-11-06 17:24:51 +03:00
|
|
|
TAG,
|
|
|
|
"expecting BB_ENCRYPTED_DATA_BLOB blob, probably a windows 2003 server, continuing...");
|
2018-10-31 12:27:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, wBlobLen);
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
encryptedData = Stream_Pointer(s);
|
|
|
|
if (!Stream_SafeSeek(s, wBlobLen))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"short license encrypted blob::length, expected %" PRIu16 " bytes, got %" PRIuz,
|
|
|
|
wBlobLen, Stream_GetRemainingLength(s));
|
2018-10-31 12:27:31 +03:00
|
|
|
return FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
}
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
return license_rc4_with_licenseKey(license, encryptedData, wBlobLen, target);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read a NEW_LICENSE packet.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
BOOL license_read_new_or_upgrade_license_packet(rdpLicense* license, wStream* s)
|
2011-07-12 04:46:03 +04:00
|
|
|
{
|
2018-10-31 12:27:31 +03:00
|
|
|
UINT32 os_major;
|
|
|
|
UINT32 os_minor;
|
|
|
|
UINT32 cbScope, cbCompanyName, cbProductId, cbLicenseInfo;
|
2022-10-06 12:32:08 +03:00
|
|
|
wStream sbuffer;
|
2019-11-06 17:24:51 +03:00
|
|
|
wStream* licenseStream = NULL;
|
2018-10-31 12:27:31 +03:00
|
|
|
BOOL ret = FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
BYTE computedMac[16] = { 0 };
|
2019-11-06 17:24:51 +03:00
|
|
|
LICENSE_BLOB* calBlob;
|
2022-10-06 12:32:08 +03:00
|
|
|
const BYTE* readMac;
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
DEBUG_LICENSE("Receiving Server New/Upgrade License Packet");
|
|
|
|
|
|
|
|
calBlob = license_new_binary_blob(BB_DATA_BLOB);
|
|
|
|
if (!calBlob)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* EncryptedLicenseInfo */
|
|
|
|
if (!license_read_encrypted_blob(license, s, calBlob))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
/* compute MAC and check it */
|
2022-10-06 12:32:08 +03:00
|
|
|
readMac = Stream_Pointer(s);
|
2023-01-28 15:16:39 +03:00
|
|
|
if (!Stream_SafeSeek(s, sizeof(computedMac)))
|
2022-10-06 12:32:08 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "short license new/upgrade, expected 16 bytes, got %" PRIuz,
|
|
|
|
Stream_GetRemainingLength(s));
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2023-01-28 15:16:39 +03:00
|
|
|
if (!security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), calBlob->data,
|
|
|
|
calBlob->length, computedMac, sizeof(computedMac)))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
if (memcmp(computedMac, readMac, sizeof(computedMac)) != 0)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "new or upgrade license MAC mismatch");
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
2018-10-31 12:27:31 +03:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
licenseStream = Stream_StaticConstInit(&sbuffer, calBlob->data, calBlob->length);
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!licenseStream)
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, 8, "license new/upgrade::blob::version"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
2020-05-25 10:37:48 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Read_UINT16(licenseStream, os_minor);
|
|
|
|
Stream_Read_UINT16(licenseStream, os_major);
|
|
|
|
|
2023-06-26 12:08:21 +03:00
|
|
|
WLog_DBG(TAG, "Version: %" PRIu16 ".%" PRIu16, os_major, os_minor);
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
/* Scope */
|
|
|
|
Stream_Read_UINT32(licenseStream, cbScope);
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, cbScope, "license new/upgrade::blob::scope"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
|
|
|
WLog_DBG(TAG, "Scope:");
|
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Pointer(licenseStream), cbScope);
|
|
|
|
#endif
|
|
|
|
Stream_Seek(licenseStream, cbScope);
|
|
|
|
|
|
|
|
/* CompanyName */
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, 4, "license new/upgrade::blob::cbCompanyName"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Read_UINT32(licenseStream, cbCompanyName);
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, cbCompanyName,
|
|
|
|
"license new/upgrade::blob::CompanyName"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
|
|
|
WLog_DBG(TAG, "Company name:");
|
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Pointer(licenseStream), cbCompanyName);
|
|
|
|
#endif
|
|
|
|
Stream_Seek(licenseStream, cbCompanyName);
|
|
|
|
|
|
|
|
/* productId */
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, 4, "license new/upgrade::blob::cbProductId"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Read_UINT32(licenseStream, cbProductId);
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, cbProductId,
|
|
|
|
"license new/upgrade::blob::ProductId"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
|
|
|
WLog_DBG(TAG, "Product id:");
|
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Pointer(licenseStream), cbProductId);
|
|
|
|
#endif
|
|
|
|
Stream_Seek(licenseStream, cbProductId);
|
|
|
|
|
|
|
|
/* licenseInfo */
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, 4, "license new/upgrade::blob::cbLicenseInfo"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Read_UINT32(licenseStream, cbLicenseInfo);
|
2023-04-19 11:06:02 +03:00
|
|
|
if (!license_check_stream_length(licenseStream, cbLicenseInfo,
|
|
|
|
"license new/upgrade::blob::LicenseInfo"))
|
2022-10-06 12:32:08 +03:00
|
|
|
goto fail;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
license->type = LICENSE_TYPE_ISSUED;
|
|
|
|
ret = license_set_state(license, LICENSE_STATE_COMPLETED);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2019-04-08 10:42:02 +03:00
|
|
|
if (!license->rdp->settings->OldLicenseBehaviour)
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = saveCal(license->rdp->settings, Stream_Pointer(licenseStream), cbLicenseInfo,
|
|
|
|
license->rdp->settings->ClientHostname);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
fail:
|
2018-10-31 12:27:31 +03:00
|
|
|
license_free_binary_blob(calBlob);
|
|
|
|
return ret;
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read an ERROR_ALERT packet.
|
|
|
|
* 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
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, 8ul, "error alert"))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-02-05 01:39:05 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, dwErrorCode); /* dwErrorCode (4 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
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
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(TAG, "dwErrorCode: %s, dwStateTransition: %s", 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)
|
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
license->type = LICENSE_TYPE_NONE;
|
|
|
|
return license_set_state(license, LICENSE_STATE_COMPLETED);
|
2011-07-15 10:02:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (dwStateTransition)
|
|
|
|
{
|
|
|
|
case ST_TOTAL_ABORT:
|
2022-10-06 12:32:08 +03:00
|
|
|
license_set_state(license, LICENSE_STATE_ABORTED);
|
2011-07-15 10:02:09 +04:00
|
|
|
break;
|
|
|
|
case ST_NO_TRANSITION:
|
2022-10-06 12:32:08 +03:00
|
|
|
license_set_state(license, LICENSE_STATE_COMPLETED);
|
2011-07-15 10:02:09 +04:00
|
|
|
break;
|
|
|
|
case ST_RESET_PHASE_TO_START:
|
2022-10-06 12:32:08 +03:00
|
|
|
license_set_state(license, LICENSE_STATE_CONFIGURED);
|
2011-07-15 10:02:09 +04:00
|
|
|
break;
|
|
|
|
case ST_RESEND_LAST_MESSAGE:
|
|
|
|
break;
|
|
|
|
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
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Write a NEW_LICENSE_REQUEST packet.
|
|
|
|
* msdn{cc241918}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_write_new_license_request_packet(const rdpLicense* license, wStream* s)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
2023-02-03 13:51:14 +03:00
|
|
|
|
|
|
|
const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
|
|
|
|
if (!info)
|
|
|
|
return FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2023-01-28 14:57:17 +03:00
|
|
|
if (!license_check_stream_capacity(s, 8 + sizeof(license->ClientRandom), "License Request"))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
Stream_Write_UINT32(s,
|
|
|
|
license->PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
|
2023-01-28 14:57:17 +03:00
|
|
|
Stream_Write(s, license->ClientRandom,
|
|
|
|
sizeof(license->ClientRandom)); /* ClientRandom (32 bytes) */
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
if (/* EncryptedPremasterSecret */
|
2023-02-03 13:51:14 +03:00
|
|
|
!license_write_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
|
|
|
|
info->ModulusLength) ||
|
2019-11-06 17:24:51 +03:00
|
|
|
/* ClientUserName */
|
|
|
|
!license_write_binary_blob(s, license->ClientUserName) ||
|
|
|
|
/* ClientMachineName */
|
|
|
|
!license_write_binary_blob(s, license->ClientMachineName))
|
2015-04-01 12:38:53 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-05 10:07:34 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2022-10-06 12:32:08 +03:00
|
|
|
WLog_DBG(TAG, "PreferredKeyExchangeAlg: 0x%08" PRIX32 "", license->PreferredKeyExchangeAlg);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "ClientRandom:");
|
2023-01-28 14:57:17 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->ClientRandom, sizeof(license->ClientRandom));
|
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,
|
2019-11-06 17:24:51 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_read_new_license_request_packet(rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
UINT32 PreferredKeyExchangeAlg;
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
2023-02-03 13:51:14 +03:00
|
|
|
|
2023-01-28 14:57:17 +03:00
|
|
|
if (!license_check_stream_length(s, 8ull + sizeof(license->ClientRandom),
|
|
|
|
"new license request"))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
|
|
|
|
if (!license_check_preferred_alg(license, PreferredKeyExchangeAlg, "new license request"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
|
2023-01-28 14:57:17 +03:00
|
|
|
Stream_Read(s, license->ClientRandom,
|
|
|
|
sizeof(license->ClientRandom)); /* ClientRandom (32 bytes) */
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
/* EncryptedPremasterSecret */
|
2023-02-03 13:51:14 +03:00
|
|
|
UINT32 ModulusLength = 0;
|
|
|
|
if (!license_read_encrypted_premaster_secret_blob(s, license->EncryptedPremasterSecret,
|
|
|
|
&ModulusLength))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-04-24 13:11:50 +03:00
|
|
|
const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
|
|
|
|
if (!info)
|
|
|
|
WLog_WARN(TAG, "Missing license certificate, skipping ModulusLength checks");
|
|
|
|
else if (ModulusLength != info->ModulusLength)
|
2023-02-03 13:51:14 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"EncryptedPremasterSecret expected to be %" PRIu32 " bytes, but read %" PRIu32
|
|
|
|
" bytes",
|
|
|
|
info->ModulusLength, ModulusLength);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
/* ClientUserName */
|
|
|
|
if (!license_read_binary_blob(s, license->ClientUserName))
|
|
|
|
return FALSE;
|
|
|
|
/* ClientMachineName */
|
|
|
|
if (!license_read_binary_blob(s, license->ClientMachineName))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Send a NEW_LICENSE_REQUEST packet.
|
|
|
|
* msdn{cc241918}
|
2011-07-12 09:16:59 +04:00
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
BOOL license_answer_license_request(rdpLicense* license)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2018-10-31 12:27:31 +03:00
|
|
|
wStream* s;
|
2019-11-06 17:24:51 +03:00
|
|
|
BYTE* license_data = NULL;
|
2021-02-07 21:58:32 +03:00
|
|
|
size_t license_size = 0;
|
2018-10-31 12:27:31 +03:00
|
|
|
BOOL status;
|
2011-10-05 03:06:39 +04:00
|
|
|
char* username;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
WINPR_ASSERT(license->rdp->settings);
|
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
if (!license->rdp->settings->OldLicenseBehaviour)
|
2019-11-06 17:24:51 +03:00
|
|
|
license_data = loadCalFile(license->rdp->settings, license->rdp->settings->ClientHostname,
|
|
|
|
&license_size);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (license_data)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
LICENSE_BLOB* calBlob = NULL;
|
2022-10-06 12:32:08 +03:00
|
|
|
BYTE signature[LICENSING_ENCRYPTION_KEY_LENGTH] = { 0 };
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
DEBUG_LICENSE("Sending Saved License Packet");
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license->EncryptedHardwareId);
|
2018-10-31 12:27:31 +03:00
|
|
|
license->EncryptedHardwareId->type = BB_ENCRYPTED_DATA_BLOB;
|
2023-01-28 15:18:59 +03:00
|
|
|
if (!license_encrypt_and_MAC(license, license->HardwareId, sizeof(license->HardwareId),
|
2023-01-28 15:16:39 +03:00
|
|
|
license->EncryptedHardwareId, signature, sizeof(signature)))
|
2018-11-29 14:14:20 +03:00
|
|
|
{
|
|
|
|
free(license_data);
|
2018-10-31 12:27:31 +03:00
|
|
|
return FALSE;
|
2018-11-29 14:14:20 +03:00
|
|
|
}
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
calBlob = license_new_binary_blob(BB_DATA_BLOB);
|
|
|
|
if (!calBlob)
|
2018-11-29 14:14:20 +03:00
|
|
|
{
|
|
|
|
free(license_data);
|
2018-10-31 12:27:31 +03:00
|
|
|
return FALSE;
|
2018-11-29 14:14:20 +03:00
|
|
|
}
|
2018-10-31 12:27:31 +03:00
|
|
|
calBlob->data = license_data;
|
|
|
|
calBlob->length = license_size;
|
|
|
|
|
2023-01-28 15:16:39 +03:00
|
|
|
status = license_send_license_info(license, calBlob, signature, sizeof(signature));
|
2018-10-31 12:27:31 +03:00
|
|
|
license_free_binary_blob(calBlob);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-02-05 10:07:34 +04:00
|
|
|
DEBUG_LICENSE("Sending New License Packet");
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
s = license_send_stream_init(license);
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
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";
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license->ClientUserName);
|
2019-11-06 17:24:51 +03:00
|
|
|
license->ClientUserName->data = (BYTE*)username;
|
2013-02-05 08:57:04 +04:00
|
|
|
license->ClientUserName->length = strlen(username) + 1;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(license->ClientMachineName);
|
2019-11-06 17:24:51 +03:00
|
|
|
license->ClientMachineName->data = (BYTE*)license->rdp->settings->ClientHostname;
|
2013-02-05 08:57:04 +04:00
|
|
|
license->ClientMachineName->length = strlen(license->rdp->settings->ClientHostname) + 1;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
status = license_write_new_license_request_packet(license, s);
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license->ClientUserName);
|
2013-02-05 08:57:04 +04:00
|
|
|
license->ClientUserName->data = NULL;
|
|
|
|
license->ClientUserName->length = 0;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(license->ClientMachineName);
|
2013-02-05 08:57:04 +04:00
|
|
|
license->ClientMachineName->data = NULL;
|
|
|
|
license->ClientMachineName->length = 0;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return license_send(license, s, NEW_LICENSE_REQUEST);
|
2011-07-12 09:57:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Send Client Challenge Response Packet.
|
|
|
|
* msdn{cc241922}
|
2011-07-12 09:57:09 +04:00
|
|
|
* @param license license module
|
|
|
|
*/
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_send_platform_challenge_response(rdpLicense* license)
|
2011-07-12 09:57:09 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
wStream* s = license_send_stream_init(license);
|
2019-11-06 17:24:51 +03:00
|
|
|
wStream* challengeRespData;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* buffer;
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL status;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->PlatformChallenge);
|
|
|
|
WINPR_ASSERT(license->MacSaltKey);
|
|
|
|
WINPR_ASSERT(license->EncryptedPlatformChallenge);
|
|
|
|
WINPR_ASSERT(license->EncryptedHardwareId);
|
|
|
|
|
2011-07-12 09:57:09 +04:00
|
|
|
DEBUG_LICENSE("Sending Platform Challenge Response Packet");
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2013-02-05 08:57:04 +04:00
|
|
|
license->EncryptedPlatformChallenge->type = BB_DATA_BLOB;
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
/* prepare the PLATFORM_CHALLENGE_RESPONSE_DATA */
|
|
|
|
challengeRespData = Stream_New(NULL, 8 + license->PlatformChallenge->length);
|
|
|
|
if (!challengeRespData)
|
2016-02-28 13:12:17 +03:00
|
|
|
return FALSE;
|
2022-10-06 12:32:08 +03:00
|
|
|
Stream_Write_UINT16(challengeRespData, PLATFORM_CHALLENGE_RESPONSE_VERSION); /* wVersion */
|
|
|
|
Stream_Write_UINT16(challengeRespData, license->ClientType); /* wClientType */
|
|
|
|
Stream_Write_UINT16(challengeRespData, license->LicenseDetailLevel); /* wLicenseDetailLevel */
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Write_UINT16(challengeRespData, license->PlatformChallenge->length); /* cbChallenge */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write(challengeRespData, license->PlatformChallenge->data,
|
|
|
|
license->PlatformChallenge->length); /* pbChallenge */
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_SealLength(challengeRespData);
|
|
|
|
|
|
|
|
/* compute MAC of PLATFORM_CHALLENGE_RESPONSE_DATA + HWID */
|
2023-03-06 16:18:52 +03:00
|
|
|
const size_t length = Stream_Length(challengeRespData) + sizeof(license->HardwareId);
|
2019-11-06 17:24:51 +03:00
|
|
|
buffer = (BYTE*)malloc(length);
|
2015-04-07 22:06:53 +03:00
|
|
|
if (!buffer)
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
|
|
|
Stream_Free(challengeRespData, TRUE);
|
2015-04-07 22:06:53 +03:00
|
|
|
return FALSE;
|
2018-10-31 12:27:31 +03:00
|
|
|
}
|
2015-04-07 22:06:53 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
CopyMemory(buffer, Stream_Buffer(challengeRespData), Stream_Length(challengeRespData));
|
2023-01-28 15:18:59 +03:00
|
|
|
CopyMemory(&buffer[Stream_Length(challengeRespData)], license->HardwareId,
|
|
|
|
sizeof(license->HardwareId));
|
2023-01-30 15:00:13 +03:00
|
|
|
status = security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), buffer, length,
|
|
|
|
license->MACData, sizeof(license->MACData));
|
2018-10-31 12:27:31 +03:00
|
|
|
free(buffer);
|
2018-10-02 14:18:13 +03:00
|
|
|
|
2016-02-28 13:12:17 +03:00
|
|
|
if (!status)
|
|
|
|
{
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Free(challengeRespData, TRUE);
|
2016-02-28 13:12:17 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-02-24 19:04:03 +03:00
|
|
|
|
2018-10-31 12:27:31 +03:00
|
|
|
license->EncryptedHardwareId->type = BB_ENCRYPTED_DATA_BLOB;
|
2023-01-28 15:18:59 +03:00
|
|
|
if (!license_rc4_with_licenseKey(license, license->HardwareId, sizeof(license->HardwareId),
|
2019-11-06 17:24:51 +03:00
|
|
|
license->EncryptedHardwareId))
|
2018-10-31 12:27:31 +03:00
|
|
|
{
|
|
|
|
Stream_Free(challengeRespData, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = license_rc4_with_licenseKey(license, Stream_Buffer(challengeRespData),
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Length(challengeRespData),
|
|
|
|
license->EncryptedPlatformChallengeResponse);
|
2018-10-31 12:27:31 +03:00
|
|
|
Stream_Free(challengeRespData, TRUE);
|
|
|
|
if (!status)
|
|
|
|
return FALSE;
|
|
|
|
|
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:");
|
2023-01-28 15:18:59 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->HardwareId, sizeof(license->HardwareId));
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "EncryptedHardwareId:");
|
2023-01-28 15:18:59 +03:00
|
|
|
winpr_HexDump(TAG, WLOG_DEBUG, license->EncryptedHardwareId->data,
|
|
|
|
license->EncryptedHardwareId->length);
|
2011-08-08 22:51:03 +04:00
|
|
|
#endif
|
2022-10-06 12:32:08 +03:00
|
|
|
if (license_write_client_platform_challenge_response(license, s))
|
2018-10-31 12:27:31 +03:00
|
|
|
return license_send(license, s, PLATFORM_CHALLENGE_RESPONSE);
|
|
|
|
|
|
|
|
Stream_Release(s);
|
|
|
|
return FALSE;
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
BOOL license_read_platform_challenge_response(rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
UINT16 wVersion;
|
|
|
|
UINT16 cbChallenge;
|
|
|
|
const BYTE* pbChallenge;
|
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->PlatformChallenge);
|
|
|
|
WINPR_ASSERT(license->MacSaltKey);
|
|
|
|
WINPR_ASSERT(license->EncryptedPlatformChallenge);
|
|
|
|
WINPR_ASSERT(license->EncryptedHardwareId);
|
|
|
|
|
|
|
|
DEBUG_LICENSE("Receiving Platform Challenge Response Packet");
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, 8, "PLATFORM_CHALLENGE_RESPONSE_DATA"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, wVersion);
|
|
|
|
if (wVersion != PLATFORM_CHALLENGE_RESPONSE_VERSION)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"Invalid PLATFORM_CHALLENGE_RESPONSE_DATA::wVersion 0x%04" PRIx16
|
|
|
|
", expected 0x04" PRIx16,
|
|
|
|
wVersion, PLATFORM_CHALLENGE_RESPONSE_VERSION);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
Stream_Read_UINT16(s, license->ClientType);
|
|
|
|
Stream_Read_UINT16(s, license->LicenseDetailLevel);
|
|
|
|
Stream_Read_UINT16(s, cbChallenge);
|
|
|
|
|
|
|
|
if (!license_check_stream_length(s, cbChallenge,
|
|
|
|
"PLATFORM_CHALLENGE_RESPONSE_DATA::pbChallenge"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pbChallenge = Stream_Pointer(s);
|
|
|
|
if (!license_read_binary_blob_data(license->EncryptedPlatformChallengeResponse, BB_DATA_BLOB,
|
|
|
|
pbChallenge, cbChallenge))
|
|
|
|
return FALSE;
|
|
|
|
return Stream_SafeSeek(s, cbChallenge);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_write_client_platform_challenge_response(rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
if (!license_write_binary_blob(s, license->EncryptedPlatformChallengeResponse))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_write_binary_blob(s, license->EncryptedHardwareId))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_check_stream_capacity(s, sizeof(license->MACData),
|
|
|
|
"CLIENT_PLATFORM_CHALLENGE_RESPONSE::MACData"))
|
|
|
|
return FALSE;
|
|
|
|
Stream_Write(s, license->MACData, sizeof(license->MACData));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_read_client_platform_challenge_response(rdpLicense* license, wStream* s)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
|
|
|
|
if (!license_read_binary_blob(s, license->EncryptedPlatformChallengeResponse))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_read_binary_blob(s, license->EncryptedHardwareId))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_check_stream_length(s, sizeof(license->MACData),
|
|
|
|
"CLIENT_PLATFORM_CHALLENGE_RESPONSE::MACData"))
|
|
|
|
return FALSE;
|
|
|
|
Stream_Read(s, license->MACData, sizeof(license->MACData));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-08-20 17:41:40 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Send Server License Error - Valid Client Packet.
|
|
|
|
* msdn{cc241922}
|
|
|
|
*
|
|
|
|
* @param rdp A pointer to the context to use
|
|
|
|
*
|
|
|
|
* @return \b TRUE for success, \b FALSE otherwise
|
2011-08-20 17:41:40 +04:00
|
|
|
*/
|
|
|
|
|
2018-11-01 13:02:54 +03:00
|
|
|
BOOL license_send_valid_client_error_packet(rdpRdp* rdp)
|
2011-08-20 17:41:40 +04:00
|
|
|
{
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpLicense* license = rdp->license;
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(license);
|
2015-04-01 12:38:53 +03:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
license->state = LICENSE_STATE_COMPLETED;
|
|
|
|
license->type = LICENSE_TYPE_NONE;
|
|
|
|
return license_send_error_alert(license, STATUS_VALID_CLIENT, ST_NO_TRANSITION,
|
|
|
|
license->ErrorInfo);
|
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;
|
2022-10-06 12:32:08 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
license = (rdpLicense*)calloc(1, sizeof(rdpLicense));
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!license)
|
|
|
|
return NULL;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2022-10-06 12:32:08 +03:00
|
|
|
license->PlatformId = PLATFORMID;
|
|
|
|
license->ClientType = OTHER_PLATFORM_CHALLENGE_TYPE;
|
|
|
|
license->LicenseDetailLevel = LICENSE_DETAIL_DETAIL;
|
|
|
|
license->PreferredKeyExchangeAlg = KEY_EXCHANGE_ALG_RSA;
|
2015-06-16 16:42:07 +03:00
|
|
|
license->rdp = rdp;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
license_set_state(license, LICENSE_STATE_INITIAL);
|
2023-02-03 13:51:14 +03:00
|
|
|
if (!(license->certificate = freerdp_certificate_new()))
|
2015-06-16 16:42:07 +03:00
|
|
|
goto out_error;
|
|
|
|
if (!(license->ProductInfo = license_new_product_info()))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->ErrorInfo = license_new_binary_blob(BB_ERROR_BLOB)))
|
|
|
|
goto out_error;
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!(license->LicenseInfo = license_new_binary_blob(BB_DATA_BLOB)))
|
|
|
|
goto out_error;
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->KeyExchangeList = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB)))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->ServerCertificate = license_new_binary_blob(BB_CERTIFICATE_BLOB)))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->ClientUserName = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB)))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->ClientMachineName = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB)))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->PlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->EncryptedPlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
|
|
|
|
goto out_error;
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(license->EncryptedPlatformChallengeResponse =
|
|
|
|
license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
|
2018-10-31 12:27:31 +03:00
|
|
|
goto out_error;
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->EncryptedPremasterSecret = license_new_binary_blob(BB_ANY_BLOB)))
|
|
|
|
goto out_error;
|
|
|
|
if (!(license->EncryptedHardwareId = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
|
|
|
|
goto out_error;
|
2022-10-06 12:32:08 +03:00
|
|
|
if (!(license->EncryptedLicenseInfo = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
|
|
|
|
goto out_error;
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!(license->ScopeList = license_new_scope_list()))
|
|
|
|
goto out_error;
|
|
|
|
|
|
|
|
license_generate_randoms(license);
|
2018-10-31 12:27:31 +03:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
return license;
|
2018-10-31 12:27:31 +03:00
|
|
|
|
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
|
|
|
{
|
2023-02-03 13:51:14 +03:00
|
|
|
freerdp_certificate_free(license->certificate);
|
2013-02-05 08:57:04 +04:00
|
|
|
license_free_product_info(license->ProductInfo);
|
|
|
|
license_free_binary_blob(license->ErrorInfo);
|
2022-10-06 12:32:08 +03:00
|
|
|
license_free_binary_blob(license->LicenseInfo);
|
2013-02-05 08:57:04 +04:00
|
|
|
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);
|
2018-10-31 12:27:31 +03:00
|
|
|
license_free_binary_blob(license->EncryptedPlatformChallengeResponse);
|
2013-02-05 08:57:04 +04:00
|
|
|
license_free_binary_blob(license->EncryptedPremasterSecret);
|
|
|
|
license_free_binary_blob(license->EncryptedHardwareId);
|
2022-10-06 12:32:08 +03:00
|
|
|
license_free_binary_blob(license->EncryptedLicenseInfo);
|
2013-02-05 08:57:04 +04:00
|
|
|
license_free_scope_list(license->ScopeList);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(license);
|
2011-07-12 04:46:03 +04:00
|
|
|
}
|
|
|
|
}
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
LICENSE_STATE license_get_state(const rdpLicense* license)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
return license->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
LICENSE_TYPE license_get_type(const rdpLicense* license)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
return license->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_set_state(rdpLicense* license, LICENSE_STATE state)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
license->state = state;
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case LICENSE_STATE_COMPLETED:
|
|
|
|
break;
|
|
|
|
case LICENSE_STATE_ABORTED:
|
|
|
|
default:
|
|
|
|
license->type = LICENSE_TYPE_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* license_get_state_string(LICENSE_STATE state)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case LICENSE_STATE_INITIAL:
|
|
|
|
return "LICENSE_STATE_INITIAL";
|
|
|
|
case LICENSE_STATE_CONFIGURED:
|
|
|
|
return "LICENSE_STATE_CONFIGURED";
|
|
|
|
case LICENSE_STATE_REQUEST:
|
|
|
|
return "LICENSE_STATE_REQUEST";
|
|
|
|
case LICENSE_STATE_NEW_REQUEST:
|
|
|
|
return "LICENSE_STATE_NEW_REQUEST";
|
|
|
|
case LICENSE_STATE_PLATFORM_CHALLENGE:
|
|
|
|
return "LICENSE_STATE_PLATFORM_CHALLENGE";
|
|
|
|
case LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE:
|
|
|
|
return "LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE";
|
|
|
|
case LICENSE_STATE_COMPLETED:
|
|
|
|
return "LICENSE_STATE_COMPLETED";
|
|
|
|
case LICENSE_STATE_ABORTED:
|
|
|
|
return "LICENSE_STATE_ABORTED";
|
|
|
|
default:
|
|
|
|
return "LICENSE_STATE_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_server_send_request(rdpLicense* license)
|
|
|
|
{
|
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_CONFIGURED, LICENSE_REQUEST))
|
|
|
|
return FALSE;
|
|
|
|
if (!license_send_license_request_packet(license))
|
|
|
|
return FALSE;
|
|
|
|
return license_set_state(license, LICENSE_STATE_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL license_server_configure(rdpLicense* license)
|
|
|
|
{
|
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
size_t len;
|
2022-10-06 12:32:08 +03:00
|
|
|
wStream* s;
|
|
|
|
UINT32 algs[] = { KEY_EXCHANGE_ALG_RSA };
|
|
|
|
UINT32 x;
|
|
|
|
const rdpSettings* settings;
|
|
|
|
UINT32 ProductVersion, issuerCount;
|
|
|
|
const char* CompanyName;
|
|
|
|
const char* ProductName;
|
2022-11-14 12:17:03 +03:00
|
|
|
const char* const* issuers;
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(license);
|
|
|
|
WINPR_ASSERT(license->rdp);
|
|
|
|
|
|
|
|
settings = license->rdp->settings;
|
|
|
|
|
|
|
|
CompanyName = freerdp_settings_get_string(settings, FreeRDP_ServerLicenseCompanyName);
|
|
|
|
|
|
|
|
ProductName = freerdp_settings_get_string(settings, FreeRDP_ServerLicenseProductName);
|
|
|
|
ProductVersion = freerdp_settings_get_uint32(settings, FreeRDP_ServerLicenseProductVersion);
|
|
|
|
issuerCount = freerdp_settings_get_uint32(settings, FreeRDP_ServerLicenseProductIssuersCount);
|
2022-11-14 12:17:03 +03:00
|
|
|
issuers = (const char* const*)freerdp_settings_get_pointer(settings,
|
|
|
|
FreeRDP_ServerLicenseProductIssuers);
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(CompanyName);
|
|
|
|
WINPR_ASSERT(ProductName);
|
|
|
|
WINPR_ASSERT(ProductVersion > 0);
|
|
|
|
WINPR_ASSERT(issuers || (issuerCount == 0));
|
|
|
|
|
|
|
|
if (!license_ensure_state(license, LICENSE_STATE_INITIAL, LICENSE_REQUEST))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
license->ProductInfo->dwVersion = ProductVersion;
|
2022-10-28 09:09:27 +03:00
|
|
|
license->ProductInfo->pbCompanyName = (BYTE*)ConvertUtf8ToWCharAlloc(CompanyName, &len);
|
|
|
|
if (!license->ProductInfo->pbCompanyName || (len > UINT32_MAX / sizeof(WCHAR)))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
2022-10-28 09:09:27 +03:00
|
|
|
license->ProductInfo->cbCompanyName = (UINT32)len * sizeof(WCHAR);
|
2022-10-06 12:32:08 +03:00
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
license->ProductInfo->pbProductId = (BYTE*)ConvertUtf8ToWCharAlloc(ProductName, &len);
|
|
|
|
if (!license->ProductInfo->pbProductId || (len > UINT32_MAX / sizeof(WCHAR)))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
2022-10-28 09:09:27 +03:00
|
|
|
license->ProductInfo->cbProductId = (UINT32)len * sizeof(WCHAR);
|
2022-10-06 12:32:08 +03:00
|
|
|
|
|
|
|
if (!license_read_binary_blob_data(license->KeyExchangeList, BB_KEY_EXCHG_ALG_BLOB, algs,
|
|
|
|
sizeof(algs)))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-02-03 13:51:14 +03:00
|
|
|
if (!freerdp_certificate_read_server_cert(license->certificate, settings->ServerCertificate,
|
|
|
|
settings->ServerCertificateLength))
|
2022-10-06 12:32:08 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
s = Stream_New(NULL, 1024);
|
|
|
|
if (!s)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
{
|
2023-01-20 10:35:57 +03:00
|
|
|
BOOL r = FALSE;
|
|
|
|
SSIZE_T res =
|
2023-02-03 13:51:14 +03:00
|
|
|
freerdp_certificate_write_server_cert(license->certificate, CERT_CHAIN_VERSION_2, s);
|
2023-01-20 10:35:57 +03:00
|
|
|
if (res >= 0)
|
2022-10-06 12:32:08 +03:00
|
|
|
r = license_read_binary_blob_data(license->ServerCertificate, BB_CERTIFICATE_BLOB,
|
|
|
|
Stream_Buffer(s), Stream_GetPosition(s));
|
|
|
|
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
if (!r)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!license_scope_list_resize(license->ScopeList, issuerCount))
|
|
|
|
return FALSE;
|
|
|
|
for (x = 0; x < issuerCount; x++)
|
|
|
|
{
|
|
|
|
LICENSE_BLOB* blob = license->ScopeList->array[x];
|
|
|
|
const char* name = issuers[x];
|
|
|
|
const size_t length = strnlen(name, UINT16_MAX) + 1;
|
|
|
|
if ((length == 0) || (length > UINT16_MAX))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"%s: Invalid issuer at position %" PRIuz ": length 0 < %" PRIuz " <= %" PRIu16
|
|
|
|
" ['%s']",
|
|
|
|
x, length, UINT16_MAX, name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!license_read_binary_blob_data(blob, BB_SCOPE_BLOB, name, length))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return license_set_state(license, LICENSE_STATE_CONFIGURED);
|
|
|
|
}
|
|
|
|
|
|
|
|
rdpLicense* license_get(rdpContext* context)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->rdp);
|
|
|
|
return context->rdp->license;
|
|
|
|
}
|