Ejemplo n.º 1
0
        /// <summary>
        /// Implements memcached's SASL auth sequence. (See the protocol docs for more details.)
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        private bool Auth(IPooledSocket socket)
        {
            SaslStep currentStep = new SaslStart(this.authenticationProvider);

            socket.Write(currentStep.GetBuffer());

            while (!currentStep.ReadResponse(socket).Success)
            {
                // challenge-response authentication
                if (currentStep.StatusCode == 0x21)
                {
                    currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
                    socket.Write(currentStep.GetBuffer());
                }
                else
                {
                    if (log.IsWarnEnabled)
                        log.WarnFormat("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);

                    // invalid credentials or other error
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implements memcached's SASL auth sequence. (See the protocol docs for more details.)
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        private bool Auth(IPooledSocket socket)
        {
            SaslStep currentStep = new SaslStart(this.authenticationProvider);

            socket.Write(currentStep.GetBuffer());

            while (!currentStep.ReadResponse(socket).Success)
            {
                // challenge-response authentication
                if (currentStep.StatusCode == 0x21)
                {
                    currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
                    socket.Write(currentStep.GetBuffer());
                }
                else
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);
                    }

                    // invalid credentials or other error
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Implements memcached's SASL authenticate sequence (see the protocol docs for more details.)
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        bool Authenticate(PooledSocket socket)
        {
            SaslStep step = new SaslStart(this._authenticationProvider);

            socket.Send(step.GetBuffer());

            while (!step.ReadResponse(socket).Success)
            {
                // challenge-response authentication
                if (step.StatusCode == 0x21)
                {
                    step = new SaslContinue(this._authenticationProvider, step.Data);
                    socket.Send(step.GetBuffer());
                }

                // invalid credentials or other error
                else
                {
                    this._logger.LogWarning("Authentication failed, return code: 0x{0:x}", step.StatusCode);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        bool Authenticate(IPooledSocket socket)
        {
            var isAuthenticated = true;
            const int authContinue = 0x21;

            SaslStep step = new SaslStart(_provider);
            socket.Write(step.GetBuffer());
            while (!step.ReadResponse(socket).Success)
            {
                if (step.StatusCode == authContinue)
                {
                    step = new SaslContinue(_provider, step.Data);
                    socket.Write(step.GetBuffer());
                }
                else
                {
                    isAuthenticated = false;
                    break;
                }
            }
            return isAuthenticated;
        }