コード例 #1
0
 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());
 }
コード例 #2
0
 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());
 }
コード例 #3
0
 /// <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");
     }
 }
コード例 #4
0
 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());
 }
コード例 #5
0
 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());
 }
コード例 #6
0
 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());
 }
コード例 #7
0
 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());
 }
コード例 #8
0
            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);
            }
コード例 #9
0
    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);
    }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 /// <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);
     }
 }
コード例 #13
0
 public void testAlias_BatchModeDefault()
 {
     OpenSshConfig.Host h = _osc.lookup("orcz");
     Assert.IsNotNull(h);
     Assert.AreEqual(false, h.isBatchMode());
 }
コード例 #14
0
 public void testAlias_PreferredAuthenticationsDefault()
 {
     OpenSshConfig.Host h = _osc.lookup("orcz");
     Assert.IsNotNull(h);
     Assert.IsNull(h.getPreferredAuthentications());
 }
コード例 #15
0
 protected override void Configure(OpenSshConfig.Host hc, Session session)
 {
 }