This is the Secure Remote Password Protocol Request object. If Claire is someone that tries to connect, then Claire's username and a random runtime-generated public key is packed into this packet.
Inheritance: Packet
Esempio n. 1
0
        /// <summary>
        /// Initiates the SRPP Request
        /// </summary>
        /// <param name="username">Username to login with</param>
        /// <param name="password">Password to login with</param>
        /// <param name="otherdata">Other data passed to LogonManager</param>
        /// <returns></returns>
        internal NetSRP.Request GenerateSRPRequest(String username, String password, Byte[] otherdata)
        {
            if ((this.HandshakeState != Handshake.State.NotInitialized) && (Handshake.State.AllowRequest & this.HandshakeState) != this.HandshakeState)
            {
                return(_request); // Already Created
            }
            if (username == null || password == null)
            {
                throw new NetSRP.HandShakeException("Need username and password to created SRP.Request");
            }

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

            // First get the public key A from random private a
            _cache.a = NetSRP.Geta();
            _cache.A = NetSRP.CalcA(N, g, _cache.a);

            // Save the password to use when the response comes in
            _cache.UserData = password;

            // Create a new request
            _request = new NetSRP.Request(username, _cache.A, otherdata);

            return(_request);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a completed handshake
        /// </summary>
        /// <param name="username"></param>
        /// <param name="key"></param>
        public Handshake(String username, Byte[] key)
        {
            _cache = new NetSRP.State();
            _cache.K = key;
            _request = new NetSRP.Request(username, null);

            this.HandshakeState = State.Succeeded;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a completed handshake
        /// </summary>
        /// <param name="username"></param>
        /// <param name="key"></param>
        public Handshake(String username, Byte[] key)
        {
            _cache   = new NetSRP.State();
            _cache.K = key;
            _request = new NetSRP.Request(username, null);

            this.HandshakeState = State.Succeeded;
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <summary>
        /// Processes a handshake that was not initated locally
        /// </summary>
        /// <param name="msg">Incomming msg with handshake</param>
        internal static NetSRP.Response HandshakeFromActive(NetIncomingMessage msg)
        {
            // Read request
            NetSRP.Request request = new NetSRP.Request();
            request.ExtractPacketData(msg);

            // Create response
            return((msg.SenderConnection.Tag as Handshake).ResponseFromRequest(request));
        }
        /// <summary>
        /// Processes a handshake that was not initated locally
        /// </summary>
        /// <param name="msg">Incomming msg with handshake</param>
        internal static NetSRP.Response HandshakeFromActive(NetIncomingMessage msg)
        {
            // Read request
            NetSRP.Request request = new NetSRP.Request();
            request.ExtractPacketData(msg);

            // Create response
            return (msg.SenderConnection.Tag as Handshake).ResponseFromRequest(request);
        }
        /// <summary>
        /// Initiates the SRPP Request
        /// </summary>
        /// <param name="username">Username to login with</param>
        /// <param name="password">Password to login with</param>
        /// <param name="otherdata">Other data passed to LogonManager</param>
        /// <returns></returns>
        internal NetSRP.Request GenerateSRPRequest(String username, String password, Byte[] otherdata)
        {
            if ((this.HandshakeState != Handshake.State.NotInitialized) && (Handshake.State.AllowRequest & this.HandshakeState) != this.HandshakeState)
                return _request; // Already Created

            if (username == null || password == null)
                throw new NetSRP.HandShakeException("Need username and password to created SRP.Request");

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

            // First get the public key A from random private a
            _cache.a = NetSRP.Geta();
            _cache.A = NetSRP.CalcA(N, g, _cache.a);

            // Save the password to use when the response comes in
            _cache.UserData = password;

            // Create a new request
            _request = new NetSRP.Request(username, _cache.A, otherdata);

            return _request;
        }
 /// <summary>
 /// Returns Verifier and Salt for request
 /// </summary>
 /// <param name="request">Request data</param>
 /// <param name="salt">salt output</param>
 /// <returns>verifier</returns>
 private NetBigInteger Lookup(NetSRP.Request request, out Byte[] salt)
 {
     return(_logonManager.Lookup(request.Username, request.OtherData, out salt));
 }