Changeset 42127dc for lib


Ignore:
Timestamp:
2006-09-24T11:57:45Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
e101506
Parents:
172a73f1
Message:

Added support for SSL- and TLS-connections. Checking of the "tls" user
setting has to be finished, plus an ssl_starttls() function for the other
SSL libraries (this code will only compile with GnuTLS for now).

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/ssl_client.h

    r172a73f1 r42127dc  
    5252G_MODULE_EXPORT void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data );
    5353
     54/* Start an SSL session on an existing fd. Useful for STARTTLS functionality,
     55   for example in Jabber. */
     56G_MODULE_EXPORT void *ssl_starttls( int fd, ssl_input_function func, gpointer data );
     57
    5458/* Obviously you need special read/write functions to read data. */
    5559G_MODULE_EXPORT int ssl_read( void *conn, char *buf, int len );
  • lib/ssl_gnutls.c

    r172a73f1 r42127dc  
    6363        {
    6464                g_free( conn );
    65                 return( NULL );
     65                return NULL;
     66        }
     67       
     68        return conn;
     69}
     70
     71/* FIXME: It can happen that the handshake fails even before ssl_connected()
     72   returns already. This function will then return an invalid pointer because
     73   these failures can't be detected properly yet. Maybe ssl_connected()
     74   shouldn't be called directly, but via a short timeout? */
     75void *ssl_starttls( int fd, ssl_input_function func, gpointer data )
     76{
     77        struct scd *conn = g_new0( struct scd, 1 );
     78       
     79        conn->fd = fd;
     80        conn->func = func;
     81        conn->data = data;
     82        conn->inpa = -1;
     83       
     84        ssl_connected( conn, fd, GAIM_INPUT_WRITE );
     85       
     86        return conn;
     87}
     88
     89static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
     90
     91static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond )
     92{
     93        struct scd *conn = data;
     94       
     95        if( source == -1 )
     96        {
     97                conn->func( conn->data, NULL, cond );
     98               
     99                g_free( conn );
     100               
     101                return FALSE;
    66102        }
    67103       
     
    77113        gnutls_set_default_priority( conn->session );
    78114        gnutls_credentials_set( conn->session, GNUTLS_CRD_CERTIFICATE, conn->xcred );
    79        
    80         return( conn );
    81 }
    82 
    83 static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond );
    84 
    85 static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond )
    86 {
    87         struct scd *conn = data;
    88        
    89         if( source == -1 )
    90         {
    91                 conn->func( conn->data, NULL, cond );
    92                
    93                 gnutls_deinit( conn->session );
    94                 gnutls_certificate_free_credentials( conn->xcred );
    95                
    96                 g_free( conn );
    97                
    98                 return FALSE;
    99         }
    100115       
    101116        sock_make_nonblocking( conn->fd );
Note: See TracChangeset for help on using the changeset viewer.