public SSHShortcutLoginDialog(IPoderosaMainWindow parent, ISSHLoginParameter param, ITerminalSettings settings) : base(parent) { this.TerminalSettings = settings; // // Windows フォーム デザイナ サポートに必要です。 // InitializeComponent(); this._privateKeyLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._privateKeyLabel"); this._passphraseLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._passphraseLabel"); this._logFileLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._logFileLabel"); this._hostLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._hostLabel"); this._methodLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._methodLabel"); this._accountLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._accountLabel"); this._authenticationTypeLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._authenticationTypeLabel"); this._encodingLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._encodingLabel"); this._logTypeLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._logTypeLabel"); this.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog.Text"); this._autoExecMacroPathLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._autoExecMacroPathLabel"); this._cancelButton.Text = TEnv.Strings.GetString("Common.Cancel"); this._loginButton.Text = TEnv.Strings.GetString("Common.OK"); this._logTypeBox.Items.AddRange(EnumListItem <LogType> .GetListItems()); _sshParam = param; InitUI(); }
public static string FormatItemDescription(MRUItem item) { ITerminalParameter param = item.TerminalParameter; string suffix = ""; ICygwinParameter cygwin = (ICygwinParameter)param.GetAdapter(typeof(ICygwinParameter)); if (cygwin != null) { suffix = "- Cygwin"; } ISSHLoginParameter ssh = (ISSHLoginParameter)param.GetAdapter(typeof(ISSHLoginParameter)); ITCPParameter tcp = (ITCPParameter)param.GetAdapter(typeof(ITCPParameter)); if (ssh != null) { suffix = String.Format("- {0}", ssh.Method.ToString()); } else if (tcp != null) { suffix = "- Telnet"; } return(String.Format("{0} {1}", item.TerminalSettings.Caption, suffix)); }
public void ApplyLoginDialogInfo(ITelnetSSHLoginDialogInitializeInfo info) { foreach (MRUItem item in _data) { ITerminalParameter tp = item.TerminalParameter; ITCPParameter tcp = (ITCPParameter)tp.GetAdapter(typeof(ITCPParameter)); ISSHLoginParameter ssh = (ISSHLoginParameter)tp.GetAdapter(typeof(ISSHLoginParameter)); ICygwinParameter cygwin = (ICygwinParameter)tp.GetAdapter(typeof(ICygwinParameter)); if (tcp != null) { info.AddHost(tcp.Destination); } if (tcp != null) { info.AddPort(tcp.Port); } if (ssh != null) { info.AddIdentityFile(ssh.IdentityFileName); } if (ssh != null) { info.AddAccount(ssh.Account); } } }
public bool Verify(ISSHLoginParameter param, SSHConnectionInfo info) { if (!_loaded) { try { Load(); } catch (Exception ex) { //ロード中のエラーのときは鍵は拒否。安全側に! RuntimeUtil.ReportException(ex); return(false); } } string keystr = info.DumpHostKeyInKnownHostsStyle(); string local = param.Method == SSHProtocol.SSH1 ? _dataForSSH1[ToKeyString(param)] : _dataForSSH2[ToKeyString(param)]; if (local == null) { return(AskUserReliability(param, info, keystr, "Message.HostKeyChecker.AskHostKeyRegister")); } else if (keystr != local) { return(AskUserReliability(param, info, keystr, "Message.HostKeyChecker.AskHostKeyRenew")); } else { return(true); } }
public void T07_FormBaseFail() { ProtocolServiceTestPlugin.Instance.Reset(); ISSHLoginParameter ssh = _protocolService.CreateDefaultSSHParameter(); ssh.Method = SSHProtocol.SSH2; ssh.Account = UnitTestUtil.GetUnitTestConfig("protocols.ssh_account"); ssh.PasswordOrPassphrase = UnitTestUtil.GetUnitTestConfig("protocols.ssh_wrongpassword"); ITCPParameter tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter)); tcp.Destination = GetSSHConnectableHost(); Assert.AreEqual(22, tcp.Port); ISynchronizedConnector sc = _protocolService.CreateFormBasedSynchronozedConnector(null); IInterruptable t = _protocolService.AsyncSSHConnect(sc.InterruptableConnectorClient, ssh); ITerminalConnection con = sc.WaitConnection(t, 5000); ProtocolServiceTestPlugin.Instance.AssertFail(); Socket s = ((InterruptableConnector)t).RawSocket; Assert.IsFalse(s.Connected); Assert.IsNull(con); }
public bool IsSupporting(ITerminalParameter param, ITerminalSettings settings) { ITCPParameter tcp = (ITCPParameter)param.GetAdapter(typeof(ITCPParameter)); ISSHLoginParameter ssh = (ISSHLoginParameter)param.GetAdapter(typeof(ISSHLoginParameter)); return(tcp != null && ssh == null); //SSHならSSHを使う。 }
private bool AskUserReliability(ISSHLoginParameter param, SSHConnectionInfo info, string keystr, string message_text_id) { //比較結果に基づく処理 IPoderosaForm form = UsabilityPlugin.Instance.WindowManager.ActiveWindow; Debug.Assert(form.AsForm().InvokeRequired); //別スレッドで実行しているはず //fingerprint StringBuilder bld = new StringBuilder(); byte[] fingerprint = info.HostKeyMD5FingerPrint(); for (int i = 0; i < fingerprint.Length; i++) { if (bld.Length > 0) { bld.Append(':'); } bld.Append(fingerprint[i].ToString("x2")); } string message = String.Format("ssh hostkey fingerprint {0}\n\n{1}", bld.ToString(), UsabilityPlugin.Strings.GetString(message_text_id)); if (form.AskUserYesNo(message) == DialogResult.Yes) { Update(param, keystr, true); return(true); } else { return(false); } }
public SSHShortcutLoginDialog(IPoderosaMainWindow parent, ISSHLoginParameter param, ITerminalSettings settings) : base(parent) { this.TerminalSettings = settings; // // Windows フォーム デザイナ サポートに必要です。 // InitializeComponent(); this._privateKeyLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._privateKeyLabel"); this._passphraseLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._passphraseLabel"); this._logFileLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._logFileLabel"); this._hostLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._hostLabel"); this._methodLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._methodLabel"); this._accountLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._accountLabel"); this._authenticationTypeLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._authenticationTypeLabel"); this._encodingLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._encodingLabel"); this._logTypeLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._logTypeLabel"); this.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog.Text"); this._autoExecMacroPathLabel.Text = TEnv.Strings.GetString("Form.SSHShortcutLoginDialog._autoExecMacroPathLabel"); this._cancelButton.Text = TEnv.Strings.GetString("Common.Cancel"); this._loginButton.Text = TEnv.Strings.GetString("Common.OK"); this._logTypeBox.Items.AddRange(EnumListItem<LogType>.GetListItems()); _sshParam = param; InitUI(); }
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)); //時間? } }
public ParameterItem(ISSHLoginParameter sshParam, ITCPParameter tcpParam, ITerminalParameter terminalParam, ITerminalSettings terminalSettings) { SSHParameter = sshParam; TCPParameter = tcpParam; TerminalParameter = terminalParam; TerminalSettings = terminalSettings; }
public bool Vefiry(ISSHLoginParameter param, SSHConnectionInfo info) { if (_verifier == null) _verifier = FindHostKeyVerifier(); if (_verifier == null) return true; //普通KnownHostsくらいはあるだろう。エラーにすべきかもしれないが else return _verifier.Verify(param, info); }
public bool Vefiry(ISSHLoginParameter param, SSHConnectionInfo info) { if (_verifier == null) _verifier = FindHostKeyVerifier(); if (_verifier == null) return true; //����KnownHosts���炢�͂��邾�낤�B�G���[�ɂ��ׂ��������Ȃ��� else return _verifier.Verify(param, info); }
/// <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); }
public SSHTerminalConnection(ISSHLoginParameter ssh) : base((ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter))) { _sshLoginParameter = ssh; SSHSocket s = new SSHSocket(this); _sshSocket = s; _socket = s; _terminalOutput = s; }
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); }
public void BeforeAsyncConnect(ITerminalParameter tp) { ISSHLoginParameter ssh = (ISSHLoginParameter)tp.GetAdapter(typeof(ISSHLoginParameter)); if (ssh == null) { return; //SSH以外は興味なし } if (ssh.Method == SSHProtocol.SSH2 && _originalOptions.EnableKeyAgent) { ssh.AgentForward = this; //自分をハンドルするように設定 } }
public void BeforeAsyncConnect(ITerminalParameter tp) { ISSHLoginParameter ssh = (ISSHLoginParameter)tp.GetAdapter(typeof(ISSHLoginParameter)); if (ssh == null) { return; //SSH以外は興味なし } if (ssh.Method == SSHProtocol.SSH2 && ssh.EnableAgentForwarding) { ssh.AgentForwardingAuthKeyProvider = this; //自分をハンドルするように設定 } }
/// <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); } } }
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(); }
public bool Vefiry(ISSHLoginParameter param, SSHConnectionInfo info) { if (_verifier == null) { _verifier = FindHostKeyVerifier(); } if (_verifier == null) { return(true); //普通KnownHostsくらいはあるだろう。エラーにすべきかもしれないが } else { return(_verifier.Verify(param, info)); } }
public bool Vefiry(ISSHLoginParameter param, SSHConnectionInfo info) { if (_verifier == null) { _verifier = FindHostKeyVerifier(); } if (_verifier == null) { return(true); //•’ÊKnownHosts‚‚ç‚¢‚Í‚ ‚邾‚낤BƒGƒ‰[‚É‚·‚ׂ«‚©‚à‚µ‚ê‚È‚¢‚ª } else { return(_verifier.Verify(param, info)); } }
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))); }
private CommandResult Reproduce(ITerminalSession ts) { //TODO SSH2では同一コネクションでもう一本張るショートカット、シリアルでは複製できないことを通知するショートカットがあるが... ITerminalParameter param = (ITerminalParameter)ts.TerminalTransmission.Connection.Destination.Clone(); ISSHLoginParameter ssh = (ISSHLoginParameter)param.GetAdapter(typeof(ISSHLoginParameter)); if (ssh != null) { ssh.LetUserInputPassword = false; } ITerminalSettings settings = ts.TerminalSettings.Clone(); ITerminalSession session = TerminalSessionsPlugin.Instance.TerminalSessionStartCommand.StartTerminalSession(ts.OwnerWindow, param, settings); return(session != null ? CommandResult.Succeeded : CommandResult.Failed); }
private void Update(ISSHLoginParameter param, string key, bool flush) { if (param.Method == SSHProtocol.SSH1) { _dataForSSH1[ToKeyString(param)] = key; } else { _dataForSSH2[ToKeyString(param)] = key; } _modified = true; if (flush) { Flush(); } }
/// <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; } }
protected void SetSshPassword(ISSHLoginParameter sshParameters, SecureString password) { sshParameters.AuthenticationType = AuthenticationType.Password; // TODO: add the ability for Poderosa to set this securely IntPtr passwordPointer = IntPtr.Zero; try { passwordPointer = Marshal.SecureStringToGlobalAllocUnicode(password); sshParameters.PasswordOrPassphrase = Marshal.PtrToStringUni(passwordPointer); } finally { Marshal.ZeroFreeGlobalAllocUnicode(passwordPointer); } }
public SSHTerminalConnection(ISSHLoginParameter ssh) : base((ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter))) { _sshLoginParameter = ssh; if (ssh.AuthenticationType != AuthenticationType.KeyboardInteractive) { SSHSocket s = new SSHSocket(this); _sshSocket = s; _socket = s; _terminalOutput = s; } else { KeyboardInteractiveAuthHanlder s = new KeyboardInteractiveAuthHanlder(this); _sshSocket = s; _socket = s; _terminalOutput = null; //まだ利用可能でない } }
public SSHTerminalConnection(ISSHLoginParameter ssh) : base((ITCPParameter)ssh) { _sshLoginParameter = ssh; if (ssh.AuthenticationType != AuthenticationType.KeyboardInteractive) { SSHSocket s = new SSHSocket(this); _sshSocket = s; _socket = s; _terminalOutput = s; } else { KeyboardInteractiveAuthHanlder s = new KeyboardInteractiveAuthHanlder(this); _sshSocket = s; _socket = s; _terminalOutput = null; //‚Ü‚¾—˜—p‰Â”\‚Å‚È‚¢ } }
public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) { Debug.Assert(args != null && args.Length == 1); MRUItem item = (MRUItem)args[0].GetAdapter(typeof(MRUItem)); //コマンド実行時点でIsolateする。 //なぜなら、TerminalSettingsはSessionごとにコピーを持たないといけない(セッション間の共有はNG)し、 //しかしSettingを接続後に変更したらそれは保存するMRUに反映したい。 //結果として、同じMRUItemを複数回インスタンシエートしたら、最後に開いた接続のTerminalSettingsがMRUデータとして保存される。 item.IsolateSettings(); ISSHLoginParameter ssh = (ISSHLoginParameter)item.TerminalParameter.GetAdapter(typeof(ISSHLoginParameter)); if (ssh != null) { ssh.PasswordOrPassphrase = ""; //MRUからのSSH起動はパスワード入力は外せない。オプションで省略化にしてもいいが } ITerminalSession ts = MRUPlugin.Instance.TerminalSessionsService.TerminalSessionStartCommand.StartTerminalSession(target, item.TerminalParameter, item.TerminalSettings); return(ts != null ? CommandResult.Succeeded : CommandResult.Failed); }
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(); } }
private CommandResult ConnectAgain(ITerminalSession ts0) { TerminalSession ts = (TerminalSession)ts0.GetAdapter(typeof(TerminalSession)); ITerminalParameter param = (ITerminalParameter)ts.TerminalTransmission.Connection.Destination.Clone(); ISSHLoginParameter ssh = (ISSHLoginParameter)param.GetAdapter(typeof(ISSHLoginParameter)); if (ssh != null) { ssh.LetUserInputPassword = false; } ITerminalConnection connection = TerminalSessionsPlugin.Instance.TerminalSessionStartCommand.OpenConnection(ts.OwnerWindow, param, ts.TerminalSettings); if (connection == null) { return(CommandResult.Failed); } ts.Revive(connection); //接続を復活 return(CommandResult.Succeeded); }
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(); }
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); }
public bool Verify(ISSHLoginParameter param, SSHConnectionInfo info) { if (!_loaded) { try { Load(); } catch (Exception ex) { //ロード中のエラーのときは鍵は拒否。安全側に! RuntimeUtil.ReportException(ex); return false; } } string keystr = info.DumpHostKeyInKnownHostsStyle(); string local = param.Method == SSHProtocol.SSH1 ? _dataForSSH1[ToKeyString(param)] : _dataForSSH2[ToKeyString(param)]; if (local == null) { return AskUserReliability(param, info, keystr, "Message.HostKeyChecker.AskHostKeyRegister"); } else if (keystr != local) { return AskUserReliability(param, info, keystr, "Message.HostKeyChecker.AskHostKeyRenew"); } else return true; }
private bool AskUserReliability(ISSHLoginParameter param, SSHConnectionInfo info, string keystr, string message_text_id) { //比較結果に基づく処理 IPoderosaForm form = UsabilityPlugin.Instance.WindowManager.ActiveWindow; Debug.Assert(form.AsForm().InvokeRequired); //別スレッドで実行しているはず //fingerprint StringBuilder bld = new StringBuilder(); byte[] fingerprint = info.HostKeyMD5FingerPrint(); for (int i = 0; i < fingerprint.Length; i++) { if (bld.Length > 0) bld.Append(':'); bld.Append(fingerprint[i].ToString("x2")); } string message = String.Format("ssh hostkey fingerprint {0}\n\n{1}", bld.ToString(), UsabilityPlugin.Strings.GetString(message_text_id)); if (form.AskUserYesNo(message) == DialogResult.Yes) { Update(param, keystr, true); return true; } else return false; }
private void Update(ISSHLoginParameter param, string key, bool flush) { if (param.Method == SSHProtocol.SSH1) _dataForSSH1[ToKeyString(param)] = key; else _dataForSSH2[ToKeyString(param)] = key; _modified = true; if (flush) Flush(); }
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; }
protected override ITerminalParameter PrepareTerminalParameter() { _sshParam = ValidateContent(); return _sshParam == null ? null : (ITerminalParameter)_sshParam.GetAdapter(typeof(ITerminalParameter)); }
//ISSHHostKeyVerifier public bool Verify(ISSHLoginParameter param, SSHConnectionInfo info) { return _acceptsHostKey; }
public SSHConnector(ISSHLoginParameter destination, HostKeyVerifierBridge keycheck) { _destination = destination; _keycheck = keycheck; }
private SSHConnectionEventReceiverBase _sshSocket; //Keyboard-interactiveのときの認証中のみ_sshSocketはKeyboardInteractiveAuthHanlder #endregion Fields #region Constructors public SSHTerminalConnection(ISSHLoginParameter ssh) : base((ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter))) { _sshLoginParameter = ssh; if (ssh.AuthenticationType != AuthenticationType.KeyboardInteractive) { SSHSocket s = new SSHSocket(this); _sshSocket = s; _socket = s; _terminalOutput = s; } else { KeyboardInteractiveAuthHanlder s = new KeyboardInteractiveAuthHanlder(this); _sshSocket = s; _socket = s; _terminalOutput = null; //まだ利用可能でない } }
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; }