Search code examples
certificatersadtls

What to sign for DTLSv1.0 Certificate Verify Message with RSA


I'm using DTLS v1.0 to communicate with a server. I'm having some trouble figuring out exactly what to do to generate the certificate verify message. I've been reading the RFCs (DTLSv1.0 and TLS1.1, which DTLS v1.0 is based on) but they're somewhat non-specific when it comes to this particular message.

I see the structure of the message is as below, and I know the signature type is RSA.

struct {
       Signature signature;   
} CertificateVerify;

The Signature type is defined in 7.4.3.

CertificateVerify.signature.md5_hash
      MD5(handshake_messages);

CertificateVerify.signature.sha_hash
      SHA(handshake_messages);

Based on what I've read it seems to be a concatenation of the sha1 hash and the md5 hash of all the previous messages sent and received (up to and excluding this one) and then RSA signed.

The piece that's got me a bit confused though is how to assemble the messages to hash them.

Does it use each fragment piece or does it use the re-assembled messages? Also, what parts of the messages does it use?

The RFC for TLS 1.1 says

starting at client hello up to but not including this message, including the type and length fields of the handshake messages

but what about the DTLS specific parts like message_seq, fragment_offset, and fragment_length, do I include them?

UPDATE: I have tried doing as the RFC for DTLS 1.2 shows (meaning keeping the messages fragmented, using all the handshake fields including DTLS specific fields, and not including the initial Client Hello or Hello Verify Request messages) but I am still receiving "Bad Signature". I do believe I'm signing properly, so it's my belief that I'm concatenating the data improperly to be signed.


Solution

  • For DTLS 1.2 it is defined. And reading RFC 4347, my impression is, RFC 6347 doesn't differ, it clarifies the calculations.

    RFC 6347, 4.2.6. CertificateVerify and Finished Messages

    RFC 4347, 4.2.6. Finished Messages