Provides data for the VncServerSession.PasswordProvided event.
Inheritance: System.EventArgs
Beispiel #1
0
        /// <summary>
        /// Raises the <see cref="PasswordProvided"/> event.
        /// </summary>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        protected virtual void OnPasswordProvided(PasswordProvidedEventArgs e)
        {
            var ev = this.PasswordProvided;

            if (ev != null)
            {
                ev(this, e);
            }
        }
        protected void RaisePasswordProvided(PasswordProvidedEventArgs e)
        {
            var ev = PasswordProvided;

            if (ev != null)
            {
                ev(this, e);
            }
        }
Beispiel #3
0
        private void NegotiateSecurity(AuthenticationMethod[] methods)
        {
            this.logger?.Log(LogLevel.Info, () => "Negotiating security");

            this.c.SendByte((byte)methods.Length);
            VncStream.Require(
                methods.Length > 0,
                "Client is not allowed in.",
                VncFailureReason.NoSupportedAuthenticationMethods);
            foreach (var method in methods)
            {
                this.c.SendByte((byte)method);
            }

            var selectedMethod = (AuthenticationMethod)this.c.ReceiveByte();

            VncStream.Require(
                methods.Contains(selectedMethod),
                "Invalid authentication method.",
                VncFailureReason.UnrecognizedProtocolElement);

            bool success = true;

            if (selectedMethod == AuthenticationMethod.Password)
            {
                var challenge = this.passwordChallenge.GenerateChallenge();
                using (new Utility.AutoClear(challenge))
                {
                    this.c.Send(challenge);

                    var response = this.c.Receive(16);
                    using (new Utility.AutoClear(response))
                    {
                        var e = new PasswordProvidedEventArgs(this.passwordChallenge, challenge, response);
                        this.OnPasswordProvided(e);
                        success = e.IsAuthenticated;
                    }
                }
            }

            this.c.SendUInt32BE(success ? 0 : (uint)1);
            VncStream.Require(
                success,
                "Failed to authenticate.",
                VncFailureReason.AuthenticationFailed);

            this.logger?.Log(LogLevel.Info, () => "The user authenticated successfully.");
            this.securityNegotiated = true;
        }
        void NegotiateSecurity(AuthenticationMethod[] methods)
        {
            _c.SendByte((byte)methods.Length);
            //验证密码
            VncStream.Require(methods.Length > 0,
                              "Client is not allowed in.",
                              VncFailureReason.NoSupportedAuthenticationMethods);
            foreach (var method in methods)
            {
                _c.SendByte((byte)method);
            }

            var selectedMethod = (AuthenticationMethod)_c.ReceiveByte();

            VncStream.Require(methods.Contains(selectedMethod),
                              "Invalid authentication method.",
                              VncFailureReason.UnrecognizedProtocolElement);

            bool success = true;

            if (selectedMethod == AuthenticationMethod.Password)
            {
                var challenge = VncPasswordChallenge.GenerateChallenge();
                using (new Utility.AutoClear(challenge))
                {
                    _c.Send(challenge);

                    var response = _c.Receive(16);
                    using (new Utility.AutoClear(response))
                    {
                        var e = new PasswordProvidedEventArgs(challenge, response);
                        OnPasswordProvided(e);
                        success = e.IsAuthenticated;
                    }
                }
            }

            _c.SendUInt32BE(success ? 0 : (uint)1);

            if (!success)
            {
                _c.SendString("Password authentication failed!", true);
            }

            VncStream.Require(success,
                              "Failed to authenticate.",
                              VncFailureReason.AuthenticationFailed);
        }
        private void NegotiateSecurity(AuthenticationMethod[] methods)
        {
            Logger.Info("Negotiating security");

            this.c.SendByte((byte)methods.Length);
            VncStream.Require(
                methods.Length > 0,
                                  "Client is not allowed in.",
                                  VncFailureReason.NoSupportedAuthenticationMethods);
            foreach (var method in methods)
            {
                this.c.SendByte((byte)method);
            }

            var selectedMethod = (AuthenticationMethod)this.c.ReceiveByte();
            VncStream.Require(
                methods.Contains(selectedMethod),
                              "Invalid authentication method.",
                              VncFailureReason.UnrecognizedProtocolElement);

            bool success = true;
            if (selectedMethod == AuthenticationMethod.Password)
            {
                var challenge = VncPasswordChallenge.GenerateChallenge();
                using (new Utility.AutoClear(challenge))
                {
                    this.c.Send(challenge);

                    var response = this.c.Receive(16);
                    using (new Utility.AutoClear(response))
                    {
                        var e = new PasswordProvidedEventArgs(challenge, response);
                        this.OnPasswordProvided(e);
                        success = e.IsAuthenticated;
                    }
                }
            }

            this.c.SendUInt32BE(success ? 0 : (uint)1);
            VncStream.Require(
                success,
                              "Failed to authenticate.",
                              VncFailureReason.AuthenticationFailed);

            Logger.Info("The user authenticated successfully.");
        }
 /// <summary>
 /// Raises the <see cref="PasswordProvided"/> event.
 /// </summary>
 /// <param name="e">
 /// The event arguments.
 /// </param>
 protected virtual void OnPasswordProvided(PasswordProvidedEventArgs e)
 {
     var ev = this.PasswordProvided;
     if (ev != null)
     {
         ev(this, e);
     }
 }
 protected virtual void OnPasswordProvided(PasswordProvidedEventArgs e)
 {
     RaisePasswordProvided(e);
 }
Beispiel #8
0
 /// <summary>
 /// Raises the <see cref="PasswordProvided"/> event.
 /// </summary>
 /// <param name="e">
 /// The event arguments.
 /// </param>
 protected virtual void OnPasswordProvided(PasswordProvidedEventArgs e)
 {
     this.PasswordProvided?.Invoke(this, e);
 }
Beispiel #9
0
        /// <summary>
        /// Negotiates the security mechanism used to authenticate the client, and authenticates the client.
        /// </summary>
        /// <param name="methods">
        /// The authentication methods supported by this server.
        /// </param>
        /// <returns>
        /// <see langword="true"/> if the client authenticated successfully; otherwise, <see langword="false"/>.
        /// </returns>
        /// <seealso href="https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst#712security"/>
        internal bool NegotiateSecurity(AuthenticationMethod[] methods)
        {
            this.logger?.LogInformation("Negotiating security");

            this.c.SendByte((byte)methods.Length);

            if (methods.Length == 0)
            {
                this.logger?.LogWarning("The server and client could not agree on any authentication method.");
                this.c.SendString("The server and client could not agree on any authentication method.", includeLength: true);
                return(false);
            }

            foreach (var method in methods)
            {
                this.c.SendByte((byte)method);
            }

            var selectedMethod = (AuthenticationMethod)this.c.ReceiveByte();

            if (!methods.Contains(selectedMethod))
            {
                this.c.SendUInt32BE(1);
                this.logger?.LogInformation("Invalid authentication method.");
                this.c.SendString("Invalid authentication method.", includeLength: true);
                return(false);
            }

            bool success = true;

            if (selectedMethod == AuthenticationMethod.Password)
            {
                var challenge = this.passwordChallenge.GenerateChallenge();
                using (new Utility.AutoClear(challenge))
                {
                    this.c.Send(challenge);

                    var response = this.c.Receive(16);
                    using (new Utility.AutoClear(response))
                    {
                        var e = new PasswordProvidedEventArgs(this.passwordChallenge, challenge, response);
                        this.OnPasswordProvided(e);
                        success = e.IsAuthenticated;
                    }
                }
            }

            this.c.SendUInt32BE(success ? 0 : 1U);

            if (!success)
            {
                this.logger?.LogInformation("The user failed to authenticate.");
                this.c.SendString("Failed to authenticate", includeLength: true);
                return(false);
            }

            this.logger?.LogInformation("The user authenticated successfully.");
            this.securityNegotiated = true;

            return(true);
        }
Beispiel #10
0
 static void HandlePasswordProvided(object sender, PasswordProvidedEventArgs e)
 {
     e.Accept(Password.ToCharArray());
 }
Beispiel #11
0
 /// <summary>
 /// Raises the <see cref="PasswordProvided"/> event.
 /// </summary>
 /// <param name="sender">
 /// The sender of the event.
 /// </param>
 /// <param name="e">
 /// The event arguments.
 /// </param>
 protected virtual void OnPasswordProvided(object sender, PasswordProvidedEventArgs e)
 {
     this.PasswordProvided?.Invoke(sender, e);
 }