Пример #1
0
        /// <summary>
        /// Obtain the JSch used to create new sessions.
        /// </summary>
        /// <param name="hc">host configuration</param>
        /// <returns>the JSch instance to use.</returns>
        protected JSch getJSch(OpenSshConfig.Host hc)
        {
            if (hc == null)
            {
                throw new System.ArgumentNullException("hc");
            }

            JSch     def          = getDefaultJSch();
            FileInfo identityFile = hc.getIdentityFile();

            if (identityFile == null)
            {
                return(def);
            }

            string identityKey = identityFile.FullName;
            JSch   jsch        = _byIdentityFile[identityKey];

            if (jsch == null)
            {
                jsch = new JSch();
                jsch.setHostKeyRepository(def.getHostKeyRepository());
                jsch.addIdentity(identityKey);
                _byIdentityFile.Add(identityKey, jsch);
            }
            return(jsch);
        }
Пример #2
0
        protected JSch getJSch(OpenSshConfig.Host hc)
        {
            JSch     def          = getDefaultJSch();
            FileInfo identityFile = hc.getIdentityFile();

            if (identityFile == null)
            {
                return(def);
            }

            string identityKey = Path.GetFullPath(identityFile.ToString());
            JSch   jsch        = byIdentityFile[identityKey];

            if (jsch == null)
            {
                jsch = new JSch();
                jsch.setHostKeyRepository(def.getHostKeyRepository());
                jsch.addIdentity(identityKey);
                byIdentityFile.Add(identityKey, jsch);
            }
            return(jsch);
        }
Пример #3
0
 /// <summary>
 /// Adds a "known fingerprint" for the target host, and enables strict host checking
 /// </summary>
 /// <param name="hostFingerprint">The known fingerprint of the target host key</param>
 public virtual void SetKnownHostFingerprint(string hostFingerprint)
 {
     m_jsch.setHostKeyRepository(new SshFingerprintOnlyHostsList(m_host, hostFingerprint));
     //the "SshFingerprintOnlyHostsList" does not support saving - "ask" makes no sense.
     m_checkType = HostKeyCheckType.ForceMatch;
 }