/// <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); }
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(); }
/// <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); } } }
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); }