libfreerdp-core: establish TLS connection

This commit is contained in:
Marc-André Moreau 2011-07-03 19:27:02 -04:00
parent 5c21c8491d
commit 27bca27636
5 changed files with 60 additions and 14 deletions

View File

@ -44,17 +44,21 @@ int main(int argc, char* argv[])
hostname = (char*) xmalloc(strlen(argv[1]));
memcpy(hostname, argv[1], strlen(argv[1]));
hostname[strlen(argv[1])] = '\0';
username = (char*) xmalloc(strlen(argv[2]));
memcpy(username, argv[2], strlen(argv[2]));
username[strlen(argv[2])] = '\0';
printf("hostname: %s username: %s\n", hostname, username);
nego_init(nego);
nego_set_target(nego, hostname, 3389);
nego_set_protocols(nego, 1, 1, 1);
nego_set_protocols(nego, 1, 1, 0);
nego_set_cookie(nego, username);
nego_connect(nego);
transport_connect_tls(transport);
return 0;
}

View File

@ -213,10 +213,8 @@ int nego_recv(rdpTransport * transport, STREAM* s, void * extra)
break;
}
}
else
{
nego->state = NEGO_STATE_FINAL;
}
nego->state = NEGO_STATE_FINAL;
return 0;
}

View File

@ -68,7 +68,7 @@ tpdu_read_header(STREAM* s, uint8* code)
/* Class 0 (1 byte) */
stream_seek(s, 5);
if (code == X224_TPDU_DATA)
if (*code == X224_TPDU_DATA)
{
/* EOT (1 byte) */
stream_seek(s, 1);

View File

@ -46,10 +46,48 @@ transport_disconnect(rdpTransport * transport)
return transport->tcp->disconnect(transport->tcp);
}
int
transport_start_tls(rdpTransport * transport)
FRDP_BOOL
transport_connect_rdp(rdpTransport * transport)
{
return 0;
transport->state = TRANSPORT_STATE_RDP;
/* RDP encryption */
return True;
}
FRDP_BOOL
transport_connect_tls(rdpTransport * transport)
{
if (transport->tls == NULL)
transport->tls = tls_new();
transport->state = TRANSPORT_STATE_TLS;
transport->tls->sockfd = transport->tcp->sockfd;
if (tls_connect(transport->tls) != True)
return False;
return True;
}
FRDP_BOOL
transport_connect_nla(rdpTransport * transport)
{
if (transport->tls == NULL)
transport->tls = tls_new();
transport->state = TRANSPORT_STATE_NLA;
transport->tls->sockfd = transport->tcp->sockfd;
if (tls_connect(transport->tls) != True)
return False;
/* Network Level Authentication */
return True;
}
static int
@ -101,7 +139,7 @@ transport_send_tcp(rdpTransport * transport, STREAM * stream)
int
transport_send(rdpTransport * transport, STREAM * stream)
{
if (transport->tls)
if (transport->state == TRANSPORT_STATE_TLS)
return transport_send_tls(transport, stream);
else
return transport_send_tcp(transport, stream);
@ -144,7 +182,7 @@ transport_check_fds(rdpTransport * transport)
uint16 length;
STREAM * received;
if (transport->tls)
if (transport->state == TRANSPORT_STATE_TLS)
bytes = transport_recv_tls(transport);
else
bytes = transport_recv_tcp(transport);

View File

@ -21,6 +21,7 @@
#define __TRANSPORT_H
#include "tcp.h"
#include "tls.h"
#include <time.h>
#include <freerdp/types/base.h>
@ -30,6 +31,7 @@ enum _TRANSPORT_STATE
{
TRANSPORT_STATE_INITIAL,
TRANSPORT_STATE_NEGO,
TRANSPORT_STATE_RDP,
TRANSPORT_STATE_TLS,
TRANSPORT_STATE_NLA,
TRANSPORT_STATE_FINAL
@ -43,7 +45,7 @@ struct rdp_transport
{
TRANSPORT_STATE state;
struct rdp_tcp * tcp;
struct crypto_tls * tls;
struct rdp_tls * tls;
struct timespec ts;
STREAM * recv_buffer;
PacketReceivedCallback recv_callback;
@ -58,8 +60,12 @@ FRDP_BOOL
transport_connect(rdpTransport * transport, const char * server, int port);
FRDP_BOOL
transport_disconnect(rdpTransport * transport);
int
transport_start_tls(rdpTransport * transport);
FRDP_BOOL
transport_connect_rdp(rdpTransport * transport);
FRDP_BOOL
transport_connect_tls(rdpTransport * transport);
FRDP_BOOL
transport_connect_nla(rdpTransport * transport);
int
transport_send(rdpTransport * transport, STREAM * stream);
int