Skip to content

Commit

Permalink
libfreerdp-core: started network abstraction layer, started decouplin…
Browse files Browse the repository at this point in the history
…g secure.c from the rest
  • Loading branch information
awakecoding committed Jun 29, 2011
1 parent 7c3facc commit 2b95558
Show file tree
Hide file tree
Showing 22 changed files with 527 additions and 353 deletions.
Empty file added dbg.txt
Empty file.
1 change: 1 addition & 0 deletions libfreerdp-core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ libfreerdp_core_la_SOURCES = \
rail.c rail.h \
rdp.c rdp.h \
secure.c secure.h \
network.c network.h \
crypto.h \
tcp.c tcp.h \
nego.c nego.h \
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp-core/asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ber_parse_header(rdpMcs * mcs, STREAM s, int tagval, int *length)

if (tag != tagval)
{
ui_error(mcs->sec->rdp->inst, "expected tag %d, got %d\n", tagval, tag);
ui_error(mcs->net->rdp->inst, "expected tag %d, got %d\n", tagval, tag);
return False;
}

Expand Down
10 changes: 5 additions & 5 deletions libfreerdp-core/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ vchan_send(rdpChannels * chan, int mcs_id, char * data, int total_length)
rdpSet * settings;
struct rdp_chan * channel;

settings = chan->mcs->sec->rdp->settings;
settings = chan->mcs->net->rdp->settings;
chan_index = (mcs_id - MCS_GLOBAL_CHANNEL) - 1;
if ((chan_index < 0) || (chan_index >= settings->num_channels))
{
ui_error(chan->mcs->sec->rdp->inst, "error\n");
ui_error(chan->mcs->net->rdp->inst, "error\n");
return 0;
}
channel = &(settings->channels[chan_index]);
Expand All @@ -61,12 +61,12 @@ vchan_send(rdpChannels * chan, int mcs_id, char * data, int total_length)
{
chan_flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
}
s = sec_init(chan->mcs->sec, sec_flags, length + 8);
s = sec_init(chan->mcs->net->sec, sec_flags, length + 8);
out_uint32_le(s, total_length);
out_uint32_le(s, chan_flags);
out_uint8p(s, data + sent, length);
s_mark_end(s);
sec_send_to_channel(chan->mcs->sec, s, sec_flags, mcs_id);
sec_send_to_channel(chan->mcs->net->sec, s, sec_flags, mcs_id);
sent += length;
chan_flags = 0;
}
Expand All @@ -86,7 +86,7 @@ vchan_process(rdpChannels * chan, STREAM s, int mcs_id)
length = (int) (s->end - s->p);
data = (char *) (s->p);
s->p += length;
ui_channel_data(chan->mcs->sec->rdp->inst, mcs_id, data, length, flags, total_length);
ui_channel_data(chan->mcs->net->sec->rdp->inst, mcs_id, data, length, flags, total_length);
}

rdpChannels *
Expand Down
1 change: 1 addition & 0 deletions libfreerdp-core/chan.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define __CHAN_H

#include "mcs.h"
#include "network.h"

struct rdp_channels
{
Expand Down
12 changes: 6 additions & 6 deletions libfreerdp-core/credssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ asn1_write(const void *buffer, size_t size, void *fd)
void credssp_ntlmssp_init(rdpCredssp *credssp)
{
NTLMSSP *ntlmssp = credssp->ntlmssp;
rdpSet *settings = credssp->sec->rdp->settings;
rdpSet *settings = credssp->net->rdp->settings;

ntlmssp_set_password(ntlmssp, settings->password);
ntlmssp_set_username(ntlmssp, settings->username);
Expand Down Expand Up @@ -92,7 +92,7 @@ int credssp_get_public_key(rdpCredssp *credssp)
CryptoCert cert;
int ret;

cert = tls_get_certificate(credssp->sec->tls);
cert = tls_get_certificate(credssp->net->tls);
if (cert == NULL)
{
printf("credssp_get_public_key: tls_get_certificate failed to return the server certificate.\n");
Expand Down Expand Up @@ -396,7 +396,7 @@ void credssp_send(rdpCredssp *credssp, DATABLOB *negoToken, DATABLOB *pubKeyAuth

if (enc_rval.encoded != -1)
{
tls_write(credssp->sec->tls, buffer, size);
tls_write(credssp->net->tls, buffer, size);
}

asn_DEF_TSRequest.free_struct(&asn_DEF_TSRequest, ts_request, 0);
Expand All @@ -422,7 +422,7 @@ int credssp_recv(rdpCredssp *credssp, DATABLOB *negoToken, DATABLOB *pubKeyAuth,
TSRequest_t *ts_request = 0;

recv_buffer = xmalloc(size);
bytes_read = tls_read(credssp->sec->tls, recv_buffer, size);
bytes_read = tls_read(credssp->net->tls, recv_buffer, size);

if (bytes_read < 0)
return -1;
Expand Down Expand Up @@ -503,15 +503,15 @@ void credssp_current_time(uint8* timestamp)
*/

rdpCredssp *
credssp_new(struct rdp_sec * sec)
credssp_new(struct rdp_network * net)
{
rdpCredssp * self;

self = (rdpCredssp *) xmalloc(sizeof(rdpCredssp));
if (self != NULL)
{
memset(self, 0, sizeof(rdpCredssp));
self->sec = sec;
self->net = net;
self->send_seq_num = 0;
self->ntlmssp = ntlmssp_new();
}
Expand Down
8 changes: 4 additions & 4 deletions libfreerdp-core/credssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef __CREDSSP_H
#define __CREDSSP_H

#include "secure.h"
#include "network.h"
#include "ntlmssp.h"

struct rdp_credssp
Expand All @@ -33,7 +33,7 @@ struct rdp_credssp
DATABLOB ts_credentials;
CryptoRc4 rc4_seal_state;
struct _NTLMSSP *ntlmssp;
struct rdp_sec * sec;
struct rdp_network * net;
};
typedef struct rdp_credssp rdpCredssp;

Expand All @@ -50,7 +50,7 @@ void credssp_encode_ts_credentials(rdpCredssp *credssp);
void credssp_current_time(uint8* timestamp);
void credssp_rc4k(uint8* key, int length, uint8* plaintext, uint8* ciphertext);

rdpCredssp* credssp_new(rdpSec *sec);
rdpCredssp* credssp_new(struct rdp_network * net);
void credssp_free(rdpCredssp *credssp);

#endif // __CREDSSP_H
#endif /* __CREDSSP_H */
10 changes: 5 additions & 5 deletions libfreerdp-core/freerdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ l_rdp_get_fds(rdpInst * inst, void ** read_fds, int * read_count,

rdp = RDP_FROM_INST(inst);
#ifdef _WIN32
read_fds[*read_count] = (void *) (rdp->sec->mcs->iso->tcp->wsa_event);
read_fds[*read_count] = (void *) (rdp->net->tcp->wsa_event);
#else
read_fds[*read_count] = (void *)(long) (rdp->sec->mcs->iso->tcp->sock);
read_fds[*read_count] = (void *)(long) (rdp->net->tcp->sock);
#endif
(*read_count)++;
return 0;
Expand All @@ -468,10 +468,10 @@ l_rdp_check_fds(rdpInst * inst)

rdp = RDP_FROM_INST(inst);
#ifdef _WIN32
WSAResetEvent(rdp->sec->mcs->iso->tcp->wsa_event);
WSAResetEvent(rdp->net->tcp->wsa_event);
#endif
rv = 0;
if (tcp_can_recv(rdp->sec->mcs->iso->tcp->sock, 0))
if (tcp_can_recv(rdp->net->tcp->sock, 0))
{
if (!rdp_loop(rdp, &deactivated))
{
Expand Down Expand Up @@ -532,7 +532,7 @@ l_rdp_channel_data(rdpInst * inst, int chan_id, char * data, int data_size)
rdpChannels * chan;

rdp = RDP_FROM_INST(inst);
chan = rdp->sec->mcs->chan;
chan = rdp->net->mcs->chan;
return vchan_send(chan, chan_id, data, data_size);
}

Expand Down
44 changes: 26 additions & 18 deletions libfreerdp-core/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ x224_send_dst_src_class(rdpIso * iso, uint8 code)
out_uint8(s, 0); /* class */

s_mark_end(s);
tcp_send(iso->tcp, s);
network_send(iso->net, s);
}

/* Output and send X.224 Connection Request TPDU with routing for username */
Expand All @@ -93,9 +93,9 @@ x224_send_connection_request(rdpIso * iso)

cookie_length = strlen(iso->cookie);

if (iso->mcs->sec->rdp->redirect_routingtoken)
if (iso->net->rdp->redirect_routingtoken)
/* routingToken */
length += iso->mcs->sec->rdp->redirect_routingtoken_len;
length += iso->net->rdp->redirect_routingtoken_len;
else
/* cookie */
length += 19 + cookie_length;
Expand All @@ -115,10 +115,10 @@ x224_send_connection_request(rdpIso * iso)
out_uint16_le(s, 0); /* src_ref */
out_uint8(s, 0); /* class */

if (iso->mcs->sec->rdp->redirect_routingtoken)
if (iso->net->rdp->redirect_routingtoken)
{
/* routingToken */
out_uint8p(s, iso->mcs->sec->rdp->redirect_routingtoken, iso->mcs->sec->rdp->redirect_routingtoken_len);
out_uint8p(s, iso->net->rdp->redirect_routingtoken, iso->net->rdp->redirect_routingtoken_len);
}
else
{
Expand All @@ -138,7 +138,7 @@ x224_send_connection_request(rdpIso * iso)
}

s_mark_end(s);
tcp_send(iso->tcp, s);
network_send(iso->net, s);
}

/* Receive an X.224 TPDU */
Expand All @@ -149,7 +149,7 @@ x224_recv(rdpIso * iso, STREAM s, int length, uint8 * pcode)
uint8 code;
uint8 subcode;

s = tcp_recv(iso->tcp, s, length - 4);
s = network_recv(iso->net, s, length - 4);

if (s == NULL)
return NULL;
Expand Down Expand Up @@ -217,7 +217,7 @@ tpkt_recv(rdpIso * iso, uint8 * pcode, isoRecvType * ptype)
STREAM s;
int length;

s = tcp_recv(iso->tcp, NULL, 4);
s = network_recv(iso->net, NULL, 4);

if (s == NULL)
return NULL;
Expand Down Expand Up @@ -250,7 +250,7 @@ tpkt_recv(rdpIso * iso, uint8 * pcode, isoRecvType * ptype)
next_be(s, length);
}

s = tcp_recv(iso->tcp, s, length - 4);
s = network_recv(iso->net, s, length - 4);
return s;
}
return NULL; /* Fast-Path not allowed */
Expand Down Expand Up @@ -300,7 +300,7 @@ iso_send(rdpIso * iso, STREAM s)
out_uint8(s, X224_TPDU_DATA); /* code */
out_uint8(s, 0x80); /* eot */

tcp_send(iso->tcp, s);
network_send(iso->net, s);
}

/* Send an fast path data PDU */
Expand Down Expand Up @@ -335,7 +335,7 @@ iso_fp_send(rdpIso * iso, STREAM s, uint32 flags)
out_uint8(s, len);
}

tcp_send(iso->tcp, s);
network_send(iso->net, s);
}

/* Receive ISO transport data packet
Expand All @@ -355,7 +355,7 @@ iso_recv(rdpIso * iso, isoRecvType * ptype)
(*ptype == ISO_RECV_X224) &&
(code != X224_TPDU_DATA))
{
ui_error(iso->mcs->sec->rdp->inst, "expected X224_TPDU_DATA, got 0x%x\n", code);
ui_error(iso->net->rdp->inst, "expected X224_TPDU_DATA, got 0x%x\n", code);
return NULL;
}

Expand All @@ -366,8 +366,14 @@ iso_recv(rdpIso * iso, isoRecvType * ptype)
RD_BOOL
iso_connect(rdpIso * iso, char *server, char *username, int port)
{
if (strlen(iso->mcs->sec->rdp->settings->domain) > 0)
iso->cookie = iso->mcs->sec->rdp->settings->domain;
if (iso->net == NULL)
printf("iso->net\n");

if (iso->net->rdp == NULL)
printf("iso->net->rdp\n");

if (strlen(iso->net->rdp->settings->domain) > 0)
iso->cookie = iso->net->rdp->settings->domain;
else
iso->cookie = username;

Expand All @@ -376,6 +382,7 @@ iso_connect(rdpIso * iso, char *server, char *username, int port)
iso->nego->tcp_connected = 0;

nego_init(iso->nego);

if (nego_connect(iso->nego) > 0)
{
return True;
Expand All @@ -393,14 +400,14 @@ iso_disconnect(rdpIso * iso)
{
x224_send_dst_src_class(iso, X224_TPDU_DISCONNECT_REQUEST);
#ifndef DISABLE_TLS
if (iso->mcs->sec->tls)
tls_disconnect(iso->mcs->sec->tls);
if (iso->net->tls)
tls_disconnect(iso->net->tls);
#endif
tcp_disconnect(iso->tcp);
}

rdpIso *
iso_new(struct rdp_mcs *mcs)
iso_new(struct rdp_network * net)
{
rdpIso *self;

Expand All @@ -409,7 +416,8 @@ iso_new(struct rdp_mcs *mcs)
if (self != NULL)
{
memset(self, 0, sizeof(rdpIso));
self->mcs = mcs;
self->net = net;
self->mcs = net->mcs;
self->tcp = tcp_new(self);
self->nego = nego_new(self);
}
Expand Down
7 changes: 5 additions & 2 deletions libfreerdp-core/iso.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

#include <freerdp/types/ui.h>

#include "network.h"
#include "stream.h"
#include "nego.h"

Expand All @@ -28,8 +30,9 @@ struct rdp_iso
{
char* cookie;
struct _NEGO * nego;
struct rdp_mcs * mcs;
struct rdp_tcp * tcp;
struct rdp_mcs * mcs;
struct rdp_network * net;
};
typedef struct rdp_iso rdpIso;

Expand Down Expand Up @@ -60,7 +63,7 @@ iso_connect(rdpIso * iso, char * server, char * username, int port);
void
iso_disconnect(rdpIso * iso);
rdpIso *
iso_new(struct rdp_mcs * mcs);
iso_new(struct rdp_network * net);
void
iso_free(rdpIso * iso);

Expand Down
Loading

0 comments on commit 2b95558

Please sign in to comment.