summaryrefslogtreecommitdiffstats
path: root/common/trans.c
diff options
context:
space:
mode:
authorIdan Freiberg <speidy@gmail.com>2014-07-23 15:31:45 +0300
committerIdan Freiberg <speidy@gmail.com>2014-07-23 15:31:45 +0300
commitafdf638c7b56e7420e32853df6299d9217e0f8d4 (patch)
treed2a63333e6ef04a6e34db906b3af2097525a6359 /common/trans.c
parent1acdc3085eb260c166db7d575f6dfcb8a9cc2e72 (diff)
downloadxrdp-proprietary-afdf638c7b56e7420e32853df6299d9217e0f8d4.tar.gz
xrdp-proprietary-afdf638c7b56e7420e32853df6299d9217e0f8d4.zip
libxrdp, common: work on TLS mode
Diffstat (limited to 'common/trans.c')
-rw-r--r--common/trans.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/common/trans.c b/common/trans.c
index 421d5679..d58bdd91 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -38,8 +38,10 @@ trans_create(int mode, int in_size, int out_size)
make_stream(self->out_s);
init_stream(self->out_s, out_size);
self->mode = mode;
- self->do_tls = 0; /* default simple tcp layer */
self->tls = 0;
+ /* assign tcp functions */
+ self->trans_read_call = trans_tcp_force_read_s;
+ self->trans_write_call = trans_tcp_force_write_s;
}
return self;
@@ -70,6 +72,11 @@ trans_delete(struct trans *self)
g_free(self->listen_filename);
}
+ if (self->tls != 0)
+ {
+ xrdp_tls_delete(self->tls);
+ }
+
g_free(self);
}
@@ -301,11 +308,16 @@ trans_check_wait_objs(struct trans *self)
return rv;
}
-
/*****************************************************************************/
int APP_CC
trans_force_read_s(struct trans *self, struct stream *in_s, int size)
{
+ return self->trans_read_call(self, in_s, size);
+}
+/*****************************************************************************/
+int APP_CC
+trans_tcp_force_read_s(struct trans *self, struct stream *in_s, int size)
+{
int rcvd;
if (self->status != TRANS_STATUS_UP)
@@ -368,6 +380,10 @@ trans_force_read_s(struct trans *self, struct stream *in_s, int size)
int APP_CC
trans_force_read(struct trans *self, int size)
{
+ if (self->tls != 0)
+ {
+ return xrdp_tls_force_read_s(self, self->in_s, size);
+ }
return trans_force_read_s(self, self->in_s, size);
}
@@ -375,6 +391,12 @@ trans_force_read(struct trans *self, int size)
int APP_CC
trans_force_write_s(struct trans *self, struct stream *out_s)
{
+ return self->trans_write_call(self, out_s);
+}
+/*****************************************************************************/
+int APP_CC
+trans_tcp_force_write_s(struct trans *self, struct stream *out_s)
+{
int size;
int total;
int sent;
@@ -632,3 +654,42 @@ trans_get_out_s(struct trans *self, int size)
return rv;
}
+/*****************************************************************************/
+/* returns error */
+int APP_CC
+trans_set_tls_mode(struct trans *self, const char *key, const char *cert)
+{
+ self->tls = xrdp_tls_create(self, key, cert);
+ if (self->tls == NULL)
+ {
+ g_writeln("trans_set_tls_mode: xrdp_tls_create malloc error");
+ return 1;
+ }
+
+ if (xrdp_tls_accept(self->tls) != 0)
+ {
+ g_writeln("trans_set_tls_mode: xrdp_tls_accept failed");
+ return 1;
+ }
+
+ /* assign tls functions */
+ self->trans_read_call = xrdp_tls_force_read_s;
+ self->trans_write_call = xrdp_tls_force_write_s;
+
+ return 0;
+}
+/*****************************************************************************/
+/* returns error */
+int APP_CC
+trans_shutdown_tls_mode(struct trans *self)
+{
+ if (self->tls != NULL)
+ {
+ return xrdp_tls_disconnect(self->tls);
+ }
+
+ /* set callback to tls */
+ self->trans_read_call = trans_tcp_force_read_s;
+ self->trans_write_call = trans_tcp_force_write_s;
+ return 0;
+}