use of org.eclipse.jgit.transport.sshd.SshdSessionFactory in project gerrit by GerritCodeReview.
the class SshSessionMina method getMinaSession.
private SshdSession getMinaSession() throws Exception {
if (session == null) {
String username = getUsername();
URIish uri = new URIish("ssh://" + username + "@" + addr.getAddress().getHostAddress() + ":" + addr.getPort());
// TODO(davido): Switch to memory only key resolving mode.
File userhome = createTempDirectory("home-").toFile();
FS fs = FS.DETECTED.setUserHome(userhome);
File sshDir = new File(userhome, ".ssh");
sshDir.mkdir();
OpenSSHKeyPairResourceWriter keyPairWriter = new OpenSSHKeyPairResourceWriter();
try (OutputStream out = new FileOutputStream(new File(sshDir, "id_ecdsa"))) {
keyPairWriter.writePrivateKey(sshKeys.getKeyPair(account), null, null, out);
}
// TODO(davido): Disable programmatically host key checking: "StrictHostKeyChecking: no" mode.
CharSink configFile = Files.asCharSink(new File(sshDir, "config"), UTF_8);
configFile.writeLines(Arrays.asList("Host *", "StrictHostKeyChecking no"));
JGitKeyCache keyCache = new JGitKeyCache();
try (SshdSessionFactory factory = new SshdSessionFactory(keyCache, new DefaultProxyDataFactory())) {
factory.setHomeDirectory(userhome);
factory.setSshDirectory(sshDir);
session = factory.getSession(uri, null, fs, TIMEOUT);
session.addCloseListener(future -> {
try {
MoreFiles.deleteRecursively(userhome.toPath(), ALLOW_INSECURE);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Failed to cleanup userhome", e);
}
});
}
}
return session;
}
use of org.eclipse.jgit.transport.sshd.SshdSessionFactory in project gerrit by GerritCodeReview.
the class SshSessionFactoryInitializer method init.
public static void init() {
SshdSessionFactory factory = new SshdSessionFactory(new JGitKeyCache(), new DefaultProxyDataFactory());
factory.setHomeDirectory(FS.DETECTED.userHome());
SshSessionFactory.setInstance(factory);
}
use of org.eclipse.jgit.transport.sshd.SshdSessionFactory in project gerrit by GerritCodeReview.
the class SshSessionMina method initClient.
public static void initClient() {
JGitKeyCache keyCache = new JGitKeyCache();
SshdSessionFactory factory = new SshdSessionFactory(keyCache, new DefaultProxyDataFactory());
SshSessionFactory.setInstance(factory);
}
Aggregations