|
Packit |
1fb8d4 |
/**
|
|
Packit |
1fb8d4 |
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
Packit |
1fb8d4 |
* RDP Licensing
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
1fb8d4 |
* you may not use this file except in compliance with the License.
|
|
Packit |
1fb8d4 |
* You may obtain a copy of the License at
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
1fb8d4 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
1fb8d4 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
1fb8d4 |
* See the License for the specific language governing permissions and
|
|
Packit |
1fb8d4 |
* limitations under the License.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#ifndef FREERDP_LIB_CORE_LICENSE_H
|
|
Packit |
1fb8d4 |
#define FREERDP_LIB_CORE_LICENSE_H
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
typedef struct rdp_license rdpLicense;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include "rdp.h"
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <freerdp/crypto/crypto.h>
|
|
Packit |
1fb8d4 |
#include <freerdp/crypto/certificate.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <freerdp/freerdp.h>
|
|
Packit |
1fb8d4 |
#include <freerdp/log.h>
|
|
Packit |
1fb8d4 |
#include <freerdp/api.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <winpr/stream.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Licensing Packet Types */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define LICENSE_REQUEST 0x01
|
|
Packit |
1fb8d4 |
#define PLATFORM_CHALLENGE 0x02
|
|
Packit |
1fb8d4 |
#define NEW_LICENSE 0x03
|
|
Packit |
1fb8d4 |
#define UPGRADE_LICENSE 0x04
|
|
Packit |
1fb8d4 |
#define LICENSE_INFO 0x12
|
|
Packit |
1fb8d4 |
#define NEW_LICENSE_REQUEST 0x13
|
|
Packit |
1fb8d4 |
#define PLATFORM_CHALLENGE_RESPONSE 0x15
|
|
Packit |
1fb8d4 |
#define ERROR_ALERT 0xFF
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define LICENSE_PKT_CS_MASK (LICENSE_INFO | NEW_LICENSE_REQUEST | PLATFORM_CHALLENGE_RESPONSE | ERROR_ALERT)
|
|
Packit |
1fb8d4 |
#define LICENSE_PKT_SC_MASK (LICENSE_REQUEST | PLATFORM_CHALLENGE | NEW_LICENSE | UPGRADE_LICENSE | ERROR_ALERT)
|
|
Packit |
1fb8d4 |
#define LICENSE_PKT_MASK (LICENSE_PKT_CS_MASK | LICENSE_PKT_SC_MASK)
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define LICENSE_PREAMBLE_LENGTH 4
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Cryptographic Lengths */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define CLIENT_RANDOM_LENGTH 32
|
|
Packit |
1fb8d4 |
#define SERVER_RANDOM_LENGTH 32
|
|
Packit |
1fb8d4 |
#define MASTER_SECRET_LENGTH 48
|
|
Packit |
1fb8d4 |
#define PREMASTER_SECRET_LENGTH 48
|
|
Packit |
1fb8d4 |
#define SESSION_KEY_BLOB_LENGTH 48
|
|
Packit |
1fb8d4 |
#define MAC_SALT_KEY_LENGTH 16
|
|
Packit |
1fb8d4 |
#define LICENSING_ENCRYPTION_KEY_LENGTH 16
|
|
Packit |
1fb8d4 |
#define HWID_PLATFORM_ID_LENGTH 4
|
|
Packit |
1fb8d4 |
#define HWID_UNIQUE_DATA_LENGTH 16
|
|
Packit |
1fb8d4 |
#define HWID_LENGTH 20
|
|
Packit |
1fb8d4 |
#define LICENSING_PADDING_SIZE 8
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Preamble Flags */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define PREAMBLE_VERSION_2_0 0x02
|
|
Packit |
1fb8d4 |
#define PREAMBLE_VERSION_3_0 0x03
|
|
Packit |
1fb8d4 |
#define LicenseProtocolVersionMask 0x0F
|
|
Packit |
1fb8d4 |
#define EXTENDED_ERROR_MSG_SUPPORTED 0x80
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Binary Blob Types */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define BB_ANY_BLOB 0x0000
|
|
Packit |
1fb8d4 |
#define BB_DATA_BLOB 0x0001
|
|
Packit |
1fb8d4 |
#define BB_RANDOM_BLOB 0x0002
|
|
Packit |
1fb8d4 |
#define BB_CERTIFICATE_BLOB 0x0003
|
|
Packit |
1fb8d4 |
#define BB_ERROR_BLOB 0x0004
|
|
Packit |
1fb8d4 |
#define BB_ENCRYPTED_DATA_BLOB 0x0009
|
|
Packit |
1fb8d4 |
#define BB_KEY_EXCHG_ALG_BLOB 0x000D
|
|
Packit |
1fb8d4 |
#define BB_SCOPE_BLOB 0x000E
|
|
Packit |
1fb8d4 |
#define BB_CLIENT_USER_NAME_BLOB 0x000F
|
|
Packit |
1fb8d4 |
#define BB_CLIENT_MACHINE_NAME_BLOB 0x0010
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* License Key Exchange Algorithms */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define KEY_EXCHANGE_ALG_RSA 0x00000001
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* License Error Codes */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define ERR_INVALID_SERVER_CERTIFICATE 0x00000001
|
|
Packit |
1fb8d4 |
#define ERR_NO_LICENSE 0x00000002
|
|
Packit |
1fb8d4 |
#define ERR_INVALID_MAC 0x00000003
|
|
Packit |
1fb8d4 |
#define ERR_INVALID_SCOPE 0x00000004
|
|
Packit |
1fb8d4 |
#define ERR_NO_LICENSE_SERVER 0x00000006
|
|
Packit |
1fb8d4 |
#define STATUS_VALID_CLIENT 0x00000007
|
|
Packit |
1fb8d4 |
#define ERR_INVALID_CLIENT 0x00000008
|
|
Packit |
1fb8d4 |
#define ERR_INVALID_PRODUCT_ID 0x0000000B
|
|
Packit |
1fb8d4 |
#define ERR_INVALID_MESSAGE_LENGTH 0x0000000C
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* State Transition Codes */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define ST_TOTAL_ABORT 0x00000001
|
|
Packit |
1fb8d4 |
#define ST_NO_TRANSITION 0x00000002
|
|
Packit |
1fb8d4 |
#define ST_RESET_PHASE_TO_START 0x00000003
|
|
Packit |
1fb8d4 |
#define ST_RESEND_LAST_MESSAGE 0x00000004
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* Platform Challenge Types */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define WIN32_PLATFORM_CHALLENGE_TYPE 0x0100
|
|
Packit |
1fb8d4 |
#define WIN16_PLATFORM_CHALLENGE_TYPE 0x0200
|
|
Packit |
1fb8d4 |
#define WINCE_PLATFORM_CHALLENGE_TYPE 0x0300
|
|
Packit |
1fb8d4 |
#define OTHER_PLATFORM_CHALLENGE_TYPE 0xFF00
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/* License Detail Levels */
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define LICENSE_DETAIL_SIMPLE 0x0001
|
|
Packit |
1fb8d4 |
#define LICENSE_DETAIL_MODERATE 0x0002
|
|
Packit |
1fb8d4 |
#define LICENSE_DETAIL_DETAIL 0x0003
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* PlatformId:
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* The most significant byte of the PlatformId field contains the operating system version of the client.
|
|
Packit |
1fb8d4 |
* The second most significant byte of the PlatformId field identifies the ISV that provided the client image.
|
|
Packit |
1fb8d4 |
* The remaining two bytes in the PlatformId field are used by the ISV to identify the build number of the operating system.
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* 0x04010000:
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* CLIENT_OS_ID_WINNT_POST_52 (0x04000000)
|
|
Packit |
1fb8d4 |
* CLIENT_IMAGE_ID_MICROSOFT (0x00010000)
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define CLIENT_OS_ID_WINNT_351 0x01000000
|
|
Packit |
1fb8d4 |
#define CLIENT_OS_ID_WINNT_40 0x02000000
|
|
Packit |
1fb8d4 |
#define CLIENT_OS_ID_WINNT_50 0x03000000
|
|
Packit |
1fb8d4 |
#define CLIENT_OS_ID_WINNT_POST_52 0x04000000
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define CLIENT_IMAGE_ID_MICROSOFT 0x00010000
|
|
Packit |
1fb8d4 |
#define CLIENT_IMAGE_ID_CITRIX 0x00020000
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
typedef struct
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
UINT32 dwVersion;
|
|
Packit |
1fb8d4 |
UINT32 cbCompanyName;
|
|
Packit |
1fb8d4 |
BYTE* pbCompanyName;
|
|
Packit |
1fb8d4 |
UINT32 cbProductId;
|
|
Packit |
1fb8d4 |
BYTE* pbProductId;
|
|
Packit |
1fb8d4 |
} LICENSE_PRODUCT_INFO;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
typedef struct
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
UINT16 type;
|
|
Packit |
1fb8d4 |
UINT16 length;
|
|
Packit |
1fb8d4 |
BYTE* data;
|
|
Packit |
1fb8d4 |
} LICENSE_BLOB;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
typedef struct
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
UINT32 count;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* array;
|
|
Packit |
1fb8d4 |
} SCOPE_LIST;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
typedef enum
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
LICENSE_STATE_AWAIT,
|
|
Packit |
1fb8d4 |
LICENSE_STATE_PROCESS,
|
|
Packit |
1fb8d4 |
LICENSE_STATE_ABORTED,
|
|
Packit |
1fb8d4 |
LICENSE_STATE_COMPLETED
|
|
Packit |
1fb8d4 |
} LICENSE_STATE;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
struct rdp_license
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
LICENSE_STATE state;
|
|
Packit |
1fb8d4 |
rdpRdp* rdp;
|
|
Packit |
1fb8d4 |
rdpCertificate* certificate;
|
|
Packit |
1fb8d4 |
BYTE* Modulus;
|
|
Packit |
1fb8d4 |
UINT32 ModulusLength;
|
|
Packit |
1fb8d4 |
BYTE Exponent[4];
|
|
Packit |
1fb8d4 |
BYTE HardwareId[HWID_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE ClientRandom[CLIENT_RANDOM_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE ServerRandom[SERVER_RANDOM_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE MasterSecret[MASTER_SECRET_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE PremasterSecret[PREMASTER_SECRET_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE SessionKeyBlob[SESSION_KEY_BLOB_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE MacSaltKey[MAC_SALT_KEY_LENGTH];
|
|
Packit |
1fb8d4 |
BYTE LicensingEncryptionKey[LICENSING_ENCRYPTION_KEY_LENGTH];
|
|
Packit |
1fb8d4 |
LICENSE_PRODUCT_INFO* ProductInfo;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* ErrorInfo;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* KeyExchangeList;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* ServerCertificate;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* ClientUserName;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* ClientMachineName;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* PlatformChallenge;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* EncryptedPremasterSecret;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* EncryptedPlatformChallenge;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB *EncryptedPlatformChallengeResponse;
|
|
Packit |
1fb8d4 |
LICENSE_BLOB* EncryptedHardwareId;
|
|
Packit |
1fb8d4 |
SCOPE_LIST* ScopeList;
|
|
Packit |
1fb8d4 |
UINT32 PacketHeaderLength;
|
|
Packit |
1fb8d4 |
};
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
FREERDP_LOCAL int license_recv(rdpLicense* license, wStream* s);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
FREERDP_LOCAL BOOL license_send_valid_client_error_packet(rdpLicense* license);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
FREERDP_LOCAL rdpLicense* license_new(rdpRdp* rdp);
|
|
Packit |
1fb8d4 |
FREERDP_LOCAL void license_free(rdpLicense* license);
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#define LICENSE_TAG FREERDP_TAG("core.license")
|
|
Packit |
1fb8d4 |
#ifdef WITH_DEBUG_LICENSE
|
|
Packit |
1fb8d4 |
#define DEBUG_LICENSE(...) WLog_DBG(LICENSE_TAG, __VA_ARGS__)
|
|
Packit |
1fb8d4 |
#else
|
|
Packit |
1fb8d4 |
#define DEBUG_LICENSE(...) do { } while (0)
|
|
Packit |
1fb8d4 |
#endif
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#endif /* FREERDP_LIB_CORE_LICENSE_H */
|