diff options
author | jsorg71 <jay.sorg@gmail.com> | 2014-03-04 14:11:02 -0800 |
---|---|---|
committer | jsorg71 <jay.sorg@gmail.com> | 2014-03-04 14:11:02 -0800 |
commit | 1ce75182afdf8a0fc5a44691dbada0fdc138d867 (patch) | |
tree | 5c6a169ac9707311c4a10e98215901846566a93f /libxrdp | |
parent | 60dbacc9ffd3b2a9f1f523ecb6426042764233ee (diff) | |
parent | 866fde498efe893144b0b596999f18af90a743c3 (diff) | |
download | xrdp-proprietary-1ce75182afdf8a0fc5a44691dbada0fdc138d867.tar.gz xrdp-proprietary-1ce75182afdf8a0fc5a44691dbada0fdc138d867.zip |
Merge pull request #111 from speidy/fastpath
libxrdp: Fastpath input
Diffstat (limited to 'libxrdp')
-rw-r--r-- | libxrdp/Makefile.am | 3 | ||||
-rw-r--r-- | libxrdp/libxrdp.c | 13 | ||||
-rw-r--r-- | libxrdp/libxrdp.h | 24 | ||||
-rw-r--r-- | libxrdp/xrdp_fastpath.c | 253 | ||||
-rw-r--r-- | libxrdp/xrdp_mcs.c | 3 | ||||
-rw-r--r-- | libxrdp/xrdp_rdp.c | 46 | ||||
-rw-r--r-- | libxrdp/xrdp_sec.c | 37 |
7 files changed, 347 insertions, 32 deletions
diff --git a/libxrdp/Makefile.am b/libxrdp/Makefile.am index e83fce10..7fe5d1b2 100644 --- a/libxrdp/Makefile.am +++ b/libxrdp/Makefile.am @@ -59,7 +59,8 @@ libxrdp_la_SOURCES = \ xrdp_bitmap32_compress.c \ xrdp_jpeg_compress.c \ xrdp_orders_rail.c \ - xrdp_mppc_enc.c + xrdp_mppc_enc.c \ + xrdp_fastpath.c libxrdp_la_LDFLAGS = \ $(EXTRA_FLAGS) diff --git a/libxrdp/libxrdp.c b/libxrdp/libxrdp.c index 7ab1f914..9d584244 100644 --- a/libxrdp/libxrdp.c +++ b/libxrdp/libxrdp.c @@ -29,6 +29,7 @@ libxrdp_init(tbus id, struct trans *trans) session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1); session->id = id; + session->trans = trans; session->rdp = xrdp_rdp_create(session, trans); session->orders = xrdp_orders_create(session, (struct xrdp_rdp *)session->rdp); session->client_info = &(((struct xrdp_rdp *)session->rdp)->client_info); @@ -143,17 +144,23 @@ libxrdp_process_data(struct xrdp_session *session, struct stream *s) xrdp_rdp_process_confirm_active(rdp, s); break; case RDP_PDU_DATA: /* 7 */ - if (xrdp_rdp_process_data(rdp, s) != 0) { DEBUG(("libxrdp_process_data returned non zero")); cont = 0; term = 1; } - + break; + case 2: /* FASTPATH_INPUT_EVENT */ + if (xrdp_fastpath_process_input_event(rdp->sec_layer->fastpath_layer, s) != 0) + { + DEBUG(("libxrdp_process_data returned non zero")); + cont = 0; + term = 1; + } break; default: - g_writeln("unknown in libxrdp_process_data"); + g_writeln("unknown in libxrdp_process_data: code= %d", code); dead_lock_counter++; break; } diff --git a/libxrdp/libxrdp.h b/libxrdp/libxrdp.h index d9e5e6d1..4e7218d6 100644 --- a/libxrdp/libxrdp.h +++ b/libxrdp/libxrdp.h @@ -37,6 +37,7 @@ #include "file_loc.h" #include "xrdp_client_info.h" + /* iso */ struct xrdp_iso { @@ -66,6 +67,16 @@ struct xrdp_mcs struct list* channel_list; }; +/* fastpath */ +struct xrdp_fastpath +{ + struct xrdp_sec* sec_layer; /* owner */ + struct trans* trans; + struct xrdp_session* session; + int numEvents; + int secFlags; +}; + /* Encryption Methods */ #define CRYPT_METHOD_NONE 0x00000000 #define CRYPT_METHOD_40BIT 0x00000001 @@ -80,11 +91,13 @@ struct xrdp_mcs #define CRYPT_LEVEL_HIGH 0x00000003 #define CRYPT_LEVEL_FIPS 0x00000004 + /* sec */ struct xrdp_sec { struct xrdp_rdp* rdp_layer; /* owner */ struct xrdp_mcs* mcs_layer; + struct xrdp_fastpath* fastpath_layer; struct xrdp_channel* chan_layer; char server_random[32]; char client_random[64]; @@ -303,6 +316,8 @@ int APP_CC xrdp_iso_send(struct xrdp_iso* self, struct stream* s); int APP_CC xrdp_iso_incoming(struct xrdp_iso* self); +int APP_CC +xrdp_iso_detect_tpkt(struct xrdp_iso *self, struct stream *s); /* xrdp_mcs.c */ struct xrdp_mcs* APP_CC @@ -528,4 +543,13 @@ int APP_CC xrdp_channel_process(struct xrdp_channel* self, struct stream* s, int chanid); +/* xrdp_fastpath.c */ +struct xrdp_fastpath *APP_CC +xrdp_fastpath_create(struct xrdp_sec *owner, struct trans *trans); +void APP_CC +xrdp_fastpath_delete(struct xrdp_fastpath *self); +int APP_CC +xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s); +int APP_CC +xrdp_fastpath_process_input_event(struct xrdp_fastpath *self, struct stream *s); #endif diff --git a/libxrdp/xrdp_fastpath.c b/libxrdp/xrdp_fastpath.c index 10f844e5..572b5a98 100644 --- a/libxrdp/xrdp_fastpath.c +++ b/libxrdp/xrdp_fastpath.c @@ -2,7 +2,7 @@ * xrdp: A Remote Desktop Protocol server. * * Copyright (C) Jay Sorg 2012-2013 - * Copyright (C) Kevin Zhou 2012 + * Copyright (C) Idan Freiberg 2013-2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,16 @@ /*****************************************************************************/ struct xrdp_fastpath *APP_CC -xrdp_fastpath_create(struct xrdp_session *session) +xrdp_fastpath_create(struct xrdp_sec *owner, struct trans *trans) { struct xrdp_fastpath *self; + DEBUG((" in xrdp_fastpath_create")); self = (struct xrdp_fastpath *)g_malloc(sizeof(struct xrdp_fastpath), 1); - self->tcp_layer = - ((struct xrdp_rdp *)session->rdp)->sec_layer-> - mcs_layer->iso_layer->tcp_layer; - make_stream(self->out_s); - init_stream(self->out_s, FASTPATH_MAX_PACKET_SIZE); + self->sec_layer = owner; + self->trans = trans; + self->session = owner->rdp_layer->session; + DEBUG((" out xrdp_fastpath_create")); return self; } @@ -42,8 +42,6 @@ xrdp_fastpath_delete(struct xrdp_fastpath *self) { return; } - - free_stream(self->out_s); g_free(self); } @@ -54,7 +52,46 @@ xrdp_fastpath_reset(struct xrdp_fastpath *self) { return 0; } +/*****************************************************************************/ +int APP_CC +xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) +{ + int fp_hdr; + int len = 0; + int byte; + int hdr_len = 2; /* fastpath header length - can be 2 or 3 bytes long, depends on length */ + DEBUG((" in xrdp_fastpath_recv")); + + in_uint8(s, fp_hdr); /* fpInputHeader (1 byte) */ + g_writeln("xrdp_fastpath_recv: header= 0x%8.8x", fp_hdr); + + self->numEvents = (fp_hdr & 0x3C) >> 2; + self->secFlags = (fp_hdr & 0xC0) >> 6; + + // receive fastpath first length packet + in_uint8(s, byte); /* length 1 */ + + if (byte & 0x80) + { + byte &= ~(0x80); + len = (byte << 8); + // receive fastpath second length packet + in_uint8(s, byte); /* length 2 */ + hdr_len++; + len += byte; + } + else + { + len = byte; + } + +// g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); + DEBUG((" out xrdp_fastpath_recv")); + + return 0; +} +/*****************************************************************************/ int APP_CC xrdp_fastpath_init(struct xrdp_fastpath *self) { @@ -76,7 +113,7 @@ xrdp_fastpath_send_update_pdu(struct xrdp_fastpath *self, tui8 updateCode, int i32; compression = 0; - s_send = self->out_s; +// s_send = self->out_s; maxLen = FASTPATH_MAX_PACKET_SIZE - 6; /* 6 bytes for header */ payloadLeft = (s->end - s->data); @@ -112,13 +149,13 @@ xrdp_fastpath_send_update_pdu(struct xrdp_fastpath *self, tui8 updateCode, ((compression & 0x03) << 6); out_uint8(s_send, i32); out_uint16_le(s_send, len); - s_copy(s_send, s, len); +// s_copy(s_send, s, len); s_mark_end(s_send); - if (xrdp_tcp_send(self->tcp_layer, s_send) != 0) - { - return 1; - } +// if (xrdp_tcp_send(self->tcp_layer, s_send) != 0) +// { +// return 1; +// } } return 0; @@ -169,12 +206,12 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, encryptionFlags = (header & 0xc0) >> 6; numberEvents = (header & 0x3c) >> 2; - xrdp_tcp_recv(self->tcp_layer, s, 1); +// xrdp_tcp_recv(self->tcp_layer, s, 1); in_uint8(s, length); if (length & 0x80) { - xrdp_tcp_recv(self->tcp_layer, s, 1); +// xrdp_tcp_recv(self->tcp_layer, s, 1); in_uint8(s, length2); length = (length & 0x7f) << 8 + length2 - 3; } @@ -183,7 +220,7 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, length -= 2; } - xrdp_tcp_recv(self->tcp_layer, s, length); +// xrdp_tcp_recv(self->tcp_layer, s, length); if (encryptionFlags != 0) { @@ -207,3 +244,183 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, in_uint16_le(s, size); return xrdp_fastpath_process_update(self, updateCode, size, s); } + +/*****************************************************************************/ +/* FASTPATH_INPUT_EVENT_SCANCODE */ +int APP_CC +xrdp_fastpath_process_EVENT_SCANCODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +{ + int flags; + int code; + flags = 0; + + in_uint8(s, code); /* keyCode (1 byte) */ + //g_writeln("scan code detected: %d", code); + + if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) + flags |= KBD_FLAG_UP; + else + flags |= KBD_FLAG_DOWN; + + if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED)) + flags |= KBD_FLAG_EXT; + + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_SCANCODE, code, 0, + flags, 0); + } + return 0; +} +/*****************************************************************************/ +/* FASTPATH_INPUT_EVENT_MOUSE */ +int APP_CC +xrdp_fastpath_process_EVENT_MOUSE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +{ + int pointerFlags; + int xPos; + int yPos; + + in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ + in_uint16_le(s, xPos); /* xPos (2 bytes) */ + in_uint16_le(s, yPos); /* yPos (2 bytes) */ + + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_MOUSE, xPos, yPos, + pointerFlags, 0); + } + return 0; +} +/*****************************************************************************/ +/* FASTPATH_INPUT_EVENT_MOUSEX */ +int APP_CC +xrdp_fastpath_process_EVENT_MOUSEX(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +{ + int pointerFlags; + int xPos; + int yPos; + + in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ + in_uint16_le(s, xPos); /* xPos (2 bytes) */ + in_uint16_le(s, yPos); /* yPos (2 bytes) */ + + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_MOUSEX, xPos, yPos, + pointerFlags, 0); + } + return 0; +} +/*****************************************************************************/ +/* FASTPATH_INPUT_EVENT_SYNC */ +int APP_CC +xrdp_fastpath_process_EVENT_SYNC(struct xrdp_fastpath *self, int eventCode, int eventFlags, struct stream *s) +{ + /* + * The eventCode bitfield (3 bits in size) MUST be set to FASTPATH_INPUT_EVENT_SYNC (3). + * The eventFlags bitfield (5 bits in size) contains flags indicating the "on" + * status of the keyboard toggle keys. + */ + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_SYNCHRONIZE, eventCode, 0, + eventFlags, 0); + } + return 0; +} +/*****************************************************************************/ +/* FASTPATH_INPUT_EVENT_UNICODE */ +int APP_CC +xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) +{ + in_uint8s(s, 2); + return 0; +} +/*****************************************************************************/ +/* FASTPATH_INPUT_EVENT */ +int APP_CC +xrdp_fastpath_process_input_event(struct xrdp_fastpath *self, struct stream *s) +{ + int i; + int eventHeader; + int eventCode; + int eventFlags; + + // process fastpath input events + for (i = 0 ; i < self->numEvents ; i++) { + in_uint8(s, eventHeader); + + eventFlags = (eventHeader & 0x1F); + eventCode = (eventHeader >> 5); + +// g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", +// eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); + + switch (eventCode) + { + case FASTPATH_INPUT_EVENT_SCANCODE: + if (xrdp_fastpath_process_EVENT_SCANCODE(self, eventFlags, s) != 0) + { + return 1; + } + break; + + case FASTPATH_INPUT_EVENT_MOUSE: + if (xrdp_fastpath_process_EVENT_MOUSE(self, eventFlags, s) != 0) + { + return 1; + } + break; + case FASTPATH_INPUT_EVENT_MOUSEX: + if (xrdp_fastpath_process_EVENT_MOUSEX(self, eventFlags, s) != 0) + { + return 1; + } + break; + case FASTPATH_INPUT_EVENT_SYNC: + if (xrdp_fastpath_process_EVENT_SYNC(self, eventCode, eventFlags, s) != 0) + { + return 1; + } + break; + case FASTPATH_INPUT_EVENT_UNICODE: + if (xrdp_fastpath_process_EVENT_UNICODE(self, eventFlags, s) != 0) + { + return 1; + } + + break; + default: + g_writeln("xrdp_rdp_process_fastpath_data_input: unknown eventCode %d", eventCode); + break; + } + + } + + return 0; +} diff --git a/libxrdp/xrdp_mcs.c b/libxrdp/xrdp_mcs.c index 9dcb5b51..08055191 100644 --- a/libxrdp/xrdp_mcs.c +++ b/libxrdp/xrdp_mcs.c @@ -122,14 +122,13 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan) int len; int userid; int chanid; - DEBUG((" in xrdp_mcs_recv")); while (1) { if (xrdp_iso_recv(self->iso_layer, s) != 0) { - DEBUG((" out xrdp_mcs_recv xrdp_iso_recv returned non zero")); + DEBUG((" out xrdp_mcs_recv, xrdp_iso_recv return non zero")); return 1; } diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index ec882f4e..787b6e6c 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -123,6 +123,31 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) { client_info->require_credentials = g_text2bool(value); } + else if (g_strcasecmp(item, "use_fastpath") == 0) + { + if (g_strcasecmp(value, "output") == 0) + { + client_info->use_fast_path = 1; + } + else if (g_strcasecmp(value, "input") == 0) + { + client_info->use_fast_path = 2; + } + else if (g_strcasecmp(value, "both") == 0) + { + client_info->use_fast_path = 3; + } + else if (g_strcasecmp(value, "none") == 0) + { + client_info->use_fast_path = 0; + } + else + { + log_message(LOG_LEVEL_ALWAYS,"Warning: Your configured fastpath level is" + "undefined, fastpath will not be used"); + client_info->use_fast_path = 0; + } + } } list_delete(items); @@ -264,9 +289,8 @@ xrdp_rdp_init_data(struct xrdp_rdp *self, struct stream *s) s_push_layer(s, rdp_hdr, 18); return 0; } - /*****************************************************************************/ -/* returns erros */ +/* returns error */ int APP_CC xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) { @@ -274,11 +298,25 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) int len = 0; int pdu_code = 0; int chan = 0; + const tui8 *header; + header = (const tui8 *) (self->session->trans->in_s->p); DEBUG(("in xrdp_rdp_recv")); - if (s->next_packet == 0 || s->next_packet >= s->end) { + /* check for fastpath first */ + if ((header[0] != 0x3) && (header[0] != 0x3c)) + { + if (xrdp_sec_recv_fastpath(self->sec_layer, s) != 0) + { + return 1; + } + *code = 2; // special code for fastpath input + DEBUG(("out (fastpath) xrdp_rdp_recv")); + return 0; + } + + /* not fastpath, do tpkt */ chan = 0; error = xrdp_sec_recv(self->sec_layer, s, &chan); @@ -348,7 +386,6 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) return 0; } } - /*****************************************************************************/ int APP_CC xrdp_rdp_send(struct xrdp_rdp *self, struct stream *s, int pdu_type) @@ -1694,7 +1731,6 @@ xrdp_rdp_process_data(struct xrdp_rdp *self, struct stream *s) return 0; } - /*****************************************************************************/ int APP_CC xrdp_rdp_disconnect(struct xrdp_rdp *self) diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index a4fe8c5a..d0f84273 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -271,6 +271,7 @@ xrdp_sec_create(struct xrdp_rdp *owner, struct trans *trans, int crypt_level, self->encrypt_rc4_info = ssl_rc4_info_create(); self->mcs_layer = xrdp_mcs_create(self, trans, &self->client_mcs_data, &self->server_mcs_data); + self->fastpath_layer = xrdp_fastpath_create(self, trans); self->chan_layer = xrdp_channel_create(self, self->mcs_layer); DEBUG((" out xrdp_sec_create")); return self; @@ -288,6 +289,7 @@ xrdp_sec_delete(struct xrdp_sec *self) xrdp_channel_delete(self->chan_layer); xrdp_mcs_delete(self->mcs_layer); + xrdp_fastpath_delete(self->fastpath_layer); ssl_rc4_info_delete(self->decrypt_rc4_info); /* TODO clear all data */ ssl_rc4_info_delete(self->encrypt_rc4_info); /* TODO clear all data */ ssl_des3_info_delete(self->decrypt_fips_info); @@ -948,7 +950,37 @@ xrdp_sec_establish_keys(struct xrdp_sec *self) ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key, self->rc4_key_len); ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key, self->rc4_key_len); } - +/*****************************************************************************/ +/* returns error */ +int APP_CC +xrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s) +{ + if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0) { + return 1; + } + + if (self->crypt_level == CRYPT_LEVEL_FIPS) + { + in_uint8s(s, 4); /* fipsInformation (4 bytes) */ + } + + in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */ + + if (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED) + { + xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p)); + } + + if (self->fastpath_layer->numEvents == 0) { + /** + * If numberEvents is not provided in fpInputHeader, it will be provided + * as one additional byte here. + */ + in_uint8(s, self->fastpath_layer->numEvents); /* numEvents (1 byte) (optional) */ + } + + return 0; +} /*****************************************************************************/ /* returns error */ int APP_CC @@ -963,7 +995,7 @@ xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan) if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0) { - DEBUG((" out xrdp_sec_recv error")); + DEBUG((" out xrdp_sec_recv : error")); return 1; } @@ -1181,7 +1213,6 @@ xrdp_sec_send(struct xrdp_sec *self, struct stream *s, int chan) DEBUG((" out xrdp_sec_send")); return 0; } - /*****************************************************************************/ /* http://msdn.microsoft.com/en-us/library/cc240510.aspx 2.2.1.3.2 Client Core Data (TS_UD_CS_CORE) */ |