コード例 #1
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);
                }
            }
        }
コード例 #2
0
            public ITerminalConnection EstablishConnection(IPoderosaMainWindow window, ITerminalParameter destination, ITerminalSettings settings)
            {
                ISSHLoginParameter ssh = (ISSHLoginParameter)destination.GetAdapter(typeof(ISSHLoginParameter));

                if (ssh.LetUserInputPassword && ssh.AuthenticationType != Granados.AuthenticationType.KeyboardInteractive) //ダイアログで入力を促して接続
                {
                    SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog(window, ssh, settings);
                    if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK)
                    {
                        ITerminalConnection con = dlg.Result;
                        AdjustCaptionAndText(settings, ((ITCPParameter)con.Destination.GetAdapter(typeof(ITCPParameter))).Destination, StartCommandIcon.NewConnection);
                        return(con);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else   //主にReproduceやマクロ。設定済みのパスワードで接続
                {
                    IProtocolService       protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;
                    ISynchronizedConnector conn            = protocolservice.CreateFormBasedSynchronozedConnector(window);
                    IInterruptable         r = protocolservice.AsyncSSHConnect(conn.InterruptableConnectorClient, ssh);
                    AdjustCaptionAndText(settings, ((ITCPParameter)destination.GetAdapter(typeof(ITCPParameter))).Destination, StartCommandIcon.NewConnection);
                    return(conn.WaitConnection(r, TerminalSessionsPlugin.Instance.TerminalSessionOptions.TerminalEstablishTimeout)); //時間?
                }
            }
コード例 #3
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);
        }
コード例 #4
0
        protected override void StartConnection()
        {
            IProtocolService protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;

            _connector = protocolservice.AsyncSSHConnect(this, _sshParam);

            if (_connector == null)
            {
                ClearConnectingState();
            }
        }
コード例 #5
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();
        }
コード例 #6
0
        public bool Connect(ConnectCallback callback)
        {
            _connectCallback = callback;
            var ssh = new SSHLoginParameter();

            ssh.Method               = SSHProtocol.SSH2;
            ssh.AuthenticationType   = AuthenticationType.Password;
            ssh.Account              = "cxn2356";
            ssh.PasswordOrPassphrase = "Jumanji123.";
            //--- X11 forwarding settings
            ssh.EnableX11Forwarding = false;
            ssh.X11Forwarding       = null;
            //--- Agent forwarding settings
            ssh.EnableAgentForwarding          = false;
            ssh.AgentForwardingAuthKeyProvider = null;
            // -- tcp
            var tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));

            tcp.Destination = "10.93.1.255";
            tcp.Port        = 22;
            //--- Log settings
            ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings();

            logSettings.LogType = Poderosa.ConnectionParam.LogType.None;
            if (logSettings.LogType != Poderosa.ConnectionParam.LogType.None)
            {
                logSettings.LogPath   = Path.GetTempFileName();
                logSettings.LogAppend = true;
            }
            // -- terminal settings
            _terminalSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings("Terminal", null);
            _terminalSettings.BeginUpdate();
            _terminalSettings.EnabledCharTriggerIntelliSense = false;
            _terminalSettings.Encoding     = Poderosa.ConnectionParam.EncodingType.UTF8;
            _terminalSettings.LocalEcho    = false;
            _terminalSettings.TransmitNL   = Poderosa.ConnectionParam.NewLine.CR;
            _terminalSettings.TerminalType = Poderosa.ConnectionParam.TerminalType.XTerm;
            _terminalSettings.LogSettings.Reset(logSettings);
            _terminalSettings.EndUpdate();
            IProtocolService protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;

            mreConnect.Reset();
            IInterruptable interruptable = protocolservice.AsyncSSHConnect(this, ssh);

            Task.Factory.StartNew(() => AwaitConnectResult());

            return(true);
        }
コード例 #7
0
        /// <summary>
        /// Start opening session
        /// </summary>
        /// <remarks>
        /// The implementation of this method also do validation of the input values.
        /// </remarks>
        /// <param name="client">an instance who receive the result of opening session.</param>
        /// <param name="terminalSettings">terminal settings is set if this method returns true.</param>
        /// <param name="interruptable">an object for cancellation is set if this method returns true.</param>
        /// <returns>true if the opening session has been started, or false if failed.</returns>
        public bool OpenSession(IInterruptableConnectorClient client, out ITerminalSettings terminalSettings, out IInterruptable interruptable)
        {
            ISSHLoginParameter loginParam;
            ITerminalSettings  termSettings;
            string             errorMessage;

            if (!Validate(out loginParam, out termSettings, out errorMessage))
            {
                client.ConnectionFailed(errorMessage);
                terminalSettings = null;
                interruptable    = null;
                return(false);
            }

            IProtocolService protocolservice = TerminalSessionsPlugin.Instance.ProtocolService;

            interruptable    = protocolservice.AsyncSSHConnect(client, loginParam);
            terminalSettings = termSettings;
            return(true);
        }
コード例 #8
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();
            }
        }
コード例 #9
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);
        }