Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-core / nego.h
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * RDP Protocol Security Negotiation
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #ifndef __NEGO_H
21 #define __NEGO_H
22
23 #include "transport.h"
24 #include <freerdp/types.h>
25 #include <freerdp/settings.h>
26 #include <freerdp/utils/blob.h>
27 #include <freerdp/utils/debug.h>
28 #include <freerdp/utils/stream.h>
29
30 /* Protocol Security Negotiation Protocols */
31 enum RDP_NEG_PROTOCOLS
32 {
33         PROTOCOL_RDP = 0x00000000,
34         PROTOCOL_TLS = 0x00000001,
35         PROTOCOL_NLA = 0x00000002
36 };
37
38 /* Protocol Security Negotiation Failure Codes */
39 enum RDP_NEG_FAILURE_FAILURECODES
40 {
41         SSL_REQUIRED_BY_SERVER = 0x00000001,
42         SSL_NOT_ALLOWED_BY_SERVER = 0x00000002,
43         SSL_CERT_NOT_ON_SERVER = 0x00000003,
44         INCONSISTENT_FLAGS = 0x00000004,
45         HYBRID_REQUIRED_BY_SERVER = 0x00000005
46 };
47
48 enum _NEGO_STATE
49 {
50         NEGO_STATE_INITIAL,
51         NEGO_STATE_NLA, /* Network Level Authentication (TLS implicit) */
52         NEGO_STATE_TLS, /* TLS Encryption without NLA */
53         NEGO_STATE_RDP, /* Standard Legacy RDP Encryption */
54         NEGO_STATE_FAIL, /* Negotiation failure */
55         NEGO_STATE_FINAL
56 };
57 typedef enum _NEGO_STATE NEGO_STATE;
58
59 /* RDP Negotiation Messages */
60 enum RDP_NEG_MSG
61 {
62         /* X224_TPDU_CONNECTION_REQUEST */
63         TYPE_RDP_NEG_REQ = 0x1,
64         /* X224_TPDU_CONNECTION_CONFIRM */
65         TYPE_RDP_NEG_RSP = 0x2,
66         TYPE_RDP_NEG_FAILURE = 0x3
67 };
68
69 #define EXTENDED_CLIENT_DATA_SUPPORTED 0x01
70
71 struct rdp_nego
72 {
73         int port;
74         uint32 flags;
75         char* hostname;
76         char* cookie;
77         NEGO_STATE state;
78         int tcp_connected;
79         rdpBlob* routing_token;
80         uint32 selected_protocol;
81         uint32 requested_protocols;
82         uint8 enabled_protocols[3];
83         rdpTransport* transport;
84 };
85 typedef struct rdp_nego rdpNego;
86
87 boolean nego_connect(rdpNego* nego);
88
89 void nego_attempt_nla(rdpNego* nego);
90 void nego_attempt_tls(rdpNego* nego);
91 void nego_attempt_rdp(rdpNego* nego);
92
93 void nego_send(rdpNego* nego);
94 boolean nego_recv(rdpTransport* transport, STREAM* s, void* extra);
95 boolean nego_recv_response(rdpNego* nego);
96 boolean nego_read_request(rdpNego* nego, STREAM* s);
97
98 boolean nego_send_negotiation_request(rdpNego* nego);
99 void nego_process_negotiation_request(rdpNego* nego, STREAM* s);
100 void nego_process_negotiation_response(rdpNego* nego, STREAM* s);
101 void nego_process_negotiation_failure(rdpNego* nego, STREAM* s);
102 boolean nego_send_negotiation_response(rdpNego* nego);
103
104 rdpNego* nego_new(struct rdp_transport * transport);
105 void nego_free(rdpNego* nego);
106 void nego_init(rdpNego* nego);
107 void nego_set_target(rdpNego* nego, char* hostname, int port);
108 void nego_enable_rdp(rdpNego* nego, boolean enable_rdp);
109 void nego_enable_nla(rdpNego* nego, boolean enable_nla);
110 void nego_enable_tls(rdpNego* nego, boolean enable_tls);
111 void nego_set_routing_token(rdpNego* nego, rdpBlob* routing_token);
112 void nego_set_cookie(rdpNego* nego, char* cookie);
113
114 #ifdef WITH_DEBUG_NEGO
115 #define DEBUG_NEGO(fmt, ...) DEBUG_CLASS(NEGO, fmt, ## __VA_ARGS__)
116 #else
117 #define DEBUG_NEGO(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
118 #endif
119
120 #endif /* __NEGO_H */