Closed faihan6 closed 2 weeks ago
ECDHE master secret F3E09249ECD0B258D889E4B792F6B3524F8A7B83158CD0CD075A8C8CF99B2FC5120E6F988E3D045E131E23B4A39B6BB1
Keys Seed 835C25D160012C38FE33C39F8FA4B2C105E258754A7ABE0E0EE5E72EC01B42DA14668A92FC430B58092FCCE747F499B13B0C56574B54377990C26C628F575B88
Request Bytes 40
Client Write Key @0,312E7C5C32E6801720A123A91F539FA5
Server Write Key @16,4EEEB91406C287C0C4047613A09DC88D
Client Write IV @32,9164F6AD
Server Write IV @36,964AB3FF
OK, the keys are well. I will check decrypting the encrypted handshake message, but it will take some time.
Client Write Key @0,312E7C5C32E6801720A123A91F539FA5
Server Write Key @16,4EEEB91406C287C0C4047613A09DC88D
Client Write IV @32,9164F6AD
Server Write IV @36,964AB3FF
AAD 000100000000000016FEFD0018
NOUNCE 9164F6ADD5FA7C4D573A28D5
payload 1400000C000300000000000C4FF7BF3EBBEFC50BBFE0E982
Your AAD:
000100000000000016fefd0030
You use the record length, but it's the fragment length. In case of decrypt, that's the record.length - record.header.length(13) - record.explicitIV.length(8) - record.mac.length(16) .
For record
16fefd00010000000000000030d5fa7c4d573a28d56f956a759f15de8945f4081b19ba2f3eebe15ae564cbde1d170866427cdb9db9a745701625754f62
61-13-8-16 => 24 = 0x18
RFC 5246 6.2.2 Record Compression and Decompression
The compression algorithm translates a TLSPlaintext structure into a TLSCompressed structure.
Though mainly CompressionMethod.null
is used,
struct {
ContentType type; /* same as TLSPlaintext.type */
ProtocolVersion version;/* same as TLSPlaintext.version */
uint16 length;
opaque fragment[TLSCompressed.length];
} TLSCompressed;
will contain the plain-payload (unencrypted), and TLSCompressed.length
is the length of fragment
(here, before encryption, the same as payload).
additional_data = seq_num + TLSCompressed.type +
TLSCompressed.version + TLSCompressed.length;
The aead_output consists of the ciphertext output by the AEAD
encryption operation. The length will generally be larger than
TLSCompressed.length,
So, on decrypt, it's required to calculate the length of the plain payload, using the record.length will be to large.
This is it. Using the length of just encrypted output instead of the whole record length in AAD solves the problem.
Thanks you very much. It means a lot. Will consolidate all the issues and post it as an answer to the original StackOverflow question.
You're welcome. I did that "step-by-step" so many times, for each extension. But it's the only way it works, because small differences will make it impossible to trace the error back, that's what good encryption is.
This is a continuation of this issue from StackOverflow. Continuing here as stated in the comments.
I tried a new DTLS session and will attach the parameters below. I am still facing the same error when decrypting.
Please find the Wireshark dump here
Thanks in advance.