Cryptography Reference
In-Depth Information
Listing 6-12: “tls.c” append buffer
/**
* This is just like memcpy, except it returns a pointer to dest + n instead
* of dest, to simplify the process of repeated appends to a buffer.
*/
static char *append_buffer( char *dest, char *src, size_t n )
{
memcpy( dest, src, n );
return dest + n;
}
This fl attened structure is illustrated in Figure 6-2.
major
minor
current time
random bytes
client
random
random bytes
sess
id
len
cipher
suites
length
Comp
meth
len
compression
methods
(variable)
session id
(variable)
cipher suites
(variable)
random bytes
Figure 6-2: Client hello structure
Finally, the client hello is sent off in Listing 6-13:
Listing 6-13: “tls.c” send_client_hello (continued from Listing 6-11)
assert( ( ( char * ) write_buffer - send_buffer ) == send_buffer_size );
status = send_handshake_message( connection, client_hello, send_buffer,
send_buffer_size );
free( send_buffer );
return status;
}
Notice that send still isn't called. Instead, you invoke send_handshake_
message . Like TCP and IP, and network programming in general, TLS is an
onion-like nesting of headers. Each handshake message must be prepended
with a header indicating its type and length. The defi nition of the handshake
header is shown in Listing 6-14.
Search WWH ::




Custom Search