/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Protocol services - ISO layer
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
Copyright 2005-2011 Peter Astrand <astrand@cendio.se> for Cendio AB
Copyright 2012 Henrik Andersson <hean01@cendio.se> for Cendio AB
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the General Public License version 2 (GPLv2) at this time for any software where
* a choice of GPL license versions is made available with the language indicating
* that GPLv2 or any later version may be used, or where a choice of which version
* of the GPL is applied is otherwise unspecified.
*/
#include "rdesktop.h"
extern RD_BOOL g_encryption;
extern RD_BOOL g_encryption_initial;
extern RDP_VERSION g_rdp_version;
extern RD_BOOL g_use_password_as_pin;
extern char *g_sc_csp_name;
extern char *g_sc_reader_name;
extern char *g_sc_card_name;
extern char *g_sc_container_name;
/* Send a self-contained ISO PDU */
static void
{
STREAM s;
s = tcp_init(11);
out_uint8(s, 0); /* reserved */
out_uint16(s, 0); /* dst_ref */
out_uint16(s, 0); /* src_ref */
out_uint8(s, 0); /* class */
s_mark_end(s);
tcp_send(s);
}
static void
{
STREAM s;
length += 8;
out_uint8(s, 0); /* reserved */
out_uint8(s, ISO_PDU_CR);
out_uint16(s, 0); /* dst_ref */
out_uint16(s, 0); /* src_ref */
out_uint8(s, 0); /* class */
out_uint8(s, 0x0a);
{
/* optional rdp protocol negotiation request for RDPv5 */
out_uint8(s, RDP_NEG_REQ);
out_uint8(s, 0);
out_uint16(s, 8);
out_uint32(s, neg_proto);
}
s_mark_end(s);
tcp_send(s);
}
/* Receive a message on the ISO layer, return code */
static STREAM
{
STREAM s;
if (s == NULL)
return NULL;
if (version == 3)
{
in_uint16_be(s, length);
}
else
{
if (length & 0x80)
{
length &= ~0x80;
}
}
if (length < 4)
{
error("Bad packet header\n");
return NULL;
}
if (s == NULL)
return NULL;
if (version != 3)
return s;
if (*code == ISO_PDU_DT)
{
return s;
}
return s;
}
/* Initialise ISO transport data packet */
{
STREAM s;
return s;
}
/* Send an ISO data PDU */
void
{
s_pop_layer(s, iso_hdr);
out_uint8(s, 0); /* reserved */
out_uint16_be(s, length);
tcp_send(s);
}
/* Receive ISO transport data packet */
{
STREAM s;
if (s == NULL)
return NULL;
if (*rdpver != 3)
return s;
if (code != ISO_PDU_DT)
{
return NULL;
}
return s;
}
/* Establish a connection up to the ISO layer */
{
STREAM s;
#ifdef WITH_CREDSSP
if (!g_use_password_as_pin)
else
warning("Disables CredSSP due to missing smartcard information for SSO.\n");
#endif
code = 0;
if (!tcp_connect(server))
return False;
if (s == NULL)
return False;
if (code != ISO_PDU_CC)
{
return False;
}
{
/* handle RDP_NEG_REQ response */
if (type == RDP_NEG_FAILURE)
{
switch (data)
{
reason = "SSL with user authentication required by server";
break;
reason = "SSL not allowed by server";
break;
case SSL_CERT_NOT_ON_SERVER:
reason = "no valid authentication certificate on server";
break;
case INCONSISTENT_FLAGS:
reason = "inconsistent negotiation flags";
break;
case SSL_REQUIRED_BY_SERVER:
reason = "SSL required by server";
break;
reason = "CredSSP required by server";
break;
default:
reason = "unknown reason";
}
if (retry_without_neg)
{
"Failed to negotiate protocol, retrying with plain RDP.\n");
goto retry;
}
return False;
}
if (type != RDP_NEG_RSP)
{
return False;
}
/* handle negotiation response */
if (data == PROTOCOL_SSL)
{
if (!tcp_tls_connect())
{
/* failed to connect using cssp, let retry with plain TLS */
goto retry;
}
/* do not use encryption when using TLS */
}
#ifdef WITH_CREDSSP
else if (data == PROTOCOL_HYBRID)
{
{
/* failed to connect using cssp, let retry with plain TLS */
goto retry;
}
/* do not use encryption when using TLS */
}
#endif
else if (data == PROTOCOL_RDP)
{
}
else if (data != PROTOCOL_RDP)
{
error("Unexpected protocol in negotiation response, got data = 0x%x.\n",
data);
return False;
}
}
return True;
}
/* Disconnect from the ISO layer */
void
iso_disconnect(void)
{
}
/* reset the state to support reconnecting */
void
iso_reset_state(void)
{
}