Esempio n. 1
0
        // ================== Encyption ================

        void SetupEncryption()
        {
            if (state != RawClient.State.Connected)
            {
                return;
            }
#if SLEEPY_DEBUG
            RSAKeys = RSAEncryption.GenerateKeys(512);
#else
            RSAKeys = Sleepy.Security.RSAEncryption.GenerateKeys(2048);
#endif
            Send(new RSARegistration(RSARegistration.Step.InitalRequest, new byte[0])); // Kick off the Encrption Handshake
        }
Esempio n. 2
0
        // ================== Encyption ================

        void SetupEncryption()
        {
            if (!Connected)
            {
                return;
            }
#if SLEEPY_DEBUG
            RSAKeys = RSAEncryption.GenerateKeys(512);
#else
            RSAKeys = Sleepy.Security.RSAEncryption.GenerateKeys(2048);
#endif
            RSARegistration rsar = new RSARegistration(RSARegistration.Step.InitalRequest, new byte[0]);
            rawClient.Send(MessageUtil.Serialize(ref rsar)); // Kick off the Encrption Handshake
        }
Esempio n. 3
0
        // ============== Connection =================

        public void Start()
        {
            ResetData();
            rawServer.Start();

            // ======== Encypted Message ===============
#if SLEEPY_DEBUG
            Log.WriteNow("Server | Setting Up Encryption");
            RSAServerKeys = RSAEncryption.GenerateKeys(1024);
            Log.WriteNow("Server | Encryption Setup");
#else
            RSAServerKeys = Sleepy.Security.RSAEncryption.GenerateKeys(4096);
#endif
            // ========= End Encrpted Message ==================
        }
Esempio n. 4
0
        // ============== Connection =================

        public bool Start()
        {
            if (Active)
            {
                return(false);
            }
            ResetData();

            // ======== Encypted Message ===============
            Log.WriteNow("Server | Setting Up Encryption");
#if SLEEPY_DEBUG
            RSAServerKeys = RSAEncryption.GenerateKeys(1024);
#else
            RSAServerKeys = Sleepy.Security.RSAEncryption.GenerateKeys(4096);
#endif
            Log.WriteNow("Server | Encryption Setup");
            // ========= End Encrpted Message ==================

            rawServer.Start();
            return(true);
        }
Esempio n. 5
0
        void ProcessMessage(ref Header header, byte[] payload, int len)
        {
            switch (header.Channel)
            {
            case MessageTypes.MessagePartConfirmation:
                MessagePartConfirmation part = MessagePartConfirmation.Desserialize(payload, len);

                if (ActiveMessageParts.TryGetValue(part.MessageID, out ClientMessagePartsActive activeMessage))
                {
                    activeMessage.RecievedPart(part.PartNumber);
                }
                break;

            // ======== Encypted Message ===============
            case MessageTypes.RSARegistration:
                RSARegistration rsaMessage = RSARegistration.Desserialize(payload, len);
                RSARegistration rsaReply;
                switch (rsaMessage.step)
                {
                case RSARegistration.Step.ServerKey:
                    ServerPublicRSAKey = new RSAEncryption.RSAKeys(_public: rsaMessage.Data);

                    rsaReply = new RSARegistration(RSARegistration.Step.ClientResponse, RSAKeys.PublicBytes);
                    rsaReply.Encrypt(ServerPublicRSAKey);
                    Send(ref rsaReply);
                    break;

                case RSARegistration.Step.AESKey:
                    rsaMessage.Decrypt(RSAKeys);

                    AESKey = System.Text.Encoding.Unicode.GetString(rsaMessage.Data);
                    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(payload, len);
                        }
                        else
                        {
                            SyncMessagesToProcess.Enqueue(new ClientSyncMessageCall(h, payload, len));
                        }
                    }
                }

                for (int i = DynamicMessagesInProgresses.Count - 1; i >= 0; --i)
                {
                    Handler dh = DynamicMessagesInProgresses[i];

                    if (dh.MessageID == header.ID)
                    {
                        if (header.IsAsync)
                        {
                            dh.Call(payload, len);
                        }
                        else
                        {
                            SyncMessagesToProcess.Enqueue(new ClientSyncMessageCall(dh, payload, len));
                        }
                        DynamicMessagesInProgresses.RemoveAt(i);
                    }
                }
                break;
            }
        }