private string[] FixHostKeyAlgorithms(string[] algorithms)
        {
            if (algorithms == null)
            {
                return(null);
            }

            var algorithmVals =
                LocalSSHUtil.AppendMissingPublicKeyAlgorithm(
                    LocalSSHUtil.ParsePublicKeyAlgorithm(algorithms));

            return(algorithmVals.Select(a => a.ToString()).ToArray());
        }
        protected override void Negotiate()
        {
            ITerminalParameter term = (ITerminalParameter)_destination.GetAdapter(typeof(ITerminalParameter));
            ITCPParameter      tcp  = (ITCPParameter)_destination.GetAdapter(typeof(ITCPParameter));

            SSHConnectionParameter con = new SSHConnectionParameter();

#if DEBUG
            // con.EventTracer = new SSHDebugTracer();
#endif
            con.Protocol                    = _destination.Method;
            con.CheckMACError               = PEnv.Options.SSHCheckMAC;
            con.UserName                    = _destination.Account;
            con.Password                    = _destination.PasswordOrPassphrase;
            con.AuthenticationType          = _destination.AuthenticationType;
            con.IdentityFile                = _destination.IdentityFileName;
            con.TerminalWidth               = term.InitialWidth;
            con.TerminalHeight              = term.InitialHeight;
            con.TerminalName                = term.TerminalType;
            con.WindowSize                  = PEnv.Options.SSHWindowSize;
            con.PreferableCipherAlgorithms  = LocalSSHUtil.ParseCipherAlgorithm(PEnv.Options.CipherAlgorithmOrder);
            con.PreferableHostKeyAlgorithms = LocalSSHUtil.ParsePublicKeyAlgorithm(PEnv.Options.HostKeyAlgorithmOrder);
            con.AgentForward                = _destination.AgentForward;
            if (ProtocolsPlugin.Instance.ProtocolOptions.LogSSHEvents)
            {
                con.EventTracer = new SSHEventTracer(tcp.Destination);
            }
            if (_keycheck != null)
            {
                con.KeyCheck += new HostKeyCheckCallback(this.CheckKey);
            }


            SSHTerminalConnection r   = new SSHTerminalConnection(_destination);
            SSHConnection         ssh = SSHConnection.Connect(con, r.ConnectionEventReceiver, _socket);
            if (ssh != null)
            {
                if (PEnv.Options.RetainsPassphrase && _destination.AuthenticationType != AuthenticationType.KeyboardInteractive)
                {
                    ProtocolsPlugin.Instance.PassphraseCache.Add(tcp.Destination, _destination.Account, _destination.PasswordOrPassphrase);                     //接続成功時のみセット
                }
                //_destination.PasswordOrPassphrase = ""; 接続の複製のためにここで消さずに残しておく
                r.AttachTransmissionSide(ssh);
                r.UsingSocks = _socks != null;
                _result      = r;
            }
            else
            {
                throw new IOException(PEnv.Strings.GetString("Message.SSHConnector.Cancelled"));
            }
        }
Exemple #3
0
        protected override void Negotiate()
        {
            ITerminalParameter term = (ITerminalParameter)_destination.GetAdapter(typeof(ITerminalParameter));
            ITCPParameter      tcp  = (ITCPParameter)_destination.GetAdapter(typeof(ITCPParameter));

            SSHTerminalConnection terminalConnection = new SSHTerminalConnection(_destination);

            SSHConnectionParameter con =
                new SSHConnectionParameter(
                    tcp.Destination,
                    tcp.Port,
                    _destination.Method,
                    _destination.AuthenticationType,
                    _destination.Account,
                    _destination.PasswordOrPassphrase);

#if DEBUG
            // con.EventTracer = new SSHDebugTracer();
#endif
            con.Protocol                       = _destination.Method;
            con.CheckMACError                  = PEnv.Options.SSHCheckMAC;
            con.UserName                       = _destination.Account;
            con.Password                       = _destination.PasswordOrPassphrase;
            con.AuthenticationType             = _destination.AuthenticationType;
            con.IdentityFile                   = _destination.IdentityFileName;
            con.TerminalWidth                  = term.InitialWidth;
            con.TerminalHeight                 = term.InitialHeight;
            con.TerminalName                   = term.TerminalType;
            con.WindowSize                     = PEnv.Options.SSHWindowSize;
            con.PreferableCipherAlgorithms     = LocalSSHUtil.ParseCipherAlgorithm(PEnv.Options.CipherAlgorithmOrder);
            con.PreferableHostKeyAlgorithms    = LocalSSHUtil.ParsePublicKeyAlgorithm(PEnv.Options.HostKeyAlgorithmOrder);
            con.AgentForwardingAuthKeyProvider = _destination.AgentForwardingAuthKeyProvider;
            if (_keycheck != null)
            {
                con.VerifySSHHostKey = (info) => {
                    return(_keycheck.Vefiry(info));
                };
            }
            con.KeyboardInteractiveAuthenticationHandlerCreator =
                sshconn => terminalConnection.GetKeyboardInteractiveAuthenticationHandler();

            ISSHProtocolEventLogger protocolEventLogger;
            if (ProtocolsPlugin.Instance.ProtocolOptions.LogSSHEvents)
            {
                protocolEventLogger = new SSHEventTracer(tcp.Destination);
            }
            else
            {
                protocolEventLogger = null;
            }

            var connection = SSHConnection.Connect(_socket, con,
                                                   sshconn => terminalConnection.ConnectionEventReceiver,
                                                   sshconn => protocolEventLogger);
            if (PEnv.Options.RetainsPassphrase && _destination.AuthenticationType != AuthenticationType.KeyboardInteractive)
            {
                ProtocolsPlugin.Instance.PassphraseCache.Add(tcp.Destination, _destination.Account, _destination.PasswordOrPassphrase); //接続成功時のみセット
            }
            //_destination.PasswordOrPassphrase = ""; 接続の複製のためにここで消さずに残しておく
            terminalConnection.AttachTransmissionSide(connection, connection.AuthenticationStatus);
            _result = terminalConnection;
        }
Exemple #4
0
        protected override void Negotiate()
        {
            ITerminalParameter term = (ITerminalParameter)_destination.GetAdapter(typeof(ITerminalParameter));
            ITCPParameter      tcp  = (ITCPParameter)_destination.GetAdapter(typeof(ITCPParameter));

            SSHTerminalConnection terminalConnection = new SSHTerminalConnection(_destination);

            SSHConnectionParameter con =
                new SSHConnectionParameter(
                    tcp.Destination,
                    tcp.Port,
                    _destination.Method,
                    _destination.AuthenticationType,
                    _destination.Account,
                    _destination.PasswordOrPassphrase);

#if DEBUG
            // con.EventTracer = new SSHDebugTracer();
#endif
            con.Protocol                   = _destination.Method;
            con.CheckMACError              = PEnv.Options.SSHCheckMAC;
            con.UserName                   = _destination.Account;
            con.Password                   = _destination.PasswordOrPassphrase;
            con.AuthenticationType         = _destination.AuthenticationType;
            con.IdentityFile               = _destination.IdentityFileName;
            con.TerminalWidth              = term.InitialWidth;
            con.TerminalHeight             = term.InitialHeight;
            con.TerminalName               = term.TerminalType;
            con.WindowSize                 = PEnv.Options.SSHWindowSize;
            con.Timeouts.ResponseTimeout   = PEnv.Options.SSHResponseTimeout;
            con.PreferableCipherAlgorithms =
                LocalSSHUtil.AppendMissingCipherAlgorithm(
                    LocalSSHUtil.ParseCipherAlgorithm(PEnv.Options.CipherAlgorithmOrder));
            con.PreferableHostKeyAlgorithms =
                LocalSSHUtil.AppendMissingPublicKeyAlgorithm(
                    LocalSSHUtil.ParsePublicKeyAlgorithm(PEnv.Options.HostKeyAlgorithmOrder));
            con.AgentForwardingAuthKeyProvider = _destination.AgentForwardingAuthKeyProvider;
            con.X11ForwardingParams            = _destination.X11Forwarding;
            if (_keycheck != null)
            {
                con.VerifySSHHostKey = (info) => {
                    return(_keycheck.Vefiry(info));
                };
            }
            con.KeyboardInteractiveAuthenticationHandlerCreator =
                sshconn => terminalConnection.GetKeyboardInteractiveAuthenticationHandler();

            ISSHProtocolEventLogger protocolEventLogger;
            if (ProtocolsPlugin.Instance.ProtocolOptions.LogSSHEvents)
            {
                protocolEventLogger = new SSHEventTracer(tcp.Destination);
            }
            else
            {
                protocolEventLogger = null;
            }

            var connection = SSHConnection.Connect(_socket, con,
                                                   sshconn => terminalConnection.ConnectionEventReceiver,
                                                   sshconn => protocolEventLogger);

            // Note: password must not be cleared here. it will be required when duplicating connection later.

            // The login settings was accepted.
            // No need to ask a password on the new attempt to login from the shortcut functionality.
            _destination.LetUserInputPassword = false;

            terminalConnection.AttachTransmissionSide(connection, connection.AuthenticationStatus);
            _result = terminalConnection;
        }