Commit c6d7c7f5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Implement net_* virtualization with TLS module

parent 5f2fabb3
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#ifndef _VLC_TLS_H #ifndef _VLC_TLS_H
# define _VLC_TLS_H # define _VLC_TLS_H
# include "network.h"
struct tls_t struct tls_t
{ {
VLC_COMMON_MEMBERS VLC_COMMON_MEMBERS
...@@ -56,10 +58,9 @@ struct tls_session_t ...@@ -56,10 +58,9 @@ struct tls_session_t
void *p_sys; void *p_sys;
struct virtual_socket_t sock;
tls_session_t * (*pf_handshake) ( tls_session_t *, int ); tls_session_t * (*pf_handshake) ( tls_session_t *, int );
void (*pf_close) ( tls_session_t * ); void (*pf_close) ( tls_session_t * );
int (*pf_send) ( tls_session_t *, const char *, int );
int (*pf_recv) ( tls_session_t *, char *, int );
}; };
...@@ -105,8 +106,9 @@ VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) ); ...@@ -105,8 +106,9 @@ VLC_EXPORT( void, tls_ClientDelete, ( tls_session_t * ) );
# define tls_SessionClose( a ) (((tls_session_t *)a)->pf_close (a)) # define tls_SessionClose( a ) (((tls_session_t *)a)->pf_close (a))
# define __tls_ClientDelete( a ) tls_SessionClose( a ) # define __tls_ClientDelete( a ) tls_SessionClose( a )
# define tls_Send( a, b, c ) (((tls_session_t *)a)->pf_send (a, b, c )) /* NOTE: It is assumed that a->sock.p_sys = a */
# define tls_Send( a, b, c ) (((tls_session_t *)a)->sock.pf_send (a, b, c ))
# define tls_Recv( a, b, c ) (((tls_session_t *)a)->pf_recv (a, b, c )) # define tls_Recv( a, b, c ) (((tls_session_t *)a)->sock.pf_recv (a, b, c ))
#endif #endif
...@@ -88,12 +88,12 @@ typedef struct tls_client_sys_t ...@@ -88,12 +88,12 @@ typedef struct tls_client_sys_t
* Sends data through a TLS session. * Sends data through a TLS session.
*****************************************************************************/ *****************************************************************************/
static int static int
gnutls_Send( tls_session_t *p_session, const char *buf, int i_length ) gnutls_Send( void *p_session, const void *buf, int i_length )
{ {
int val; int val;
val = gnutls_record_send( *(gnutls_session *)(p_session->p_sys), val = gnutls_record_send( *(gnutls_session *)(((tls_session_t *)p_session)
buf, i_length ); ->p_sys), buf, i_length );
return val < 0 ? -1 : val; return val < 0 ? -1 : val;
} }
...@@ -104,12 +104,12 @@ gnutls_Send( tls_session_t *p_session, const char *buf, int i_length ) ...@@ -104,12 +104,12 @@ gnutls_Send( tls_session_t *p_session, const char *buf, int i_length )
* Receives data through a TLS session. * Receives data through a TLS session.
*****************************************************************************/ *****************************************************************************/
static int static int
gnutls_Recv( tls_session_t *p_session, char *buf, int i_length ) gnutls_Recv( void *p_session, void *buf, int i_length )
{ {
int val; int val;
val = gnutls_record_recv( *(gnutls_session *)(p_session->p_sys), val = gnutls_record_recv( *(gnutls_session *)(((tls_session_t *)p_session)
buf, i_length ); ->p_sys), buf, i_length );
return val < 0 ? -1 : val; return val < 0 ? -1 : val;
} }
...@@ -269,10 +269,11 @@ gnutls_ClientCreate( tls_t *p_tls, const char *psz_ca_path ) ...@@ -269,10 +269,11 @@ gnutls_ClientCreate( tls_t *p_tls, const char *psz_ca_path )
p_session->p_tls = p_tls; p_session->p_tls = p_tls;
p_session->p_server = NULL; p_session->p_server = NULL;
p_session->p_sys = p_sys; p_session->p_sys = p_sys;
p_session->sock.p_sys = p_session;
p_session->sock.pf_send = gnutls_Send;
p_session->sock.pf_recv = gnutls_Recv;
p_session->pf_handshake = gnutls_SessionHandshake; p_session->pf_handshake = gnutls_SessionHandshake;
p_session->pf_close = gnutls_SessionClose; p_session->pf_close = gnutls_SessionClose;
p_session->pf_send = gnutls_Send;
p_session->pf_recv = gnutls_Recv;
return p_session; return p_session;
} }
...@@ -350,10 +351,11 @@ gnutls_ServerSessionPrepare( tls_server_t *p_server ) ...@@ -350,10 +351,11 @@ gnutls_ServerSessionPrepare( tls_server_t *p_server )
p_session->p_tls = p_server->p_tls; p_session->p_tls = p_server->p_tls;
p_session->p_server = p_server; p_session->p_server = p_server;
p_session->p_sys = p_sys; p_session->p_sys = p_sys;
p_session->sock.p_sys = p_session;
p_session->sock.pf_send = gnutls_Send;
p_session->sock.pf_recv = gnutls_Recv;
p_session->pf_handshake = gnutls_SessionHandshake; p_session->pf_handshake = gnutls_SessionHandshake;
p_session->pf_close = gnutls_SessionClose; p_session->pf_close = gnutls_SessionClose;
p_session->pf_send = gnutls_Send;
p_session->pf_recv = gnutls_Recv;
return p_session; return p_session;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment