private void OnClientKeyExchange(NetMQMessage incomingMessage, OutgoingMessageBag outgoingMessages) { if (m_lastReceivedMessage != HandshakeType.ClientHello || m_lastSentMessage != HandshakeType.ServerHelloDone) { throw new NetMQSecurityException(NetMQSecurityErrorCode.HandshakeUnexpectedMessage, "Client Key Exchange received when expecting another message"); } HashLocalAndRemote(incomingMessage); ClientKeyExchangeMessage clientKeyExchangeMessage = new ClientKeyExchangeMessage(); clientKeyExchangeMessage.SetFromNetMQMessage(incomingMessage); RSACryptoServiceProvider rsa = LocalCertificate.PrivateKey as RSACryptoServiceProvider; byte[] premasterSecret = rsa.Decrypt(clientKeyExchangeMessage.EncryptedPreMasterSecret, false); GenerateMasterSecret(premasterSecret); InvokeChangeCipherSuite(); }
private void AddClientKeyExchange(OutgoingMessageBag outgoingMessages) { ClientKeyExchangeMessage clientKeyExchangeMessage = new ClientKeyExchangeMessage(); byte[] premasterSecret = new byte[ClientKeyExchangeMessage.PreMasterSecretLength]; m_rng.GetBytes(premasterSecret); RSACryptoServiceProvider rsa = RemoteCertificate.PublicKey.Key as RSACryptoServiceProvider; clientKeyExchangeMessage.EncryptedPreMasterSecret = rsa.Encrypt(premasterSecret, false); GenerateMasterSecret(premasterSecret); NetMQMessage outgoingMessage = clientKeyExchangeMessage.ToNetMQMessage(); HashLocalAndRemote(outgoingMessage); outgoingMessages.AddHandshakeMessage(outgoingMessage); m_lastSentMessage = HandshakeType.ClientKeyExchange; }