private void ProcessDecryptedClientMessages(AsynchronousSocket socket, byte[] message) { string command = ASCIIEncoding.ASCII.GetString(message, 0, (message.Length > 128 ? 128 : message.Length)); OnDebug("Client Message \"" + SRP6.ArrayToString(message, 0, message.Length) + "\""); if (command.StartsWith("SUBMIT_CRASH")) // Client wants to send us a crash report { OnDebug("Beginning submitting Crash Report"); string strMessage = SRP6.ArrayToString(message, 13, message.Length - 13); string[] strTokens = strMessage.Split(' '); try { crashReportSize = Convert.ToInt32(strTokens[0]); } catch { } try { crashReportEncryptedSize = Convert.ToInt32(strTokens[1]); } catch { } if ((crashReportSize > 0) && (crashReportEncryptedSize >= crashReportSize)) { isReceivingCrashReport = true; // We know what to expect now, send "PROCEED" message. srpServer.EncryptAndSend(socket, "PROCEED"); } else { OnDebug( "Failed to get valid transfer information from the client"); } } else if (command.StartsWith("VERSION")) { srpServer.EncryptAndSend(socket, TemposVersionString); } else if (command.StartsWith("SEND")) { socket.SendStream = new FileStream(UpdateFileLocation, FileMode.Open, FileAccess.Read); socket.EncryptedSendStream = srpServer.Encrypt(socket.SendStream); srpServer.EncryptAndSend(socket, socket.SendStream.Length.ToString() + " " + socket.EncryptedSendStream.Length.ToString()); } else if (command.StartsWith("CONTINUE")) { if (socket.EncryptedSendStream != null) { socket.SendFile(socket.EncryptedSendStream); } } else { socket.Disconnect(); OnDebug("Unhandled: " + command); } }
private void ServerReadyReceived(AsynchronousSocket socket) { byte[] message = SRP6.SubArray( socket.ReceiveBuffer, 0, socket.ReceiveBufferLength); string strMessage = SRP6.ArrayToString(message, 0, message.Length); // Server and client are now both ready for encrypted communications if (strMessage.Equals("READY")) { OnDebug("Received \"READY\" from server"); step++; if (Authenticated != null) { Authenticated.Invoke(this, new EventArgs()); } if (crashReportOnly) { // Request to send a crash report to the server OnDebug("Telling server we want to upload a crash report"); try { byte[] serializedObject = CrashException.SerializeObject(); socket.SendStream = new MemoryStream(serializedObject); socket.EncryptedSendStream = srpClient.Encrypt(socket.SendStream); srpClient.EncryptAndSend(socket, "SUBMIT_CRASH " + socket.SendStream.Length + " " + socket.EncryptedSendStream.Length); } catch (Exception ex) { OnDebug("Exception: " + ex.Message); } } else { // Request the current version OnDebug("Sending version-check request to server"); isCheckingVersion = true; srpClient.EncryptAndSend(socket, "VERSION"); } } else { OnDebug("Authentication Failed"); socket.Disconnect(); } }
private void ProcessDecryptedServerMessages(AsynchronousSocket socket, byte[] message) { // Server is going to tell us the size of the update if (isRequestingSend) { isRequestingSend = false; string strMessage = SRP6.ArrayToString(message, 0, message.Length); string[] strTokens = strMessage.Split(' '); try { UpdateFileSize = Convert.ToInt32(strTokens[0]); } catch { } try { encryptedFileSize = Convert.ToInt32(strTokens[1]); } catch { } if ((UpdateFileSize > 0) && (encryptedFileSize >= UpdateFileSize)) { isReceivingUpdate = true; srpClient.EncryptAndSend(socket, "CONTINUE"); } else { OnDebug("Bad transfer information sent from the server"); } return; } { string strMessage = SRP6.ArrayToString(message, 0, message.Length); OnDebug("Server Message \"" + strMessage + "\""); if (strMessage.Equals("PROCEED")) // CrashException != null { // Send the CrashException to the server (serialized) OnDebug("Sending crash report to server"); srpClient.EncryptAndSend(socket, CrashException.SerializeObject()); } } if (isCheckingVersion) { isCheckingVersion = false; string text = SRP6.ArrayToString(message, 0, message.Length); OnDebug("Server reports that version is \"" + text + "\""); Srp6ClientSocket.NewestUpdateVersion = text; if (ReceivedVersion != null) { ReceivedVersion.Invoke(this, new EventArgs()); } if (checkVersionOnly) { isCheckingVersion = false; socket.Disconnect(); } else { isRequestingSend = true; srpClient.EncryptAndSend(socket, "SEND"); } } }