//Estabilish crypto tunnel and save session keys to CryptoManager object static CryptoManager Handshake(Networker networker) { CryptoManager cryptoManager = null; string AESKey = CryptoManager.GetAESKeyB64(); string response = networker.SendMessageAndWaitResponse( CryptoManager.EncryptRSA2B64("message=handshake&key=" + AESKey) ); if (!String.IsNullOrEmpty(response)) { CryptoManager cryptoManagerTest = new CryptoManager(AESKey, response); string responseConnected = ChatManager.SendMessageAndWaitResponseCrypted(ServerSpecificStrings.MesageOk, networker, cryptoManagerTest); if (responseConnected.Equals(ServerSpecificStrings.MesageOk)) { cryptoManager = cryptoManagerTest; } } return(cryptoManager); }
//Trying to get positive response from server, if all OK, then create ChatManager //This function contains server-specific strings public static ChatManager TryStartChatManager(Networker networker, string serverRequest) { CryptoManager cryptoManager = Handshake(networker); if (cryptoManager != null) { //message = serverRequest string response = ChatManager.SendMessageAndWaitResponseCrypted(serverRequest, networker, cryptoManager); if (response.Equals(ServerSpecificStrings.MesageOk)) { return(new ChatManager(networker, cryptoManager)); } else { return(null); } } else { return(null); } }
string SendMessageAndWaitResponseCrypted(string message, CryptoManager cryptoManager) { return(ChatManager.SendMessageAndWaitResponseCrypted(message, m_networker, cryptoManager)); }