FreeRDP
Loading...
Searching...
No Matches
license.c
1/*
2 * FreeRDP: A Remote Desktop Protocol Implementation
3 * RDP Licensing
4 *
5 * Copyright 2011-2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6 * Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
7 * Copyright 2018 David Fort <contact@hardening-consulting.com>
8 * Copyright 2022,2023 Armin Novak <armin.novak@thincast.com>
9 * Copyright 2022,2023 Thincast Technologies GmbH
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24#include <freerdp/config.h>
25
26#include "settings.h"
27
28#include <freerdp/license.h>
29
30#include <winpr/crt.h>
31#include <winpr/assert.h>
32#include <winpr/crypto.h>
33#include <winpr/shell.h>
34#include <winpr/path.h>
35#include <winpr/file.h>
36
37#include <freerdp/log.h>
38
39#include <freerdp/crypto/certificate.h>
40
41#include "license.h"
42
43#include "../crypto/crypto.h"
44#include "../crypto/certificate.h"
45
46#define LICENSE_TAG FREERDP_TAG("core.license")
47
48// #define LICENSE_NULL_CLIENT_RANDOM 1
49// #define LICENSE_NULL_PREMASTER_SECRET 1
50
51// #define WITH_LICENSE_DECRYPT_CHALLENGE_RESPONSE
52
53#define PLATFORM_CHALLENGE_RESPONSE_VERSION 0x0100
54
55/* Upper limits for data exchanged.
56 * In real situations they are not very large, but protocol wise these could be UINT32_MAX.
57 * So limit to something larger than actually used but less than the giant limit.
58 */
59#define LICENSE_MAX_CAL_LENGTH (1ull * UINT16_MAX)
60#define LICENSE_MAX_SCOPE_LENGTH (1ull * UINT16_MAX)
61#define LICENSE_MAX_PRODUCT_ID_LENGTH (1ull * UINT16_MAX)
62#define LICENSE_MAX_COMPANY_NAME_LENGTH (1ull * UINT16_MAX)
63
65enum LicenseRequestType
66{
67 LICENSE_REQUEST = 0x01,
68 PLATFORM_CHALLENGE = 0x02,
69 NEW_LICENSE = 0x03,
70 UPGRADE_LICENSE = 0x04,
71 LICENSE_INFO = 0x12,
72 NEW_LICENSE_REQUEST = 0x13,
73 PLATFORM_CHALLENGE_RESPONSE = 0x15,
74 ERROR_ALERT = 0xFF
75};
76
77/*
78#define LICENSE_PKT_CS_MASK \
79 (LICENSE_INFO | NEW_LICENSE_REQUEST | PLATFORM_CHALLENGE_RESPONSE | ERROR_ALERT)
80#define LICENSE_PKT_SC_MASK \
81 (LICENSE_REQUEST | PLATFORM_CHALLENGE | NEW_LICENSE | UPGRADE_LICENSE | ERROR_ALERT)
82#define LICENSE_PKT_MASK (LICENSE_PKT_CS_MASK | LICENSE_PKT_SC_MASK)
83*/
84#define LICENSE_PREAMBLE_LENGTH 4
85
86/* Cryptographic Lengths */
87
88#define SERVER_RANDOM_LENGTH 32
89#define MASTER_SECRET_LENGTH 48
90#define PREMASTER_SECRET_LENGTH 48
91#define SESSION_KEY_BLOB_LENGTH 48
92#define MAC_SALT_KEY_LENGTH 16
93#define LICENSING_ENCRYPTION_KEY_LENGTH 16
94#define HWID_PLATFORM_ID_LENGTH 4
95// #define HWID_UNIQUE_DATA_LENGTH 16
96#define HWID_LENGTH 20
97// #define LICENSING_PADDING_SIZE 8
98
99/* Preamble Flags */
100
101// #define PREAMBLE_VERSION_2_0 0x02
102#define PREAMBLE_VERSION_3_0 0x03
103// #define LicenseProtocolVersionMask 0x0F
104#define EXTENDED_ERROR_MSG_SUPPORTED 0x80
105
107enum
108{
109 BB_ANY_BLOB = 0x0000,
110 BB_DATA_BLOB = 0x0001,
111 BB_RANDOM_BLOB = 0x0002,
112 BB_CERTIFICATE_BLOB = 0x0003,
113 BB_ERROR_BLOB = 0x0004,
114 BB_ENCRYPTED_DATA_BLOB = 0x0009,
115 BB_KEY_EXCHG_ALG_BLOB = 0x000D,
116 BB_SCOPE_BLOB = 0x000E,
117 BB_CLIENT_USER_NAME_BLOB = 0x000F,
118 BB_CLIENT_MACHINE_NAME_BLOB = 0x0010
119};
120
121/* License Key Exchange Algorithms */
122
123#define KEY_EXCHANGE_ALG_RSA 0x00000001
124
127enum
128{
129 ERR_INVALID_SERVER_CERTIFICATE = 0x00000001,
130 ERR_NO_LICENSE = 0x00000002,
131 ERR_INVALID_MAC = 0x00000003,
132 ERR_INVALID_SCOPE = 0x00000004,
133 ERR_NO_LICENSE_SERVER = 0x00000006,
134 STATUS_VALID_CLIENT = 0x00000007,
135 ERR_INVALID_CLIENT = 0x00000008,
136 ERR_INVALID_PRODUCT_ID = 0x0000000B,
137 ERR_INVALID_MESSAGE_LENGTH = 0x0000000C
138};
139
142enum
143{
144 ST_TOTAL_ABORT = 0x00000001,
145 ST_NO_TRANSITION = 0x00000002,
146 ST_RESET_PHASE_TO_START = 0x00000003,
147 ST_RESEND_LAST_MESSAGE = 0x00000004
148};
149
152enum
153{
154 WIN32_PLATFORM_CHALLENGE_TYPE = 0x0100,
155 WIN16_PLATFORM_CHALLENGE_TYPE = 0x0200,
156 WINCE_PLATFORM_CHALLENGE_TYPE = 0x0300,
157 OTHER_PLATFORM_CHALLENGE_TYPE = 0xFF00
158};
159
162enum
163{
164 LICENSE_DETAIL_SIMPLE = 0x0001,
165 LICENSE_DETAIL_MODERATE = 0x0002,
166 LICENSE_DETAIL_DETAIL = 0x0003
167};
168
169/*
170 * PlatformId:
171 *
172 * The most significant byte of the PlatformId field contains the operating system version of the
173 * client. The second most significant byte of the PlatformId field identifies the ISV that provided
174 * the client image. The remaining two bytes in the PlatformId field are used by the ISV to identify
175 * the build number of the operating system.
176 *
177 * 0x04010000:
178 *
179 * CLIENT_OS_ID_WINNT_POST_52 (0x04000000)
180 * CLIENT_IMAGE_ID_MICROSOFT (0x00010000)
181 */
182enum
183{
184 CLIENT_OS_ID_WINNT_351 = 0x01000000,
185 CLIENT_OS_ID_WINNT_40 = 0x02000000,
186 CLIENT_OS_ID_WINNT_50 = 0x03000000,
187 CLIENT_OS_ID_WINNT_POST_52 = 0x04000000,
188
189 CLIENT_IMAGE_ID_MICROSOFT = 0x00010000,
190 CLIENT_IMAGE_ID_CITRIX = 0x00020000,
191};
192
193struct rdp_license
194{
195 LICENSE_STATE state;
196 LICENSE_TYPE type;
197 rdpRdp* rdp;
198 rdpCertificate* certificate;
199 BYTE HardwareId[HWID_LENGTH];
200 BYTE ClientRandom[CLIENT_RANDOM_LENGTH];
201 BYTE ServerRandom[SERVER_RANDOM_LENGTH];
202 BYTE MasterSecret[MASTER_SECRET_LENGTH];
203 BYTE PremasterSecret[PREMASTER_SECRET_LENGTH];
204 BYTE SessionKeyBlob[SESSION_KEY_BLOB_LENGTH];
205 BYTE MacSaltKey[MAC_SALT_KEY_LENGTH];
206 BYTE LicensingEncryptionKey[LICENSING_ENCRYPTION_KEY_LENGTH];
207 LICENSE_PRODUCT_INFO* ProductInfo;
208 LICENSE_BLOB* ErrorInfo;
209 LICENSE_BLOB* LicenseInfo; /* Client -> Server */
210 LICENSE_BLOB* KeyExchangeList;
211 LICENSE_BLOB* ServerCertificate;
212 LICENSE_BLOB* ClientUserName;
213 LICENSE_BLOB* ClientMachineName;
214 LICENSE_BLOB* PlatformChallenge;
215 LICENSE_BLOB* PlatformChallengeResponse;
216 LICENSE_BLOB* EncryptedPremasterSecret;
217 LICENSE_BLOB* EncryptedPlatformChallenge;
218 LICENSE_BLOB* EncryptedPlatformChallengeResponse;
219 LICENSE_BLOB* EncryptedHardwareId;
220 LICENSE_BLOB* EncryptedLicenseInfo;
221 BYTE MACData[LICENSING_ENCRYPTION_KEY_LENGTH];
222 SCOPE_LIST* ScopeList;
223 UINT32 PacketHeaderLength;
224 UINT32 PreferredKeyExchangeAlg;
225 UINT32 PlatformId;
226 UINT16 ClientType;
227 UINT16 LicenseDetailLevel;
228 BOOL update;
229 wLog* log;
230};
231
232WINPR_ATTR_NODISCARD
233static BOOL license_send_error_alert(rdpLicense* license, UINT32 dwErrorCode,
234 UINT32 dwStateTransition, const LICENSE_BLOB* info);
235
236static void license_set_state(rdpLicense* license, LICENSE_STATE state);
237
238WINPR_ATTR_NODISCARD
239static const char* license_get_state_string(LICENSE_STATE state);
240
241WINPR_ATTR_NODISCARD
242static const char* license_preferred_key_exchange_alg_string(UINT32 alg, char* buffer, size_t size)
243{
244 const char* name = nullptr;
245
246 switch (alg)
247 {
248 case KEY_EXCHANGE_ALG_RSA:
249 name = "KEY_EXCHANGE_ALG_RSA";
250 break;
251 default:
252 name = "KEY_EXCHANGE_ALG_UNKNOWN";
253 break;
254 }
255
256 (void)_snprintf(buffer, size, "%s [0x%08" PRIx32 "]", name, alg);
257 return buffer;
258}
259
260WINPR_ATTR_NODISCARD
261static const char* license_request_type_string(UINT32 type)
262{
263 switch (type)
264 {
265 case LICENSE_REQUEST:
266 return "LICENSE_REQUEST";
267 case PLATFORM_CHALLENGE:
268 return "PLATFORM_CHALLENGE";
269 case NEW_LICENSE:
270 return "NEW_LICENSE";
271 case UPGRADE_LICENSE:
272 return "UPGRADE_LICENSE";
273 case LICENSE_INFO:
274 return "LICENSE_INFO";
275 case NEW_LICENSE_REQUEST:
276 return "NEW_LICENSE_REQUEST";
277 case PLATFORM_CHALLENGE_RESPONSE:
278 return "PLATFORM_CHALLENGE_RESPONSE";
279 case ERROR_ALERT:
280 return "ERROR_ALERT";
281 default:
282 return "LICENSE_REQUEST_TYPE_UNKNOWN";
283 }
284}
285
286WINPR_ATTR_NODISCARD
287static const char* license_blob_type_string(UINT16 type)
288{
289 switch (type)
290 {
291 case BB_ANY_BLOB:
292 return "BB_ANY_BLOB";
293 case BB_DATA_BLOB:
294 return "BB_DATA_BLOB";
295 case BB_RANDOM_BLOB:
296 return "BB_RANDOM_BLOB";
297 case BB_CERTIFICATE_BLOB:
298 return "BB_CERTIFICATE_BLOB";
299 case BB_ERROR_BLOB:
300 return "BB_ERROR_BLOB";
301 case BB_ENCRYPTED_DATA_BLOB:
302 return "BB_ENCRYPTED_DATA_BLOB";
303 case BB_KEY_EXCHG_ALG_BLOB:
304 return "BB_KEY_EXCHG_ALG_BLOB";
305 case BB_SCOPE_BLOB:
306 return "BB_SCOPE_BLOB";
307 case BB_CLIENT_USER_NAME_BLOB:
308 return "BB_CLIENT_USER_NAME_BLOB";
309 case BB_CLIENT_MACHINE_NAME_BLOB:
310 return "BB_CLIENT_MACHINE_NAME_BLOB";
311 default:
312 return "BB_UNKNOWN";
313 }
314}
315
316WINPR_ATTR_NODISCARD
317static wStream* license_send_stream_init(rdpLicense* license, UINT16* sec_flags);
318
319WINPR_ATTR_NODISCARD
320static BOOL license_generate_randoms(rdpLicense* license);
321
322WINPR_ATTR_NODISCARD
323static BOOL license_generate_keys(rdpLicense* license);
324
325WINPR_ATTR_NODISCARD
326static BOOL license_generate_hwid(rdpLicense* license);
327
328WINPR_ATTR_NODISCARD
329static BOOL license_encrypt_premaster_secret(rdpLicense* license);
330
331static void license_free_product_info(LICENSE_PRODUCT_INFO* productInfo);
332
333WINPR_ATTR_MALLOC(license_free_product_info, 1)
334static LICENSE_PRODUCT_INFO* license_new_product_info(void);
335
336WINPR_ATTR_NODISCARD
337static BOOL license_read_product_info(wLog* log, wStream* s, LICENSE_PRODUCT_INFO* productInfo);
338
339static void license_free_binary_blob(LICENSE_BLOB* blob);
340
341WINPR_ATTR_MALLOC(license_free_binary_blob, 1)
342static LICENSE_BLOB* license_new_binary_blob(UINT16 type);
343
344WINPR_ATTR_NODISCARD
345static BOOL license_read_binary_blob_data(wLog* log, LICENSE_BLOB* blob, UINT16 type,
346 const void* data, size_t length);
347
348WINPR_ATTR_NODISCARD
349static BOOL license_read_binary_blob(wLog* log, wStream* s, LICENSE_BLOB* blob);
350
351WINPR_ATTR_NODISCARD
352static BOOL license_write_binary_blob(wStream* s, const LICENSE_BLOB* blob);
353
354static void license_free_scope_list(SCOPE_LIST* scopeList);
355
356WINPR_ATTR_MALLOC(license_free_scope_list, 1)
357static SCOPE_LIST* license_new_scope_list(void);
358
359WINPR_ATTR_NODISCARD
360static BOOL license_scope_list_resize(SCOPE_LIST* scopeList, UINT32 count);
361
362WINPR_ATTR_NODISCARD
363static BOOL license_read_scope_list(wLog* log, wStream* s, SCOPE_LIST* scopeList);
364
365WINPR_ATTR_NODISCARD
366static BOOL license_write_scope_list(wLog* log, wStream* s, const SCOPE_LIST* scopeList);
367
368WINPR_ATTR_NODISCARD
369static BOOL license_read_license_request_packet(rdpLicense* license, wStream* s);
370
371WINPR_ATTR_NODISCARD
372static BOOL license_write_license_request_packet(const rdpLicense* license, wStream* s);
373
374WINPR_ATTR_NODISCARD
375static BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s);
376
377WINPR_ATTR_NODISCARD
378static BOOL license_send_platform_challenge_packet(rdpLicense* license);
379
380WINPR_ATTR_NODISCARD
381static BOOL license_read_new_or_upgrade_license_packet(rdpLicense* license, wStream* s);
382
383WINPR_ATTR_NODISCARD
384static BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s);
385
386WINPR_ATTR_NODISCARD
387static BOOL license_write_new_license_request_packet(const rdpLicense* license, wStream* s);
388
389WINPR_ATTR_NODISCARD
390static BOOL license_read_new_license_request_packet(rdpLicense* license, wStream* s);
391
392WINPR_ATTR_NODISCARD
393static BOOL license_answer_license_request(rdpLicense* license);
394
395WINPR_ATTR_NODISCARD
396static BOOL license_send_platform_challenge_response(rdpLicense* license);
397
398WINPR_ATTR_NODISCARD
399static BOOL license_read_platform_challenge_response(rdpLicense* license);
400
401WINPR_ATTR_NODISCARD
402static BOOL license_read_client_platform_challenge_response(rdpLicense* license, wStream* s);
403
404WINPR_ATTR_NODISCARD
405static BOOL license_write_client_platform_challenge_response(rdpLicense* license, wStream* s);
406
407WINPR_ATTR_NODISCARD
408static BOOL license_write_server_upgrade_license(const rdpLicense* license, wStream* s);
409
410WINPR_ATTR_NODISCARD
411static BOOL license_send_license_info(rdpLicense* license, const LICENSE_BLOB* calBlob,
412 const BYTE* signature, size_t signature_length);
413
414WINPR_ATTR_NODISCARD
415static BOOL license_read_license_info(rdpLicense* license, wStream* s);
416
417WINPR_ATTR_NODISCARD
418static state_run_t license_client_recv(rdpLicense* license, wStream* s);
419
420WINPR_ATTR_NODISCARD
421static state_run_t license_server_recv(rdpLicense* license, wStream* s);
422
423#define PLATFORMID (CLIENT_OS_ID_WINNT_POST_52 | CLIENT_IMAGE_ID_MICROSOFT)
424
425#ifdef WITH_DEBUG_LICENSE
426
427WINPR_ATTR_NODISCARD
428static const char* error_codes(UINT32 idx)
429{
430#define EVCASE(x) \
431 case x: \
432 return #x
433 switch (idx)
434 {
435 EVCASE(ERR_INVALID_SERVER_CERTIFICATE);
436 EVCASE(ERR_NO_LICENSE);
437 EVCASE(ERR_INVALID_MAC);
438 EVCASE(ERR_INVALID_SCOPE);
439 EVCASE(ERR_NO_LICENSE_SERVER);
440 EVCASE(STATUS_VALID_CLIENT);
441 EVCASE(ERR_INVALID_CLIENT);
442 EVCASE(ERR_INVALID_PRODUCT_ID);
443 EVCASE(ERR_INVALID_MESSAGE_LENGTH);
444 default:
445 return "ERR_UNKNOWN";
446 }
447}
448
449WINPR_ATTR_NODISCARD
450static const char* state_transitions(UINT32 idx)
451{
452#define EVCASE(x) \
453 case x: \
454 return #x
455
456 switch (idx)
457 {
458 EVCASE(ST_TOTAL_ABORT);
459 EVCASE(ST_NO_TRANSITION);
460 EVCASE(ST_RESET_PHASE_TO_START);
461 EVCASE(ST_RESEND_LAST_MESSAGE);
462 default:
463 return "ST_UNKNOWN";
464 }
465}
466
467static void license_print_product_info(wLog* log, const LICENSE_PRODUCT_INFO* productInfo)
468{
469 char* CompanyName = nullptr;
470 char* ProductId = nullptr;
471
472 WINPR_ASSERT(productInfo);
473 WINPR_ASSERT(productInfo->pbCompanyName);
474 WINPR_ASSERT(productInfo->pbProductId);
475
476 CompanyName =
477 ConvertWCharNToUtf8Alloc(WINPR_PACKED_ALIGN_CAST(const WCHAR*, productInfo->pbCompanyName),
478 productInfo->cbCompanyName / sizeof(WCHAR), nullptr);
479 ProductId =
480 ConvertWCharNToUtf8Alloc(WINPR_PACKED_ALIGN_CAST(const WCHAR*, productInfo->pbProductId),
481 productInfo->cbProductId / sizeof(WCHAR), nullptr);
482 WLog_Print(log, WLOG_INFO, "ProductInfo:");
483 WLog_Print(log, WLOG_INFO, "\tdwVersion: 0x%08" PRIX32 "", productInfo->dwVersion);
484 WLog_Print(log, WLOG_INFO, "\tCompanyName: %s", CompanyName);
485 WLog_Print(log, WLOG_INFO, "\tProductId: %s", ProductId);
486 free(CompanyName);
487 free(ProductId);
488}
489
490static void license_print_scope_list(wLog* log, const SCOPE_LIST* scopeList)
491{
492 WINPR_ASSERT(scopeList);
493
494 WLog_Print(log, WLOG_INFO, "ScopeList (%" PRIu32 "):", scopeList->count);
495
496 for (UINT32 index = 0; index < scopeList->count; index++)
497 {
498 WINPR_ASSERT(scopeList->array);
499 const LICENSE_BLOB* scope = scopeList->array[index];
500 WINPR_ASSERT(scope);
501
502 WLog_Print(log, WLOG_INFO, "\t%.*s", (int)scope->length, (const char*)scope->data);
503 }
504}
505#endif
506
507static const char licenseStore[] = "licenses";
508
509WINPR_ATTR_NODISCARD
510static BOOL license_ensure_state(rdpLicense* license, LICENSE_STATE state, UINT32 msg)
511{
512 const LICENSE_STATE cstate = license_get_state(license);
513
514 WINPR_ASSERT(license);
515
516 if (cstate != state)
517 {
518 const char* scstate = license_get_state_string(cstate);
519 const char* sstate = license_get_state_string(state);
520 const char* where = license_request_type_string(msg);
521
522 WLog_Print(license->log, WLOG_WARN,
523 "Received [%s], but found invalid licensing state %s, expected %s", where,
524 scstate, sstate);
525 return FALSE;
526 }
527 return TRUE;
528}
529
530state_run_t license_recv(rdpLicense* license, wStream* s)
531{
532 WINPR_ASSERT(license);
533 WINPR_ASSERT(license->rdp);
534 WINPR_ASSERT(license->rdp->settings);
535
536 if (freerdp_settings_get_bool(license->rdp->settings, FreeRDP_ServerMode))
537 return license_server_recv(license, s);
538 else
539 return license_client_recv(license, s);
540}
541
542WINPR_ATTR_NODISCARD
543static BOOL license_check_stream_length(wLog* log, wStream* s, UINT64 expect, const char* where,
544 UINT64 limit)
545{
546 const size_t remain = Stream_GetRemainingLength(s);
547
548 WINPR_ASSERT(where);
549
550 if (remain < expect)
551 {
552 WLog_Print(log, WLOG_WARN, "short %s, expected %" PRIu64 " bytes, got %" PRIuz, where,
553 expect, remain);
554 return FALSE;
555 }
556 if ((limit > 0) && (remain > limit))
557 {
558 WLog_Print(log, WLOG_WARN,
559 "oversized %s, got %" PRIuz " bytes, but size is limited to %" PRIu64 ".", where,
560 remain, limit);
561 return FALSE;
562 }
563 return TRUE;
564}
565
566WINPR_ATTR_NODISCARD
567static BOOL license_check_stream_capacity(wLog* log, wStream* s, size_t expect, const char* where)
568{
569 WINPR_ASSERT(where);
570
571 return (Stream_CheckAndLogRequiredCapacityWLogEx(log, WLOG_WARN, s, expect, 1,
572 "%s(%s:%" PRIuz ") %s", __func__, __FILE__,
573 (size_t)__LINE__, where));
574}
575
576WINPR_ATTR_NODISCARD
577static BOOL computeCalHash(wLog* log, const char* hostname, char* hashStr, size_t len)
578{
579 WINPR_DIGEST_CTX* sha1 = nullptr;
580 BOOL ret = FALSE;
581 BYTE hash[20] = WINPR_C_ARRAY_INIT;
582
583 WINPR_ASSERT(hostname);
584 WINPR_ASSERT(hashStr);
585
586 if (len < 2 * sizeof(hash) + 1)
587 return FALSE;
588
589 if (!(sha1 = winpr_Digest_New()))
590 goto out;
591 if (!winpr_Digest_Init(sha1, WINPR_MD_SHA1))
592 goto out;
593 if (!winpr_Digest_Update(sha1, (const BYTE*)hostname, strlen(hostname)))
594 goto out;
595 if (!winpr_Digest_Final(sha1, hash, sizeof(hash)))
596 goto out;
597
598 for (size_t i = 0; i < sizeof(hash); i++, hashStr += 2)
599 (void)sprintf_s(hashStr, 3, "%.2x", hash[i]);
600
601 ret = TRUE;
602out:
603 if (!ret)
604 WLog_Print(log, WLOG_ERROR, "failed to generate SHA1 of hostname '%s'", hostname);
605 winpr_Digest_Free(sha1);
606 return ret;
607}
608
609WINPR_ATTR_NODISCARD
610static BOOL saveCal(wLog* log, const rdpSettings* settings, const BYTE* data, size_t length,
611 const char* hostname)
612{
613 char hash[41] = WINPR_C_ARRAY_INIT;
614 FILE* fp = nullptr;
615 char* licenseStorePath = nullptr;
616 char filename[MAX_PATH] = WINPR_C_ARRAY_INIT;
617 char filenameNew[MAX_PATH] = WINPR_C_ARRAY_INIT;
618 char* filepath = nullptr;
619 char* filepathNew = nullptr;
620
621 size_t written = 0;
622 BOOL ret = FALSE;
623 const char* path = freerdp_settings_get_string(settings, FreeRDP_ConfigPath);
624
625 WINPR_ASSERT(path);
626 WINPR_ASSERT(data || (length == 0));
627 WINPR_ASSERT(hostname);
628
629 if (!winpr_PathFileExists(path))
630 {
631 if (!winpr_PathMakePath(path, nullptr))
632 {
633 WLog_Print(log, WLOG_ERROR, "error creating directory '%s'", path);
634 goto out;
635 }
636 WLog_Print(log, WLOG_INFO, "creating directory %s", path);
637 }
638
639 if (!(licenseStorePath = GetCombinedPath(path, licenseStore)))
640 {
641 WLog_Print(log, WLOG_ERROR, "Failed to get license store path from '%s' + '%s'", path,
642 licenseStore);
643 goto out;
644 }
645
646 if (!winpr_PathFileExists(licenseStorePath))
647 {
648 if (!winpr_PathMakePath(licenseStorePath, nullptr))
649 {
650 WLog_Print(log, WLOG_ERROR, "error creating directory '%s'", licenseStorePath);
651 goto out;
652 }
653 WLog_Print(log, WLOG_INFO, "creating directory %s", licenseStorePath);
654 }
655
656 if (!computeCalHash(log, hostname, hash, sizeof(hash)))
657 goto out;
658 (void)sprintf_s(filename, sizeof(filename) - 1, "%s.cal", hash);
659 (void)sprintf_s(filenameNew, sizeof(filenameNew) - 1, "%s.cal.new", hash);
660
661 if (!(filepath = GetCombinedPath(licenseStorePath, filename)))
662 {
663 WLog_Print(log, WLOG_ERROR, "Failed to get license file path from '%s' + '%s'", path,
664 filename);
665 goto out;
666 }
667
668 if (!(filepathNew = GetCombinedPath(licenseStorePath, filenameNew)))
669 {
670 WLog_Print(log, WLOG_ERROR, "Failed to get license new file path from '%s' + '%s'", path,
671 filenameNew);
672 goto out;
673 }
674
675 fp = winpr_fopen(filepathNew, "wb");
676 if (!fp)
677 {
678 WLog_Print(log, WLOG_ERROR, "Failed to open license file '%s'", filepathNew);
679 goto out;
680 }
681
682 written = fwrite(data, length, 1, fp);
683 (void)fclose(fp);
684
685 if (written != 1)
686 {
687 WLog_Print(log, WLOG_ERROR, "Failed to write to license file '%s'", filepathNew);
688 winpr_DeleteFile(filepathNew);
689 goto out;
690 }
691
692 ret = winpr_MoveFileEx(filepathNew, filepath, MOVEFILE_REPLACE_EXISTING);
693 if (!ret)
694 WLog_Print(log, WLOG_ERROR, "Failed to move license file '%s' to '%s'", filepathNew,
695 filepath);
696
697out:
698 free(filepathNew);
699 free(filepath);
700 free(licenseStorePath);
701 return ret;
702}
703
704WINPR_ATTR_MALLOC(free, 1)
705static BYTE* loadCalFile(wLog* log, const rdpSettings* settings, const char* hostname,
706 size_t* dataLen)
707{
708 char* licenseStorePath = nullptr;
709 char calFilename[MAX_PATH] = WINPR_C_ARRAY_INIT;
710 char hash[41] = WINPR_C_ARRAY_INIT;
711 INT64 length = 0;
712 size_t status = 0;
713 FILE* fp = nullptr;
714 BYTE* ret = nullptr;
715
716 WINPR_ASSERT(settings);
717 WINPR_ASSERT(hostname);
718 WINPR_ASSERT(dataLen);
719
720 if (!computeCalHash(log, hostname, hash, sizeof(hash)))
721 {
722 WLog_Print(log, WLOG_ERROR, "%s: unable to compute hostname hash", __func__);
723 return nullptr;
724 }
725
726 (void)sprintf_s(calFilename, sizeof(calFilename) - 1, "%s.cal", hash);
727
728 if (!(licenseStorePath = GetCombinedPath(
729 freerdp_settings_get_string(settings, FreeRDP_ConfigPath), licenseStore)))
730 return nullptr;
731
732 char* calPath = GetCombinedPath(licenseStorePath, calFilename);
733 if (!calPath)
734 goto fail;
735
736 fp = winpr_fopen(calPath, "rb");
737 if (!fp)
738 goto fail;
739
740 if (_fseeki64(fp, 0, SEEK_END) != 0)
741 goto fail;
742 length = _ftelli64(fp);
743 if (_fseeki64(fp, 0, SEEK_SET) != 0)
744 goto fail;
745 if (length < 0)
746 goto fail;
747
748 if ((UINT64)length > LICENSE_MAX_CAL_LENGTH)
749 {
750 WLog_Print(log, WLOG_ERROR,
751 "%s: the file size %" PRId64 " exceeds the CAL size limit of %llu", __func__,
752 length, LICENSE_MAX_CAL_LENGTH);
753 goto fail;
754 }
755
756 ret = (BYTE*)malloc((size_t)length);
757 if (!ret)
758 goto fail;
759
760 status = fread(ret, (size_t)length, 1, fp);
761 if (status == 0)
762 goto fail;
763
764 *dataLen = (size_t)length;
765
766 (void)fclose(fp);
767 free(calPath);
768 free(licenseStorePath);
769 return ret;
770
771fail:
772 free(ret);
773 if (fp)
774 (void)fclose(fp);
775 free(calPath);
776 free(licenseStorePath);
777 return nullptr;
778}
779
789WINPR_ATTR_NODISCARD
790static BOOL license_read_preamble(wLog* log, wStream* s, BYTE* bMsgType, BYTE* flags,
791 UINT16* wMsgSize)
792{
793 WINPR_ASSERT(bMsgType);
794 WINPR_ASSERT(flags);
795 WINPR_ASSERT(wMsgSize);
796
797 /* preamble (4 bytes) */
798 if (!license_check_stream_length(log, s, 4, "license preamble", 0))
799 return FALSE;
800
801 Stream_Read_UINT8(s, *bMsgType); /* bMsgType (1 byte) */
802 Stream_Read_UINT8(s, *flags); /* flags (1 byte) */
803 Stream_Read_UINT16(s, *wMsgSize); /* wMsgSize (2 bytes) */
804 if (*wMsgSize < 4)
805 {
806 WLog_Print(log, WLOG_WARN,
807 "invalid license preamble::wMsgSize, expected value >= 4, got %" PRIu32,
808 *wMsgSize);
809 return FALSE;
810 }
811 return license_check_stream_length(log, s, *wMsgSize - 4ull, "license preamble::wMsgSize", 0);
812}
813
823WINPR_ATTR_NODISCARD
824static BOOL license_write_preamble(wStream* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSize)
825{
826 if (!Stream_EnsureRemainingCapacity(s, 4))
827 return FALSE;
828
829 /* preamble (4 bytes) */
830 Stream_Write_UINT8(s, bMsgType); /* bMsgType (1 byte) */
831 Stream_Write_UINT8(s, flags); /* flags (1 byte) */
832 Stream_Write_UINT16(s, wMsgSize); /* wMsgSize (2 bytes) */
833 return TRUE;
834}
835
844wStream* license_send_stream_init(rdpLicense* license, UINT16* sec_flags)
845{
846 WINPR_ASSERT(license);
847 WINPR_ASSERT(license->rdp);
848 WINPR_ASSERT(sec_flags);
849
850 const BOOL do_crypt = license->rdp->do_crypt;
851
852 *sec_flags = SEC_LICENSE_PKT;
853
854 /*
855 * Encryption of licensing packets is optional even if the rdp security
856 * layer is used. If the peer has not indicated that it is capable of
857 * processing encrypted licensing packets (rdp->do_crypt_license) we turn
858 * off encryption (via rdp->do_crypt) before initializing the rdp stream
859 * and re-enable it afterwards.
860 */
861
862 if (do_crypt)
863 {
864 *sec_flags |= SEC_LICENSE_ENCRYPT_CS;
865 license->rdp->do_crypt = license->rdp->do_crypt_license;
866 }
867
868 wStream* s = rdp_send_stream_init(license->rdp, sec_flags);
869 if (!s)
870 return nullptr;
871
872 license->rdp->do_crypt = do_crypt;
873 license->PacketHeaderLength = (UINT16)Stream_GetPosition(s);
874 if (!Stream_SafeZero(s, LICENSE_PREAMBLE_LENGTH))
875 goto fail;
876 return s;
877
878fail:
879 Stream_Release(s);
880 return nullptr;
881}
882
889WINPR_ATTR_NODISCARD
890static BOOL license_send(rdpLicense* license, wStream* s, BYTE type, UINT16 sec_flags)
891{
892 WINPR_ASSERT(license);
893 WINPR_ASSERT(license->rdp);
894
895 rdpRdp* rdp = license->rdp;
896 WINPR_ASSERT(rdp->settings);
897
898 DEBUG_LICENSE("Sending %s Packet", license_request_type_string(type));
899 const size_t length = Stream_GetPosition(s);
900 WINPR_ASSERT(length >= license->PacketHeaderLength);
901 WINPR_ASSERT(length <= UINT16_MAX + license->PacketHeaderLength);
902
903 const UINT16 wMsgSize = (UINT16)(length - license->PacketHeaderLength);
904 if (!Stream_SetPosition(s, license->PacketHeaderLength))
905 return FALSE;
906 BYTE flags = PREAMBLE_VERSION_3_0;
907
913 if (!rdp->settings->ServerMode)
914 flags |= EXTENDED_ERROR_MSG_SUPPORTED;
915
916 if (!license_write_preamble(s, type, flags, wMsgSize))
917 {
918 Stream_Release(s);
919 return FALSE;
920 }
921
922#ifdef WITH_DEBUG_LICENSE
923 WLog_Print(license->log, WLOG_DEBUG, "Sending %s Packet, length %" PRIu16 "",
924 license_request_type_string(type), wMsgSize);
925 winpr_HexLogDump(license->log, WLOG_DEBUG, Stream_PointerAs(s, char) - LICENSE_PREAMBLE_LENGTH,
926 wMsgSize);
927#endif
928 if (!Stream_SetPosition(s, length))
929 return FALSE;
930 const BOOL ret = rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID, sec_flags);
931 return ret;
932}
933
934BOOL license_write_server_upgrade_license(const rdpLicense* license, wStream* s)
935{
936 WINPR_ASSERT(license);
937
938 if (!license_write_binary_blob(s, license->EncryptedLicenseInfo))
939 return FALSE;
940 if (!license_check_stream_capacity(license->log, s, sizeof(license->MACData),
941 "SERVER_UPGRADE_LICENSE::MACData"))
942 return FALSE;
943 Stream_Write(s, license->MACData, sizeof(license->MACData));
944 return TRUE;
945}
946
947WINPR_ATTR_NODISCARD
948static BOOL license_server_send_new_or_upgrade_license(rdpLicense* license, BOOL upgrade)
949{
950 UINT16 sec_flags = 0;
951 wStream* s = license_send_stream_init(license, &sec_flags);
952 const BYTE type = upgrade ? UPGRADE_LICENSE : NEW_LICENSE;
953
954 if (!s)
955 return FALSE;
956
957 if (!license_write_server_upgrade_license(license, s))
958 goto fail;
959
960 return license_send(license, s, type, sec_flags);
961
962fail:
963 Stream_Release(s);
964 return FALSE;
965}
966
974WINPR_ATTR_NODISCARD
975static state_run_t license_client_recv_int(rdpLicense* license, wStream* s)
976{
977 BYTE flags = 0;
978 BYTE bMsgType = 0;
979 UINT16 wMsgSize = 0;
980 const size_t length = Stream_GetRemainingLength(s);
981
982 WINPR_ASSERT(license);
983
984 if (!license_read_preamble(license->log, s, &bMsgType, &flags,
985 &wMsgSize)) /* preamble (4 bytes) */
986 return STATE_RUN_FAILED;
987
988 DEBUG_LICENSE("Receiving %s Packet", license_request_type_string(bMsgType));
989
990 switch (bMsgType)
991 {
992 case LICENSE_REQUEST:
993 /* Client does not require configuration, so skip this state */
994 if (license_get_state(license) == LICENSE_STATE_INITIAL)
995 license_set_state(license, LICENSE_STATE_CONFIGURED);
996
997 if (!license_ensure_state(license, LICENSE_STATE_CONFIGURED, bMsgType))
998 return STATE_RUN_FAILED;
999
1000 if (!license_read_license_request_packet(license, s))
1001 return STATE_RUN_FAILED;
1002
1003 if (!license_answer_license_request(license))
1004 return STATE_RUN_FAILED;
1005
1006 license_set_state(license, LICENSE_STATE_NEW_REQUEST);
1007 break;
1008
1009 case PLATFORM_CHALLENGE:
1010 if (!license_ensure_state(license, LICENSE_STATE_NEW_REQUEST, bMsgType))
1011 return STATE_RUN_FAILED;
1012
1013 if (!license_read_platform_challenge_packet(license, s))
1014 return STATE_RUN_FAILED;
1015
1016 if (!license_send_platform_challenge_response(license))
1017 return STATE_RUN_FAILED;
1018 license_set_state(license, LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE);
1019 break;
1020
1021 case NEW_LICENSE:
1022 case UPGRADE_LICENSE:
1023 if (!license_ensure_state(license, LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE, bMsgType))
1024 return STATE_RUN_FAILED;
1025 if (!license_read_new_or_upgrade_license_packet(license, s))
1026 return STATE_RUN_FAILED;
1027 break;
1028
1029 case ERROR_ALERT:
1030 if (!license_read_error_alert_packet(license, s))
1031 return STATE_RUN_FAILED;
1032 break;
1033
1034 default:
1035 WLog_Print(license->log, WLOG_ERROR, "invalid bMsgType:%" PRIu8 "", bMsgType);
1036 return STATE_RUN_FAILED;
1037 }
1038
1039 if (!tpkt_ensure_stream_consumed(license->log, s, length))
1040 return STATE_RUN_FAILED;
1041 return STATE_RUN_SUCCESS;
1042}
1043
1044state_run_t license_client_recv(rdpLicense* license, wStream* s)
1045{
1046 state_run_t rc = license_client_recv_int(license, s);
1047 if (state_run_failed(rc))
1048 {
1049 freerdp_set_last_error(license->rdp->context, ERROR_CTX_LICENSE_CLIENT_INVALID);
1050 }
1051 return rc;
1052}
1053
1054state_run_t license_server_recv(rdpLicense* license, wStream* s)
1055{
1056 state_run_t rc = STATE_RUN_FAILED;
1057 BYTE flags = 0;
1058 BYTE bMsgType = 0;
1059 UINT16 wMsgSize = 0;
1060 const size_t length = Stream_GetRemainingLength(s);
1061
1062 WINPR_ASSERT(license);
1063
1064 if (!license_read_preamble(license->log, s, &bMsgType, &flags,
1065 &wMsgSize)) /* preamble (4 bytes) */
1066 goto fail;
1067
1068 DEBUG_LICENSE("Receiving %s Packet", license_request_type_string(bMsgType));
1069
1070 switch (bMsgType)
1071 {
1072 case NEW_LICENSE_REQUEST:
1073 if (!license_ensure_state(license, LICENSE_STATE_REQUEST, bMsgType))
1074 goto fail;
1075 if (!license_read_new_license_request_packet(license, s))
1076 goto fail;
1077 // TODO: Validate if client is allowed
1078 if (!license_send_error_alert(license, ERR_INVALID_MAC, ST_TOTAL_ABORT,
1079 license->ErrorInfo))
1080 goto fail;
1081 if (!license_send_platform_challenge_packet(license))
1082 goto fail;
1083 license->update = FALSE;
1084 license_set_state(license, LICENSE_STATE_PLATFORM_CHALLENGE);
1085 break;
1086 case LICENSE_INFO:
1087 if (!license_ensure_state(license, LICENSE_STATE_REQUEST, bMsgType))
1088 goto fail;
1089 if (!license_read_license_info(license, s))
1090 goto fail;
1091 // TODO: Validate license info
1092 if (!license_send_platform_challenge_packet(license))
1093 goto fail;
1094 license_set_state(license, LICENSE_STATE_PLATFORM_CHALLENGE);
1095 license->update = TRUE;
1096 break;
1097
1098 case PLATFORM_CHALLENGE_RESPONSE:
1099 if (!license_ensure_state(license, LICENSE_STATE_PLATFORM_CHALLENGE, bMsgType))
1100 goto fail;
1101 if (!license_read_client_platform_challenge_response(license, s))
1102 goto fail;
1103
1104 // TODO: validate challenge response
1105 if (FALSE)
1106 {
1107 if (license_send_error_alert(license, ERR_INVALID_CLIENT, ST_TOTAL_ABORT,
1108 license->ErrorInfo))
1109 goto fail;
1110 }
1111 else
1112 {
1113 if (!license_server_send_new_or_upgrade_license(license, license->update))
1114 goto fail;
1115
1116 license->type = LICENSE_TYPE_ISSUED;
1117 license_set_state(license, LICENSE_STATE_COMPLETED);
1118
1119 rc = STATE_RUN_CONTINUE; /* License issued, switch state */
1120 }
1121 break;
1122
1123 case ERROR_ALERT:
1124 if (!license_read_error_alert_packet(license, s))
1125 goto fail;
1126 break;
1127
1128 default:
1129 WLog_Print(license->log, WLOG_ERROR, "invalid bMsgType:%" PRIu8 "", bMsgType);
1130 goto fail;
1131 }
1132
1133 if (!tpkt_ensure_stream_consumed(license->log, s, length))
1134 goto fail;
1135
1136 if (!state_run_success(rc))
1137 rc = STATE_RUN_SUCCESS;
1138
1139fail:
1140 if (state_run_failed(rc))
1141 {
1142 if (flags & EXTENDED_ERROR_MSG_SUPPORTED)
1143 {
1144 if (!license_send_error_alert(license, ERR_INVALID_CLIENT, ST_TOTAL_ABORT, nullptr))
1145 {
1146 WLog_Print(license->log, WLOG_ERROR, "license_send_error_alert failed");
1147 }
1148 }
1149 license_set_state(license, LICENSE_STATE_ABORTED);
1150 }
1151
1152 return rc;
1153}
1154
1155BOOL license_generate_randoms(rdpLicense* license)
1156{
1157 WINPR_ASSERT(license);
1158
1159#ifdef LICENSE_NULL_CLIENT_RANDOM
1160 ZeroMemory(license->ClientRandom, sizeof(license->ClientRandom)); /* ClientRandom */
1161#else
1162 if (winpr_RAND(license->ClientRandom, sizeof(license->ClientRandom)) < 0) /* ClientRandom */
1163 return FALSE;
1164#endif
1165
1166 if (winpr_RAND(license->ServerRandom, sizeof(license->ServerRandom)) < 0) /* ServerRandom */
1167 return FALSE;
1168
1169#ifdef LICENSE_NULL_PREMASTER_SECRET
1170 ZeroMemory(license->PremasterSecret, sizeof(license->PremasterSecret)); /* PremasterSecret */
1171#else
1172 if (winpr_RAND(license->PremasterSecret, sizeof(license->PremasterSecret)) <
1173 0) /* PremasterSecret */
1174 return FALSE;
1175#endif
1176 return TRUE;
1177}
1178
1183WINPR_ATTR_NODISCARD
1184static BOOL license_generate_keys(rdpLicense* license)
1185{
1186 WINPR_ASSERT(license);
1187
1188 if (
1189 /* MasterSecret */
1190 !security_master_secret(license->PremasterSecret, sizeof(license->PremasterSecret),
1191 license->ClientRandom, sizeof(license->ClientRandom),
1192 license->ServerRandom, sizeof(license->ServerRandom),
1193 license->MasterSecret, sizeof(license->MasterSecret)) ||
1194 /* SessionKeyBlob */
1195 !security_session_key_blob(license->MasterSecret, sizeof(license->MasterSecret),
1196 license->ClientRandom, sizeof(license->ClientRandom),
1197 license->ServerRandom, sizeof(license->ServerRandom),
1198 license->SessionKeyBlob, sizeof(license->SessionKeyBlob)))
1199 {
1200 return FALSE;
1201 }
1202 security_mac_salt_key(license->SessionKeyBlob, sizeof(license->SessionKeyBlob),
1203 license->ClientRandom, sizeof(license->ClientRandom),
1204 license->ServerRandom, sizeof(license->ServerRandom), license->MacSaltKey,
1205 sizeof(license->MacSaltKey)); /* MacSaltKey */
1206 const BOOL ret = security_licensing_encryption_key(
1207 license->SessionKeyBlob, sizeof(license->SessionKeyBlob), license->ClientRandom,
1208 sizeof(license->ClientRandom), license->ServerRandom, sizeof(license->ServerRandom),
1209 license->LicensingEncryptionKey,
1210 sizeof(license->LicensingEncryptionKey)); /* LicensingEncryptionKey */
1211
1212 WLog_Print(license->log, WLOG_TRACE, "license keys %s generated", ret ? "successfully" : "NOT");
1213
1214#ifdef WITH_DEBUG_LICENSE
1215 WLog_Print(license->log, WLOG_DEBUG, "ClientRandom:");
1216 winpr_HexLogDump(license->log, WLOG_DEBUG, license->ClientRandom,
1217 sizeof(license->ClientRandom));
1218 WLog_Print(license->log, WLOG_DEBUG, "ServerRandom:");
1219 winpr_HexLogDump(license->log, WLOG_DEBUG, license->ServerRandom,
1220 sizeof(license->ServerRandom));
1221 WLog_Print(license->log, WLOG_DEBUG, "PremasterSecret:");
1222 winpr_HexLogDump(license->log, WLOG_DEBUG, license->PremasterSecret,
1223 sizeof(license->PremasterSecret));
1224 WLog_Print(license->log, WLOG_DEBUG, "MasterSecret:");
1225 winpr_HexLogDump(license->log, WLOG_DEBUG, license->MasterSecret,
1226 sizeof(license->MasterSecret));
1227 WLog_Print(license->log, WLOG_DEBUG, "SessionKeyBlob:");
1228 winpr_HexLogDump(license->log, WLOG_DEBUG, license->SessionKeyBlob,
1229 sizeof(license->SessionKeyBlob));
1230 WLog_Print(license->log, WLOG_DEBUG, "MacSaltKey:");
1231 winpr_HexLogDump(license->log, WLOG_DEBUG, license->MacSaltKey, sizeof(license->MacSaltKey));
1232 WLog_Print(license->log, WLOG_DEBUG, "LicensingEncryptionKey:");
1233 winpr_HexLogDump(license->log, WLOG_DEBUG, license->LicensingEncryptionKey,
1234 sizeof(license->LicensingEncryptionKey));
1235#endif
1236 return ret;
1237}
1238
1244BOOL license_generate_hwid(rdpLicense* license)
1245{
1246 const BYTE* hashTarget = nullptr;
1247 size_t targetLen = 0;
1248 BYTE macAddress[6] = WINPR_C_ARRAY_INIT;
1249
1250 WINPR_ASSERT(license);
1251 WINPR_ASSERT(license->rdp);
1252 WINPR_ASSERT(license->rdp->settings);
1253
1254 ZeroMemory(license->HardwareId, sizeof(license->HardwareId));
1255
1256 if (license->rdp->settings->OldLicenseBehaviour)
1257 {
1258 hashTarget = macAddress;
1259 targetLen = sizeof(macAddress);
1260 }
1261 else
1262 {
1263 wStream buffer = WINPR_C_ARRAY_INIT;
1264 const char* hostname = license->rdp->settings->ClientHostname;
1265 wStream* s = Stream_StaticInit(&buffer, license->HardwareId, 4);
1266 Stream_Write_UINT32(s, license->PlatformId);
1267
1268 hashTarget = (const BYTE*)hostname;
1269 targetLen = hostname ? strlen(hostname) : 0;
1270 }
1271
1272 /* Allow FIPS override for use of MD5 here, really this does not have to be MD5 as we are just
1273 * taking a MD5 hash of the 6 bytes of 0's(macAddress) */
1274 /* and filling in the Data1-Data4 fields of the CLIENT_HARDWARE_ID structure(from MS-RDPELE
1275 * section 2.2.2.3.1). This is for RDP licensing packets */
1276 /* which will already be encrypted under FIPS, so the use of MD5 here is not for sensitive data
1277 * protection. */
1278 return winpr_Digest_Allow_FIPS(WINPR_MD_MD5, hashTarget, targetLen,
1279 &license->HardwareId[HWID_PLATFORM_ID_LENGTH],
1280 WINPR_MD5_DIGEST_LENGTH);
1281}
1282
1283WINPR_ATTR_NODISCARD
1284static BOOL license_get_server_rsa_public_key(rdpLicense* license)
1285{
1286 rdpSettings* settings = nullptr;
1287
1288 WINPR_ASSERT(license);
1289 WINPR_ASSERT(license->certificate);
1290 WINPR_ASSERT(license->rdp);
1291
1292 settings = license->rdp->settings;
1293 WINPR_ASSERT(settings);
1294
1295 if (license->ServerCertificate->length < 1)
1296 {
1297 if (!freerdp_certificate_read_server_cert(license->certificate, settings->ServerCertificate,
1298 settings->ServerCertificateLength))
1299 return FALSE;
1300 }
1301
1302 return TRUE;
1303}
1304
1305BOOL license_encrypt_premaster_secret(rdpLicense* license)
1306{
1307 WINPR_ASSERT(license);
1308 WINPR_ASSERT(license->certificate);
1309
1310 if (!license_get_server_rsa_public_key(license))
1311 return FALSE;
1312
1313 WINPR_ASSERT(license->EncryptedPremasterSecret);
1314
1315 const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
1316 if (!info)
1317 {
1318 WLog_Print(license->log, WLOG_ERROR, "info=%p, license->certificate=%p", (const void*)info,
1319 (void*)license->certificate);
1320 return FALSE;
1321 }
1322
1323#ifdef WITH_DEBUG_LICENSE
1324 WLog_Print(license->log, WLOG_DEBUG, "Modulus (%" PRIu32 " bits):", info->ModulusLength * 8);
1325 winpr_HexLogDump(license->log, WLOG_DEBUG, info->Modulus, info->ModulusLength);
1326 WLog_Print(license->log, WLOG_DEBUG, "Exponent:");
1327 winpr_HexLogDump(license->log, WLOG_DEBUG, info->exponent, sizeof(info->exponent));
1328#endif
1329
1330 BYTE* EncryptedPremasterSecret = (BYTE*)calloc(1, info->ModulusLength);
1331 if (!EncryptedPremasterSecret)
1332 {
1333 WLog_Print(license->log, WLOG_ERROR,
1334 "EncryptedPremasterSecret=%p, info->ModulusLength=%" PRIu32,
1335 (const void*)EncryptedPremasterSecret, info->ModulusLength);
1336 return FALSE;
1337 }
1338
1339 license->EncryptedPremasterSecret->type = BB_RANDOM_BLOB;
1340 license->EncryptedPremasterSecret->length = sizeof(license->PremasterSecret);
1341#ifndef LICENSE_NULL_PREMASTER_SECRET
1342 {
1343 const SSIZE_T length =
1344 crypto_rsa_public_encrypt(license->PremasterSecret, sizeof(license->PremasterSecret),
1345 info, EncryptedPremasterSecret, info->ModulusLength);
1346 if ((length < 0) || (length > UINT16_MAX))
1347 {
1348 WLog_Print(license->log, WLOG_ERROR, "RSA public encrypt length=%" PRIdz " < 0 || > %d",
1349 length, UINT16_MAX);
1350 return FALSE;
1351 }
1352 license->EncryptedPremasterSecret->length = (UINT16)length;
1353 }
1354#endif
1355 license->EncryptedPremasterSecret->data = EncryptedPremasterSecret;
1356 return TRUE;
1357}
1358
1359WINPR_ATTR_NODISCARD
1360static BOOL license_rc4_with_licenseKey(const rdpLicense* license, const BYTE* input, size_t len,
1361 LICENSE_BLOB* target)
1362{
1363 WINPR_ASSERT(license);
1364 WINPR_ASSERT(input || (len == 0));
1365 WINPR_ASSERT(target);
1366 WINPR_ASSERT(len <= UINT16_MAX);
1367
1368 WINPR_RC4_CTX* rc4 = winpr_RC4_New_Allow_FIPS(license->LicensingEncryptionKey,
1369 sizeof(license->LicensingEncryptionKey));
1370 if (!rc4)
1371 {
1372 WLog_Print(license->log, WLOG_ERROR, "Failed to allocate RC4");
1373 return FALSE;
1374 }
1375
1376 BYTE* buffer = nullptr;
1377 if (len > 0)
1378 buffer = realloc(target->data, len);
1379 if (!buffer)
1380 goto error_buffer;
1381
1382 target->data = buffer;
1383 target->length = (UINT16)len;
1384
1385 if (!winpr_RC4_Update(rc4, len, input, buffer))
1386 goto error_buffer;
1387
1388 winpr_RC4_Free(rc4);
1389 return TRUE;
1390
1391error_buffer:
1392 WLog_Print(license->log, WLOG_ERROR, "Failed to create/update RC4: len=%" PRIuz ", buffer=%p",
1393 len, (const void*)buffer);
1394 winpr_RC4_Free(rc4);
1395 return FALSE;
1396}
1397
1409WINPR_ATTR_NODISCARD
1410static BOOL license_encrypt_and_MAC(rdpLicense* license, const BYTE* input, size_t len,
1411 LICENSE_BLOB* target, BYTE* mac, size_t mac_length)
1412{
1413 WINPR_ASSERT(license);
1414 return license_rc4_with_licenseKey(license, input, len, target) &&
1415 security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), input, len, mac,
1416 mac_length);
1417}
1418
1430WINPR_ATTR_NODISCARD
1431static BOOL license_decrypt_and_check_MAC(rdpLicense* license, const BYTE* input, size_t len,
1432 LICENSE_BLOB* target, const BYTE* packetMac)
1433{
1434 BYTE macData[sizeof(license->MACData)] = WINPR_C_ARRAY_INIT;
1435
1436 WINPR_ASSERT(license);
1437 WINPR_ASSERT(target);
1438
1439 if (freerdp_settings_get_bool(license->rdp->settings, FreeRDP_TransportDumpReplay))
1440 {
1441 WLog_Print(license->log, WLOG_DEBUG, "TransportDumpReplay active, skipping...");
1442 return TRUE;
1443 }
1444
1445 if (!license_rc4_with_licenseKey(license, input, len, target))
1446 return FALSE;
1447
1448 if (!security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), target->data, len,
1449 macData, sizeof(macData)))
1450 return FALSE;
1451
1452 if (memcmp(packetMac, macData, sizeof(macData)) != 0)
1453 {
1454 WLog_Print(license->log, WLOG_ERROR, "packetMac != expectedMac");
1455 return FALSE;
1456 }
1457 return TRUE;
1458}
1459
1467BOOL license_read_product_info(wLog* log, wStream* s, LICENSE_PRODUCT_INFO* productInfo)
1468{
1469 WINPR_ASSERT(productInfo);
1470
1471 if (!license_check_stream_length(log, s, 8, "license product info::cbCompanyName", 0))
1472 return FALSE;
1473
1474 Stream_Read_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
1475 Stream_Read_UINT32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */
1476
1477 /* Name must be >0, but there is no upper limit defined, use UINT32_MAX */
1478 if ((productInfo->cbCompanyName < 2) || (productInfo->cbCompanyName % 2 != 0))
1479 {
1480 WLog_Print(log, WLOG_WARN, "license product info invalid cbCompanyName %" PRIu32,
1481 productInfo->cbCompanyName);
1482 return FALSE;
1483 }
1484
1485 if (!license_check_stream_length(log, s, productInfo->cbCompanyName,
1486 "license product info::CompanyName",
1487 LICENSE_MAX_COMPANY_NAME_LENGTH))
1488 return FALSE;
1489
1490 productInfo->pbProductId = nullptr;
1491 productInfo->pbCompanyName = (BYTE*)malloc(productInfo->cbCompanyName);
1492 if (!productInfo->pbCompanyName)
1493 goto out_fail;
1494 Stream_Read(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
1495
1496 if (!license_check_stream_length(log, s, 4, "license product info::cbProductId", 0))
1497 goto out_fail;
1498
1499 Stream_Read_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
1500
1501 if ((productInfo->cbProductId < 2) || (productInfo->cbProductId % 2 != 0))
1502 {
1503 WLog_Print(log, WLOG_WARN, "license product info invalid cbProductId %" PRIu32,
1504 productInfo->cbProductId);
1505 goto out_fail;
1506 }
1507
1508 if (!license_check_stream_length(log, s, productInfo->cbProductId,
1509 "license product info::ProductId",
1510 LICENSE_MAX_PRODUCT_ID_LENGTH))
1511 goto out_fail;
1512
1513 productInfo->pbProductId = (BYTE*)malloc(productInfo->cbProductId);
1514 if (!productInfo->pbProductId)
1515 goto out_fail;
1516 Stream_Read(s, productInfo->pbProductId, productInfo->cbProductId);
1517 return TRUE;
1518
1519out_fail:
1520 free(productInfo->pbCompanyName);
1521 free(productInfo->pbProductId);
1522 productInfo->pbCompanyName = nullptr;
1523 productInfo->pbProductId = nullptr;
1524 return FALSE;
1525}
1526
1527WINPR_ATTR_NODISCARD
1528static BOOL license_write_product_info(wLog* log, wStream* s,
1529 const LICENSE_PRODUCT_INFO* productInfo)
1530{
1531 WINPR_ASSERT(productInfo);
1532
1533 if (!license_check_stream_capacity(log, s, 8, "license product info::cbCompanyName"))
1534 return FALSE;
1535
1536 Stream_Write_UINT32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */
1537 Stream_Write_UINT32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */
1538
1539 /* Name must be >0, but there is no upper limit defined, use UINT32_MAX */
1540 if ((productInfo->cbCompanyName < 2) || (productInfo->cbCompanyName % 2 != 0) ||
1541 !productInfo->pbCompanyName)
1542 {
1543 WLog_Print(log, WLOG_WARN, "license product info invalid cbCompanyName %" PRIu32,
1544 productInfo->cbCompanyName);
1545 return FALSE;
1546 }
1547
1548 if (!license_check_stream_capacity(log, s, productInfo->cbCompanyName,
1549 "license product info::CompanyName"))
1550 return FALSE;
1551
1552 Stream_Write(s, productInfo->pbCompanyName, productInfo->cbCompanyName);
1553
1554 if (!license_check_stream_capacity(log, s, 4, "license product info::cbProductId"))
1555 return FALSE;
1556
1557 Stream_Write_UINT32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */
1558
1559 if ((productInfo->cbProductId < 2) || (productInfo->cbProductId % 2 != 0) ||
1560 !productInfo->pbProductId)
1561 {
1562 WLog_Print(log, WLOG_WARN, "license product info invalid cbProductId %" PRIu32,
1563 productInfo->cbProductId);
1564 return FALSE;
1565 }
1566
1567 if (!license_check_stream_capacity(log, s, productInfo->cbProductId,
1568 "license product info::ProductId"))
1569 return FALSE;
1570
1571 Stream_Write(s, productInfo->pbProductId, productInfo->cbProductId);
1572 return TRUE;
1573}
1574
1581LICENSE_PRODUCT_INFO* license_new_product_info(void)
1582{
1583 LICENSE_PRODUCT_INFO* productInfo =
1584 (LICENSE_PRODUCT_INFO*)calloc(1, sizeof(LICENSE_PRODUCT_INFO));
1585 if (!productInfo)
1586 return nullptr;
1587 return productInfo;
1588}
1589
1596void license_free_product_info(LICENSE_PRODUCT_INFO* productInfo)
1597{
1598 if (productInfo)
1599 {
1600 free(productInfo->pbCompanyName);
1601 free(productInfo->pbProductId);
1602 free(productInfo);
1603 }
1604}
1605
1606BOOL license_read_binary_blob_data(wLog* log, LICENSE_BLOB* blob, UINT16 wBlobType,
1607 const void* data, size_t length)
1608{
1609 WINPR_ASSERT(blob);
1610 WINPR_ASSERT(length <= UINT16_MAX);
1611 WINPR_ASSERT(data || (length == 0));
1612
1613 blob->length = (UINT16)length;
1614 free(blob->data);
1615 blob->data = nullptr;
1616
1617 if ((blob->type != wBlobType) && (blob->type != BB_ANY_BLOB))
1618 {
1619 WLog_Print(log, WLOG_ERROR, "license binary blob::type expected %s, got %s",
1620 license_blob_type_string(wBlobType), license_blob_type_string(blob->type));
1621 }
1622
1623 /*
1624 * Server can choose to not send data by setting length to 0.
1625 * If so, it may not bother to set the type, so shortcut the warning
1626 */
1627 if ((blob->type != BB_ANY_BLOB) && (blob->length == 0))
1628 {
1629 WLog_Print(log, WLOG_DEBUG, "license binary blob::type %s, length=0, skipping.",
1630 license_blob_type_string(blob->type));
1631 return TRUE;
1632 }
1633
1634 blob->type = wBlobType;
1635 blob->data = nullptr;
1636 if (blob->length > 0)
1637 blob->data = malloc(blob->length);
1638 if (!blob->data)
1639 {
1640 WLog_Print(log, WLOG_ERROR, "license binary blob::length=%" PRIu16 ", blob::data=%p",
1641 blob->length, (const void*)blob->data);
1642 return FALSE;
1643 }
1644 memcpy(blob->data, data, blob->length); /* blobData */
1645 return TRUE;
1646}
1647
1655BOOL license_read_binary_blob(wLog* log, wStream* s, LICENSE_BLOB* blob)
1656{
1657 UINT16 wBlobType = 0;
1658 UINT16 length = 0;
1659
1660 WINPR_ASSERT(blob);
1661
1662 if (!license_check_stream_length(log, s, 4, "license binary blob::type", 0))
1663 return FALSE;
1664
1665 Stream_Read_UINT16(s, wBlobType); /* wBlobType (2 bytes) */
1666 Stream_Read_UINT16(s, length); /* wBlobLen (2 bytes) */
1667
1668 if (!license_check_stream_length(log, s, length, "license binary blob::length", 0))
1669 return FALSE;
1670
1671 if (!license_read_binary_blob_data(log, blob, wBlobType, Stream_Pointer(s), length))
1672 return FALSE;
1673
1674 return Stream_SafeSeek(s, length);
1675}
1676
1684BOOL license_write_binary_blob(wStream* s, const LICENSE_BLOB* blob)
1685{
1686 WINPR_ASSERT(blob);
1687
1688 if (!Stream_EnsureRemainingCapacity(s, blob->length + 4ull))
1689 return FALSE;
1690
1691 Stream_Write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
1692 Stream_Write_UINT16(s, blob->length); /* wBlobLen (2 bytes) */
1693
1694 if (blob->length > 0)
1695 Stream_Write(s, blob->data, blob->length); /* blobData */
1696 return TRUE;
1697}
1698
1699WINPR_ATTR_NODISCARD
1700static BOOL license_write_encrypted_premaster_secret_blob(wLog* log, wStream* s,
1701 const LICENSE_BLOB* blob,
1702 UINT32 ModulusLength)
1703{
1704 const UINT32 length = ModulusLength + 8;
1705
1706 WINPR_ASSERT(blob);
1707 WINPR_ASSERT(length <= UINT16_MAX);
1708
1709 if (blob->length > ModulusLength)
1710 {
1711 WLog_Print(log, WLOG_ERROR, "invalid blob");
1712 return FALSE;
1713 }
1714
1715 if (!Stream_EnsureRemainingCapacity(s, length + 4ull))
1716 return FALSE;
1717 Stream_Write_UINT16(s, blob->type); /* wBlobType (2 bytes) */
1718 Stream_Write_UINT16(s, (UINT16)length); /* wBlobLen (2 bytes) */
1719
1720 if (blob->length > 0)
1721 Stream_Write(s, blob->data, blob->length); /* blobData */
1722
1723 Stream_Zero(s, length - blob->length);
1724 return TRUE;
1725}
1726
1727WINPR_ATTR_NODISCARD
1728static BOOL license_read_encrypted_premaster_secret_blob(wLog* log, wStream* s, LICENSE_BLOB* blob,
1729 UINT32* ModulusLength)
1730{
1731 if (!license_read_binary_blob(log, s, blob))
1732 return FALSE;
1733 WINPR_ASSERT(ModulusLength);
1734 *ModulusLength = blob->length;
1735 return TRUE;
1736}
1737
1744LICENSE_BLOB* license_new_binary_blob(UINT16 type)
1745{
1746 LICENSE_BLOB* blob = (LICENSE_BLOB*)calloc(1, sizeof(LICENSE_BLOB));
1747 if (blob)
1748 blob->type = type;
1749 return blob;
1750}
1751
1758void license_free_binary_blob(LICENSE_BLOB* blob)
1759{
1760 if (blob)
1761 {
1762 free(blob->data);
1763 free(blob);
1764 }
1765}
1766
1774BOOL license_read_scope_list(wLog* log, wStream* s, SCOPE_LIST* scopeList)
1775{
1776 UINT32 scopeCount = 0;
1777
1778 WINPR_ASSERT(scopeList);
1779
1780 if (!license_check_stream_length(log, s, 4, "license scope list", 0))
1781 return FALSE;
1782
1783 Stream_Read_UINT32(s, scopeCount); /* ScopeCount (4 bytes) */
1784
1785 if (!license_check_stream_length(log, s, 4ull * scopeCount, "license scope list::count",
1786 LICENSE_MAX_SCOPE_LENGTH))
1787 return FALSE;
1788
1789 if (!license_scope_list_resize(scopeList, scopeCount))
1790 return FALSE;
1791 /* ScopeArray */
1792 for (UINT32 i = 0; i < scopeCount; i++)
1793 {
1794 if (!license_read_binary_blob(log, s, scopeList->array[i]))
1795 return FALSE;
1796 }
1797
1798 return TRUE;
1799}
1800
1801BOOL license_write_scope_list(wLog* log, wStream* s, const SCOPE_LIST* scopeList)
1802{
1803 WINPR_ASSERT(scopeList);
1804
1805 if (!license_check_stream_capacity(log, s, 4, "license scope list"))
1806 return FALSE;
1807
1808 Stream_Write_UINT32(s, scopeList->count); /* ScopeCount (4 bytes) */
1809
1810 if (!license_check_stream_capacity(log, s, scopeList->count * 4ull,
1811 "license scope list::count"))
1812 return FALSE;
1813
1814 /* ScopeArray */
1815 WINPR_ASSERT(scopeList->array || (scopeList->count == 0));
1816 for (UINT32 i = 0; i < scopeList->count; i++)
1817 {
1818 const LICENSE_BLOB* element = scopeList->array[i];
1819
1820 if (!license_write_binary_blob(s, element))
1821 return FALSE;
1822 }
1823
1824 return TRUE;
1825}
1826
1833SCOPE_LIST* license_new_scope_list(void)
1834{
1835 SCOPE_LIST* list = calloc(1, sizeof(SCOPE_LIST));
1836 return list;
1837}
1838
1839static void license_scope_list_free(SCOPE_LIST* scopeList, UINT32 count)
1840{
1841 WINPR_ASSERT(scopeList);
1842 WINPR_ASSERT(scopeList->array || (scopeList->count == 0));
1843
1844 for (UINT32 x = count; x < scopeList->count; x++)
1845 {
1846 license_free_binary_blob(scopeList->array[x]);
1847 scopeList->array[x] = nullptr;
1848 }
1849
1850 if (count == 0)
1851 {
1852 free((void*)scopeList->array);
1853 scopeList->array = nullptr;
1854 }
1855}
1856
1857BOOL license_scope_list_resize(SCOPE_LIST* scopeList, UINT32 count)
1858{
1859 license_scope_list_free(scopeList, count);
1860 if (count > 0)
1861 {
1862 LICENSE_BLOB** tmp =
1863 (LICENSE_BLOB**)realloc((void*)scopeList->array, count * sizeof(LICENSE_BLOB*));
1864 if (!tmp)
1865 return FALSE;
1866 scopeList->array = tmp;
1867 }
1868
1869 for (UINT32 x = scopeList->count; x < count; x++)
1870 {
1871 LICENSE_BLOB* blob = license_new_binary_blob(BB_SCOPE_BLOB);
1872 if (!blob)
1873 {
1874 scopeList->count = x;
1875 return FALSE;
1876 }
1877 scopeList->array[x] = blob;
1878 }
1879
1880 scopeList->count = count;
1881 return TRUE;
1882}
1883
1890void license_free_scope_list(SCOPE_LIST* scopeList)
1891{
1892 if (!scopeList)
1893 return;
1894
1895 license_scope_list_free(scopeList, 0);
1896 free(scopeList);
1897}
1898
1899BOOL license_send_license_info(rdpLicense* license, const LICENSE_BLOB* calBlob,
1900 const BYTE* signature, size_t signature_length)
1901{
1902 WINPR_ASSERT(calBlob);
1903 WINPR_ASSERT(signature);
1904 WINPR_ASSERT(license->certificate);
1905
1906 const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
1907 if (!info)
1908 return FALSE;
1909
1910 UINT16 sec_flags = 0;
1911 wStream* s = license_send_stream_init(license, &sec_flags);
1912 if (!s)
1913 return FALSE;
1914
1915 if (!license_check_stream_capacity(license->log, s, 8 + sizeof(license->ClientRandom),
1916 "license info::ClientRandom"))
1917 goto error;
1918
1919 Stream_Write_UINT32(s,
1920 license->PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
1921 Stream_Write_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
1922
1923 /* ClientRandom (32 bytes) */
1924 Stream_Write(s, license->ClientRandom, sizeof(license->ClientRandom));
1925
1926 /* Licensing Binary Blob with EncryptedPreMasterSecret: */
1927 if (!license_write_encrypted_premaster_secret_blob(
1928 license->log, s, license->EncryptedPremasterSecret, info->ModulusLength))
1929 goto error;
1930
1931 /* Licensing Binary Blob with LicenseInfo: */
1932 if (!license_write_binary_blob(s, calBlob))
1933 goto error;
1934
1935 /* Licensing Binary Blob with EncryptedHWID */
1936 if (!license_write_binary_blob(s, license->EncryptedHardwareId))
1937 goto error;
1938
1939 /* MACData */
1940 if (!license_check_stream_capacity(license->log, s, signature_length, "license info::MACData"))
1941 goto error;
1942 Stream_Write(s, signature, signature_length);
1943
1944 return license_send(license, s, LICENSE_INFO, sec_flags);
1945
1946error:
1947 Stream_Release(s);
1948 return FALSE;
1949}
1950
1951WINPR_ATTR_NODISCARD
1952static BOOL license_check_preferred_alg(rdpLicense* license, UINT32 PreferredKeyExchangeAlg,
1953 const char* where)
1954{
1955 WINPR_ASSERT(license);
1956 WINPR_ASSERT(where);
1957
1958 if (license->PreferredKeyExchangeAlg != PreferredKeyExchangeAlg)
1959 {
1960 char buffer1[64] = WINPR_C_ARRAY_INIT;
1961 char buffer2[64] = WINPR_C_ARRAY_INIT;
1962 WLog_Print(license->log, WLOG_WARN, "%s::PreferredKeyExchangeAlg, expected %s, got %s",
1963 where,
1964 license_preferred_key_exchange_alg_string(license->PreferredKeyExchangeAlg,
1965 buffer1, sizeof(buffer1)),
1966 license_preferred_key_exchange_alg_string(PreferredKeyExchangeAlg, buffer2,
1967 sizeof(buffer2)));
1968 return FALSE;
1969 }
1970 return TRUE;
1971}
1972
1973BOOL license_read_license_info(rdpLicense* license, wStream* s)
1974{
1975 BOOL rc = FALSE;
1976 UINT32 PreferredKeyExchangeAlg = 0;
1977
1978 WINPR_ASSERT(license);
1979 WINPR_ASSERT(license->certificate);
1980
1981 const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
1982 if (!info)
1983 goto error;
1984
1985 /* ClientRandom (32 bytes) */
1986 if (!license_check_stream_length(license->log, s, 8 + sizeof(license->ClientRandom),
1987 "license info", 0))
1988 goto error;
1989
1990 Stream_Read_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
1991 if (!license_check_preferred_alg(license, PreferredKeyExchangeAlg, "license info"))
1992 goto error;
1993 Stream_Read_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
1994
1995 /* ClientRandom (32 bytes) */
1996 Stream_Read(s, license->ClientRandom, sizeof(license->ClientRandom));
1997
1998 /* Licensing Binary Blob with EncryptedPreMasterSecret: */
1999 {
2000 UINT32 ModulusLength = 0;
2001 if (!license_read_encrypted_premaster_secret_blob(
2002 license->log, s, license->EncryptedPremasterSecret, &ModulusLength))
2003 goto error;
2004
2005 if (ModulusLength != info->ModulusLength)
2006 {
2007 WLog_Print(license->log, WLOG_WARN,
2008 "EncryptedPremasterSecret,::ModulusLength[%" PRIu32
2009 "] != rdpCertInfo::ModulusLength[%" PRIu32 "]",
2010 ModulusLength, info->ModulusLength);
2011 goto error;
2012 }
2013 }
2014
2015 /* Licensing Binary Blob with LicenseInfo: */
2016 if (!license_read_binary_blob(license->log, s, license->LicenseInfo))
2017 goto error;
2018
2019 /* Licensing Binary Blob with EncryptedHWID */
2020 if (!license_read_binary_blob(license->log, s, license->EncryptedHardwareId))
2021 goto error;
2022
2023 /* MACData */
2024 if (!license_check_stream_length(license->log, s, sizeof(license->MACData),
2025 "license info::MACData", 0))
2026 goto error;
2027 Stream_Read(s, license->MACData, sizeof(license->MACData));
2028
2029 rc = TRUE;
2030
2031error:
2032 return rc;
2033}
2034
2042BOOL license_read_license_request_packet(rdpLicense* license, wStream* s)
2043{
2044 WINPR_ASSERT(license);
2045
2046 /* ServerRandom (32 bytes) */
2047 if (!license_check_stream_length(license->log, s, sizeof(license->ServerRandom),
2048 "license request", 0))
2049 return FALSE;
2050
2051 Stream_Read(s, license->ServerRandom, sizeof(license->ServerRandom));
2052
2053 /* ProductInfo */
2054 if (!license_read_product_info(license->log, s, license->ProductInfo))
2055 return FALSE;
2056
2057 /* KeyExchangeList */
2058 if (!license_read_binary_blob(license->log, s, license->KeyExchangeList))
2059 return FALSE;
2060
2061 /* ServerCertificate */
2062 if (!license_read_binary_blob(license->log, s, license->ServerCertificate))
2063 return FALSE;
2064
2065 /* ScopeList */
2066 if (!license_read_scope_list(license->log, s, license->ScopeList))
2067 return FALSE;
2068
2069 /* Parse Server Certificate */
2070 if (!freerdp_certificate_read_server_cert(license->certificate,
2071 license->ServerCertificate->data,
2072 license->ServerCertificate->length))
2073 return FALSE;
2074
2075 if (!license_generate_keys(license) || !license_generate_hwid(license) ||
2076 !license_encrypt_premaster_secret(license))
2077 return FALSE;
2078
2079#ifdef WITH_DEBUG_LICENSE
2080 WLog_Print(license->log, WLOG_DEBUG, "ServerRandom:");
2081 winpr_HexLogDump(license->log, WLOG_DEBUG, license->ServerRandom,
2082 sizeof(license->ServerRandom));
2083 license_print_product_info(license->log, license->ProductInfo);
2084 license_print_scope_list(license->log, license->ScopeList);
2085#endif
2086 return TRUE;
2087}
2088
2089BOOL license_write_license_request_packet(const rdpLicense* license, wStream* s)
2090{
2091 WINPR_ASSERT(license);
2092
2093 /* ServerRandom (32 bytes) */
2094 if (!license_check_stream_capacity(license->log, s, sizeof(license->ServerRandom),
2095 "license request"))
2096 return FALSE;
2097 Stream_Write(s, license->ServerRandom, sizeof(license->ServerRandom));
2098
2099 /* ProductInfo */
2100 if (!license_write_product_info(license->log, s, license->ProductInfo))
2101 return FALSE;
2102
2103 /* KeyExchangeList */
2104 if (!license_write_binary_blob(s, license->KeyExchangeList))
2105 return FALSE;
2106
2107 /* ServerCertificate */
2108 if (!license_write_binary_blob(s, license->ServerCertificate))
2109 return FALSE;
2110
2111 /* ScopeList */
2112 if (!license_write_scope_list(license->log, s, license->ScopeList))
2113 return FALSE;
2114
2115 return TRUE;
2116}
2117
2118WINPR_ATTR_NODISCARD
2119static BOOL license_send_license_request_packet(rdpLicense* license)
2120{
2121 UINT16 sec_flags = 0;
2122 wStream* s = license_send_stream_init(license, &sec_flags);
2123 if (!s)
2124 return FALSE;
2125
2126 if (!license_write_license_request_packet(license, s))
2127 goto fail;
2128
2129 return license_send(license, s, LICENSE_REQUEST, sec_flags);
2130
2131fail:
2132 Stream_Release(s);
2133 return FALSE;
2134}
2135
2136/*
2137 * Read a PLATFORM_CHALLENGE packet.
2138 * msdn{cc241921}
2139 * @param license license module
2140 * @param s stream
2141 */
2142
2143BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s)
2144{
2145 BYTE macData[LICENSING_ENCRYPTION_KEY_LENGTH] = WINPR_C_ARRAY_INIT;
2146
2147 WINPR_ASSERT(license);
2148
2149 DEBUG_LICENSE("Receiving Platform Challenge Packet");
2150
2151 if (!license_check_stream_length(license->log, s, 4, "license platform challenge", 0))
2152 return FALSE;
2153
2154 /* [MS-RDPELE] 2.2.2.4 Server Platform Challenge (SERVER_PLATFORM_CHALLENGE)
2155 * reserved field */
2156 Stream_Seek_UINT32(s); /* ConnectFlags, Reserved (4 bytes) */
2157
2158 /* EncryptedPlatformChallenge */
2159 license->EncryptedPlatformChallenge->type = BB_ANY_BLOB;
2160 if (!license_read_binary_blob(license->log, s, license->EncryptedPlatformChallenge))
2161 return FALSE;
2162 license->EncryptedPlatformChallenge->type = BB_ENCRYPTED_DATA_BLOB;
2163
2164 /* MACData (16 bytes) */
2165 if (!license_check_stream_length(license->log, s, sizeof(macData),
2166 "license platform challenge::MAC", 0))
2167 return FALSE;
2168
2169 Stream_Read(s, macData, sizeof(macData));
2170 if (!license_decrypt_and_check_MAC(license, license->EncryptedPlatformChallenge->data,
2171 license->EncryptedPlatformChallenge->length,
2172 license->PlatformChallenge, macData))
2173 return FALSE;
2174
2175 WLog_Print(license->log, WLOG_TRACE, "platform challenge read");
2176
2177#ifdef WITH_DEBUG_LICENSE
2178 WLog_Print(license->log, WLOG_DEBUG, "EncryptedPlatformChallenge:");
2179 winpr_HexLogDump(license->log, WLOG_DEBUG, license->EncryptedPlatformChallenge->data,
2180 license->EncryptedPlatformChallenge->length);
2181 WLog_Print(license->log, WLOG_DEBUG, "PlatformChallenge:");
2182 winpr_HexLogDump(license->log, WLOG_DEBUG, license->PlatformChallenge->data,
2183 license->PlatformChallenge->length);
2184 WLog_Print(license->log, WLOG_DEBUG, "MacData:");
2185 winpr_HexLogDump(license->log, WLOG_DEBUG, macData, sizeof(macData));
2186#endif
2187 return TRUE;
2188}
2189
2190BOOL license_send_error_alert(rdpLicense* license, UINT32 dwErrorCode, UINT32 dwStateTransition,
2191 const LICENSE_BLOB* info)
2192{
2193 UINT16 sec_flags = 0;
2194 wStream* s = license_send_stream_init(license, &sec_flags);
2195
2196 if (!s)
2197 goto fail;
2198
2199 if (!license_check_stream_capacity(license->log, s, 8, "license error alert"))
2200 goto fail;
2201 Stream_Write_UINT32(s, dwErrorCode);
2202 Stream_Write_UINT32(s, dwStateTransition);
2203
2204 if (info)
2205 {
2206 if (!license_write_binary_blob(s, info))
2207 goto fail;
2208 }
2209
2210 return license_send(license, s, ERROR_ALERT, sec_flags);
2211fail:
2212 Stream_Release(s);
2213 return FALSE;
2214}
2215
2216BOOL license_send_platform_challenge_packet(rdpLicense* license)
2217{
2218 UINT16 sec_flags = 0;
2219 wStream* s = license_send_stream_init(license, &sec_flags);
2220
2221 if (!s)
2222 goto fail;
2223
2224 DEBUG_LICENSE("Receiving Platform Challenge Packet");
2225
2226 if (!license_check_stream_capacity(license->log, s, 4, "license platform challenge"))
2227 goto fail;
2228
2229 Stream_Zero(s, 4); /* ConnectFlags, Reserved (4 bytes) */
2230
2231 /* EncryptedPlatformChallenge */
2232 if (!license_write_binary_blob(s, license->EncryptedPlatformChallenge))
2233 goto fail;
2234
2235 /* MACData (16 bytes) */
2236 if (!license_check_stream_length(license->log, s, sizeof(license->MACData),
2237 "license platform challenge::MAC", 0))
2238 goto fail;
2239
2240 Stream_Write(s, license->MACData, sizeof(license->MACData));
2241
2242 return license_send(license, s, PLATFORM_CHALLENGE, sec_flags);
2243fail:
2244 Stream_Release(s);
2245 return FALSE;
2246}
2247
2248WINPR_ATTR_NODISCARD
2249static BOOL license_read_encrypted_blob(const rdpLicense* license, wStream* s, LICENSE_BLOB* target)
2250{
2251 UINT16 wBlobType = 0;
2252 UINT16 wBlobLen = 0;
2253
2254 WINPR_ASSERT(license);
2255 WINPR_ASSERT(target);
2256
2257 if (!license_check_stream_length(license->log, s, 4, "license encrypted blob", 0))
2258 return FALSE;
2259
2260 Stream_Read_UINT16(s, wBlobType);
2261 if (wBlobType != BB_ENCRYPTED_DATA_BLOB)
2262 {
2263 WLog_Print(
2264 license->log, WLOG_WARN,
2265 "expecting BB_ENCRYPTED_DATA_BLOB blob, probably a windows 2003 server, continuing...");
2266 }
2267
2268 Stream_Read_UINT16(s, wBlobLen);
2269
2270 BYTE* encryptedData = Stream_Pointer(s);
2271 if (!Stream_SafeSeek(s, wBlobLen))
2272 {
2273 WLog_Print(license->log, WLOG_WARN,
2274 "short license encrypted blob::length, expected %" PRIu16 " bytes, got %" PRIuz,
2275 wBlobLen, Stream_GetRemainingLength(s));
2276 return FALSE;
2277 }
2278
2279 return license_rc4_with_licenseKey(license, encryptedData, wBlobLen, target);
2280}
2281
2289BOOL license_read_new_or_upgrade_license_packet(rdpLicense* license, wStream* s)
2290{
2291 UINT32 os_major = 0;
2292 UINT32 os_minor = 0;
2293 UINT32 cbScope = 0;
2294 UINT32 cbCompanyName = 0;
2295 UINT32 cbProductId = 0;
2296 UINT32 cbLicenseInfo = 0;
2297 wStream sbuffer = WINPR_C_ARRAY_INIT;
2298 wStream* licenseStream = nullptr;
2299 BOOL ret = FALSE;
2300 BYTE computedMac[16] = WINPR_C_ARRAY_INIT;
2301 const BYTE* readMac = nullptr;
2302
2303 WINPR_ASSERT(license);
2304
2305 DEBUG_LICENSE("Receiving Server New/Upgrade License Packet");
2306
2307 LICENSE_BLOB* calBlob = license_new_binary_blob(BB_DATA_BLOB);
2308 if (!calBlob)
2309 return FALSE;
2310
2311 /* EncryptedLicenseInfo */
2312 if (!license_read_encrypted_blob(license, s, calBlob))
2313 goto fail;
2314
2315 /* compute MAC and check it */
2316 readMac = Stream_Pointer(s);
2317 if (!Stream_SafeSeek(s, sizeof(computedMac)))
2318 {
2319 WLog_Print(license->log, WLOG_WARN,
2320 "short license new/upgrade, expected 16 bytes, got %" PRIuz,
2321 Stream_GetRemainingLength(s));
2322 goto fail;
2323 }
2324
2325 if (!security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), calBlob->data,
2326 calBlob->length, computedMac, sizeof(computedMac)))
2327 goto fail;
2328
2329 if (memcmp(computedMac, readMac, sizeof(computedMac)) != 0)
2330 {
2331 WLog_Print(license->log, WLOG_ERROR, "new or upgrade license MAC mismatch");
2332 goto fail;
2333 }
2334
2335 licenseStream = Stream_StaticConstInit(&sbuffer, calBlob->data, calBlob->length);
2336 if (!licenseStream)
2337 {
2338 WLog_Print(license->log, WLOG_ERROR,
2339 "license::blob::data=%p, license::blob::length=%" PRIu16,
2340 (const void*)calBlob->data, calBlob->length);
2341 goto fail;
2342 }
2343
2344 if (!license_check_stream_length(license->log, licenseStream, 8,
2345 "license new/upgrade::blob::version", 0))
2346 goto fail;
2347
2348 Stream_Read_UINT16(licenseStream, os_minor);
2349 Stream_Read_UINT16(licenseStream, os_major);
2350
2351 WLog_Print(license->log, WLOG_DEBUG, "Version: %" PRIu16 ".%" PRIu16, os_major, os_minor);
2352
2353 /* Scope */
2354 Stream_Read_UINT32(licenseStream, cbScope);
2355 if (!license_check_stream_length(license->log, licenseStream, cbScope,
2356 "license new/upgrade::blob::scope", LICENSE_MAX_SCOPE_LENGTH))
2357 goto fail;
2358
2359#ifdef WITH_DEBUG_LICENSE
2360 WLog_Print(license->log, WLOG_DEBUG, "Scope:");
2361 winpr_HexLogDump(license->log, WLOG_DEBUG, Stream_Pointer(licenseStream), cbScope);
2362#endif
2363 Stream_Seek(licenseStream, cbScope);
2364
2365 /* CompanyName */
2366 if (!license_check_stream_length(license->log, licenseStream, 4,
2367 "license new/upgrade::blob::cbCompanyName", 0))
2368 goto fail;
2369
2370 Stream_Read_UINT32(licenseStream, cbCompanyName);
2371 if (!license_check_stream_length(license->log, licenseStream, cbCompanyName,
2372 "license new/upgrade::blob::CompanyName",
2373 LICENSE_MAX_COMPANY_NAME_LENGTH))
2374 goto fail;
2375
2376#ifdef WITH_DEBUG_LICENSE
2377 WLog_Print(license->log, WLOG_DEBUG, "Company name:");
2378 winpr_HexLogDump(license->log, WLOG_DEBUG, Stream_Pointer(licenseStream), cbCompanyName);
2379#endif
2380 Stream_Seek(licenseStream, cbCompanyName);
2381
2382 /* productId */
2383 if (!license_check_stream_length(license->log, licenseStream, 4,
2384 "license new/upgrade::blob::cbProductId", 0))
2385 goto fail;
2386
2387 Stream_Read_UINT32(licenseStream, cbProductId);
2388
2389 if (!license_check_stream_length(license->log, licenseStream, cbProductId,
2390 "license new/upgrade::blob::ProductId",
2391 LICENSE_MAX_PRODUCT_ID_LENGTH))
2392 goto fail;
2393
2394#ifdef WITH_DEBUG_LICENSE
2395 WLog_Print(license->log, WLOG_DEBUG, "Product id:");
2396 winpr_HexLogDump(license->log, WLOG_DEBUG, Stream_Pointer(licenseStream), cbProductId);
2397#endif
2398 Stream_Seek(licenseStream, cbProductId);
2399
2400 /* licenseInfo */
2401 if (!license_check_stream_length(license->log, licenseStream, 4,
2402 "license new/upgrade::blob::cbLicenseInfo", 0))
2403 goto fail;
2404
2405 Stream_Read_UINT32(licenseStream, cbLicenseInfo);
2406 if (!license_check_stream_length(license->log, licenseStream, cbLicenseInfo,
2407 "license new/upgrade::blob::LicenseInfo",
2408 LICENSE_MAX_CAL_LENGTH))
2409 goto fail;
2410
2411 license->type = LICENSE_TYPE_ISSUED;
2412 license_set_state(license, LICENSE_STATE_COMPLETED);
2413 ret = TRUE;
2414
2415 if (!license->rdp->settings->OldLicenseBehaviour)
2416 ret = saveCal(license->log, license->rdp->settings, Stream_Pointer(licenseStream),
2417 cbLicenseInfo, license->rdp->settings->ClientHostname);
2418
2419fail:
2420 license_free_binary_blob(calBlob);
2421 return ret;
2422}
2423
2431BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s)
2432{
2433 UINT32 dwErrorCode = 0;
2434 UINT32 dwStateTransition = 0;
2435
2436 WINPR_ASSERT(license);
2437 WINPR_ASSERT(license->rdp);
2438
2439 if (!license_check_stream_length(license->log, s, 8ul, "error alert", 0))
2440 return FALSE;
2441
2442 Stream_Read_UINT32(s, dwErrorCode); /* dwErrorCode (4 bytes) */
2443 Stream_Read_UINT32(s, dwStateTransition); /* dwStateTransition (4 bytes) */
2444
2445 if (!license_read_binary_blob(license->log, s, license->ErrorInfo)) /* bbErrorInfo */
2446 return FALSE;
2447
2448#ifdef WITH_DEBUG_LICENSE
2449 WLog_Print(license->log, WLOG_DEBUG, "dwErrorCode: %s, dwStateTransition: %s",
2450 error_codes(dwErrorCode), state_transitions(dwStateTransition));
2451#endif
2452
2453 if (dwErrorCode == STATUS_VALID_CLIENT)
2454 {
2455 license->type = LICENSE_TYPE_NONE;
2456 license_set_state(license, LICENSE_STATE_COMPLETED);
2457 return TRUE;
2458 }
2459
2460 switch (dwStateTransition)
2461 {
2462 case ST_TOTAL_ABORT:
2463 license_set_state(license, LICENSE_STATE_ABORTED);
2464 break;
2465 case ST_NO_TRANSITION:
2466 license_set_state(license, LICENSE_STATE_COMPLETED);
2467 break;
2468 case ST_RESET_PHASE_TO_START:
2469 license_set_state(license, LICENSE_STATE_CONFIGURED);
2470 break;
2471 case ST_RESEND_LAST_MESSAGE:
2472 break;
2473 default:
2474 break;
2475 }
2476
2477 return TRUE;
2478}
2479
2487BOOL license_write_new_license_request_packet(const rdpLicense* license, wStream* s)
2488{
2489 WINPR_ASSERT(license);
2490
2491 const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
2492 if (!info)
2493 return FALSE;
2494
2495 if (!license_check_stream_capacity(license->log, s, 8 + sizeof(license->ClientRandom),
2496 "License Request"))
2497 return FALSE;
2498
2499 Stream_Write_UINT32(s,
2500 license->PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
2501 Stream_Write_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
2502 Stream_Write(s, license->ClientRandom,
2503 sizeof(license->ClientRandom)); /* ClientRandom (32 bytes) */
2504
2505 if (/* EncryptedPremasterSecret */
2506 !license_write_encrypted_premaster_secret_blob(
2507 license->log, s, license->EncryptedPremasterSecret, info->ModulusLength) ||
2508 /* ClientUserName */
2509 !license_write_binary_blob(s, license->ClientUserName) ||
2510 /* ClientMachineName */
2511 !license_write_binary_blob(s, license->ClientMachineName))
2512 {
2513 return FALSE;
2514 }
2515
2516 WLog_Print(license->log, WLOG_TRACE, "new license written");
2517
2518#ifdef WITH_DEBUG_LICENSE
2519 WLog_Print(license->log, WLOG_DEBUG, "PreferredKeyExchangeAlg: 0x%08" PRIX32 "",
2520 license->PreferredKeyExchangeAlg);
2521 WLog_Print(license->log, WLOG_DEBUG, "ClientRandom:");
2522 winpr_HexLogDump(license->log, WLOG_DEBUG, license->ClientRandom,
2523 sizeof(license->ClientRandom));
2524 WLog_Print(license->log, WLOG_DEBUG, "EncryptedPremasterSecret");
2525 winpr_HexLogDump(license->log, WLOG_DEBUG, license->EncryptedPremasterSecret->data,
2526 license->EncryptedPremasterSecret->length);
2527 WLog_Print(license->log, WLOG_DEBUG, "ClientUserName (%" PRIu16 "): %s",
2528 license->ClientUserName->length, (char*)license->ClientUserName->data);
2529 WLog_Print(license->log, WLOG_DEBUG, "ClientMachineName (%" PRIu16 "): %s",
2530 license->ClientMachineName->length, (char*)license->ClientMachineName->data);
2531#endif
2532 return TRUE;
2533}
2534
2535BOOL license_read_new_license_request_packet(rdpLicense* license, wStream* s)
2536{
2537 UINT32 PreferredKeyExchangeAlg = 0;
2538
2539 WINPR_ASSERT(license);
2540
2541 if (!license_check_stream_length(license->log, s, 8ull + sizeof(license->ClientRandom),
2542 "new license request", 0))
2543 return FALSE;
2544
2545 Stream_Read_UINT32(s, PreferredKeyExchangeAlg); /* PreferredKeyExchangeAlg (4 bytes) */
2546 if (!license_check_preferred_alg(license, PreferredKeyExchangeAlg, "new license request"))
2547 return FALSE;
2548
2549 Stream_Read_UINT32(s, license->PlatformId); /* PlatformId (4 bytes) */
2550 Stream_Read(s, license->ClientRandom,
2551 sizeof(license->ClientRandom)); /* ClientRandom (32 bytes) */
2552
2553 /* EncryptedPremasterSecret */
2554 UINT32 ModulusLength = 0;
2555 if (!license_read_encrypted_premaster_secret_blob(
2556 license->log, s, license->EncryptedPremasterSecret, &ModulusLength))
2557 return FALSE;
2558
2559 const rdpCertInfo* info = freerdp_certificate_get_info(license->certificate);
2560 if (!info)
2561 WLog_Print(license->log, WLOG_WARN,
2562 "Missing license certificate, skipping ModulusLength checks");
2563 else if (ModulusLength != info->ModulusLength)
2564 {
2565 WLog_Print(license->log, WLOG_WARN,
2566 "EncryptedPremasterSecret expected to be %" PRIu32 " bytes, but read %" PRIu32
2567 " bytes",
2568 info->ModulusLength, ModulusLength);
2569 return FALSE;
2570 }
2571
2572 /* ClientUserName */
2573 if (!license_read_binary_blob(license->log, s, license->ClientUserName))
2574 return FALSE;
2575 /* ClientMachineName */
2576 if (!license_read_binary_blob(license->log, s, license->ClientMachineName))
2577 return FALSE;
2578
2579 return TRUE;
2580}
2581
2588BOOL license_answer_license_request(rdpLicense* license)
2589{
2590 UINT16 sec_flags = 0;
2591 wStream* s = nullptr;
2592 BYTE* license_data = nullptr;
2593 size_t license_size = 0;
2594 BOOL status = 0;
2595 char* username = nullptr;
2596
2597 WINPR_ASSERT(license);
2598 WINPR_ASSERT(license->rdp);
2599 WINPR_ASSERT(license->rdp->settings);
2600
2601 if (!license->rdp->settings->OldLicenseBehaviour)
2602 license_data = loadCalFile(license->log, license->rdp->settings,
2603 license->rdp->settings->ClientHostname, &license_size);
2604
2605 if (license_data)
2606 {
2607 LICENSE_BLOB* calBlob = nullptr;
2608 BYTE signature[LICENSING_ENCRYPTION_KEY_LENGTH] = WINPR_C_ARRAY_INIT;
2609
2610 DEBUG_LICENSE("Sending Saved License Packet");
2611
2612 WINPR_ASSERT(license->EncryptedHardwareId);
2613 license->EncryptedHardwareId->type = BB_ENCRYPTED_DATA_BLOB;
2614 if (!license_encrypt_and_MAC(license, license->HardwareId, sizeof(license->HardwareId),
2615 license->EncryptedHardwareId, signature, sizeof(signature)))
2616 {
2617 free(license_data);
2618 return FALSE;
2619 }
2620
2621 calBlob = license_new_binary_blob(BB_DATA_BLOB);
2622 if (!calBlob)
2623 {
2624 free(license_data);
2625 return FALSE;
2626 }
2627 calBlob->data = license_data;
2628 WINPR_ASSERT(license_size <= UINT16_MAX);
2629 calBlob->length = (UINT16)license_size;
2630
2631 status = license_send_license_info(license, calBlob, signature, sizeof(signature));
2632 license_free_binary_blob(calBlob);
2633
2634 return status;
2635 }
2636
2637 DEBUG_LICENSE("Sending New License Packet");
2638
2639 s = license_send_stream_init(license, &sec_flags);
2640 if (!s)
2641 return FALSE;
2642 if (license->rdp->settings->Username != nullptr)
2643 username = license->rdp->settings->Username;
2644 else
2645 username = "username";
2646
2647 {
2648 WINPR_ASSERT(license->ClientUserName);
2649 const size_t len = strlen(username) + 1;
2650 WINPR_ASSERT(len <= UINT16_MAX);
2651
2652 license->ClientUserName->data = (BYTE*)username;
2653 license->ClientUserName->length = (UINT16)len;
2654 }
2655
2656 {
2657 WINPR_ASSERT(license->ClientMachineName);
2658 const size_t len = strlen(license->rdp->settings->ClientHostname) + 1;
2659 WINPR_ASSERT(len <= UINT16_MAX);
2660
2661 license->ClientMachineName->data = (BYTE*)license->rdp->settings->ClientHostname;
2662 license->ClientMachineName->length = (UINT16)len;
2663 }
2664 status = license_write_new_license_request_packet(license, s);
2665
2666 WINPR_ASSERT(license->ClientUserName);
2667 license->ClientUserName->data = nullptr;
2668 license->ClientUserName->length = 0;
2669
2670 WINPR_ASSERT(license->ClientMachineName);
2671 license->ClientMachineName->data = nullptr;
2672 license->ClientMachineName->length = 0;
2673
2674 if (!status)
2675 {
2676 Stream_Release(s);
2677 return FALSE;
2678 }
2679
2680 return license_send(license, s, NEW_LICENSE_REQUEST, sec_flags);
2681}
2682
2689BOOL license_send_platform_challenge_response(rdpLicense* license)
2690{
2691 wStream* challengeRespData = nullptr;
2692 BYTE* buffer = nullptr;
2693 BOOL status = 0;
2694
2695 WINPR_ASSERT(license);
2696 WINPR_ASSERT(license->PlatformChallenge);
2697 WINPR_ASSERT(license->MacSaltKey);
2698 WINPR_ASSERT(license->EncryptedPlatformChallenge);
2699 WINPR_ASSERT(license->EncryptedHardwareId);
2700
2701 DEBUG_LICENSE("Sending Platform Challenge Response Packet");
2702
2703 license->EncryptedPlatformChallenge->type = BB_DATA_BLOB;
2704
2705 /* prepare the PLATFORM_CHALLENGE_RESPONSE_DATA */
2706 challengeRespData = Stream_New(nullptr, 8 + license->PlatformChallenge->length);
2707 if (!challengeRespData)
2708 return FALSE;
2709 Stream_Write_UINT16(challengeRespData, PLATFORM_CHALLENGE_RESPONSE_VERSION); /* wVersion */
2710 Stream_Write_UINT16(challengeRespData, license->ClientType); /* wClientType */
2711 Stream_Write_UINT16(challengeRespData, license->LicenseDetailLevel); /* wLicenseDetailLevel */
2712 Stream_Write_UINT16(challengeRespData, license->PlatformChallenge->length); /* cbChallenge */
2713 Stream_Write(challengeRespData, license->PlatformChallenge->data,
2714 license->PlatformChallenge->length); /* pbChallenge */
2715 Stream_SealLength(challengeRespData);
2716
2717 /* compute MAC of PLATFORM_CHALLENGE_RESPONSE_DATA + HWID */
2718 const size_t length = Stream_Length(challengeRespData) + sizeof(license->HardwareId);
2719 buffer = (BYTE*)malloc(length);
2720 if (!buffer)
2721 {
2722 Stream_Free(challengeRespData, TRUE);
2723 return FALSE;
2724 }
2725
2726 CopyMemory(buffer, Stream_Buffer(challengeRespData), Stream_Length(challengeRespData));
2727 CopyMemory(&buffer[Stream_Length(challengeRespData)], license->HardwareId,
2728 sizeof(license->HardwareId));
2729 status = security_mac_data(license->MacSaltKey, sizeof(license->MacSaltKey), buffer, length,
2730 license->MACData, sizeof(license->MACData));
2731 free(buffer);
2732
2733 if (!status)
2734 {
2735 Stream_Free(challengeRespData, TRUE);
2736 return FALSE;
2737 }
2738
2739 license->EncryptedHardwareId->type = BB_ENCRYPTED_DATA_BLOB;
2740 if (!license_rc4_with_licenseKey(license, license->HardwareId, sizeof(license->HardwareId),
2741 license->EncryptedHardwareId))
2742 {
2743 Stream_Free(challengeRespData, TRUE);
2744 return FALSE;
2745 }
2746
2747 status = license_rc4_with_licenseKey(license, Stream_Buffer(challengeRespData),
2748 Stream_Length(challengeRespData),
2749 license->EncryptedPlatformChallengeResponse);
2750 Stream_Free(challengeRespData, TRUE);
2751 if (!status)
2752 return FALSE;
2753
2754#ifdef WITH_DEBUG_LICENSE
2755 WLog_Print(license->log, WLOG_DEBUG, "LicensingEncryptionKey:");
2756 winpr_HexLogDump(license->log, WLOG_DEBUG, license->LicensingEncryptionKey, 16);
2757 WLog_Print(license->log, WLOG_DEBUG, "HardwareId:");
2758 winpr_HexLogDump(license->log, WLOG_DEBUG, license->HardwareId, sizeof(license->HardwareId));
2759 WLog_Print(license->log, WLOG_DEBUG, "EncryptedHardwareId:");
2760 winpr_HexLogDump(license->log, WLOG_DEBUG, license->EncryptedHardwareId->data,
2761 license->EncryptedHardwareId->length);
2762#endif
2763 UINT16 sec_flags = 0;
2764 wStream* s = license_send_stream_init(license, &sec_flags);
2765 if (!s)
2766 return FALSE;
2767
2768 if (license_write_client_platform_challenge_response(license, s))
2769 return license_send(license, s, PLATFORM_CHALLENGE_RESPONSE, sec_flags);
2770
2771 Stream_Release(s);
2772 return FALSE;
2773}
2774
2775BOOL license_read_platform_challenge_response(WINPR_ATTR_UNUSED rdpLicense* license)
2776{
2777 WINPR_ASSERT(license);
2778 WINPR_ASSERT(license->PlatformChallenge);
2779 WINPR_ASSERT(license->MacSaltKey);
2780 WINPR_ASSERT(license->EncryptedPlatformChallenge);
2781 WINPR_ASSERT(license->EncryptedHardwareId);
2782
2783 DEBUG_LICENSE("Receiving Platform Challenge Response Packet");
2784
2785#if defined(WITH_LICENSE_DECRYPT_CHALLENGE_RESPONSE)
2786 BOOL rc = FALSE;
2787 LICENSE_BLOB* dblob = license_new_binary_blob(BB_ANY_BLOB);
2788 if (!dblob)
2789 return FALSE;
2790
2791 wStream sbuffer = WINPR_C_ARRAY_INIT;
2792 UINT16 wVersion = 0;
2793 UINT16 cbChallenge = 0;
2794 const BYTE* pbChallenge = nullptr;
2795 LICENSE_BLOB* blob = license->EncryptedPlatformChallengeResponse;
2796
2797 if (!license_rc4_with_licenseKey(license, blob->data, blob->length, dblob))
2798 goto fail;
2799
2800 wStream* s = Stream_StaticConstInit(&sbuffer, dblob->data, dblob->length);
2801 if (!license_check_stream_length(s, 8, "PLATFORM_CHALLENGE_RESPONSE_DATA", 0))
2802 goto fail;
2803
2804 Stream_Read_UINT16(s, wVersion);
2805 if (wVersion != PLATFORM_CHALLENGE_RESPONSE_VERSION)
2806 {
2807 WLog_Print(license->log, WLOG_WARN,
2808 "Invalid PLATFORM_CHALLENGE_RESPONSE_DATA::wVersion 0x%04" PRIx16
2809 ", expected 0x04" PRIx16,
2810 wVersion, PLATFORM_CHALLENGE_RESPONSE_VERSION);
2811 goto fail;
2812 }
2813 Stream_Read_UINT16(s, license->ClientType);
2814 Stream_Read_UINT16(s, license->LicenseDetailLevel);
2815 Stream_Read_UINT16(s, cbChallenge);
2816
2817 if (!license_check_stream_length(s, cbChallenge,
2818 "PLATFORM_CHALLENGE_RESPONSE_DATA::pbChallenge", 0))
2819 goto fail;
2820
2821 pbChallenge = Stream_Pointer(s);
2822 if (!license_read_binary_blob_data(license->PlatformChallengeResponse, BB_DATA_BLOB,
2823 pbChallenge, cbChallenge))
2824 goto fail;
2825 if (!Stream_SafeSeek(s, cbChallenge))
2826 goto fail;
2827
2828 rc = TRUE;
2829fail:
2830 license_free_binary_blob(dblob);
2831 return rc;
2832#else
2833 return TRUE;
2834#endif
2835}
2836
2837BOOL license_write_client_platform_challenge_response(rdpLicense* license, wStream* s)
2838{
2839 WINPR_ASSERT(license);
2840
2841 if (!license_write_binary_blob(s, license->EncryptedPlatformChallengeResponse))
2842 return FALSE;
2843 if (!license_write_binary_blob(s, license->EncryptedHardwareId))
2844 return FALSE;
2845 if (!license_check_stream_capacity(license->log, s, sizeof(license->MACData),
2846 "CLIENT_PLATFORM_CHALLENGE_RESPONSE::MACData"))
2847 return FALSE;
2848 Stream_Write(s, license->MACData, sizeof(license->MACData));
2849 return TRUE;
2850}
2851
2852BOOL license_read_client_platform_challenge_response(rdpLicense* license, wStream* s)
2853{
2854 WINPR_ASSERT(license);
2855
2856 if (!license_read_binary_blob(license->log, s, license->EncryptedPlatformChallengeResponse))
2857 return FALSE;
2858 if (!license_read_binary_blob(license->log, s, license->EncryptedHardwareId))
2859 return FALSE;
2860 if (!license_check_stream_length(license->log, s, sizeof(license->MACData),
2861 "CLIENT_PLATFORM_CHALLENGE_RESPONSE::MACData", 0))
2862 return FALSE;
2863 Stream_Read(s, license->MACData, sizeof(license->MACData));
2864 return license_read_platform_challenge_response(license);
2865}
2866
2876BOOL license_send_valid_client_error_packet(rdpRdp* rdp)
2877{
2878 WINPR_ASSERT(rdp);
2879 rdpLicense* license = rdp->license;
2880 WINPR_ASSERT(license);
2881
2882 license->state = LICENSE_STATE_COMPLETED;
2883 license->type = LICENSE_TYPE_NONE;
2884 return license_send_error_alert(license, STATUS_VALID_CLIENT, ST_NO_TRANSITION,
2885 license->ErrorInfo);
2886}
2887
2894rdpLicense* license_new(rdpRdp* rdp)
2895{
2896 WINPR_ASSERT(rdp);
2897
2898 rdpLicense* license = (rdpLicense*)calloc(1, sizeof(rdpLicense));
2899 if (!license)
2900 return nullptr;
2901 license->log = WLog_Get(LICENSE_TAG);
2902 WINPR_ASSERT(license->log);
2903
2904 license->PlatformId = PLATFORMID;
2905 license->ClientType = OTHER_PLATFORM_CHALLENGE_TYPE;
2906 license->LicenseDetailLevel = LICENSE_DETAIL_DETAIL;
2907 license->PreferredKeyExchangeAlg = KEY_EXCHANGE_ALG_RSA;
2908 license->rdp = rdp;
2909
2910 license_set_state(license, LICENSE_STATE_INITIAL);
2911 if (!(license->certificate = freerdp_certificate_new()))
2912 goto out_error;
2913 if (!(license->ProductInfo = license_new_product_info()))
2914 goto out_error;
2915 if (!(license->ErrorInfo = license_new_binary_blob(BB_ERROR_BLOB)))
2916 goto out_error;
2917 if (!(license->LicenseInfo = license_new_binary_blob(BB_DATA_BLOB)))
2918 goto out_error;
2919 if (!(license->KeyExchangeList = license_new_binary_blob(BB_KEY_EXCHG_ALG_BLOB)))
2920 goto out_error;
2921 if (!(license->ServerCertificate = license_new_binary_blob(BB_CERTIFICATE_BLOB)))
2922 goto out_error;
2923 if (!(license->ClientUserName = license_new_binary_blob(BB_CLIENT_USER_NAME_BLOB)))
2924 goto out_error;
2925 if (!(license->ClientMachineName = license_new_binary_blob(BB_CLIENT_MACHINE_NAME_BLOB)))
2926 goto out_error;
2927 if (!(license->PlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
2928 goto out_error;
2929 if (!(license->PlatformChallengeResponse = license_new_binary_blob(BB_ANY_BLOB)))
2930 goto out_error;
2931 if (!(license->EncryptedPlatformChallenge = license_new_binary_blob(BB_ANY_BLOB)))
2932 goto out_error;
2933 if (!(license->EncryptedPlatformChallengeResponse =
2934 license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
2935 goto out_error;
2936 if (!(license->EncryptedPremasterSecret = license_new_binary_blob(BB_ANY_BLOB)))
2937 goto out_error;
2938 if (!(license->EncryptedHardwareId = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
2939 goto out_error;
2940 if (!(license->EncryptedLicenseInfo = license_new_binary_blob(BB_ENCRYPTED_DATA_BLOB)))
2941 goto out_error;
2942 if (!(license->ScopeList = license_new_scope_list()))
2943 goto out_error;
2944
2945 if (!license_generate_randoms(license))
2946 goto out_error;
2947
2948 return license;
2949
2950out_error:
2951 WINPR_PRAGMA_DIAG_PUSH
2952 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2953 license_free(license);
2954 WINPR_PRAGMA_DIAG_POP
2955 return nullptr;
2956}
2957
2963void license_free(rdpLicense* license)
2964{
2965 if (license)
2966 {
2967 freerdp_certificate_free(license->certificate);
2968 license_free_product_info(license->ProductInfo);
2969 license_free_binary_blob(license->ErrorInfo);
2970 license_free_binary_blob(license->LicenseInfo);
2971 license_free_binary_blob(license->KeyExchangeList);
2972 license_free_binary_blob(license->ServerCertificate);
2973 license_free_binary_blob(license->ClientUserName);
2974 license_free_binary_blob(license->ClientMachineName);
2975 license_free_binary_blob(license->PlatformChallenge);
2976 license_free_binary_blob(license->PlatformChallengeResponse);
2977 license_free_binary_blob(license->EncryptedPlatformChallenge);
2978 license_free_binary_blob(license->EncryptedPlatformChallengeResponse);
2979 license_free_binary_blob(license->EncryptedPremasterSecret);
2980 license_free_binary_blob(license->EncryptedHardwareId);
2981 license_free_binary_blob(license->EncryptedLicenseInfo);
2982 license_free_scope_list(license->ScopeList);
2983 free(license);
2984 }
2985}
2986
2987LICENSE_STATE license_get_state(const rdpLicense* license)
2988{
2989 WINPR_ASSERT(license);
2990 return license->state;
2991}
2992
2993LICENSE_TYPE license_get_type(const rdpLicense* license)
2994{
2995 WINPR_ASSERT(license);
2996 return license->type;
2997}
2998
2999void license_set_state(rdpLicense* license, LICENSE_STATE state)
3000{
3001 WINPR_ASSERT(license);
3002 license->state = state;
3003 switch (state)
3004 {
3005 case LICENSE_STATE_COMPLETED:
3006 break;
3007 case LICENSE_STATE_ABORTED:
3008 default:
3009 license->type = LICENSE_TYPE_INVALID;
3010 break;
3011 }
3012}
3013
3014const char* license_get_state_string(LICENSE_STATE state)
3015{
3016 switch (state)
3017 {
3018 case LICENSE_STATE_INITIAL:
3019 return "LICENSE_STATE_INITIAL";
3020 case LICENSE_STATE_CONFIGURED:
3021 return "LICENSE_STATE_CONFIGURED";
3022 case LICENSE_STATE_REQUEST:
3023 return "LICENSE_STATE_REQUEST";
3024 case LICENSE_STATE_NEW_REQUEST:
3025 return "LICENSE_STATE_NEW_REQUEST";
3026 case LICENSE_STATE_PLATFORM_CHALLENGE:
3027 return "LICENSE_STATE_PLATFORM_CHALLENGE";
3028 case LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE:
3029 return "LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE";
3030 case LICENSE_STATE_COMPLETED:
3031 return "LICENSE_STATE_COMPLETED";
3032 case LICENSE_STATE_ABORTED:
3033 return "LICENSE_STATE_ABORTED";
3034 default:
3035 return "LICENSE_STATE_UNKNOWN";
3036 }
3037}
3038
3039BOOL license_server_send_request(rdpLicense* license)
3040{
3041 if (!license_ensure_state(license, LICENSE_STATE_CONFIGURED, LICENSE_REQUEST))
3042 return FALSE;
3043 if (!license_send_license_request_packet(license))
3044 return FALSE;
3045 license_set_state(license, LICENSE_STATE_REQUEST);
3046 return TRUE;
3047}
3048
3049WINPR_ATTR_NODISCARD
3050static BOOL license_set_string(wLog* log, const char* what, const char* value, BYTE** bdst,
3051 UINT32* dstLen)
3052{
3053 WINPR_ASSERT(what);
3054 WINPR_ASSERT(value);
3055 WINPR_ASSERT(bdst);
3056 WINPR_ASSERT(dstLen);
3057
3058 union
3059 {
3060 WCHAR** w;
3061 BYTE** b;
3062 } cnv;
3063 cnv.b = bdst;
3064
3065 size_t len = 0;
3066 *cnv.w = ConvertUtf8ToWCharAlloc(value, &len);
3067 if (!*cnv.w || (len > UINT32_MAX / sizeof(WCHAR)))
3068 {
3069 WLog_Print(log, WLOG_ERROR, "license->ProductInfo: %s == %p || %" PRIuz " > UINT32_MAX",
3070 what, (void*)(*cnv.w), len);
3071 return FALSE;
3072 }
3073 *dstLen = (UINT32)(len * sizeof(WCHAR));
3074 return TRUE;
3075}
3076
3077BOOL license_server_configure(rdpLicense* license)
3078{
3079 wStream* s = nullptr;
3080 UINT32 algs[] = { KEY_EXCHANGE_ALG_RSA };
3081
3082 WINPR_ASSERT(license);
3083 WINPR_ASSERT(license->rdp);
3084
3085 const rdpSettings* settings = license->rdp->settings;
3086
3087 const char* CompanyName =
3088 freerdp_settings_get_string(settings, FreeRDP_ServerLicenseCompanyName);
3089
3090 const char* ProductName =
3091 freerdp_settings_get_string(settings, FreeRDP_ServerLicenseProductName);
3092 const UINT32 ProductVersion =
3093 freerdp_settings_get_uint32(settings, FreeRDP_ServerLicenseProductVersion);
3094 const UINT32 issuerCount =
3095 freerdp_settings_get_uint32(settings, FreeRDP_ServerLicenseProductIssuersCount);
3096
3097 const void* ptr = freerdp_settings_get_pointer(settings, FreeRDP_ServerLicenseProductIssuers);
3098 const char** issuers = WINPR_REINTERPRET_CAST(ptr, const void*, const char**);
3099
3100 WINPR_ASSERT(CompanyName);
3101 WINPR_ASSERT(ProductName);
3102 WINPR_ASSERT(ProductVersion > 0);
3103 WINPR_ASSERT(issuers || (issuerCount == 0));
3104
3105 if (!license_ensure_state(license, LICENSE_STATE_INITIAL, LICENSE_REQUEST))
3106 return FALSE;
3107
3108 license->ProductInfo->dwVersion = ProductVersion;
3109 if (!license_set_string(license->log, "pbCompanyName", CompanyName,
3110 &license->ProductInfo->pbCompanyName,
3111 &license->ProductInfo->cbCompanyName))
3112 return FALSE;
3113
3114 if (!license_set_string(license->log, "pbProductId", ProductName,
3115 &license->ProductInfo->pbProductId, &license->ProductInfo->cbProductId))
3116 return FALSE;
3117
3118 if (!license_read_binary_blob_data(license->log, license->KeyExchangeList,
3119 BB_KEY_EXCHG_ALG_BLOB, algs, sizeof(algs)))
3120 return FALSE;
3121
3122 if (!freerdp_certificate_read_server_cert(license->certificate, settings->ServerCertificate,
3123 settings->ServerCertificateLength))
3124 return FALSE;
3125
3126 s = Stream_New(nullptr, 1024);
3127 if (!s)
3128 return FALSE;
3129 else
3130 {
3131 BOOL r = FALSE;
3132 SSIZE_T res =
3133 freerdp_certificate_write_server_cert(license->certificate, CERT_CHAIN_VERSION_2, s);
3134 if (res >= 0)
3135 r = license_read_binary_blob_data(license->log, license->ServerCertificate,
3136 BB_CERTIFICATE_BLOB, Stream_Buffer(s),
3137 Stream_GetPosition(s));
3138
3139 Stream_Free(s, TRUE);
3140 if (!r)
3141 return FALSE;
3142 }
3143
3144 if (!license_scope_list_resize(license->ScopeList, issuerCount))
3145 return FALSE;
3146 for (size_t x = 0; x < issuerCount; x++)
3147 {
3148 LICENSE_BLOB* blob = license->ScopeList->array[x];
3149 const char* name = issuers[x];
3150 const size_t length = strnlen(name, UINT16_MAX) + 1;
3151 if ((length == 0) || (length > UINT16_MAX))
3152 {
3153 WLog_Print(license->log, WLOG_WARN,
3154 "Invalid issuer at position %" PRIuz ": length 0 < %" PRIuz " <= %d"
3155 " ['%s']",
3156 x, length, UINT16_MAX, name);
3157 return FALSE;
3158 }
3159 if (!license_read_binary_blob_data(license->log, blob, BB_SCOPE_BLOB, name, length))
3160 return FALSE;
3161 }
3162
3163 license_set_state(license, LICENSE_STATE_CONFIGURED);
3164 return TRUE;
3165}
3166
3167rdpLicense* license_get(rdpContext* context)
3168{
3169 WINPR_ASSERT(context);
3170 WINPR_ASSERT(context->rdp);
3171 return context->rdp->license;
3172}
WINPR_ATTR_NODISCARD FREERDP_API const void * freerdp_settings_get_pointer(const rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a immutable pointer settings value.
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.