- Timestamp:
- 2012-12-24T19:17:37Z (12 years ago)
- Branches:
- master
- Children:
- c1d9c95
- Parents:
- def3650
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/ssl_gnutls.c
rdef3650 r9b67285 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-201 1Wilmer van der Gaast and others *4 * Copyright 2002-2012 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 63 63 }; 64 64 65 static GHashTable *session_cache; 66 65 67 static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond ); 66 68 static gboolean ssl_starttls_real( gpointer data, gint source, b_input_condition cond ); … … 97 99 */ 98 100 101 session_cache = g_hash_table_new_full( g_str_hash, g_str_equal, g_free, g_free ); 102 99 103 atexit( ssl_deinit ); 100 104 } … … 104 108 gnutls_global_deinit(); 105 109 gnutls_certificate_free_credentials( xcred ); 110 g_hash_table_destroy( session_cache ); 111 session_cache = NULL; 106 112 } 107 113 … … 220 226 221 227 return verifyret; 228 } 229 230 struct ssl_session 231 { 232 size_t size; 233 char data[]; 234 }; 235 236 static void ssl_cache_add( struct scd *conn ) 237 { 238 size_t data_size; 239 struct ssl_session *data; 240 char *hostname; 241 242 if( !conn->hostname || 243 gnutls_session_get_data( conn->session, NULL, &data_size ) != 0 ) 244 return; 245 246 data = g_malloc( sizeof( struct ssl_session ) + data_size ); 247 if( gnutls_session_get_data( conn->session, data->data, &data->size ) != 0 ) 248 { 249 g_free( data ); 250 return; 251 } 252 253 hostname = g_strdup( conn->hostname ); 254 g_hash_table_insert( session_cache, hostname, data ); 255 } 256 257 static void ssl_cache_resume( struct scd *conn ) 258 { 259 struct ssl_session *data; 260 261 if( conn->hostname && 262 ( data = g_hash_table_lookup( session_cache, conn->hostname ) ) ) 263 { 264 gnutls_session_set_data( conn->session, data->data, data->size ); 265 g_hash_table_remove( session_cache, conn->hostname ); 266 } 222 267 } 223 268 … … 280 325 gnutls_transport_set_ptr( conn->session, (gnutls_transport_ptr_t) GNUTLS_STUPID_CAST conn->fd ); 281 326 327 ssl_cache_resume( conn ); 328 282 329 return ssl_handshake( data, source, cond ); 283 330 } … … 320 367 /* For now we can't handle non-blocking perfectly everywhere... */ 321 368 sock_make_blocking( conn->fd ); 322 369 370 ssl_cache_add( conn ); 323 371 conn->established = TRUE; 324 372 conn->func( conn->data, 0, conn, cond );
Note: See TracChangeset
for help on using the changeset viewer.