FreeRDP
|
#include <freerdp/config.h>
#include "../settings.h"
#include <winpr/assert.h>
#include <winpr/crt.h>
#include <winpr/error.h>
#include <winpr/print.h>
#include <winpr/stream.h>
#include <freerdp/log.h>
#include "rpc_bind.h"
#include "rpc_client.h"
#include "tsg.h"
#include "../utils.h"
#include "../../crypto/opensslcompat.h"
Macros | |
#define | TAG FREERDP_TAG("core.gateway.tsg") |
#define | TSG_CAPABILITY_TYPE_NAP 0x00000001 |
#define | TSG_PACKET_TYPE_HEADER 0x00004844 |
#define | TSG_PACKET_TYPE_VERSIONCAPS 0x00005643 |
#define | TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143 |
#define | TSG_PACKET_TYPE_QUARREQUEST 0x00005152 |
#define | TSG_PACKET_TYPE_RESPONSE 0x00005052 |
#define | TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552 |
#define | TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350 |
#define | TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752 |
#define | TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750 |
#define | TSG_PACKET_TYPE_AUTH 0x00004054 |
#define | TSG_PACKET_TYPE_REAUTH 0x00005250 |
#define | ENTRY(x) |
Typedefs | |
typedef WCHAR * | RESOURCENAME |
Functions | |
static BOOL | tsg_stream_align (wLog *log, wStream *s, size_t align) |
static const char * | tsg_packet_id_to_string (UINT32 packetId) |
static const char * | tsg_component_id_to_string (UINT16 ComponentId, char *buffer, size_t bytelen) |
static const char * | tsg_state_to_string (TSG_STATE state) |
static BOOL | TsProxyReadTunnelContext (wLog *log, wStream *s, CONTEXT_HANDLE *tunnelContext) |
static BOOL | TsProxyWriteTunnelContext (wLog *log, wStream *s, const CONTEXT_HANDLE *tunnelContext) |
static BOOL | tsg_ndr_pointer_write (wLog *log, wStream *s, UINT32 *index, DWORD length) |
static BOOL | tsg_ndr_pointer_read (wLog *log, wStream *s, UINT32 *index, UINT32 *ptrval, BOOL required) |
static BOOL | tsg_ndr_write_string (wLog *log, wStream *s, const WCHAR *str, UINT32 length) |
static BOOL | tsg_ndr_read_string (wLog *log, wStream *s, WCHAR **str, UINT32 lengthInBytes) |
static BOOL | tsg_ndr_read_packet_header (wLog *log, wStream *s, TSG_PACKET_HEADER *header) |
static BOOL | tsg_ndr_write_packet_header (wLog *log, wStream *s, const TSG_PACKET_HEADER *header) |
static BOOL | tsg_ndr_read_nap (wLog *log, wStream *s, TSG_CAPABILITY_NAP *nap) |
static BOOL | tsg_ndr_write_nap (wLog *log, wStream *s, const TSG_CAPABILITY_NAP *nap) |
static BOOL | tsg_ndr_read_tsg_caps (wLog *log, wStream *s, TSG_PACKET_CAPABILITIES *caps) |
static BOOL | tsg_ndr_write_tsg_caps (wLog *log, wStream *s, const TSG_PACKET_CAPABILITIES *caps) |
static BOOL | tsg_ndr_read_version_caps (wLog *log, wStream *s, UINT32 *index, TSG_PACKET_VERSIONCAPS *caps) |
static BOOL | tsg_ndr_write_version_caps (wLog *log, wStream *s, UINT32 *index, const TSG_PACKET_VERSIONCAPS *caps) |
static BOOL | tsg_ndr_read_quarenc_response (wLog *log, wStream *s, UINT32 *index, TSG_PACKET_QUARENC_RESPONSE *quarenc) |
static BOOL | tsg_ndr_read_quarenc_data (wLog *log, wStream *s, UINT32 *index, TSG_PACKET_QUARENC_RESPONSE *quarenc) |
static BOOL | tsg_ndr_write_auth (wLog *log, wStream *s, UINT32 *index, const TSG_PACKET_AUTH *auth) |
static BOOL | tsg_ndr_write_reauth (wLog *log, wStream *s, UINT32 *index, const TSG_PACKET_REAUTH *auth) |
static BOOL | tsg_ndr_read_packet_response (wLog *log, wStream *s, UINT32 *index, TSG_PACKET_RESPONSE *response) |
static BOOL | tsg_print (char **buffer, size_t *len, WINPR_FORMAT_ARG const char *fmt,...) |
static BOOL | tsg_packet_header_to_string (char **buffer, size_t *length, const TSG_PACKET_HEADER *header) |
static BOOL | tsg_type_capability_nap_to_string (char **buffer, size_t *length, const TSG_CAPABILITY_NAP *cur) |
static BOOL | tsg_packet_capabilities_to_string (char **buffer, size_t *length, const TSG_PACKET_CAPABILITIES *caps, UINT32 numCaps) |
static BOOL | tsg_packet_versioncaps_to_string (char **buffer, size_t *length, const TSG_PACKET_VERSIONCAPS *caps) |
static BOOL | tsg_packet_quarconfigrequest_to_string (char **buffer, size_t *length, const TSG_PACKET_QUARCONFIGREQUEST *caps) |
static BOOL | tsg_packet_quarrequest_to_string (char **buffer, size_t *length, const TSG_PACKET_QUARREQUEST *caps) |
static const char * | tsg_bool_to_string (BOOL val) |
static const char * | tsg_redirection_flags_to_string (char *buffer, size_t size, const TSG_REDIRECTION_FLAGS *flags) |
static BOOL | tsg_packet_response_to_string (char **buffer, size_t *length, const TSG_PACKET_RESPONSE *caps) |
static BOOL | tsg_packet_quarenc_response_to_string (char **buffer, size_t *length, const TSG_PACKET_QUARENC_RESPONSE *caps) |
static BOOL | tsg_packet_message_response_to_string (char **buffer, size_t *length, const TSG_PACKET_MSG_RESPONSE *caps) |
static BOOL | tsg_packet_caps_response_to_string (char **buffer, size_t *length, const TSG_PACKET_CAPS_RESPONSE *caps) |
static BOOL | tsg_packet_message_request_to_string (char **buffer, size_t *length, const TSG_PACKET_MSG_REQUEST *caps) |
static BOOL | tsg_packet_auth_to_string (char **buffer, size_t *length, const TSG_PACKET_AUTH *caps) |
static BOOL | tsg_packet_reauth_to_string (char **buffer, size_t *length, const TSG_PACKET_REAUTH *caps) |
static const char * | tsg_packet_to_string (const TSG_PACKET *packet) |
static BIO_METHOD * | BIO_s_tsg (void) |
static int | TsProxySendToServer (handle_t IDL_handle, const byte pRpcMessage[], UINT32 count, const UINT32 *lengths) |
static BOOL | TsProxyCreateTunnelWriteRequest (rdpTsg *tsg, const TSG_PACKET *tsgPacket) |
static BOOL | tsg_ndr_read_consent_message (wLog *log, rdpContext *context, wStream *s, UINT32 *index) |
static BOOL | tsg_ndr_read_tunnel_context (wLog *log, wStream *s, CONTEXT_HANDLE *tunnelContext, UINT32 *tunnelId) |
static BOOL | tsg_ndr_read_caps_response (wLog *log, rdpContext *context, wStream *s, UINT32 *index, UINT32 PacketPtr, TSG_PACKET_CAPS_RESPONSE *caps, CONTEXT_HANDLE *tunnelContext, UINT32 *tunnelId) |
static BOOL | TsProxyCreateTunnelReadResponse (rdpTsg *tsg, const RPC_PDU *pdu, CONTEXT_HANDLE *tunnelContext, UINT32 *tunnelId) |
static BOOL | TsProxyAuthorizeTunnelWriteRequest (rdpTsg *tsg, CONTEXT_HANDLE *tunnelContext) |
static UINT32 | tsg_redir_to_flags (const TSG_REDIRECTION_FLAGS *redirect) |
static BOOL | tsg_redirect_apply (rdpTsg *tsg, const TSG_REDIRECTION_FLAGS *redirect) |
static BOOL | TsProxyAuthorizeTunnelReadResponse (rdpTsg *tsg, const RPC_PDU *pdu) |
static BOOL | TsProxyMakeTunnelCallWriteRequest (rdpTsg *tsg, CONTEXT_HANDLE *tunnelContext, UINT32 procId) |
static BOOL | TsProxyReadPacketSTringMessage (rdpTsg *tsg, wStream *s, TSG_PACKET_STRING_MESSAGE *msg) |
static BOOL | TsProxyMakeTunnelCallReadResponse (rdpTsg *tsg, const RPC_PDU *pdu) |
static BOOL | TsProxyCreateChannelWriteRequest (rdpTsg *tsg, CONTEXT_HANDLE *tunnelContext) |
static BOOL | TsProxyCreateChannelReadResponse (wLog *log, const RPC_PDU *pdu, CONTEXT_HANDLE *channelContext, UINT32 *channelId) |
static BOOL | TsProxyCloseChannelWriteRequest (rdpTsg *tsg, CONTEXT_HANDLE *context) |
static BOOL | TsProxyCloseChannelReadResponse (wLog *log, const RPC_PDU *pdu, CONTEXT_HANDLE *context) |
static BOOL | TsProxyCloseTunnelWriteRequest (rdpTsg *tsg, const CONTEXT_HANDLE *context) |
static BOOL | TsProxyCloseTunnelReadResponse (wLog *log, const RPC_PDU *pdu, CONTEXT_HANDLE *context) |
static BOOL | TsProxySetupReceivePipeWriteRequest (rdpTsg *tsg, const CONTEXT_HANDLE *channelContext) |
static BOOL | tsg_transition_to_state (rdpTsg *tsg, TSG_STATE state) |
static BOOL | tsg_initialize_version_caps (TSG_PACKET_VERSIONCAPS *packetVersionCaps) |
BOOL | tsg_proxy_begin (rdpTsg *tsg) |
static BOOL | tsg_proxy_reauth (rdpTsg *tsg) |
BOOL | tsg_recv_pdu (rdpTsg *tsg, const RPC_PDU *pdu) |
BOOL | tsg_check_event_handles (rdpTsg *tsg) |
DWORD | tsg_get_event_handles (rdpTsg *tsg, HANDLE *events, DWORD count) |
static BOOL | tsg_set_hostname (rdpTsg *tsg, const char *hostname) |
static BOOL | tsg_set_machine_name (rdpTsg *tsg, const char *machineName) |
BOOL | tsg_connect (rdpTsg *tsg, const char *hostname, UINT16 port, DWORD timeout) |
BOOL | tsg_disconnect (rdpTsg *tsg) |
static int | tsg_read (rdpTsg *tsg, BYTE *data, size_t length) |
Read data from TSG. More... | |
static int | tsg_write (rdpTsg *tsg, const BYTE *data, UINT32 length) |
rdpTsg * | tsg_new (rdpTransport *transport) |
void | tsg_free (rdpTsg *tsg) |
static int | transport_bio_tsg_write (BIO *bio, const char *buf, int num) |
static int | transport_bio_tsg_read (BIO *bio, char *buf, int size) |
static int | transport_bio_tsg_puts (BIO *bio, const char *str) |
static int | transport_bio_tsg_gets (BIO *bio, char *str, int size) |
static long | transport_bio_tsg_ctrl (BIO *bio, int cmd, long arg1, void *arg2) |
static int | transport_bio_tsg_new (BIO *bio) |
static int | transport_bio_tsg_free (BIO *bio) |
TSG_STATE | tsg_get_state (rdpTsg *tsg) |
BIO * | tsg_get_bio (rdpTsg *tsg) |
BOOL | tsg_set_state (rdpTsg *tsg, TSG_STATE state) |
#define ENTRY | ( | x | ) |
#define TAG FREERDP_TAG("core.gateway.tsg") |
FreeRDP: A Remote Desktop Protocol Implementation Terminal Server Gateway (TSG)
Copyright 2012 Fujitsu Technology Solutions GmbH Copyright 2012 Dmitrij Jasnov dmitr Copyright 2015 Thincast Technologies GmbH Copyright 2015 DI (FH) Martin Haimberger ij.j asnov @ts. fujit su.c ommarti n.ha imber ger@ thinc ast. 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.
#define TSG_CAPABILITY_TYPE_NAP 0x00000001 |
#define TSG_PACKET_TYPE_AUTH 0x00004054 |
#define TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350 |
#define TSG_PACKET_TYPE_HEADER 0x00004844 |
#define TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750 |
#define TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752 |
#define TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143 |
#define TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552 |
#define TSG_PACKET_TYPE_QUARREQUEST 0x00005152 |
#define TSG_PACKET_TYPE_REAUTH 0x00005250 |
#define TSG_PACKET_TYPE_RESPONSE 0x00005052 |
#define TSG_PACKET_TYPE_VERSIONCAPS 0x00005643 |
typedef WCHAR* RESOURCENAME |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
BOOL tsg_check_event_handles | ( | rdpTsg * | tsg | ) |
|
static |
BOOL tsg_connect | ( | rdpTsg * | tsg, |
const char * | hostname, | ||
UINT16 | port, | ||
DWORD | timeout | ||
) |
BOOL tsg_disconnect | ( | rdpTsg * | tsg | ) |
Gateway Shutdown Phase
Client Server | |
----------—TsProxyCloseChannel Request-------—> |
---|
<----—TsProxySetupReceivePipe Final Response--— |
<--------—TsProxyCloseChannel Response--------— |
-—TsProxyMakeTunnelCall Request (cancel async)--> |
<—TsProxyMakeTunnelCall Response (call async)-— |
<—TsProxyMakeTunnelCall Response (cancel async)– |
-----------—TsProxyCloseTunnel Request-------—> |
<----------—TsProxyCloseTunnel Response-------— |
void tsg_free | ( | rdpTsg * | tsg | ) |
BIO* tsg_get_bio | ( | rdpTsg * | tsg | ) |
DWORD tsg_get_event_handles | ( | rdpTsg * | tsg, |
HANDLE * | events, | ||
DWORD | count | ||
) |
TSG_STATE tsg_get_state | ( | rdpTsg * | tsg | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
rdpTsg* tsg_new | ( | rdpTransport * | transport | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
BOOL tsg_proxy_begin | ( | rdpTsg * | tsg | ) |
|
static |
|
static |
Read data from TSG.
[in] | tsg | The TSG instance to read from |
[in] | data | A pointer to the data buffer |
[in] | length | length of data |
BOOL tsg_recv_pdu | ( | rdpTsg * | tsg, |
const RPC_PDU * | pdu | ||
) |
|
static |
|
static |
|
static |
|
static |
|
static |
BOOL tsg_set_state | ( | rdpTsg * | tsg, |
TSG_STATE | state | ||
) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
OpNum = 2
HRESULT TsProxyAuthorizeTunnel( [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext, [in, ref] TSG_PACKET* tsgPacket, [out, ref] TSG_PACKET** tsgPacketResponse );
|
static |
|
static |
HRESULT TsProxyCloseChannel( [in, out] PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* context );
|
static |
|
static |
HRESULT TsProxyCloseTunnel( [in, out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context );
|
static |
|
static |
OpNum = 4
HRESULT TsProxyCreateChannel( [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext, [in, ref] PTSENDPOINTINFO tsEndPointInfo, [out] PCHANNEL_CONTEXT_HANDLE_SERIALIZE* channelContext, [out] unsigned long* channelId );
|
static |
|
static |
OpNum = 1
HRESULT TsProxyCreateTunnel( [in, ref] TSG_PACKET* tsgPacket, [out, ref] TSG_PACKET** tsgPacketResponse, [out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* tunnelContext, [out] unsigned long* tunnelId );
The following 60-byte structure is apparently undocumented, but parts of it can be matched to known C706 data structures.
|
static |
|
static |
OpNum = 3
HRESULT TsProxyMakeTunnelCall( [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext, [in] unsigned long procId, [in, ref] TSG_PACKET* tsgPacket, [out, ref] TSG_PACKET** tsgPacketResponse );
|
static |
|
static |
|
static |
RPC Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378623/ Remote Procedure Call: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378651/ RPC NDR Interface Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/hh802752/ call sequence with silent reauth:
TsProxyCreateTunnelRequest() TsProxyCreateTunnelResponse(TunnelContext) TsProxyAuthorizeTunnelRequest(TunnelContext) TsProxyAuthorizeTunnelResponse() TsProxyMakeTunnelCallRequest(TunnelContext) TsProxyCreateChannelRequest(TunnelContext) TsProxyCreateChannelResponse(ChannelContext) TsProxySetupReceivePipeRequest(ChannelContext) TsProxySendToServerRequest(ChannelContext)
...
TsProxyMakeTunnelCallResponse(reauth) TsProxyCreateTunnelRequest() TsProxyMakeTunnelCallRequest(TunnelContext) TsProxyCreateTunnelResponse(NewTunnelContext) TsProxyAuthorizeTunnelRequest(NewTunnelContext) TsProxyAuthorizeTunnelResponse() TsProxyCreateChannelRequest(NewTunnelContext) TsProxyCreateChannelResponse(NewChannelContext) TsProxyCloseChannelRequest(NewChannelContext) TsProxyCloseTunnelRequest(NewTunnelContext) TsProxyCloseChannelResponse(NullChannelContext) TsProxyCloseTunnelResponse(NullTunnelContext) TsProxySendToServerRequest(ChannelContext)