This is the Secure Remote Password Protocol Response object. Remember Claire? She has send a request to Bob, the one she want to connect to. When Bob receives Claire's username and public Key, he will send Claire her personal Salt and a random runtime-generated public key.
Inheritance: Packet
Esempio n. 1
0
        /// <summary>
        /// Create a response on received request.
        /// </summary>
        /// <param name="request">Receieved Request</param>
        /// <returns></returns>
        private NetSRP.Response ResponseFromRequest(NetSRP.Request request)
        {
            if (Handshake._defaultLogonManager == null)
            {
                throw new NetSRP.HandShakeException("No HandShake.Passive functions are available until LogonManager is provided.");
            }

            if (this.HandshakeState != Handshake.State.NotInitialized && (Handshake.State.AllowResponse & this.HandshakeState) != this.HandshakeState)
            {
                return(_response);
            }

            // Set State and start timer
            this.HandshakeState   = Handshake.State.Responding;
            _cache.ExpirationTime = DateTime.Now.AddSeconds(Handshake.ExpirationInSeconds);

            if (request.A.Mod(N).IntValue == 0)
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("Request contains invalid data", new ArgumentException("A mod N is zero."));
            }

            Byte[]        salt;
            NetBigInteger v;

            // Get verifier
            try
            {
                v = Lookup(request, out salt);
            }
            catch (Exception exception)
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("LogonManager failed lookup.", exception);
            }

            if (v == null)
            {
                this.HandshakeState = Handshake.State.Denied;
                throw new NetSRP.HandShakeException("Wrong username or password."); // Clearly its username.
            }

            // Cache request
            _request        = request;
            _cache.UserData = _request.Username;

            // Get public ket B from random private b
            _cache.b = NetSRP.Getb();
            _cache.B = NetSRP.CalcB(N, g, _cache.b, v);

            // Create the response message
            _response = new NetSRP.Response(salt, _cache.B);

            // First create the key
            KeyFromRequest(request.A, v);

            return(_response);
        }
        /// <summary>
        /// Processes a handshake response (initiated locally)
        /// </summary>
        /// <param name="msg">Incoming message with resonse data</param>
        internal static NetSRP.Verification HandshakeFromPassive(NetIncomingMessage msg)
        {
            // Get response
            NetSRP.Response response = new NetSRP.Response();
            response.ExtractPacketData(msg);

            // Create Verification data
            return (msg.SenderConnection.Tag as Handshake).KeyFromResponse(response);
        }
Esempio n. 3
0
        /// <summary>
        /// Processes a handshake response (initiated locally)
        /// </summary>
        /// <param name="msg">Incoming message with resonse data</param>
        internal static NetSRP.Verification HandshakeFromPassive(NetIncomingMessage msg)
        {
            // Get response
            NetSRP.Response response = new NetSRP.Response();
            response.ExtractPacketData(msg);

            // Create Verification data
            return((msg.SenderConnection.Tag as Handshake).KeyFromResponse(response));
        }
Esempio n. 4
0
        /// <summary>
        /// Generates Session key from response
        /// </summary>
        /// <param name="response"></param>
        /// <response></response>
        private NetSRP.Verification KeyFromResponse(NetSRP.Response response)
        {
            if ((Handshake.State.AllowVerificating & this.HandshakeState) != this.HandshakeState)
            {
                return(_verification); // Double Request
            }
            // When we get the response, get their public key B
            if (response.B.Mod(N).IntValue == 0)
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("Response contains invalid data", new ArgumentException("B mod N is zero."));
            }

            // Shared random scrambler
            NetBigInteger u = NetSRP.Calcu(_cache.A, response.B);

            if (u.IntValue == 0)
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("Response contains invalid data", new ArgumentException("u is zero."));
            }

            // Private key x
            NetBigInteger x = NetSRP.Calcx(response.Salt, _request.Username, _cache.UserData);

            // Cache Response;
            _response = response;

            // Session key
            _cache.S = NetSRP.CalcSClient(N, g, response.B, k, x, _cache.a, u);
            _cache.K = NetSRP.CalcK(_cache.S);


            // Create the verification
            _verification = new NetSRP.Verification(NetSRP.CalcM(N, g, _request.Username, response.Salt, _cache.A, response.B, _cache.K));

            // Set State
            this.HandshakeState = Handshake.State.Verificating;
            return(_verification);
        }
        /// <summary>
        /// Create a response on received request.
        /// </summary>
        /// <param name="request">Receieved Request</param>
        /// <returns></returns>
        private NetSRP.Response ResponseFromRequest(NetSRP.Request request)
        {
            if (Handshake._defaultLogonManager == null)
                throw new NetSRP.HandShakeException("No HandShake.Passive functions are available until LogonManager is provided.");

            if (this.HandshakeState != Handshake.State.NotInitialized && (Handshake.State.AllowResponse & this.HandshakeState) != this.HandshakeState)
                return _response;

            // Set State and start timer
            this.HandshakeState = Handshake.State.Responding;
            _cache.ExpirationTime = DateTime.Now.AddSeconds(Handshake.ExpirationInSeconds);

            if (request.A.Mod(N).IntValue == 0)
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("Request contains invalid data", new ArgumentException("A mod N is zero."));
            }

            Byte[] salt;
            NetBigInteger v;

            // Get verifier
            try
            {
                v = Lookup(request, out salt);
            }
            catch (Exception exception)
            {
                this.HandshakeState = Handshake.State.Failed;
                throw new NetSRP.HandShakeException("LogonManager failed lookup.", exception);
            }

            if (v == null)
            {
                this.HandshakeState = Handshake.State.Denied;
                throw new NetSRP.HandShakeException("Wrong username or password."); // Clearly its username.
            }

            // Cache request
            _request = request;
            _cache.UserData = _request.Username;

            // Get public ket B from random private b
            _cache.b = NetSRP.Getb();
            _cache.B = NetSRP.CalcB(N, g, _cache.b, v);

            // Create the response message
            _response = new NetSRP.Response(salt, _cache.B);

            // First create the key
            KeyFromRequest(request.A, v);

            return _response;
        }