void ProcessMessage(ref Header header, Connection conn, byte[] payload, int len) { switch (header.Channel) { case MessageTypes.Ping: // Ping Test rawServer.Send(conn, payload.SubArray(0, len)); conn.FTT = Ping.Desserialize(payload, len).LastKnownFTT; break; // ======== Encypted Message =============== case MessageTypes.RSARegistration: RSARegistration rsaMessage = RSARegistration.Desserialize(payload, len); RSARegistration rsaReply; switch (rsaMessage.step) { case RSARegistration.Step.InitalRequest: rsaReply = new RSARegistration(RSARegistration.Step.ServerKey, RSAServerKeys.PublicBytes); Send(conn, ref rsaReply); break; case RSARegistration.Step.ClientResponse: rsaMessage.Decrypt(RSAServerKeys); byte[] clientRSAKey = rsaMessage.Data; // RSAPublicKeys[conn] = clientRSAKey; AESKeys[conn] = "Some Generated Key"; // TODO: Generate this AESKey rsaReply = new RSARegistration(RSARegistration.Step.AESKey, System.Text.Encoding.Unicode.GetBytes(AESKeys[conn])); rsaReply.Encrypt(new RSAEncryption.RSAKeys(_public: clientRSAKey)); Send(conn, ref rsaReply); break; } break; // ========= End Encrpted Message ================== default: for (int i = 0; i < Handlers.Count; ++i) { Handler h = Handlers[i]; if (h.channel == header.Channel) { if (header.IsAsync) { h.Call(conn, payload, len); } else { SyncMessagesToProcess.Enqueue(new ServerSyncMessageCall(h, payload, len, conn)); } } } break; } }