예제 #1
0
        private static void HandleAkep2Message2(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var user = GetUserByIpAndPort(sksMessageReceivedEventArgs.FromIp, sksMessageReceivedEventArgs.FromPort);

            Akep2 akep2;

            lock (akep2sLock)
            {
                akep2 = Akep2s.FirstOrDefault(a => a.User == user);
            }

            if (akep2 == null)
            {
                return;
            }

            var message = Akep2Message2.FromString(sksMessageReceivedEventArgs.Message, user.Key);

            akep2.NonceB = message.NonceB;

            var newMessage = new Akep2Message3(MyUsername, akep2.NonceB, user.Key);

            user.SendMessage(newMessage.ToString());

            akep2.IncrementMessageCount();
        }
예제 #2
0
        private static void HandleChatMessage(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var user = GetUserByIpAndPort(sksMessageReceivedEventArgs.FromIp, sksMessageReceivedEventArgs.FromPort);

            var message = ChatMessage.FromString(sksMessageReceivedEventArgs.Message);

            var secret = user.GetSecretFromProtocol();

            var messageStr = SksAes.DecryptStringFromBytes_Aes(message.EncryptedMessageBytes, secret, message.Iv);

            user.Client.OnChatMessageReceived(user.Client.tcpClient, messageStr);
        }
예제 #3
0
        private static void Client_MessageReceived(object source, SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var client = (SksClient)source;

            if (client.Type == SksClientType.Local)
            {
                LocalClientMessageReceived(sksMessageReceivedEventArgs);
            }
            else if (client.Type == SksClientType.Remote)
            {
                RemoteClientMessageReceived(sksMessageReceivedEventArgs);
            }
        }
예제 #4
0
        private static void HandleHandshakeMessage2(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var user = GetUserByIpAndPort(sksMessageReceivedEventArgs.FromIp, sksMessageReceivedEventArgs.FromPort);

            Handshake handshake;

            lock (handshakesLock)
            {
                handshake = Handshakes.FirstOrDefault(h => h.User == user);
            }

            if (handshake == null)
            {
                Logger.Log(LogTag, "ERROR: Handshake message 2 - handshake doesn't exist");
                return;
            }

            var message = HandshakeMessage2.FromString(sksMessageReceivedEventArgs.Message);

            user.Protocol = message.ProtocolId;

            switch (message.ProtocolId)
            {
            case ProtocolType.None:
                break;

            case ProtocolType.Akep2:
                InitAkep2(user, SksClientType.Local);
                break;

            case ProtocolType.LamportScheme:
                InitLamportScheme(user, SksClientType.Local);
                break;

            case ProtocolType.OtwayRees:
                break;

            case ProtocolType.Rsa:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #5
0
        private static void HandleAkep2Message3(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var user = GetUserByIpAndPort(sksMessageReceivedEventArgs.FromIp, sksMessageReceivedEventArgs.FromPort);

            Akep2 akep2;

            lock (akep2sLock)
            {
                akep2 = Akep2s.FirstOrDefault(a => a.User == user);
            }

            if (akep2 == null)
            {
                return;
            }

            var message = Akep2Message3.FromString(sksMessageReceivedEventArgs.Message, user.Key);

            akep2.IncrementMessageCount();
        }
예제 #6
0
        private static void HandleAkep2Message1(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var user = GetUserByIpAndPort(sksMessageReceivedEventArgs.FromIp, sksMessageReceivedEventArgs.FromPort);

            var akep2 = InitAkep2(user, SksClientType.Remote);

            if (akep2 == null)
            {
                return;
            }

            var message = Akep2Message1.FromString(sksMessageReceivedEventArgs.Message);

            akep2.NonceA = message.NonceA;
            akep2.NonceB = Utils.GenerateRandom16();

            var newMessage = new Akep2Message2(MyUsername, user.Name, akep2.NonceA, akep2.NonceB, user.Key);

            user.SendMessage(newMessage.ToString());

            akep2.IncrementMessageCount();
        }
예제 #7
0
        private static void HandleHandshakeMessage1(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var user = GetUserByIpAndPort(sksMessageReceivedEventArgs.FromIp, sksMessageReceivedEventArgs.FromPort);

            Handshake handshake;

            lock (handshakesLock)
            {
                handshake = Handshakes.FirstOrDefault(h => h.User == user);
            }

            if (handshake != null)
            {
                Logger.Log(LogTag, "ERROR: Handshake message 1 - handshake already existed");
                return;
            }

            handshake = InitHandshake(user, SksClientType.Remote);

            if (handshake == null)
            {
                return;
            }

            var message = HandshakeMessage1.FromString(sksMessageReceivedEventArgs.Message);

            user.Protocol = Utils.DetermineProtocol(user);

            if (user.Protocol == ProtocolType.LamportScheme)
            {
                InitLamportScheme(user, SksClientType.Remote);
            }

            var newMessage = new HandshakeMessage2(user.Protocol, null);

            user.SendMessage(newMessage.ToString());

            handshake.IncrementMessageCount();
        }
예제 #8
0
 private static void HandleHandshakeMessage4(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
 {
     // todo: ukoncenie komunikacie
 }
예제 #9
0
        public static void HandleMessage(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
        {
            var messageType = PemParser.GetMessageType(sksMessageReceivedEventArgs.Message);

            // todo: doriesit otway reese
            switch (messageType)
            {
            case PemMessageType.LongTermKey:
                break;

            case PemMessageType.InitialMessage1:
                break;

            case PemMessageType.InitialMessage2:
                break;

            case PemMessageType.ErrorMessage:
                break;

            case PemMessageType.ChatMessage:
                HandleChatMessage(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.Akep2Message1:
                HandleAkep2Message1(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.Akep2Message2:
                HandleAkep2Message2(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.Akep2Message3:
                HandleAkep2Message3(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.OtwayReesMessage1:
                break;

            case PemMessageType.OtwayReesMessage2:
                //HandleOtwayReeseMessage2(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.OtwayReesMessage3:
                break;

            case PemMessageType.OtwayReesMessage4:
                //HandleOtwayReeseMessage4(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.HandshakeMessage1:
                HandleHandshakeMessage1(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.HandshakeMessage2:
                HandleHandshakeMessage2(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.HandshakeMessage3:
                HandleHandshakeMessage3(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.HandshakeMessage4:
                HandleHandshakeMessage4(sksMessageReceivedEventArgs);
                break;

            case PemMessageType.SshTlsMessage1:
                break;

            case PemMessageType.SshTlsMessage2:
                break;

            case PemMessageType.SshTlsMessage3:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #10
0
 private static void RemoteClientMessageReceived(SksMessageReceivedEventArgs sksMessageReceivedEventArgs)
 {
     HandleMessage(sksMessageReceivedEventArgs);
 }