FreeRDP
Loading...
Searching...
No Matches
fastpath.c
1
23#include <freerdp/config.h>
24
25#include "settings.h"
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31#include <winpr/crt.h>
32#include <winpr/assert.h>
33#include <winpr/stream.h>
34
35#include <freerdp/api.h>
36#include <freerdp/log.h>
37#include <freerdp/crypto/per.h>
38
39#include "orders.h"
40#include "update.h"
41#include "surface.h"
42#include "fastpath.h"
43#include "rdp.h"
44
45#include "../cache/pointer.h"
46#include "../cache/palette.h"
47#include "../cache/bitmap.h"
48
49#define TAG FREERDP_TAG("core.fastpath")
50
51enum FASTPATH_INPUT_ENCRYPTION_FLAGS
52{
53 FASTPATH_INPUT_SECURE_CHECKSUM = 0x1,
54 FASTPATH_INPUT_ENCRYPTED = 0x2
55};
56
57enum FASTPATH_OUTPUT_ENCRYPTION_FLAGS
58{
59 FASTPATH_OUTPUT_SECURE_CHECKSUM = 0x1,
60 FASTPATH_OUTPUT_ENCRYPTED = 0x2
61};
62
63struct rdp_fastpath
64{
65 rdpRdp* rdp;
66 wStream* fs;
67 BYTE encryptionFlags;
68 BYTE numberEvents;
69 wStream* updateData;
70 int fragmentation;
71};
72
83static const char* const FASTPATH_UPDATETYPE_STRINGS[] = {
84 "Orders", /* 0x0 */
85 "Bitmap", /* 0x1 */
86 "Palette", /* 0x2 */
87 "Synchronize", /* 0x3 */
88 "Surface Commands", /* 0x4 */
89 "System Pointer Hidden", /* 0x5 */
90 "System Pointer Default", /* 0x6 */
91 "???", /* 0x7 */
92 "Pointer Position", /* 0x8 */
93 "Color Pointer", /* 0x9 */
94 "Cached Pointer", /* 0xA */
95 "New Pointer", /* 0xB */
96};
97
98static const char* fastpath_update_to_string(UINT8 update)
99{
100 if (update >= ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS))
101 return "UNKNOWN";
102
103 return FASTPATH_UPDATETYPE_STRINGS[update];
104}
105
106static BOOL fastpath_read_update_header(wStream* s, BYTE* updateCode, BYTE* fragmentation,
107 BYTE* compression)
108{
109 BYTE updateHeader = 0;
110
111 if (!s || !updateCode || !fragmentation || !compression)
112 return FALSE;
113
114 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
115 return FALSE;
116
117 Stream_Read_UINT8(s, updateHeader);
118 *updateCode = updateHeader & 0x0F;
119 *fragmentation = (updateHeader >> 4) & 0x03;
120 *compression = (updateHeader >> 6) & 0x03;
121 return TRUE;
122}
123
124static BOOL fastpath_write_update_header(wStream* s, const FASTPATH_UPDATE_HEADER* fpUpdateHeader)
125{
126 BYTE updateHeader = 0;
127 WINPR_ASSERT(fpUpdateHeader);
128
129 updateHeader |= fpUpdateHeader->updateCode & 0x0F;
130 updateHeader |= (fpUpdateHeader->fragmentation & 0x03) << 4;
131 updateHeader |= (fpUpdateHeader->compression & 0x03) << 6;
132
133 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 1))
134 return FALSE;
135 Stream_Write_UINT8(s, updateHeader);
136
137 if (fpUpdateHeader->compression)
138 {
139 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 1))
140 return FALSE;
141
142 Stream_Write_UINT8(s, fpUpdateHeader->compressionFlags);
143 }
144
145 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 2))
146 return FALSE;
147
148 Stream_Write_UINT16(s, fpUpdateHeader->size);
149 return TRUE;
150}
151
152static UINT32 fastpath_get_update_header_size(FASTPATH_UPDATE_HEADER* fpUpdateHeader)
153{
154 WINPR_ASSERT(fpUpdateHeader);
155 return (fpUpdateHeader->compression) ? 4 : 3;
156}
157
158static BOOL fastpath_write_update_pdu_header(wStream* s,
159 const FASTPATH_UPDATE_PDU_HEADER* fpUpdatePduHeader,
160 rdpRdp* rdp)
161{
162 BYTE fpOutputHeader = 0;
163 WINPR_ASSERT(fpUpdatePduHeader);
164 WINPR_ASSERT(rdp);
165
166 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 3))
167 return FALSE;
168
169 fpOutputHeader |= (fpUpdatePduHeader->action & 0x03);
170 fpOutputHeader |= (fpUpdatePduHeader->secFlags & 0x03) << 6;
171 Stream_Write_UINT8(s, fpOutputHeader); /* fpOutputHeader (1 byte) */
172 Stream_Write_UINT8(s, 0x80 | (fpUpdatePduHeader->length >> 8)); /* length1 */
173 Stream_Write_UINT8(s, fpUpdatePduHeader->length & 0xFF); /* length2 */
174
175 if (fpUpdatePduHeader->secFlags)
176 {
177 WINPR_ASSERT(rdp->settings);
178 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
179 ENCRYPTION_METHOD_FIPS)
180 {
181 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 4))
182 return FALSE;
183
184 Stream_Write(s, fpUpdatePduHeader->fipsInformation, 4);
185 }
186
187 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
188 return FALSE;
189
190 Stream_Write(s, fpUpdatePduHeader->dataSignature, 8);
191 }
192
193 return TRUE;
194}
195
196static UINT32 fastpath_get_update_pdu_header_size(FASTPATH_UPDATE_PDU_HEADER* fpUpdatePduHeader,
197 rdpRdp* rdp)
198{
199 UINT32 size = 3; /* fpUpdatePduHeader + length1 + length2 */
200
201 if (!fpUpdatePduHeader || !rdp)
202 return 0;
203
204 if (fpUpdatePduHeader->secFlags)
205 {
206 size += 8; /* dataSignature */
207
208 WINPR_ASSERT(rdp->settings);
209 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
210 ENCRYPTION_METHOD_FIPS)
211 size += 4; /* fipsInformation */
212 }
213
214 return size;
215}
216
217BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16* length)
218{
219 BYTE header = 0;
220
221 if (!s || !length)
222 return FALSE;
223
224 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
225 return FALSE;
226
227 Stream_Read_UINT8(s, header);
228
229 if (fastpath)
230 {
231 fastpath->encryptionFlags = (header & 0xC0) >> 6;
232 fastpath->numberEvents = (header & 0x3C) >> 2;
233 }
234
235 if (!per_read_length(s, length))
236 return FALSE;
237
238 const size_t pos = Stream_GetPosition(s);
239 if (pos > *length)
240 return FALSE;
241
242 *length = *length - (UINT16)pos;
243 return TRUE;
244}
245
246static BOOL fastpath_recv_orders(rdpUpdate* update, wStream* s)
247{
248 UINT16 numberOrders = 0;
249
250 if (!s)
251 {
252 WLog_ERR(TAG, "Invalid arguments");
253 return FALSE;
254 }
255
256 if (!update)
257 {
258 WLog_ERR(TAG, "Invalid configuration");
259 return FALSE;
260 }
261
262 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
263 return FALSE;
264
265 Stream_Read_UINT16(s, numberOrders); /* numberOrders (2 bytes) */
266
267 while (numberOrders > 0)
268 {
269 if (!update_recv_order(update, s))
270 return FALSE;
271
272 numberOrders--;
273 }
274
275 return TRUE;
276}
277
278static BOOL fastpath_recv_update_common(rdpUpdate* update, wStream* s)
279{
280 BOOL rc = FALSE;
281 UINT16 updateType = 0;
282 BOOL defaultReturn = 0;
283
284 if (!s)
285 return FALSE;
286
287 if (!update || !update->context)
288 return FALSE;
289
290 rdpContext* context = update->context;
291
292 defaultReturn = freerdp_settings_get_bool(context->settings, FreeRDP_DeactivateClientDecoding);
293
294 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
295 return FALSE;
296
297 Stream_Read_UINT16(s, updateType); /* updateType (2 bytes) */
298 switch (updateType)
299 {
300 case UPDATE_TYPE_BITMAP:
301 {
302 BITMAP_UPDATE* bitmap_update = update_read_bitmap_update(update, s);
303
304 if (!bitmap_update)
305 return FALSE;
306
307 rc = IFCALLRESULT(defaultReturn, update->BitmapUpdate, context, bitmap_update);
308 free_bitmap_update(context, bitmap_update);
309 }
310 break;
311
312 case UPDATE_TYPE_PALETTE:
313 {
314 PALETTE_UPDATE* palette_update = update_read_palette(update, s);
315
316 if (!palette_update)
317 return FALSE;
318
319 rc = IFCALLRESULT(defaultReturn, update->Palette, context, palette_update);
320 free_palette_update(context, palette_update);
321 }
322 break;
323
324 default:
325 break;
326 }
327
328 return rc;
329}
330
331static BOOL fastpath_recv_update_synchronize(WINPR_ATTR_UNUSED rdpFastPath* fastpath, wStream* s)
332{
333 /* server 2008 can send invalid synchronize packet with missing padding,
334 so don't return FALSE even if the packet is invalid */
335 WINPR_ASSERT(fastpath);
336 WINPR_ASSERT(s);
337
338 const size_t len = Stream_GetRemainingLength(s);
339 const size_t skip = MIN(2, len);
340 return Stream_SafeSeek(s, skip); /* size (2 bytes), MUST be set to zero */
341}
342
343static BOOL fastpath_recv_update_paint_block(rdpUpdate* update, wStream* s,
344 BOOL (*fkt)(rdpUpdate*, wStream*))
345{
346 WINPR_ASSERT(fkt);
347 if (!update_begin_paint(update))
348 return FALSE;
349
350 BOOL res = fkt(update, s);
351 if (!update_end_paint(update))
352 return FALSE;
353 return res;
354}
355
356static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* s)
357{
358 BOOL rc = FALSE;
359 int status = 0;
360
361 if (!fastpath || !fastpath->rdp || !s)
362 return -1;
363
364 Stream_SealLength(s);
365 Stream_ResetPosition(s);
366
367 rdpUpdate* update = fastpath->rdp->update;
368
369 if (!update || !update->pointer || !update->context)
370 return -1;
371
372 rdpContext* context = update->context;
373 WINPR_ASSERT(context);
374
375 rdpPointerUpdate* pointer = update->pointer;
376 WINPR_ASSERT(pointer);
377
378#ifdef WITH_DEBUG_RDP
379 DEBUG_RDP(fastpath->rdp, "recv Fast-Path %s Update (0x%02" PRIX8 "), length:%" PRIuz "",
380 fastpath_update_to_string(updateCode), updateCode, Stream_GetRemainingLength(s));
381#endif
382
383 const BOOL defaultReturn =
384 freerdp_settings_get_bool(context->settings, FreeRDP_DeactivateClientDecoding);
385 switch (updateCode)
386 {
387 case FASTPATH_UPDATETYPE_ORDERS:
388 rc = fastpath_recv_update_paint_block(update, s, fastpath_recv_orders);
389 break;
390
391 case FASTPATH_UPDATETYPE_BITMAP:
392 case FASTPATH_UPDATETYPE_PALETTE:
393 rc = fastpath_recv_update_paint_block(update, s, fastpath_recv_update_common);
394 break;
395
396 case FASTPATH_UPDATETYPE_SYNCHRONIZE:
397 if (!fastpath_recv_update_synchronize(fastpath, s))
398 WLog_ERR(TAG, "fastpath_recv_update_synchronize failure but we continue");
399 else
400 rc = IFCALLRESULT(TRUE, update->Synchronize, context);
401
402 break;
403
404 case FASTPATH_UPDATETYPE_SURFCMDS:
405 status = fastpath_recv_update_paint_block(update, s, update_recv_surfcmds);
406 rc = (status >= 0);
407 break;
408
409 case FASTPATH_UPDATETYPE_PTR_NULL:
410 {
411 POINTER_SYSTEM_UPDATE pointer_system = WINPR_C_ARRAY_INIT;
412 pointer_system.type = SYSPTR_NULL;
413 rc = IFCALLRESULT(defaultReturn, pointer->PointerSystem, context, &pointer_system);
414 }
415 break;
416
417 case FASTPATH_UPDATETYPE_PTR_DEFAULT:
418 {
419 POINTER_SYSTEM_UPDATE pointer_system = WINPR_C_ARRAY_INIT;
420 pointer_system.type = SYSPTR_DEFAULT;
421 rc = IFCALLRESULT(defaultReturn, pointer->PointerSystem, context, &pointer_system);
422 }
423 break;
424
425 case FASTPATH_UPDATETYPE_PTR_POSITION:
426 {
427 POINTER_POSITION_UPDATE* pointer_position = update_read_pointer_position(update, s);
428
429 if (pointer_position)
430 {
431 rc = IFCALLRESULT(defaultReturn, pointer->PointerPosition, context,
432 pointer_position);
433 free_pointer_position_update(context, pointer_position);
434 }
435 }
436 break;
437
438 case FASTPATH_UPDATETYPE_COLOR:
439 {
440 POINTER_COLOR_UPDATE* pointer_color = update_read_pointer_color(update, s, 24);
441
442 if (pointer_color)
443 {
444 rc = IFCALLRESULT(defaultReturn, pointer->PointerColor, context, pointer_color);
445 free_pointer_color_update(context, pointer_color);
446 }
447 }
448 break;
449
450 case FASTPATH_UPDATETYPE_CACHED:
451 {
452 POINTER_CACHED_UPDATE* pointer_cached = update_read_pointer_cached(update, s);
453
454 if (pointer_cached)
455 {
456 rc = IFCALLRESULT(defaultReturn, pointer->PointerCached, context, pointer_cached);
457 free_pointer_cached_update(context, pointer_cached);
458 }
459 }
460 break;
461
462 case FASTPATH_UPDATETYPE_POINTER:
463 {
464 POINTER_NEW_UPDATE* pointer_new = update_read_pointer_new(update, s);
465
466 if (pointer_new)
467 {
468 rc = IFCALLRESULT(defaultReturn, pointer->PointerNew, context, pointer_new);
469 free_pointer_new_update(context, pointer_new);
470 }
471 }
472 break;
473
474 case FASTPATH_UPDATETYPE_LARGE_POINTER:
475 {
476 POINTER_LARGE_UPDATE* pointer_large = update_read_pointer_large(update, s);
477
478 if (pointer_large)
479 {
480 rc = IFCALLRESULT(defaultReturn, pointer->PointerLarge, context, pointer_large);
481 free_pointer_large_update(context, pointer_large);
482 }
483 }
484 break;
485 default:
486 break;
487 }
488
489 Stream_ResetPosition(s);
490 if (!rc)
491 {
492 WLog_ERR(TAG, "Fastpath update %s [%" PRIx8 "] failed, status %d",
493 fastpath_update_to_string(updateCode), updateCode, status);
494 return -1;
495 }
496
497 return status;
498}
499
500static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
501{
502 int status = 0;
503 UINT16 size = 0;
504 BYTE updateCode = 0;
505 BYTE fragmentation = 0;
506 BYTE compression = 0;
507 BYTE compressionFlags = 0;
508 UINT32 DstSize = 0;
509 const BYTE* pDstData = nullptr;
510
511 if (!fastpath || !s)
512 return -1;
513
514 rdpRdp* rdp = fastpath->rdp;
515
516 if (!rdp)
517 return -1;
518
519 rdpTransport* transport = rdp->transport;
520
521 if (!transport)
522 return -1;
523
524 if (!fastpath_read_update_header(s, &updateCode, &fragmentation, &compression))
525 return -1;
526
527 if (compression == FASTPATH_OUTPUT_COMPRESSION_USED)
528 {
529 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
530 return -1;
531
532 Stream_Read_UINT8(s, compressionFlags);
533 }
534 else
535 compressionFlags = 0;
536
537 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
538 return -1;
539
540 Stream_Read_UINT16(s, size);
541
542 if (!Stream_CheckAndLogRequiredLength(TAG, s, size))
543 return -1;
544
545 const int bulkStatus =
546 bulk_decompress(rdp->bulk, Stream_Pointer(s), size, &pDstData, &DstSize, compressionFlags);
547 Stream_Seek(s, size);
548
549 if (bulkStatus < 0)
550 {
551 WLog_ERR(TAG, "bulk_decompress() failed");
552 return -1;
553 }
554
555 if (!Stream_EnsureRemainingCapacity(fastpath->updateData, DstSize))
556 return -1;
557
558 Stream_Write(fastpath->updateData, pDstData, DstSize);
559
560 if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
561 {
562 if (fastpath->fragmentation != -1)
563 {
564 WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_SINGLE");
565 goto out_fail;
566 }
567
568 status = fastpath_recv_update(fastpath, updateCode, fastpath->updateData);
569
570 if (status < 0)
571 {
572 WLog_ERR(TAG, "fastpath_recv_update() - %i", status);
573 goto out_fail;
574 }
575 }
576 else
577 {
578 rdpContext* context = nullptr;
579 const size_t totalSize = Stream_GetPosition(fastpath->updateData);
580
581 context = transport_get_context(transport);
582 WINPR_ASSERT(context);
583 WINPR_ASSERT(context->settings);
584
585 if (totalSize >
586 freerdp_settings_get_uint32(context->settings, FreeRDP_MultifragMaxRequestSize))
587 {
588 WLog_ERR(
589 TAG, "Total size (%" PRIuz ") exceeds MultifragMaxRequestSize (%" PRIu32 ")",
590 totalSize,
591 freerdp_settings_get_uint32(context->settings, FreeRDP_MultifragMaxRequestSize));
592 goto out_fail;
593 }
594
595 if (fragmentation == FASTPATH_FRAGMENT_FIRST)
596 {
597 if (fastpath->fragmentation != -1)
598 {
599 WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_FIRST");
600 goto out_fail;
601 }
602
603 fastpath->fragmentation = FASTPATH_FRAGMENT_FIRST;
604 }
605 else if (fragmentation == FASTPATH_FRAGMENT_NEXT)
606 {
607 if ((fastpath->fragmentation != FASTPATH_FRAGMENT_FIRST) &&
608 (fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
609 {
610 WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_NEXT");
611 goto out_fail;
612 }
613
614 fastpath->fragmentation = FASTPATH_FRAGMENT_NEXT;
615 }
616 else if (fragmentation == FASTPATH_FRAGMENT_LAST)
617 {
618 if ((fastpath->fragmentation != FASTPATH_FRAGMENT_FIRST) &&
619 (fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
620 {
621 WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_LAST");
622 goto out_fail;
623 }
624
625 fastpath->fragmentation = -1;
626 status = fastpath_recv_update(fastpath, updateCode, fastpath->updateData);
627
628 if (status < 0)
629 {
630 WLog_ERR(TAG, "fastpath_recv_update() - %i", status);
631 goto out_fail;
632 }
633 }
634 }
635
636 return status;
637out_fail:
638 return -1;
639}
640
641state_run_t fastpath_recv_updates(rdpFastPath* fastpath, wStream* s)
642{
643 state_run_t rc = STATE_RUN_FAILED;
644
645 WINPR_ASSERT(s);
646 WINPR_ASSERT(fastpath);
647 WINPR_ASSERT(fastpath->rdp);
648
649 while (Stream_GetRemainingLength(s) >= 3)
650 {
651 if (fastpath_recv_update_data(fastpath, s) < 0)
652 {
653 WLog_ERR(TAG, "fastpath_recv_update_data() fail");
654 rc = STATE_RUN_FAILED;
655 goto fail;
656 }
657 }
658
659 rc = STATE_RUN_SUCCESS;
660fail:
661
662 return rc;
663}
664
665static BOOL fastpath_read_input_event_header(wStream* s, BYTE* eventFlags, BYTE* eventCode)
666{
667 BYTE eventHeader = 0;
668
669 WINPR_ASSERT(s);
670 WINPR_ASSERT(eventFlags);
671 WINPR_ASSERT(eventCode);
672
673 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
674 return FALSE;
675
676 Stream_Read_UINT8(s, eventHeader); /* eventHeader (1 byte) */
677 *eventFlags = (eventHeader & 0x1F);
678 *eventCode = (eventHeader >> 5);
679 return TRUE;
680}
681
682static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
683{
684 WINPR_ASSERT(fastpath);
685 WINPR_ASSERT(fastpath->rdp);
686 WINPR_ASSERT(fastpath->rdp->input);
687 WINPR_ASSERT(s);
688
689 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
690 return FALSE;
691
692 rdpInput* input = fastpath->rdp->input;
693
694 const UINT8 code = Stream_Get_UINT8(s); /* keyCode (1 byte) */
695
696 UINT16 flags = 0;
697 if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
698 flags |= KBD_FLAGS_RELEASE;
699
700 if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED))
701 flags |= KBD_FLAGS_EXTENDED;
702
703 if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_PREFIX_E1))
704 flags |= KBD_FLAGS_EXTENDED1;
705
706 return IFCALLRESULT(TRUE, input->KeyboardEvent, input, flags, code);
707}
708
709static BOOL fastpath_recv_input_event_mouse(rdpFastPath* fastpath, wStream* s,
710 WINPR_ATTR_UNUSED BYTE eventFlags)
711{
712 rdpInput* input = nullptr;
713 UINT16 pointerFlags = 0;
714 UINT16 xPos = 0;
715 UINT16 yPos = 0;
716 WINPR_ASSERT(fastpath);
717 WINPR_ASSERT(fastpath->rdp);
718 WINPR_ASSERT(fastpath->rdp->input);
719 WINPR_ASSERT(s);
720
721 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
722 return FALSE;
723
724 input = fastpath->rdp->input;
725
726 Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
727 Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
728 Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
729 return IFCALLRESULT(TRUE, input->MouseEvent, input, pointerFlags, xPos, yPos);
730}
731
732static BOOL fastpath_recv_input_event_relmouse(rdpFastPath* fastpath, wStream* s,
733 WINPR_ATTR_UNUSED BYTE eventFlags)
734{
735 rdpInput* input = nullptr;
736 UINT16 pointerFlags = 0;
737 INT16 xDelta = 0;
738 INT16 yDelta = 0;
739 WINPR_ASSERT(fastpath);
740 WINPR_ASSERT(fastpath->rdp);
741 WINPR_ASSERT(fastpath->rdp->context);
742 WINPR_ASSERT(fastpath->rdp->input);
743 WINPR_ASSERT(s);
744
745 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
746 return FALSE;
747
748 input = fastpath->rdp->input;
749
750 Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
751 Stream_Read_INT16(s, xDelta); /* xDelta (2 bytes) */
752 Stream_Read_INT16(s, yDelta); /* yDelta (2 bytes) */
753
754 if (!freerdp_settings_get_bool(input->context->settings, FreeRDP_HasRelativeMouseEvent))
755 {
756 WLog_ERR(TAG,
757 "Received relative mouse event(flags=0x%04" PRIx16 ", xPos=%" PRId16
758 ", yPos=%" PRId16 "), but we did not announce support for that",
759 pointerFlags, xDelta, yDelta);
760 return FALSE;
761 }
762
763 return IFCALLRESULT(TRUE, input->RelMouseEvent, input, pointerFlags, xDelta, yDelta);
764}
765
766static BOOL fastpath_recv_input_event_qoe(rdpFastPath* fastpath, wStream* s,
767 WINPR_ATTR_UNUSED BYTE eventFlags)
768{
769 WINPR_ASSERT(fastpath);
770 WINPR_ASSERT(fastpath->rdp);
771 WINPR_ASSERT(fastpath->rdp->context);
772 WINPR_ASSERT(fastpath->rdp->input);
773 WINPR_ASSERT(s);
774
775 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
776 return FALSE;
777
778 rdpInput* input = fastpath->rdp->input;
779
780 UINT32 timestampMS = 0;
781 Stream_Read_UINT32(s, timestampMS); /* timestamp (4 bytes) */
782
783 if (!freerdp_settings_get_bool(input->context->settings, FreeRDP_HasQoeEvent))
784 {
785 WLog_ERR(TAG,
786 "Received qoe event(timestamp=%" PRIu32
787 "ms), but we did not announce support for that",
788 timestampMS);
789 return FALSE;
790 }
791
792 return IFCALLRESULT(TRUE, input->QoEEvent, input, timestampMS);
793}
794
795static BOOL fastpath_recv_input_event_mousex(rdpFastPath* fastpath, wStream* s,
796 WINPR_ATTR_UNUSED BYTE eventFlags)
797{
798 rdpInput* input = nullptr;
799 UINT16 pointerFlags = 0;
800 UINT16 xPos = 0;
801 UINT16 yPos = 0;
802
803 WINPR_ASSERT(fastpath);
804 WINPR_ASSERT(fastpath->rdp);
805 WINPR_ASSERT(fastpath->rdp->context);
806 WINPR_ASSERT(fastpath->rdp->input);
807 WINPR_ASSERT(s);
808
809 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
810 return FALSE;
811
812 input = fastpath->rdp->input;
813
814 Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
815 Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
816 Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
817
818 if (!freerdp_settings_get_bool(input->context->settings, FreeRDP_HasExtendedMouseEvent))
819 {
820 WLog_ERR(TAG,
821 "Received extended mouse event(flags=0x%04" PRIx16 ", xPos=%" PRIu16
822 ", yPos=%" PRIu16 "), but we did not announce support for that",
823 pointerFlags, xPos, yPos);
824 return FALSE;
825 }
826
827 return IFCALLRESULT(TRUE, input->ExtendedMouseEvent, input, pointerFlags, xPos, yPos);
828}
829
830static BOOL fastpath_recv_input_event_sync(rdpFastPath* fastpath, WINPR_ATTR_UNUSED wStream* s,
831 BYTE eventFlags)
832{
833 rdpInput* input = nullptr;
834
835 WINPR_ASSERT(fastpath);
836 WINPR_ASSERT(fastpath->rdp);
837 WINPR_ASSERT(fastpath->rdp->input);
838 WINPR_ASSERT(s);
839
840 input = fastpath->rdp->input;
841 return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, eventFlags);
842}
843
844static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
845{
846 UINT16 unicodeCode = 0;
847 UINT16 flags = 0;
848
849 WINPR_ASSERT(fastpath);
850 WINPR_ASSERT(s);
851
852 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
853 return FALSE;
854
855 Stream_Read_UINT16(s, unicodeCode); /* unicodeCode (2 bytes) */
856 flags = 0;
857
858 if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
859 flags |= KBD_FLAGS_RELEASE;
860
861 WINPR_ASSERT(fastpath->rdp);
862 WINPR_ASSERT(fastpath->rdp);
863 WINPR_ASSERT(fastpath->rdp->input);
864 return IFCALLRESULT(FALSE, fastpath->rdp->input->UnicodeKeyboardEvent, fastpath->rdp->input,
865 flags, unicodeCode);
866}
867
868static BOOL fastpath_recv_input_event(rdpFastPath* fastpath, wStream* s)
869{
870 BYTE eventFlags = 0;
871 BYTE eventCode = 0;
872
873 WINPR_ASSERT(fastpath);
874 WINPR_ASSERT(s);
875
876 if (!fastpath_read_input_event_header(s, &eventFlags, &eventCode))
877 return FALSE;
878
879 switch (eventCode)
880 {
881 case FASTPATH_INPUT_EVENT_SCANCODE:
882 if (!fastpath_recv_input_event_scancode(fastpath, s, eventFlags))
883 return FALSE;
884
885 break;
886
887 case FASTPATH_INPUT_EVENT_MOUSE:
888 if (!fastpath_recv_input_event_mouse(fastpath, s, eventFlags))
889 return FALSE;
890
891 break;
892
893 case FASTPATH_INPUT_EVENT_MOUSEX:
894 if (!fastpath_recv_input_event_mousex(fastpath, s, eventFlags))
895 return FALSE;
896
897 break;
898
899 case FASTPATH_INPUT_EVENT_SYNC:
900 if (!fastpath_recv_input_event_sync(fastpath, s, eventFlags))
901 return FALSE;
902
903 break;
904
905 case FASTPATH_INPUT_EVENT_UNICODE:
906 if (!fastpath_recv_input_event_unicode(fastpath, s, eventFlags))
907 return FALSE;
908
909 break;
910
911 case TS_FP_RELPOINTER_EVENT:
912 if (!fastpath_recv_input_event_relmouse(fastpath, s, eventFlags))
913 return FALSE;
914
915 break;
916
917 case TS_FP_QOETIMESTAMP_EVENT:
918 if (!fastpath_recv_input_event_qoe(fastpath, s, eventFlags))
919 return FALSE;
920 break;
921
922 default:
923 WLog_ERR(TAG, "Unknown eventCode %" PRIu8 "", eventCode);
924 break;
925 }
926
927 return TRUE;
928}
929
930state_run_t fastpath_recv_inputs(rdpFastPath* fastpath, wStream* s)
931{
932 WINPR_ASSERT(fastpath);
933 WINPR_ASSERT(s);
934
935 if (fastpath->numberEvents == 0)
936 {
941 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
942 return STATE_RUN_FAILED;
943
944 Stream_Read_UINT8(s, fastpath->numberEvents); /* eventHeader (1 byte) */
945 }
946
947 for (BYTE i = 0; i < fastpath->numberEvents; i++)
948 {
949 if (!fastpath_recv_input_event(fastpath, s))
950 return STATE_RUN_FAILED;
951 }
952
953 return STATE_RUN_SUCCESS;
954}
955
956static UINT32 fastpath_get_sec_bytes(rdpRdp* rdp)
957{
958 UINT32 sec_bytes = 0;
959 sec_bytes = 0;
960
961 if (!rdp)
962 return 0;
963
964 if (rdp->do_crypt)
965 {
966 sec_bytes = 8;
967
968 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
969 ENCRYPTION_METHOD_FIPS)
970 sec_bytes += 4;
971 }
972
973 return sec_bytes;
974}
975
976wStream* fastpath_input_pdu_init_header(rdpFastPath* fastpath, UINT16* sec_flags)
977{
978 if (!fastpath || !fastpath->rdp)
979 return nullptr;
980
981 rdpRdp* rdp = fastpath->rdp;
982 wStream* s = transport_send_stream_init(rdp->transport, 256);
983
984 if (!s)
985 return nullptr;
986
987 Stream_Seek(s, 3); /* fpInputHeader, length1 and length2 */
988
989 if (rdp->do_crypt)
990 {
991 *sec_flags |= SEC_ENCRYPT;
992
993 if (rdp->do_secure_checksum)
994 *sec_flags |= SEC_SECURE_CHECKSUM;
995 }
996
997 Stream_Seek(s, fastpath_get_sec_bytes(rdp));
998 return s;
999}
1000
1001wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode,
1002 UINT16* sec_flags)
1003{
1004 wStream* s = nullptr;
1005 s = fastpath_input_pdu_init_header(fastpath, sec_flags);
1006
1007 if (!s)
1008 return nullptr;
1009
1010 WINPR_ASSERT(eventCode < 8);
1011 WINPR_ASSERT(eventFlags < 0x20);
1012 Stream_Write_UINT8(s, (UINT8)(eventFlags | (eventCode << 5))); /* eventHeader (1 byte) */
1013 return s;
1014}
1015
1016BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, size_t iNumEvents,
1017 UINT16 sec_flags)
1018{
1019 BOOL rc = FALSE;
1020 BYTE eventHeader = 0;
1021 BOOL should_unlock = FALSE;
1022 rdpRdp* rdp = nullptr;
1023
1024 WINPR_ASSERT(iNumEvents > 0);
1025 if (!s)
1026 return FALSE;
1027
1028 if (!fastpath)
1029 goto fail;
1030
1031 rdp = fastpath->rdp;
1032 WINPR_ASSERT(rdp);
1033
1034 {
1035 const CONNECTION_STATE state = rdp_get_state(rdp);
1036 if (!rdp_is_active_state(rdp))
1037 {
1038 WLog_WARN(TAG, "called before activation [%s]", rdp_state_string(state));
1039 goto fail;
1040 }
1041 }
1042
1043 /*
1044 * A maximum of 15 events are allowed per request
1045 * if the optional numEvents field isn't used
1046 * see MS-RDPBCGR 2.2.8.1.2 for details
1047 */
1048 if (iNumEvents > 15)
1049 goto fail;
1050
1051 {
1052 size_t length = Stream_GetPosition(s);
1053
1054 if (length >= (2u << 14))
1055 {
1056 WLog_ERR(TAG, "Maximum FastPath PDU length is 32767");
1057 goto fail;
1058 }
1059
1060 eventHeader = FASTPATH_INPUT_ACTION_FASTPATH;
1061 eventHeader |= (iNumEvents << 2); /* numberEvents */
1062
1063 if (sec_flags & SEC_ENCRYPT)
1064 eventHeader |= (FASTPATH_INPUT_ENCRYPTED << 6);
1065
1066 if (sec_flags & SEC_SECURE_CHECKSUM)
1067 eventHeader |= (FASTPATH_INPUT_SECURE_CHECKSUM << 6);
1068
1069 Stream_ResetPosition(s);
1070 Stream_Write_UINT8(s, eventHeader);
1071 /* Write length later, RDP encryption might add a padding */
1072 Stream_Seek(s, 2);
1073
1074 if (sec_flags & SEC_ENCRYPT)
1075 {
1076 security_lock(rdp);
1077 should_unlock = TRUE;
1078
1079 const size_t sec_bytes = fastpath_get_sec_bytes(fastpath->rdp);
1080 if (sec_bytes + 3ULL > length)
1081 goto fail;
1082
1083 BYTE* fpInputEvents = Stream_PointerAs(s, BYTE) + sec_bytes;
1084 const UINT16 fpInputEvents_length = (UINT16)(length - 3 - sec_bytes);
1085
1086 WINPR_ASSERT(rdp->settings);
1087 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
1088 ENCRYPTION_METHOD_FIPS)
1089 {
1090 BYTE pad = 0;
1091
1092 if ((pad = 8 - (fpInputEvents_length % 8)) == 8)
1093 pad = 0;
1094
1095 Stream_Write_UINT16(s, 0x10); /* length */
1096 Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/
1097 Stream_Write_UINT8(s, pad); /* padding */
1098
1099 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
1100 goto fail;
1101
1102 if (!security_hmac_signature(fpInputEvents, fpInputEvents_length, Stream_Pointer(s),
1103 8, rdp))
1104 goto fail;
1105
1106 if (pad)
1107 memset(fpInputEvents + fpInputEvents_length, 0, pad);
1108
1109 if (!security_fips_encrypt(fpInputEvents, fpInputEvents_length + pad, rdp))
1110 goto fail;
1111
1112 length += pad;
1113 }
1114 else
1115 {
1116 BOOL res = 0;
1117 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
1118 goto fail;
1119 if (sec_flags & SEC_SECURE_CHECKSUM)
1120 res = security_salted_mac_signature(rdp, fpInputEvents, fpInputEvents_length,
1121 TRUE, Stream_Pointer(s), 8);
1122 else
1123 res = security_mac_signature(rdp, fpInputEvents, fpInputEvents_length,
1124 Stream_Pointer(s), 8);
1125
1126 if (!res || !security_encrypt(fpInputEvents, fpInputEvents_length, rdp))
1127 goto fail;
1128 }
1129 }
1130
1131 /*
1132 * We always encode length in two bytes, even though we could use
1133 * only one byte if length <= 0x7F. It is just easier that way,
1134 * because we can leave room for fixed-length header, store all
1135 * the data first and then store the header.
1136 */
1137 WINPR_ASSERT(length < UINT16_MAX);
1138 if (!Stream_SetPosition(s, 1))
1139 goto fail;
1140 Stream_Write_UINT16_BE(s, 0x8000 | (UINT16)length);
1141 if (!Stream_SetPosition(s, length))
1142 goto fail;
1143 Stream_SealLength(s);
1144 }
1145
1146 if (transport_write(rdp->transport, s) < 0)
1147 goto fail;
1148
1149 rc = TRUE;
1150fail:
1151 if (should_unlock)
1152 security_unlock(rdp);
1153 Stream_Release(s);
1154 return rc;
1155}
1156
1157BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s, UINT16 sec_flags)
1158{
1159 return fastpath_send_multiple_input_pdu(fastpath, s, 1, sec_flags);
1160}
1161
1162wStream* fastpath_update_pdu_init(rdpFastPath* fastpath)
1163{
1164 return transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE);
1165}
1166
1167wStream* fastpath_update_pdu_init_new(WINPR_ATTR_UNUSED rdpFastPath* fastpath)
1168{
1169 wStream* s = nullptr;
1170 s = Stream_New(nullptr, FASTPATH_MAX_PACKET_SIZE);
1171 return s;
1172}
1173
1174BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s,
1175 BOOL skipCompression)
1176{
1177 BOOL status = TRUE;
1178 wStream* fs = nullptr;
1179 rdpSettings* settings = nullptr;
1180 rdpRdp* rdp = nullptr;
1181 UINT32 fpHeaderSize = 6;
1182 UINT32 fpUpdatePduHeaderSize = 0;
1183 UINT32 fpUpdateHeaderSize = 0;
1184 FASTPATH_UPDATE_PDU_HEADER fpUpdatePduHeader = WINPR_C_ARRAY_INIT;
1185 FASTPATH_UPDATE_HEADER fpUpdateHeader = WINPR_C_ARRAY_INIT;
1186 UINT16 sec_flags = 0;
1187
1188 if (!fastpath || !fastpath->rdp || !fastpath->fs || !s)
1189 return FALSE;
1190
1191 rdp = fastpath->rdp;
1192 fs = fastpath->fs;
1193 settings = rdp->settings;
1194
1195 if (!settings)
1196 return FALSE;
1197
1198 UINT16 maxLength = FASTPATH_MAX_PACKET_SIZE - 20;
1199
1200 if (freerdp_settings_get_bool(rdp->settings, FreeRDP_CompressionEnabled) && !skipCompression)
1201 {
1202 const UINT16 CompressionMaxSize = bulk_compression_max_size(rdp->bulk);
1203 maxLength = (maxLength < CompressionMaxSize) ? maxLength : CompressionMaxSize;
1204 maxLength -= 20;
1205 }
1206
1207 size_t totalLength = Stream_GetPosition(s);
1208 Stream_ResetPosition(s);
1209
1210 /* check if fast path output is possible */
1211 if (!freerdp_settings_get_bool(rdp->settings, FreeRDP_FastPathOutput))
1212 {
1213 WLog_ERR(TAG, "client does not support fast path output");
1214 return FALSE;
1215 }
1216
1217 /* check if the client's fast path pdu buffer is large enough */
1218 if (totalLength > freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize))
1219 {
1220 WLog_ERR(TAG,
1221 "fast path update size (%" PRIuz
1222 ") exceeds the client's maximum request size (%" PRIu32 ")",
1223 totalLength,
1224 freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize));
1225 return FALSE;
1226 }
1227
1228 if (rdp->do_crypt)
1229 {
1230 sec_flags |= SEC_ENCRYPT;
1231
1232 if (rdp->do_secure_checksum)
1233 sec_flags |= SEC_SECURE_CHECKSUM;
1234 }
1235
1236 for (int fragment = 0; (totalLength > 0) || (fragment == 0); fragment++)
1237 {
1238 UINT32 DstSize = 0;
1239 const BYTE* pDstData = nullptr;
1240 UINT32 compressionFlags = 0;
1241 BYTE pad = 0;
1242 BYTE* pSignature = nullptr;
1243 fpUpdatePduHeader.action = 0;
1244 fpUpdatePduHeader.secFlags = 0;
1245 fpUpdateHeader.compression = 0;
1246 fpUpdateHeader.compressionFlags = 0;
1247 fpUpdateHeader.updateCode = updateCode;
1248 fpUpdateHeader.size = (UINT16)(totalLength > maxLength) ? maxLength : (UINT16)totalLength;
1249 const BYTE* pSrcData = Stream_Pointer(s);
1250 UINT32 SrcSize = DstSize = fpUpdateHeader.size;
1251 BOOL should_unlock = FALSE;
1252
1253 if (sec_flags & SEC_ENCRYPT)
1254 fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_ENCRYPTED;
1255
1256 if (sec_flags & SEC_SECURE_CHECKSUM)
1257 fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_SECURE_CHECKSUM;
1258
1259 if (freerdp_settings_get_bool(settings, FreeRDP_CompressionEnabled) && !skipCompression)
1260 {
1261 if (bulk_compress(rdp->bulk, pSrcData, SrcSize, &pDstData, &DstSize,
1262 &compressionFlags) >= 0)
1263 {
1264 if (compressionFlags)
1265 {
1266 WINPR_ASSERT(compressionFlags <= UINT8_MAX);
1267 fpUpdateHeader.compressionFlags = (UINT8)compressionFlags;
1268 fpUpdateHeader.compression = FASTPATH_OUTPUT_COMPRESSION_USED;
1269 }
1270 }
1271 }
1272
1273 if (!fpUpdateHeader.compression)
1274 {
1275 pDstData = Stream_Pointer(s);
1276 DstSize = fpUpdateHeader.size;
1277 }
1278
1279 if (DstSize > UINT16_MAX)
1280 return FALSE;
1281 fpUpdateHeader.size = (UINT16)DstSize;
1282 totalLength -= SrcSize;
1283
1284 if (totalLength == 0)
1285 fpUpdateHeader.fragmentation =
1286 (fragment == 0) ? FASTPATH_FRAGMENT_SINGLE : FASTPATH_FRAGMENT_LAST;
1287 else
1288 fpUpdateHeader.fragmentation =
1289 (fragment == 0) ? FASTPATH_FRAGMENT_FIRST : FASTPATH_FRAGMENT_NEXT;
1290
1291 fpUpdateHeaderSize = fastpath_get_update_header_size(&fpUpdateHeader);
1292 fpUpdatePduHeaderSize = fastpath_get_update_pdu_header_size(&fpUpdatePduHeader, rdp);
1293 fpHeaderSize = fpUpdateHeaderSize + fpUpdatePduHeaderSize;
1294
1295 if (sec_flags & SEC_ENCRYPT)
1296 {
1297 pSignature = Stream_Buffer(fs) + 3;
1298
1299 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
1300 ENCRYPTION_METHOD_FIPS)
1301 {
1302 pSignature += 4;
1303
1304 if ((pad = 8 - ((DstSize + fpUpdateHeaderSize) % 8)) == 8)
1305 pad = 0;
1306
1307 fpUpdatePduHeader.fipsInformation[0] = 0x10;
1308 fpUpdatePduHeader.fipsInformation[1] = 0x00;
1309 fpUpdatePduHeader.fipsInformation[2] = 0x01;
1310 fpUpdatePduHeader.fipsInformation[3] = pad;
1311 }
1312 }
1313
1314 const size_t len = fpUpdateHeader.size + fpHeaderSize + pad;
1315 if (len > UINT16_MAX)
1316 return FALSE;
1317
1318 fpUpdatePduHeader.length = (UINT16)len;
1319 Stream_ResetPosition(fs);
1320 if (!fastpath_write_update_pdu_header(fs, &fpUpdatePduHeader, rdp))
1321 return FALSE;
1322 if (!fastpath_write_update_header(fs, &fpUpdateHeader))
1323 return FALSE;
1324
1325 if (!Stream_CheckAndLogRequiredCapacity(TAG, (fs), (size_t)DstSize + pad))
1326 return FALSE;
1327 Stream_Write(fs, pDstData, DstSize);
1328
1329 if (pad)
1330 Stream_Zero(fs, pad);
1331
1332 BOOL res = FALSE;
1333 if (sec_flags & SEC_ENCRYPT)
1334 {
1335 security_lock(rdp);
1336
1337 should_unlock = TRUE;
1338 UINT32 dataSize = fpUpdateHeaderSize + DstSize + pad;
1339 BYTE* data = Stream_PointerAs(fs, BYTE) - dataSize;
1340
1341 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
1342 ENCRYPTION_METHOD_FIPS)
1343 {
1344 // TODO: Ensure stream capacity
1345 if (!security_hmac_signature(data, dataSize - pad, pSignature, 8, rdp))
1346 goto unlock;
1347
1348 if (!security_fips_encrypt(data, dataSize, rdp))
1349 goto unlock;
1350 }
1351 else
1352 {
1353 // TODO: Ensure stream capacity
1354 if (sec_flags & SEC_SECURE_CHECKSUM)
1355 status =
1356 security_salted_mac_signature(rdp, data, dataSize, TRUE, pSignature, 8);
1357 else
1358 status = security_mac_signature(rdp, data, dataSize, pSignature, 8);
1359
1360 if (!status || !security_encrypt(data, dataSize, rdp))
1361 goto unlock;
1362 }
1363 }
1364 res = TRUE;
1365
1366 Stream_SealLength(fs);
1367
1368 if (transport_write(rdp->transport, fs) < 0)
1369 {
1370 status = FALSE;
1371 }
1372
1373 unlock:
1374 if (should_unlock)
1375 security_unlock(rdp);
1376
1377 if (!res || !status)
1378 return FALSE;
1379
1380 Stream_Seek(s, SrcSize);
1381 }
1382
1383 return status;
1384}
1385
1386rdpFastPath* fastpath_new(rdpRdp* rdp)
1387{
1388 rdpFastPath* fastpath = nullptr;
1389
1390 WINPR_ASSERT(rdp);
1391
1392 fastpath = (rdpFastPath*)calloc(1, sizeof(rdpFastPath));
1393
1394 if (!fastpath)
1395 return nullptr;
1396
1397 fastpath->rdp = rdp;
1398 fastpath->fragmentation = -1;
1399 fastpath->fs = Stream_New(nullptr, FASTPATH_MAX_PACKET_SIZE);
1400 fastpath->updateData = Stream_New(nullptr, FASTPATH_MAX_PACKET_SIZE);
1401
1402 if (!fastpath->fs || !fastpath->updateData)
1403 goto out_free;
1404
1405 return fastpath;
1406out_free:
1407 fastpath_free(fastpath);
1408 return nullptr;
1409}
1410
1411void fastpath_free(rdpFastPath* fastpath)
1412{
1413 if (fastpath)
1414 {
1415 Stream_Free(fastpath->updateData, TRUE);
1416 Stream_Free(fastpath->fs, TRUE);
1417 free(fastpath);
1418 }
1419}
1420
1421BYTE fastpath_get_encryption_flags(rdpFastPath* fastpath)
1422{
1423 WINPR_ASSERT(fastpath);
1424 return fastpath->encryptionFlags;
1425}
1426
1427BOOL fastpath_decrypt(rdpFastPath* fastpath, wStream* s, UINT16* length)
1428{
1429 WINPR_ASSERT(fastpath);
1430 if (fastpath_get_encryption_flags(fastpath) & FASTPATH_OUTPUT_ENCRYPTED)
1431 {
1432 const UINT16 flags =
1433 (fastpath_get_encryption_flags(fastpath) & FASTPATH_OUTPUT_SECURE_CHECKSUM)
1434 ? SEC_SECURE_CHECKSUM
1435 : 0;
1436
1437 if (!rdp_decrypt(fastpath->rdp, s, length, flags))
1438 return FALSE;
1439 }
1440
1441 return TRUE;
1442}
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.