Cryptography Reference
In-Depth Information
Correctly Receiving the Finished Message
Unfortunately, parse_finished , in Listing 6-57, doesn't work. The handshake
digests were fi nalized when verify_data was called the fi rst time around, but
they need to be fi nalized again when the server sends its fi nished message.
And because the server's fi nished message is based on a hash including the cli-
ent's fi nished message you can't just reuse the original hashes; the server sends
verifi cation of a different hash code.
Therefore, it's necessary to modify compute_verify_data so that it doesn't
operate on the running hash. The easiest way to do this is to make a temporary
copy and operate on that temporary copy, as in Listing 6-58.
Listing 6-58: “tls.c” compute_verify_data with temporary copy
void compute_handshake_hash( TLSParameters *parameters, unsigned char
*handshake_hash )
{
digest_ctx tmp_md5_handshake_digest;
digest_ctx tmp_sha1_handshake_digest;
// “cheating”. Copy the handshake digests into local memory (and change
// the hash pointer) so that we can finalize twice (again in “recv”)
memcpy( &tmp_md5_handshake_digest, &parameters->md5_handshake_digest,
sizeof( digest_ctx ) );
memcpy( &tmp_sha1_handshake_digest, &parameters->sha1_handshake_digest,
sizeof( digest_ctx ) );
tmp_md5_handshake_digest.hash = ( unsigned int * ) malloc( MD5_BYTE_SIZE );
tmp_sha1_handshake_digest.hash = ( unsigned int * ) malloc( SHA1_BYTE_SIZE );
memcpy( tmp_md5_handshake_digest.hash, parameters->md5_handshake_digest.hash,
MD5_BYTE_SIZE );
memcpy( tmp_sha1_handshake_digest.hash, parameters->sha1_handshake_digest.hash,
SHA1_BYTE_SIZE );
finalize_digest( &tmp_md5_handshake_digest );
finalize_digest( &tmp_sha1_handshake_digest );
memcpy( handshake_hash, tmp_md5_handshake_digest.hash, MD5_BYTE_SIZE );
memcpy( handshake_hash + MD5_BYTE_SIZE, tmp_sha1_handshake_digest.hash,
SHA1_BYTE_SIZE );
free( tmp_md5_handshake_digest.hash );
free( tmp_sha1_handshake_digest.hash );
}
static void compute_verify_data( const char *finished_label,
TLSParameters *parameters,
char *verify_data )
{
// Per 6.2.3.1 - encrypted data should always be followed by a MAC
 
Search WWH ::




Custom Search