@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); }
private void addInvalidLine(String line) throws JSchException { HostKey hk = new HostKey(line, HostKey.UNKNOWN, null); pool.addElement(hk); } String getKnownHostsFile(){ return known_hosts; }
private void addInvalidLine(String line) throws JSchException { HostKey hk = new HostKey(line, HostKey.UNKNOWN, null); pool.addElement(hk); } String getKnownHostsFile(){ return known_hosts; }
private void addInvalidLine(String line) throws JSchException { HostKey hk = new HostKey(line, HostKey.UNKNOWN, null); pool.addElement(hk); } String getKnownHostsFile(){ return known_hosts; }
private void addInvalidLine(String line) throws JSchException { HostKey hk = new HostKey(line, HostKey.UNKNOWN, null); pool.addElement(hk); } String getKnownHostsFile(){ return known_hosts; }
private void addInvalidLine(String line) throws JSchException { HostKey hk = new HostKey(line, HostKey.UNKNOWN, null); pool.add(hk); }
@Override public HostKey[] getHostKey( String host, String type ) { host = host.replace("[", "").replace("]", "").split(":")[0]; Set<byte[]> keys = knownHostsMap.get(host); HostKey[] hostKeys = new HostKey[keys.size()]; Iterator<byte[]> it = keys.iterator(); int i = 0; while (it.hasNext()) { try { hostKeys[i++] = new HostKey(host, HostKey.SSHRSA, it.next()); } catch (JSchException e) { throw new RuntimeException("Unable to get hostkey for host '" + host + "'"); } } return hostKeys; }
public boolean hasSameFingerprint(String pubkey, String fingerprint) { try { byte[] pubKeyDecoded = Base64.getDecoder().decode(pubkey.getBytes()); HostKey hk; hk = new HostKey(HOST, pubKeyDecoded); String pubkeyFingerprint = hk.getFingerPrint(new JSch()); return fingerprint.equals(pubkeyFingerprint); } catch (JSchException e) { log.warn(e.getMessage()); return false; } }
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); }
hk = new HostKey(host, HostKey.GUESS, key);
hk = new HostKey(host, HostKey.GUESS, key);
hk = new HostKey(host, HostKey.GUESS, key);
public int check(String host, byte[] key) { int result = NOT_INCLUDED; if (host == null) { return result; } HostKey hk; try { hk = new HostKey(host, HostKey.GUESS, key); } catch (JSchException e) { return result; } synchronized (pool) { for (HostKey _hk : pool) { if (_hk.isMatched(host) && _hk.type == hk.type) { if (Util.array_equals(_hk.key, key)) { return OK; } else { result = CHANGED; } } } } if (result == NOT_INCLUDED && host.startsWith("[") && host.indexOf("]:") > 1 ) { return check(host.substring(1, host.indexOf("]:")), key); } return result; }
private List<HostKey> computeHostKeys() { final List<PublicKey> keys = myHostKeys(); final ArrayList<HostKey> r = new ArrayList<HostKey>(); for (final PublicKey pub : keys) { final Buffer buf = new Buffer(); buf.putRawPublicKey(pub); final byte[] keyBin = buf.getCompactData(); for (final InetSocketAddress addr : myAddresses()) { try { r.add(new HostKey(SocketUtil.format(addr, IANA_SSH_PORT), keyBin)); } catch (JSchException e) { log.warn("Cannot format SSHD host key", e); } } } return Collections.unmodifiableList(r); }
private List<HostKey> computeHostKeys() { final List<PublicKey> keys = myHostKeys(); final ArrayList<HostKey> r = new ArrayList<HostKey>(); for (final PublicKey pub : keys) { final Buffer buf = new Buffer(); buf.putRawPublicKey(pub); final byte[] keyBin = buf.getCompactData(); for (final InetSocketAddress addr : myAddresses()) { try { r.add(new HostKey(SocketUtil.format(addr, IANA_SSH_PORT), keyBin)); } catch (JSchException e) { log.warn("Cannot format SSHD host key", e); } } } return Collections.unmodifiableList(r); }
} else { try { hkr.add(new HostKey(hostKey.getHost(), hostKey.getType().equals(SshConfiguration.PUBLIC_KEY_SSHDSA) ? HostKey.SSHDSS : HostKey.SSHRSA, hostKey .getKey()), new UserInfo() {
hostkey = ((KnownHosts) hkr).createHashedHostKey(chost, K_S); } else { hostkey = new HostKey(chost, K_S);
hostkey=new HostKey(chost, K_S);
hostkey=new HostKey(chost, K_S);
hostkey=new HostKey(chost, K_S);