本文整理汇总了Java中com.trilead.ssh2.KnownHosts.HOSTKEY_HAS_CHANGED属性的典型用法代码示例。如果您正苦于以下问题:Java KnownHosts.HOSTKEY_HAS_CHANGED属性的具体用法?Java KnownHosts.HOSTKEY_HAS_CHANGED怎么用?Java KnownHosts.HOSTKEY_HAS_CHANGED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.trilead.ssh2.KnownHosts
的用法示例。
在下文中一共展示了KnownHosts.HOSTKEY_HAS_CHANGED属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyServerHostKey
public boolean verifyServerHostKey(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey)
throws Exception
{
int result = database.verifyHostkey(hostname, serverHostKeyAlgorithm, serverHostKey);
switch (result)
{
case KnownHosts.HOSTKEY_IS_OK:
return true; // We are happy
case KnownHosts.HOSTKEY_IS_NEW:
// Unknown host? Blindly accept the key and put it into the cache.
// Well, you definitely can do better (e.g., ask the user).
// The following call will ONLY put the key into the memory cache!
// To save it in a known hosts file, also call "KnownHosts.addHostkeyToFile(...)"
database.addHostkey(new String[] { hostname }, serverHostKeyAlgorithm, serverHostKey);
return true;
case KnownHosts.HOSTKEY_HAS_CHANGED:
// Close the connection if the hostkey has changed.
// Better: ask user and add new key to database.
return false;
default:
throw new IllegalStateException();
}
}
示例2: verifyServerHostKey
public boolean verifyServerHostKey(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey)
throws Exception
{
int result = database.verifyHostkey(hostname, serverHostKeyAlgorithm, serverHostKey);
switch (result)
{
case KnownHosts.HOSTKEY_IS_OK:
return true; // We are happy
case KnownHosts.HOSTKEY_IS_NEW:
// Unknown host? Blindly accept the key and put it into the cache.
// Well, you definitely can do better (e.g., ask the user).
// The following call will ONLY put the key into the memory cache!
// To save it in a known hosts file, also call "KnownHosts.addHostkeyToFile(...)"
database.addHostkey(new String[] { hostname }, serverHostKeyAlgorithm, serverHostKey);
return true;
case KnownHosts.HOSTKEY_HAS_CHANGED:
// The connection if the hostkey has changed.
// put the key into the memory cache!
database.addHostkey(new String[] { hostname }, serverHostKeyAlgorithm, serverHostKey);
return true;
default:
throw new IllegalStateException();
}
}
示例3: verifyServerHostKey
public boolean verifyServerHostKey( String hostname, int port, String serverHostKeyAlgorithm,
byte[] serverHostKey ) throws Exception {
int result = database.verifyHostkey( hostname, serverHostKeyAlgorithm, serverHostKey );
switch ( result ) {
case KnownHosts.HOSTKEY_IS_OK:
return true; // We are happy
case KnownHosts.HOSTKEY_IS_NEW:
// Unknown host? Blindly accept the key and put it into the cache.
// Well, you definitely can do better (e.g., ask the user).
// The following call will ONLY put the key into the memory cache!
// To save it in a known hosts file, also call "KnownHosts.addHostkeyToFile(...)"
database.addHostkey( new String[] { hostname }, serverHostKeyAlgorithm, serverHostKey );
return true;
case KnownHosts.HOSTKEY_HAS_CHANGED:
// The connection if the hostkey has changed.
// put the key into the memory cache!
database.addHostkey( new String[] { hostname }, serverHostKeyAlgorithm, serverHostKey );
return true;
default:
throw new IllegalStateException();
}
}
示例4: verifyServerHostKey
public boolean verifyServerHostKey(String hostname, int port,
String serverHostKeyAlgorithm, byte[] serverHostKey) throws IOException {
// read in all known hosts from hostdb
KnownHosts hosts = manager.hostdb.getKnownHosts();
Boolean result;
String matchName = String.format(Locale.US, "%s:%d", hostname, port);
String fingerprint = KnownHosts.createHexFingerprint(serverHostKeyAlgorithm, serverHostKey);
String algorithmName;
if ("ssh-rsa".equals(serverHostKeyAlgorithm))
algorithmName = "RSA";
else if ("ssh-dss".equals(serverHostKeyAlgorithm))
algorithmName = "DSA";
else if (serverHostKeyAlgorithm.startsWith("ecdsa-"))
algorithmName = "EC";
else if ("ssh-ed25519".equals(serverHostKeyAlgorithm))
algorithmName = "Ed25519";
else
algorithmName = serverHostKeyAlgorithm;
switch (hosts.verifyHostkey(matchName, serverHostKeyAlgorithm, serverHostKey)) {
case KnownHosts.HOSTKEY_IS_OK:
bridge.outputLine(manager.res.getString(R.string.terminal_sucess, algorithmName, fingerprint));
return true;
case KnownHosts.HOSTKEY_IS_NEW:
// prompt user
bridge.outputLine(manager.res.getString(R.string.host_authenticity_warning, hostname));
bridge.outputLine(manager.res.getString(R.string.host_fingerprint, algorithmName, fingerprint));
result = bridge.promptHelper.requestBooleanPrompt(null, manager.res.getString(R.string.prompt_continue_connecting));
if (result == null) {
return false;
}
if (result) {
// save this key in known database
manager.hostdb.saveKnownHost(hostname, port, serverHostKeyAlgorithm, serverHostKey);
}
return result;
case KnownHosts.HOSTKEY_HAS_CHANGED:
String header = String.format("@ %s @",
manager.res.getString(R.string.host_verification_failure_warning_header));
char[] atsigns = new char[header.length()];
Arrays.fill(atsigns, '@');
String border = new String(atsigns);
bridge.outputLine(border);
bridge.outputLine(header);
bridge.outputLine(border);
bridge.outputLine(manager.res.getString(R.string.host_verification_failure_warning));
bridge.outputLine(String.format(manager.res.getString(R.string.host_fingerprint),
algorithmName, fingerprint));
// Users have no way to delete keys, so we'll prompt them for now.
result = bridge.promptHelper.requestBooleanPrompt(null, manager.res.getString(R.string.prompt_continue_connecting));
if (result != null && result) {
// save this key in known database
manager.hostdb.saveKnownHost(hostname, port, serverHostKeyAlgorithm, serverHostKey);
return true;
} else {
return false;
}
default:
bridge.outputLine(manager.res.getString(R.string.terminal_failed));
return false;
}
}
示例5: verifyServerHostKey
public boolean verifyServerHostKey(String hostname, int port,
String serverHostKeyAlgorithm, byte[] serverHostKey) throws IOException {
// read in all known hosts from hostdb
KnownHosts hosts = manager.hostdb.getKnownHosts();
Boolean result;
String matchName = String.format(Locale.US, "%s:%d", hostname, port);
String fingerprint = KnownHosts.createHexFingerprint(serverHostKeyAlgorithm, serverHostKey);
String algorithmName;
if ("ssh-rsa".equals(serverHostKeyAlgorithm))
algorithmName = "RSA";
else if ("ssh-dss".equals(serverHostKeyAlgorithm))
algorithmName = "DSA";
else if (serverHostKeyAlgorithm.startsWith("ecdsa-"))
algorithmName = "EC";
else
algorithmName = serverHostKeyAlgorithm;
switch(hosts.verifyHostkey(matchName, serverHostKeyAlgorithm, serverHostKey)) {
case KnownHosts.HOSTKEY_IS_OK:
bridge.outputLine(manager.res.getString(R.string.terminal_sucess, algorithmName, fingerprint));
return true;
case KnownHosts.HOSTKEY_IS_NEW:
// prompt user
bridge.outputLine(manager.res.getString(R.string.host_authenticity_warning, hostname));
bridge.outputLine(manager.res.getString(R.string.host_fingerprint, algorithmName, fingerprint));
result = bridge.promptHelper.requestBooleanPrompt(null, manager.res.getString(R.string.prompt_continue_connecting));
if(result == null) return false;
if(result.booleanValue()) {
// save this key in known database
manager.hostdb.saveKnownHost(hostname, port, serverHostKeyAlgorithm, serverHostKey);
}
return result.booleanValue();
case KnownHosts.HOSTKEY_HAS_CHANGED:
String header = String.format("@ %s @",
manager.res.getString(R.string.host_verification_failure_warning_header));
char[] atsigns = new char[header.length()];
Arrays.fill(atsigns, '@');
String border = new String(atsigns);
bridge.outputLine(border);
bridge.outputLine(manager.res.getString(R.string.host_verification_failure_warning));
bridge.outputLine(border);
bridge.outputLine(String.format(manager.res.getString(R.string.host_fingerprint),
algorithmName, fingerprint));
// Users have no way to delete keys, so we'll prompt them for now.
result = bridge.promptHelper.requestBooleanPrompt(null, manager.res.getString(R.string.prompt_continue_connecting));
if(result == null) return false;
if(result.booleanValue()) {
// save this key in known database
manager.hostdb.saveKnownHost(hostname, port, serverHostKeyAlgorithm, serverHostKey);
}
return result.booleanValue();
default:
return false;
}
}