Cryptography Reference
In-Depth Information
The designers of TLS recognized that it is somewhat wasteful to rigidly
separate messages this way, so the TLS format actually allows either side to
concatenate multiple handshake messages within a single TLS message. This
capability was one of the big benefi ts of TLS over SSLv2. Remember the TLS
header that included a message length which was then followed by the seemingly
superfl uous handshake header that included essentially the same length? This is
why it was done this way; a single TLS header can identify multiple handshake
messages, each with its own independent length. Most TLS implementations
do take advantage of this optimization, so you must be prepared to handle it.
This slightly complicates the design of receive_tls_msg , though. The cli-
ent must now be prepared to process multiple handshake messages within a
single TLS message. Modify the content_handshake handler to keep process-
ing the TLS message until there are no more handshake messages remaining
as in Listing 6-28.
Listing 6-28: “tls.c” receive_tls_msg with multiple handshake support
if ( message.type == content_handshake )
{
while ( ( read_pos - decrypted_message ) < decrypted_length )
{
Handshake handshake;
read_pos = read_buffer( ( void * ) &handshake.msg_type,
( void * ) read_pos, 1 );
switch ( handshake.msg_type )
{
case certificate:
read_pos = parse_x509_chain( read_pos, handshake.length,
&parameters->server_public_key );
if ( read_pos == NULL )
{
printf( “Rejected, bad certificate\n” );
send_alert_message( connection, bad_certificate );
return -1;
}
break;
Notice that the call is made, not directly to the parse_x509_certificate
function developed in Chapter 5, but to a new function parse_x509_chain .
TLS actually allows the server to pass in not just its own certifi cate, but the
signing certifi cate of its certifi cate, and the signing certifi cate of that certifi cate,
and so on, until a top-level, self-signed certifi cate is reached. It's up to the client
to determine whether or not it trusts the top-level certifi cate. Of course, each
certifi cate after the fi rst should be checked to ensure that it includes the “is a
certifi cate authority” extension described in Chapter 5 as well.
 
Search WWH ::




Custom Search