2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-12 04:46:03 +04:00
|
|
|
* RDP Licensing
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LICENSE_H
|
|
|
|
#define __LICENSE_H
|
|
|
|
|
|
|
|
typedef struct rdp_license rdpLicense;
|
|
|
|
|
|
|
|
#include "rdp.h"
|
2013-03-22 00:45:25 +04:00
|
|
|
|
2012-02-17 09:58:30 +04:00
|
|
|
#include <freerdp/crypto/crypto.h>
|
|
|
|
#include <freerdp/crypto/certificate.h>
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
|
|
|
|
#include <winpr/stream.h>
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
/* Licensing Packet Types */
|
2013-02-05 09:19:57 +04:00
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
#define LICENSE_REQUEST 0x01
|
|
|
|
#define PLATFORM_CHALLENGE 0x02
|
|
|
|
#define NEW_LICENSE 0x03
|
|
|
|
#define UPGRADE_LICENSE 0x04
|
|
|
|
#define LICENSE_INFO 0x12
|
|
|
|
#define NEW_LICENSE_REQUEST 0x13
|
|
|
|
#define PLATFORM_CHALLENGE_RESPONSE 0x15
|
|
|
|
#define ERROR_ALERT 0xFF
|
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
#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)
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2012-01-25 14:12:37 +04:00
|
|
|
#define LICENSE_PREAMBLE_LENGTH 4
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2011-07-12 23:10:43 +04:00
|
|
|
/* Cryptographic Lengths */
|
2013-02-05 09:19:57 +04:00
|
|
|
|
2011-07-12 23:10:43 +04:00
|
|
|
#define CLIENT_RANDOM_LENGTH 32
|
|
|
|
#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
|
2011-07-15 01:02:35 +04:00
|
|
|
#define LICENSING_PADDING_SIZE 8
|
2011-07-12 23:10:43 +04:00
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
/* Preamble Flags */
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
#define PREAMBLE_VERSION_2_0 0x02
|
|
|
|
#define PREAMBLE_VERSION_3_0 0x03
|
|
|
|
#define LicenseProtocolVersionMask 0x0F
|
|
|
|
#define EXTENDED_ERROR_MSG_SUPPORTED 0x80
|
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
/* Binary Blob Types */
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
#define BB_ANY_BLOB 0x0000
|
2011-07-12 04:46:03 +04:00
|
|
|
#define BB_DATA_BLOB 0x0001
|
|
|
|
#define BB_RANDOM_BLOB 0x0002
|
|
|
|
#define BB_CERTIFICATE_BLOB 0x0003
|
|
|
|
#define BB_ERROR_BLOB 0x0004
|
|
|
|
#define BB_ENCRYPTED_DATA_BLOB 0x0009
|
|
|
|
#define BB_KEY_EXCHG_ALG_BLOB 0x000D
|
|
|
|
#define BB_SCOPE_BLOB 0x000E
|
|
|
|
#define BB_CLIENT_USER_NAME_BLOB 0x000F
|
|
|
|
#define BB_CLIENT_MACHINE_NAME_BLOB 0x0010
|
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
/* License Key Exchange Algorithms */
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
#define KEY_EXCHANGE_ALG_RSA 0x00000001
|
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
/* License Error Codes */
|
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
#define ERR_INVALID_SERVER_CERTIFICATE 0x00000001
|
|
|
|
#define ERR_NO_LICENSE 0x00000002
|
|
|
|
#define ERR_INVALID_MAC 0x00000003
|
|
|
|
#define ERR_INVALID_SCOPE 0x00000004
|
|
|
|
#define ERR_NO_LICENSE_SERVER 0x00000006
|
|
|
|
#define STATUS_VALID_CLIENT 0x00000007
|
|
|
|
#define ERR_INVALID_CLIENT 0x00000008
|
|
|
|
#define ERR_INVALID_PRODUCT_ID 0x0000000B
|
|
|
|
#define ERR_INVALID_MESSAGE_LENGTH 0x0000000C
|
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
/* State Transition Codes */
|
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
#define ST_TOTAL_ABORT 0x00000001
|
|
|
|
#define ST_NO_TRANSITION 0x00000002
|
|
|
|
#define ST_RESET_PHASE_TO_START 0x00000003
|
|
|
|
#define ST_RESEND_LAST_MESSAGE 0x00000004
|
|
|
|
|
2013-02-05 09:19:57 +04:00
|
|
|
/* Platform Challenge Types */
|
|
|
|
|
|
|
|
#define WIN32_PLATFORM_CHALLENGE_TYPE 0x0100
|
|
|
|
#define WIN16_PLATFORM_CHALLENGE_TYPE 0x0200
|
|
|
|
#define WINCE_PLATFORM_CHALLENGE_TYPE 0x0300
|
|
|
|
#define OTHER_PLATFORM_CHALLENGE_TYPE 0xFF00
|
|
|
|
|
|
|
|
/* License Detail Levels */
|
|
|
|
|
|
|
|
#define LICENSE_DETAIL_SIMPLE 0x0001
|
|
|
|
#define LICENSE_DETAIL_MODERATE 0x0002
|
|
|
|
#define LICENSE_DETAIL_DETAIL 0x0003
|
|
|
|
|
2013-02-05 10:07:34 +04:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CLIENT_OS_ID_WINNT_351 0x01000000
|
|
|
|
#define CLIENT_OS_ID_WINNT_40 0x02000000
|
|
|
|
#define CLIENT_OS_ID_WINNT_50 0x03000000
|
|
|
|
#define CLIENT_OS_ID_WINNT_POST_52 0x04000000
|
|
|
|
|
|
|
|
#define CLIENT_IMAGE_ID_MICROSOFT 0x00010000
|
|
|
|
#define CLIENT_IMAGE_ID_CITRIX 0x00020000
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwVersion;
|
|
|
|
UINT32 cbCompanyName;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* pbCompanyName;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbProductId;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* pbProductId;
|
2014-02-17 03:02:50 +04:00
|
|
|
} LICENSE_PRODUCT_INFO;
|
2011-07-12 04:46:03 +04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 type;
|
|
|
|
UINT16 length;
|
|
|
|
BYTE* data;
|
2011-07-12 04:46:03 +04:00
|
|
|
} LICENSE_BLOB;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 count;
|
2011-07-12 04:46:03 +04:00
|
|
|
LICENSE_BLOB* array;
|
|
|
|
} SCOPE_LIST;
|
|
|
|
|
2011-07-15 10:02:09 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LICENSE_STATE_AWAIT,
|
|
|
|
LICENSE_STATE_PROCESS,
|
|
|
|
LICENSE_STATE_ABORTED,
|
|
|
|
LICENSE_STATE_COMPLETED
|
|
|
|
} LICENSE_STATE;
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
struct rdp_license
|
|
|
|
{
|
2011-07-15 10:02:09 +04:00
|
|
|
LICENSE_STATE state;
|
2013-02-05 18:46:25 +04:00
|
|
|
rdpRdp* rdp;
|
|
|
|
rdpCertificate* certificate;
|
2013-02-05 18:30:53 +04:00
|
|
|
BYTE* Modulus;
|
|
|
|
UINT32 ModulusLength;
|
|
|
|
BYTE Exponent[4];
|
2013-02-05 08:57:04 +04:00
|
|
|
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];
|
2014-02-17 03:02:50 +04:00
|
|
|
LICENSE_PRODUCT_INFO* ProductInfo;
|
2013-02-05 08:57:04 +04:00
|
|
|
LICENSE_BLOB* ErrorInfo;
|
|
|
|
LICENSE_BLOB* KeyExchangeList;
|
|
|
|
LICENSE_BLOB* ServerCertificate;
|
|
|
|
LICENSE_BLOB* ClientUserName;
|
|
|
|
LICENSE_BLOB* ClientMachineName;
|
|
|
|
LICENSE_BLOB* PlatformChallenge;
|
|
|
|
LICENSE_BLOB* EncryptedPremasterSecret;
|
|
|
|
LICENSE_BLOB* EncryptedPlatformChallenge;
|
|
|
|
LICENSE_BLOB* EncryptedHardwareId;
|
|
|
|
SCOPE_LIST* ScopeList;
|
2014-04-02 16:17:39 +04:00
|
|
|
UINT32 PacketHeaderLength;
|
2011-07-12 04:46:03 +04:00
|
|
|
};
|
|
|
|
|
2013-11-05 00:52:29 +04:00
|
|
|
int license_recv(rdpLicense* license, wStream* s);
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_send(rdpLicense* license, wStream* s, BYTE type);
|
|
|
|
wStream* license_send_stream_init(rdpLicense* license);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2011-07-13 19:40:19 +04:00
|
|
|
void license_generate_randoms(rdpLicense* license);
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL license_generate_keys(rdpLicense* license);
|
|
|
|
BOOL license_generate_hwid(rdpLicense* license);
|
|
|
|
BOOL license_encrypt_premaster_secret(rdpLicense* license);
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_decrypt_platform_challenge(rdpLicense* license);
|
2011-07-12 09:57:09 +04:00
|
|
|
|
2014-02-17 03:02:50 +04:00
|
|
|
LICENSE_PRODUCT_INFO* license_new_product_info(void);
|
|
|
|
void license_free_product_info(LICENSE_PRODUCT_INFO* productInfo);
|
|
|
|
BOOL license_read_product_info(wStream* s, LICENSE_PRODUCT_INFO* productInfo);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
LICENSE_BLOB* license_new_binary_blob(UINT16 type);
|
2011-07-12 09:16:59 +04:00
|
|
|
void license_free_binary_blob(LICENSE_BLOB* blob);
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob);
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_write_binary_blob(wStream* s, LICENSE_BLOB* blob);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2013-02-15 01:20:43 +04:00
|
|
|
SCOPE_LIST* license_new_scope_list(void);
|
2011-07-12 09:16:59 +04:00
|
|
|
void license_free_scope_list(SCOPE_LIST* scopeList);
|
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
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL license_read_license_request_packet(rdpLicense* license, wStream* s);
|
|
|
|
BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s);
|
|
|
|
void license_read_new_license_packet(rdpLicense* license, wStream* s);
|
|
|
|
void license_read_upgrade_license_packet(rdpLicense* license, wStream* s);
|
|
|
|
BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s);
|
2011-07-12 04:46:03 +04:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_write_new_license_request_packet(rdpLicense* license, wStream* s);
|
|
|
|
BOOL license_send_new_license_request_packet(rdpLicense* license);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2015-04-01 12:38:53 +03:00
|
|
|
BOOL license_write_platform_challenge_response_packet(rdpLicense* license, wStream* s, BYTE* mac_data);
|
2015-04-01 12:11:37 +03:00
|
|
|
BOOL license_send_platform_challenge_response_packet(rdpLicense* license);
|
2011-07-12 09:57:09 +04:00
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL license_send_valid_client_error_packet(rdpLicense* license);
|
2011-08-20 17:41:40 +04:00
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
rdpLicense* license_new(rdpRdp* rdp);
|
2011-07-12 04:46:03 +04:00
|
|
|
void license_free(rdpLicense* license);
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define LICENSE_TAG FREERDP_TAG("core.license")
|
2011-07-12 09:57:09 +04:00
|
|
|
#ifdef WITH_DEBUG_LICENSE
|
2014-09-12 16:36:29 +04:00
|
|
|
#define DEBUG_LICENSE(fmt, ...) WLog_DBG(LICENSE_TAG, fmt, ## __VA_ARGS__)
|
2011-07-12 09:57:09 +04:00
|
|
|
#else
|
2014-09-12 16:36:29 +04:00
|
|
|
#define DEBUG_LICENSE(fmt, ...) do { } while (0)
|
2011-07-12 09:57:09 +04:00
|
|
|
#endif
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
#endif /* __LICENSE_H */
|