2011-07-01 02:48:48 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-01 02:48:48 +04:00
|
|
|
* RDP Protocol Security Negotiation
|
|
|
|
*
|
2012-11-01 04:38:48 +04:00
|
|
|
* Copyright 2011-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-07-01 02:48:48 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
#ifndef FREERDP_CORE_NEGO_H
|
|
|
|
#define FREERDP_CORE_NEGO_H
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
#include "transport.h"
|
2013-03-22 00:45:25 +04:00
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
#include <freerdp/types.h>
|
|
|
|
#include <freerdp/settings.h>
|
2011-07-03 20:42:35 +04:00
|
|
|
#include <freerdp/utils/debug.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
|
|
|
|
#include <winpr/stream.h>
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-18 07:16:31 +04:00
|
|
|
/* Protocol Security Negotiation Protocols */
|
|
|
|
enum RDP_NEG_PROTOCOLS
|
|
|
|
{
|
|
|
|
PROTOCOL_RDP = 0x00000000,
|
|
|
|
PROTOCOL_TLS = 0x00000001,
|
2012-11-01 04:38:48 +04:00
|
|
|
PROTOCOL_NLA = 0x00000002,
|
|
|
|
PROTOCOL_EXT = 0x00000008
|
2011-07-18 07:16:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Protocol Security Negotiation Failure Codes */
|
|
|
|
enum RDP_NEG_FAILURE_FAILURECODES
|
|
|
|
{
|
|
|
|
SSL_REQUIRED_BY_SERVER = 0x00000001,
|
|
|
|
SSL_NOT_ALLOWED_BY_SERVER = 0x00000002,
|
|
|
|
SSL_CERT_NOT_ON_SERVER = 0x00000003,
|
|
|
|
INCONSISTENT_FLAGS = 0x00000004,
|
|
|
|
HYBRID_REQUIRED_BY_SERVER = 0x00000005
|
|
|
|
};
|
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
/* Authorization Result */
|
|
|
|
#define AUTHZ_SUCCESS 0x00000000
|
|
|
|
#define AUTHZ_ACCESS_DENIED 0x0000052E
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
enum _NEGO_STATE
|
|
|
|
{
|
|
|
|
NEGO_STATE_INITIAL,
|
2012-11-01 04:38:48 +04:00
|
|
|
NEGO_STATE_EXT, /* Extended NLA (NLA + TLS implicit) */
|
2011-07-01 02:48:48 +04:00
|
|
|
NEGO_STATE_NLA, /* Network Level Authentication (TLS implicit) */
|
|
|
|
NEGO_STATE_TLS, /* TLS Encryption without NLA */
|
|
|
|
NEGO_STATE_RDP, /* Standard Legacy RDP Encryption */
|
|
|
|
NEGO_STATE_FAIL, /* Negotiation failure */
|
|
|
|
NEGO_STATE_FINAL
|
|
|
|
};
|
|
|
|
typedef enum _NEGO_STATE NEGO_STATE;
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
/* RDP Negotiation Messages */
|
|
|
|
enum RDP_NEG_MSG
|
|
|
|
{
|
|
|
|
/* X224_TPDU_CONNECTION_REQUEST */
|
|
|
|
TYPE_RDP_NEG_REQ = 0x1,
|
|
|
|
/* X224_TPDU_CONNECTION_CONFIRM */
|
|
|
|
TYPE_RDP_NEG_RSP = 0x2,
|
|
|
|
TYPE_RDP_NEG_FAILURE = 0x3
|
|
|
|
};
|
|
|
|
|
2012-10-26 02:38:51 +04:00
|
|
|
#define EXTENDED_CLIENT_DATA_SUPPORTED 0x01
|
2012-12-13 23:38:02 +04:00
|
|
|
#define DYNVC_GFX_PROTOCOL_SUPPORTED 0x02
|
|
|
|
#define RDP_NEGRSP_RESERVED 0x04
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
#define PRECONNECTION_PDU_V1_SIZE 16
|
2012-10-26 02:38:51 +04:00
|
|
|
#define PRECONNECTION_PDU_V2_MIN_SIZE (PRECONNECTION_PDU_V1_SIZE + 2)
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
#define PRECONNECTION_PDU_V1 1
|
|
|
|
#define PRECONNECTION_PDU_V2 2
|
2012-10-26 02:38:51 +04:00
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
struct rdp_nego
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
|
|
|
int port;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 flags;
|
2011-07-03 20:42:35 +04:00
|
|
|
char* hostname;
|
2011-07-07 21:37:48 +04:00
|
|
|
char* cookie;
|
2012-09-24 12:40:32 +04:00
|
|
|
BYTE* RoutingToken;
|
|
|
|
DWORD RoutingTokenLength;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL send_preconnection_pdu;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 preconnection_id;
|
2012-07-25 20:46:43 +04:00
|
|
|
char* preconnection_blob;
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
NEGO_STATE state;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL tcp_connected;
|
|
|
|
BOOL security_connected;
|
2012-10-26 02:38:51 +04:00
|
|
|
UINT32 cookie_max_length;
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2013-04-13 02:03:56 +04:00
|
|
|
BOOL sendNegoData;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 selected_protocol;
|
|
|
|
UINT32 requested_protocols;
|
2013-01-10 20:19:57 +04:00
|
|
|
BOOL NegotiateSecurityLayer;
|
2012-11-01 04:38:48 +04:00
|
|
|
BYTE enabled_protocols[16];
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
rdpTransport* transport;
|
2011-07-01 02:48:48 +04:00
|
|
|
};
|
2011-07-03 20:42:35 +04:00
|
|
|
typedef struct rdp_nego rdpNego;
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_connect(rdpNego* nego);
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_send_preconnection_pdu(rdpNego* nego);
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
void nego_attempt_ext(rdpNego* nego);
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_attempt_nla(rdpNego* nego);
|
|
|
|
void nego_attempt_tls(rdpNego* nego);
|
|
|
|
void nego_attempt_rdp(rdpNego* nego);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_send(rdpNego* nego);
|
2013-03-21 23:19:33 +04:00
|
|
|
int nego_recv(rdpTransport* transport, wStream* s, void* extra);
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_recv_response(rdpNego* nego);
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL nego_read_request(rdpNego* nego, wStream* s);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_send_negotiation_request(rdpNego* nego);
|
2013-03-21 23:19:33 +04:00
|
|
|
void nego_process_negotiation_request(rdpNego* nego, wStream* s);
|
|
|
|
void nego_process_negotiation_response(rdpNego* nego, wStream* s);
|
|
|
|
void nego_process_negotiation_failure(rdpNego* nego, wStream* s);
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_send_negotiation_response(rdpNego* nego);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
rdpNego* nego_new(struct rdp_transport * transport);
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_free(rdpNego* nego);
|
2012-09-24 12:40:32 +04:00
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_init(rdpNego* nego);
|
|
|
|
void nego_set_target(rdpNego* nego, char* hostname, int port);
|
2012-11-07 20:02:46 +04:00
|
|
|
void nego_set_negotiation_enabled(rdpNego* nego, BOOL NegotiateSecurityLayer_enabled);
|
2012-10-09 10:38:39 +04:00
|
|
|
void nego_enable_rdp(rdpNego* nego, BOOL enable_rdp);
|
|
|
|
void nego_enable_tls(rdpNego* nego, BOOL enable_tls);
|
2012-11-01 04:38:48 +04:00
|
|
|
void nego_enable_nla(rdpNego* nego, BOOL enable_nla);
|
|
|
|
void nego_enable_ext(rdpNego* nego, BOOL enable_ext);
|
2012-09-24 12:40:32 +04:00
|
|
|
void nego_set_routing_token(rdpNego* nego, BYTE* RoutingToken, DWORD RoutingTokenLength);
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_set_cookie(rdpNego* nego, char* cookie);
|
2012-10-26 02:38:51 +04:00
|
|
|
void nego_set_cookie_max_length(rdpNego* nego, UINT32 cookie_max_length);
|
2012-10-09 10:38:39 +04:00
|
|
|
void nego_set_send_preconnection_pdu(rdpNego* nego, BOOL send_pcpdu);
|
2012-10-09 11:26:39 +04:00
|
|
|
void nego_set_preconnection_id(rdpNego* nego, UINT32 id);
|
2012-07-25 20:46:43 +04:00
|
|
|
void nego_set_preconnection_blob(rdpNego* nego, char* blob);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
#ifdef WITH_DEBUG_NEGO
|
|
|
|
#define DEBUG_NEGO(fmt, ...) DEBUG_CLASS(NEGO, fmt, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DEBUG_NEGO(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
|
|
|
|
#endif
|
2011-07-01 02:48:48 +04:00
|
|
|
|
|
|
|
#endif /* __NEGO_H */
|