Cryptography Reference
In-Depth Information
{
int session_id_length;
unsigned char session_id[ MAX_SESSION_ID_LENGTH ];
unsigned char master_secret[ MASTER_SECRET_LENGTH ];
struct StoredSessions_list_t *next;
}
StoredSessionsList;
static StoredSessionsList *stored_sessions[ HASH_TABLE_SIZE ];
This structure simply contains the session ID and the master secret, which is
the bare minimum amount of information you need to resume a prior session.
Because this is a static variable (again, not thread safe), it must be initialized
on startup by the init_tls function shown in Listing 8-11.
Listing 8-11: “tls.c” init_tls
void init_tls()
{
int i = 0;
for ( i = 0; i < HASH_TABLE_SIZE; i++ )
{
stored_sessions[ i ] = NULL;
}
}
First of all, you need to store each successfully negotiated session in this struc-
ture. Listing 8-12 illustrates how to fi nd the correct placement in the hash map
for the master secret. By forcing the session IDs themselves to be numeric values,
the hash function is simply the session ID modulo the size of the hash table.
Listing 8-12: “tls.c” remember_session
/**
* Store the session in the stored sessions cache
*/
static void remember_session( TLSParameters *parameters )
{
if ( parameters->session_id_length > 0 )
{
int session_id;
StoredSessionsList *head;
memcpy( &session_id, parameters->session_id, sizeof( int ) );
head = stored_sessions[ session_id % HASH_TABLE_SIZE ];
if ( head == NULL )
{
head = stored_sessions[ session_id % HASH_TABLE_SIZE ] =
malloc( sizeof( StoredSessionsList ) );
}
else
Search WWH ::




Custom Search