Examples of HostKeyRepository


Examples of com.jcraft.jsch.HostKeyRepository

            if ( getKnownHostsProvider() != null )
            {
                PrintWriter w = new PrintWriter( stringWriter );

                HostKeyRepository hkr = sch.getHostKeyRepository();
                HostKey[] keys = hkr.getHostKey();

                for ( int i = 0; keys != null && i < keys.length; i++ )
                {
                    HostKey key = keys[i];
                    w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
View Full Code Here

Examples of com.jcraft.jsch.HostKeyRepository

            if ( getKnownHostsProvider() != null )
            {
                PrintWriter w = new PrintWriter( stringWriter );

                HostKeyRepository hkr = sch.getHostKeyRepository();
                HostKey[] keys = hkr.getHostKey();

                for ( int i = 0; keys != null && i < keys.length; i++ )
                {
                    HostKey key = keys[i];
                    w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
View Full Code Here

Examples of com.jcraft.jsch.HostKeyRepository

            if ( getKnownHostsProvider() != null )
            {
                PrintWriter w = new PrintWriter( stringWriter );

                HostKeyRepository hkr = sch.getHostKeyRepository();
                HostKey[] keys = hkr.getHostKey();

                for ( int i = 0; keys != null && i < keys.length; i++ )
                {
                    HostKey key = keys[i];
                    w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
View Full Code Here

Examples of com.jcraft.jsch.HostKeyRepository

               sHomeDir + SysUtil.FILE_SEP + ".ssh" + SysUtil.FILE_SEP + "known_hosts");

            if ("<trust-all>".equals(sKnownHostsPath))
            {
               // Trust ALL
               m_jsch.setHostKeyRepository(new HostKeyRepository()
               {
                  // operations

                  public int check(String host, byte[] key)
                  {
View Full Code Here

Examples of com.jcraft.jsch.HostKeyRepository

            if ( knownHostsProvider != null )
            {
                PrintWriter w = new PrintWriter( stringWriter );

                HostKeyRepository hkr = sch.getHostKeyRepository();
                HostKey[] keys = hkr.getHostKey();

                for ( int i = 0; i < keys.length; i++ )
                {
                    HostKey key = keys[i];
                    w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
View Full Code Here

Examples of com.jcraft.jsch.HostKeyRepository

            if ( getKnownHostsProvider() != null )
            {
                PrintWriter w = new PrintWriter( stringWriter );

                HostKeyRepository hkr = sch.getHostKeyRepository();
                HostKey[] keys = hkr.getHostKey();

                for ( int i = 0; keys != null && i < keys.length; i++ )
                {
                    HostKey key = keys[i];
                    w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
View Full Code Here

Examples of org.vngx.jsch.util.HostKeyRepository

    } else if( _session.getPort() != SSHConstants.DEFAULT_SSH_PORT ) {
      chost = "[" + chost + "]:" + _session.getPort();
    }

    // Check host against known hosts repository
    HostKeyRepository hkr = JSch.getInstance().getHostKeyRepository();
    Check keyCheck;
    synchronized( hkr ) {
      keyCheck = hkr.check(chost, kex.K_S);
    }

    boolean insert = false;
    String shkc = _session.getConfig().getString(SessionConfig.STRICT_HOST_KEY_CHECKING);
    if( ("ask".equals(shkc) || "yes".equals(shkc)) && keyCheck == Check.CHANGED ) {
      String file = hkr.getKnownHostsRepositoryID() != null ?
        hkr.getKnownHostsRepositoryID() : SSHConstants.KNOWN_HOSTS;

      // Notify user host key changed (ask if requested) and throw exception
      // if user doesn't accept the new key
      if( _userinfo != null ) {
        if( "ask".equals(shkc) ) {
          if( !_userinfo.promptYesNo(String.format(MessageConstants.PROMPT_REPLACE_KEY,
              kex._hostKeyType.DISPLAY_NAME, Util.getFingerPrint(kex.K_S), file)) ) {
            throw new JSchException("HostKey has changed (StrictHostKeyChecking:ask): "+chost);
          }
        } else // shkc.equals("yes")
          _userinfo.showMessage(String.format(MessageConstants.INVALID_SERVER_HOST,
              kex._hostKeyType.DISPLAY_NAME, Util.getFingerPrint(kex.K_S), file));
          throw new JSchException("HostKey has changed (StrictHostKeyChecking:yes): "+chost);
        }
      }

      // Remove the old key from the repository
      synchronized ( hkr ) {
        hkr.remove(chost, kex._hostKeyType, null);
        insert = true;
      }
    }

    if( ("ask".equals(shkc) || "yes".equals(shkc)) && keyCheck != Check.OK && !insert ) {
      if( "yes".equals(shkc) ) {
        throw new JSchException("HostKey does not match known hosts (StrictHostKeyChecking:yes): "+chost);
      }
      if( _userinfo != null ) {
        if( !_userinfo.promptYesNo(String.format(MessageConstants.PROMPT_UNKNOWN_KEY,
            chost, kex._hostKeyType.DISPLAY_NAME, Util.getFingerPrint(kex.K_S))) ) {
          throw new JSchException("HostKey does not match known hosts (StrictHostKeyChecking:ask): "+chost);
        }
        insert = true;
      } else {
        if( keyCheck == Check.NOT_INCLUDED ) {
          throw new JSchException("UnknownHostKey: "+chost+". "+kex._hostKeyType+" key fingerprint is "+Util.getFingerPrint(kex.K_S));
        } else {
          throw new JSchException("HostKey has been changed (StrictHostKeyChecking:ask): " + chost);
        }
      }
    }

    if( "no".equals(shkc) && keyCheck == Check.NOT_INCLUDED ) {
      insert = true;
    }
    if( keyCheck == Check.OK && JSch.getLogger().isEnabled(Logger.Level.INFO) ) {
      JSch.getLogger().log(Logger.Level.INFO, "Host '"+chost+"' is known and matches the "+kex._hostKeyType+" host key");
    }
    if( insert && JSch.getLogger().isEnabled(Logger.Level.WARN) ) {
      JSch.getLogger().log(Logger.Level.WARN, "Permanently added '"+chost+"' ("+kex._hostKeyType+") to the list of known hosts.");
    }

    // Create host key instance
    _hostKey = HostKey.createHostKey(chost, kex.K_S, _session.getConfig().getBoolean(SessionConfig.HASH_KNOWN_HOSTS));
    if( insert ) {
      synchronized( hkr ) {
        hkr.add(_hostKey, _userinfo);
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.