diff --git a/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java b/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java index 1ed2396e..237ae3db 100644 --- a/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java +++ b/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java @@ -39,8 +39,9 @@ public class ConsoleKnownHostsVerifier @Override protected boolean hostKeyUnverifiableAction(String hostname, PublicKey key) { + final KeyType type = KeyType.fromKey(key); console.printf("The authenticity of host '%s' can't be established.\n" + - "%s key fingerprint is %s.\n", hostname, KeyType.fromKey(key), SecurityUtils.getFingerprint(key)); + "%s key fingerprint is %s.\n", hostname, type, SecurityUtils.getFingerprint(key)); String response = console.readLine("Are you sure you want to continue connecting (yes/no)? "); while (!(response.equalsIgnoreCase(YES) || response.equalsIgnoreCase(NO))) { response = console.readLine("Please explicitly enter yes/no: "); @@ -49,6 +50,7 @@ public class ConsoleKnownHostsVerifier try { entries().add(new SimpleEntry(hostname, key)); write(); + console.printf("Warning: Permanently added '%s' (%s) to the list of known hosts.\n", hostname, type); } catch (IOException e) { throw new RuntimeException(e); } @@ -62,7 +64,7 @@ public class ConsoleKnownHostsVerifier throws IOException { final KeyType type = KeyType.fromKey(key); final String fp = SecurityUtils.getFingerprint(key); - final String path = khFile.getAbsolutePath(); + final String path = getFile().getAbsolutePath(); console.printf( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" + "@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n" + @@ -73,7 +75,9 @@ public class ConsoleKnownHostsVerifier "The fingerprint for the %s key sent by the remote host is\n" + "%s.\n" + "Please contact your system administrator or" + - "add correct host key in %s to get rid of this message.\n", type, fp, path); + "add correct host key in %s to get rid of this message.\n", + type, fp, path); return false; } + } diff --git a/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java b/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java index e3fbd4f7..ceb1dca3 100644 --- a/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java +++ b/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java @@ -189,10 +189,10 @@ public class OpenSSHKnownHosts throw new SSHException("Line parts not 3: " + line); hashedHost = parts[0]; { - final String[] split = hashedHost.split("\\|"); - if (split.length != 4) + final String[] hostParts = hashedHost.split("\\|"); + if (hostParts.length != 4) throw new SSHException("Unrecognized format for hashed hostname"); - salt = split[2]; + salt = hostParts[2]; } init(parts[1], parts[2]); } @@ -235,13 +235,6 @@ public class OpenSSHKnownHosts protected final File khFile; protected final List entries = new ArrayList(); - /** - * Constructs a {@code KnownHosts} object from a file location - * - * @param khFile the file location - * - * @throws IOException if there is an error reading the file - */ public OpenSSHKnownHosts(File khFile) throws IOException { this.khFile = khFile;