I'm programming a client that partecipates in a TLS 1.2 handshake by sending messages through a TCP socket connected to Google's server. I'm using the ECDH key exchange method.
I am trying to derive the shared secret using this code.
I received the key through the serverKeyExchange message and stored it in a buffer, so my question is: how do I generate a EVP_PKEY from a buffer? I found a possible solution in this post and tried with:
i2d_PublicKey(peerkey, (unsigned char **) &server_pub_key)
but when I run the code I get an error in this step:
/* Provide the peer public key */
if(1 != EVP_PKEY_derive_set_peer(ctx, peerkey)) handleErrors();
Which makes me think that I have not succeded at retrieving the server Public key.
Any Suggestions? How do I even know if the key was succesfully encoded?