Beispiel #1
0
        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);
            }
        }