1 import ch.ethz.ssh2.KnownHosts; 2 import ch.ethz.ssh2.ServerHostKeyVerifier; 3 4 class SimpleVerifier implements ServerHostKeyVerifier 5 { 6 KnownHosts database; 7 8 11 12 public SimpleVerifier(KnownHosts database) 13 { 14 if (database == null) 15 throw new IllegalArgumentException (); 16 17 this.database = database; 18 } 19 20 public boolean verifyServerHostKey(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey) 21 throws Exception 22 { 23 int result = database.verifyHostkey(hostname, serverHostKeyAlgorithm, serverHostKey); 24 25 switch (result) 26 { 27 case KnownHosts.HOSTKEY_IS_OK: 28 29 return true; 31 case KnownHosts.HOSTKEY_IS_NEW: 32 33 36 database.addHostkey(new String [] { hostname }, serverHostKeyAlgorithm, serverHostKey); 39 40 return true; 41 42 case KnownHosts.HOSTKEY_HAS_CHANGED: 43 44 return false; 47 48 default: 49 throw new IllegalStateException (); 50 } 51 } 52 } | Popular Tags |