@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); }
public void add(HostKey hostkey, UserInfo ui) { knownHosts.add(hostkey, ui); }
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); }
} else { try { hkr.add(new HostKey(hostKey.getHost(), hostKey.getType().equals(SshConfiguration.PUBLIC_KEY_SSHDSA) ? HostKey.SSHDSS : HostKey.SSHRSA, hostKey .getKey()), new UserInfo() {
hkr.add(hostkey, userinfo);
hkr.add(hostkey, userinfo);
hkr.add(hostkey, userinfo);
hkr.add(hostkey, userinfo);
hkr.add(hostkey, userinfo);