Cryptography Reference
In-Depth Information
is broken out for specifi c implementation types that are examined later. Also,
the protocol version is included on every packet.
The TLS Message header is illustrated in Figure 6-4.
TLS Message
(variable)
type
major minor
length
Figure 6-4: TLS Message header
Notice that this header is added to every packet that is sent over a TLS con-
nection, not just the handshake messages. If, after handshake negotiation, either
side receives a packet whose fi rst byte is not greater than or equal to 20 and less
than or equal to 23 then something has gone wrong, and the whole connection
should be terminated.
Finally, you need one last send function that prepends this header on top of
the handshake message as shown in Listing 6-17.
Listing 6-17: “tls.c” send_message
static int send_message( int connection,
int content_type,
const unsigned char *content,
short content_len )
{
TLSPlaintext header;
unsigned char *send_buffer;
int send_buffer_size;
send_buffer_size = content_len;
send_buffer_size +=5;
send_buffer = ( unsigned char * ) malloc( send_buffer_size );
header.type = content_type;
header.version.major = TLS_VERSION_MAJOR;
header.version.minor = TLS_VERSION_MINOR;
header.length = htons( content_len );
send_buffer[ 0 ] = header.type;
send_buffer[ 1 ] = header.version.major;
send_buffer[ 2 ] = header.version.minor;
memcpy( send_buffer + 3, &header.length, sizeof( short ) );
memcpy( send_buffer + 5, content, content_len );
(Continued)
 
Search WWH ::




Custom Search