当前位置: 首页>>代码示例>>Java>>正文


Java KnownHosts.HOSTKEY_IS_NEW属性代码示例

本文整理汇总了Java中com.trilead.ssh2.KnownHosts.HOSTKEY_IS_NEW属性的典型用法代码示例。如果您正苦于以下问题:Java KnownHosts.HOSTKEY_IS_NEW属性的具体用法?Java KnownHosts.HOSTKEY_IS_NEW怎么用?Java KnownHosts.HOSTKEY_IS_NEW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.trilead.ssh2.KnownHosts的用法示例。


在下文中一共展示了KnownHosts.HOSTKEY_IS_NEW属性的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();
	}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:SimpleVerifier.java

示例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();
	}
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:34,代码来源:SimpleVerifier.java

示例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();
  }
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:32,代码来源:SimpleVerifier.java

示例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;
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:75,代码来源:SSH.java

示例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;
	}
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:67,代码来源:SSH.java


注:本文中的com.trilead.ssh2.KnownHosts.HOSTKEY_IS_NEW属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。