Cryptography Reference
In-Depth Information
Because each of the three parameters — cipher specs, session ID and chal-
lenge token — can be of variable length, length bytes are given for each before
their values. You can build a client hello packet for a new, non-resumed, session
as in Listing C-11.
Listing C-11: “ssl.c” send_client_hello
#define SSL_MT_CLIENT_HELLO 1
static int send_client_hello( int connection,
SSLParameters *parameters )
{
unsigned char *send_buffer, *write_buffer;
int buf_len;
int i;
unsigned short network_number;
int status = 0;
ClientHello package;
package.version_major = 0;
package.version_minor = 2;
package.cipher_specs_length = sizeof( specs ) / sizeof( CipherSpec );
package.session_id_length = 0;
package.challenge_length = CHALLENGE_LEN;
// Each cipher spec takes up 3 bytes in SSLv2
package.cipher_specs = malloc( sizeof( unsigned char ) * 3 *
package.cipher_specs_length );
package.session_id = malloc( sizeof( unsigned char ) *
package.session_id_length );
package.challenge = malloc( sizeof( unsigned char ) *
package.challenge_length );
buf_len = sizeof( unsigned char ) * 2 +
sizeof( unsigned short ) * 3 +
( package.cipher_specs_length * 3 ) +
package.session_id_length +
package.challenge_length;
for ( i = 0; i < package.cipher_specs_length; i++ )
{
memcpy( package.cipher_specs + ( i * 3 ),
&specs[ i ].cipher_spec_code, 3 );
}
memcpy( package.challenge, parameters->challenge, CHALLENGE_LEN );
write_buffer = send_buffer = malloc( buf_len );
write_buffer = append_buffer( write_buffer,
&package.version_major, 1 );
(Continued)
 
Search WWH ::




Custom Search