@Test public void testVerifyDenyServerHostKey() throws Exception { PreferencesHostKeyVerifier v = new PreferencesHostKeyVerifier() { @Override public boolean isChangedKeyAccepted(Host hostname, PublicKey key) { return false; } @Override public boolean isUnknownKeyAccepted(Host hostname, final PublicKey key) { return false; } }; final PublicKey key = SecurityUtils.getKeyFactory("RSA").generatePublic(new RSAPublicKeySpec(new BigInteger("a19f65e93926d9a2f5b52072db2c38c54e6cf0113d31fa92ff827b0f3bec609c45ea84264c88e64adba11ff093ed48ee0ed297757654b0884ab5a7e28b3c463bc9074b32837a2b69b61d914abf1d74ccd92b20fa44db3b31fb208c0dd44edaeb4ab097118e8ee374b6727b89ad6ce43f1b70c5a437ccebc36d2dad8ae973caad15cd89ae840fdae02cae42d241baef8fda8aa6bbaa54fd507a23338da6f06f61b34fb07d560e63fbce4a39c073e28573c2962cedb292b14b80d1b4e67b0465f2be0e38526232d0a7f88ce91a055fde082038a87ed91f3ef5ff971e30ea6cccf70d38498b186621c08f8fdceb8632992b480bf57fc218e91f2ca5936770fe9469", 16), new BigInteger("23", 16))); assertFalse(v.verify(new Host(new SFTPProtocol(), "bhostname", 22), key)); assertNull(PreferencesFactory.get().getProperty("ssh.hostkey.ssh-rsa.bhostname")); }
@Override public boolean verify(final Host host, final PublicKey key) throws ConnectionCanceledException, ChecksumException { final String lookup = preferences.getProperty(this.getFormat(host, key)); if(StringUtils.equals(Base64.toBase64String(key.getEncoded()), lookup)) { if(log.isInfoEnabled()) { log.info(String.format("Accepted host key %s matching %s", key, lookup)); } return true; } final boolean accept; if(null == lookup) { accept = this.isUnknownKeyAccepted(host, key); } else { accept = this.isChangedKeyAccepted(host, key); } return accept; }
PreferencesHostKeyVerifier extends AbstractHostKeyCallback { @Override public boolean verify(final Host host, final PublicKey key) throws ConnectionCanceledException, ChecksumException { final String lookup = preferences.getProperty(this.getFormat(host, key)); if(StringUtils.equals(Base64.toBase64String(key.getEncoded()), lookup)) { if(log.isInfoEnabled()) { log.info(String.format("Accepted host key %s matching %s", key, lookup)); } return true; } final boolean accept; if(null == lookup) { accept = this.isUnknownKeyAccepted(host, key); } else { accept = this.isChangedKeyAccepted(host, key); } return accept; } }
PreferencesHostKeyVerifier extends AbstractHostKeyCallback { @Override public boolean verify(final Host host, final PublicKey key) throws ConnectionCanceledException, ChecksumException { final String lookup = preferences.getProperty(this.getFormat(host, key)); if(StringUtils.equals(Base64.toBase64String(key.getEncoded()), lookup)) { if(log.isInfoEnabled()) { log.info(String.format("Accepted host key %s matching %s", key, lookup)); } return true; } final boolean accept; if(null == lookup) { accept = this.isUnknownKeyAccepted(host, key); } else { accept = this.isChangedKeyAccepted(host, key); } return accept; }  }
PreferencesHostKeyVerifier extends AbstractHostKeyCallback { @Override public boolean verify(final Host host, final PublicKey key) throws ConnectionCanceledException, ChecksumException { final String lookup = preferences.getProperty(this.getFormat(host, key)); if(StringUtils.equals(Base64.toBase64String(key.getEncoded()), lookup)) { if(log.isInfoEnabled()) { log.info(String.format("Accepted host key %s matching %s", key, lookup)); } return true; } final boolean accept; if(null == lookup) { accept = this.isUnknownKeyAccepted(host, key); } else { accept = this.isChangedKeyAccepted(host, key); } return accept; }  @Override boolean verify(final Host host, final PublicKey key); }
PreferencesHostKeyVerifier extends AbstractHostKeyCallback { @Override public boolean verify(final Host host, final PublicKey key) throws ConnectionCanceledException, ChecksumException { final String lookup = preferences.getProperty(this.getFormat(host, key)); if(StringUtils.equals(Base64.toBase64String(key.getEncoded()), lookup)) { if(log.isInfoEnabled()) { log.info(String.format("Accepted host key %s matching %s", key, lookup)); } return true; } final boolean accept; if(null == lookup) { accept = this.isUnknownKeyAccepted(host, key); } else { accept = this.isChangedKeyAccepted(host, key); } return accept; }  @Override boolean verify(final Host host, final PublicKey key);  }