private static void setPreferredKeyTypesOrder(Session session) { HostKeyRepository hkr = session.getHostKeyRepository(); List<String> known = Stream.of(hkr.getHostKey(hostName(session), null)) .map(HostKey::getType) .collect(toList()); if (!known.isEmpty()) { String serverHostKey = "server_host_key"; //$NON-NLS-1$ String current = session.getConfig(serverHostKey); if (current == null) { session.setConfig(serverHostKey, String.join(",", known)); //$NON-NLS-1$ return; } String knownFirst = Stream.concat( known.stream(), Stream.of(current.split(",")) //$NON-NLS-1$ .filter(s -> !known.contains(s))) .collect(joining(",")); //$NON-NLS-1$ session.setConfig(serverHostKey, knownFirst); } }
@Override protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException { if (sshKeysByHostname.containsKey(host)) { JGitEnvironmentProperties 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); }
i = hkr.check(chost, K_S); String file; synchronized (hkr) { file = hkr.getKnownHostsRepositoryID(); hkr.remove(chost, kex.getKeyAlgorithName(), null); insert = true; HostKey[] keys = hkr.getHostKey(chost, kex.getKeyAlgorithName()); String _key = Util.byte2str(Util.toBase64(K_S, 0, K_S.length)); for (HostKey key : keys) { hkr.add(hostkey, userinfo);
HostKey[] hks = hkr.getHostKey(); if (hks != null) { log.debug("Host keys in {}", hkr.getKnownHostsRepositoryID()); for (HostKey hk : hks) { log.trace("Loaded host key {} {} {}", hk.getHost(), hk.getType(), hk.getFingerPrint(jsch));
public void remove(String host, String type, byte[] key) { knownHosts.remove(host, type, key); } }
public String getKnownHostsRepositoryID() { return knownHosts.getKnownHostsRepositoryID(); }
return knownHosts.check(host, key);
int i=0; synchronized(hkr){ i=hkr.check(chost, K_S); String file=null; synchronized(hkr){ file=hkr.getKnownHostsRepositoryID(); hkr.remove(chost, (key_type.equals("DSA") ? "ssh-dss" : "ssh-rsa"), null); hkr.add(hostkey, userinfo);
public void remove(String host, String type) { knownHosts.remove(host, type); }
i=hkr.check(chost, K_S); String file=null; synchronized(hkr){ file=hkr.getKnownHostsRepositoryID(); hkr.remove(chost, kex.getKeyAlgorithName(), null); hkr.getHostKey(chost, kex.getKeyAlgorithName()); String _key= Util.byte2str(Util.toBase64(K_S, 0, K_S.length)); for(int j=0; j< keys.length; j++){ hkr.add(hostkey, userinfo);
public HostKey[] getHostKey(String host, String type) { return knownHosts.getHostKey(host, type); }
public void add(HostKey hostkey, UserInfo ui) { knownHosts.add(hostkey, ui); }
public void remove(SshHostKey hostKey) { hkr.remove(hostKey.getHost(), hostKey.getType()); }
i=hkr.check(chost, K_S); String file=null; synchronized(hkr){ file=hkr.getKnownHostsRepositoryID(); hkr.remove(chost, kex.getKeyAlgorithName(), null); hkr.getHostKey(chost, kex.getKeyAlgorithName()); String _key= Util.byte2str(Util.toBase64(K_S, 0, K_S.length)); for(int j=0; j< keys.length; j++){ hkr.add(hostkey, userinfo);
public HostKey[] getHostKey() { return knownHosts.getHostKey(); }
private void addPublicKeyToHostKeyRepostitory( PublicKey key, HostKeyRepository hostKeyRepository ) throws Exception { if (!key.getAlgorithm().contains("RSA")) { throw new Exception("Only RSA keys are supported!."); } byte[] opensshKeyContent = convertToOpenSSHKeyFormat((RSAPublicKey) key); HostKey hostkey = new HostKey(hostname, HostKey.SSHRSA, opensshKeyContent); hostKeyRepository.add(hostkey, null); }
i=hkr.check(chost, K_S); String file=null; synchronized(hkr){ file=hkr.getKnownHostsRepositoryID(); hkr.remove(chost, kex.getKeyAlgorithName(), null); hkr.getHostKey(chost, kex.getKeyAlgorithName()); String _key= Util.byte2str(Util.toBase64(K_S, 0, K_S.length)); for(int j=0; j< keys.length; j++){ hkr.add(hostkey, userinfo);
public SshHostKey[] getKeys() { List hostKeys = new ArrayList(); HostKey[] keys = hkr.getHostKey(); if (keys != null) { for (int i = 0; i < keys.length; i++) { hostKeys.add(new JschHostKey(keys[i])); } } return (SshHostKey[]) hostKeys.toArray(new SshHostKey[0]); }
} else { try { hkr.add(new HostKey(hostKey.getHost(), hostKey.getType().equals(SshConfiguration.PUBLIC_KEY_SSHDSA) ? HostKey.SSHDSS : HostKey.SSHRSA, hostKey .getKey()), new UserInfo() {
private static void setPreferredKeyTypesOrder(Session session) { HostKeyRepository hkr = session.getHostKeyRepository(); List<String> known = Stream.of(hkr.getHostKey(hostName(session), null)) .map(HostKey::getType) .collect(toList()); if (!known.isEmpty()) { String serverHostKey = "server_host_key"; //$NON-NLS-1$ String current = session.getConfig(serverHostKey); if (current == null) { session.setConfig(serverHostKey, String.join(",", known)); //$NON-NLS-1$ return; } String knownFirst = Stream.concat( known.stream(), Stream.of(current.split(",")) //$NON-NLS-1$ .filter(s -> !known.contains(s))) .collect(joining(",")); //$NON-NLS-1$ session.setConfig(serverHostKey, knownFirst); } }