I'm trying to understand how the final Encrypted Handshake message works
To do this, I'm trying to ensure that my algorithm gives the same result as this example that works:
https://www.cloudshark.org/captures/56acf0481a79
I'm quiet sure that DTLS 1.0 is following RFC 4347 due to the 0xFEFF header.
The known are
Preshared Key: 123456789012345678901234567890aa
Server Random: d87eeeb79b8c5bb29a6e01236ca75a00d515ac18a060e7b4dd4aa85d66130b41
Client Random: df14cead6b8a82a7f0fa710ed4437fa747f5f20e160b6865a3486ca3abc1c427
Cipher Suite: TLS_PSK_WITH_AES_256_CBC_SHA
I'm doing the following step:
Pre Master Secret
The premaster secret is formed as follows: if the PSK is N octets long, concatenate a uint16 with the value N, N zero octets, a second uint16 with the value N, and the PSK itself. (RFC 4279 Section 2)
001000000000000000000000000000000000
0010123456789012345678901234567890aa
The master_secret = PRF(pre_master_secret, "master secret", ClientHello.random + ServerHello.random) [0..47];
The PRF is defined as combining two different hashing functions. Section 5 of RFC 2246:
197c358a9de99d7c50120aea40af2095
c7c340719385f23f5355004c07d9f896
681942c494eb0d77992c3acf1bc92e4f
The key_block = PRF(SecurityParameters.master_secret, "key expansion", ServerHello.random + ClientHello.Random) according to RFC4346 Section 6.3
- 20 bytes for a client MAC key (SHA1)
- 20 bytes for a server MAC key (SHA1)
- 32 bytes for a client encryption key (AES256)
- 32 bytes for a server encryption key (AES256)
- 16 bytes for a client IV (AES uses 128-bit blocks)
- 16 bytes for a server IV (AES uses 128-bit blocks)
In this case we need to generate 136 byte
4921654a071c95e2ddb8e3a8162258fa
acffdd8def0a0b7ce49f492a6f088af9
e539aae851232337c90564d6d4b01fb1
0b34466fe379e34b10b5738203453253
3fe0823297ca5c111b3d23dfb6145447
a638a84376f21a845de503b324f2beab
e145274f680519cc2ecc088e0bf6fb37
69b31c82df3ce706f6ac2cb45226234a
dbd564a2b43c79ee
If the above is correct then
Client Write Key: c90564d6d4b01fb10b34466fe379e34b
10b57382034532533fe0823297ca5c11
Client Write IV: 2ecc088e0bf6fb3769b31c82df3ce706
Therefore, if I decrypt the client handshake encrypted record with the key and IV above I get
7fd6314cf559a60c14a44a2fd4ac5494
1400000c000200000000000ce93fd3d8
557a3eb9574d25943e01f797b982a5ed
35ce268520ef7475144441ea03030303
How do I get the value above?
I understand that this needs to be hashed (the concatenation of Client Hello + Sever Hello + Sever Hello Done + Client Key Exchange)
010000390000000000000039feffdf14
cead6b8a82a7f0fa710ed4437fa747f5
f20e160b6865a3486ca3abc1c4270000
0006008d008c00ff0100000900230000
000f0001010200003600000000000000
36feffd87eeeb79b8c5bb29a6e01236c
a75a00d515ac18a060e7b4dd4aa85d66
130b4100008d00000eff010001000023
0000000f0001010e0000000001000000
00000010000011000100000000001100
0f436c69656e745f6964656e74697479
Can anyone help?