Beispiel #1
0
        public AuthenticationResult DoConnect(AbstractSocket target)
        {
            _stream = target;

            // Phase2 receives server keys
            ReceiveServerKeys();
            if (_param.KeyCheck != null && !_param.KeyCheck(_cInfo))
            {
                _stream.Close();
                return(GranadosRT.Routrek.SSHC.AuthenticationResult.Failure);
            }

            // Phase3 generates session key
            byte[] session_key = GenerateSessionKey();

            // Phase4 establishes the session key
            try {
                _packetBuilder.SetSignal(false);
                SendSessionKey(session_key);
                InitCipher(session_key);
            }
            finally {
                _packetBuilder.SetSignal(true);
            }
            ReceiveKeyConfirmation();

            // Phase5 user authentication
            SendUserName(_param.UserName);
            if (ReceiveAuthenticationRequirement() == AUTH_REQUIRED)
            {
                if (_param.AuthenticationType == AuthenticationType.Password)
                {
                    SendPlainPassword();
                }
                else if (_param.AuthenticationType == AuthenticationType.PublicKey)
                {
                    DoRSAChallengeResponse();
                }
                bool auth = ReceiveAuthenticationResult();
                if (!auth)
                {
                    throw new Exception(Strings.GetString("AuthenticationFailed"));
                }
            }

            _packetBuilder.Handler = new CallbackSSH1PacketHandler(this);
            return(GranadosRT.Routrek.SSHC.AuthenticationResult.Success);
        }