/** * Append a single entry */ public void write(KnownHostEntry entry) throws IOException { final BufferedWriter writer = new BufferedWriter(new FileWriter(khFile, true)); try { writer.write(entry.getLine()); writer.newLine(); writer.flush(); } finally { IOUtils.closeQuietly(writer); } }
@Override public boolean verify(final String hostname, final int port, final PublicKey key) { final KeyType type = KeyType.fromKey(key); if (type == KeyType.UNKNOWN) { return false; } final String adjustedHostname = (port != 22) ? "[" + hostname + "]:" + port : hostname; boolean foundApplicableHostEntry = false; for (KnownHostEntry e : entries) { try { if (e.appliesTo(type, adjustedHostname)) { foundApplicableHostEntry = true; if (e.verify(key)) { return true; } } } catch (IOException ioe) { log.error("Error with {}: {}", e, ioe); return false; } } if (foundApplicableHostEntry) { return hostKeyChangedAction(adjustedHostname, key); } return hostKeyUnverifiableAction(adjustedHostname, key); }
/** * Append a single entry */ public void write(KnownHostEntry entry) throws IOException { final BufferedWriter writer = new BufferedWriter(new FileWriter(khFile, true)); try { writer.write(entry.getLine()); writer.newLine(); writer.flush(); } finally { IOUtils.closeQuietly(writer); } }
public void write() throws IOException { final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(khFile)); try { for (KnownHostEntry entry : entries) bos.write((entry.getLine() + LS).getBytes(IOUtils.UTF8)); } finally { bos.close(); } }
@Override public boolean verify(final String hostname, final int port, final PublicKey key) { final KeyType type = KeyType.fromKey(key); if (type == KeyType.UNKNOWN) { return false; } final String adjustedHostname = (port != 22) ? "[" + hostname + "]:" + port : hostname; boolean foundApplicableHostEntry = false; for (KnownHostEntry e : entries) { try { if (e.appliesTo(type, adjustedHostname)) { foundApplicableHostEntry = true; if (e.verify(key)) { return true; } } } catch (IOException ioe) { log.error("Error with {}: {}", e, ioe); return false; } } if (foundApplicableHostEntry) { return hostKeyChangedAction(adjustedHostname, key); } return hostKeyUnverifiableAction(adjustedHostname, key); }
public void write() throws IOException { final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(khFile)); try { for (KnownHostEntry entry : entries) bos.write((entry.getLine() + LS).getBytes(IOUtils.UTF8)); } finally { bos.close(); } }