Merge branch 'gateway' of https://github.com/dvincent-devolutions/FreeRDP into gateway
This commit is contained in:
commit
bdf17450e5
@ -28,6 +28,8 @@ set(${MODULE_PREFIX}_GATEWAY_DIR "gateway")
|
||||
set(${MODULE_PREFIX}_GATEWAY_SRCS
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/tsg.c
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/tsg.h
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/rdg.c
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/rdg.h
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/rpc.c
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/rpc.h
|
||||
${${MODULE_PREFIX}_GATEWAY_DIR}/rpc_bind.c
|
||||
|
@ -174,6 +174,17 @@ BOOL http_context_set_pragma(HttpContext* context, const char* Pragma)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL http_context_set_rdg_connection_id(HttpContext* context, const char* RdgConnectionId)
|
||||
{
|
||||
free(context->RdgConnectionId);
|
||||
context->RdgConnectionId = _strdup(RdgConnectionId);
|
||||
|
||||
if (!context->RdgConnectionId)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void http_context_free(HttpContext* context)
|
||||
{
|
||||
if (context)
|
||||
@ -186,6 +197,7 @@ void http_context_free(HttpContext* context)
|
||||
free(context->CacheControl);
|
||||
free(context->Connection);
|
||||
free(context->Pragma);
|
||||
free(context->RdgConnectionId);
|
||||
free(context);
|
||||
}
|
||||
}
|
||||
@ -234,6 +246,17 @@ BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL http_request_set_transfer_encoding(HttpRequest* request, const char* TransferEncoding)
|
||||
{
|
||||
free(request->TransferEncoding);
|
||||
request->TransferEncoding = _strdup(TransferEncoding);
|
||||
|
||||
if (!request->TransferEncoding)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char* http_encode_body_line(char* param, char* value)
|
||||
{
|
||||
char* line;
|
||||
@ -325,6 +348,26 @@ wStream* http_request_write(HttpContext* context, HttpRequest* request)
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if (context->RdgConnectionId)
|
||||
{
|
||||
lines[count] = http_encode_body_line("RDG-Connection-Id", context->RdgConnectionId);
|
||||
|
||||
if (!lines[count])
|
||||
goto out_free;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
if (request->TransferEncoding)
|
||||
{
|
||||
lines[count] = http_encode_body_line("Transfer-Encoding", request->TransferEncoding);
|
||||
|
||||
if (!lines[count])
|
||||
goto out_free;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
if (request->Authorization)
|
||||
{
|
||||
lines[count] = http_encode_body_line("Authorization", request->Authorization);
|
||||
|
@ -40,6 +40,7 @@ struct _http_context
|
||||
char* CacheControl;
|
||||
char* Connection;
|
||||
char* Pragma;
|
||||
char* RdgConnectionId;
|
||||
};
|
||||
|
||||
BOOL http_context_set_method(HttpContext* context, const char* Method);
|
||||
@ -50,6 +51,7 @@ BOOL http_context_set_accept(HttpContext* context, const char* Accept);
|
||||
BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl);
|
||||
BOOL http_context_set_connection(HttpContext* context, const char* Connection);
|
||||
BOOL http_context_set_pragma(HttpContext* context, const char* Pragma);
|
||||
BOOL http_context_set_rdg_connection_id(HttpContext* context, const char* RdgConnectionId);
|
||||
|
||||
HttpContext* http_context_new(void);
|
||||
void http_context_free(HttpContext* context);
|
||||
@ -63,12 +65,14 @@ struct _http_request
|
||||
char* Authorization;
|
||||
int ContentLength;
|
||||
char* Content;
|
||||
char* TransferEncoding;
|
||||
};
|
||||
|
||||
BOOL http_request_set_method(HttpRequest* request, const char* Method);
|
||||
BOOL http_request_set_uri(HttpRequest* request, const char* URI);
|
||||
BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme);
|
||||
BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam);
|
||||
BOOL http_request_set_transfer_encoding(HttpRequest* request, const char* TransferEncoding);
|
||||
|
||||
wStream* http_request_write(HttpContext* context, HttpRequest* request);
|
||||
|
||||
|
1465
libfreerdp/core/gateway/rdg.c
Normal file
1465
libfreerdp/core/gateway/rdg.c
Normal file
File diff suppressed because it is too large
Load Diff
161
libfreerdp/core/gateway/rdg.h
Normal file
161
libfreerdp/core/gateway/rdg.h
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Remote Desktop Gateway (RDG)
|
||||
*
|
||||
* Copyright 2015 Denis Vincent <dvincent@devolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FREERDP_CORE_RDG_H
|
||||
#define FREERDP_CORE_RDG_H
|
||||
|
||||
|
||||
#include <winpr/wtypes.h>
|
||||
#include <winpr/stream.h>
|
||||
#include <winpr/collections.h>
|
||||
#include <winpr/interlocked.h>
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <freerdp/utils/ringbuffer.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/crypto/tls.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/settings.h>
|
||||
|
||||
#include "http.h"
|
||||
#include "ntlm.h"
|
||||
|
||||
|
||||
/* HTTP channel response fields present flags. */
|
||||
#define HTTP_CHANNEL_RESPONSE_FIELD_CHANNELID 0x1
|
||||
#define HTTP_CHANNEL_RESPONSE_OPTIONAL 0x2
|
||||
#define HTTP_CHANNEL_RESPONSE_FIELD_UDPPORT 0x4
|
||||
|
||||
/* HTTP extended auth. */
|
||||
#define HTTP_EXTENDED_AUTH_NONE 0x0
|
||||
#define HTTP_EXTENDED_AUTH_SC 0x1 /* Smart card authentication. */
|
||||
#define HTTP_EXTENDED_AUTH_PAA 0x02 /* Pluggable authentication. */
|
||||
|
||||
/* HTTP packet types. */
|
||||
#define PKT_TYPE_HANDSHAKE_REQUEST 0x1
|
||||
#define PKT_TYPE_HANDSHAKE_RESPONSE 0x2
|
||||
#define PKT_TYPE_EXTENDED_AUTH_MSG 0x3
|
||||
#define PKT_TYPE_TUNNEL_CREATE 0x4
|
||||
#define PKT_TYPE_TUNNEL_RESPONSE 0x5
|
||||
#define PKT_TYPE_TUNNEL_AUTH 0x6
|
||||
#define PKT_TYPE_TUNNEL_AUTH_RESPONSE 0x7
|
||||
#define PKT_TYPE_CHANNEL_CREATE 0x8
|
||||
#define PKT_TYPE_CHANNEL_RESPONSE 0x9
|
||||
#define PKT_TYPE_DATA 0xA
|
||||
#define PKT_TYPE_SERVICE_MESSAGE 0xB
|
||||
#define PKT_TYPE_REAUTH_MESSAGE 0xC
|
||||
#define PKT_TYPE_KEEPALIVE 0xD
|
||||
#define PKT_TYPE_CLOSE_CHANNEL 0x10
|
||||
#define PKT_TYPE_CLOSE_CHANNEL_RESPONSE 0x11
|
||||
|
||||
/* HTTP tunnel auth fields present flags. */
|
||||
#define HTTP_TUNNEL_AUTH_FIELD_SOH 0x1
|
||||
|
||||
/* HTTP tunnel auth response fields present flags. */
|
||||
#define HTTP_TUNNEL_AUTH_RESPONSE_FIELD_REDIR_FLAGS 0x1
|
||||
#define HTTP_TUNNEL_AUTH_RESPONSE_FIELD_IDLE_TIMEOUT 0x2
|
||||
#define HTTP_TUNNEL_AUTH_RESPONSE_FIELD_SOH_RESPONSE 0x4
|
||||
|
||||
/* HTTP tunnel packet fields present flags. */
|
||||
#define HTTP_TUNNEL_PACKET_FIELD_PAA_COOKIE 0x1
|
||||
#define HTTP_TUNNEL_PACKET_FIELD_REAUTH 0x2
|
||||
|
||||
/* HTTP tunnel redir flags. */
|
||||
#define HTTP_TUNNEL_REDIR_ENABLE_ALL 0x80000000
|
||||
#define HTTP_TUNNEL_REDIR_DISABLE_ALL 0x40000000
|
||||
#define HTTP_TUNNEL_REDIR_DISABLE_DRIVE 0x1
|
||||
#define HTTP_TUNNEL_REDIR_DISABLE_PRINTER 0x2
|
||||
#define HTTP_TUNNEL_REDIR_DISABLE_PORT 0x4
|
||||
#define HTTP_TUNNEL_REDIR_DISABLE_CLIPBOARD 0x8
|
||||
#define HTTP_TUNNEL_REDIR_DISABLE_PNP 0x10
|
||||
|
||||
/* HTTP tunnel response fields present flags. */
|
||||
#define HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID 0x1
|
||||
#define HTTP_TUNNEL_RESPONSE_FIELD_CAPS 0x2
|
||||
#define HTTP_TUNNEL_RESPONSE_FIELD_SOH_REQ 0x4
|
||||
#define HTTP_TUNNEL_RESPONSE_FIELD_CONSENT_MSG 0x10
|
||||
|
||||
/* HTTP capability type enumeration. */
|
||||
#define HTTP_CAPABILITY_TYPE_QUAR_SOH 0x1
|
||||
#define HTTP_CAPABILITY_IDLE_TIMEOUT 0x2
|
||||
#define HTTP_CAPABILITY_MESSAGING_CONSENT_SIGN 0x4
|
||||
#define HTTP_CAPABILITY_MESSAGING_SERVICE_MSG 0x8
|
||||
#define HTTP_CAPABILITY_REAUTH 0x10
|
||||
#define HTTP_CAPABILITY_UDP_TRANSPORT 0x20
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
RDG_CLIENT_STATE_INITIAL,
|
||||
RDG_CLIENT_STATE_OUT_CHANNEL_REQUEST,
|
||||
RDG_CLIENT_STATE_OUT_CHANNEL_AUTHORIZE,
|
||||
RDG_CLIENT_STATE_OUT_CHANNEL_AUTHORIZED,
|
||||
RDG_CLIENT_STATE_IN_CHANNEL_REQUEST,
|
||||
RDG_CLIENT_STATE_IN_CHANNEL_AUTHORIZE,
|
||||
RDG_CLIENT_STATE_IN_CHANNEL_AUTHORIZED,
|
||||
RDG_CLIENT_STATE_HANDSHAKE,
|
||||
RDG_CLIENT_STATE_TUNNEL_CREATE,
|
||||
RDG_CLIENT_STATE_TUNNEL_AUTHORIZE,
|
||||
RDG_CLIENT_STATE_CHANNEL_CREATE,
|
||||
RDG_CLIENT_STATE_OPENED,
|
||||
RDG_CLIENT_STATE_CLOSE,
|
||||
RDG_CLIENT_STATE_CLOSED,
|
||||
};
|
||||
|
||||
|
||||
typedef struct rdp_transport rdpTransport;
|
||||
|
||||
typedef struct rdp_rdg rdpRdg;
|
||||
struct rdp_rdg
|
||||
{
|
||||
rdpContext* context; /* Shortcut to parent context. */
|
||||
BIO* bioIn;
|
||||
BIO* bioOut;
|
||||
BIO* frontBio;
|
||||
rdpTls* tlsIn;
|
||||
rdpTls* tlsOut;
|
||||
rdpNtlm* ntlm;
|
||||
HttpContext* http;
|
||||
HANDLE readEvent;
|
||||
|
||||
UUID guid;
|
||||
|
||||
//UINT32 tunnelId;
|
||||
//UINT32 negotiatedCapsFlags;
|
||||
//UUID nonce;
|
||||
//LPWSTR serverCert;
|
||||
//LPWSTR consentMsg;
|
||||
|
||||
int state;
|
||||
int packetRemainingCount;
|
||||
int nonBlocking;
|
||||
int timeout;
|
||||
};
|
||||
|
||||
|
||||
rdpRdg* rdg_new(rdpTransport* transport);
|
||||
void rdg_free(rdpRdg* rdg);
|
||||
|
||||
BOOL rdg_connect(rdpRdg* rdg, const char* hostname, UINT16 port, int timeout);
|
||||
UINT32 rdg_get_event_handles(rdpRdg* rdg, HANDLE* events);
|
||||
BOOL rdg_check_event_handles(rdpRdg* rdg);
|
||||
|
||||
|
||||
#endif /* FREERDP_CORE_RDG_H */
|
@ -207,17 +207,32 @@ BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 por
|
||||
|
||||
if (transport->GatewayEnabled)
|
||||
{
|
||||
transport->tsg = tsg_new(transport);
|
||||
|
||||
if (!transport->tsg)
|
||||
/* New RDP 8 gateway test. */
|
||||
transport->rdg = rdg_new(transport);
|
||||
if (!transport->rdg)
|
||||
{
|
||||
return FALSE;
|
||||
|
||||
if (!tsg_connect(transport->tsg, hostname, port, timeout))
|
||||
}
|
||||
status = rdg_connect(transport->rdg, hostname, port, timeout);
|
||||
if (!status)
|
||||
{
|
||||
return FALSE;
|
||||
|
||||
transport->frontBio = transport->tsg->bio;
|
||||
}
|
||||
transport->frontBio = transport->rdg->frontBio;
|
||||
BIO_set_nonblock(transport->frontBio, 0);
|
||||
transport->layer = TRANSPORT_LAYER_TSG;
|
||||
|
||||
//transport->tsg = tsg_new(transport);
|
||||
|
||||
//if (!transport->tsg)
|
||||
// return FALSE;
|
||||
|
||||
//if (!tsg_connect(transport->tsg, hostname, port, timeout))
|
||||
// return FALSE;
|
||||
|
||||
//transport->frontBio = transport->tsg->bio;
|
||||
//transport->layer = TRANSPORT_LAYER_TSG;
|
||||
|
||||
status = TRUE;
|
||||
}
|
||||
else
|
||||
@ -621,7 +636,14 @@ UINT32 transport_get_event_handles(rdpTransport* transport, HANDLE* events)
|
||||
}
|
||||
else
|
||||
{
|
||||
nCount += tsg_get_event_handles(transport->tsg, events);
|
||||
if (transport->rdg)
|
||||
{
|
||||
nCount += rdg_get_event_handles(transport->rdg, events);
|
||||
}
|
||||
else if (transport->tsg)
|
||||
{
|
||||
nCount += tsg_get_event_handles(transport->tsg, events);
|
||||
}
|
||||
}
|
||||
|
||||
return nCount;
|
||||
|
@ -35,6 +35,7 @@ typedef struct rdp_transport rdpTransport;
|
||||
#include "nla.h"
|
||||
|
||||
#include "gateway/tsg.h"
|
||||
#include "gateway/rdg.h"
|
||||
|
||||
#include <winpr/sspi.h>
|
||||
#include <winpr/wlog.h>
|
||||
@ -56,6 +57,7 @@ struct rdp_transport
|
||||
{
|
||||
TRANSPORT_LAYER layer;
|
||||
BIO* frontBio;
|
||||
rdpRdg* rdg;
|
||||
rdpTsg* tsg;
|
||||
rdpTls* tls;
|
||||
rdpContext* context;
|
||||
|
Loading…
Reference in New Issue
Block a user