2011-07-10 23:34:43 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* RDP Core
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rdp.h"
|
|
|
|
|
2011-07-27 03:14:11 +04:00
|
|
|
#include "info.h"
|
|
|
|
#include "per.h"
|
|
|
|
#include "redirection.h"
|
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
static const char* const DATA_PDU_TYPE_STRINGS[] =
|
2011-07-22 19:02:31 +04:00
|
|
|
{
|
|
|
|
"", "", /* 0x00 - 0x01 */
|
|
|
|
"Update", /* 0x02 */
|
|
|
|
"", "", "", "", "", "", "", "", /* 0x03 - 0x0A */
|
|
|
|
"", "", "", "", "", "", "", "", "", /* 0x0B - 0x13 */
|
|
|
|
"Control", /* 0x14 */
|
|
|
|
"", "", "", "", "", "", /* 0x15 - 0x1A */
|
|
|
|
"Pointer", /* 0x1B */
|
|
|
|
"Input", /* 0x1C */
|
|
|
|
"", "", /* 0x1D - 0x1E */
|
|
|
|
"Synchronize", /* 0x1F */
|
|
|
|
"", /* 0x20 */
|
|
|
|
"Refresh Rect", /* 0x21 */
|
|
|
|
"Play Sound", /* 0x22 */
|
|
|
|
"Suppress Output", /* 0x23 */
|
|
|
|
"Shutdown Request", /* 0x24 */
|
|
|
|
"Shutdown Denied", /* 0x25 */
|
|
|
|
"Save Session Info", /* 0x26 */
|
|
|
|
"Font List", /* 0x27 */
|
|
|
|
"Font Map", /* 0x28 */
|
|
|
|
"Set Keyboard Indicators", /* 0x29 */
|
|
|
|
"", /* 0x2A */
|
|
|
|
"Bitmap Cache Persistent List", /* 0x2B */
|
|
|
|
"Bitmap Cache Error", /* 0x2C */
|
|
|
|
"Set Keyboard IME Status", /* 0x2D */
|
|
|
|
"Offscreen Cache Error", /* 0x2E */
|
|
|
|
"Set Error Info", /* 0x2F */
|
|
|
|
"Draw Nine Grid Error", /* 0x30 */
|
|
|
|
"Draw GDI+ Error", /* 0x31 */
|
|
|
|
"ARC Status", /* 0x32 */
|
|
|
|
"", "", "", /* 0x33 - 0x35 */
|
|
|
|
"Status Info", /* 0x36 */
|
|
|
|
"Monitor Layout" /* 0x37 */
|
|
|
|
"", "", "", /* 0x38 - 0x40 */
|
|
|
|
"", "", "", "", "", "" /* 0x41 - 0x46 */
|
|
|
|
};
|
|
|
|
|
2011-07-11 23:58:39 +04:00
|
|
|
/**
|
|
|
|
* Read RDP Security Header.\n
|
|
|
|
* @msdn{cc240579}
|
|
|
|
* @param s stream
|
|
|
|
* @param flags security flags
|
|
|
|
*/
|
|
|
|
|
|
|
|
void rdp_read_security_header(STREAM* s, uint16* flags)
|
|
|
|
{
|
|
|
|
/* Basic Security Header */
|
|
|
|
stream_read_uint16(s, *flags); /* flags */
|
|
|
|
stream_seek(s, 2); /* flagsHi (unused) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write RDP Security Header.\n
|
|
|
|
* @msdn{cc240579}
|
|
|
|
* @param s stream
|
|
|
|
* @param flags security flags
|
|
|
|
*/
|
|
|
|
|
2011-07-10 23:34:43 +04:00
|
|
|
void rdp_write_security_header(STREAM* s, uint16 flags)
|
|
|
|
{
|
|
|
|
/* Basic Security Header */
|
|
|
|
stream_write_uint16(s, flags); /* flags */
|
|
|
|
stream_write_uint16(s, 0); /* flagsHi (unused) */
|
|
|
|
}
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2011-08-21 11:52:44 +04:00
|
|
|
boolean rdp_read_share_control_header(STREAM* s, uint16* length, uint16* type, uint16* channel_id)
|
2011-07-20 00:30:05 +04:00
|
|
|
{
|
|
|
|
/* Share Control Header */
|
|
|
|
stream_read_uint16(s, *length); /* totalLength */
|
|
|
|
stream_read_uint16(s, *type); /* pduType */
|
|
|
|
stream_read_uint16(s, *channel_id); /* pduSource */
|
|
|
|
*type &= 0x0F; /* type is in the 4 least significant bits */
|
2011-08-21 11:52:44 +04:00
|
|
|
|
|
|
|
if (*length - 6 > stream_get_left(s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-21 11:52:44 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-20 00:30:05 +04:00
|
|
|
}
|
|
|
|
|
2011-07-21 21:57:57 +04:00
|
|
|
void rdp_write_share_control_header(STREAM* s, uint16 length, uint16 type, uint16 channel_id)
|
|
|
|
{
|
2012-01-16 00:16:32 +04:00
|
|
|
length -= RDP_PACKET_HEADER_LENGTH;
|
2011-07-24 02:05:34 +04:00
|
|
|
|
2011-07-21 21:57:57 +04:00
|
|
|
/* Share Control Header */
|
|
|
|
stream_write_uint16(s, length); /* totalLength */
|
2011-07-22 05:44:11 +04:00
|
|
|
stream_write_uint16(s, type | 0x10); /* pduType */
|
2011-07-21 21:57:57 +04:00
|
|
|
stream_write_uint16(s, channel_id); /* pduSource */
|
|
|
|
}
|
|
|
|
|
2011-09-08 09:17:58 +04:00
|
|
|
boolean rdp_read_share_data_header(STREAM* s, uint16* length, uint8* type, uint32* share_id,
|
|
|
|
uint8 *compressed_type, uint16 *compressed_len)
|
2011-07-21 23:10:53 +04:00
|
|
|
{
|
2011-08-21 18:52:37 +04:00
|
|
|
if (stream_get_left(s) < 12)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2011-07-21 23:10:53 +04:00
|
|
|
/* Share Data Header */
|
2011-07-22 00:20:41 +04:00
|
|
|
stream_read_uint32(s, *share_id); /* shareId (4 bytes) */
|
2011-07-21 23:10:53 +04:00
|
|
|
stream_seek_uint8(s); /* pad1 (1 byte) */
|
|
|
|
stream_seek_uint8(s); /* streamId (1 byte) */
|
2011-07-22 00:20:41 +04:00
|
|
|
stream_read_uint16(s, *length); /* uncompressedLength (2 bytes) */
|
|
|
|
stream_read_uint8(s, *type); /* pduType2, Data PDU Type (1 byte) */
|
2012-01-16 00:16:32 +04:00
|
|
|
|
2011-09-08 09:17:58 +04:00
|
|
|
if (*type & 0x80)
|
|
|
|
{
|
|
|
|
stream_read_uint8(s, *compressed_type); /* compressedType (1 byte) */
|
|
|
|
stream_read_uint16(s, *compressed_len); /* compressedLength (2 bytes) */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-09 17:50:16 +04:00
|
|
|
stream_seek(s, 3);
|
2011-09-08 09:17:58 +04:00
|
|
|
*compressed_type = 0;
|
|
|
|
*compressed_len = 0;
|
|
|
|
}
|
2011-08-21 18:52:37 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-21 23:10:53 +04:00
|
|
|
}
|
|
|
|
|
2011-07-22 00:20:41 +04:00
|
|
|
void rdp_write_share_data_header(STREAM* s, uint16 length, uint8 type, uint32 share_id)
|
2011-07-21 23:10:53 +04:00
|
|
|
{
|
2011-07-24 02:05:34 +04:00
|
|
|
length -= RDP_PACKET_HEADER_LENGTH;
|
|
|
|
length -= RDP_SHARE_CONTROL_HEADER_LENGTH;
|
|
|
|
length -= RDP_SHARE_DATA_HEADER_LENGTH;
|
|
|
|
|
2011-07-21 23:10:53 +04:00
|
|
|
/* Share Data Header */
|
2011-07-22 00:20:41 +04:00
|
|
|
stream_write_uint32(s, share_id); /* shareId (4 bytes) */
|
2011-07-21 23:10:53 +04:00
|
|
|
stream_write_uint8(s, 0); /* pad1 (1 byte) */
|
2011-07-22 00:20:41 +04:00
|
|
|
stream_write_uint8(s, STREAM_LOW); /* streamId (1 byte) */
|
2011-07-21 23:10:53 +04:00
|
|
|
stream_write_uint16(s, length); /* uncompressedLength (2 bytes) */
|
|
|
|
stream_write_uint8(s, type); /* pduType2, Data PDU Type (1 byte) */
|
2011-07-22 05:44:11 +04:00
|
|
|
stream_write_uint8(s, 0); /* compressedType (1 byte) */
|
|
|
|
stream_write_uint16(s, 0); /* compressedLength (2 bytes) */
|
2011-07-21 23:10:53 +04:00
|
|
|
}
|
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
static int rdp_security_stream_init(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
if (rdp->do_crypt)
|
|
|
|
{
|
|
|
|
stream_seek(s, 12);
|
2011-09-16 03:54:03 +04:00
|
|
|
if (rdp->settings->encryption_method == ENCRYPTION_METHOD_FIPS)
|
|
|
|
stream_seek(s, 4);
|
2011-09-13 10:40:27 +04:00
|
|
|
rdp->sec_flags |= SEC_ENCRYPT;
|
|
|
|
}
|
|
|
|
else if (rdp->sec_flags != 0)
|
|
|
|
{
|
|
|
|
stream_seek(s, 4);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
|
|
|
* Initialize an RDP packet stream.\n
|
|
|
|
* @param rdp rdp module
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
STREAM* rdp_send_stream_init(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-09-13 10:40:27 +04:00
|
|
|
|
2011-07-21 21:57:57 +04:00
|
|
|
s = transport_send_stream_init(rdp->transport, 2048);
|
2011-07-12 02:46:36 +04:00
|
|
|
stream_seek(s, RDP_PACKET_HEADER_LENGTH);
|
2011-09-13 10:40:27 +04:00
|
|
|
rdp_security_stream_init(rdp, s);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-07-22 04:06:28 +04:00
|
|
|
STREAM* rdp_pdu_init(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
s = transport_send_stream_init(rdp->transport, 2048);
|
|
|
|
stream_seek(s, RDP_PACKET_HEADER_LENGTH);
|
2011-09-13 10:40:27 +04:00
|
|
|
rdp_security_stream_init(rdp, s);
|
2011-07-22 04:06:28 +04:00
|
|
|
stream_seek(s, RDP_SHARE_CONTROL_HEADER_LENGTH);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-07-21 23:10:53 +04:00
|
|
|
STREAM* rdp_data_pdu_init(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
s = transport_send_stream_init(rdp->transport, 2048);
|
|
|
|
stream_seek(s, RDP_PACKET_HEADER_LENGTH);
|
2011-09-13 10:40:27 +04:00
|
|
|
rdp_security_stream_init(rdp, s);
|
2011-07-24 02:05:34 +04:00
|
|
|
stream_seek(s, RDP_SHARE_CONTROL_HEADER_LENGTH);
|
2011-07-21 23:10:53 +04:00
|
|
|
stream_seek(s, RDP_SHARE_DATA_HEADER_LENGTH);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-08-20 12:43:29 +04:00
|
|
|
/**
|
|
|
|
* Read an RDP packet header.\n
|
|
|
|
* @param rdp rdp module
|
|
|
|
* @param s stream
|
|
|
|
* @param length RDP packet length
|
|
|
|
* @param channel_id channel id
|
|
|
|
*/
|
|
|
|
|
|
|
|
boolean rdp_read_header(rdpRdp* rdp, STREAM* s, uint16* length, uint16* channel_id)
|
|
|
|
{
|
|
|
|
uint16 initiator;
|
|
|
|
enum DomainMCSPDU MCSPDU;
|
|
|
|
|
2011-08-25 00:54:32 +04:00
|
|
|
MCSPDU = (rdp->settings->server_mode) ? DomainMCSPDU_SendDataRequest : DomainMCSPDU_SendDataIndication;
|
2011-08-20 12:43:29 +04:00
|
|
|
mcs_read_domain_mcspdu_header(s, &MCSPDU, length);
|
|
|
|
|
|
|
|
per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID); /* initiator (UserId) */
|
|
|
|
per_read_integer16(s, channel_id, 0); /* channelId */
|
|
|
|
stream_seek(s, 1); /* dataPriority + Segmentation (0x70) */
|
|
|
|
per_read_length(s, length); /* userData (OCTET_STRING) */
|
2011-08-25 00:54:32 +04:00
|
|
|
|
2011-08-20 12:43:29 +04:00
|
|
|
if (*length > stream_get_left(s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-20 12:43:29 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-20 12:43:29 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 09:16:59 +04:00
|
|
|
/**
|
|
|
|
* Write an RDP packet header.\n
|
|
|
|
* @param rdp rdp module
|
|
|
|
* @param s stream
|
|
|
|
* @param length RDP packet length
|
2011-08-03 08:34:55 +04:00
|
|
|
* @param channel_id channel id
|
2011-07-12 09:16:59 +04:00
|
|
|
*/
|
|
|
|
|
2011-08-20 12:43:29 +04:00
|
|
|
void rdp_write_header(rdpRdp* rdp, STREAM* s, uint16 length, uint16 channel_id)
|
2011-07-12 09:16:59 +04:00
|
|
|
{
|
2011-09-16 03:54:03 +04:00
|
|
|
int body_length;
|
2011-11-10 00:59:03 +04:00
|
|
|
enum DomainMCSPDU MCSPDU;
|
2011-08-20 12:43:29 +04:00
|
|
|
|
2011-08-25 00:54:32 +04:00
|
|
|
MCSPDU = (rdp->settings->server_mode) ? DomainMCSPDU_SendDataIndication : DomainMCSPDU_SendDataRequest;
|
2011-08-20 12:43:29 +04:00
|
|
|
|
2011-11-10 00:59:03 +04:00
|
|
|
if ((rdp->sec_flags & SEC_ENCRYPT) && (rdp->settings->encryption_method == ENCRYPTION_METHOD_FIPS))
|
2011-09-27 09:30:58 +04:00
|
|
|
{
|
2011-09-16 03:54:03 +04:00
|
|
|
int pad;
|
|
|
|
|
|
|
|
body_length = length - RDP_PACKET_HEADER_LENGTH - 16;
|
|
|
|
pad = 8 - (body_length % 8);
|
|
|
|
if (pad != 8)
|
|
|
|
length += pad;
|
|
|
|
}
|
|
|
|
|
2011-08-20 12:43:29 +04:00
|
|
|
mcs_write_domain_mcspdu_header(s, MCSPDU, length, 0);
|
2011-07-12 09:16:59 +04:00
|
|
|
per_write_integer16(s, rdp->mcs->user_id, MCS_BASE_CHANNEL_ID); /* initiator */
|
2011-08-03 08:34:55 +04:00
|
|
|
per_write_integer16(s, channel_id, 0); /* channelId */
|
2011-07-12 09:16:59 +04:00
|
|
|
stream_write_uint8(s, 0x70); /* dataPriority + segmentation */
|
2011-07-24 02:05:34 +04:00
|
|
|
|
|
|
|
length = (length - RDP_PACKET_HEADER_LENGTH) | 0x8000;
|
|
|
|
stream_write_uint16_be(s, length); /* userData (OCTET_STRING) */
|
2011-07-12 09:16:59 +04:00
|
|
|
}
|
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
static uint32 rdp_security_stream_out(rdpRdp* rdp, STREAM* s, int length)
|
|
|
|
{
|
|
|
|
uint8* data;
|
2011-09-15 06:09:33 +04:00
|
|
|
uint32 sec_flags;
|
2011-09-16 03:54:03 +04:00
|
|
|
uint32 pad = 0;
|
2011-09-13 10:40:27 +04:00
|
|
|
|
|
|
|
sec_flags = rdp->sec_flags;
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
if (sec_flags != 0)
|
|
|
|
{
|
|
|
|
rdp_write_security_header(s, sec_flags);
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
if (sec_flags & SEC_ENCRYPT)
|
|
|
|
{
|
2011-09-16 03:54:03 +04:00
|
|
|
if (rdp->settings->encryption_method == ENCRYPTION_METHOD_FIPS)
|
|
|
|
{
|
|
|
|
data = s->p + 12;
|
|
|
|
|
|
|
|
length = length - (data - s->data);
|
|
|
|
stream_write_uint16(s, 0x10); /* length */
|
|
|
|
stream_write_uint8(s, 0x1); /* TSFIPS_VERSION 1*/
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
/* handle padding */
|
|
|
|
pad = 8 - (length % 8);
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
if (pad == 8)
|
|
|
|
pad = 0;
|
|
|
|
if (pad)
|
|
|
|
memset(data+length, 0, pad);
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
stream_write_uint8(s, pad);
|
|
|
|
|
|
|
|
security_hmac_signature(data, length, s->p, rdp);
|
|
|
|
stream_seek(s, 8);
|
|
|
|
security_fips_encrypt(data, length + pad, rdp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = s->p + 8;
|
|
|
|
length = length - (data - s->data);
|
2012-01-19 08:07:30 +04:00
|
|
|
security_mac_signature(rdp, data, length, s->p);
|
2011-09-16 03:54:03 +04:00
|
|
|
stream_seek(s, 8);
|
|
|
|
security_encrypt(s->p, length, rdp);
|
|
|
|
}
|
2011-09-13 10:40:27 +04:00
|
|
|
}
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
rdp->sec_flags = 0;
|
|
|
|
}
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
return pad;
|
2011-09-13 10:40:27 +04:00
|
|
|
}
|
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
static uint32 rdp_get_sec_bytes(rdpRdp* rdp)
|
2011-09-13 10:40:27 +04:00
|
|
|
{
|
|
|
|
uint32 sec_bytes;
|
|
|
|
|
2011-09-24 10:09:29 +04:00
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
|
|
|
{
|
2011-09-13 10:40:27 +04:00
|
|
|
sec_bytes = 12;
|
2012-01-14 01:20:36 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
if (rdp->settings->encryption_method == ENCRYPTION_METHOD_FIPS)
|
|
|
|
sec_bytes += 4;
|
2011-09-24 10:09:29 +04:00
|
|
|
}
|
|
|
|
else if (rdp->sec_flags != 0)
|
2012-01-14 01:20:36 +04:00
|
|
|
{
|
2011-09-13 10:40:27 +04:00
|
|
|
sec_bytes = 4;
|
2012-01-14 01:20:36 +04:00
|
|
|
}
|
2011-09-13 10:40:27 +04:00
|
|
|
else
|
2012-01-14 01:20:36 +04:00
|
|
|
{
|
2011-09-13 10:40:27 +04:00
|
|
|
sec_bytes = 0;
|
2012-01-14 01:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
return sec_bytes;
|
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
|
|
|
* Send an RDP packet.\n
|
|
|
|
* @param rdp RDP module
|
|
|
|
* @param s stream
|
2011-08-03 08:34:55 +04:00
|
|
|
* @param channel_id channel id
|
2011-07-12 04:46:03 +04:00
|
|
|
*/
|
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
boolean rdp_send(rdpRdp* rdp, STREAM* s, uint16 channel_id)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2011-08-20 12:43:29 +04:00
|
|
|
uint16 length;
|
2011-09-13 10:40:27 +04:00
|
|
|
uint32 sec_bytes;
|
|
|
|
uint8* sec_hold;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
length = stream_get_length(s);
|
|
|
|
stream_set_pos(s, 0);
|
|
|
|
|
2011-08-03 08:34:55 +04:00
|
|
|
rdp_write_header(rdp, s, length, channel_id);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
sec_bytes = rdp_get_sec_bytes(rdp);
|
2011-09-13 10:40:27 +04:00
|
|
|
sec_hold = s->p;
|
|
|
|
stream_seek(s, sec_bytes);
|
|
|
|
|
|
|
|
s->p = sec_hold;
|
2011-09-16 03:54:03 +04:00
|
|
|
length += rdp_security_stream_out(rdp, s, length);
|
2011-09-13 10:40:27 +04:00
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
stream_set_pos(s, length);
|
2011-08-22 11:03:58 +04:00
|
|
|
if (transport_write(rdp->transport, s) < 0)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-12 02:46:36 +04:00
|
|
|
}
|
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
boolean rdp_send_pdu(rdpRdp* rdp, STREAM* s, uint16 type, uint16 channel_id)
|
2011-07-22 04:06:28 +04:00
|
|
|
{
|
2011-08-20 12:43:29 +04:00
|
|
|
uint16 length;
|
2011-09-13 10:40:27 +04:00
|
|
|
uint32 sec_bytes;
|
|
|
|
uint8* sec_hold;
|
2011-07-22 04:06:28 +04:00
|
|
|
|
|
|
|
length = stream_get_length(s);
|
|
|
|
stream_set_pos(s, 0);
|
|
|
|
|
2011-08-03 08:34:55 +04:00
|
|
|
rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID);
|
2011-09-13 10:40:27 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
sec_bytes = rdp_get_sec_bytes(rdp);
|
2011-09-13 10:40:27 +04:00
|
|
|
sec_hold = s->p;
|
|
|
|
stream_seek(s, sec_bytes);
|
|
|
|
|
2012-01-16 00:16:32 +04:00
|
|
|
rdp_write_share_control_header(s, length - sec_bytes, type, channel_id);
|
2011-07-22 04:06:28 +04:00
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
s->p = sec_hold;
|
2011-09-16 03:54:03 +04:00
|
|
|
length += rdp_security_stream_out(rdp, s, length);
|
2011-09-13 10:40:27 +04:00
|
|
|
|
2011-07-22 04:06:28 +04:00
|
|
|
stream_set_pos(s, length);
|
2011-08-22 11:03:58 +04:00
|
|
|
if (transport_write(rdp->transport, s) < 0)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-22 04:06:28 +04:00
|
|
|
}
|
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
boolean rdp_send_data_pdu(rdpRdp* rdp, STREAM* s, uint8 type, uint16 channel_id)
|
2011-07-21 23:10:53 +04:00
|
|
|
{
|
2011-08-20 12:43:29 +04:00
|
|
|
uint16 length;
|
2011-09-13 10:40:27 +04:00
|
|
|
uint32 sec_bytes;
|
|
|
|
uint8* sec_hold;
|
2011-07-21 23:10:53 +04:00
|
|
|
|
|
|
|
length = stream_get_length(s);
|
|
|
|
stream_set_pos(s, 0);
|
|
|
|
|
2011-08-03 08:34:55 +04:00
|
|
|
rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID);
|
2011-09-13 10:40:27 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
sec_bytes = rdp_get_sec_bytes(rdp);
|
2011-09-13 10:40:27 +04:00
|
|
|
sec_hold = s->p;
|
|
|
|
stream_seek(s, sec_bytes);
|
|
|
|
|
2012-01-16 00:16:32 +04:00
|
|
|
rdp_write_share_control_header(s, length - sec_bytes, PDU_TYPE_DATA, channel_id);
|
|
|
|
rdp_write_share_data_header(s, length - sec_bytes, type, rdp->settings->share_id);
|
2011-07-21 23:10:53 +04:00
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
s->p = sec_hold;
|
2011-09-16 03:54:03 +04:00
|
|
|
length += rdp_security_stream_out(rdp, s, length);
|
2011-09-13 10:40:27 +04:00
|
|
|
|
2011-07-21 23:10:53 +04:00
|
|
|
stream_set_pos(s, length);
|
2011-08-22 11:03:58 +04:00
|
|
|
if (transport_write(rdp->transport, s) < 0)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-21 23:10:53 +04:00
|
|
|
}
|
|
|
|
|
2011-10-24 22:37:21 +04:00
|
|
|
void rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, STREAM* s)
|
2011-07-22 00:20:41 +04:00
|
|
|
{
|
2011-10-24 22:37:21 +04:00
|
|
|
stream_read_uint32(s, rdp->errorInfo); /* errorInfo (4 bytes) */
|
2011-07-22 00:20:41 +04:00
|
|
|
|
2011-10-24 22:37:21 +04:00
|
|
|
if (rdp->errorInfo != ERRINFO_SUCCESS)
|
|
|
|
rdp_print_errinfo(rdp->errorInfo);
|
2011-07-22 00:20:41 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
void rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s)
|
2011-07-22 00:20:41 +04:00
|
|
|
{
|
|
|
|
uint8 type;
|
|
|
|
uint16 length;
|
|
|
|
uint32 share_id;
|
2011-09-08 09:17:58 +04:00
|
|
|
uint8 compressed_type;
|
|
|
|
uint16 compressed_len;
|
2011-07-22 00:20:41 +04:00
|
|
|
|
2011-09-08 09:17:58 +04:00
|
|
|
rdp_read_share_data_header(s, &length, &type, &share_id, &compressed_type, &compressed_len);
|
2011-07-22 00:20:41 +04:00
|
|
|
|
2011-09-02 21:29:17 +04:00
|
|
|
#ifdef WITH_DEBUG_RDP
|
2011-07-27 02:32:14 +04:00
|
|
|
if (type != DATA_PDU_TYPE_UPDATE)
|
|
|
|
printf("recv %s Data PDU (0x%02X), length:%d\n", DATA_PDU_TYPE_STRINGS[type], type, length);
|
2011-09-02 21:29:17 +04:00
|
|
|
#endif
|
2011-07-22 00:20:41 +04:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2011-07-23 00:19:08 +04:00
|
|
|
case DATA_PDU_TYPE_UPDATE:
|
2011-07-28 08:38:25 +04:00
|
|
|
update_recv(rdp->update, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_CONTROL:
|
2011-08-23 08:58:10 +04:00
|
|
|
rdp_recv_server_control_pdu(rdp, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_POINTER:
|
2011-08-24 10:38:39 +04:00
|
|
|
update_recv_pointer(rdp->update, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_INPUT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SYNCHRONIZE:
|
2012-01-09 01:02:59 +04:00
|
|
|
rdp_recv_synchronize_pdu(rdp, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_REFRESH_RECT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_PLAY_SOUND:
|
2011-08-24 10:54:46 +04:00
|
|
|
update_recv_play_sound(rdp->update, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SUPPRESS_OUTPUT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SHUTDOWN_REQUEST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SHUTDOWN_DENIED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SAVE_SESSION_INFO:
|
2011-08-23 08:58:10 +04:00
|
|
|
rdp_recv_save_session_info(rdp, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_FONT_LIST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_FONT_MAP:
|
2012-01-09 01:02:59 +04:00
|
|
|
rdp_recv_font_map_pdu(rdp, s);
|
2011-07-23 00:19:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_BITMAP_CACHE_ERROR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_OFFSCREEN_CACHE_ERROR:
|
|
|
|
break;
|
|
|
|
|
2011-07-22 00:20:41 +04:00
|
|
|
case DATA_PDU_TYPE_SET_ERROR_INFO:
|
2011-10-24 22:37:21 +04:00
|
|
|
rdp_recv_set_error_info_data_pdu(rdp, s);
|
2011-07-22 00:20:41 +04:00
|
|
|
break;
|
|
|
|
|
2011-07-23 00:19:08 +04:00
|
|
|
case DATA_PDU_TYPE_DRAW_NINEGRID_ERROR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_DRAW_GDIPLUS_ERROR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_ARC_STATUS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_STATUS_INFO:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_PDU_TYPE_MONITOR_LAYOUT:
|
|
|
|
break;
|
|
|
|
|
2011-07-22 00:20:41 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-03 05:34:51 +04:00
|
|
|
boolean rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
uint16 type;
|
|
|
|
uint16 length;
|
|
|
|
uint16 channelId;
|
|
|
|
|
|
|
|
rdp_read_share_control_header(s, &length, &type, &channelId);
|
|
|
|
|
|
|
|
if (type == PDU_TYPE_DATA)
|
|
|
|
{
|
|
|
|
rdp_recv_data_pdu(rdp, s);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-09-03 05:34:51 +04:00
|
|
|
}
|
|
|
|
else if (type == PDU_TYPE_SERVER_REDIRECTION)
|
|
|
|
{
|
|
|
|
rdp_recv_enhanced_security_redirection_packet(rdp, s);
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-09-03 05:34:51 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-09-03 05:34:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 22:02:52 +04:00
|
|
|
/**
|
|
|
|
* Decrypt an RDP packet.\n
|
|
|
|
* @param rdp RDP module
|
|
|
|
* @param s stream
|
|
|
|
* @param length int
|
|
|
|
*/
|
|
|
|
|
2011-09-15 01:14:50 +04:00
|
|
|
boolean rdp_decrypt(rdpRdp* rdp, STREAM* s, int length)
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
2012-01-16 00:01:16 +04:00
|
|
|
uint8 cmac[8], wmac[8];
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2011-09-16 03:54:03 +04:00
|
|
|
if (rdp->settings->encryption_method == ENCRYPTION_METHOD_FIPS)
|
|
|
|
{
|
|
|
|
uint16 len;
|
|
|
|
uint8 version, pad;
|
|
|
|
uint8 *sig;
|
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
stream_read_uint16(s, len); /* 0x10 */
|
|
|
|
stream_read_uint8(s, version); /* 0x1 */
|
2011-09-16 03:54:03 +04:00
|
|
|
stream_read_uint8(s, pad);
|
|
|
|
|
|
|
|
sig = s->p;
|
|
|
|
stream_seek(s, 8); /* signature */
|
|
|
|
|
2012-01-16 00:01:16 +04:00
|
|
|
length -= 12;
|
2011-09-16 03:54:03 +04:00
|
|
|
|
2012-01-16 00:01:16 +04:00
|
|
|
if (!security_fips_decrypt(s->p, length, rdp))
|
2011-09-16 03:54:03 +04:00
|
|
|
{
|
|
|
|
printf("FATAL: cannot decrypt\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false; /* TODO */
|
2011-09-16 03:54:03 +04:00
|
|
|
}
|
|
|
|
|
2012-01-16 00:01:16 +04:00
|
|
|
if (!security_fips_check_signature(s->p, length - pad, sig, rdp))
|
2011-09-16 03:54:03 +04:00
|
|
|
{
|
|
|
|
printf("FATAL: invalid packet signature\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false; /* TODO */
|
2011-09-16 03:54:03 +04:00
|
|
|
}
|
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
/* is this what needs adjusting? */
|
2011-09-16 03:54:03 +04:00
|
|
|
s->size -= pad;
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-09-16 03:54:03 +04:00
|
|
|
}
|
|
|
|
|
2012-01-16 00:01:16 +04:00
|
|
|
stream_read(s, wmac, sizeof(wmac));
|
|
|
|
length -= sizeof(wmac);
|
|
|
|
security_decrypt(s->p, length, rdp);
|
2012-01-19 08:07:30 +04:00
|
|
|
security_mac_signature(rdp, s->p, length, cmac);
|
2012-01-16 00:01:16 +04:00
|
|
|
if (memcmp(wmac, cmac, sizeof(wmac)) != 0) {
|
|
|
|
printf("FATAL: invalid packet signature\n");
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 04:46:03 +04:00
|
|
|
/**
|
2011-08-01 08:43:53 +04:00
|
|
|
* Process an RDP packet.\n
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param rdp RDP module
|
2011-08-01 08:43:53 +04:00
|
|
|
* @param s stream
|
2011-07-12 04:46:03 +04:00
|
|
|
*/
|
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
static boolean rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2011-08-20 12:43:29 +04:00
|
|
|
uint16 length;
|
2011-07-20 00:30:05 +04:00
|
|
|
uint16 pduType;
|
|
|
|
uint16 pduLength;
|
2011-11-19 11:33:49 +04:00
|
|
|
uint16 pduSource;
|
2011-07-12 02:46:36 +04:00
|
|
|
uint16 channelId;
|
2011-09-05 22:02:52 +04:00
|
|
|
uint32 securityHeader;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2011-08-20 12:43:29 +04:00
|
|
|
if (!rdp_read_header(rdp, s, &length, &channelId))
|
|
|
|
{
|
|
|
|
printf("Incorrect RDP header.\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-20 00:30:05 +04:00
|
|
|
}
|
2011-08-08 07:59:28 +04:00
|
|
|
|
2011-09-05 22:02:52 +04:00
|
|
|
if (rdp->settings->encryption)
|
|
|
|
{
|
|
|
|
stream_read_uint32(s, securityHeader);
|
|
|
|
if (securityHeader & SEC_SECURE_CHECKSUM)
|
|
|
|
{
|
|
|
|
printf("Error: TODO\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
2011-12-21 23:59:31 +04:00
|
|
|
if (securityHeader & (SEC_ENCRYPT|SEC_REDIRECTION_PKT))
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
2011-09-15 01:14:50 +04:00
|
|
|
if (!rdp_decrypt(rdp, s, length - 4))
|
2011-09-05 22:02:52 +04:00
|
|
|
{
|
|
|
|
printf("rdp_decrypt failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-21 23:59:31 +04:00
|
|
|
if (securityHeader & SEC_REDIRECTION_PKT)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* [MS-RDPBCGR] 2.2.13.2.1
|
|
|
|
* - no share control header, nor the 2 byte pad
|
|
|
|
*/
|
|
|
|
s->p -= 2;
|
|
|
|
rdp_recv_enhanced_security_redirection_packet(rdp, s);
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-05 22:02:52 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 07:59:28 +04:00
|
|
|
if (channelId != MCS_GLOBAL_CHANNEL_ID)
|
2011-08-02 22:03:02 +04:00
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
freerdp_channel_process(rdp->instance, s, channelId);
|
2011-08-02 22:03:02 +04:00
|
|
|
}
|
2011-07-20 00:30:05 +04:00
|
|
|
else
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2011-11-19 11:33:49 +04:00
|
|
|
rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);
|
|
|
|
|
|
|
|
rdp->settings->pdu_source = pduSource;
|
2011-07-20 00:30:05 +04:00
|
|
|
|
|
|
|
switch (pduType)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2011-07-22 00:20:41 +04:00
|
|
|
case PDU_TYPE_DATA:
|
2011-08-23 08:58:10 +04:00
|
|
|
rdp_recv_data_pdu(rdp, s);
|
2011-07-22 00:20:41 +04:00
|
|
|
break;
|
|
|
|
|
2011-07-20 00:30:05 +04:00
|
|
|
case PDU_TYPE_DEACTIVATE_ALL:
|
2011-08-23 08:58:10 +04:00
|
|
|
if (!rdp_recv_deactivate_all(rdp, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-07-12 02:46:36 +04:00
|
|
|
break;
|
|
|
|
|
2011-07-20 00:30:05 +04:00
|
|
|
case PDU_TYPE_SERVER_REDIRECTION:
|
2011-08-23 08:58:10 +04:00
|
|
|
rdp_recv_enhanced_security_redirection_packet(rdp, s);
|
2011-07-12 02:46:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-07-20 00:30:05 +04:00
|
|
|
printf("incorrect PDU type: 0x%04X\n", pduType);
|
2011-07-12 02:46:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-22 11:03:58 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-07-12 02:46:36 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
static boolean rdp_recv_fastpath_pdu(rdpRdp* rdp, STREAM* s)
|
2011-08-09 12:40:58 +04:00
|
|
|
{
|
2011-08-09 19:28:02 +04:00
|
|
|
uint16 length;
|
2011-09-27 09:30:58 +04:00
|
|
|
rdpFastPath* fastpath;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
fastpath = rdp->fastpath;
|
|
|
|
length = fastpath_read_header_rdp(fastpath, s);
|
2011-09-15 01:14:50 +04:00
|
|
|
|
|
|
|
if (length == 0 || length > stream_get_left(s))
|
2011-08-13 12:37:03 +04:00
|
|
|
{
|
|
|
|
printf("incorrect FastPath PDU header length %d\n", length);
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-13 12:37:03 +04:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-09-27 09:30:58 +04:00
|
|
|
if (fastpath->encryptionFlags & FASTPATH_OUTPUT_ENCRYPTED)
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
|
|
|
rdp_decrypt(rdp, s, length);
|
|
|
|
}
|
2011-08-09 12:40:58 +04:00
|
|
|
|
2011-08-23 09:05:58 +04:00
|
|
|
return fastpath_recv_updates(rdp->fastpath, s);
|
2011-08-09 12:40:58 +04:00
|
|
|
}
|
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
static boolean rdp_recv_pdu(rdpRdp* rdp, STREAM* s)
|
2011-08-09 12:40:58 +04:00
|
|
|
{
|
|
|
|
if (tpkt_verify_header(s))
|
2011-08-23 08:58:10 +04:00
|
|
|
return rdp_recv_tpkt_pdu(rdp, s);
|
2011-08-09 12:40:58 +04:00
|
|
|
else
|
2011-08-23 08:58:10 +04:00
|
|
|
return rdp_recv_fastpath_pdu(rdp, s);
|
2011-08-09 12:40:58 +04:00
|
|
|
}
|
|
|
|
|
2011-08-01 08:43:53 +04:00
|
|
|
/**
|
|
|
|
* Receive an RDP packet.\n
|
|
|
|
* @param rdp RDP module
|
|
|
|
*/
|
|
|
|
|
|
|
|
void rdp_recv(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
|
|
|
|
s = transport_recv_stream_init(rdp->transport, 4096);
|
|
|
|
transport_read(rdp->transport, s);
|
|
|
|
|
2011-08-23 08:58:10 +04:00
|
|
|
rdp_recv_pdu(rdp, s);
|
2011-08-01 08:43:53 +04:00
|
|
|
}
|
|
|
|
|
2011-09-25 22:54:07 +04:00
|
|
|
static boolean rdp_recv_callback(rdpTransport* transport, STREAM* s, void* extra)
|
2011-08-01 08:43:53 +04:00
|
|
|
{
|
|
|
|
rdpRdp* rdp = (rdpRdp*) extra;
|
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
switch (rdp->state)
|
|
|
|
{
|
|
|
|
case CONNECTION_STATE_NEGO:
|
|
|
|
if (!rdp_client_connect_mcs_connect_response(rdp, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_MCS_ATTACH_USER:
|
|
|
|
if (!rdp_client_connect_mcs_attach_user_confirm(rdp, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_MCS_CHANNEL_JOIN:
|
|
|
|
if (!rdp_client_connect_mcs_channel_join_confirm(rdp, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_LICENSE:
|
|
|
|
if (!rdp_client_connect_license(rdp, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONNECTION_STATE_CAPABILITY:
|
|
|
|
if (!rdp_client_connect_demand_active(rdp, s))
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
|
|
|
printf("rdp_client_connect_demand_active failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-09-15 01:14:50 +04:00
|
|
|
}
|
2011-08-22 11:03:58 +04:00
|
|
|
break;
|
|
|
|
|
2011-12-19 00:15:48 +04:00
|
|
|
case CONNECTION_STATE_FINALIZATION:
|
|
|
|
if (!rdp_recv_pdu(rdp, s))
|
|
|
|
return false;
|
|
|
|
if (rdp->finalize_sc_pdus == FINALIZE_SC_COMPLETE)
|
|
|
|
rdp->state = CONNECTION_STATE_ACTIVE;
|
|
|
|
break;
|
|
|
|
|
2011-08-22 11:03:58 +04:00
|
|
|
case CONNECTION_STATE_ACTIVE:
|
2011-08-23 08:58:10 +04:00
|
|
|
if (!rdp_recv_pdu(rdp, s))
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Invalid state %d\n", rdp->state);
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-22 11:03:58 +04:00
|
|
|
}
|
2011-08-01 08:43:53 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-01 08:43:53 +04:00
|
|
|
}
|
|
|
|
|
2011-08-03 07:00:56 +04:00
|
|
|
int rdp_send_channel_data(rdpRdp* rdp, int channel_id, uint8* data, int size)
|
|
|
|
{
|
2011-12-10 11:51:42 +04:00
|
|
|
return freerdp_channel_send(rdp, channel_id, data, size);
|
2011-08-03 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
2011-08-01 08:43:53 +04:00
|
|
|
/**
|
|
|
|
* Set non-blocking mode information.
|
|
|
|
* @param rdp RDP module
|
|
|
|
* @param blocking blocking mode
|
|
|
|
*/
|
|
|
|
void rdp_set_blocking_mode(rdpRdp* rdp, boolean blocking)
|
|
|
|
{
|
|
|
|
rdp->transport->recv_callback = rdp_recv_callback;
|
|
|
|
rdp->transport->recv_extra = rdp;
|
|
|
|
transport_set_blocking_mode(rdp->transport, blocking);
|
|
|
|
}
|
|
|
|
|
|
|
|
int rdp_check_fds(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
return transport_check_fds(rdp->transport);
|
|
|
|
}
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
/**
|
|
|
|
* Instantiate new RDP module.
|
|
|
|
* @return new RDP module
|
|
|
|
*/
|
|
|
|
|
2011-08-02 22:03:02 +04:00
|
|
|
rdpRdp* rdp_new(freerdp* instance)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
|
|
|
rdpRdp* rdp;
|
|
|
|
|
|
|
|
rdp = (rdpRdp*) xzalloc(sizeof(rdpRdp));
|
|
|
|
|
|
|
|
if (rdp != NULL)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdp->instance = instance;
|
2011-09-29 09:03:07 +04:00
|
|
|
rdp->settings = settings_new((void*) instance);
|
2011-11-17 06:41:42 +04:00
|
|
|
if (instance != NULL)
|
|
|
|
instance->settings = rdp->settings;
|
2011-11-10 00:59:03 +04:00
|
|
|
rdp->extension = extension_new(instance);
|
2011-07-12 02:46:36 +04:00
|
|
|
rdp->transport = transport_new(rdp->settings);
|
2011-07-12 09:16:59 +04:00
|
|
|
rdp->license = license_new(rdp);
|
2011-07-28 08:38:25 +04:00
|
|
|
rdp->input = input_new(rdp);
|
|
|
|
rdp->update = update_new(rdp);
|
2011-08-09 19:28:02 +04:00
|
|
|
rdp->fastpath = fastpath_new(rdp);
|
2011-07-12 02:46:36 +04:00
|
|
|
rdp->nego = nego_new(rdp->transport);
|
|
|
|
rdp->mcs = mcs_new(rdp->transport);
|
2011-09-04 00:36:27 +04:00
|
|
|
rdp->redirection = redirection_new();
|
2011-09-08 09:17:58 +04:00
|
|
|
rdp->mppc = mppc_new(rdp);
|
2011-07-12 02:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rdp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free RDP module.
|
2011-07-12 04:46:03 +04:00
|
|
|
* @param rdp RDP module to be freed
|
2011-07-12 02:46:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void rdp_free(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
if (rdp != NULL)
|
|
|
|
{
|
2011-11-10 00:59:03 +04:00
|
|
|
extension_free(rdp->extension);
|
2011-07-12 02:46:36 +04:00
|
|
|
settings_free(rdp->settings);
|
2011-07-12 04:46:03 +04:00
|
|
|
transport_free(rdp->transport);
|
|
|
|
license_free(rdp->license);
|
2011-07-28 08:38:25 +04:00
|
|
|
input_free(rdp->input);
|
2011-07-27 02:32:14 +04:00
|
|
|
update_free(rdp->update);
|
2011-08-09 19:28:02 +04:00
|
|
|
fastpath_free(rdp->fastpath);
|
2011-08-25 09:45:43 +04:00
|
|
|
nego_free(rdp->nego);
|
2011-07-12 04:46:03 +04:00
|
|
|
mcs_free(rdp->mcs);
|
2011-09-04 00:36:27 +04:00
|
|
|
redirection_free(rdp->redirection);
|
2011-09-08 09:17:58 +04:00
|
|
|
mppc_free(rdp);
|
2011-09-10 15:41:59 +04:00
|
|
|
xfree(rdp);
|
2011-07-12 02:46:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|