Cryptography Reference
In-Depth Information
certainly be nice if the TLS alert protocol allowed space for a descriptive error
message.
send_alert_message is shown in Listing 6-20.
Listing 6-20: “tls.c” send_alert_message
static int send_alert_message( int connection,
int alert_code )
{
char buffer[ 2 ];
// TODO support warnings
buffer[ 0 ] = fatal;
buffer[ 1 ] = alert_code;
return send_message( connection, content_alert, buffer, 2 );
}
By reusing the send_message routine from above, sending an alert message
is extremely simple.
Parsing the Server Hello Structure
Assuming nothing went wrong, the message has now been completely read
from the connection and is contained in msg_buf . For the moment, the only
type of message you're interested in is content_handshake , whose parsing is
shown in Listing 6-21:
Listing 6-21: “tls.c” receive_tls_msg (continued from Listing 6-19)
read_pos = msg_buf;
if ( message.type == content_handshake )
{
Handshake handshake;
// Now, read the handshake type and length of the next packet
// TODO - this fails if the read, above, only got part of the message
read_pos = read_buffer( ( void * ) &handshake.msg_type,
( void * ) read_pos, 1 );
handshake.length = read_pos[ 0 ] << 16 | read_pos[ 1 ] << 8 | read_pos[ 2 ];
read_pos += 3;
// TODO check for negative or unreasonably long length
// Now, depending on the type, read in and process the packet itself.
switch ( handshake.msg_type )
{
// Client-side messages
case server_hello:
(Continued)
Search WWH ::




Custom Search