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
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
#include "tpkt.h"
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
#include "nego.h"
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
#include "transport.h"
|
|
|
|
|
2011-12-01 02:40:36 +04:00
|
|
|
static const char* const NEGO_STATE_STRINGS[] =
|
2011-07-10 09:48:10 +04:00
|
|
|
{
|
|
|
|
"NEGO_STATE_INITIAL",
|
2012-11-01 04:38:48 +04:00
|
|
|
"NEGO_STATE_EXT",
|
2011-07-10 09:48:10 +04:00
|
|
|
"NEGO_STATE_NLA",
|
|
|
|
"NEGO_STATE_TLS",
|
|
|
|
"NEGO_STATE_RDP",
|
|
|
|
"NEGO_STATE_FAIL",
|
|
|
|
"NEGO_STATE_FINAL"
|
|
|
|
};
|
|
|
|
|
2013-10-29 00:54:00 +04:00
|
|
|
static const char PROTOCOL_SECURITY_STRINGS[9][4] =
|
2011-07-10 09:48:10 +04:00
|
|
|
{
|
|
|
|
"RDP",
|
|
|
|
"TLS",
|
2012-11-01 04:38:48 +04:00
|
|
|
"NLA",
|
2013-10-29 00:54:00 +04:00
|
|
|
"UNK",
|
|
|
|
"UNK",
|
|
|
|
"UNK",
|
|
|
|
"UNK",
|
|
|
|
"UNK",
|
2012-11-01 04:38:48 +04:00
|
|
|
"EXT"
|
2011-07-10 09:48:10 +04:00
|
|
|
};
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_security_connect(rdpNego* nego);
|
2012-07-25 20:50:19 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
/**
|
|
|
|
* Negotiate protocol security and connect.
|
|
|
|
* @param nego
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_connect(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
|
|
|
if (nego->state == NEGO_STATE_INITIAL)
|
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
if (nego->enabled_protocols[PROTOCOL_EXT])
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_EXT;
|
|
|
|
}
|
|
|
|
else if (nego->enabled_protocols[PROTOCOL_NLA])
|
|
|
|
{
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_NLA;
|
2012-11-01 04:38:48 +04:00
|
|
|
}
|
|
|
|
else if (nego->enabled_protocols[PROTOCOL_TLS])
|
|
|
|
{
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_TLS;
|
2012-11-01 04:38:48 +04:00
|
|
|
}
|
|
|
|
else if (nego->enabled_protocols[PROTOCOL_RDP])
|
|
|
|
{
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_RDP;
|
2012-11-01 04:38:48 +04:00
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
else
|
2012-07-25 14:29:49 +04:00
|
|
|
{
|
|
|
|
DEBUG_NEGO("No security protocol is enabled");
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_FAIL;
|
2012-07-25 14:29:49 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 20:19:57 +04:00
|
|
|
if (!nego->NegotiateSecurityLayer)
|
2012-07-25 14:29:49 +04:00
|
|
|
{
|
|
|
|
DEBUG_NEGO("Security Layer Negotiation is disabled");
|
2012-08-01 00:58:41 +04:00
|
|
|
/* attempt only the highest enabled protocol (see nego_attempt_*) */
|
2012-11-01 04:38:48 +04:00
|
|
|
|
|
|
|
nego->enabled_protocols[PROTOCOL_NLA] = FALSE;
|
|
|
|
nego->enabled_protocols[PROTOCOL_TLS] = FALSE;
|
|
|
|
nego->enabled_protocols[PROTOCOL_RDP] = FALSE;
|
|
|
|
nego->enabled_protocols[PROTOCOL_EXT] = FALSE;
|
|
|
|
|
|
|
|
if (nego->state == NEGO_STATE_EXT)
|
2012-08-01 00:58:41 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
nego->enabled_protocols[PROTOCOL_EXT] = TRUE;
|
|
|
|
nego->enabled_protocols[PROTOCOL_NLA] = TRUE;
|
|
|
|
nego->selected_protocol = PROTOCOL_EXT;
|
|
|
|
}
|
|
|
|
else if (nego->state == NEGO_STATE_NLA)
|
|
|
|
{
|
|
|
|
nego->enabled_protocols[PROTOCOL_NLA] = TRUE;
|
2012-08-01 00:58:41 +04:00
|
|
|
nego->selected_protocol = PROTOCOL_NLA;
|
|
|
|
}
|
2012-07-25 14:29:49 +04:00
|
|
|
else if (nego->state == NEGO_STATE_TLS)
|
2012-08-01 00:58:41 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
nego->enabled_protocols[PROTOCOL_TLS] = TRUE;
|
2012-08-01 00:58:41 +04:00
|
|
|
nego->selected_protocol = PROTOCOL_TLS;
|
|
|
|
}
|
2012-07-25 14:29:49 +04:00
|
|
|
else if (nego->state == NEGO_STATE_RDP)
|
2012-08-01 00:58:41 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
nego->enabled_protocols[PROTOCOL_RDP] = TRUE;
|
2012-08-01 00:58:41 +04:00
|
|
|
nego->selected_protocol = PROTOCOL_RDP;
|
|
|
|
}
|
2012-07-25 14:29:49 +04:00
|
|
|
}
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
if (!nego_send_preconnection_pdu(nego))
|
2012-07-25 20:46:43 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
DEBUG_NEGO("Failed to send preconnection pdu");
|
2012-07-25 20:46:43 +04:00
|
|
|
nego->state = NEGO_STATE_FINAL;
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-07-25 20:46:43 +04:00
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
do
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("state: %s", NEGO_STATE_STRINGS[nego->state]);
|
|
|
|
|
2011-07-03 23:34:15 +04:00
|
|
|
nego_send(nego);
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
if (nego->state == NEGO_STATE_FAIL)
|
|
|
|
{
|
2011-07-07 21:37:48 +04:00
|
|
|
DEBUG_NEGO("Protocol Security Negotiation Failure");
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_FINAL;
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
}
|
2011-07-07 21:37:48 +04:00
|
|
|
while (nego->state != NEGO_STATE_FINAL);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-03 23:34:15 +04:00
|
|
|
DEBUG_NEGO("Negotiated %s security", PROTOCOL_SECURITY_STRINGS[nego->selected_protocol]);
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
/* update settings with negotiated protocol security */
|
2012-11-07 20:02:46 +04:00
|
|
|
nego->transport->settings->RequestedProtocols = nego->requested_protocols;
|
|
|
|
nego->transport->settings->SelectedProtocol = nego->selected_protocol;
|
|
|
|
nego->transport->settings->NegotiationFlags = nego->flags;
|
2011-07-07 21:37:48 +04:00
|
|
|
|
2012-11-15 05:46:51 +04:00
|
|
|
if (nego->selected_protocol == PROTOCOL_RDP)
|
2011-10-05 02:54:38 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
nego->transport->settings->DisableEncryption = TRUE;
|
|
|
|
nego->transport->settings->EncryptionMethods = ENCRYPTION_METHOD_40BIT | ENCRYPTION_METHOD_128BIT | ENCRYPTION_METHOD_FIPS;
|
2012-11-07 20:02:46 +04:00
|
|
|
nego->transport->settings->EncryptionLevel = ENCRYPTION_LEVEL_CLIENT_COMPATIBLE;
|
2011-10-05 02:54:38 +04:00
|
|
|
}
|
|
|
|
|
2012-07-25 20:50:19 +04:00
|
|
|
/* finally connect security layer (if not already done) */
|
2012-11-15 05:46:51 +04:00
|
|
|
if (!nego_security_connect(nego))
|
2012-07-25 20:50:19 +04:00
|
|
|
{
|
|
|
|
DEBUG_NEGO("Failed to connect with %s security", PROTOCOL_SECURITY_STRINGS[nego->selected_protocol]);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-07-25 20:50:19 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
/* connect to selected security layer */
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_security_connect(rdpNego* nego)
|
2012-07-25 14:29:49 +04:00
|
|
|
{
|
2012-10-26 02:38:51 +04:00
|
|
|
if (!nego->tcp_connected)
|
2012-07-25 14:29:49 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
nego->security_connected = FALSE;
|
2012-07-25 14:29:49 +04:00
|
|
|
}
|
|
|
|
else if (!nego->security_connected)
|
|
|
|
{
|
2012-08-01 00:58:41 +04:00
|
|
|
if (nego->selected_protocol == PROTOCOL_NLA)
|
2012-07-27 16:43:57 +04:00
|
|
|
{
|
2012-08-01 00:58:41 +04:00
|
|
|
DEBUG_NEGO("nego_security_connect with PROTOCOL_NLA");
|
2012-07-25 14:29:49 +04:00
|
|
|
nego->security_connected = transport_connect_nla(nego->transport);
|
2012-07-27 16:43:57 +04:00
|
|
|
}
|
2012-10-26 02:38:51 +04:00
|
|
|
else if (nego->selected_protocol == PROTOCOL_TLS)
|
2012-07-27 16:43:57 +04:00
|
|
|
{
|
2012-08-01 00:58:41 +04:00
|
|
|
DEBUG_NEGO("nego_security_connect with PROTOCOL_TLS");
|
2012-07-25 14:29:49 +04:00
|
|
|
nego->security_connected = transport_connect_tls(nego->transport);
|
2012-07-27 16:43:57 +04:00
|
|
|
}
|
2012-08-01 00:58:41 +04:00
|
|
|
else if (nego->selected_protocol == PROTOCOL_RDP)
|
2012-07-27 16:43:57 +04:00
|
|
|
{
|
2012-08-01 00:58:41 +04:00
|
|
|
DEBUG_NEGO("nego_security_connect with PROTOCOL_RDP");
|
2012-07-25 14:29:49 +04:00
|
|
|
nego->security_connected = transport_connect_rdp(nego->transport);
|
2012-07-27 16:43:57 +04:00
|
|
|
}
|
2012-08-01 01:07:48 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_NEGO("cannot connect security layer because no protocol has been selected yet.");
|
|
|
|
}
|
2012-07-25 14:29:49 +04:00
|
|
|
}
|
2012-10-26 02:38:51 +04:00
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
return nego->security_connected;
|
|
|
|
}
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
/**
|
|
|
|
* Connect TCP layer.
|
|
|
|
* @param nego
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_tcp_connect(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-07-25 14:29:49 +04:00
|
|
|
if (!nego->tcp_connected)
|
|
|
|
nego->tcp_connected = transport_connect(nego->transport, nego->hostname, nego->port);
|
2012-09-09 01:49:37 +04:00
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
return nego->tcp_connected;
|
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
/**
|
|
|
|
* Connect TCP layer. For direct approach, connect security layer as well.
|
|
|
|
* @param nego
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_transport_connect(rdpNego* nego)
|
2012-07-25 14:29:49 +04:00
|
|
|
{
|
|
|
|
nego_tcp_connect(nego);
|
|
|
|
|
2013-01-10 20:19:57 +04:00
|
|
|
if (nego->tcp_connected && !nego->NegotiateSecurityLayer)
|
2012-07-25 20:46:43 +04:00
|
|
|
return nego_security_connect(nego);
|
2012-07-25 14:29:49 +04:00
|
|
|
|
|
|
|
return nego->tcp_connected;
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect TCP layer.
|
|
|
|
* @param nego
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
int nego_transport_disconnect(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
|
|
|
if (nego->tcp_connected)
|
2011-07-03 20:42:35 +04:00
|
|
|
transport_disconnect(nego->transport);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
nego->tcp_connected = FALSE;
|
|
|
|
nego->security_connected = FALSE;
|
2012-09-09 01:49:37 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-07-25 20:46:43 +04:00
|
|
|
/**
|
|
|
|
* Send preconnection information if enabled.
|
|
|
|
* @param nego
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_send_preconnection_pdu(rdpNego* nego)
|
2012-07-25 20:46:43 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 cchPCB = 0;
|
2012-09-24 03:49:13 +04:00
|
|
|
WCHAR* wszPCB = NULL;
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2012-07-29 03:30:21 +04:00
|
|
|
if (!nego->send_preconnection_pdu)
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-07-25 20:46:43 +04:00
|
|
|
|
|
|
|
DEBUG_NEGO("Sending preconnection PDU");
|
2012-07-29 03:30:21 +04:00
|
|
|
|
|
|
|
if (!nego_tcp_connect(nego))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-07-25 20:46:43 +04:00
|
|
|
|
|
|
|
/* it's easier to always send the version 2 PDU, and it's just 2 bytes overhead */
|
|
|
|
cbSize = PRECONNECTION_PDU_V2_MIN_SIZE;
|
2012-07-29 03:30:21 +04:00
|
|
|
|
|
|
|
if (nego->preconnection_blob)
|
|
|
|
{
|
2012-12-17 19:20:25 +04:00
|
|
|
cchPCB = (UINT16) ConvertToUnicode(CP_UTF8, 0, nego->preconnection_blob, -1, &wszPCB, 0);
|
2012-09-24 03:49:13 +04:00
|
|
|
cchPCB += 1; /* zero-termination */
|
|
|
|
cbSize += cchPCB * 2;
|
2012-07-25 20:46:43 +04:00
|
|
|
}
|
|
|
|
|
2013-05-15 21:17:29 +04:00
|
|
|
s = Stream_New(NULL, cbSize);
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, cbSize); /* cbSize */
|
|
|
|
Stream_Write_UINT32(s, 0); /* Flags */
|
|
|
|
Stream_Write_UINT32(s, PRECONNECTION_PDU_V2); /* Version */
|
|
|
|
Stream_Write_UINT32(s, nego->preconnection_id); /* Id */
|
|
|
|
Stream_Write_UINT16(s, cchPCB); /* cchPCB */
|
2012-07-29 03:30:21 +04:00
|
|
|
|
|
|
|
if (wszPCB)
|
2012-07-25 20:46:43 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, wszPCB, cchPCB * 2); /* wszPCB */
|
2012-10-09 07:21:26 +04:00
|
|
|
free(wszPCB);
|
2012-07-25 20:46:43 +04:00
|
|
|
}
|
|
|
|
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_SealLength(s);
|
|
|
|
|
2012-07-25 20:46:43 +04:00
|
|
|
if (transport_write(nego->transport, s) < 0)
|
2013-09-06 13:07:33 +04:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-09-06 13:07:33 +04:00
|
|
|
}
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2013-05-15 21:17:29 +04:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-07-25 20:46:43 +04:00
|
|
|
}
|
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
/**
|
|
|
|
* Attempt negotiating NLA + TLS extended security.
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nego_attempt_ext(rdpNego* nego)
|
|
|
|
{
|
|
|
|
nego->requested_protocols = PROTOCOL_NLA | PROTOCOL_TLS | PROTOCOL_EXT;
|
|
|
|
|
|
|
|
DEBUG_NEGO("Attempting NLA extended security");
|
|
|
|
|
|
|
|
if (!nego_transport_connect(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nego_send_negotiation_request(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nego_recv_response(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_NEGO("state: %s", NEGO_STATE_STRINGS[nego->state]);
|
|
|
|
|
|
|
|
if (nego->state != NEGO_STATE_FINAL)
|
|
|
|
{
|
|
|
|
nego_transport_disconnect(nego);
|
|
|
|
|
|
|
|
if (nego->enabled_protocols[PROTOCOL_NLA])
|
|
|
|
nego->state = NEGO_STATE_NLA;
|
|
|
|
else if (nego->enabled_protocols[PROTOCOL_TLS])
|
|
|
|
nego->state = NEGO_STATE_TLS;
|
|
|
|
else if (nego->enabled_protocols[PROTOCOL_RDP])
|
|
|
|
nego->state = NEGO_STATE_RDP;
|
|
|
|
else
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
/**
|
|
|
|
* Attempt negotiating NLA + TLS security.
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_attempt_nla(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
|
|
|
nego->requested_protocols = PROTOCOL_NLA | PROTOCOL_TLS;
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Attempting NLA security");
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
if (!nego_transport_connect(nego))
|
2011-08-13 08:40:14 +04:00
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (!nego_send_negotiation_request(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (!nego_recv_response(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-03-29 22:06:17 +04:00
|
|
|
DEBUG_NEGO("state: %s", NEGO_STATE_STRINGS[nego->state]);
|
2012-11-01 04:38:48 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
if (nego->state != NEGO_STATE_FINAL)
|
|
|
|
{
|
2012-07-25 14:29:49 +04:00
|
|
|
nego_transport_disconnect(nego);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
if (nego->enabled_protocols[PROTOCOL_TLS])
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_TLS;
|
2012-11-01 04:38:48 +04:00
|
|
|
else if (nego->enabled_protocols[PROTOCOL_RDP])
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_RDP;
|
|
|
|
else
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt negotiating TLS security.
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_attempt_tls(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
|
|
|
nego->requested_protocols = PROTOCOL_TLS;
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Attempting TLS security");
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
if (!nego_transport_connect(nego))
|
2011-08-13 08:40:14 +04:00
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (!nego_send_negotiation_request(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (!nego_recv_response(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
|
|
|
|
if (nego->state != NEGO_STATE_FINAL)
|
|
|
|
{
|
2012-07-25 14:29:49 +04:00
|
|
|
nego_transport_disconnect(nego);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
if (nego->enabled_protocols[PROTOCOL_RDP])
|
2011-07-01 02:48:48 +04:00
|
|
|
nego->state = NEGO_STATE_RDP;
|
|
|
|
else
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt negotiating standard RDP security.
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_attempt_rdp(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
|
|
|
nego->requested_protocols = PROTOCOL_RDP;
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Attempting RDP security");
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
if (!nego_transport_connect(nego))
|
2011-08-13 08:40:14 +04:00
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (!nego_send_negotiation_request(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (!nego_recv_response(nego))
|
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
2011-07-07 21:37:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait to receive a negotiation response
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_recv_response(rdpNego* nego)
|
2011-07-07 21:37:48 +04:00
|
|
|
{
|
2013-05-15 23:54:33 +04:00
|
|
|
int status;
|
|
|
|
wStream* s;
|
|
|
|
|
|
|
|
s = Stream_New(NULL, 1024);
|
|
|
|
|
|
|
|
status = transport_read(nego->transport, s);
|
2012-02-12 21:46:53 +04:00
|
|
|
|
2013-05-15 23:54:33 +04:00
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2013-01-14 02:37:50 +04:00
|
|
|
return FALSE;
|
2013-05-15 23:54:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
status = nego_recv(nego->transport, s, nego);
|
2012-02-12 21:46:53 +04:00
|
|
|
|
2013-08-28 18:42:23 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2013-05-15 23:54:33 +04:00
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-05 05:35:32 +04:00
|
|
|
* Receive protocol security negotiation message.\n
|
|
|
|
* @msdn{cc240501}
|
|
|
|
* @param transport transport
|
|
|
|
* @param s stream
|
|
|
|
* @param extra nego pointer
|
2011-07-01 02:48:48 +04:00
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
int nego_recv(rdpTransport* transport, wStream* s, void* extra)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE li;
|
|
|
|
BYTE type;
|
2012-12-12 02:24:52 +04:00
|
|
|
UINT16 length;
|
2011-07-07 21:37:48 +04:00
|
|
|
rdpNego* nego = (rdpNego*) extra;
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2012-12-12 02:24:52 +04:00
|
|
|
length = tpkt_read_header(s);
|
|
|
|
|
|
|
|
if (length == 0)
|
2013-01-07 02:24:08 +04:00
|
|
|
return -1;
|
2011-09-25 22:54:07 +04:00
|
|
|
|
2013-04-13 02:03:56 +04:00
|
|
|
if (!tpdu_read_connection_confirm(s, &li))
|
2013-01-12 17:49:01 +04:00
|
|
|
return -1;
|
2011-07-03 21:49:06 +04:00
|
|
|
|
|
|
|
if (li > 6)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2011-07-03 21:49:06 +04:00
|
|
|
/* rdpNegData (optional) */
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, type); /* Type */
|
2011-07-03 21:49:06 +04:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TYPE_RDP_NEG_RSP:
|
|
|
|
nego_process_negotiation_response(nego, s);
|
2012-03-29 22:06:17 +04:00
|
|
|
|
|
|
|
DEBUG_NEGO("selected_protocol: %d", nego->selected_protocol);
|
2012-03-31 18:09:19 +04:00
|
|
|
|
|
|
|
/* enhanced security selected ? */
|
2012-06-20 04:10:49 +04:00
|
|
|
|
|
|
|
if (nego->selected_protocol)
|
|
|
|
{
|
|
|
|
if ((nego->selected_protocol == PROTOCOL_NLA) &&
|
2012-11-01 04:38:48 +04:00
|
|
|
(!nego->enabled_protocols[PROTOCOL_NLA]))
|
2012-06-20 04:10:49 +04:00
|
|
|
{
|
2012-03-31 18:09:19 +04:00
|
|
|
nego->state = NEGO_STATE_FAIL;
|
2012-06-20 04:10:49 +04:00
|
|
|
}
|
|
|
|
if ((nego->selected_protocol == PROTOCOL_TLS) &&
|
|
|
|
(!nego->enabled_protocols[PROTOCOL_TLS]))
|
|
|
|
{
|
2012-03-31 18:09:19 +04:00
|
|
|
nego->state = NEGO_STATE_FAIL;
|
2012-06-20 04:10:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!nego->enabled_protocols[PROTOCOL_RDP])
|
|
|
|
{
|
2012-03-29 22:06:17 +04:00
|
|
|
nego->state = NEGO_STATE_FAIL;
|
2012-06-20 04:10:49 +04:00
|
|
|
}
|
2011-07-03 21:49:06 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_RDP_NEG_FAILURE:
|
|
|
|
nego_process_negotiation_failure(nego, s);
|
|
|
|
break;
|
|
|
|
}
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
2012-12-12 02:24:52 +04:00
|
|
|
else if (li == 6)
|
2011-07-07 21:37:48 +04:00
|
|
|
{
|
2012-03-31 18:09:19 +04:00
|
|
|
DEBUG_NEGO("no rdpNegData");
|
2012-06-20 04:10:49 +04:00
|
|
|
|
2012-03-31 18:09:19 +04:00
|
|
|
if (!nego->enabled_protocols[PROTOCOL_RDP])
|
2012-03-29 22:06:17 +04:00
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
else
|
|
|
|
nego->state = NEGO_STATE_FINAL;
|
2011-07-07 21:37:48 +04:00
|
|
|
}
|
2012-12-12 02:24:52 +04:00
|
|
|
else
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "invalid negotiation response\n");
|
2012-12-12 02:24:52 +04:00
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
}
|
2011-07-03 21:49:06 +04:00
|
|
|
|
2013-01-07 02:24:08 +04:00
|
|
|
return 0;
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
/**
|
2011-08-22 11:03:58 +04:00
|
|
|
* Read protocol security negotiation request message.\n
|
2011-08-18 19:15:28 +04:00
|
|
|
* @param nego
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL nego_read_request(rdpNego* nego, wStream* s)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE li;
|
|
|
|
BYTE c;
|
|
|
|
BYTE type;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
|
|
|
tpkt_read_header(s);
|
2013-04-13 02:03:56 +04:00
|
|
|
|
|
|
|
if (!tpdu_read_connection_request(s, &li))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2012-02-12 21:46:53 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (li != Stream_GetRemainingLength(s) + 6)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Incorrect TPDU length indicator.\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) > 8)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
|
|
|
/* Optional routingToken or cookie, ending with CR+LF */
|
2013-04-30 06:35:15 +04:00
|
|
|
while (Stream_GetRemainingLength(s) > 0)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, c);
|
2012-09-09 01:49:37 +04:00
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
if (c != '\x0D')
|
|
|
|
continue;
|
2012-09-09 01:49:37 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Peek_UINT8(s, c);
|
2012-09-09 01:49:37 +04:00
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
if (c != '\x0A')
|
|
|
|
continue;
|
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(s);
|
2011-08-18 19:15:28 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) >= 8)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
|
|
|
/* rdpNegData (optional) */
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, type); /* Type */
|
2012-06-20 04:10:49 +04:00
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
if (type != TYPE_RDP_NEG_REQ)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Incorrect negotiation request type %d\n", type);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nego_process_negotiation_request(nego, s);
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
/**
|
|
|
|
* Send protocol security negotiation message.
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_send(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
if (nego->state == NEGO_STATE_EXT)
|
|
|
|
nego_attempt_ext(nego);
|
|
|
|
else if (nego->state == NEGO_STATE_NLA)
|
2011-07-01 02:48:48 +04:00
|
|
|
nego_attempt_nla(nego);
|
|
|
|
else if (nego->state == NEGO_STATE_TLS)
|
|
|
|
nego_attempt_tls(nego);
|
|
|
|
else if (nego->state == NEGO_STATE_RDP)
|
|
|
|
nego_attempt_rdp(nego);
|
2011-07-07 21:37:48 +04:00
|
|
|
else
|
|
|
|
DEBUG_NEGO("invalid negotiation state for sending");
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
2011-07-05 05:35:32 +04:00
|
|
|
/**
|
|
|
|
* Send RDP Negotiation Request (RDP_NEG_REQ).\n
|
|
|
|
* @msdn{cc240500}\n
|
|
|
|
* @msdn{cc240470}
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_send_negotiation_request(rdpNego* nego)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2011-07-03 20:42:35 +04:00
|
|
|
int length;
|
2013-05-15 22:42:37 +04:00
|
|
|
int bm, em;
|
2013-11-06 10:51:55 +04:00
|
|
|
BYTE flags = 0;
|
2012-10-26 02:38:51 +04:00
|
|
|
int cookie_length;
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2013-05-15 21:17:29 +04:00
|
|
|
s = Stream_New(NULL, 512);
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
length = TPDU_CONNECTION_REQUEST_LENGTH;
|
2013-05-15 22:42:37 +04:00
|
|
|
bm = Stream_GetPosition(s);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, length);
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2013-04-11 19:51:10 +04:00
|
|
|
if (nego->RoutingToken)
|
2011-09-04 02:21:21 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, nego->RoutingToken, nego->RoutingTokenLength);
|
|
|
|
Stream_Write_UINT8(s, 0x0D); /* CR */
|
|
|
|
Stream_Write_UINT8(s, 0x0A); /* LF */
|
2013-04-11 19:51:10 +04:00
|
|
|
length += nego->RoutingTokenLength + 2;
|
2011-09-04 02:21:21 +04:00
|
|
|
}
|
2013-04-11 19:51:10 +04:00
|
|
|
else if (nego->cookie)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
2012-10-26 02:38:51 +04:00
|
|
|
cookie_length = strlen(nego->cookie);
|
|
|
|
|
2012-10-28 20:12:36 +04:00
|
|
|
if (cookie_length > (int) nego->cookie_max_length)
|
2012-10-26 02:38:51 +04:00
|
|
|
cookie_length = nego->cookie_max_length;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, "Cookie: mstshash=", 17);
|
|
|
|
Stream_Write(s, (BYTE*) nego->cookie, cookie_length);
|
|
|
|
Stream_Write_UINT8(s, 0x0D); /* CR */
|
|
|
|
Stream_Write_UINT8(s, 0x0A); /* LF */
|
2011-07-03 20:42:35 +04:00
|
|
|
length += cookie_length + 19;
|
|
|
|
}
|
|
|
|
|
2012-11-13 20:06:33 +04:00
|
|
|
DEBUG_NEGO("requested_protocols: %d", nego->requested_protocols);
|
2012-09-09 01:49:37 +04:00
|
|
|
|
2013-04-13 02:03:56 +04:00
|
|
|
if ((nego->requested_protocols > PROTOCOL_RDP) || (nego->sendNegoData))
|
2011-07-03 21:49:06 +04:00
|
|
|
{
|
|
|
|
/* RDP_NEG_DATA must be present for TLS and NLA */
|
2013-11-06 10:51:55 +04:00
|
|
|
|
|
|
|
if (nego->RestrictedAdminModeRequired)
|
|
|
|
flags |= RESTRICTED_ADMIN_MODE_REQUIRED;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, TYPE_RDP_NEG_REQ);
|
2013-11-06 10:51:55 +04:00
|
|
|
Stream_Write_UINT8(s, flags);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, 8); /* RDP_NEG_DATA length (8) */
|
|
|
|
Stream_Write_UINT32(s, nego->requested_protocols); /* requestedProtocols */
|
2011-07-03 21:49:06 +04:00
|
|
|
length += 8;
|
|
|
|
}
|
|
|
|
|
2013-05-15 22:42:37 +04:00
|
|
|
em = Stream_GetPosition(s);
|
|
|
|
Stream_SetPosition(s, bm);
|
2011-07-03 20:42:35 +04:00
|
|
|
tpkt_write_header(s, length);
|
|
|
|
tpdu_write_connection_request(s, length - 5);
|
2013-05-15 22:42:37 +04:00
|
|
|
Stream_SetPosition(s, em);
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_SealLength(s);
|
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (transport_write(nego->transport, s) < 0)
|
2013-09-06 13:07:33 +04:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-09-06 13:07:33 +04:00
|
|
|
}
|
2011-09-16 19:16:16 +04:00
|
|
|
|
2013-05-15 21:17:29 +04:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-03 20:42:35 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
/**
|
|
|
|
* Process Negotiation Request from Connection Request message.
|
|
|
|
* @param nego
|
|
|
|
* @param s
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void nego_process_negotiation_request(rdpNego* nego, wStream* s)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags;
|
|
|
|
UINT16 length;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
|
|
|
DEBUG_NEGO("RDP_NEG_REQ");
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, flags);
|
|
|
|
Stream_Read_UINT16(s, length);
|
|
|
|
Stream_Read_UINT32(s, nego->requested_protocols);
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2012-11-13 20:06:33 +04:00
|
|
|
DEBUG_NEGO("requested_protocols: %d", nego->requested_protocols);
|
2012-06-20 04:10:49 +04:00
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
nego->state = NEGO_STATE_FINAL;
|
|
|
|
}
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
/**
|
|
|
|
* Process Negotiation Response from Connection Confirm message.
|
|
|
|
* @param nego
|
|
|
|
* @param s
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void nego_process_negotiation_response(rdpNego* nego, wStream* s)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 length;
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-03 21:49:06 +04:00
|
|
|
DEBUG_NEGO("RDP_NEG_RSP");
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 7)
|
2013-01-12 17:49:01 +04:00
|
|
|
{
|
|
|
|
DEBUG_NEGO("RDP_INVALID_NEG_RSP");
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, nego->flags);
|
|
|
|
Stream_Read_UINT16(s, length);
|
|
|
|
Stream_Read_UINT32(s, nego->selected_protocol);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
|
|
|
nego->state = NEGO_STATE_FINAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process Negotiation Failure from Connection Confirm message.
|
|
|
|
* @param nego
|
|
|
|
* @param s
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void nego_process_negotiation_failure(rdpNego* nego, wStream* s)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE flags;
|
|
|
|
UINT16 length;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 failureCode;
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2011-07-03 21:49:06 +04:00
|
|
|
DEBUG_NEGO("RDP_NEG_FAILURE");
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, flags);
|
|
|
|
Stream_Read_UINT16(s, length);
|
|
|
|
Stream_Read_UINT32(s, failureCode);
|
2011-07-01 02:48:48 +04:00
|
|
|
|
|
|
|
switch (failureCode)
|
|
|
|
{
|
|
|
|
case SSL_REQUIRED_BY_SERVER:
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Error: SSL_REQUIRED_BY_SERVER");
|
2011-07-01 02:48:48 +04:00
|
|
|
break;
|
2013-04-13 02:03:56 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
case SSL_NOT_ALLOWED_BY_SERVER:
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Error: SSL_NOT_ALLOWED_BY_SERVER");
|
2013-09-19 03:16:48 +04:00
|
|
|
nego->sendNegoData = TRUE;
|
2011-07-01 02:48:48 +04:00
|
|
|
break;
|
2013-04-13 02:03:56 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
case SSL_CERT_NOT_ON_SERVER:
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Error: SSL_CERT_NOT_ON_SERVER");
|
2013-04-13 02:03:56 +04:00
|
|
|
nego->sendNegoData = TRUE;
|
2011-07-01 02:48:48 +04:00
|
|
|
break;
|
2013-04-13 02:03:56 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
case INCONSISTENT_FLAGS:
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Error: INCONSISTENT_FLAGS");
|
2011-07-01 02:48:48 +04:00
|
|
|
break;
|
2013-04-13 02:03:56 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
case HYBRID_REQUIRED_BY_SERVER:
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Error: HYBRID_REQUIRED_BY_SERVER");
|
2011-07-01 02:48:48 +04:00
|
|
|
break;
|
2013-04-13 02:03:56 +04:00
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
default:
|
2011-07-03 20:42:35 +04:00
|
|
|
DEBUG_NEGO("Error: Unknown protocol security error %d", failureCode);
|
2011-07-01 02:48:48 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-07-03 21:49:06 +04:00
|
|
|
|
|
|
|
nego->state = NEGO_STATE_FAIL;
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
/**
|
|
|
|
* Send RDP Negotiation Response (RDP_NEG_RSP).\n
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL nego_send_negotiation_response(rdpNego* nego)
|
2011-08-18 19:15:28 +04:00
|
|
|
{
|
|
|
|
int length;
|
2013-05-15 22:42:37 +04:00
|
|
|
int bm, em;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL status;
|
2013-05-15 22:42:37 +04:00
|
|
|
wStream* s;
|
2013-10-22 07:33:25 +04:00
|
|
|
BYTE flags;
|
2012-06-20 04:10:49 +04:00
|
|
|
rdpSettings* settings;
|
2012-01-25 20:08:10 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
status = TRUE;
|
2012-01-25 20:08:10 +04:00
|
|
|
settings = nego->transport->settings;
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2013-05-15 21:17:29 +04:00
|
|
|
s = Stream_New(NULL, 512);
|
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
length = TPDU_CONNECTION_CONFIRM_LENGTH;
|
2013-05-15 22:42:37 +04:00
|
|
|
bm = Stream_GetPosition(s);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, length);
|
2011-08-18 19:15:28 +04:00
|
|
|
|
|
|
|
if (nego->selected_protocol > PROTOCOL_RDP)
|
|
|
|
{
|
2013-10-22 07:33:25 +04:00
|
|
|
flags = EXTENDED_CLIENT_DATA_SUPPORTED;
|
|
|
|
|
|
|
|
if (settings->SupportGraphicsPipeline)
|
|
|
|
flags |= DYNVC_GFX_PROTOCOL_SUPPORTED;
|
|
|
|
|
2011-08-18 19:15:28 +04:00
|
|
|
/* RDP_NEG_DATA must be present for TLS and NLA */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, TYPE_RDP_NEG_RSP);
|
2013-10-22 07:33:25 +04:00
|
|
|
Stream_Write_UINT8(s, flags); /* flags */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, 8); /* RDP_NEG_DATA length (8) */
|
|
|
|
Stream_Write_UINT32(s, nego->selected_protocol); /* selectedProtocol */
|
2011-08-18 19:15:28 +04:00
|
|
|
length += 8;
|
|
|
|
}
|
2012-11-07 20:02:46 +04:00
|
|
|
else if (!settings->RdpSecurity)
|
2012-01-25 20:08:10 +04:00
|
|
|
{
|
2013-10-22 07:33:25 +04:00
|
|
|
flags = 0;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, TYPE_RDP_NEG_FAILURE);
|
2013-10-22 07:33:25 +04:00
|
|
|
Stream_Write_UINT8(s, flags); /* flags */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, 8); /* RDP_NEG_DATA length (8) */
|
2012-01-25 20:08:10 +04:00
|
|
|
/*
|
|
|
|
* TODO: Check for other possibilities,
|
|
|
|
* like SSL_NOT_ALLOWED_BY_SERVER.
|
|
|
|
*/
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "nego_send_negotiation_response: client supports only Standard RDP Security\n");
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, SSL_REQUIRED_BY_SERVER);
|
2012-01-25 20:08:10 +04:00
|
|
|
length += 8;
|
2012-10-09 10:31:28 +04:00
|
|
|
status = FALSE;
|
2012-01-25 20:08:10 +04:00
|
|
|
}
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2013-05-15 22:42:37 +04:00
|
|
|
em = Stream_GetPosition(s);
|
|
|
|
Stream_SetPosition(s, bm);
|
2011-08-18 19:15:28 +04:00
|
|
|
tpkt_write_header(s, length);
|
|
|
|
tpdu_write_connection_confirm(s, length - 5);
|
2013-05-15 22:42:37 +04:00
|
|
|
Stream_SetPosition(s, em);
|
2011-08-18 19:15:28 +04:00
|
|
|
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_SealLength(s);
|
|
|
|
|
2011-09-16 19:16:16 +04:00
|
|
|
if (transport_write(nego->transport, s) < 0)
|
2013-09-06 13:07:33 +04:00
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-09-06 13:07:33 +04:00
|
|
|
}
|
2011-08-19 13:39:37 +04:00
|
|
|
|
2013-05-15 21:17:29 +04:00
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
|
2012-06-20 04:10:49 +04:00
|
|
|
if (status)
|
2012-01-25 20:08:10 +04:00
|
|
|
{
|
|
|
|
/* update settings with negotiated protocol security */
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->RequestedProtocols = nego->requested_protocols;
|
|
|
|
settings->SelectedProtocol = nego->selected_protocol;
|
2011-09-16 19:16:16 +04:00
|
|
|
|
2012-11-07 20:02:46 +04:00
|
|
|
if (settings->SelectedProtocol == PROTOCOL_RDP)
|
2012-01-25 20:08:10 +04:00
|
|
|
{
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->TlsSecurity = FALSE;
|
|
|
|
settings->NlaSecurity = FALSE;
|
|
|
|
settings->RdpSecurity = TRUE;
|
2012-06-20 04:10:49 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (!settings->LocalConnection)
|
2012-05-22 19:21:09 +04:00
|
|
|
{
|
2012-11-08 08:29:24 +04:00
|
|
|
settings->DisableEncryption = TRUE;
|
|
|
|
settings->EncryptionMethods = ENCRYPTION_METHOD_40BIT | ENCRYPTION_METHOD_128BIT | ENCRYPTION_METHOD_FIPS;
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->EncryptionLevel = ENCRYPTION_LEVEL_CLIENT_COMPATIBLE;
|
2012-05-22 19:21:09 +04:00
|
|
|
}
|
2012-06-20 04:10:49 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (settings->DisableEncryption && settings->RdpServerRsaKey == NULL && settings->RdpKeyFile == NULL)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-01-25 20:08:10 +04:00
|
|
|
}
|
2012-11-07 20:02:46 +04:00
|
|
|
else if (settings->SelectedProtocol == PROTOCOL_TLS)
|
2012-01-25 20:08:10 +04:00
|
|
|
{
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->TlsSecurity = TRUE;
|
|
|
|
settings->NlaSecurity = FALSE;
|
|
|
|
settings->RdpSecurity = FALSE;
|
2012-11-08 08:29:24 +04:00
|
|
|
settings->DisableEncryption = FALSE;
|
|
|
|
settings->EncryptionMethods = ENCRYPTION_METHOD_NONE;
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->EncryptionLevel = ENCRYPTION_LEVEL_NONE;
|
2012-01-25 20:08:10 +04:00
|
|
|
}
|
2012-11-07 20:02:46 +04:00
|
|
|
else if (settings->SelectedProtocol == PROTOCOL_NLA)
|
2012-01-25 20:08:10 +04:00
|
|
|
{
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->TlsSecurity = TRUE;
|
|
|
|
settings->NlaSecurity = TRUE;
|
|
|
|
settings->RdpSecurity = FALSE;
|
2012-11-08 08:29:24 +04:00
|
|
|
settings->DisableEncryption = FALSE;
|
|
|
|
settings->EncryptionMethods = ENCRYPTION_METHOD_NONE;
|
2012-11-07 20:02:46 +04:00
|
|
|
settings->EncryptionLevel = ENCRYPTION_LEVEL_NONE;
|
2012-01-25 20:08:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 04:10:49 +04:00
|
|
|
return status;
|
2011-08-18 19:15:28 +04:00
|
|
|
}
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
/**
|
|
|
|
* Initialize NEGO state machine.
|
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_init(rdpNego* nego)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
|
|
|
nego->state = NEGO_STATE_INITIAL;
|
|
|
|
nego->requested_protocols = PROTOCOL_RDP;
|
2012-12-22 00:49:02 +04:00
|
|
|
nego->transport->ReceiveCallback = nego_recv;
|
|
|
|
nego->transport->ReceiveExtra = (void*) nego;
|
2012-10-26 02:38:51 +04:00
|
|
|
nego->cookie_max_length = DEFAULT_COOKIE_MAX_LENGTH;
|
2013-09-19 03:16:48 +04:00
|
|
|
nego->sendNegoData = FALSE;
|
2011-12-18 21:10:56 +04:00
|
|
|
nego->flags = 0;
|
2011-07-03 20:42:35 +04:00
|
|
|
}
|
|
|
|
|
2011-07-01 02:48:48 +04:00
|
|
|
/**
|
|
|
|
* Create a new NEGO state machine instance.
|
2011-07-03 20:42:35 +04:00
|
|
|
* @param transport
|
2011-07-01 02:48:48 +04:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2013-11-01 22:13:09 +04:00
|
|
|
rdpNego* nego_new(rdpTransport* transport)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
rdpNego* nego = (rdpNego*) malloc(sizeof(rdpNego));
|
2011-07-01 02:48:48 +04:00
|
|
|
|
2013-11-04 01:25:56 +04:00
|
|
|
if (nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2012-11-01 04:38:48 +04:00
|
|
|
ZeroMemory(nego, sizeof(rdpNego));
|
2013-11-04 01:25:56 +04:00
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
nego->transport = transport;
|
2011-07-01 02:48:48 +04:00
|
|
|
nego_init(nego);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nego;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-03 20:42:35 +04:00
|
|
|
* Free NEGO state machine.
|
2011-07-01 02:48:48 +04:00
|
|
|
* @param nego
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_free(rdpNego* nego)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2013-11-04 01:25:56 +04:00
|
|
|
free(nego->RoutingToken);
|
2012-12-12 09:49:15 +04:00
|
|
|
free(nego->cookie);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(nego);
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-03 20:42:35 +04:00
|
|
|
* Set target hostname and port.
|
2011-07-01 02:48:48 +04:00
|
|
|
* @param nego
|
2011-07-03 20:42:35 +04:00
|
|
|
* @param hostname
|
|
|
|
* @param port
|
2011-07-01 02:48:48 +04:00
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_set_target(rdpNego* nego, char* hostname, int port)
|
2011-07-01 02:48:48 +04:00
|
|
|
{
|
2011-07-03 20:42:35 +04:00
|
|
|
nego->hostname = hostname;
|
|
|
|
nego->port = port;
|
|
|
|
}
|
|
|
|
|
2012-07-25 14:29:49 +04:00
|
|
|
/**
|
|
|
|
* Enable security layer negotiation.
|
|
|
|
* @param nego pointer to the negotiation structure
|
2012-10-09 10:31:28 +04:00
|
|
|
* @param enable_rdp whether to enable security layer negotiation (TRUE for enabled, FALSE for disabled)
|
2012-07-25 14:29:49 +04:00
|
|
|
*/
|
|
|
|
|
2013-01-10 20:19:57 +04:00
|
|
|
void nego_set_negotiation_enabled(rdpNego* nego, BOOL NegotiateSecurityLayer)
|
2012-07-25 14:29:49 +04:00
|
|
|
{
|
2013-01-10 20:19:57 +04:00
|
|
|
DEBUG_NEGO("Enabling security layer negotiation: %s", NegotiateSecurityLayer ? "TRUE" : "FALSE");
|
|
|
|
nego->NegotiateSecurityLayer = NegotiateSecurityLayer;
|
2012-07-25 14:29:49 +04:00
|
|
|
}
|
|
|
|
|
2013-11-06 10:51:55 +04:00
|
|
|
/**
|
|
|
|
* Enable restricted admin mode.
|
|
|
|
* @param nego pointer to the negotiation structure
|
|
|
|
* @param enable_restricted whether to enable security layer negotiation (TRUE for enabled, FALSE for disabled)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nego_set_restricted_admin_mode_required(rdpNego* nego, BOOL RestrictedAdminModeRequired)
|
|
|
|
{
|
|
|
|
DEBUG_NEGO("Enabling restricted admin mode: %s", RestrictedAdminModeRequired ? "TRUE" : "FALSE");
|
|
|
|
nego->RestrictedAdminModeRequired = RestrictedAdminModeRequired;
|
|
|
|
}
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
/**
|
2011-07-31 07:51:26 +04:00
|
|
|
* Enable RDP security protocol.
|
|
|
|
* @param nego pointer to the negotiation structure
|
2012-10-09 10:31:28 +04:00
|
|
|
* @param enable_rdp whether to enable normal RDP protocol (TRUE for enabled, FALSE for disabled)
|
2011-07-31 07:51:26 +04:00
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
void nego_enable_rdp(rdpNego* nego, BOOL enable_rdp)
|
2011-07-31 07:51:26 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
DEBUG_NEGO("Enabling RDP security: %s", enable_rdp ? "TRUE" : "FALSE");
|
2011-07-31 07:51:26 +04:00
|
|
|
nego->enabled_protocols[PROTOCOL_RDP] = enable_rdp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable TLS security protocol.
|
|
|
|
* @param nego pointer to the negotiation structure
|
2012-10-09 10:31:28 +04:00
|
|
|
* @param enable_tls whether to enable TLS + RDP protocol (TRUE for enabled, FALSE for disabled)
|
2011-07-31 07:51:26 +04:00
|
|
|
*/
|
2013-11-06 10:51:55 +04:00
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
void nego_enable_tls(rdpNego* nego, BOOL enable_tls)
|
2011-07-31 07:51:26 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
DEBUG_NEGO("Enabling TLS security: %s", enable_tls ? "TRUE" : "FALSE");
|
2011-07-31 07:51:26 +04:00
|
|
|
nego->enabled_protocols[PROTOCOL_TLS] = enable_tls;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable NLA security protocol.
|
|
|
|
* @param nego pointer to the negotiation structure
|
2012-10-09 10:31:28 +04:00
|
|
|
* @param enable_nla whether to enable network level authentication protocol (TRUE for enabled, FALSE for disabled)
|
2011-07-03 20:42:35 +04:00
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
void nego_enable_nla(rdpNego* nego, BOOL enable_nla)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
DEBUG_NEGO("Enabling NLA security: %s", enable_nla ? "TRUE" : "FALSE");
|
2011-07-31 07:51:26 +04:00
|
|
|
nego->enabled_protocols[PROTOCOL_NLA] = enable_nla;
|
2011-07-03 20:42:35 +04:00
|
|
|
}
|
|
|
|
|
2012-11-01 04:38:48 +04:00
|
|
|
/**
|
|
|
|
* Enable NLA extended security protocol.
|
|
|
|
* @param nego pointer to the negotiation structure
|
|
|
|
* @param enable_ext whether to enable network level authentication extended protocol (TRUE for enabled, FALSE for disabled)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nego_enable_ext(rdpNego* nego, BOOL enable_ext)
|
|
|
|
{
|
|
|
|
DEBUG_NEGO("Enabling NLA extended security: %s", enable_ext ? "TRUE" : "FALSE");
|
|
|
|
nego->enabled_protocols[PROTOCOL_EXT] = enable_ext;
|
|
|
|
}
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
/**
|
|
|
|
* Set routing token.
|
|
|
|
* @param nego
|
2012-09-24 12:40:32 +04:00
|
|
|
* @param RoutingToken
|
|
|
|
* @param RoutingTokenLength
|
2011-07-03 20:42:35 +04:00
|
|
|
*/
|
|
|
|
|
2012-09-24 12:40:32 +04:00
|
|
|
void nego_set_routing_token(rdpNego* nego, BYTE* RoutingToken, DWORD RoutingTokenLength)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
2013-11-04 01:25:56 +04:00
|
|
|
free(nego->RoutingToken);
|
2012-09-24 12:40:32 +04:00
|
|
|
nego->RoutingTokenLength = RoutingTokenLength;
|
2013-11-04 01:25:56 +04:00
|
|
|
nego->RoutingToken = (BYTE*) malloc(nego->RoutingTokenLength);
|
|
|
|
CopyMemory(nego->RoutingToken, RoutingToken, nego->RoutingTokenLength);
|
2011-07-03 20:42:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set cookie.
|
|
|
|
* @param nego
|
|
|
|
* @param cookie
|
|
|
|
*/
|
|
|
|
|
2011-07-07 21:37:48 +04:00
|
|
|
void nego_set_cookie(rdpNego* nego, char* cookie)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
2012-12-12 09:49:15 +04:00
|
|
|
if (nego->cookie)
|
|
|
|
free(nego->cookie);
|
|
|
|
|
|
|
|
nego->cookie = _strdup(cookie);
|
2011-07-01 02:48:48 +04:00
|
|
|
}
|
2012-07-25 20:46:43 +04:00
|
|
|
|
2012-10-26 02:38:51 +04:00
|
|
|
/**
|
|
|
|
* Set cookie maximum length
|
|
|
|
* @param nego
|
|
|
|
* @param cookie_max_length
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nego_set_cookie_max_length(rdpNego* nego, UINT32 cookie_max_length)
|
|
|
|
{
|
|
|
|
nego->cookie_max_length = cookie_max_length;
|
|
|
|
}
|
|
|
|
|
2012-07-25 20:46:43 +04:00
|
|
|
/**
|
|
|
|
* Enable / disable preconnection PDU.
|
|
|
|
* @param nego
|
|
|
|
* @param send_pcpdu
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
void nego_set_send_preconnection_pdu(rdpNego* nego, BOOL send_pcpdu)
|
2012-07-25 20:46:43 +04:00
|
|
|
{
|
|
|
|
nego->send_preconnection_pdu = send_pcpdu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set preconnection id.
|
|
|
|
* @param nego
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
nego->preconnection_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set preconnection blob.
|
|
|
|
* @param nego
|
|
|
|
* @param blob
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nego_set_preconnection_blob(rdpNego* nego, char* blob)
|
|
|
|
{
|
|
|
|
nego->preconnection_blob = blob;
|
|
|
|
}
|