This commit is contained in:
Shikhar Bhushan
2010-03-07 15:56:08 +01:00
parent 2d28857729
commit 795912958d
2 changed files with 10 additions and 13 deletions

View File

@@ -39,8 +39,9 @@ public class ConsoleKnownHostsVerifier
@Override @Override
protected boolean hostKeyUnverifiableAction(String hostname, PublicKey key) { 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" + 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)? "); String response = console.readLine("Are you sure you want to continue connecting (yes/no)? ");
while (!(response.equalsIgnoreCase(YES) || response.equalsIgnoreCase(NO))) { while (!(response.equalsIgnoreCase(YES) || response.equalsIgnoreCase(NO))) {
response = console.readLine("Please explicitly enter yes/no: "); response = console.readLine("Please explicitly enter yes/no: ");
@@ -49,6 +50,7 @@ public class ConsoleKnownHostsVerifier
try { try {
entries().add(new SimpleEntry(hostname, key)); entries().add(new SimpleEntry(hostname, key));
write(); write();
console.printf("Warning: Permanently added '%s' (%s) to the list of known hosts.\n", hostname, type);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -62,7 +64,7 @@ public class ConsoleKnownHostsVerifier
throws IOException { throws IOException {
final KeyType type = KeyType.fromKey(key); final KeyType type = KeyType.fromKey(key);
final String fp = SecurityUtils.getFingerprint(key); final String fp = SecurityUtils.getFingerprint(key);
final String path = khFile.getAbsolutePath(); final String path = getFile().getAbsolutePath();
console.printf( console.printf(
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" +
"@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\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" + "The fingerprint for the %s key sent by the remote host is\n" +
"%s.\n" + "%s.\n" +
"Please contact your system administrator or" + "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; return false;
} }
} }

View File

@@ -189,10 +189,10 @@ public class OpenSSHKnownHosts
throw new SSHException("Line parts not 3: " + line); throw new SSHException("Line parts not 3: " + line);
hashedHost = parts[0]; hashedHost = parts[0];
{ {
final String[] split = hashedHost.split("\\|"); final String[] hostParts = hashedHost.split("\\|");
if (split.length != 4) if (hostParts.length != 4)
throw new SSHException("Unrecognized format for hashed hostname"); throw new SSHException("Unrecognized format for hashed hostname");
salt = split[2]; salt = hostParts[2];
} }
init(parts[1], parts[2]); init(parts[1], parts[2]);
} }
@@ -235,13 +235,6 @@ public class OpenSSHKnownHosts
protected final File khFile; protected final File khFile;
protected final List<Entry> entries = new ArrayList<Entry>(); protected final List<Entry> entries = new ArrayList<Entry>();
/**
* 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) public OpenSSHKnownHosts(File khFile)
throws IOException { throws IOException {
this.khFile = khFile; this.khFile = khFile;