Support for OpenSSL 1.1.0
[platform/upstream/freerdp.git] / libfreerdp / core / rdp.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Implementation
3  * RDP Core
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  * Copyright 2014 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #ifndef __RDP_H
22 #define __RDP_H
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "nla.h"
29 #include "mcs.h"
30 #include "tpkt.h"
31 #include "bulk.h"
32 #include "fastpath.h"
33 #include "tpdu.h"
34 #include "nego.h"
35 #include "input.h"
36 #include "update.h"
37 #include "license.h"
38 #include "errinfo.h"
39 #include "autodetect.h"
40 #include "heartbeat.h"
41 #include "multitransport.h"
42 #include "security.h"
43 #include "transport.h"
44 #include "connection.h"
45 #include "redirection.h"
46 #include "capabilities.h"
47 #include "channels.h"
48
49 #include <freerdp/freerdp.h>
50 #include <freerdp/settings.h>
51 #include <freerdp/log.h>
52 #include <freerdp/api.h>
53
54 #include <winpr/stream.h>
55 #include <winpr/crypto.h>
56
57 /* Security Header Flags */
58 #define SEC_EXCHANGE_PKT                                        0x0001
59 #define SEC_TRANSPORT_REQ                                       0x0002
60 #define SEC_TRANSPORT_RSP                                       0x0004
61 #define SEC_ENCRYPT                                             0x0008
62 #define SEC_RESET_SEQNO                                         0x0010
63 #define SEC_IGNORE_SEQNO                                        0x0020
64 #define SEC_INFO_PKT                                            0x0040
65 #define SEC_LICENSE_PKT                                         0x0080
66 #define SEC_LICENSE_ENCRYPT_CS                                  0x0200
67 #define SEC_LICENSE_ENCRYPT_SC                                  0x0200
68 #define SEC_REDIRECTION_PKT                                     0x0400
69 #define SEC_SECURE_CHECKSUM                                     0x0800
70 #define SEC_AUTODETECT_REQ                                      0x1000
71 #define SEC_AUTODETECT_RSP                                      0x2000
72 #define SEC_HEARTBEAT                                           0x4000
73 #define SEC_FLAGSHI_VALID                                       0x8000
74
75 #define SEC_PKT_CS_MASK                                         (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
76 #define SEC_PKT_SC_MASK                                         (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
77 #define SEC_PKT_MASK                                            (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
78
79 #define RDP_SECURITY_HEADER_LENGTH                              4
80 #define RDP_SHARE_CONTROL_HEADER_LENGTH                         6
81 #define RDP_SHARE_DATA_HEADER_LENGTH                            12
82 #define RDP_PACKET_HEADER_MAX_LENGTH                            (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_MAX_LENGTH)
83
84 #define PDU_TYPE_DEMAND_ACTIVE                                  0x1
85 #define PDU_TYPE_CONFIRM_ACTIVE                                 0x3
86 #define PDU_TYPE_DEACTIVATE_ALL                                 0x6
87 #define PDU_TYPE_DATA                                           0x7
88 #define PDU_TYPE_SERVER_REDIRECTION                             0xA
89
90 #define PDU_TYPE_FLOW_TEST                                      0x41
91 #define PDU_TYPE_FLOW_RESPONSE                                  0x42
92 #define PDU_TYPE_FLOW_STOP                                      0x43
93
94 #define FINALIZE_SC_SYNCHRONIZE_PDU                             0x01
95 #define FINALIZE_SC_CONTROL_COOPERATE_PDU                       0x02
96 #define FINALIZE_SC_CONTROL_GRANTED_PDU                         0x04
97 #define FINALIZE_SC_FONT_MAP_PDU                                0x08
98 #define FINALIZE_SC_COMPLETE                                    0x0F
99
100 /* Data PDU Types */
101 #define DATA_PDU_TYPE_UPDATE                                    0x02
102 #define DATA_PDU_TYPE_CONTROL                                   0x14
103 #define DATA_PDU_TYPE_POINTER                                   0x1B
104 #define DATA_PDU_TYPE_INPUT                                     0x1C
105 #define DATA_PDU_TYPE_SYNCHRONIZE                               0x1F
106 #define DATA_PDU_TYPE_REFRESH_RECT                              0x21
107 #define DATA_PDU_TYPE_PLAY_SOUND                                0x22
108 #define DATA_PDU_TYPE_SUPPRESS_OUTPUT                           0x23
109 #define DATA_PDU_TYPE_SHUTDOWN_REQUEST                          0x24
110 #define DATA_PDU_TYPE_SHUTDOWN_DENIED                           0x25
111 #define DATA_PDU_TYPE_SAVE_SESSION_INFO                         0x26
112 #define DATA_PDU_TYPE_FONT_LIST                                 0x27
113 #define DATA_PDU_TYPE_FONT_MAP                                  0x28
114 #define DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS                   0x29
115 #define DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST              0x2B
116 #define DATA_PDU_TYPE_BITMAP_CACHE_ERROR                        0x2C
117 #define DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS                   0x2D
118 #define DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR                     0x2E
119 #define DATA_PDU_TYPE_SET_ERROR_INFO                            0x2F
120 #define DATA_PDU_TYPE_DRAW_NINEGRID_ERROR                       0x30
121 #define DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR                        0x31
122 #define DATA_PDU_TYPE_ARC_STATUS                                0x32
123 #define DATA_PDU_TYPE_STATUS_INFO                               0x36
124 #define DATA_PDU_TYPE_MONITOR_LAYOUT                            0x37
125 #define DATA_PDU_TYPE_FRAME_ACKNOWLEDGE                         0x38
126
127 /* Stream Identifiers */
128 #define STREAM_UNDEFINED                                        0x00
129 #define STREAM_LOW                                              0x01
130 #define STREAM_MED                                              0x02
131 #define STREAM_HI                                               0x04
132
133 struct rdp_rdp
134 {
135         int state;
136         freerdp* instance;
137         rdpContext* context;
138         rdpNla* nla;
139         rdpMcs* mcs;
140         rdpNego* nego;
141         rdpBulk* bulk;
142         rdpInput* input;
143         rdpUpdate* update;
144         rdpFastPath* fastpath;
145         rdpLicense* license;
146         rdpRedirection* redirection;
147         rdpSettings* settings;
148         rdpTransport* transport;
149         rdpAutoDetect* autodetect;
150         rdpHeartbeat* heartbeat;
151         rdpMultitransport* multitransport;
152         WINPR_RC4_CTX* rc4_decrypt_key;
153         int decrypt_use_count;
154         int decrypt_checksum_use_count;
155         WINPR_RC4_CTX* rc4_encrypt_key;
156         int encrypt_use_count;
157         int encrypt_checksum_use_count;
158         WINPR_CIPHER_CTX* fips_encrypt;
159         WINPR_CIPHER_CTX* fips_decrypt;
160         UINT32 sec_flags;
161         BOOL do_crypt;
162         BOOL do_crypt_license;
163         BOOL do_secure_checksum;
164         BYTE sign_key[16];
165         BYTE decrypt_key[16];
166         BYTE encrypt_key[16];
167         BYTE decrypt_update_key[16];
168         BYTE encrypt_update_key[16];
169         int rc4_key_len;
170         BYTE fips_sign_key[20];
171         BYTE fips_encrypt_key[24];
172         BYTE fips_decrypt_key[24];
173         UINT32 errorInfo;
174         UINT32 finalize_sc_pdus;
175         BOOL resendFocus;
176         BOOL deactivation_reactivation;
177         BOOL AwaitCapabilities;
178         rdpSettings* settingsCopy;
179 };
180
181 FREERDP_LOCAL BOOL rdp_read_security_header(wStream* s, UINT16* flags);
182 FREERDP_LOCAL void rdp_write_security_header(wStream* s, UINT16 flags);
183
184 FREERDP_LOCAL BOOL rdp_read_share_control_header(wStream* s, UINT16* length,
185         UINT16* type, UINT16* channel_id);
186 FREERDP_LOCAL void rdp_write_share_control_header(wStream* s, UINT16 length,
187         UINT16 type, UINT16 channel_id);
188
189 FREERDP_LOCAL BOOL rdp_read_share_data_header(wStream* s, UINT16* length,
190         BYTE* type, UINT32* share_id,
191         BYTE* compressed_type, UINT16* compressed_len);
192
193 FREERDP_LOCAL void rdp_write_share_data_header(wStream* s, UINT16 length,
194         BYTE type, UINT32 share_id);
195
196 FREERDP_LOCAL int rdp_init_stream(rdpRdp* rdp, wStream* s);
197 FREERDP_LOCAL wStream* rdp_send_stream_init(rdpRdp* rdp);
198
199 FREERDP_LOCAL BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length,
200                                    UINT16* channel_id);
201 FREERDP_LOCAL void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length,
202                                     UINT16 channel_id);
203
204 FREERDP_LOCAL int rdp_init_stream_pdu(rdpRdp* rdp, wStream* s);
205 FREERDP_LOCAL BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type,
206                                 UINT16 channel_id);
207
208 FREERDP_LOCAL wStream* rdp_data_pdu_init(rdpRdp* rdp);
209 FREERDP_LOCAL int rdp_init_stream_data_pdu(rdpRdp* rdp, wStream* s);
210 FREERDP_LOCAL BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type,
211                                      UINT16 channel_id);
212 FREERDP_LOCAL int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s);
213
214 FREERDP_LOCAL BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channelId);
215
216 FREERDP_LOCAL int rdp_send_channel_data(rdpRdp* rdp, UINT16 channelId,
217                                         BYTE* data, int size);
218
219 FREERDP_LOCAL wStream* rdp_message_channel_pdu_init(rdpRdp* rdp);
220 FREERDP_LOCAL BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s,
221         UINT16 sec_flags);
222 FREERDP_LOCAL int rdp_recv_message_channel_pdu(rdpRdp* rdp, wStream* s,
223         UINT16 securityFlags);
224
225 FREERDP_LOCAL int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s);
226
227 FREERDP_LOCAL void rdp_read_flow_control_pdu(wStream* s, UINT16* type);
228
229 FREERDP_LOCAL BOOL rdp_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount,
230         const rdpMonitor* monitorDefArray);
231
232 FREERDP_LOCAL int rdp_recv_callback(rdpTransport* transport, wStream* s,
233                                     void* extra);
234
235 FREERDP_LOCAL int rdp_check_fds(rdpRdp* rdp);
236
237 FREERDP_LOCAL rdpRdp* rdp_new(rdpContext* context);
238 FREERDP_LOCAL void rdp_reset(rdpRdp* rdp);
239 FREERDP_LOCAL void rdp_free(rdpRdp* rdp);
240
241 #define RDP_TAG FREERDP_TAG("core.rdp")
242 #ifdef WITH_DEBUG_RDP
243 #define DEBUG_RDP(...) WLog_DBG(RDP_TAG, __VA_ARGS__)
244 #else
245 #define DEBUG_RDP(...) do { } while (0)
246 #endif
247
248 BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, int length, UINT16 securityFlags);
249
250 BOOL rdp_set_error_info(rdpRdp* rdp, UINT32 errorInfo);
251 BOOL rdp_send_error_info(rdpRdp* rdp);
252
253 #endif /* __RDP_H */