Cryptography Reference
In-Depth Information
Listing 7-4: “tls.c” tls_accept
int tls_accept( int connection,
TLSParameters *parameters )
{
init_parameters( parameters );
parameters->connection_end = connection_end_server;
new_md5_digest( &parameters->md5_handshake_digest );
new_sha1_digest( &parameters->sha1_handshake_digest );
// The client sends the first message
parameters->got_client_hello = 0;
while ( !parameters->got_client_hello )
{
if ( receive_tls_msg( connection, NULL, 0, parameters ) < 0 )
{
perror( “Unable to receive client hello” );
send_alert_message( connection, handshake_failure,
&parameters->active_send_parameters );
return 1;
}
}
if ( send_server_hello( connection, parameters ) )
{
send_alert_message( connection, handshake_failure,
&parameters->active_send_parameters );
return 2;
}
if ( send_certificate( connection, parameters ) )
{
send_alert_message( connection, handshake_failure,
&parameters->active_send_parameters );
return 3;
}
if ( send_server_hello_done( connection, parameters ) )
{
send_alert_message( connection, handshake_failure,
&parameters->active_send_parameters );
return 4;
}
// Now the client should send a client key exchange, change cipher spec, and
// an encrypted “finalize” message
parameters->peer_finished = 0;
while ( !parameters->peer_finished )
{
if ( receive_tls_msg( connection, NULL, 0, parameters ) < 0 )
Search WWH ::




Custom Search