Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
        }