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


Java KnownHosts类代码示例

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


KnownHosts类属于com.trilead.ssh2包,在下文中一共展示了KnownHosts类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKnownHosts

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
/**
 * Build list of known hosts for Trilead library.
 * @return
 */
public KnownHosts getKnownHosts() {
	KnownHosts known = new KnownHosts();

	Cursor c = mDb.query(TABLE_HOSTS + " LEFT OUTER JOIN " + TABLE_KNOWNHOSTS
					+ " ON " + TABLE_HOSTS + "._id = "
					+ TABLE_KNOWNHOSTS + "." + FIELD_KNOWNHOSTS_HOSTID,
			new String[] {FIELD_HOST_HOSTNAME, FIELD_HOST_PORT, FIELD_KNOWNHOSTS_HOSTKEYALGO,
					FIELD_KNOWNHOSTS_HOSTKEY},
			null, null, null, null, null);

	if (c != null) {
		int COL_HOSTNAME = c.getColumnIndexOrThrow(FIELD_HOST_HOSTNAME),
				COL_PORT = c.getColumnIndexOrThrow(FIELD_HOST_PORT),
				COL_HOSTKEYALGO = c.getColumnIndexOrThrow(FIELD_KNOWNHOSTS_HOSTKEYALGO),
				COL_HOSTKEY = c.getColumnIndexOrThrow(FIELD_KNOWNHOSTS_HOSTKEY);

		while (c.moveToNext()) {
			String hostname = c.getString(COL_HOSTNAME);
			String hostkeyalgo = c.getString(COL_HOSTKEYALGO);
			int port = c.getInt(COL_PORT);
			byte[] hostkey = c.getBlob(COL_HOSTKEY);

			if (hostkeyalgo == null || hostkeyalgo.length() == 0) continue;
			if (hostkey == null || hostkey.length == 0) continue;

			try {
				known.addHostkey(new String[] {String.format(Locale.US, "%s:%d", hostname, port)},
						hostkeyalgo, hostkey);
			} catch (Exception e) {
				Log.e(TAG, "Problem while adding a known host from database", e);
			}
		}

		c.close();
	}

	return known;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:43,代码来源:HostDatabase.java

示例2: getKnownHosts

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
/**
 * Build list of known hosts for Trilead library.
 * @return
 */
public KnownHosts getKnownHosts() {
	KnownHosts known = new KnownHosts();

	synchronized (dbLock) {
		SQLiteDatabase db = this.getReadableDatabase();
		Cursor c = db.query(TABLE_HOSTS, new String[] { FIELD_HOST_HOSTNAME,
				FIELD_HOST_PORT, FIELD_HOST_HOSTKEYALGO, FIELD_HOST_HOSTKEY },
				null, null, null, null, null);

		if (c != null) {
			int COL_HOSTNAME = c.getColumnIndexOrThrow(FIELD_HOST_HOSTNAME),
				COL_PORT = c.getColumnIndexOrThrow(FIELD_HOST_PORT),
				COL_HOSTKEYALGO = c.getColumnIndexOrThrow(FIELD_HOST_HOSTKEYALGO),
				COL_HOSTKEY = c.getColumnIndexOrThrow(FIELD_HOST_HOSTKEY);

			while (c.moveToNext()) {
				String hostname = c.getString(COL_HOSTNAME),
					hostkeyalgo = c.getString(COL_HOSTKEYALGO);
				int port = c.getInt(COL_PORT);
				byte[] hostkey = c.getBlob(COL_HOSTKEY);

				if (hostkeyalgo == null || hostkeyalgo.length() == 0) continue;
				if (hostkey == null || hostkey.length == 0) continue;

				try {
					known.addHostkey(new String[] { String.format("%s:%d", hostname, port) }, hostkeyalgo, hostkey);
				} catch(Exception e) {
					Log.e(TAG, "Problem while adding a known host from database", e);
				}
			}

			c.close();
		}
	}

	return known;
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:42,代码来源:HostDatabase.java

示例3: SimpleVerifier

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
public SimpleVerifier(KnownHosts database)
{
	if (database == null)
		throw new IllegalArgumentException();

	this.database = database;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:SimpleVerifier.java

示例4: verifyServerHostKey

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
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,代码行数:33,代码来源:SimpleVerifier.java

示例5: verifyServerHostKey

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
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,代码行数:35,代码来源:SimpleVerifier.java

示例6: SimpleVerifier

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
public SimpleVerifier( KnownHosts database ) {
  if ( database == null ) {
    throw new IllegalArgumentException();
  }

  this.database = database;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:8,代码来源:SimpleVerifier.java

示例7: verifyServerHostKey

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
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,代码行数:33,代码来源:SimpleVerifier.java

示例8: verifyServerHostKey

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
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,代码行数:76,代码来源:SSH.java

示例9: verifyServerHostKey

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
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,代码行数:68,代码来源:SSH.java

示例10: customizeScriptGenerator

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
@Override
protected void customizeScriptGenerator(@NotNull ScriptGenerator generator) {
  generator.addClasses(KnownHosts.class);
  generator.addResource(SSHMainBundle.class, "/org/jetbrains/git4idea/ssh/SSHMainBundle.properties");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:GitXmlRpcSshService.java

示例11: verifyServerHostKey

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
@Override
public boolean verifyServerHostKey(String hostname, int port,
		String serverHostKeyAlgorithm, byte[] serverHostKey)
		throws Exception {

	String fingerPrint = KnownHosts.createHexFingerprint(
			serverHostKeyAlgorithm, serverHostKey);
	int fingerPrintStatus = Constraints.FINGER_PRINT_CHANGED;

	if (profile.getFingerPrintType() == null
			|| profile.getFingerPrintType().equals("")) {
		fingerPrintStatus = Constraints.FINGER_PRINT_INIITIALIZE;
		reason = getString(R.string.finger_print_unknown);

	} else {

		if (profile.getFingerPrintType().equals(serverHostKeyAlgorithm)
				&& profile.getFingerPrint() != null
				&& profile.getFingerPrint().equals(fingerPrint)) {
			return true;
		} else {
			fingerPrintStatus = Constraints.FINGER_PRINT_CHANGED;
			reason = getString(R.string.finger_print_mismatch);
		}

	}

	Log.d(TAG, "Finger Print: " + profile.getFingerPrint());
	Log.d(TAG, "Finger Print Type: " + profile.getFingerPrintType());

	Bundle bundle = new Bundle();
	bundle.putInt(Constraints.ID, profile.getId());
	bundle.putInt(Constraints.FINGER_PRINT_STATUS, fingerPrintStatus);
	bundle.putString(Constraints.FINGER_PRINT, fingerPrint);
	bundle.putString(Constraints.FINGER_PRINT_TYPE, serverHostKeyAlgorithm);

	Message msg = new Message();
	msg.setData(bundle);

	hostKeyHandler.sendMessage(msg);

	synchronized (fingerPrintLock) {
		fingerPrintLock.wait();
	}

	return fingerPrintChecker;

}
 
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:49,代码来源:SSHTunnelService.java

示例12: getHostKeySignature

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
/**
 * Return a string holding a Hex representation of the signature of the remote host's key.
 */
public String getHostKeySignature () {
    return KnownHosts.createHexFingerprint(connectionInfo.serverHostKeyAlgorithm,
                                           connectionInfo.serverHostKey);
}
 
开发者ID:runsoftdev,项目名称:bVnc,代码行数:8,代码来源:SSHConnection.java

示例13: getKnownHosts

import com.trilead.ssh2.KnownHosts; //导入依赖的package包/类
/**
 * Returns the list of known hosts.
 *
 * @see #saveKnownHost(String, int, String, byte[])
 */
KnownHosts getKnownHosts();
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:HostStorage.java


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