Cryptography Reference
In-Depth Information
Listing 6-22: “tls.h” ServerHello structure
typedef struct
{
ProtocolVersion server_version;
Random random;
unsigned char session_id_length;
unsigned char session_id[ 32 ]; // technically, this len should be dynamic.
unsigned short cipher_suite;
unsigned char compression_method;
}
ServerHello;
Because the TLSParameters were passed into the receive_tls_message func-
tion, the parse_server_hello can go ahead and update the ongoing state as it's
parsed, as in Listing 6-23.
Listing 6-23: “tls.c” parse_server_hello
static char *parse_server_hello( char *read_pos,
int pdu_length,
TLSParameters *parameters )
{
ServerHello hello;
read_pos = read_buffer( ( void * ) &hello.server_version.major,
( void * ) read_pos, 1 );
read_pos = read_buffer( ( void * ) &hello.server_version.minor,
( void * ) read_pos, 1 );
read_pos = read_buffer( ( void * ) &hello.random.gmt_unix_time,
( void * ) read_pos, 4 );
// *DON'T* put this in host order, since it's not used as a time! Just
// accept it as is
read_pos = read_buffer( ( void * ) hello.random.random_bytes,
( void * ) read_pos, 28 );
read_pos = read_buffer( ( void * ) &hello.session_id_length,
( void * ) read_pos, 1 );
read_pos = read_buffer( ( void * ) hello.session_id,
( void * ) read_pos, hello.session_id_length );
read_pos = read_buffer( ( void * ) &hello.cipher_suite,
( void * ) read_pos, 2 );
hello.cipher_suite = ntohs( hello.cipher_suite );
// TODO check that these values were actually in the client hello
// list.
parameters->pending_recv_parameters.suite = hello.cipher_suite;
parameters->pending_send_parameters.suite = hello.cipher_suite;
read_pos = read_buffer( ( void * ) &hello.compression_method,
( void * ) read_pos, 1 );
if ( hello.compression_method != 0 )
(Continued)
Search WWH ::




Custom Search