コード例 #1
0
ファイル: ProtocolsPlugin.cs プロジェクト: sunxking/poderosa
        public IInterruptable AsyncSSHConnect(IInterruptableConnectorClient result_client, ISSHLoginParameter destination)
        {
            InterruptableConnector swt = new SSHConnector(destination, new HostKeyVerifierBridge());
            ITCPParameter          tcp = (ITCPParameter)destination.GetAdapter(typeof(ITCPParameter));

            swt.AsyncConnect(result_client, tcp);
            return(swt);
        }
コード例 #2
0
        internal override ITerminalParameter ConvertToTerminalParameter()
        {
            ITCPParameter tcp = MacroPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();

            tcp.Port        = _port;
            tcp.Destination = _host;
            return((ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)));
        }
コード例 #3
0
        /// <summary>
        /// Establishes the connection to the remote server; initializes a <see cref="ITCPParameter"/> with the connection properties from
        /// <see cref="BaseConnectionForm{T}.Connection"/> and then calls <see cref="IProtocolService.AsyncTelnetConnect(IInterruptableConnectorClient, ITCPParameter)"/>
        /// to start the connection process.
        /// </summary>
        public override void Connect()
        {
            ITCPParameter tcpParameters = PoderosaProtocolService.CreateDefaultTelnetParameter();

            tcpParameters.Destination = Connection.Host;
            tcpParameters.Port        = Connection.Port;

            PoderosaProtocolService.AsyncTelnetConnect(this, tcpParameters);
        }
コード例 #4
0
        /// <summary>
        /// Initiates the SSH connection process by getting the <see cref="IProtocolService"/> instance and calling
        /// <see cref="IProtocolService.AsyncSSHConnect"/>.  This is an asynchronous process:  the <see cref="SuccessfullyExit"/> method is called when the
        /// connection is established successfully and <see cref="ConnectionFailed"/> method is called when we are unable to establish the connection.
        /// </summary>
        public void AsyncConnect()
        {
            ITerminalEmulatorService terminalEmulatorService =
                (ITerminalEmulatorService)_poderosaWorld.PluginManager.FindPlugin("org.poderosa.terminalemulator", typeof(ITerminalEmulatorService));
            IProtocolService protocolService = (IProtocolService)_poderosaWorld.PluginManager.FindPlugin("org.poderosa.protocols", typeof(IProtocolService));

            // Create and initialize the SSH login parameters
            ISSHLoginParameter sshLoginParameter = protocolService.CreateDefaultSSHParameter();

            sshLoginParameter.Account = Username;

            if (!String.IsNullOrEmpty(IdentityFile))
            {
                sshLoginParameter.AuthenticationType = AuthenticationType.PublicKey;
                sshLoginParameter.IdentityFileName   = IdentityFile;
            }

            else
            {
                sshLoginParameter.AuthenticationType = AuthenticationType.Password;

                if (Password != null && Password.Length > 0)
                {
                    IntPtr passwordBytes = Marshal.SecureStringToGlobalAllocAnsi(Password);
                    sshLoginParameter.PasswordOrPassphrase = Marshal.PtrToStringAnsi(passwordBytes);
                }
            }

            sshLoginParameter.Method = (SSHProtocol)Enum.Parse(typeof(SSHProtocol), SshProtocol.ToString("G"));

            // Create and initialize the various socket connection properties
            ITCPParameter tcpParameter = (ITCPParameter)sshLoginParameter.GetAdapter(typeof(ITCPParameter));

            tcpParameter.Destination = HostName;
            tcpParameter.Port        = Port;

            // Set the UI settings to use for the terminal itself
            terminalEmulatorService.TerminalEmulatorOptions.RightButtonAction = MouseButtonAction.Paste;
            _settings = terminalEmulatorService.CreateDefaultTerminalSettings(tcpParameter.Destination, null);

            _settings.BeginUpdate();
            _settings.TerminalType            = (ConnectionParam.TerminalType)Enum.Parse(typeof(ConnectionParam.TerminalType), TerminalType.ToString("G"));
            _settings.RenderProfile           = terminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
            _settings.RenderProfile.BackColor = BackColor;
            _settings.RenderProfile.ForeColor = ForeColor;
            _settings.RenderProfile.FontName  = Font.Name;
            _settings.RenderProfile.FontSize  = Font.Size;
            _settings.EndUpdate();

            ITerminalParameter param = (ITerminalParameter)tcpParameter.GetAdapter(typeof(ITerminalParameter));

            param.SetTerminalName(_settings.TerminalType.ToString("G").ToLower());

            // Initiate the connection process
            protocolService.AsyncSSHConnect(this, sshLoginParameter);
        }
コード例 #5
0
 public TelnetTerminalConnection(ITCPParameter p, TelnetNegotiator neg, PlainPoderosaSocket s)
     : base(p)
 {
     s.SetOwnerConnection(this);
     _telnetReceiver = new TelnetReceiver(this, neg);
     _telnetSocket   = new TelnetSocket(this, s, _telnetReceiver);
     _rawSocket      = s;
     _socket         = _telnetSocket;
     _terminalOutput = _telnetSocket;
 }
コード例 #6
0
        private static string ToKeyString(ISSHLoginParameter param)
        {
            ITCPParameter tcp = (ITCPParameter)param.GetAdapter(typeof(ITCPParameter));
            string        h   = tcp.Destination;

            if (tcp.Port != 22)
            {
                h += ":" + tcp.Port;
            }
            return(h);
        }
コード例 #7
0
            public ITerminalConnection EstablishConnection(IPoderosaMainWindow window, ITerminalParameter destination, ITerminalSettings settings)
            {
                ITCPParameter          tcp = (ITCPParameter)destination.GetAdapter(typeof(ITCPParameter));
                IProtocolService       ps  = TerminalSessionsPlugin.Instance.ProtocolService;
                ISynchronizedConnector sc  = ps.CreateFormBasedSynchronozedConnector(window);
                IInterruptable         t   = ps.AsyncTelnetConnect(sc.InterruptableConnectorClient, tcp);
                ITerminalConnection    con = sc.WaitConnection(t, TerminalSessionsPlugin.Instance.TerminalSessionOptions.TerminalEstablishTimeout);

                AdjustCaptionAndText(settings, tcp.Destination, StartCommandIcon.NewConnection);
                return(con);
            }
コード例 #8
0
        public void AsyncConnect(IInterruptableConnectorClient client, ITCPParameter param) {
            _client = client;
            _tcpDestination = param;
            _host = param.Destination;
            _port = param.Port;

            //AgentForward等のチェックをする
            foreach (IConnectionResultEventHandler ch in ProtocolsPlugin.Instance.ConnectionResultEventHandler.GetExtensions())
                ch.BeforeAsyncConnect((ITerminalParameter)param.GetAdapter(typeof(ITerminalParameter)));

            Thread th = new Thread(new ThreadStart(this.Run));
            th.Start();
        }
コード例 #9
0
        public TelnetTerminalConnection(ITCPParameter p, TelnetNegotiator neg, PlainPoderosaSocket s)
            : base(p)
        {
            s.SetOwnerConnection(this);
            _telnetReceiver = new TelnetReceiver(this, neg);
            ITelnetParameter telnetParams  = (ITelnetParameter)p.GetAdapter(typeof(ITelnetParameter));
            bool             telnetNewLine = (telnetParams != null) ? telnetParams.TelnetNewLine : true /*default*/;

            _telnetSocket   = new TelnetSocket(this, s, _telnetReceiver, telnetNewLine);
            _rawSocket      = s;
            _socket         = _telnetSocket;
            _terminalOutput = _telnetSocket;
        }
コード例 #10
0
        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"));
            }
        }
コード例 #11
0
        private void InitUI()
        {
            ITCPParameter tcp = (ITCPParameter)_sshParam.GetAdapter(typeof(ITCPParameter));

            _hostBox.Text   = tcp.Destination;
            _methodBox.Text = _sshParam.Method.ToString();
            //if(_sshParam.Port!=22) _methodBox.Text += String.Format(TEnv.Strings.GetString("Caption.SSHShortcutLoginDialog.NotStandardPort"), _sshParam.Port);
            _accountBox.Text            = _sshParam.Account;
            _authenticationTypeBox.Text = _sshParam.AuthenticationType.ToString(); //さぼり
            _encodingBox.Text           = EnumListItem <EncodingType> .CreateListItem(this.TerminalSettings.Encoding).Text;

            _logTypeBox.SelectedItem = LogType.None;    // select EnumListItem<T> by T

            if (_sshParam.AuthenticationType == AuthenticationType.Password)
            {
                _privateKeyBox.Enabled    = false;
                _privateKeySelect.Enabled = false;
            }
            else if (_sshParam.AuthenticationType == AuthenticationType.PublicKey)
            {
                _privateKeyBox.Text = _sshParam.IdentityFileName;
            }
            else if (_sshParam.AuthenticationType == AuthenticationType.KeyboardInteractive)
            {
                _privateKeyBox.Enabled    = false;
                _privateKeySelect.Enabled = false;
                _passphraseBox.Enabled    = false;
            }

            _passphraseBox.Text = "";
            if (_sshParam.PasswordOrPassphrase.Length == 0 && TerminalSessionsPlugin.Instance.ProtocolService.ProtocolOptions.RetainsPassphrase)
            {
                string p = TerminalSessionsPlugin.Instance.ProtocolService.PassphraseCache.GetOrEmpty(tcp.Destination, _sshParam.Account);
                _passphraseBox.Text = p;
            }

            IAutoExecMacroParameter autoExecParams = _sshParam.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;

            if (autoExecParams != null && TelnetSSHPlugin.Instance.MacroEngine != null)
            {
                _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty;
            }
            else
            {
                _autoExecMacroPathLabel.Enabled    = false;
                _autoExecMacroPathBox.Enabled      = false;
                _selectAutoExecMacroButton.Enabled = false;
            }

            AdjustUI();
        }
コード例 #12
0
        public void ApplyParam(IAdaptable destination, ITerminalSettings terminal)
        {
            _initializing = true;
            Debug.Assert(destination != null);
            Debug.Assert(terminal != null);
            this.TerminalSettings = terminal.Clone();

            ITCPParameter      tcp_destination = (ITCPParameter)destination.GetAdapter(typeof(ITCPParameter));
            ISSHLoginParameter ssh_destination = (ISSHLoginParameter)destination.GetAdapter(typeof(ISSHLoginParameter));
            bool is_telnet = ssh_destination == null;

            _methodBox.SelectedIndex = is_telnet? 0 : ssh_destination.Method == SSHProtocol.SSH1? 1 : 2;
            _portBox.SelectedIndex   = _portBox.FindStringExact(PortDescription(tcp_destination.Port));
            if (ssh_destination != null)
            {
                _userNameBox.SelectedIndex = _userNameBox.FindStringExact(ssh_destination.Account);
                _passphraseBox.Text        = ssh_destination.PasswordOrPassphrase;

                if (ssh_destination.AuthenticationType == AuthenticationType.PublicKey)
                {
                    _privateKeyFile.Text = ssh_destination.IdentityFileName;
                }
                else
                {
                    _privateKeyFile.Text = "";
                }
                _authOptions.SelectedIndex = ToAuthenticationIndex(ssh_destination.AuthenticationType);
            }

            IAutoExecMacroParameter autoExecParams = destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter;

            if (autoExecParams != null && TelnetSSHPlugin.Instance.MacroEngine != null)
            {
                _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty;
            }
            else
            {
                _autoExecMacroPathLabel.Enabled    = false;
                _autoExecMacroPathBox.Enabled      = false;
                _selectAutoExecMacroButton.Enabled = false;
            }

            _encodingBox.SelectedIndex     = (int)terminal.Encoding;
            _newLineBox.SelectedIndex      = (int)terminal.TransmitNL;
            _localEchoBox.SelectedIndex    = terminal.LocalEcho? 1 : 0;
            _terminalTypeBox.SelectedIndex = (int)terminal.TerminalType;
            _initializing = false;

            EnableValidControls();
        }
コード例 #13
0
        /// <summary>
        /// Establishes the connection to the remote server; initializes a <see cref="ISSHLoginParameter"/> with the connection properties from
        /// <see cref="BaseConnectionForm{T}.Connection"/> and then calls <see cref="IProtocolService.AsyncSSHConnect"/> to start the connection
        /// process.
        /// </summary>
        public override void Connect()
        {
            _terminal.Font = Connection.Font;

            ISSHLoginParameter sshParameters = PoderosaProtocolService.CreateDefaultSSHParameter();
            ITCPParameter      tcpParameters = (ITCPParameter)sshParameters.GetAdapter(typeof(ITCPParameter));

            tcpParameters.Destination = Connection.Host;
            // TODO: allow user to specify this
            tcpParameters.Port = 22;

            sshParameters.Account = Connection.InheritedUsername;

            SecureString password = Connection.InheritedPassword;

            // Set the auth file and the auth method to PublicKey if an identity file was specified
            if (!String.IsNullOrEmpty(Connection.IdentityFile))
            {
                sshParameters.AuthenticationType = AuthenticationType.PublicKey;
                sshParameters.IdentityFileName   = Connection.IdentityFile;

                PoderosaProtocolService.AsyncSSHConnect(this, sshParameters);
            }

            // Otherwise, set the auth type to Password
            else if (password != null && password.Length > 0)
            {
                SetSshPassword(sshParameters, password);
                PoderosaProtocolService.AsyncSSHConnect(this, sshParameters);
            }

            else
            {
                UsernamePasswordWindow usernamePasswordWindow = new UsernamePasswordWindow
                {
                    Username = String.IsNullOrEmpty(Connection.InheritedUsername) ? Environment.UserName : Connection.InheritedUsername
                };

                if (usernamePasswordWindow.ShowDialog() == DialogResult.OK)
                {
                    Connection.Username = usernamePasswordWindow.Username;
                    Connection.Password = usernamePasswordWindow.Password;

                    sshParameters.Account = usernamePasswordWindow.Username;
                    SetSshPassword(sshParameters, usernamePasswordWindow.Password);

                    PoderosaProtocolService.AsyncSSHConnect(this, sshParameters);
                }
            }
        }
コード例 #14
0
        internal override ITerminalParameter ConvertToTerminalParameter()
        {
            ISSHLoginParameter ssh = MacroPlugin.Instance.ProtocolService.CreateDefaultSSHParameter();

            ssh.Account              = _account;
            ssh.AuthenticationType   = ConvertAuth(_auth);
            ssh.PasswordOrPassphrase = _passphrase;
            ssh.IdentityFileName     = _identityfile;
            ssh.Method = _method == ConnectionMethod.SSH1 ? SSHProtocol.SSH1 : SSHProtocol.SSH2;
            ssh.LetUserInputPassword = false; //マクロからはユーザにパスワード入力を促すことはしない
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = _host;
            tcp.Port        = _port;
            return((ITerminalParameter)ssh.GetAdapter(typeof(ITerminalParameter)));
        }
コード例 #15
0
        public void T00_TelnetSuccess()
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ITCPParameter tcp = _protocolService.CreateDefaultTelnetParameter();

            tcp.Destination = GetTelnetConnectableHost();
            Assert.AreEqual(23, tcp.Port);

            ResultCallback client = new ResultCallback();
            IInterruptable t      = _protocolService.AsyncTelnetConnect(client, tcp);

            client.AssertSuccess();

            ProtocolServiceTestPlugin.Instance.AssertSuccess();
        }
コード例 #16
0
        public void AsyncConnect(IInterruptableConnectorClient client, ITCPParameter param)
        {
            _client         = client;
            _tcpDestination = param;
            _host           = param.Destination;
            _port           = param.Port;
            _NetUtil        = new NetUtil(_client.ConMain);

            ////AgentForward“™‚̃`ƒFƒbƒN‚ð‚·‚é
            //foreach(IConnectionResultEventHandler ch in ProtocolsPlugin.Instance.ConnectionResultEventHandler.GetExtensions())
            //    ch.BeforeAsyncConnect((ITerminalParameter)param.GetAdapter(typeof(ITerminalParameter)));

            Thread th = new Thread(new ThreadStart(this.Run));

            th.Start();
        }
コード例 #17
0
        /// <summary>
        /// Load connection parameter history
        /// </summary>
        private void LoadHistory()
        {
            _hostBox.Items.Clear();
            _historyItems.Clear();

            IExtensionPoint extp = TerminalSessionsPlugin.Instance.PoderosaWorld.PluginManager.FindExtensionPoint("org.poderosa.terminalsessions.terminalParameterStore");

            if (extp != null)
            {
                var stores = extp.GetExtensions() as ITerminalSessionParameterStore[];
                if (stores != null)
                {
                    foreach (var store in stores)
                    {
                        _historyItems.AddRange(
                            // create combobox items from SSH parameters
                            store.FindTerminalParameter <ISSHLoginParameter>()
                            .Select((sessionParams) =>
                        {
                            ISSHLoginParameter sshParam = sessionParams.ConnectionParameter;
                            ITCPParameter tcpParam      = sshParam.GetAdapter(typeof(ITCPParameter)) as ITCPParameter;
                            if (tcpParam != null)
                            {
                                return(new ParameterItem(sshParam, tcpParam, sessionParams.TerminalParameter, sessionParams.TerminalSettings));
                            }
                            else
                            {
                                return(null);
                            }
                        })
                            .Where((item) =>
                        {
                            return(item != null);
                        })
                            );
                    }
                }
            }

            if (_historyItems.Count > 0)
            {
                _hostBox.Items.AddRange(_historyItems.ToArray());
                _hostBox.SelectedIndex = 0;
            }
        }
コード例 #18
0
ファイル: MRUPlugin.cs プロジェクト: yoshikixxxx/poderosa
        private static bool CheckDestination(ITerminalParameter tp, string destination)
        {
            //destinationがnull(FillTop()由来)なら常にOK
            if (destination == null)
            {
                return(true);
            }
            ITCPParameter tcp = (ITCPParameter)tp.GetAdapter(typeof(ITCPParameter));

            if (tcp == null)
            {
                return(false);
            }
            else
            {
                return(tcp.Destination == destination);
            }
        }
コード例 #19
0
        public void T06_FormBaseSuccess()
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ITCPParameter tcp = _protocolService.CreateDefaultTelnetParameter();

            tcp.Destination = GetTelnetConnectableHost();
            Assert.AreEqual(23, tcp.Port);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncTelnetConnect(sc.InterruptableConnectorClient, tcp);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            Assert.IsNotNull(con);
            Assert.IsFalse(con.IsClosed);

            ProtocolServiceTestPlugin.Instance.AssertSuccess();
        }
コード例 #20
0
        //TODO シリアル用テストケースは追加必要。CygwinはTelnetと同じなのでまあいいだろう

        //TODO ITerminalOutputのテスト。正しく送信されたかを確認するのは難しい感じもするが

        //TODO Reproduceサポートの後、SSH2で1Connection-複数Channelを開き、個別に開閉してみる

        private ITerminalConnection CreateTelnetConnection()
        {
            ITCPParameter tcp = _protocolService.CreateDefaultTelnetParameter();

            tcp.Destination = UnitTestUtil.GetUnitTestConfig("protocols.telnet_connectable");
            Debug.Assert(tcp.Port == 23);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncTelnetConnect(sc.InterruptableConnectorClient, tcp);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            //Assert.ReferenceEquals(con.Destination, tcp); //なぜか成立しない
            Debug.Assert(con.Destination == tcp);
            _rawsocket    = ((InterruptableConnector)t).RawSocket;
            _testReceiver = new TestReceiver();
            con.Socket.RepeatAsyncRead(_testReceiver);
            return(con);
        }
コード例 #21
0
        protected override void StartConnection()
        {
            ISSHLoginParameter ssh             = (ISSHLoginParameter)_param.GetAdapter(typeof(ISSHLoginParameter));
            ITCPParameter      tcp             = (ITCPParameter)_param.GetAdapter(typeof(ITCPParameter));
            IProtocolService   protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;

            if (ssh != null)
            {
                _connector = protocolservice.AsyncSSHConnect(this, ssh);
            }
            else
            {
                _connector = protocolservice.AsyncTelnetConnect(this, tcp);
            }

            if (_connector == null)
            {
                ClearConnectingState();
            }
        }
コード例 #22
0
        public void AsyncConnect(IInterruptableConnectorClient client, ITCPParameter param)
        {
            _client         = client;
            _tcpDestination = param;
            _host           = param.Destination;
            _port           = param.Port;

            //AgentForward等のチェックをする
            if (ProtocolsPlugin.Instance != null)
            {
                foreach (IConnectionResultEventHandler ch in ProtocolsPlugin.Instance.ConnectionResultEventHandler.GetExtensions())
                {
                    ch.BeforeAsyncConnect((ITerminalParameter)param.GetAdapter(typeof(ITerminalParameter)));
                }
            }

            Thread th = new Thread(new ThreadStart(this.Run));

            th.Start();
        }
コード例 #23
0
        private void SSHSuccess(SSHProtocol sshprotocol)
        {
            ProtocolServiceTestPlugin.Instance.Reset();

            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = sshprotocol;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_password");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = GetSSHConnectableHost();
            Assert.AreEqual(22, tcp.Port);

            ResultCallback client = new ResultCallback();
            IInterruptable t      = _protocolService.AsyncSSHConnect(client, ssh);

            client.AssertSuccess();

            ProtocolServiceTestPlugin.Instance.AssertSuccess();
        }
コード例 #24
0
        private ITerminalConnection CreateSSHConnection(SSHProtocol sshprotocol)
        {
            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = sshprotocol;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_password");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = UnitTestUtil.GetUnitTestConfig("protocols.ssh_connectable");
            Debug.Assert(tcp.Port == 22);

            ISynchronizedConnector sc  = _protocolService.CreateFormBasedSynchronozedConnector(null);
            IInterruptable         t   = _protocolService.AsyncSSHConnect(sc.InterruptableConnectorClient, ssh);
            ITerminalConnection    con = sc.WaitConnection(t, 5000);

            Debug.Assert(con.Destination == ssh);
            _rawsocket    = ((InterruptableConnector)t).RawSocket;
            _testReceiver = new TestReceiver();
            con.Socket.RepeatAsyncRead(_testReceiver);
            return(con);
        }
コード例 #25
0
        public void T05_DenyHostKey()
        {
            ProtocolServiceTestPlugin.Instance.Reset();
            ProtocolServiceTestPlugin.Instance.AcceptsHostKey = false;

            ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter();

            ssh.Method  = SSHProtocol.SSH2;
            ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account");
            ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_password");
            ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = GetSSHConnectableHost();
            Assert.AreEqual(22, tcp.Port);

            ResultCallback client = new ResultCallback();
            IInterruptable t      = _protocolService.AsyncSSHConnect(client, ssh);

            client.AssertFail();

            ProtocolServiceTestPlugin.Instance.AssertFail();
            ProtocolServiceTestPlugin.Instance.AcceptsHostKey = true;
        }
コード例 #26
0
 protected TCPTerminalConnection(ITCPParameter p)
     : base((ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)))
 {
     _usingSocks = false;
 }
コード例 #27
0
ファイル: ProtocolsPlugin.cs プロジェクト: sunxking/poderosa
        public IInterruptable AsyncTelnetConnect(IInterruptableConnectorClient result_client, ITCPParameter destination)
        {
            InterruptableConnector swt = new TelnetConnector(destination);

            swt.AsyncConnect(result_client, destination);
            return(swt);
        }
コード例 #28
0
 protected TCPTerminalConnection(ITCPParameter p)
     : base((ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)))
 {
 }
コード例 #29
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;
        }
コード例 #30
0
 public TelnetConnector(ITCPParameter destination)
 {
     _destination = destination;
 }
コード例 #31
0
 public TelnetTerminalConnection(ITCPParameter p, TelnetNegotiator neg, PlainPoderosaSocket s)
     : base(p)
 {
     s.SetOwnerConnection(this);
     _telnetReceiver = new TelnetReceiver(this, neg);
     ITelnetParameter telnetParams = (ITelnetParameter)p.GetAdapter(typeof(ITelnetParameter));
     bool telnetNewLine = (telnetParams != null) ? telnetParams.TelnetNewLine : true/*default*/;
     _telnetSocket = new TelnetSocket(this, s, _telnetReceiver, telnetNewLine);
     _rawSocket = s;
     _socket = _telnetSocket;
     _terminalOutput = _telnetSocket;
 }
コード例 #32
0
        /// <summary>
        /// カレントセッションプロファイルを新規作成
        /// </summary>
        /// <param name="ts">ターミナルセッション</param>
        public void NewProfileCurrentSessionCommand(ITerminalSession ts)
        {
            ISSHLoginParameter   ssh    = (ISSHLoginParameter)ts.TerminalConnection.Destination.GetAdapter(typeof(ISSHLoginParameter));
            ITelnetParameter     telnet = (ITelnetParameter)ts.TerminalConnection.Destination.GetAdapter(typeof(ITelnetParameter));
            ITCPParameter        tcp    = null;
            ConnectProfileStruct prof   = new ConnectProfileStruct();

            // プロトコルチェック
            if (telnet != null)
            {
                // Telnet
                tcp                = (ITCPParameter)ts.TerminalConnection.Destination.GetAdapter(typeof(ITCPParameter));
                prof.Protocol      = ConnectionMethod.Telnet;
                prof.HostName      = tcp.Destination;
                prof.Port          = tcp.Port;
                prof.TelnetNewLine = telnet.TelnetNewLine;
            }
            else
            {
                // SSH
                tcp            = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
                prof.HostName  = tcp.Destination;
                prof.Port      = tcp.Port;
                prof.UserName  = ssh.Account;
                prof.Password  = ssh.PasswordOrPassphrase;
                prof.KeyFile   = ssh.IdentityFileName;
                prof.AutoLogin = true;
                if (ssh.Method.ToString() == "SSH1")
                {
                    prof.Protocol = ConnectionMethod.SSH1;
                }
                else if (ssh.Method.ToString() == "SSH2")
                {
                    prof.Protocol = ConnectionMethod.SSH2;
                }
                if (ssh.AuthenticationType.ToString() == "Password")
                {
                    prof.AuthType = AuthType.Password;
                }
                else if (ssh.AuthenticationType.ToString() == "PublicKey")
                {
                    prof.AuthType = AuthType.PublicKey;
                }
                else if (ssh.AuthenticationType.ToString() == "KeyboardInteractive")
                {
                    prof.AuthType = AuthType.KeyboardInteractive;
                }
            }

            // その他設定
            prof.CharCode     = ts.TerminalSettings.Encoding;
            prof.NewLine      = ts.TerminalSettings.TransmitNL;
            prof.TerminalType = ts.TerminalSettings.TerminalType;
            if (ts.TerminalSettings.RenderProfile == null)
            {
                prof.RenderProfile            = ConnectProfilePlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
                prof.RenderProfile.ESColorSet = new EscapesequenceColorSet();
                prof.RenderProfile.ESColorSet.ResetToDefault();
            }
            else
            {
                prof.RenderProfile = ts.TerminalSettings.RenderProfile;
            }
            prof.CommandSendInterval = ConnectProfileStruct.DEFAULT_CMD_SEND_INTERVAL;
            prof.PromptRecvTimeout   = ConnectProfileStruct.DEFAULT_PROMPT_RECV_TIMEOUT;
            prof.ProfileItemColor    = System.Drawing.Color.Black;

            // ウィンドウ表示/プロファイル追加
            ProfileEditForm dlg = new ProfileEditForm(prof);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                AddProfileCommand(ConnectProfilePlugin.Profiles, dlg.ResultProfile);
            }
        }
コード例 #33
0
ファイル: ProtocolsPlugin.cs プロジェクト: yiyi99/poderosa
 public IInterruptable AsyncTelnetConnect(IInterruptableConnectorClient result_client, ITCPParameter destination)
 {
     InterruptableConnector swt = new TelnetConnector(destination);
     swt.AsyncConnect(result_client, destination);
     return swt;
 }
コード例 #34
0
        public override bool UIEquals(ITerminalParameter param)
        {
            ITCPParameter tcp = (ITCPParameter)param.GetAdapter(typeof(ITCPParameter));

            return(tcp != null && _destination == tcp.Destination && _port == tcp.Port);
        }
コード例 #35
0
        /// <summary>
        /// 接続
        /// </summary>
        public void Connect()
        {
            ITCPParameter tcp = null;

            // プロトコル
            if (_prof.Protocol == ConnectionMethod.Telnet)
            {
                // Telnet
                tcp             = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
                tcp.Destination = _prof.HostName;
                tcp.Port        = _prof.Port;
                ITelnetParameter telnetParameter = null;
                telnetParameter = (ITelnetParameter)tcp.GetAdapter(typeof(ITelnetParameter));
                if (telnetParameter != null)
                {
                    telnetParameter.TelnetNewLine = _prof.TelnetNewLine;
                }
            }
            else if ((_prof.Protocol == ConnectionMethod.SSH1) || (_prof.Protocol == ConnectionMethod.SSH2))
            {
                // SSH
                ISSHLoginParameter ssh = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                tcp                      = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
                tcp.Destination          = _prof.HostName;
                tcp.Port                 = _prof.Port;
                ssh.Method               = (_prof.Protocol == ConnectionMethod.SSH1) ? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                ssh.Account              = _prof.UserName;
                ssh.AuthenticationType   = ConvertAuth(_prof.AuthType);
                ssh.PasswordOrPassphrase = _prof.Password;
                ssh.IdentityFileName     = _prof.KeyFile;
                ssh.LetUserInputPassword = (_prof.AutoLogin == true) ? false : true;
            }

            // TerminalSettings(表示プロファイル/改行コード/文字コード)
            ITerminalSettings terminalSettings = ConnectProfilePlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(_prof.HostName, null);

            terminalSettings.BeginUpdate();
            terminalSettings.RenderProfile = _prof.RenderProfile;
            terminalSettings.TransmitNL    = _prof.NewLine;
            terminalSettings.Encoding      = _prof.CharCode;
            terminalSettings.LocalEcho     = false;
            terminalSettings.EndUpdate();

            // TerminalParameter
            ITerminalParameter terminalParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));

            // ターミナルサイズ(これを行わないとPoderosa起動直後のOnReceptionが何故か機能しない, 行わない場合は2回目以降の接続時は正常)
            IViewManager            viewManager            = CommandTargetUtil.AsWindow(ConnectProfilePlugin.Instance.WindowManager.ActiveWindow).ViewManager;
            IContentReplaceableView contentReplaceableView = (IContentReplaceableView)viewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         terminalControl        = (TerminalControl)contentReplaceableView.GetCurrentContent().GetAdapter(typeof(TerminalControl));

            if (terminalControl != null)
            {
                Size size = terminalControl.CalcTerminalSize(terminalSettings.RenderProfile);
                terminalParam.SetTerminalSize(size.Width, size.Height);
            }

            // 接続(セッションオープン)
            _terminalSession = (ITerminalSession)ConnectProfilePlugin.Instance.WindowManager.ActiveWindow.AsForm().Invoke(new OpenSessionDelegate(InvokeOpenSessionOrNull), terminalParam, terminalSettings);

            // 自動ログイン/SU/実行コマンド
            if (_terminalSession != null)
            {
                // 受信データオブジェクト作成(ユーザからのキーボード入力が不可)
                ReceptionData pool = new ReceptionData();
                _terminalSession.Terminal.StartModalTerminalTask(pool);

                // Telnet自動ログイン
                if ((_prof.AutoLogin == true) && (_prof.Protocol == ConnectionMethod.Telnet))
                {
                    if (TelnetAutoLogin() != true)
                    {
                        return;
                    }
                }

                // SU
                if ((_prof.AutoLogin == true) && (_prof.SUUserName != ""))
                {
                    if (SUSwitch() != true)
                    {
                        return;
                    }
                }

                // 実行コマンド
                if ((_prof.AutoLogin == true) && (_prof.ExecCommand != ""))
                {
                    if (ExecCommand() != true)
                    {
                        return;
                    }
                }

                // 受信データオブジェクト定義解除(ユーザからのキーボード入力を許可)
                _terminalSession.Terminal.EndModalTerminalTask();
            }
        }
コード例 #36
0
ファイル: Connector.cs プロジェクト: FNKGino/poderosa
 public TelnetConnector(ITCPParameter destination)
 {
     _destination = destination;
 }