Cryptography Reference
In-Depth Information
huge a;
int message_size;
short transmit_len;
// TODO obviously, make this random, and much longer
set_huge( &a, 6 );
mod_pow( &server_dh_key->g, &a, &server_dh_key->p, &Yc );
mod_pow( &server_dh_key->Y, &a, &server_dh_key->p, &Z );
// Now copy Z into premaster secret and Yc into key_exchange_message
memcpy( premaster_secret, Z.rep, Z.size );
message_size = Yc.size + 2;
transmit_len = htons( Yc.size );
*key_exchange_message = malloc( message_size );
memcpy( *key_exchange_message, &transmit_len, 2 );
memcpy( *key_exchange_message + 2, Yc.rep, Yc.size );
free_huge( &Yc );
free_huge( &Z );
free_huge( &a );
return message_size;
}
If you've been following closely, you may be wondering where the server's
dh_key value β€” the p , g and Y values that this key exchange relies on β€” come
from? Although it's possible to get one from a certifi cate (it's offi cially defi ned,
anyway), practically speaking this never happens. Instead, there's a specifi c
server key exchange handshake type where the server can provide these values
as well as authenticate them. This is examined in Chapter 8.
TLS Change Cipher Spec
After the key exchange has been successfully completed, the client should send
a change cipher spec message. Although change cipher spec can never be legally
sent outside of the context of a handshake, it's not declared as a handshake
message. Why? According to the specifi cation,
β€œTo help avoid pipeline stalls, ChangeCipherSpec is an independent TLS Protocol
content type, and is not actually a TLS handshake message.”
This isn't made particularly clear, but it appears that they're concerned with
the possibility of an implementation that automatically piggy-backs handshake
messages into one large TLS message doing so with change cipher spec mes-
sages and having the other side lose this.
The change cipher spec message is a marker message, just like server hello
done was, that doesn't include any data. It is a major milestone in the handshake
process, though, because the reception of a change cipher spec message tells the
Search WWH ::




Custom Search