public void testAlias_PreferredAuthentications() { Config("Host orcz\n" + "\tPreferredAuthentications publickey\n"); OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual("publickey", h.getPreferredAuthentications()); }
public void testAlias_BatchModeYes() { Config("Host orcz\n" + "\tBatchMode yes\n"); OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual(true, h.isBatchMode()); }
/// <summary> /// Update Private Key selection /// </summary> private void UpdateIdentity() { View.PkCheckboxEnabled = View.SelectedProtocol == Protocol.SFTP; if (View.SelectedProtocol == Protocol.SFTP) { if (Utils.IsNotBlank(View.Hostname)) { OpenSshConfig.Host entry = OpenSshConfig.create().lookup(View.Hostname); if (null != entry.getIdentityFile()) { if (!View.PkCheckboxState) { // No previously manually selected key View.PkCheckboxState = true; View.PkLabel = LocalFactory.createLocal(entry.getIdentityFile().getAbsolutePath()).getAbbreviatedPath(); } } else { View.PkCheckboxState = false; View.PkLabel = Locale.localizedString("No private key selected"); } if (Utils.IsNotBlank(entry.getUser())) { View.Username = entry.getUser(); } } } else { View.PkCheckboxState = false; View.PkLabel = Locale.localizedString("No private key selected"); } }
public void testAlias_InheritBatchMode() { Config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + "\tBatchMode yes\n"); OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual(true, h.isBatchMode()); }
public void testAlias_InheritPreferredAuthentications() { Config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + "\tPreferredAuthentications publickey, hostbased\n"); OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual("publickey,hostbased", h.getPreferredAuthentications()); }
public void testNoConfig() { OpenSshConfig.Host h = _osc.lookup("repo.or.cz"); Assert.IsNotNull(h); Assert.AreEqual("repo.or.cz", h.getHostName()); Assert.AreEqual(Environment.UserName, h.getUser()); Assert.AreEqual(22, h.getPort()); Assert.IsNull(h.getIdentityFile()); }
public void testAlias_DoesNotMatch() { Config("Host orcz\n" + "\tHostName repo.or.cz\n"); OpenSshConfig.Host h = _osc.lookup("repo.or.cz"); Assert.IsNotNull(h); Assert.AreEqual("repo.or.cz", h.getHostName()); Assert.AreEqual(Environment.UserName, h.getUser()); Assert.AreEqual(22, h.port); Assert.IsNull(h.getIdentityFile()); }
protected override JSch GetJSch(OpenSshConfig.Host hc, FS fs) { JSch.SetConfig("StrictHostKeyChecking", "no"); // automatic acceptance for known host if 'known_hosts' is missing var jsch = base.GetJSch(hc, fs); var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var sshPath = homePath + @"\.ssh"; jsch.AddIdentity(sshPath + @"\id_rsa"); jsch.SetKnownHosts(sshPath + @"\known_hosts"); return(jsch); }
protected override void Configure(OpenSshConfig.Host hc, Session session) { var config = new Properties(); config["StrictHostKeyChecking"] = "no"; config["PreferredAuthentications"] = "publickey"; session.SetConfig(config); var jsch = this.GetJSch(hc, FS.DETECTED); jsch.AddIdentity("KeyPair", Encoding.UTF8.GetBytes(PrivateKey), Encoding.UTF8.GetBytes(PublicKey), null); }
public void testAlias_OptionsKeywordCaseInsensitive() { Config("hOsT orcz\n" + "\thOsTnAmE repo.or.cz\n" + "\tPORT 2222\n" + "\tuser jex\n" + "\tidentityfile .ssh/id_jex\n" + "\tForwardX11 no\n"); OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual("repo.or.cz", h.getHostName()); Assert.AreEqual("jex", h.getUser()); Assert.AreEqual(2222, h.getPort()); Assert.AreEqual(new FileInfo(Path.Combine(_home.FullName, ".ssh/id_jex")).FullName, h.getIdentityFile().FullName); }
public void testAlias_OptionsSet() { Config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\tPort 2222\n" + "\tUser jex\n" + "\tIdentityFile .ssh/id_jex\n" + "\tForwardX11 no\n"); OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual("repo.or.cz", h.getHostName()); Assert.AreEqual("jex", h.getUser()); Assert.AreEqual(2222, h.getPort()); Assert.AreEqual(new FileInfo(Path.Combine(_home.FullName, ".ssh/id_jex")).FullName, h.getIdentityFile().FullName); }
/// <summary> /// Update this host credentials from the OpenSSH configuration file in ~/.ssh/config /// </summary> private void ReadOpenSshConfiguration() { if (_host.getProtocol().equals(Protocol.SFTP)) { OpenSshConfig.Host entry = OpenSshConfig.create().lookup(_host.getHostname()); if (null != entry.getIdentityFile()) { _host.getCredentials().setIdentity( LocalFactory.createLocal(entry.getIdentityFile().getAbsolutePath())); } if (Utils.IsNotBlank(entry.getUser())) { _host.getCredentials().setUsername(entry.getUser()); } } else { _host.getCredentials().setIdentity(null); } }
public void testAlias_BatchModeDefault() { OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.AreEqual(false, h.isBatchMode()); }
public void testAlias_PreferredAuthenticationsDefault() { OpenSshConfig.Host h = _osc.lookup("orcz"); Assert.IsNotNull(h); Assert.IsNull(h.getPreferredAuthentications()); }
protected override void Configure(OpenSshConfig.Host hc, Session session) { }