Exemple #1
0
        /// <summary>
        /// Starts the synchronous authentication process.
        /// </summary>
        /// <exception cref="ProxyException">Authentication with the proxy server failed.</exception>
        /// <exception cref="ProtocolViolationException">The proxy server uses an invalid protocol.</exception>
        /// <exception cref="SocketException">An operating system error occurs while accessing the Socket.</exception>
        /// <exception cref="ObjectDisposedException">The Socket has been closed.</exception>
        private void Authenticate()
        {
            Server.Send(new byte [] { 5, 2, 0, 2 });
            byte[] buffer = ReadBytes(2);
            if (buffer[1] == 255)
            {
                throw new ProxyException("No authentication method accepted.");
            }
            AuthMethod authenticate;

            switch (buffer[1])
            {
            case 0:
                authenticate = new AuthNone(Server);
                break;

            case 2:
                authenticate = new AuthUserPass(Server, Username, Password);
                break;

            default:
                throw new ProtocolViolationException();
            }
            authenticate.Authenticate();
        }
Exemple #2
0
        /// <summary>
        /// Starts the synchronous authentication process.
        /// </summary>
        /// <exception cref="ProxyException">Authentication with the proxy server failed.</exception>
        /// <exception cref="ProtocolViolationException">The proxy server uses an invalid protocol.</exception>
        /// <exception cref="SocketException">An operating system error occurs while accessing the Socket.</exception>
        /// <exception cref="ObjectDisposedException">The Socket has been closed.</exception>
        private void Authenticate(byte[] buffer)
        {
            buffer[0] = 5;
            buffer[1] = 2;
            buffer[2] = 0;
            buffer[3] = 2;
            if (Server.Send(buffer, 0, 4, SocketFlags.None) < 4)
            {
                throw new SocketException(10054);
            }

            ReadBytes(buffer, 2);
            if (buffer[1] == 255)
            {
                throw new ProxyException("No authentication method accepted.");
            }

            AuthMethod authenticate;

            switch (buffer[1])
            {
            case 0:
                authenticate = new AuthNone(Server);
                break;

            case 2:
                authenticate = new AuthUserPass(Server, Username, Password);
                break;

            default:
                throw new ProtocolViolationException();
            }

            authenticate.Authenticate();
        }