X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.core%2Fsrc%2Forg%2Fargeo%2Fssh%2FAbstractSsh.java;h=88b28b525290a113f94250b90458df06ef94bade;hb=2604d709c4554fecdf54a7d4e03cfb4d3c29d987;hp=ae1d6a0d4acabf446948ccbfce60026140c1ef8b;hpb=a8cfb641dff564ad08cbb437c2b0c29638a95252;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.core/src/org/argeo/ssh/AbstractSsh.java b/org.argeo.core/src/org/argeo/ssh/AbstractSsh.java index ae1d6a0d4..88b28b525 100644 --- a/org.argeo.core/src/org/argeo/ssh/AbstractSsh.java +++ b/org.argeo.core/src/org/argeo/ssh/AbstractSsh.java @@ -26,6 +26,8 @@ abstract class AbstractSsh { private boolean passwordSet = false; private ClientSession session; + private SshKeyPair sshKeyPair; + synchronized SshClient getSshClient() { if (sshClient == null) { long begin = System.currentTimeMillis(); @@ -48,21 +50,26 @@ abstract class AbstractSsh { void authenticate() { try { - if (!passwordSet) { - String password; - Console console = System.console(); - if (console == null) {// IDE - System.out.print("Password: "); - Scanner s = new Scanner(System.in); - password = s.next(); - } else { - console.printf("Password: "); - char[] pwd = console.readPassword(); - password = new String(pwd); - Arrays.fill(pwd, ' '); + if (sshKeyPair != null) { + session.addPublicKeyIdentity(sshKeyPair.asKeyPair()); + } else { + + if (!passwordSet) { + String password; + Console console = System.console(); + if (console == null) {// IDE + System.out.print("Password: "); + Scanner s = new Scanner(System.in); + password = s.next(); + } else { + console.printf("Password: "); + char[] pwd = console.readPassword(); + password = new String(pwd); + Arrays.fill(pwd, ' '); + } + session.addPasswordIdentity(password); + passwordSet = true; } - session.addPasswordIdentity(password); - passwordSet = true; } session.auth().verify(1000l); } catch (IOException e) {