2011-08-01 20:19:39 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-01 20:19:39 +04:00
|
|
|
* Fast Path
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
2014-04-02 16:17:39 +04:00
|
|
|
* Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
|
2017-02-20 20:31:58 +03:00
|
|
|
* Copyright 2017 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2017 Thincast Technologies GmbH
|
2011-08-01 20:19:39 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2023-10-16 13:59:19 +03:00
|
|
|
#include "settings.h"
|
|
|
|
|
2011-08-01 20:19:39 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2021-09-03 12:52:55 +03:00
|
|
|
#include <winpr/assert.h>
|
2013-04-30 07:55:44 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
#include <freerdp/api.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2012-02-17 09:58:30 +04:00
|
|
|
#include <freerdp/crypto/per.h>
|
2011-08-01 20:19:39 +04:00
|
|
|
|
2011-08-16 11:04:57 +04:00
|
|
|
#include "orders.h"
|
|
|
|
#include "update.h"
|
2011-08-23 17:01:19 +04:00
|
|
|
#include "surface.h"
|
2011-08-01 20:19:39 +04:00
|
|
|
#include "fastpath.h"
|
2012-03-30 07:57:26 +04:00
|
|
|
#include "rdp.h"
|
2011-08-01 20:19:39 +04:00
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
#include "../cache/pointer.h"
|
|
|
|
#include "../cache/palette.h"
|
|
|
|
#include "../cache/bitmap.h"
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.fastpath")
|
|
|
|
|
2023-01-24 12:44:46 +03:00
|
|
|
enum FASTPATH_INPUT_ENCRYPTION_FLAGS
|
|
|
|
{
|
|
|
|
FASTPATH_INPUT_SECURE_CHECKSUM = 0x1,
|
|
|
|
FASTPATH_INPUT_ENCRYPTED = 0x2
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FASTPATH_OUTPUT_ENCRYPTION_FLAGS
|
|
|
|
{
|
|
|
|
FASTPATH_OUTPUT_SECURE_CHECKSUM = 0x1,
|
|
|
|
FASTPATH_OUTPUT_ENCRYPTED = 0x2
|
|
|
|
};
|
|
|
|
|
2021-09-03 12:52:55 +03:00
|
|
|
struct rdp_fastpath
|
|
|
|
{
|
|
|
|
rdpRdp* rdp;
|
|
|
|
wStream* fs;
|
|
|
|
BYTE encryptionFlags;
|
|
|
|
BYTE numberEvents;
|
|
|
|
wStream* updateData;
|
|
|
|
int fragmentation;
|
|
|
|
};
|
|
|
|
|
2011-08-01 20:19:39 +04:00
|
|
|
/**
|
|
|
|
* Fast-Path packet format is defined in [MS-RDPBCGR] 2.2.9.1.2, which revises
|
|
|
|
* server output packets from the first byte with the goal of improving
|
|
|
|
* bandwidth.
|
2016-03-01 13:39:21 +03:00
|
|
|
*
|
2011-08-01 20:19:39 +04:00
|
|
|
* Slow-Path packet always starts with TPKT header, which has the first
|
|
|
|
* byte 0x03, while Fast-Path packet starts with 2 zero bits in the first
|
|
|
|
* two less significant bits of the first byte.
|
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const char* const FASTPATH_UPDATETYPE_STRINGS[] = {
|
|
|
|
"Orders", /* 0x0 */
|
|
|
|
"Bitmap", /* 0x1 */
|
|
|
|
"Palette", /* 0x2 */
|
|
|
|
"Synchronize", /* 0x3 */
|
|
|
|
"Surface Commands", /* 0x4 */
|
|
|
|
"System Pointer Hidden", /* 0x5 */
|
|
|
|
"System Pointer Default", /* 0x6 */
|
|
|
|
"???", /* 0x7 */
|
|
|
|
"Pointer Position", /* 0x8 */
|
|
|
|
"Color Pointer", /* 0x9 */
|
|
|
|
"Cached Pointer", /* 0xA */
|
|
|
|
"New Pointer", /* 0xB */
|
2012-07-24 01:01:23 +04:00
|
|
|
};
|
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
static const char* fastpath_update_to_string(UINT8 update)
|
|
|
|
{
|
|
|
|
if (update >= ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS))
|
|
|
|
return "UNKNOWN";
|
|
|
|
|
|
|
|
return FASTPATH_UPDATETYPE_STRINGS[update];
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL fastpath_read_update_header(wStream* s, BYTE* updateCode, BYTE* fragmentation,
|
|
|
|
BYTE* compression)
|
2011-08-28 21:36:56 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE updateHeader = 0;
|
2011-08-28 21:36:56 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!s || !updateCode || !fragmentation || !compression)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, updateHeader);
|
2011-08-28 21:36:56 +04:00
|
|
|
*updateCode = updateHeader & 0x0F;
|
|
|
|
*fragmentation = (updateHeader >> 4) & 0x03;
|
|
|
|
*compression = (updateHeader >> 6) & 0x03;
|
2017-02-20 20:31:58 +03:00
|
|
|
return TRUE;
|
2011-08-28 21:36:56 +04:00
|
|
|
}
|
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
static BOOL fastpath_write_update_header(wStream* s, const FASTPATH_UPDATE_HEADER* fpUpdateHeader)
|
2011-08-28 21:36:56 +04:00
|
|
|
{
|
2023-01-24 13:27:24 +03:00
|
|
|
BYTE updateHeader = 0;
|
|
|
|
WINPR_ASSERT(fpUpdateHeader);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
updateHeader |= fpUpdateHeader->updateCode & 0x0F;
|
|
|
|
updateHeader |= (fpUpdateHeader->fragmentation & 0x03) << 4;
|
|
|
|
updateHeader |= (fpUpdateHeader->compression & 0x03) << 6;
|
2022-04-05 16:42:03 +03:00
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 1))
|
2022-04-05 16:42:03 +03:00
|
|
|
return FALSE;
|
2023-01-24 13:27:24 +03:00
|
|
|
Stream_Write_UINT8(s, updateHeader);
|
2014-03-12 01:25:00 +04:00
|
|
|
|
|
|
|
if (fpUpdateHeader->compression)
|
2017-02-20 20:31:58 +03:00
|
|
|
{
|
2023-01-24 13:27:24 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 1))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2014-03-12 01:25:00 +04:00
|
|
|
Stream_Write_UINT8(s, fpUpdateHeader->compressionFlags);
|
2017-02-20 20:31:58 +03:00
|
|
|
}
|
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 2))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
2014-03-12 01:25:00 +04:00
|
|
|
|
|
|
|
Stream_Write_UINT16(s, fpUpdateHeader->size);
|
2017-02-20 20:31:58 +03:00
|
|
|
return TRUE;
|
2014-03-12 01:25:00 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static UINT32 fastpath_get_update_header_size(FASTPATH_UPDATE_HEADER* fpUpdateHeader)
|
2014-03-12 01:25:00 +04:00
|
|
|
{
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(fpUpdateHeader);
|
2014-03-12 01:25:00 +04:00
|
|
|
return (fpUpdateHeader->compression) ? 4 : 3;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static BOOL fastpath_write_update_pdu_header(wStream* s,
|
2023-01-24 13:27:24 +03:00
|
|
|
const FASTPATH_UPDATE_PDU_HEADER* fpUpdatePduHeader,
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpRdp* rdp)
|
2014-03-12 01:25:00 +04:00
|
|
|
{
|
2023-01-24 13:27:24 +03:00
|
|
|
BYTE fpOutputHeader = 0;
|
|
|
|
WINPR_ASSERT(fpUpdatePduHeader);
|
|
|
|
WINPR_ASSERT(rdp);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 3))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
fpOutputHeader |= (fpUpdatePduHeader->action & 0x03);
|
|
|
|
fpOutputHeader |= (fpUpdatePduHeader->secFlags & 0x03) << 6;
|
|
|
|
Stream_Write_UINT8(s, fpOutputHeader); /* fpOutputHeader (1 byte) */
|
2014-03-12 01:25:00 +04:00
|
|
|
Stream_Write_UINT8(s, 0x80 | (fpUpdatePduHeader->length >> 8)); /* length1 */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, fpUpdatePduHeader->length & 0xFF); /* length2 */
|
2014-04-02 16:17:39 +04:00
|
|
|
|
|
|
|
if (fpUpdatePduHeader->secFlags)
|
|
|
|
{
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(rdp->settings);
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
2017-02-20 20:31:58 +03:00
|
|
|
{
|
2023-01-24 13:27:24 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 4))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
Stream_Write(s, fpUpdatePduHeader->fipsInformation, 4);
|
2017-02-20 20:31:58 +03:00
|
|
|
}
|
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
Stream_Write(s, fpUpdatePduHeader->dataSignature, 8);
|
|
|
|
}
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2023-01-24 13:27:24 +03:00
|
|
|
return TRUE;
|
2014-03-12 01:25:00 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
static UINT32 fastpath_get_update_pdu_header_size(FASTPATH_UPDATE_PDU_HEADER* fpUpdatePduHeader,
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpRdp* rdp)
|
2014-03-12 01:25:00 +04:00
|
|
|
{
|
2014-04-02 16:17:39 +04:00
|
|
|
UINT32 size = 3; /* fpUpdatePduHeader + length1 + length2 */
|
2014-03-12 01:25:00 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!fpUpdatePduHeader || !rdp)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-12 01:25:00 +04:00
|
|
|
if (fpUpdatePduHeader->secFlags)
|
|
|
|
{
|
2014-04-02 16:17:39 +04:00
|
|
|
size += 8; /* dataSignature */
|
|
|
|
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(rdp->settings);
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
|
|
|
size += 4; /* fipsInformation */
|
2014-03-12 01:25:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2011-08-28 21:36:56 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16* length)
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE header = 0;
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!s || !length)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, header);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
if (fastpath)
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
|
|
|
fastpath->encryptionFlags = (header & 0xC0) >> 6;
|
|
|
|
fastpath->numberEvents = (header & 0x3C) >> 2;
|
|
|
|
}
|
|
|
|
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!per_read_length(s, length))
|
|
|
|
return FALSE;
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2023-07-28 10:06:53 +03:00
|
|
|
const size_t pos = Stream_GetPosition(s);
|
|
|
|
if (pos > *length)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*length = *length - (UINT16)pos;
|
2013-01-14 02:37:50 +04:00
|
|
|
return TRUE;
|
2011-09-15 01:14:50 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_orders(rdpFastPath* fastpath, wStream* s)
|
2011-08-16 11:04:57 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpUpdate* update = NULL;
|
|
|
|
UINT16 numberOrders = 0;
|
2011-08-16 11:04:57 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!fastpath || !fastpath->rdp || !s)
|
2018-10-15 15:30:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Invalid arguments");
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
2018-10-15 15:30:38 +03:00
|
|
|
}
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
update = fastpath->rdp->update;
|
|
|
|
|
|
|
|
if (!update)
|
2018-10-15 15:30:38 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Invalid configuration");
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
2018-10-15 15:30:38 +03:00
|
|
|
}
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, numberOrders); /* numberOrders (2 bytes) */
|
2011-08-16 11:04:57 +04:00
|
|
|
|
|
|
|
while (numberOrders > 0)
|
|
|
|
{
|
2012-02-11 17:30:09 +04:00
|
|
|
if (!update_recv_order(update, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-16 11:04:57 +04:00
|
|
|
numberOrders--;
|
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-16 11:04:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, wStream* s)
|
2011-08-16 11:04:57 +04:00
|
|
|
{
|
2018-03-30 11:43:20 +03:00
|
|
|
BOOL rc = FALSE;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 updateType = 0;
|
|
|
|
rdpUpdate* update = NULL;
|
|
|
|
rdpContext* context = NULL;
|
|
|
|
BOOL defaultReturn = 0;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!fastpath || !s || !fastpath->rdp)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
update = fastpath->rdp->update;
|
|
|
|
|
|
|
|
if (!update || !update->context)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
context = update->context;
|
2011-08-16 11:04:57 +04:00
|
|
|
|
2021-09-17 09:59:10 +03:00
|
|
|
defaultReturn = freerdp_settings_get_bool(context->settings, FreeRDP_DeactivateClientDecoding);
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-04-13 01:05:42 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, updateType); /* updateType (2 bytes) */
|
2011-08-16 11:04:57 +04:00
|
|
|
switch (updateType)
|
|
|
|
{
|
|
|
|
case UPDATE_TYPE_BITMAP:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
BITMAP_UPDATE* bitmap_update = update_read_bitmap_update(update, s);
|
2018-03-30 11:43:20 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!bitmap_update)
|
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, update->BitmapUpdate, context, bitmap_update);
|
2019-11-06 17:24:51 +03:00
|
|
|
free_bitmap_update(context, bitmap_update);
|
|
|
|
}
|
|
|
|
break;
|
2011-08-16 11:04:57 +04:00
|
|
|
|
|
|
|
case UPDATE_TYPE_PALETTE:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
PALETTE_UPDATE* palette_update = update_read_palette(update, s);
|
2018-03-30 11:43:20 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!palette_update)
|
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, update->Palette, context, palette_update);
|
2019-11-06 17:24:51 +03:00
|
|
|
free_palette_update(context, palette_update);
|
|
|
|
}
|
|
|
|
break;
|
2018-03-30 11:43:20 +03:00
|
|
|
|
|
|
|
default:
|
2011-08-16 11:04:57 +04:00
|
|
|
break;
|
|
|
|
}
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
return rc;
|
2011-08-16 11:04:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_update_synchronize(rdpFastPath* fastpath, wStream* s)
|
2012-01-11 02:03:31 +04:00
|
|
|
{
|
2013-01-14 15:33:56 +04:00
|
|
|
/* server 2008 can send invalid synchronize packet with missing padding,
|
|
|
|
so don't return FALSE even if the packet is invalid */
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
2023-02-07 14:57:21 +03:00
|
|
|
const size_t len = Stream_GetRemainingLength(s);
|
|
|
|
const size_t skip = MIN(2, len);
|
|
|
|
return Stream_SafeSeek(s, skip); /* size (2 bytes), MUST be set to zero */
|
2012-01-11 02:03:31 +04:00
|
|
|
}
|
|
|
|
|
2018-05-02 10:25:30 +03:00
|
|
|
static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2018-03-30 11:43:20 +03:00
|
|
|
BOOL rc = FALSE;
|
2013-01-17 03:01:10 +04:00
|
|
|
int status = 0;
|
2011-09-19 22:50:40 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!fastpath || !fastpath->rdp || !s)
|
|
|
|
return -1;
|
|
|
|
|
2022-04-05 17:38:10 +03:00
|
|
|
Stream_SealLength(s);
|
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!update || !update->pointer || !update->context)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpContext* context = update->context;
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpPointerUpdate* pointer = update->pointer;
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(pointer);
|
|
|
|
|
2012-07-24 01:01:23 +04:00
|
|
|
#ifdef WITH_DEBUG_RDP
|
2023-05-22 21:54:46 +03:00
|
|
|
DEBUG_RDP(fastpath->rdp, "recv Fast-Path %s Update (0x%02" PRIX8 "), length:%" PRIuz "",
|
2018-11-21 11:55:38 +03:00
|
|
|
fastpath_update_to_string(updateCode), updateCode, Stream_GetRemainingLength(s));
|
2012-07-24 01:01:23 +04:00
|
|
|
#endif
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
const BOOL defaultReturn =
|
|
|
|
freerdp_settings_get_bool(context->settings, FreeRDP_DeactivateClientDecoding);
|
2011-08-09 19:28:02 +04:00
|
|
|
switch (updateCode)
|
|
|
|
{
|
|
|
|
case FASTPATH_UPDATETYPE_ORDERS:
|
2018-03-30 11:43:20 +03:00
|
|
|
rc = fastpath_recv_orders(fastpath, s);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_BITMAP:
|
|
|
|
case FASTPATH_UPDATETYPE_PALETTE:
|
2018-03-30 11:43:20 +03:00
|
|
|
rc = fastpath_recv_update_common(fastpath, s);
|
2013-01-14 02:37:50 +04:00
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_SYNCHRONIZE:
|
2013-01-12 17:49:01 +04:00
|
|
|
if (!fastpath_recv_update_synchronize(fastpath, s))
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update_synchronize failure but we continue");
|
2013-01-14 13:13:29 +04:00
|
|
|
else
|
2018-03-30 11:43:20 +03:00
|
|
|
rc = IFCALLRESULT(TRUE, update->Synchronize, context);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_SURFCMDS:
|
2018-02-28 12:10:09 +03:00
|
|
|
status = update_recv_surfcmds(update, s);
|
2018-03-30 11:43:20 +03:00
|
|
|
rc = (status < 0) ? FALSE : TRUE;
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_NULL:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2022-11-30 16:33:31 +03:00
|
|
|
POINTER_SYSTEM_UPDATE pointer_system = { 0 };
|
2019-11-06 17:24:51 +03:00
|
|
|
pointer_system.type = SYSPTR_NULL;
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerSystem, context, &pointer_system);
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_DEFAULT:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2022-11-30 16:33:31 +03:00
|
|
|
POINTER_SYSTEM_UPDATE pointer_system = { 0 };
|
2019-11-06 17:24:51 +03:00
|
|
|
pointer_system.type = SYSPTR_DEFAULT;
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerSystem, context, &pointer_system);
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_POSITION:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
POINTER_POSITION_UPDATE* pointer_position = update_read_pointer_position(update, s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (pointer_position)
|
|
|
|
{
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerPosition, context,
|
|
|
|
pointer_position);
|
2019-11-06 17:24:51 +03:00
|
|
|
free_pointer_position_update(context, pointer_position);
|
2018-03-30 11:43:20 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_COLOR:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
POINTER_COLOR_UPDATE* pointer_color = update_read_pointer_color(update, s, 24);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (pointer_color)
|
|
|
|
{
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerColor, context, pointer_color);
|
2019-11-06 17:24:51 +03:00
|
|
|
free_pointer_color_update(context, pointer_color);
|
2018-03-30 11:43:20 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_CACHED:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
POINTER_CACHED_UPDATE* pointer_cached = update_read_pointer_cached(update, s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (pointer_cached)
|
|
|
|
{
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerCached, context, pointer_cached);
|
2019-11-06 17:24:51 +03:00
|
|
|
free_pointer_cached_update(context, pointer_cached);
|
2018-03-30 11:43:20 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_POINTER:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
POINTER_NEW_UPDATE* pointer_new = update_read_pointer_new(update, s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (pointer_new)
|
|
|
|
{
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerNew, context, pointer_new);
|
2019-11-06 17:24:51 +03:00
|
|
|
free_pointer_new_update(context, pointer_new);
|
2018-03-30 11:43:20 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2019-12-19 11:35:53 +03:00
|
|
|
case FASTPATH_UPDATETYPE_LARGE_POINTER:
|
|
|
|
{
|
|
|
|
POINTER_LARGE_UPDATE* pointer_large = update_read_pointer_large(update, s);
|
|
|
|
|
|
|
|
if (pointer_large)
|
|
|
|
{
|
2021-09-17 09:59:10 +03:00
|
|
|
rc = IFCALLRESULT(defaultReturn, pointer->PointerLarge, context, pointer_large);
|
2019-12-19 11:35:53 +03:00
|
|
|
free_pointer_large_update(context, pointer_large);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
|
2022-04-05 17:38:10 +03:00
|
|
|
Stream_SetPosition(s, 0);
|
2018-03-30 11:43:20 +03:00
|
|
|
if (!rc)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Fastpath update %s [%" PRIx8 "] failed, status %d",
|
2018-03-30 11:43:20 +03:00
|
|
|
fastpath_update_to_string(updateCode), updateCode, status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
return status;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
int status = 0;
|
|
|
|
UINT16 size = 0;
|
|
|
|
BYTE updateCode = 0;
|
|
|
|
BYTE fragmentation = 0;
|
|
|
|
BYTE compression = 0;
|
|
|
|
BYTE compressionFlags = 0;
|
2014-03-21 18:27:11 +04:00
|
|
|
UINT32 DstSize = 0;
|
2022-02-01 12:49:40 +03:00
|
|
|
const BYTE* pDstData = NULL;
|
2011-09-08 09:17:58 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!fastpath || !s)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpRdp* rdp = fastpath->rdp;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!rdp)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpTransport* transport = rdp->transport;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!transport)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!fastpath_read_update_header(s, &updateCode, &fragmentation, &compression))
|
|
|
|
return -1;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
if (compression == FASTPATH_OUTPUT_COMPRESSION_USED)
|
2017-02-20 20:31:58 +03:00
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2017-02-20 20:31:58 +03:00
|
|
|
return -1;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, compressionFlags);
|
2017-02-20 20:31:58 +03:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
else
|
|
|
|
compressionFlags = 0;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2017-02-20 20:31:58 +03:00
|
|
|
return -1;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, size);
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, size))
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
const int bulkStatus =
|
2019-11-06 17:24:51 +03:00
|
|
|
bulk_decompress(rdp->bulk, Stream_Pointer(s), size, &pDstData, &DstSize, compressionFlags);
|
2018-04-04 14:23:14 +03:00
|
|
|
Stream_Seek(s, size);
|
2014-03-26 17:16:28 +04:00
|
|
|
|
|
|
|
if (bulkStatus < 0)
|
|
|
|
{
|
2015-03-19 02:41:29 +03:00
|
|
|
WLog_ERR(TAG, "bulk_decompress() failed");
|
2014-03-26 17:16:28 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-04 14:23:14 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(fastpath->updateData, DstSize))
|
|
|
|
return -1;
|
2013-04-30 19:26:33 +04:00
|
|
|
|
2018-04-04 14:23:14 +03:00
|
|
|
Stream_Write(fastpath->updateData, pDstData, DstSize);
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
|
|
|
|
{
|
2013-04-30 07:55:44 +04:00
|
|
|
if (fastpath->fragmentation != -1)
|
|
|
|
{
|
2015-03-19 02:41:29 +03:00
|
|
|
WLog_ERR(TAG, "Unexpected FASTPATH_FRAGMENT_SINGLE");
|
2015-05-06 17:23:37 +03:00
|
|
|
goto out_fail;
|
2013-04-30 07:55:44 +04:00
|
|
|
}
|
|
|
|
|
2018-04-04 14:23:14 +03:00
|
|
|
status = fastpath_recv_update(fastpath, updateCode, fastpath->updateData);
|
2013-04-30 07:55:44 +04:00
|
|
|
|
2015-05-02 06:26:08 +03:00
|
|
|
if (status < 0)
|
|
|
|
{
|
2015-06-23 12:08:44 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update() - %i", status);
|
2015-05-06 17:54:23 +03:00
|
|
|
goto out_fail;
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpContext* context = NULL;
|
2018-04-04 14:23:14 +03:00
|
|
|
const size_t totalSize = Stream_GetPosition(fastpath->updateData);
|
2018-09-04 11:40:17 +03:00
|
|
|
|
2021-09-06 12:01:36 +03:00
|
|
|
context = transport_get_context(transport);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->settings);
|
|
|
|
|
|
|
|
if (totalSize > context->settings->MultifragMaxRequestSize)
|
2018-04-04 14:23:14 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Total size (%" PRIuz ") exceeds MultifragMaxRequestSize (%" PRIu32 ")",
|
2021-09-06 12:01:36 +03:00
|
|
|
totalSize, context->settings->MultifragMaxRequestSize);
|
2018-04-04 14:23:14 +03:00
|
|
|
goto out_fail;
|
|
|
|
}
|
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_FIRST)
|
2013-04-30 07:55:44 +04:00
|
|
|
{
|
|
|
|
if (fastpath->fragmentation != -1)
|
|
|
|
{
|
2015-03-17 05:10:58 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update_data: Unexpected FASTPATH_FRAGMENT_FIRST");
|
2015-05-06 17:23:37 +03:00
|
|
|
goto out_fail;
|
2013-04-30 07:55:44 +04:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
fastpath->fragmentation = FASTPATH_FRAGMENT_FIRST;
|
|
|
|
}
|
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_NEXT)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-04-30 07:55:44 +04:00
|
|
|
if ((fastpath->fragmentation != FASTPATH_FRAGMENT_FIRST) &&
|
2017-02-20 20:31:58 +03:00
|
|
|
(fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
|
2013-04-30 07:55:44 +04:00
|
|
|
{
|
2015-03-17 05:10:58 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update_data: Unexpected FASTPATH_FRAGMENT_NEXT");
|
2015-05-06 17:23:37 +03:00
|
|
|
goto out_fail;
|
2013-04-30 07:55:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fastpath->fragmentation = FASTPATH_FRAGMENT_NEXT;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
2013-04-30 07:55:44 +04:00
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_LAST)
|
|
|
|
{
|
|
|
|
if ((fastpath->fragmentation != FASTPATH_FRAGMENT_FIRST) &&
|
2017-02-20 20:31:58 +03:00
|
|
|
(fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
|
2013-04-30 07:55:44 +04:00
|
|
|
{
|
2015-03-17 05:10:58 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update_data: Unexpected FASTPATH_FRAGMENT_LAST");
|
2015-05-06 17:23:37 +03:00
|
|
|
goto out_fail;
|
2013-04-30 07:55:44 +04:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
fastpath->fragmentation = -1;
|
2018-04-04 14:23:14 +03:00
|
|
|
status = fastpath_recv_update(fastpath, updateCode, fastpath->updateData);
|
2013-04-30 07:55:44 +04:00
|
|
|
|
2015-05-02 06:26:08 +03:00
|
|
|
if (status < 0)
|
|
|
|
{
|
2015-06-23 12:08:44 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update_data: fastpath_recv_update() - %i", status);
|
2015-05-06 17:54:23 +03:00
|
|
|
goto out_fail;
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2013-04-30 07:55:44 +04:00
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
return status;
|
2015-05-06 17:23:37 +03:00
|
|
|
out_fail:
|
2017-02-20 20:31:58 +03:00
|
|
|
return -1;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t fastpath_recv_updates(rdpFastPath* fastpath, wStream* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t rc = STATE_RUN_FAILED;
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2023-08-23 11:42:46 +03:00
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
2023-08-23 11:42:46 +03:00
|
|
|
WINPR_ASSERT(update);
|
2018-03-30 11:43:20 +03:00
|
|
|
|
2019-04-11 16:30:05 +03:00
|
|
|
if (!update_begin_paint(update))
|
|
|
|
goto fail;
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
while (Stream_GetRemainingLength(s) >= 3)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2015-05-02 06:38:50 +03:00
|
|
|
if (fastpath_recv_update_data(fastpath, s) < 0)
|
|
|
|
{
|
2015-06-23 12:08:44 +03:00
|
|
|
WLog_ERR(TAG, "fastpath_recv_update_data() fail");
|
2022-11-11 14:26:28 +03:00
|
|
|
rc = STATE_RUN_FAILED;
|
2019-04-11 16:30:05 +03:00
|
|
|
goto fail;
|
2015-03-17 05:10:58 +03:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
rc = STATE_RUN_SUCCESS;
|
2019-04-11 16:30:05 +03:00
|
|
|
fail:
|
|
|
|
|
|
|
|
if (!update_end_paint(update))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2018-03-30 11:43:20 +03:00
|
|
|
|
2019-04-11 16:30:05 +03:00
|
|
|
return rc;
|
2011-08-23 08:58:10 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_read_input_event_header(wStream* s, BYTE* eventFlags, BYTE* eventCode)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE eventHeader = 0;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(eventFlags);
|
|
|
|
WINPR_ASSERT(eventCode);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, eventHeader); /* eventHeader (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
*eventFlags = (eventHeader & 0x1F);
|
|
|
|
*eventCode = (eventHeader >> 5);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpInput* input = NULL;
|
|
|
|
UINT16 flags = 0;
|
|
|
|
UINT16 code = 0;
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
|
|
|
WINPR_ASSERT(s);
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
input = fastpath->rdp->input;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, code); /* keyCode (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
flags = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
|
|
|
|
flags |= KBD_FLAGS_RELEASE;
|
|
|
|
|
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED))
|
|
|
|
flags |= KBD_FLAGS_EXTENDED;
|
|
|
|
|
2019-05-16 16:14:16 +03:00
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_PREFIX_E1))
|
|
|
|
flags |= KBD_FLAGS_EXTENDED1;
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
return IFCALLRESULT(TRUE, input->KeyboardEvent, input, flags, code);
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_mouse(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpInput* input = NULL;
|
|
|
|
UINT16 pointerFlags = 0;
|
|
|
|
UINT16 xPos = 0;
|
|
|
|
UINT16 yPos = 0;
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
|
|
|
WINPR_ASSERT(s);
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
input = fastpath->rdp->input;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
|
2017-02-20 20:31:58 +03:00
|
|
|
return IFCALLRESULT(TRUE, input->MouseEvent, input, pointerFlags, xPos, yPos);
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2023-10-12 14:43:00 +03:00
|
|
|
static BOOL fastpath_recv_input_event_relmouse(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpInput* input = NULL;
|
|
|
|
UINT16 pointerFlags = 0;
|
|
|
|
INT16 xDelta = 0;
|
|
|
|
INT16 yDelta = 0;
|
2023-10-12 14:43:00 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->context);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
input = fastpath->rdp->input;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
Stream_Read_INT16(s, xDelta); /* xDelta (2 bytes) */
|
|
|
|
Stream_Read_INT16(s, yDelta); /* yDelta (2 bytes) */
|
|
|
|
|
|
|
|
if (!freerdp_settings_get_bool(input->context->settings, FreeRDP_HasRelativeMouseEvent))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Received relative mouse event(flags=0x%04" PRIx16 ", xPos=%" PRId16
|
|
|
|
", yPos=%" PRId16 "), but we did not announce support for that",
|
|
|
|
pointerFlags, xDelta, yDelta);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IFCALLRESULT(TRUE, input->RelMouseEvent, input, pointerFlags, xDelta, yDelta);
|
|
|
|
}
|
|
|
|
|
2023-10-12 14:53:50 +03:00
|
|
|
static BOOL fastpath_recv_input_event_qoe(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->context);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rdpInput* input = fastpath->rdp->input;
|
|
|
|
|
|
|
|
UINT32 timestampMS = 0;
|
|
|
|
Stream_Read_UINT32(s, timestampMS); /* timestamp (4 bytes) */
|
|
|
|
|
|
|
|
if (!freerdp_settings_get_bool(input->context->settings, FreeRDP_HasQoeEvent))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Received qoe event(timestamp=%" PRIu32
|
|
|
|
"ms), but we did not announce support for that",
|
|
|
|
timestampMS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IFCALLRESULT(TRUE, input->QoEEvent, input, timestampMS);
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_mousex(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 08:58:10 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpInput* input = NULL;
|
|
|
|
UINT16 pointerFlags = 0;
|
|
|
|
UINT16 xPos = 0;
|
|
|
|
UINT16 yPos = 0;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
2023-10-12 14:43:00 +03:00
|
|
|
WINPR_ASSERT(fastpath->rdp->context);
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
input = fastpath->rdp->input;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
|
2023-10-12 14:43:00 +03:00
|
|
|
|
|
|
|
if (!freerdp_settings_get_bool(input->context->settings, FreeRDP_HasExtendedMouseEvent))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Received extended mouse event(flags=0x%04" PRIx16 ", xPos=%" PRIu16
|
|
|
|
", yPos=%" PRIu16 "), but we did not announce support for that",
|
|
|
|
pointerFlags, xPos, yPos);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
return IFCALLRESULT(TRUE, input->ExtendedMouseEvent, input, pointerFlags, xPos, yPos);
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_sync(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpInput* input = NULL;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
|
|
|
WINPR_ASSERT(s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
input = fastpath->rdp->input;
|
|
|
|
return IFCALLRESULT(TRUE, input->SynchronizeEvent, input, eventFlags);
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 unicodeCode = 0;
|
|
|
|
UINT16 flags = 0;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, unicodeCode); /* unicodeCode (2 bytes) */
|
2012-02-07 15:22:01 +04:00
|
|
|
flags = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-02-07 15:22:01 +04:00
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
|
|
|
|
flags |= KBD_FLAGS_RELEASE;
|
|
|
|
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp);
|
|
|
|
WINPR_ASSERT(fastpath->rdp->input);
|
2019-11-06 17:24:51 +03:00
|
|
|
return IFCALLRESULT(FALSE, fastpath->rdp->input->UnicodeKeyboardEvent, fastpath->rdp->input,
|
|
|
|
flags, unicodeCode);
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event(rdpFastPath* fastpath, wStream* s)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE eventFlags = 0;
|
|
|
|
BYTE eventCode = 0;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
if (!fastpath_read_input_event_header(s, &eventFlags, &eventCode))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
switch (eventCode)
|
|
|
|
{
|
|
|
|
case FASTPATH_INPUT_EVENT_SCANCODE:
|
|
|
|
if (!fastpath_recv_input_event_scancode(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_MOUSE:
|
|
|
|
if (!fastpath_recv_input_event_mouse(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_MOUSEX:
|
|
|
|
if (!fastpath_recv_input_event_mousex(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_SYNC:
|
|
|
|
if (!fastpath_recv_input_event_sync(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_UNICODE:
|
|
|
|
if (!fastpath_recv_input_event_unicode(fastpath, s, eventFlags))
|
2023-10-12 14:43:00 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_FP_RELPOINTER_EVENT:
|
|
|
|
if (!fastpath_recv_input_event_relmouse(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
2023-10-12 14:53:50 +03:00
|
|
|
case TS_FP_QOETIMESTAMP_EVENT:
|
|
|
|
if (!fastpath_recv_input_event_qoe(fastpath, s, eventFlags))
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Unknown eventCode %" PRIu8 "", eventCode);
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
state_run_t fastpath_recv_inputs(rdpFastPath* fastpath, wStream* s)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
WINPR_ASSERT(s);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
if (fastpath->numberEvents == 0)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If numberEvents is not provided in fpInputHeader, it will be provided
|
2011-08-27 05:44:37 +04:00
|
|
|
* as one additional byte here.
|
2011-08-23 11:51:51 +04:00
|
|
|
*/
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, fastpath->numberEvents); /* eventHeader (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (BYTE i = 0; i < fastpath->numberEvents; i++)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
|
|
|
if (!fastpath_recv_input_event(fastpath, s))
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_FAILED;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:26:28 +03:00
|
|
|
return STATE_RUN_SUCCESS;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static UINT32 fastpath_get_sec_bytes(rdpRdp* rdp)
|
2012-01-25 19:08:14 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 sec_bytes = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
sec_bytes = 0;
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!rdp)
|
|
|
|
return 0;
|
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->do_crypt)
|
|
|
|
{
|
|
|
|
sec_bytes = 8;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
2012-01-25 19:08:14 +04:00
|
|
|
sec_bytes += 4;
|
|
|
|
}
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
return sec_bytes;
|
|
|
|
}
|
|
|
|
|
2013-04-15 14:14:09 +04:00
|
|
|
wStream* fastpath_input_pdu_init_header(rdpFastPath* fastpath)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpRdp* rdp = NULL;
|
|
|
|
wStream* s = NULL;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!fastpath || !fastpath->rdp)
|
|
|
|
return NULL;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
rdp = fastpath->rdp;
|
2012-01-25 19:08:14 +04:00
|
|
|
s = transport_send_stream_init(rdp->transport, 256);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2015-04-17 17:21:55 +03:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 3); /* fpInputHeader, length1 and length2 */
|
2013-05-02 02:15:55 +04:00
|
|
|
|
|
|
|
if (rdp->do_crypt)
|
|
|
|
{
|
2012-01-25 19:08:14 +04:00
|
|
|
rdp->sec_flags |= SEC_ENCRYPT;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->do_secure_checksum)
|
|
|
|
rdp->sec_flags |= SEC_SECURE_CHECKSUM;
|
|
|
|
}
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, fastpath_get_sec_bytes(rdp));
|
2013-04-15 14:14:09 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
2013-04-15 14:14:09 +04:00
|
|
|
s = fastpath_input_pdu_init_header(fastpath);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2015-04-17 17:21:55 +03:00
|
|
|
if (!s)
|
|
|
|
return NULL;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
Stream_Write_UINT8(s, eventFlags | (eventCode << 5)); /* eventHeader (1 byte) */
|
2011-08-16 10:37:11 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-01-22 10:24:16 +03:00
|
|
|
BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, size_t iNumEvents)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2018-10-23 13:33:13 +03:00
|
|
|
BOOL rc = FALSE;
|
2023-07-28 10:06:53 +03:00
|
|
|
BYTE eventHeader = 0;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
WINPR_ASSERT(iNumEvents > 0);
|
2018-10-02 14:18:13 +03:00
|
|
|
if (!s)
|
2017-02-20 20:31:58 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2021-01-22 10:24:16 +03:00
|
|
|
if (!fastpath)
|
2018-10-02 14:18:13 +03:00
|
|
|
goto fail;
|
|
|
|
|
2023-07-28 10:06:53 +03:00
|
|
|
rdpRdp* rdp = fastpath->rdp;
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
2023-07-28 10:06:53 +03:00
|
|
|
CONNECTION_STATE state = rdp_get_state(rdp);
|
2022-11-30 16:33:31 +03:00
|
|
|
if (!rdp_is_active_state(rdp))
|
2021-01-22 10:24:16 +03:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "called before activation [%s]", rdp_state_string(state));
|
2021-01-22 10:24:16 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2013-09-02 20:07:55 +04:00
|
|
|
/*
|
|
|
|
* A maximum of 15 events are allowed per request
|
|
|
|
* if the optional numEvents field isn't used
|
|
|
|
* see MS-RDPBCGR 2.2.8.1.2 for details
|
|
|
|
*/
|
|
|
|
if (iNumEvents > 15)
|
2018-10-02 14:18:13 +03:00
|
|
|
goto fail;
|
2013-09-02 20:07:55 +04:00
|
|
|
|
2023-07-28 10:06:53 +03:00
|
|
|
size_t length = Stream_GetPosition(s);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-02-21 00:03:28 +04:00
|
|
|
if (length >= (2 << 14))
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2015-03-19 02:41:29 +03:00
|
|
|
WLog_ERR(TAG, "Maximum FastPath PDU length is 32767");
|
2018-10-02 14:18:13 +03:00
|
|
|
goto fail;
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
eventHeader = FASTPATH_INPUT_ACTION_FASTPATH;
|
2013-09-02 20:07:55 +04:00
|
|
|
eventHeader |= (iNumEvents << 2); /* numberEvents */
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
|
|
|
eventHeader |= (FASTPATH_INPUT_ENCRYPTED << 6);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
|
|
|
eventHeader |= (FASTPATH_INPUT_SECURE_CHECKSUM << 6);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, eventHeader);
|
2014-04-02 16:17:39 +04:00
|
|
|
/* Write length later, RDP encryption might add a padding */
|
|
|
|
Stream_Seek(s, 2);
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
2012-01-25 19:08:14 +04:00
|
|
|
{
|
2023-01-28 15:31:33 +03:00
|
|
|
BOOL status = FALSE;
|
|
|
|
if (!security_lock(rdp))
|
|
|
|
goto fail;
|
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
int sec_bytes = fastpath_get_sec_bytes(fastpath->rdp);
|
2023-06-07 16:38:21 +03:00
|
|
|
BYTE* fpInputEvents = Stream_PointerAs(s, BYTE) + sec_bytes;
|
2014-04-02 16:17:39 +04:00
|
|
|
UINT16 fpInputEvents_length = length - 3 - sec_bytes;
|
|
|
|
|
2021-09-03 12:52:55 +03:00
|
|
|
WINPR_ASSERT(rdp->settings);
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE pad = 0;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if ((pad = 8 - (fpInputEvents_length % 8)) == 8)
|
|
|
|
pad = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
Stream_Write_UINT16(s, 0x10); /* length */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/
|
|
|
|
Stream_Write_UINT8(s, pad); /* padding */
|
2014-04-02 16:17:39 +04:00
|
|
|
|
2023-01-30 14:14:03 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
if (!security_hmac_signature(fpInputEvents, fpInputEvents_length, Stream_Pointer(s), 8,
|
2019-11-06 17:24:51 +03:00
|
|
|
rdp))
|
2023-01-28 15:31:33 +03:00
|
|
|
goto unlock;
|
2014-04-02 16:17:39 +04:00
|
|
|
|
|
|
|
if (pad)
|
|
|
|
memset(fpInputEvents + fpInputEvents_length, 0, pad);
|
|
|
|
|
2015-04-07 22:06:53 +03:00
|
|
|
if (!security_fips_encrypt(fpInputEvents, fpInputEvents_length + pad, rdp))
|
2023-01-28 15:31:33 +03:00
|
|
|
goto unlock;
|
2014-04-02 16:17:39 +04:00
|
|
|
|
|
|
|
length += pad;
|
|
|
|
}
|
2012-01-25 19:08:14 +04:00
|
|
|
else
|
2014-04-02 16:17:39 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL res = 0;
|
2023-01-30 14:14:03 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 8))
|
|
|
|
goto unlock;
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
2023-01-28 15:31:33 +03:00
|
|
|
res = security_salted_mac_signature(rdp, fpInputEvents, fpInputEvents_length, TRUE,
|
2023-01-30 14:14:03 +03:00
|
|
|
Stream_Pointer(s), 8);
|
2014-04-02 16:17:39 +04:00
|
|
|
else
|
2023-01-28 15:31:33 +03:00
|
|
|
res = security_mac_signature(rdp, fpInputEvents, fpInputEvents_length,
|
2023-01-30 14:14:03 +03:00
|
|
|
Stream_Pointer(s), 8);
|
2015-04-01 12:11:37 +03:00
|
|
|
|
2023-01-28 15:31:33 +03:00
|
|
|
if (!res || !security_encrypt(fpInputEvents, fpInputEvents_length, rdp))
|
|
|
|
goto unlock;
|
2014-04-02 16:17:39 +04:00
|
|
|
}
|
2023-01-28 15:31:33 +03:00
|
|
|
|
|
|
|
status = TRUE;
|
|
|
|
unlock:
|
|
|
|
if (!security_unlock(rdp))
|
|
|
|
goto fail;
|
|
|
|
if (!status)
|
|
|
|
goto fail;
|
2012-01-25 19:08:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rdp->sec_flags = 0;
|
2014-04-02 16:17:39 +04:00
|
|
|
/*
|
|
|
|
* We always encode length in two bytes, even though we could use
|
|
|
|
* only one byte if length <= 0x7F. It is just easier that way,
|
|
|
|
* because we can leave room for fixed-length header, store all
|
|
|
|
* the data first and then store the header.
|
|
|
|
*/
|
2023-07-28 10:06:53 +03:00
|
|
|
WINPR_ASSERT(length < UINT16_MAX);
|
2014-04-02 16:17:39 +04:00
|
|
|
Stream_SetPosition(s, 1);
|
2023-07-28 10:06:53 +03:00
|
|
|
Stream_Write_UINT16_BE(s, 0x8000 | (UINT16)length);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, length);
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_SealLength(s);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2021-09-03 12:52:55 +03:00
|
|
|
if (transport_write(rdp->transport, s) < 0)
|
2018-10-02 14:18:13 +03:00
|
|
|
goto fail;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2018-10-02 14:18:13 +03:00
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
Stream_Release(s);
|
|
|
|
return rc;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 14:14:09 +04:00
|
|
|
BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s)
|
|
|
|
{
|
|
|
|
return fastpath_send_multiple_input_pdu(fastpath, s, 1);
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* fastpath_update_pdu_init(rdpFastPath* fastpath)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE);
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-05-10 00:30:28 +04:00
|
|
|
wStream* fastpath_update_pdu_init_new(rdpFastPath* fastpath)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
2013-05-10 00:30:28 +04:00
|
|
|
s = Stream_New(NULL, FASTPATH_MAX_PACKET_SIZE);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s,
|
|
|
|
BOOL skipCompression)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2014-03-11 23:35:15 +04:00
|
|
|
BOOL status = TRUE;
|
|
|
|
wStream* fs = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpRdp* rdp = NULL;
|
2014-03-12 01:25:00 +04:00
|
|
|
UINT32 fpHeaderSize = 6;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 fpUpdatePduHeaderSize = 0;
|
|
|
|
UINT32 fpUpdateHeaderSize = 0;
|
2014-03-12 01:25:00 +04:00
|
|
|
FASTPATH_UPDATE_PDU_HEADER fpUpdatePduHeader = { 0 };
|
|
|
|
FASTPATH_UPDATE_HEADER fpUpdateHeader = { 0 };
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!fastpath || !fastpath->rdp || !fastpath->fs || !s)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rdp = fastpath->rdp;
|
2014-03-12 04:58:35 +04:00
|
|
|
fs = fastpath->fs;
|
2014-03-12 01:52:34 +04:00
|
|
|
settings = rdp->settings;
|
2014-03-12 06:33:41 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-09-17 14:19:31 +03:00
|
|
|
UINT16 maxLength = FASTPATH_MAX_PACKET_SIZE - 20;
|
2013-05-09 01:48:30 +04:00
|
|
|
|
2014-11-04 18:14:53 +03:00
|
|
|
if (settings->CompressionEnabled && !skipCompression)
|
2014-03-12 06:33:41 +04:00
|
|
|
{
|
2024-09-17 14:19:31 +03:00
|
|
|
const UINT32 CompressionMaxSize = bulk_compression_max_size(rdp->bulk);
|
|
|
|
maxLength =
|
|
|
|
(maxLength < CompressionMaxSize) ? maxLength : MIN(CompressionMaxSize, UINT16_MAX);
|
2014-03-21 18:27:11 +04:00
|
|
|
maxLength -= 20;
|
2014-03-12 06:33:41 +04:00
|
|
|
}
|
|
|
|
|
2024-09-17 14:19:31 +03:00
|
|
|
size_t totalLength = Stream_GetPosition(s);
|
2014-10-01 05:12:20 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
|
2015-02-03 15:51:35 +03:00
|
|
|
/* check if fast path output is possible */
|
|
|
|
if (!settings->FastPathOutput)
|
2014-10-01 05:12:20 +04:00
|
|
|
{
|
2015-02-03 15:51:35 +03:00
|
|
|
WLog_ERR(TAG, "client does not support fast path output");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-10-01 05:12:20 +04:00
|
|
|
|
2015-02-03 15:51:35 +03:00
|
|
|
/* check if the client's fast path pdu buffer is large enough */
|
|
|
|
if (totalLength > settings->MultifragMaxRequestSize)
|
|
|
|
{
|
2017-02-20 20:31:58 +03:00
|
|
|
WLog_ERR(TAG,
|
2024-09-17 14:19:31 +03:00
|
|
|
"fast path update size (%" PRIuz
|
2019-11-06 17:24:51 +03:00
|
|
|
") exceeds the client's maximum request size (%" PRIu32 ")",
|
2017-02-20 20:31:58 +03:00
|
|
|
totalLength, settings->MultifragMaxRequestSize);
|
2015-02-03 15:51:35 +03:00
|
|
|
return FALSE;
|
2014-10-01 05:12:20 +04:00
|
|
|
}
|
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->do_crypt)
|
|
|
|
{
|
|
|
|
rdp->sec_flags |= SEC_ENCRYPT;
|
|
|
|
|
|
|
|
if (rdp->do_secure_checksum)
|
|
|
|
rdp->sec_flags |= SEC_SECURE_CHECKSUM;
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (int fragment = 0; (totalLength > 0) || (fragment == 0); fragment++)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2014-03-12 01:52:34 +04:00
|
|
|
UINT32 DstSize = 0;
|
2022-04-27 09:33:19 +03:00
|
|
|
const BYTE* pDstData = NULL;
|
2014-03-12 01:52:34 +04:00
|
|
|
UINT32 compressionFlags = 0;
|
2014-04-02 16:17:39 +04:00
|
|
|
BYTE pad = 0;
|
2014-04-17 14:16:10 +04:00
|
|
|
BYTE* pSignature = NULL;
|
2014-03-12 01:25:00 +04:00
|
|
|
fpUpdatePduHeader.action = 0;
|
|
|
|
fpUpdatePduHeader.secFlags = 0;
|
|
|
|
fpUpdateHeader.compression = 0;
|
2014-03-12 01:52:34 +04:00
|
|
|
fpUpdateHeader.compressionFlags = 0;
|
2014-03-12 01:25:00 +04:00
|
|
|
fpUpdateHeader.updateCode = updateCode;
|
2024-09-17 14:19:31 +03:00
|
|
|
fpUpdateHeader.size = (UINT16)(totalLength > maxLength) ? maxLength : totalLength;
|
|
|
|
const BYTE* pSrcData = Stream_Pointer(s);
|
|
|
|
UINT32 SrcSize = DstSize = fpUpdateHeader.size;
|
2014-03-12 01:52:34 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
|
|
|
fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_ENCRYPTED;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
|
|
|
fpUpdatePduHeader.secFlags |= FASTPATH_OUTPUT_SECURE_CHECKSUM;
|
|
|
|
|
2014-11-04 18:14:53 +03:00
|
|
|
if (settings->CompressionEnabled && !skipCompression)
|
2014-03-12 01:52:34 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (bulk_compress(rdp->bulk, pSrcData, SrcSize, &pDstData, &DstSize,
|
|
|
|
&compressionFlags) >= 0)
|
2014-03-12 01:52:34 +04:00
|
|
|
{
|
2014-04-21 05:28:09 +04:00
|
|
|
if (compressionFlags)
|
2014-03-12 01:52:34 +04:00
|
|
|
{
|
|
|
|
fpUpdateHeader.compressionFlags = compressionFlags;
|
|
|
|
fpUpdateHeader.compression = FASTPATH_OUTPUT_COMPRESSION_USED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 04:58:35 +04:00
|
|
|
if (!fpUpdateHeader.compression)
|
|
|
|
{
|
|
|
|
pDstData = Stream_Pointer(s);
|
|
|
|
DstSize = fpUpdateHeader.size;
|
|
|
|
}
|
|
|
|
|
2014-03-12 01:52:34 +04:00
|
|
|
fpUpdateHeader.size = DstSize;
|
|
|
|
totalLength -= SrcSize;
|
2011-08-28 01:11:20 +04:00
|
|
|
|
2011-08-28 21:36:56 +04:00
|
|
|
if (totalLength == 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
fpUpdateHeader.fragmentation =
|
|
|
|
(fragment == 0) ? FASTPATH_FRAGMENT_SINGLE : FASTPATH_FRAGMENT_LAST;
|
2011-08-28 01:11:20 +04:00
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
fpUpdateHeader.fragmentation =
|
|
|
|
(fragment == 0) ? FASTPATH_FRAGMENT_FIRST : FASTPATH_FRAGMENT_NEXT;
|
2011-08-28 21:36:56 +04:00
|
|
|
|
2014-03-12 01:25:00 +04:00
|
|
|
fpUpdateHeaderSize = fastpath_get_update_header_size(&fpUpdateHeader);
|
2014-04-02 16:17:39 +04:00
|
|
|
fpUpdatePduHeaderSize = fastpath_get_update_pdu_header_size(&fpUpdatePduHeader, rdp);
|
2014-03-12 01:25:00 +04:00
|
|
|
fpHeaderSize = fpUpdateHeaderSize + fpUpdatePduHeaderSize;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
|
|
|
{
|
|
|
|
pSignature = Stream_Buffer(fs) + 3;
|
2012-03-20 21:03:36 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
|
|
|
{
|
|
|
|
pSignature += 4;
|
|
|
|
|
|
|
|
if ((pad = 8 - ((DstSize + fpUpdateHeaderSize) % 8)) == 8)
|
|
|
|
pad = 0;
|
|
|
|
|
|
|
|
fpUpdatePduHeader.fipsInformation[0] = 0x10;
|
|
|
|
fpUpdatePduHeader.fipsInformation[1] = 0x00;
|
|
|
|
fpUpdatePduHeader.fipsInformation[2] = 0x01;
|
|
|
|
fpUpdatePduHeader.fipsInformation[3] = pad;
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 10:42:13 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
fpUpdatePduHeader.length = fpUpdateHeader.size + fpHeaderSize + pad;
|
|
|
|
Stream_SetPosition(fs, 0);
|
2023-01-24 12:44:46 +03:00
|
|
|
if (!fastpath_write_update_pdu_header(fs, &fpUpdatePduHeader, rdp))
|
|
|
|
return FALSE;
|
|
|
|
if (!fastpath_write_update_header(fs, &fpUpdateHeader))
|
|
|
|
return FALSE;
|
2022-04-05 16:42:03 +03:00
|
|
|
|
2023-01-24 14:19:56 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredCapacity(TAG, (fs), (size_t)DstSize + pad))
|
2022-04-05 16:42:03 +03:00
|
|
|
return FALSE;
|
2014-03-12 01:52:34 +04:00
|
|
|
Stream_Write(fs, pDstData, DstSize);
|
2014-04-02 16:17:39 +04:00
|
|
|
|
|
|
|
if (pad)
|
|
|
|
Stream_Zero(fs, pad);
|
|
|
|
|
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
|
|
|
{
|
2023-01-28 15:31:33 +03:00
|
|
|
BOOL res = FALSE;
|
|
|
|
if (!security_lock(rdp))
|
|
|
|
return FALSE;
|
2014-04-02 16:17:39 +04:00
|
|
|
UINT32 dataSize = fpUpdateHeaderSize + DstSize + pad;
|
2023-06-07 16:38:21 +03:00
|
|
|
BYTE* data = Stream_PointerAs(fs, BYTE) - dataSize;
|
2014-04-02 16:17:39 +04:00
|
|
|
|
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
|
|
|
{
|
2023-01-30 14:14:03 +03:00
|
|
|
// TODO: Ensure stream capacity
|
|
|
|
if (!security_hmac_signature(data, dataSize - pad, pSignature, 8, rdp))
|
2023-01-28 15:31:33 +03:00
|
|
|
goto unlock;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2023-01-28 15:31:33 +03:00
|
|
|
if (!security_fips_encrypt(data, dataSize, rdp))
|
|
|
|
goto unlock;
|
2014-04-02 16:17:39 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-30 14:14:03 +03:00
|
|
|
// TODO: Ensure stream capacity
|
2014-04-02 16:17:39 +04:00
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
2023-01-30 14:14:03 +03:00
|
|
|
status =
|
|
|
|
security_salted_mac_signature(rdp, data, dataSize, TRUE, pSignature, 8);
|
2014-04-02 16:17:39 +04:00
|
|
|
else
|
2023-01-30 14:14:03 +03:00
|
|
|
status = security_mac_signature(rdp, data, dataSize, pSignature, 8);
|
2014-04-02 16:17:39 +04:00
|
|
|
|
2015-04-07 22:06:53 +03:00
|
|
|
if (!status || !security_encrypt(data, dataSize, rdp))
|
2023-01-28 15:31:33 +03:00
|
|
|
goto unlock;
|
2014-04-02 16:17:39 +04:00
|
|
|
}
|
2023-01-28 15:31:33 +03:00
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
if (!security_unlock(rdp))
|
|
|
|
return FALSE;
|
|
|
|
if (!res)
|
|
|
|
return FALSE;
|
2014-04-02 16:17:39 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 23:35:15 +04:00
|
|
|
Stream_SealLength(fs);
|
2013-05-15 20:14:26 +04:00
|
|
|
|
2014-03-11 23:35:15 +04:00
|
|
|
if (transport_write(rdp->transport, fs) < 0)
|
2011-12-03 10:42:13 +04:00
|
|
|
{
|
2014-03-11 23:35:15 +04:00
|
|
|
status = FALSE;
|
2011-12-03 10:42:13 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2014-03-12 04:58:35 +04:00
|
|
|
Stream_Seek(s, SrcSize);
|
|
|
|
}
|
2011-12-03 10:42:13 +04:00
|
|
|
|
2014-04-02 16:17:39 +04:00
|
|
|
rdp->sec_flags = 0;
|
2014-03-11 23:35:15 +04:00
|
|
|
return status;
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
rdpFastPath* fastpath_new(rdpRdp* rdp)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpFastPath* fastpath = NULL;
|
2021-09-03 12:52:55 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(rdp);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
fastpath = (rdpFastPath*)calloc(1, sizeof(rdpFastPath));
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-11-04 18:14:53 +03:00
|
|
|
if (!fastpath)
|
|
|
|
return NULL;
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2014-11-04 18:14:53 +03:00
|
|
|
fastpath->rdp = rdp;
|
|
|
|
fastpath->fragmentation = -1;
|
|
|
|
fastpath->fs = Stream_New(NULL, FASTPATH_MAX_PACKET_SIZE);
|
2018-04-04 14:23:14 +03:00
|
|
|
fastpath->updateData = Stream_New(NULL, FASTPATH_MAX_PACKET_SIZE);
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2018-04-04 14:23:14 +03:00
|
|
|
if (!fastpath->fs || !fastpath->updateData)
|
2014-11-04 18:14:53 +03:00
|
|
|
goto out_free;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
return fastpath;
|
2014-11-04 18:14:53 +03:00
|
|
|
out_free:
|
2018-04-04 14:23:14 +03:00
|
|
|
fastpath_free(fastpath);
|
2014-11-04 18:14:53 +03:00
|
|
|
return NULL;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void fastpath_free(rdpFastPath* fastpath)
|
|
|
|
{
|
2013-04-30 07:55:44 +04:00
|
|
|
if (fastpath)
|
|
|
|
{
|
2018-04-04 14:23:14 +03:00
|
|
|
Stream_Free(fastpath->updateData, TRUE);
|
2014-03-12 04:58:35 +04:00
|
|
|
Stream_Free(fastpath->fs, TRUE);
|
2013-04-30 07:55:44 +04:00
|
|
|
free(fastpath);
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
2021-09-03 12:52:55 +03:00
|
|
|
|
|
|
|
BYTE fastpath_get_encryption_flags(rdpFastPath* fastpath)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
return fastpath->encryptionFlags;
|
|
|
|
}
|
2023-01-24 12:44:46 +03:00
|
|
|
|
|
|
|
BOOL fastpath_decrypt(rdpFastPath* fastpath, wStream* s, UINT16* length)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(fastpath);
|
|
|
|
if (fastpath_get_encryption_flags(fastpath) & FASTPATH_OUTPUT_ENCRYPTED)
|
|
|
|
{
|
|
|
|
const UINT16 flags =
|
|
|
|
(fastpath_get_encryption_flags(fastpath) & FASTPATH_OUTPUT_SECURE_CHECKSUM)
|
|
|
|
? SEC_SECURE_CHECKSUM
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
if (!rdp_decrypt(fastpath->rdp, s, length, flags))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|