/// <summary> /// First thing that happens when a connection inbounds. The server always starts the conversation. /// </summary> private void SendRijndaelExchangeRequest() { PacketRijndaelExchangeRequest p = (PacketRijndaelExchangeRequest)CreatePacket((int)PacketType.PacketRijndaelExchangeRequest, 0, false, false); p.NeedsReply = true; p.PublicRSAKey = CryptoManager.PublicRSAKey; p.ConnectionKeySize = 128; Send(p); }
private void OnRijndaelExchangeRequest(INetworkConnection con, Packet msg) { PacketRijndaelExchangeRequest p = msg as PacketRijndaelExchangeRequest; // Server said hello. Generate, encrypt with public RSA key and finally send the key. this will be our // connection key for as long as this connection is valid // Generate & Store new key m_ConnectionKey = CryptoManager.GetRandomRijndaelKey(); RemoteRsaKey = p.PublicRSAKey; // Encrypt it with the public RSA key from the server byte[] encryptedKey = CryptoManager.EncryptRijndaelKey(p.PublicRSAKey, m_ConnectionKey); // Send it PacketRijndaelExchange re = (PacketRijndaelExchange)CreatePacket((int)PacketType.RijndaelExchange, 0, false, false); re.RijndaelExchangeData = encryptedKey; re.PublicRSAKey = CryptoManager.PublicRSAKey; re.ReplyCode = m_ConnectionKey != null && m_ConnectionKey.Length > 0 ? ReplyType.OK : ReplyType.Failure; re.ReplyPacketType = msg.PacketTypeID; re.ReplyPacketID = msg.PacketID; msg.ReplyPacket = re; }