Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-master secret mistmatched when implementing Diffie-Hellman key exchange

I am trying to implement DHE_DSS into go's crypto/tls package. Unfortunately I can not seem to get the PreMasterSecret (Z) to be the same, my basic workflow is:

Receive Server Key Exchange Message

  • Extract P, G, Ys
  • Verify using the digital signature provided

Prepare Client Key Exchange Message

  • Create client's Xc
  • Generate Yc (Yc = G^Xc % P)
  • Generate Z (Z = Ys^Xc % P)
  • Send back Yc, packed like so:
ckx := make([]byte, len(yC)+2) ckx[0] = byte(len(Yc)>>8) ckx[1] = byte(len(Yc)) copy(ckx[2:], yBytes) 

However, when I am debugging this with gnutls-serv the two PreMasterSecrets (Z) are different. Do I need to sign the returned Yc, or perhaps pack it in another way? I can not see anything in RFC 5246 to suggest this.

<-- EDIT -->

Here is a patch of my changes:

https://08766345559465695203.googlegroups.com/attach/48587532c74b4348/crypto.patch?part=4&view=1&vt=ANaJVrHbwydqEZc3zjUWqQ5C8Q5zEkWXZLdL0w6JJG3HYntOlBurUTY7mc9xR9OTfE0bJxs4eeL5a5SGd2jj9eIfXcwJQgLvJchXOgkYKBBynbPfshY8kuQ

like image 886
jawr Avatar asked Sep 14 '12 10:09

jawr


People also ask

What is pre-master secret key?

The premaster secret: The client sends one more random string of bytes, the "premaster secret." The premaster secret is encrypted with the public key and can only be decrypted with the private key by the server. (The client gets the public key from the server's SSL certificate.)

How is pre-master secret generated?

The pre-master secret is created by the client (the method of creation depends on the cipher suite) and then shared with the server. Before sending the pre-master secret to the server, the client encrypts it using the server public key extracted from the certificate provided by the server.

What is a pre-master key used for?

The Pre-Master Secret The pre-master key is the value you directly obtain from the key exchange (e.g. gab(modp) g a b ( mod p ) if using Diffie-Hellman). Its length varies depending on the algorithm and the parameters used during the key exchange.

Why Diffie-Hellman key exchange algorithm alone is not secure against man in the middle attacks briefly explain?

Authentication & the Diffie-Hellman key exchange In the real world, the Diffie-Hellman key exchange is rarely used by itself. The main reason behind this is that it provides no authentication, which leaves users vulnerable to man-in-the-middle attacks.


1 Answers

Client key exchange will contain:

length (2 bytes) --> Y_C (in plain text) 

I have implemented TLS in Java and I follow the same structure and works fine for me.

Do I need to sign the returned Yc?

No there is no need to sign the client DH public value, it is transferred in plain text.

You can take a pcap and check whether same values are being transferred in the packet. Also if GNU TLS has logger for printing the Y_C received, then you can check if proper data is being received.

If in case you still getting different Pre-Master secret then there seems to be some issue with the logic of generation of secret.

like image 150
Narendra Pathai Avatar answered Sep 20 '22 15:09

Narendra Pathai