2011-07-10 23:34:43 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-10 23:34:43 +04:00
|
|
|
* RDP Core
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2015-01-13 19:09:36 +03:00
|
|
|
* Copyright 2014 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
|
2011-07-10 23:34:43 +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.
|
|
|
|
*/
|
|
|
|
|
2017-06-06 15:01:41 +03:00
|
|
|
#ifndef FREERDP_LIB_CORE_RDP_H
|
|
|
|
#define FREERDP_LIB_CORE_RDP_H
|
2011-07-10 23:34:43 +04:00
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:41:40 +04:00
|
|
|
|
2015-02-16 00:04:59 +03:00
|
|
|
#include "nla.h"
|
2011-07-12 02:46:36 +04:00
|
|
|
#include "mcs.h"
|
|
|
|
#include "tpkt.h"
|
2022-04-28 11:15:31 +03:00
|
|
|
#include "../codec/bulk.h"
|
2011-08-09 12:40:58 +04:00
|
|
|
#include "fastpath.h"
|
2011-07-12 02:46:36 +04:00
|
|
|
#include "tpdu.h"
|
|
|
|
#include "nego.h"
|
2011-07-28 08:38:25 +04:00
|
|
|
#include "input.h"
|
2011-07-25 09:45:25 +04:00
|
|
|
#include "update.h"
|
2011-07-12 04:46:03 +04:00
|
|
|
#include "license.h"
|
2011-08-08 07:59:28 +04:00
|
|
|
#include "errinfo.h"
|
2014-01-24 03:01:31 +04:00
|
|
|
#include "autodetect.h"
|
2014-01-24 07:23:47 +04:00
|
|
|
#include "heartbeat.h"
|
2014-01-24 03:01:31 +04:00
|
|
|
#include "multitransport.h"
|
2011-07-12 02:46:36 +04:00
|
|
|
#include "security.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "connection.h"
|
2011-09-04 00:36:27 +04:00
|
|
|
#include "redirection.h"
|
2011-07-20 00:30:05 +04:00
|
|
|
#include "capabilities.h"
|
2014-02-12 00:42:28 +04:00
|
|
|
#include "channels.h"
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2011-07-10 23:34:43 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-07-14 09:23:44 +04:00
|
|
|
#include <freerdp/settings.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2016-08-10 10:12:55 +03:00
|
|
|
#include <freerdp/api.h>
|
2011-07-10 23:34:43 +04:00
|
|
|
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2016-02-24 19:04:03 +03:00
|
|
|
#include <winpr/crypto.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
|
2011-07-10 23:34:43 +04:00
|
|
|
/* Security Header Flags */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define SEC_EXCHANGE_PKT 0x0001
|
|
|
|
#define SEC_TRANSPORT_REQ 0x0002
|
|
|
|
#define SEC_TRANSPORT_RSP 0x0004
|
|
|
|
#define SEC_ENCRYPT 0x0008
|
|
|
|
#define SEC_RESET_SEQNO 0x0010
|
|
|
|
#define SEC_IGNORE_SEQNO 0x0020
|
|
|
|
#define SEC_INFO_PKT 0x0040
|
|
|
|
#define SEC_LICENSE_PKT 0x0080
|
|
|
|
#define SEC_LICENSE_ENCRYPT_CS 0x0200
|
|
|
|
#define SEC_LICENSE_ENCRYPT_SC 0x0200
|
|
|
|
#define SEC_REDIRECTION_PKT 0x0400
|
|
|
|
#define SEC_SECURE_CHECKSUM 0x0800
|
|
|
|
#define SEC_AUTODETECT_REQ 0x1000
|
|
|
|
#define SEC_AUTODETECT_RSP 0x2000
|
|
|
|
#define SEC_HEARTBEAT 0x4000
|
|
|
|
#define SEC_FLAGSHI_VALID 0x8000
|
|
|
|
|
|
|
|
#define SEC_PKT_CS_MASK (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
|
|
|
|
#define SEC_PKT_SC_MASK (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
|
|
|
|
#define SEC_PKT_MASK (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
|
|
|
|
|
|
|
|
#define RDP_SECURITY_HEADER_LENGTH 4
|
|
|
|
#define RDP_SHARE_CONTROL_HEADER_LENGTH 6
|
|
|
|
#define RDP_SHARE_DATA_HEADER_LENGTH 12
|
|
|
|
#define RDP_PACKET_HEADER_MAX_LENGTH (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_MAX_LENGTH)
|
|
|
|
|
|
|
|
#define PDU_TYPE_DEMAND_ACTIVE 0x1
|
|
|
|
#define PDU_TYPE_CONFIRM_ACTIVE 0x3
|
|
|
|
#define PDU_TYPE_DEACTIVATE_ALL 0x6
|
|
|
|
#define PDU_TYPE_DATA 0x7
|
|
|
|
#define PDU_TYPE_SERVER_REDIRECTION 0xA
|
|
|
|
|
|
|
|
#define PDU_TYPE_FLOW_TEST 0x41
|
|
|
|
#define PDU_TYPE_FLOW_RESPONSE 0x42
|
|
|
|
#define PDU_TYPE_FLOW_STOP 0x43
|
|
|
|
|
2022-06-23 10:59:24 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
FINALIZE_SC_SYNCHRONIZE_PDU = 0x01,
|
|
|
|
FINALIZE_SC_CONTROL_COOPERATE_PDU = 0x02,
|
|
|
|
FINALIZE_SC_CONTROL_GRANTED_PDU = 0x04,
|
|
|
|
FINALIZE_SC_FONT_MAP_PDU = 0x08,
|
|
|
|
|
|
|
|
FINALIZE_CS_SYNCHRONIZE_PDU = 0x10,
|
|
|
|
FINALIZE_CS_CONTROL_COOPERATE_PDU = 0x20,
|
|
|
|
FINALIZE_CS_CONTROL_REQUEST_PDU = 0x40,
|
|
|
|
FINALIZE_CS_PERSISTENT_KEY_LIST_PDU = 0x80,
|
|
|
|
FINALIZE_CS_FONT_LIST_PDU = 0x100,
|
|
|
|
|
|
|
|
FINALIZE_DEACTIVATE_REACTIVATE = 0x200
|
|
|
|
} rdpFinalizePduType;
|
|
|
|
|
|
|
|
#define FINALIZE_SC_COMPLETE \
|
|
|
|
(FINALIZE_SC_SYNCHRONIZE_PDU | FINALIZE_SC_CONTROL_COOPERATE_PDU | \
|
|
|
|
FINALIZE_SC_CONTROL_GRANTED_PDU | FINALIZE_SC_FONT_MAP_PDU)
|
|
|
|
#define FINALIZE_CS_COMPLETE \
|
|
|
|
(FINALIZE_CS_SYNCHRONIZE_PDU | FINALIZE_CS_CONTROL_COOPERATE_PDU | \
|
|
|
|
FINALIZE_CS_CONTROL_REQUEST_PDU | FINALIZE_CS_PERSISTENT_KEY_LIST_PDU | \
|
|
|
|
FINALIZE_CS_FONT_LIST_PDU)
|
2011-12-19 00:15:48 +04:00
|
|
|
|
2011-07-21 23:10:53 +04:00
|
|
|
/* Data PDU Types */
|
2022-04-19 15:29:17 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DATA_PDU_TYPE_UPDATE = 0x02,
|
|
|
|
DATA_PDU_TYPE_CONTROL = 0x14,
|
|
|
|
DATA_PDU_TYPE_POINTER = 0x1B,
|
|
|
|
DATA_PDU_TYPE_INPUT = 0x1C,
|
|
|
|
DATA_PDU_TYPE_SYNCHRONIZE = 0x1F,
|
|
|
|
DATA_PDU_TYPE_REFRESH_RECT = 0x21,
|
|
|
|
DATA_PDU_TYPE_PLAY_SOUND = 0x22,
|
|
|
|
DATA_PDU_TYPE_SUPPRESS_OUTPUT = 0x23,
|
|
|
|
DATA_PDU_TYPE_SHUTDOWN_REQUEST = 0x24,
|
|
|
|
DATA_PDU_TYPE_SHUTDOWN_DENIED = 0x25,
|
|
|
|
DATA_PDU_TYPE_SAVE_SESSION_INFO = 0x26,
|
|
|
|
DATA_PDU_TYPE_FONT_LIST = 0x27,
|
|
|
|
DATA_PDU_TYPE_FONT_MAP = 0x28,
|
|
|
|
DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS = 0x29,
|
|
|
|
DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST = 0x2B,
|
|
|
|
DATA_PDU_TYPE_BITMAP_CACHE_ERROR = 0x2C,
|
|
|
|
DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS = 0x2D,
|
|
|
|
DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR = 0x2E,
|
|
|
|
DATA_PDU_TYPE_SET_ERROR_INFO = 0x2F,
|
|
|
|
DATA_PDU_TYPE_DRAW_NINEGRID_ERROR = 0x30,
|
|
|
|
DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR = 0x31,
|
|
|
|
DATA_PDU_TYPE_ARC_STATUS = 0x32,
|
|
|
|
DATA_PDU_TYPE_STATUS_INFO = 0x36,
|
|
|
|
DATA_PDU_TYPE_MONITOR_LAYOUT = 0x37,
|
|
|
|
DATA_PDU_TYPE_FRAME_ACKNOWLEDGE = 0x38
|
|
|
|
} rdpPduType;
|
2011-07-21 23:10:53 +04:00
|
|
|
|
2011-07-22 00:20:41 +04:00
|
|
|
/* Stream Identifiers */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define STREAM_UNDEFINED 0x00
|
|
|
|
#define STREAM_LOW 0x01
|
|
|
|
#define STREAM_MED 0x02
|
|
|
|
#define STREAM_HI 0x04
|
2011-07-22 00:20:41 +04:00
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
struct rdp_rdp
|
|
|
|
{
|
2021-09-03 10:12:23 +03:00
|
|
|
CONNECTION_STATE state;
|
2013-07-20 05:52:28 +04:00
|
|
|
rdpContext* context;
|
2015-02-16 00:04:59 +03:00
|
|
|
rdpNla* nla;
|
2013-11-01 22:13:09 +04:00
|
|
|
rdpMcs* mcs;
|
|
|
|
rdpNego* nego;
|
2014-03-10 19:41:10 +04:00
|
|
|
rdpBulk* bulk;
|
2013-11-01 22:13:09 +04:00
|
|
|
rdpInput* input;
|
|
|
|
rdpUpdate* update;
|
|
|
|
rdpFastPath* fastpath;
|
|
|
|
rdpLicense* license;
|
|
|
|
rdpRedirection* redirection;
|
|
|
|
rdpSettings* settings;
|
2022-06-27 12:44:35 +03:00
|
|
|
rdpSettings* originalSettings;
|
2013-11-01 22:13:09 +04:00
|
|
|
rdpTransport* transport;
|
2014-01-24 03:01:31 +04:00
|
|
|
rdpAutoDetect* autodetect;
|
2014-01-24 17:38:28 +04:00
|
|
|
rdpHeartbeat* heartbeat;
|
2014-01-24 03:01:31 +04:00
|
|
|
rdpMultitransport* multitransport;
|
2016-02-24 19:04:03 +03:00
|
|
|
WINPR_RC4_CTX* rc4_decrypt_key;
|
2011-09-13 10:40:27 +04:00
|
|
|
int decrypt_use_count;
|
2012-02-22 22:23:48 +04:00
|
|
|
int decrypt_checksum_use_count;
|
2016-02-24 19:04:03 +03:00
|
|
|
WINPR_RC4_CTX* rc4_encrypt_key;
|
2011-09-13 10:40:27 +04:00
|
|
|
int encrypt_use_count;
|
2012-02-22 22:23:48 +04:00
|
|
|
int encrypt_checksum_use_count;
|
2016-02-28 01:28:49 +03:00
|
|
|
WINPR_CIPHER_CTX* fips_encrypt;
|
|
|
|
WINPR_CIPHER_CTX* fips_decrypt;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 sec_flags;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL do_crypt;
|
2014-09-19 03:43:28 +04:00
|
|
|
BOOL do_crypt_license;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL do_secure_checksum;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE sign_key[16];
|
|
|
|
BYTE decrypt_key[16];
|
|
|
|
BYTE encrypt_key[16];
|
|
|
|
BYTE decrypt_update_key[16];
|
|
|
|
BYTE encrypt_update_key[16];
|
2021-06-18 10:58:46 +03:00
|
|
|
size_t rc4_key_len;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE fips_sign_key[20];
|
|
|
|
BYTE fips_encrypt_key[24];
|
|
|
|
BYTE fips_decrypt_key[24];
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 errorInfo;
|
|
|
|
UINT32 finalize_sc_pdus;
|
2013-04-15 14:14:09 +04:00
|
|
|
BOOL resendFocus;
|
2013-07-19 01:15:10 +04:00
|
|
|
BOOL AwaitCapabilities;
|
2019-10-23 00:35:18 +03:00
|
|
|
UINT64 inBytes;
|
|
|
|
UINT64 inPackets;
|
|
|
|
UINT64 outBytes;
|
|
|
|
UINT64 outPackets;
|
2020-05-11 09:50:15 +03:00
|
|
|
CRITICAL_SECTION critical;
|
2020-09-02 14:37:04 +03:00
|
|
|
rdpTransportIo* io;
|
2022-03-16 17:28:24 +03:00
|
|
|
void* ioContext;
|
2022-04-19 15:29:17 +03:00
|
|
|
HANDLE abortEvent;
|
2011-07-12 02:46:36 +04:00
|
|
|
};
|
|
|
|
|
2017-05-29 11:50:22 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_read_security_header(wStream* s, UINT16* flags, UINT16* length);
|
2022-04-19 15:29:17 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_write_security_header(wStream* s, UINT16 flags);
|
2011-07-10 23:34:43 +04:00
|
|
|
|
2020-04-06 14:01:20 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_read_share_control_header(wStream* s, UINT16* tpktLength,
|
|
|
|
UINT16* remainingLength, UINT16* type,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT16* channel_id);
|
2011-07-21 21:57:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_read_share_data_header(wStream* s, UINT16* length, BYTE* type,
|
|
|
|
UINT32* share_id, BYTE* compressed_type,
|
|
|
|
UINT16* compressed_len);
|
2011-09-08 09:17:58 +04:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL wStream* rdp_send_stream_init(rdpRdp* rdp);
|
2018-10-02 14:18:13 +03:00
|
|
|
FREERDP_LOCAL wStream* rdp_send_stream_pdu_init(rdpRdp* rdp);
|
2011-08-20 12:43:29 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id);
|
|
|
|
FREERDP_LOCAL void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channel_id);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id);
|
2011-07-22 04:06:28 +04:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL wStream* rdp_data_pdu_init(rdpRdp* rdp);
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id);
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s);
|
2011-07-21 23:10:53 +04:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2020-03-04 16:42:42 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId, const BYTE* data,
|
|
|
|
size_t size);
|
2021-08-26 17:17:51 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_channel_send_packet(rdpRdp* rdp, UINT16 channelId, size_t totalSize,
|
|
|
|
UINT32 flags, const BYTE* data, size_t chunkSize);
|
2011-08-03 07:00:56 +04:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags);
|
|
|
|
FREERDP_LOCAL int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 securityFlags);
|
2014-01-24 03:01:31 +04:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s);
|
2011-09-03 05:34:51 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_LOCAL int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra);
|
2015-02-15 22:54:10 +03:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL int rdp_check_fds(rdpRdp* rdp);
|
2011-08-01 08:43:53 +04:00
|
|
|
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL rdpRdp* rdp_new(rdpContext* context);
|
2021-09-07 11:03:36 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_reset(rdpRdp* rdp);
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL void rdp_free(rdpRdp* rdp);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2020-09-02 14:37:04 +03:00
|
|
|
FREERDP_LOCAL const rdpTransportIo* rdp_get_io_callbacks(rdpRdp* rdp);
|
|
|
|
FREERDP_LOCAL BOOL rdp_set_io_callbacks(rdpRdp* rdp, const rdpTransportIo* io_callbacks);
|
|
|
|
|
2022-03-16 17:28:24 +03:00
|
|
|
FREERDP_LOCAL BOOL rdp_set_io_callback_context(rdpRdp* rdp, void* usercontext);
|
|
|
|
FREERDP_LOCAL void* rdp_get_io_callback_context(rdpRdp* rdp);
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define RDP_TAG FREERDP_TAG("core.rdp")
|
2011-09-02 21:29:17 +04:00
|
|
|
#ifdef WITH_DEBUG_RDP
|
2016-10-07 15:04:40 +03:00
|
|
|
#define DEBUG_RDP(...) WLog_DBG(RDP_TAG, __VA_ARGS__)
|
2011-09-02 21:29:17 +04:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
#define DEBUG_RDP(...) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
} while (0)
|
2011-09-02 21:29:17 +04:00
|
|
|
#endif
|
|
|
|
|
2020-11-19 17:21:49 +03:00
|
|
|
const char* data_pdu_type_to_string(UINT8 type);
|
|
|
|
const char* pdu_type_to_str(UINT16 pduType);
|
|
|
|
|
2022-06-23 10:59:24 +03:00
|
|
|
BOOL rdp_finalize_reset_flags(rdpRdp* rdp, BOOL clearAll);
|
|
|
|
BOOL rdp_finalize_set_flag(rdpRdp* rdp, UINT32 flag);
|
|
|
|
BOOL rdp_finalize_is_flag_set(rdpRdp* rdp, UINT32 flag);
|
|
|
|
const char* rdp_finalize_flags_to_str(UINT32 flags, char* buffer, size_t size);
|
|
|
|
|
2020-03-09 23:54:34 +03:00
|
|
|
BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, UINT16* pLength, UINT16 securityFlags);
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2013-12-21 03:26:07 +04:00
|
|
|
BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo);
|
2015-01-13 19:09:36 +03:00
|
|
|
BOOL rdp_send_error_info(rdpRdp* rdp);
|
2013-12-21 03:26:07 +04:00
|
|
|
|
2017-06-06 15:01:41 +03:00
|
|
|
#endif /* FREERDP_LIB_CORE_RDP_H */
|