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
960 if (!rdp)
961 return 0;
962
963 if (rdp->do_crypt)
964 {
965 sec_bytes = 8;
966
967 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
968 ENCRYPTION_METHOD_FIPS)
969 sec_bytes += 4;
970 }
971
972 return sec_bytes;
973}
974
975wStream* fastpath_input_pdu_init_header(rdpFastPath* fastpath, UINT16* sec_flags)
976{
977 if (!fastpath || !fastpath->rdp)
978 return nullptr;
979
980 rdpRdp* rdp = fastpath->rdp;
981 wStream* s = transport_send_stream_init(rdp->transport, 256);
982
983 if (!s)
984 return nullptr;
985
986 Stream_Seek(s, 3); /* fpInputHeader, length1 and length2 */
987
988 if (rdp->do_crypt)
989 {
990 *sec_flags |= SEC_ENCRYPT;
991
992 if (rdp->do_secure_checksum)
993 *sec_flags |= SEC_SECURE_CHECKSUM;
994 }
995
996 Stream_Seek(s, fastpath_get_sec_bytes(rdp));
997 return s;
998}
999
1000wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode,
1001 UINT16* sec_flags)
1002{
1003 wStream* s = nullptr;
1004 s = fastpath_input_pdu_init_header(fastpath, sec_flags);
1005
1006 if (!s)
1007 return nullptr;
1008
1009 WINPR_ASSERT(eventCode < 8);
1010 WINPR_ASSERT(eventFlags < 0x20);
1011 Stream_Write_UINT8(s, (UINT8)(eventFlags | (eventCode << 5))); /* eventHeader (1 byte) */
1012 return s;
1013}
1014
1015BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, size_t iNumEvents,
1016 UINT16 sec_flags)
1017{
1018 BOOL rc = FALSE;
1019 BYTE eventHeader = 0;
1020 BOOL should_unlock = FALSE;
1021 rdpRdp* rdp = nullptr;
1022
1023 WINPR_ASSERT(iNumEvents > 0);
1024 if (!s)
1025 return FALSE;
1026
1027 if (!fastpath)
1028 goto fail;
1029
1030 rdp = fastpath->rdp;
1031 WINPR_ASSERT(rdp);
1032
1033 {
1034 const CONNECTION_STATE state = rdp_get_state(rdp);
1035 if (!rdp_is_active_state(rdp))
1036 {
1037 WLog_WARN(TAG, "called before activation [%s]", rdp_state_string(state));
1038 goto fail;
1039 }
1040 }
1041
1042 /*
1043 * A maximum of 15 events are allowed per request
1044 * if the optional numEvents field isn't used
1045 * see MS-RDPBCGR 2.2.8.1.2 for details
1046 */
1047 if (iNumEvents > 15)
1048 goto fail;
1049
1050 {
1051 size_t length = Stream_GetPosition(s);
1052
1053 if (length >= (2u << 14))
1054 {
1055 WLog_ERR(TAG, "Maximum FastPath PDU length is 32767");
1056 goto fail;
1057 }
1058
1059 eventHeader = FASTPATH_INPUT_ACTION_FASTPATH;
1060 eventHeader |= (iNumEvents << 2); /* numberEvents */
1061
1062 if (sec_flags & SEC_ENCRYPT)
1063 eventHeader |= (FASTPATH_INPUT_ENCRYPTED << 6);
1064
1065 if (sec_flags & SEC_SECURE_CHECKSUM)
1066 eventHeader |= (FASTPATH_INPUT_SECURE_CHECKSUM << 6);
1067
1068 Stream_ResetPosition(s);
1069 Stream_Write_UINT8(s, eventHeader);
1070 /* Write length later, RDP encryption might add a padding */
1071 Stream_Seek(s, 2);
1072
1073 if (sec_flags & SEC_ENCRYPT)
1074 {
1075 security_lock(rdp);
1076 should_unlock = TRUE;
1077
1078 const size_t sec_bytes = fastpath_get_sec_bytes(fastpath->rdp);
1079 if (sec_bytes + 3ULL > length)
1080 goto fail;
1081
1082 BYTE* fpInputEvents = Stream_PointerAs(s, BYTE) + sec_bytes;
1083 const UINT16 fpInputEvents_length = (UINT16)(length - 3 - sec_bytes);
1084
1085 WINPR_ASSERT(rdp->settings);
1086 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
1087 ENCRYPTION_METHOD_FIPS)
1088 {
1089 BYTE pad = 0;
1090
1091 if ((pad = 8 - (fpInputEvents_length % 8)) == 8)
1092 pad = 0;
1093
1094 Stream_Write_UINT16(s, 0x10); /* length */
1095 Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/
1096 Stream_Write_UINT8(s, pad); /* padding */
1097
1098 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
1099 goto fail;
1100
1101 if (!security_hmac_signature(fpInputEvents, fpInputEvents_length, Stream_Pointer(s),
1102 8, rdp))
1103 goto fail;
1104
1105 if (pad)
1106 memset(fpInputEvents + fpInputEvents_length, 0, pad);
1107
1108 if (!security_fips_encrypt(fpInputEvents, fpInputEvents_length + pad, rdp))
1109 goto fail;
1110
1111 length += pad;
1112 }
1113 else
1114 {
1115 BOOL res = 0;
1116 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
1117 goto fail;
1118 if (sec_flags & SEC_SECURE_CHECKSUM)
1119 res = security_salted_mac_signature(rdp, fpInputEvents, fpInputEvents_length,
1120 TRUE, Stream_Pointer(s), 8);
1121 else
1122 res = security_mac_signature(rdp, fpInputEvents, fpInputEvents_length,
1123 Stream_Pointer(s), 8);
1124
1125 if (!res || !security_encrypt(fpInputEvents, fpInputEvents_length, rdp))
1126 goto fail;
1127 }
1128 }
1129
1130 /*
1131 * We always encode length in two bytes, even though we could use
1132 * only one byte if length <= 0x7F. It is just easier that way,
1133 * because we can leave room for fixed-length header, store all
1134 * the data first and then store the header.
1135 */
1136 WINPR_ASSERT(length < UINT16_MAX);
1137 if (!Stream_SetPosition(s, 1))
1138 goto fail;
1139 Stream_Write_UINT16_BE(s, 0x8000 | (UINT16)length);
1140 if (!Stream_SetPosition(s, length))
1141 goto fail;
1142 Stream_SealLength(s);
1143 }
1144
1145 if (transport_write(rdp->transport, s) < 0)
1146 goto fail;
1147
1148 rc = TRUE;
1149fail:
1150 if (should_unlock)
1151 security_unlock(rdp);
1152 Stream_Release(s);
1153 return rc;
1154}
1155
1156BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s, UINT16 sec_flags)
1157{
1158 return fastpath_send_multiple_input_pdu(fastpath, s, 1, sec_flags);
1159}
1160
1161wStream* fastpath_update_pdu_init(rdpFastPath* fastpath)
1162{
1163 return transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE);
1164}
1165
1166wStream* fastpath_update_pdu_init_new(WINPR_ATTR_UNUSED rdpFastPath* fastpath)
1167{
1168 wStream* s = nullptr;
1169 s = Stream_New(nullptr, FASTPATH_MAX_PACKET_SIZE);
1170 return s;
1171}
1172
1173BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s,
1174 BOOL skipCompression)
1175{
1176 BOOL status = TRUE;
1177 wStream* fs = nullptr;
1178 rdpSettings* settings = nullptr;
1179 rdpRdp* rdp = nullptr;
1180 UINT32 fpHeaderSize = 6;
1181 UINT32 fpUpdatePduHeaderSize = 0;
1182 UINT32 fpUpdateHeaderSize = 0;
1183 FASTPATH_UPDATE_PDU_HEADER fpUpdatePduHeader = WINPR_C_ARRAY_INIT;
1184 FASTPATH_UPDATE_HEADER fpUpdateHeader = WINPR_C_ARRAY_INIT;
1185 UINT16 sec_flags = 0;
1186
1187 if (!fastpath || !fastpath->rdp || !fastpath->fs || !s)
1188 return FALSE;
1189
1190 rdp = fastpath->rdp;
1191 fs = fastpath->fs;
1192 settings = rdp->settings;
1193
1194 if (!settings)
1195 return FALSE;
1196
1197 UINT16 maxLength = FASTPATH_MAX_PACKET_SIZE - 20;
1198
1199 if (freerdp_settings_get_bool(rdp->settings, FreeRDP_CompressionEnabled) && !skipCompression)
1200 {
1201 const UINT16 CompressionMaxSize = bulk_compression_max_size(rdp->bulk);
1202 maxLength = (maxLength < CompressionMaxSize) ? maxLength : CompressionMaxSize;
1203 maxLength -= 20;
1204 }
1205
1206 size_t totalLength = Stream_GetPosition(s);
1207 Stream_ResetPosition(s);
1208
1209 /* check if fast path output is possible */
1210 if (!freerdp_settings_get_bool(rdp->settings, FreeRDP_FastPathOutput))
1211 {
1212 WLog_ERR(TAG, "client does not support fast path output");
1213 return FALSE;
1214 }
1215
1216 /* check if the client's fast path pdu buffer is large enough */
1217 if (totalLength > freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize))
1218 {
1219 WLog_ERR(TAG,
1220 "fast path update size (%" PRIuz
1221 ") exceeds the client's maximum request size (%" PRIu32 ")",
1222 totalLength,
1223 freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize));
1224 return FALSE;
1225 }
1226
1227 if (rdp->do_crypt)
1228 {
1229 sec_flags |= SEC_ENCRYPT;
1230
1231 if (rdp->do_secure_checksum)
1232 sec_flags |= SEC_SECURE_CHECKSUM;
1233 }
1234
1235 for (int fragment = 0; (totalLength > 0) || (fragment == 0); fragment++)
1236 {
1237 UINT32 DstSize = 0;
1238 const BYTE* pDstData = nullptr;
1239 UINT32 compressionFlags = 0;
1240 BYTE pad = 0;
1241 BYTE* pSignature = nullptr;
1242 fpUpdatePduHeader.action = 0;
1243 fpUpdatePduHeader.secFlags = 0;
1244 fpUpdateHeader.compression = 0;
1245 fpUpdateHeader.compressionFlags = 0;
1246 fpUpdateHeader.updateCode = updateCode;
1247 fpUpdateHeader.size = (UINT16)(totalLength > maxLength) ? maxLength : (UINT16)totalLength;
1248 const BYTE* pSrcData = Stream_Pointer(s);
1249 UINT32 SrcSize = DstSize = fpUpdateHeader.size;
1250 BOOL should_unlock = FALSE;
1251
1252 if (sec_flags & SEC_ENCRYPT)
1253 fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_ENCRYPTED;
1254
1255 if (sec_flags & SEC_SECURE_CHECKSUM)
1256 fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_SECURE_CHECKSUM;
1257
1258 if (freerdp_settings_get_bool(settings, FreeRDP_CompressionEnabled) && !skipCompression)
1259 {
1260 if (bulk_compress(rdp->bulk, pSrcData, SrcSize, &pDstData, &DstSize,
1261 &compressionFlags) >= 0)
1262 {
1263 if (compressionFlags)
1264 {
1265 WINPR_ASSERT(compressionFlags <= UINT8_MAX);
1266 fpUpdateHeader.compressionFlags = (UINT8)compressionFlags;
1267 fpUpdateHeader.compression = FASTPATH_OUTPUT_COMPRESSION_USED;
1268 }
1269 }
1270 }
1271
1272 if (!fpUpdateHeader.compression)
1273 {
1274 pDstData = Stream_Pointer(s);
1275 DstSize = fpUpdateHeader.size;
1276 }
1277
1278 if (DstSize > UINT16_MAX)
1279 return FALSE;
1280 fpUpdateHeader.size = (UINT16)DstSize;
1281 totalLength -= SrcSize;
1282
1283 if (totalLength == 0)
1284 fpUpdateHeader.fragmentation =
1285 (fragment == 0) ? FASTPATH_FRAGMENT_SINGLE : FASTPATH_FRAGMENT_LAST;
1286 else
1287 fpUpdateHeader.fragmentation =
1288 (fragment == 0) ? FASTPATH_FRAGMENT_FIRST : FASTPATH_FRAGMENT_NEXT;
1289
1290 fpUpdateHeaderSize = fastpath_get_update_header_size(&fpUpdateHeader);
1291 fpUpdatePduHeaderSize = fastpath_get_update_pdu_header_size(&fpUpdatePduHeader, rdp);
1292 fpHeaderSize = fpUpdateHeaderSize + fpUpdatePduHeaderSize;
1293
1294 if (sec_flags & SEC_ENCRYPT)
1295 {
1296 pSignature = Stream_Buffer(fs) + 3;
1297
1298 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
1299 ENCRYPTION_METHOD_FIPS)
1300 {
1301 pSignature += 4;
1302
1303 if ((pad = 8 - ((DstSize + fpUpdateHeaderSize) % 8)) == 8)
1304 pad = 0;
1305
1306 fpUpdatePduHeader.fipsInformation[0] = 0x10;
1307 fpUpdatePduHeader.fipsInformation[1] = 0x00;
1308 fpUpdatePduHeader.fipsInformation[2] = 0x01;
1309 fpUpdatePduHeader.fipsInformation[3] = pad;
1310 }
1311 }
1312
1313 const size_t len = fpUpdateHeader.size + fpHeaderSize + pad;
1314 if (len > UINT16_MAX)
1315 return FALSE;
1316
1317 fpUpdatePduHeader.length = (UINT16)len;
1318 Stream_ResetPosition(fs);
1319 if (!fastpath_write_update_pdu_header(fs, &fpUpdatePduHeader, rdp))
1320 return FALSE;
1321 if (!fastpath_write_update_header(fs, &fpUpdateHeader))
1322 return FALSE;
1323
1324 if (!Stream_CheckAndLogRequiredCapacity(TAG, (fs), (size_t)DstSize + pad))
1325 return FALSE;
1326 Stream_Write(fs, pDstData, DstSize);
1327
1328 if (pad)
1329 Stream_Zero(fs, pad);
1330
1331 BOOL res = FALSE;
1332 if (sec_flags & SEC_ENCRYPT)
1333 {
1334 security_lock(rdp);
1335
1336 should_unlock = TRUE;
1337 UINT32 dataSize = fpUpdateHeaderSize + DstSize + pad;
1338 BYTE* data = Stream_PointerAs(fs, BYTE) - dataSize;
1339
1340 if (freerdp_settings_get_uint32(rdp->settings, FreeRDP_EncryptionMethods) ==
1341 ENCRYPTION_METHOD_FIPS)
1342 {
1343 // TODO: Ensure stream capacity
1344 if (!security_hmac_signature(data, dataSize - pad, pSignature, 8, rdp))
1345 goto unlock;
1346
1347 if (!security_fips_encrypt(data, dataSize, rdp))
1348 goto unlock;
1349 }
1350 else
1351 {
1352 // TODO: Ensure stream capacity
1353 if (sec_flags & SEC_SECURE_CHECKSUM)
1354 status =
1355 security_salted_mac_signature(rdp, data, dataSize, TRUE, pSignature, 8);
1356 else
1357 status = security_mac_signature(rdp, data, dataSize, pSignature, 8);
1358
1359 if (!status || !security_encrypt(data, dataSize, rdp))
1360 goto unlock;
1361 }
1362 }
1363 res = TRUE;
1364
1365 Stream_SealLength(fs);
1366
1367 if (transport_write(rdp->transport, fs) < 0)
1368 {
1369 status = FALSE;
1370 }
1371
1372 unlock:
1373 if (should_unlock)
1374 security_unlock(rdp);
1375
1376 if (!res || !status)
1377 return FALSE;
1378
1379 Stream_Seek(s, SrcSize);
1380 }
1381
1382 return status;
1383}
1384
1385rdpFastPath* fastpath_new(rdpRdp* rdp)
1386{
1387 rdpFastPath* fastpath = nullptr;
1388
1389 WINPR_ASSERT(rdp);
1390
1391 fastpath = (rdpFastPath*)calloc(1, sizeof(rdpFastPath));
1392
1393 if (!fastpath)
1394 return nullptr;
1395
1396 fastpath->rdp = rdp;
1397 fastpath->fragmentation = -1;
1398 fastpath->fs = Stream_New(nullptr, FASTPATH_MAX_PACKET_SIZE);
1399 fastpath->updateData = Stream_New(nullptr, FASTPATH_MAX_PACKET_SIZE);
1400
1401 if (!fastpath->fs || !fastpath->updateData)
1402 goto out_free;
1403
1404 return fastpath;
1405out_free:
1406 fastpath_free(fastpath);
1407 return nullptr;
1408}
1409
1410void fastpath_free(rdpFastPath* fastpath)
1411{
1412 if (fastpath)
1413 {
1414 Stream_Free(fastpath->updateData, TRUE);
1415 Stream_Free(fastpath->fs, TRUE);
1416 free(fastpath);
1417 }
1418}
1419
1420BYTE fastpath_get_encryption_flags(rdpFastPath* fastpath)
1421{
1422 WINPR_ASSERT(fastpath);
1423 return fastpath->encryptionFlags;
1424}
1425
1426BOOL fastpath_decrypt(rdpFastPath* fastpath, wStream* s, UINT16* length)
1427{
1428 WINPR_ASSERT(fastpath);
1429 if (fastpath_get_encryption_flags(fastpath) & FASTPATH_OUTPUT_ENCRYPTED)
1430 {
1431 const UINT16 flags =
1432 (fastpath_get_encryption_flags(fastpath) & FASTPATH_OUTPUT_SECURE_CHECKSUM)
1433 ? SEC_SECURE_CHECKSUM
1434 : 0;
1435
1436 if (!rdp_decrypt(fastpath->rdp, s, length, flags))
1437 return FALSE;
1438 }
1439
1440 return TRUE;
1441}
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.