Esempio n. 1
0
        private void ServerGreetingReceived(AsynchronousSocket socket)
        {
            if (socket.ReceiveBufferLength != 80)
            {
                OnDebug("Server did not send a proper greeting");
                socket.Disconnect();
                return;
            }
            string salt      = SRP6.BytesToHex(SRP6.SubArray(socket.ReceiveBuffer, 0, 32));
            string pubKey    = SRP6.BytesToHex(SRP6.SubArray(socket.ReceiveBuffer, 32, 32));
            string scrambler = SRP6.BytesToHex(SRP6.SubArray(socket.ReceiveBuffer, 64, 16));

            // Setup the SessionKey
            srpClient = new SRP6(IdentityHash, Modulus, 0x07, salt);
            srpClient.SetSessionKey(pubKey, scrambler);
            OnDebug("Salt = " + salt);
            OnDebug("Server's PublicKey = " + pubKey);
            OnDebug("Scrambler = " + scrambler);

            step++;

            // Send my public key to the server
            OnDebug("Client->PublicKey");
            OnDebug("PublicKey = " + srpClient.GetPublicKey());
            byte[] reply = srpClient.PublicKey.ToUnsignedByteArray();
            socket.Send(reply, 0, reply.Length);
            OnDebug("SessionKey = " + srpClient.GetSessionKey());
        }
Esempio n. 2
0
        private void InitializeSrpServer(AsynchronousSocket socket)
        {
            byte[] identityHash = SRP6.SubArray(socket.ReceiveBuffer, 0, socket.ReceiveBufferLength);
            OnDebug("IdentityHash = " + SRP6.BytesToHex(identityHash));

            // Verify that the server knows this identity before proceeding
            if (!OnAuthenticationRequest(socket, identityHash))
            {
                return;
            }

            // Server generates (and sends to client) public-key, scrambler, and salt
            srpServer = new SRP6(identityHash, Modulus, 0x07, 256, 128);
            socket.Step++;

            byte[] salt        = srpServer.Salt.ToUnsignedByteArray();
            byte[] pubKey      = srpServer.PublicKey.ToUnsignedByteArray();
            byte[] scrambler   = srpServer.Scrambler.ToUnsignedByteArray();
            byte[] replyPacket = SRP6.ConcatArray(salt, pubKey, scrambler);

            OnDebug("Server->Salt, PublicKey, and Scrambler");
            OnDebug("Salt = " + srpServer.GetSalt());
            OnDebug("PublicKey = " + srpServer.GetPublicKey());
            OnDebug("Scrambler = " + srpServer.GetScrambler());
            socket.Send(replyPacket, 0, replyPacket.Length);
        }
Esempio n. 3
0
        void socket_Connected(object sender, EventArgs e)
        {
            AsynchronousSocket socket = sender as AsynchronousSocket;

            if (Connected != null)
            {
                Connected.Invoke(this, new EventArgs());
            }

            // Send the server my identity hash
            socket.Send(IdentityHash, 0, IdentityHash.Length);
            OnDebug("Client->IdentityHash");
            OnDebug("IndetityHash = " + SRP6.BytesToHex(IdentityHash));
        }
Esempio n. 4
0
        private void ProcessClientsPublicKey(AsynchronousSocket socket)
        {
            byte[] pubKey = SRP6.SubArray(socket.ReceiveBuffer, 0, socket.ReceiveBufferLength);

            string pubKeyString = SRP6.BytesToHex(pubKey);

            srpServer.SetSessionKey(pubKeyString);

            socket.SessionKey = srpServer.SessionKey.ToUnsignedByteArray();
            OnDebug("Client's PublicKey = " + pubKeyString);
            OnDebug("SessionKey = " + srpServer.GetSessionKey());
            socket.Step++;

            // From this point on, both client and server use encrypted communications
            OnDebug("Sending READY to client");
            socket.Send("READY");
        }