Java 类com.jcraft.jsch.HostKey 实例源码

项目:gerrit    文件:SshDaemon.java   
private List<HostKey> computeHostKeys() {
  if (listen.isEmpty()) {
    return Collections.emptyList();
  }

  final List<PublicKey> keys = myHostKeys();
  final List<HostKey> r = new ArrayList<>();
  for (PublicKey pub : keys) {
    final Buffer buf = new ByteArrayBuffer();
    buf.putRawPublicKey(pub);
    final byte[] keyBin = buf.getCompactData();

    for (String addr : advertised) {
      try {
        r.add(new HostKey(addr, keyBin));
      } catch (JSchException e) {
        sshDaemonLog.warn(
            String.format(
                "Cannot format SSHD host key [%s]: %s", pub.getAlgorithm(), e.getMessage()));
      }
    }
  }
  return Collections.unmodifiableList(r);
}
项目:daris    文件:JSchConnection.java   
@Override
public Session connect(final UserDetails userDetails, boolean verifyHostKey) throws Throwable {

    _jsch.setKnownHosts(new ByteArrayInputStream(new byte[8192]));
    String hostKey = _serverDetails.hostKey();
    if (hostKey != null) {
        _jsch.getHostKeyRepository().add(new HostKey(_serverDetails.host(), Base64.decode(hostKey.getBytes())),
                JSchUserInfo.makeUserInfo(userDetails));
    }
    /*
     * added user's identity (private & public keys)
     */
    if (userDetails.privateKey() != null) {
        _jsch.addIdentity(userDetails.username() + "_identity", userDetails.privateKey().getBytes(), userDetails
                .publicKey().getBytes(), userDetails.passphrase() != null ? userDetails.passphrase().getBytes()
                : null);
    }
    JSchSession session = new JSchSession(userDetails, this, verifyHostKey);
    session.open();
    return session;
}
项目:daris    文件:JschConnection.java   
public JschConnection(ConnectionDetails cxnDetails, int maxChannels, boolean verbose) throws Throwable {
    _cxnDetails = cxnDetails;
    _maxChannels = maxChannels;
    _verbose = verbose;

    _channels = Collections.synchronizedCollection(new HashSet<com.jcraft.jsch.Channel>());

    _jsch = new JSch();
    _jsch.setKnownHosts(new ByteArrayInputStream(new byte[8192]));
    String hostKey = _cxnDetails.hostKey();
    if (hostKey != null) {
        _jsch.getHostKeyRepository()
                .add(new HostKey(_cxnDetails.host(), Base64.getDecoder().decode(hostKey.getBytes())), userInfo());
    }
    /*
     * added user's identity (private & public keys)
     */
    if (_cxnDetails.privateKey() != null) {
        _jsch.addIdentity(_cxnDetails.username() + "_identity", _cxnDetails.privateKey().getBytes(),
                _cxnDetails.publicKey() != null ? _cxnDetails.publicKey().getBytes() : null,
                _cxnDetails.passphrase() != null ? _cxnDetails.passphrase().getBytes() : null);
    }

    /*
     * connect
     */
    _jschSession = _jsch.getSession(_cxnDetails.username(), _cxnDetails.host(), _cxnDetails.port());
    _jschSession.setConfig("StrictHostKeyChecking", _cxnDetails.hostKey() != null ? "yes" : "no");
    _jschSession.setUserInfo(userInfo());
    if (_verbose) {
        System.out.print("opening connection to " + _cxnDetails.host() + ":" + _cxnDetails.port() + " ...");
    }
    _jschSession.connect();
    if (_verbose) {
        System.out.println("done");
    }
}
项目:spring-cloud-config    文件:PropertyBasedSshSessionFactory.java   
@Override
protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException {
    if (sshKeysByHostname.containsKey(host)) {
        SshUri sshUriProperties = sshKeysByHostname.get(host);
        jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null, null);
        if (sshUriProperties.getKnownHostsFile() != null) {
            jSch.setKnownHosts(sshUriProperties.getKnownHostsFile());
        }
        if (sshUriProperties.getHostKey() != null) {
            HostKey hostkey = new HostKey(host, Base64.decode(sshUriProperties.getHostKey()));
            jSch.getHostKeyRepository().add(hostkey, null);
        }
        return jSch.getSession(user, host, port);
    }
    throw new JSchException("no keys configured for hostname " + host);
}
项目:droid-ssh    文件:FingerPrintRepository.java   
public HostKey[] getHostKey(String host, String type)
{
    HostKey[] arrayOfHostKey = new HostKey[0];
    List<HostKeys> keyList = dbInstance.getHostKey(host);
    try
    {
        if(keyList.size() > 0)
        {
            Iterator localIterator = keyList.iterator();
            while (localIterator.hasNext())
            {
                HostKeys localHost = (HostKeys)localIterator.next();
                arrayOfHostKey[arrayOfHostKey.length] = new HostKey(localHost.getHostName(), localHost.getKey().getBytes());
            }
        }
    }
    catch(Exception e)
    {

    }
    return arrayOfHostKey;
}
项目:ssh-proxy    文件:HostKeyTypeTest.java   
@Test
public void testGetType() throws Exception {
    assertEquals(HostKey.SSHRSA, HostKeyType.SSH_RSA.getType());
    assertEquals(HostKey.SSHDSS, HostKeyType.SSH_DSS.getType());

    for (HostKeyType hostKeyType : HostKeyType.values()) {
        assertTrue(hostKeyType.getType() > 0);
    }
}
项目:release-maven-plugin-parent    文件:SshAgentSessionFactoryTest.java   
/**
 * 
 */
@Test
public void createDefaultJSch_WithKnownHosts() throws Exception {
    final SshAgentSessionFactory factory = new SshAgentSessionFactory(log, KNOWN_HOSTS, null, null);
    factory.setKnownHosts(getFile(KNOWN_HOSTS));
    final JSch jsch = factory.createDefaultJSch(fs);
    final HostKey[] keys = jsch.getHostKeyRepository().getHostKey("github.com", "ssh-rsa");
    assertEquals(1, keys.length);
}
项目:multi-module-maven-release-plugin    文件:SshAgentSessionFactoryTest.java   
@Test
public void createDefaultJSch_WithKnownHosts() throws Exception {
    final SshAgentSessionFactory factory = new SshAgentSessionFactory(log, KNOWN_HOSTS, null, null);
    factory.setKnownHosts(getFile(KNOWN_HOSTS));
    final JSch jsch = factory.createDefaultJSch(fs);
    final HostKey[] keys = jsch.getHostKeyRepository().getHostKey("github.com", "ssh-rsa");
    assertEquals(1, keys.length);
}
项目:gerrit    文件:SystemInfoServiceImpl.java   
@Override
public void daemonHostKeys(AsyncCallback<List<SshHostKey>> callback) {
  final ArrayList<SshHostKey> r = new ArrayList<>(hostKeys.size());
  for (HostKey hk : hostKeys) {
    String host = hk.getHost();
    if (host.startsWith("*:")) {
      final String port = host.substring(2);
      host = "[" + httpRequest.get().getServerName() + "]:" + port;
    }
    final String fp = hk.getFingerPrint(JSCH);
    r.add(new SshHostKey(host, hk.getType() + " " + hk.getKey(), fp));
  }
  callback.onSuccess(r);
}
项目:gerrit    文件:SshInfoServlet.java   
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
  final List<HostKey> hostKeys = sshd.getHostKeys();
  final String out;
  if (!hostKeys.isEmpty()) {
    String host = hostKeys.get(0).getHost();
    String port = "22";

    if (host.contains(":")) {
      final int p = host.lastIndexOf(':');
      port = host.substring(p + 1);
      host = host.substring(0, p);
    }

    if (host.equals("*")) {
      host = req.getServerName();

    } else if (host.startsWith("[") && host.endsWith("]")) {
      host = host.substring(1, host.length() - 1);
    }

    out = host + " " + port;
  } else {
    out = "NOT_AVAILABLE";
  }

  CacheHeaders.setNotCacheable(rsp);
  rsp.setCharacterEncoding(UTF_8.name());
  rsp.setContentType("text/plain");
  try (PrintWriter w = rsp.getWriter()) {
    w.write(out);
  }
}
项目:areca-backup-release-mirror    文件:SFTPEditionWindow.java   
private void updateFingerPrint() {
    if (txtHost.getText() != null && txtHostKey.getText() != null && txtHostKey.getText().length() != 0) {
        byte[] keybytes = Util.base64Decode(txtHostKey.getText());
        String fg = "<" + RM.getLabel("sftpedition.invalid.key.label") + ">";
        if (keybytes != null) {
            try {
                HostKey key = new HostKey(txtHost.getText(), keybytes);
                fg = key.getFingerPrint(new JSch());
            } catch (JSchException ignored) {
            }
        }

        lblFingerprint.setText(RM.getLabel("sftpedition.fg.label") + " " + fg); 
    }
}
项目:areca-backup-release-mirror    文件:SFTPProxy.java   
/**
 * Enforce server reconnection (closes the current connection if it is still alive)
 */
public synchronized void connect() throws SFTPConnectionException {
    //checkLocked();

    try {
        // Try to disconnect
        this.disconnect();

        // Open new connection          
        Logger.defaultLogger().info("Trying to connect to server : " + this.remoteServer + " ...");
        debug("connect : connect", remoteServer);

        JSch jsch = new JSch();
        if (checkHostKey) {
            HostKeyRepository hkr = jsch.getHostKeyRepository();
            byte[] keybytes = this.getHostKeyAsByteArray();
            if (keybytes == null) {
                throw new SFTPConnectionException("Incorrect hostkey : " + this.getHostKeyAsString());
            }
            HostKey key = new HostKey(remoteServer, keybytes);
            hkr.add(key, null);
            jsch.setHostKeyRepository(hkr);
        }

        if (useCertificateAuth) {
            if (certificateFileName == null || certificateFileName.trim().length() == 0 || ! FileSystemManager.exists(new File(certificateFileName))) {
                throw new SFTPConnectionException("Certificate file not set or not found : " + certificateFileName);
            } else {
                Logger.defaultLogger().info("Using private key file : " + certificateFileName);
                if (certificateFileName.toLowerCase().endsWith(".ppk")) {
                    Logger.defaultLogger().warn("Your private key file seems to be in PuTTY's \"ppk\" file format. Please convert it to the standard OpenSSH format (this can be done by using the \"puttygen.exe\" utility - see \"Convertions\" menu.)");
                }
                jsch.addIdentity(certificateFileName);
            }
        }
        session = jsch.getSession(login, remoteServer, remotePort);
        UserInfo ui = new DefaultUserInfo(this.password, certPassPhrase, certificateFileName);
        session.setUserInfo(ui);

        session.setDaemonThread(true);
        session.setConfig("StrictHostKeyChecking", checkHostKey ? "yes":"no");

        String preferredAuth;
        String configuredPAuth = FrameworkConfiguration.getInstance().getSftpPreferredAuthOverride();
        if (configuredPAuth != null && configuredPAuth.trim().length() != 0) {
            preferredAuth = configuredPAuth;
        } else {
            preferredAuth = useCertificateAuth ? "publickey,password" : "password,publickey";
        }
        Logger.defaultLogger().fine("Authentication methods: " + preferredAuth);

        session.setConfig("PreferredAuthentications", preferredAuth);
        session.setTimeout(FrameworkConfiguration.getInstance().getSFTPTimeout());

        Logger.defaultLogger().info("Trying to log in with user : " + this.login + " (" + (useCertificateAuth ? "certificate":"password") + ") ...");
        debug("connect : login", login);
        session.connect();

        client = (ChannelSftp)session.openChannel("sftp");
        client.connect();

        this.connectionId = Util.getRndLong();
        this.updateOpTime();

        Logger.defaultLogger().info("Connected to server : " + this.remoteServer);
    } catch (JSchException e) {
        resetClient(e);
        throw new SFTPConnectionException("Unable to connect to server : " + this.remoteServer + " (" + e.getMessage() + ")");
    } finally {
        clearCache();
    }
}
项目:droid-ssh    文件:FingerPrintRepository.java   
public int check(String host, byte[] key)
{
    try
    {
        List<HostKeys> keyList = dbInstance.getHostKey(host);
        if(keyList.size() > 0)
        {
            Iterator localIterator = keyList.iterator();
            while (localIterator.hasNext())
            {
                HostKeys localHost = (HostKeys)localIterator.next();
                HostKey JcHost = new HostKey(host, key);
                boolean res = JcHost.getKey().equals(localHost.getKey());
                if(res == true)
                {
                    return 0;
                }
                else
                {
                    return 2;
                }
            }
        }
    }
    catch(Exception e)
    {
        return 1;
    }
    return 1;
}
项目:centraldogma    文件:GitWithAuth.java   
@Override
public void add(HostKey hostkey, UserInfo ui) {}
项目:centraldogma    文件:GitWithAuth.java   
@Override
public HostKey[] getHostKey() {
    throw new UnsupportedOperationException();
}
项目:centraldogma    文件:GitWithAuth.java   
@Override
public HostKey[] getHostKey(String host, String type) {
    // TODO(trustin): Store the hostkeys in the meta repository.
    return EMPTY_HOST_KEYS;
}
项目:SimpleSSH    文件:FakeHostKeyRepository.java   
@Override
public void add(HostKey hostkey, com.jcraft.jsch.UserInfo ui) {
    //No Op implementation
}
项目:SimpleSSH    文件:FakeHostKeyRepository.java   
@Override
public HostKey[] getHostKey() {
    return new HostKey[0];
}
项目:SimpleSSH    文件:FakeHostKeyRepository.java   
@Override
public HostKey[] getHostKey(String host, String type) {
    return new HostKey[0];
}
项目:bugminer    文件:CustomSshConfigSessionFactory.java   
@Override
public void add(HostKey hostkey, UserInfo ui) {
    // nothing to do
}
项目:bugminer    文件:CustomSshConfigSessionFactory.java   
@Override
public HostKey[] getHostKey() {
    return new HostKey[0];
}
项目:bugminer    文件:CustomSshConfigSessionFactory.java   
@Override
public HostKey[] getHostKey(String host, String type) {
    return new HostKey[0];
}
项目:gerrit    文件:SshDaemon.java   
@Override
public List<HostKey> getHostKeys() {
  return hostKeys;
}
项目:gerrit    文件:NoSshInfo.java   
@Override
public List<HostKey> getHostKeys() {
  return Collections.emptyList();
}
项目:jcabi-ssh    文件:EasyRepo.java   
@Override
public void add(final HostKey hostkey, final UserInfo info) {
    // do nothing
}
项目:jcabi-ssh    文件:EasyRepo.java   
@Override
public HostKey[] getHostKey() {
    return new HostKey[0];
}
项目:jcabi-ssh    文件:EasyRepo.java   
@Override
public HostKey[] getHostKey(final String host, final String type) {
    return new HostKey[0];
}
项目:ninja_chic-    文件:CuriousHostKeyRepository.java   
public void add(HostKey hostkey, UserInfo ui) {
}
项目:ninja_chic-    文件:CuriousHostKeyRepository.java   
public HostKey[] getHostKey() {
    return new HostKey[0];
}
项目:ninja_chic-    文件:CuriousHostKeyRepository.java   
public HostKey[] getHostKey(String host, String type) {
    return new HostKey[0];
}
项目:gerrit-events    文件:SshConnectionImpl.java   
@Override
public void add(HostKey hostkey, UserInfo ui) {
}
项目:gerrit-events    文件:SshConnectionImpl.java   
@Override
public HostKey[] getHostKey() {
    return EMPTY;
}
项目:gerrit-events    文件:SshConnectionImpl.java   
@Override
public HostKey[] getHostKey(String host, String type) {
    return EMPTY;
}
项目:wagon-git    文件:AcceptAllHostKeyRepository.java   
/**
 * Does nothing. {@inheritDoc}
 */
@Override
public void add(HostKey hostkey,
    UserInfo ui) {

}
项目:wagon-git    文件:AcceptAllHostKeyRepository.java   
@Override
public HostKey[] getHostKey() {

    return new HostKey[0];
}
项目:wagon-git    文件:AcceptAllHostKeyRepository.java   
@Override
public HostKey[] getHostKey(String host,
    String type) {

    return new HostKey[0];
}
项目:droid-ssh    文件:FingerPrintRepository.java   
public void add(HostKey hostkey, UserInfo ui)
{
    HostKeys host = new HostKeys(hostkey.getHost(), hostkey.getFingerPrint(parameter), hostkey.getKey(), hostkey.getType());
    dbInstance.addHostKey(host);
}
项目:droid-ssh    文件:FingerPrintRepository.java   
public HostKey[] getHostKey()
{
    Log.d(log, "getHostKey");
    return null;
}
项目:gerrit    文件:SshInfo.java   
List<HostKey> getHostKeys();