2011-07-10 09:48:10 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Connection Sequence
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "connection.h"
|
2011-07-27 03:14:11 +04:00
|
|
|
#include "info.h"
|
2011-07-10 09:48:10 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Connection Sequence
|
|
|
|
* client server
|
|
|
|
* | |
|
|
|
|
* |-----------------------X.224 Connection Request PDU--------------------->|
|
|
|
|
* |<----------------------X.224 Connection Confirm PDU----------------------|
|
|
|
|
* |-------MCS Connect-Initial PDU with GCC Conference Create Request------->|
|
|
|
|
* |<-----MCS Connect-Response PDU with GCC Conference Create Response-------|
|
|
|
|
* |------------------------MCS Erect Domain Request PDU-------------------->|
|
|
|
|
* |------------------------MCS Attach User Request PDU--------------------->|
|
|
|
|
* |<-----------------------MCS Attach User Confirm PDU----------------------|
|
|
|
|
* |------------------------MCS Channel Join Request PDU-------------------->|
|
|
|
|
* |<-----------------------MCS Channel Join Confirm PDU---------------------|
|
|
|
|
* |----------------------------Security Exchange PDU----------------------->|
|
|
|
|
* |-------------------------------Client Info PDU-------------------------->|
|
2011-07-11 00:42:37 +04:00
|
|
|
* |<---------------------License Error PDU - Valid Client-------------------|
|
|
|
|
* |<-----------------------------Demand Active PDU--------------------------|
|
|
|
|
* |------------------------------Confirm Active PDU------------------------>|
|
|
|
|
* |-------------------------------Synchronize PDU-------------------------->|
|
|
|
|
* |---------------------------Control PDU - Cooperate---------------------->|
|
|
|
|
* |------------------------Control PDU - Request Control------------------->|
|
|
|
|
* |--------------------------Persistent Key List PDU(s)-------------------->|
|
|
|
|
* |--------------------------------Font List PDU--------------------------->|
|
|
|
|
* |<------------------------------Synchronize PDU---------------------------|
|
|
|
|
* |<--------------------------Control PDU - Cooperate-----------------------|
|
|
|
|
* |<-----------------------Control PDU - Granted Control--------------------|
|
|
|
|
* |<-------------------------------Font Map PDU-----------------------------|
|
2011-07-10 09:48:10 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-07-11 23:58:39 +04:00
|
|
|
/**
|
|
|
|
* Establish RDP Connection.\n
|
|
|
|
* @msdn{cc240452}
|
2011-07-12 02:46:36 +04:00
|
|
|
* @param rdp RDP module
|
2011-07-11 23:58:39 +04:00
|
|
|
*/
|
|
|
|
|
2011-07-18 07:16:31 +04:00
|
|
|
boolean rdp_client_connect(rdpRdp* rdp)
|
2011-07-10 09:48:10 +04:00
|
|
|
{
|
2011-08-13 12:37:03 +04:00
|
|
|
boolean ret;
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
rdp->settings->autologon = 1;
|
2011-07-10 09:48:10 +04:00
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
nego_init(rdp->nego);
|
2011-08-18 20:17:13 +04:00
|
|
|
nego_set_target(rdp->nego, rdp->settings->hostname, rdp->settings->port);
|
2011-07-12 02:46:36 +04:00
|
|
|
nego_set_cookie(rdp->nego, rdp->settings->username);
|
2011-07-31 07:51:26 +04:00
|
|
|
nego_enable_rdp(rdp->nego, rdp->settings->rdp_security);
|
|
|
|
nego_enable_nla(rdp->nego, rdp->settings->nla_security);
|
|
|
|
nego_enable_tls(rdp->nego, rdp->settings->tls_security);
|
2011-07-10 20:10:24 +04:00
|
|
|
|
2011-07-18 10:34:28 +04:00
|
|
|
if (nego_connect(rdp->nego) != True)
|
2011-07-18 07:16:31 +04:00
|
|
|
{
|
|
|
|
printf("Error: protocol security negotiation failure\n");
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2011-08-13 12:37:03 +04:00
|
|
|
ret = False;
|
2011-07-18 07:16:31 +04:00
|
|
|
if (rdp->nego->selected_protocol & PROTOCOL_NLA)
|
2011-08-13 12:37:03 +04:00
|
|
|
ret = transport_connect_nla(rdp->transport);
|
2011-07-18 07:16:31 +04:00
|
|
|
else if (rdp->nego->selected_protocol & PROTOCOL_TLS)
|
2011-08-13 12:37:03 +04:00
|
|
|
ret = transport_connect_tls(rdp->transport);
|
2011-07-18 07:16:31 +04:00
|
|
|
else if (rdp->nego->selected_protocol & PROTOCOL_RDP)
|
2011-08-13 12:37:03 +04:00
|
|
|
ret = transport_connect_rdp(rdp->transport);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return False;
|
2011-07-10 09:48:10 +04:00
|
|
|
|
2011-07-18 10:34:28 +04:00
|
|
|
if (mcs_connect(rdp->mcs) != True)
|
|
|
|
{
|
|
|
|
printf("Error: Multipoint Connection Service (MCS) connection failure\n");
|
|
|
|
return False;
|
|
|
|
}
|
2011-07-10 09:48:10 +04:00
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
rdp_send_client_info(rdp);
|
2011-07-12 09:16:59 +04:00
|
|
|
|
2011-07-18 10:34:28 +04:00
|
|
|
if (license_connect(rdp->license) != True)
|
|
|
|
{
|
|
|
|
printf("Error: license connection sequence failure\n");
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2011-07-24 00:40:33 +04:00
|
|
|
rdp->licensed = True;
|
|
|
|
|
|
|
|
rdp_client_activate(rdp);
|
2011-08-01 08:43:53 +04:00
|
|
|
rdp_set_blocking_mode(rdp, False);
|
2011-07-24 00:40:33 +04:00
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2011-08-19 05:54:43 +04:00
|
|
|
boolean rdp_server_accept_nego(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
2011-08-19 09:35:29 +04:00
|
|
|
boolean ret;
|
|
|
|
|
|
|
|
transport_set_blocking_mode(rdp->transport, True);
|
|
|
|
|
2011-08-19 05:54:43 +04:00
|
|
|
if (!nego_recv_request(rdp->nego, s))
|
|
|
|
return False;
|
|
|
|
if (rdp->nego->requested_protocols == PROTOCOL_RDP)
|
|
|
|
{
|
|
|
|
printf("Standard RDP encryption is not supported.\n");
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Requested protocols:");
|
|
|
|
if ((rdp->nego->requested_protocols | PROTOCOL_TLS))
|
|
|
|
{
|
|
|
|
printf(" TLS");
|
|
|
|
if (rdp->settings->tls_security)
|
|
|
|
{
|
|
|
|
printf("(Y)");
|
|
|
|
rdp->nego->selected_protocol |= PROTOCOL_TLS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("(n)");
|
|
|
|
}
|
|
|
|
if ((rdp->nego->requested_protocols | PROTOCOL_NLA))
|
|
|
|
{
|
|
|
|
printf(" NLA");
|
|
|
|
if (rdp->settings->nla_security)
|
|
|
|
{
|
|
|
|
printf("(Y)");
|
|
|
|
rdp->nego->selected_protocol |= PROTOCOL_NLA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("(n)");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
nego_send_negotiation_response(rdp->nego);
|
|
|
|
|
2011-08-19 09:35:29 +04:00
|
|
|
ret = False;
|
|
|
|
if (rdp->nego->selected_protocol & PROTOCOL_NLA)
|
|
|
|
ret = transport_accept_nla(rdp->transport);
|
|
|
|
else if (rdp->nego->selected_protocol & PROTOCOL_TLS)
|
|
|
|
ret = transport_accept_tls(rdp->transport);
|
|
|
|
else if (rdp->nego->selected_protocol & PROTOCOL_RDP)
|
|
|
|
ret = transport_accept_rdp(rdp->transport);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return False;
|
|
|
|
|
|
|
|
transport_set_blocking_mode(rdp->transport, False);
|
|
|
|
|
2011-08-19 05:54:43 +04:00
|
|
|
rdp->state = CONNECTION_STATE_NEGO;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2011-08-19 13:39:37 +04:00
|
|
|
boolean rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
2011-08-19 14:11:33 +04:00
|
|
|
int i;
|
|
|
|
|
2011-08-19 13:39:37 +04:00
|
|
|
if (!mcs_read_connect_initial(rdp->mcs, s))
|
|
|
|
return False;
|
|
|
|
|
2011-08-19 14:11:33 +04:00
|
|
|
printf("Accepted client: %s\n", rdp->settings->client_hostname);
|
|
|
|
printf("Accepted channels:");
|
|
|
|
for (i = 0; i < rdp->settings->num_channels; i++)
|
|
|
|
{
|
|
|
|
printf(" %s", rdp->settings->channels[i].name);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2011-08-19 19:56:47 +04:00
|
|
|
if (!mcs_send_connect_response(rdp->mcs))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
rdp->state = CONNECTION_STATE_MCS_CONNECT;
|
|
|
|
|
2011-08-19 13:39:37 +04:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2011-08-19 22:03:48 +04:00
|
|
|
boolean rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
if (!mcs_read_erect_domain_request(rdp->mcs, s))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
rdp->state = CONNECTION_STATE_MCS_ERECT_DOMAIN;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
if (!mcs_read_attach_user_request(rdp->mcs, s))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
if (!mcs_send_attach_user_confirm(rdp->mcs))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
rdp->state = CONNECTION_STATE_MCS_ATTACH_USER;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2011-08-20 10:05:03 +04:00
|
|
|
boolean rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint16 channel_id;
|
|
|
|
boolean all_joined = True;
|
|
|
|
|
|
|
|
if (!mcs_read_channel_join_request(rdp->mcs, s, &channel_id))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
if (!mcs_send_channel_join_confirm(rdp->mcs, channel_id))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
if (channel_id == rdp->mcs->user_id)
|
|
|
|
rdp->mcs->user_channel_joined = True;
|
|
|
|
else if (channel_id == MCS_GLOBAL_CHANNEL_ID)
|
|
|
|
rdp->mcs->global_channel_joined = True;
|
|
|
|
|
|
|
|
for (i = 0; i < rdp->settings->num_channels; i++)
|
|
|
|
{
|
|
|
|
if (rdp->settings->channels[i].chan_id == channel_id)
|
|
|
|
rdp->settings->channels[i].joined = True;
|
|
|
|
|
|
|
|
if (!rdp->settings->channels[i].joined)
|
|
|
|
all_joined = False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdp->mcs->user_channel_joined && rdp->mcs->global_channel_joined && all_joined)
|
|
|
|
rdp->state = CONNECTION_STATE_CHANNEL_JOIN;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
boolean rdp_server_accept_client_info(rdpRdp* rdp, STREAM* s)
|
|
|
|
{
|
|
|
|
if (!rdp_read_client_info(rdp, s))
|
|
|
|
return False;
|
|
|
|
|
2011-08-20 17:41:40 +04:00
|
|
|
if (!license_send_valid_client_error_packet(rdp->license))
|
|
|
|
return False;
|
|
|
|
|
2011-08-20 19:09:46 +04:00
|
|
|
rdp->state = CONNECTION_STATE_LICENSE;
|
|
|
|
|
|
|
|
if (!rdp_send_demand_active(rdp))
|
|
|
|
return False;
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|