diff options
author | Kenny Root <kenny@the-b.org> | 2016-03-11 19:19:44 -0800 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2016-03-11 21:29:18 -0800 |
commit | 680c02b1ac67da920b734139ddbd1a59fd15dabc (patch) | |
tree | f65a25adebec7216f7b21e520552f0a72f74640f /app | |
parent | 31aa10bbab29169bb028224373470ff2f438a221 (diff) | |
download | connectbot-680c02b1ac67da920b734139ddbd1a59fd15dabc.tar.gz connectbot-680c02b1ac67da920b734139ddbd1a59fd15dabc.tar.bz2 connectbot-680c02b1ac67da920b734139ddbd1a59fd15dabc.zip |
Make sure new known hosts are inserted and deleted
The host keys were not being inserted because it was using the old
update code, so fix that up and make sure that known host entries are
deleted when hosts are deleted.
This fixes issue #380.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/org/connectbot/util/HostDatabase.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/app/src/main/java/org/connectbot/util/HostDatabase.java b/app/src/main/java/org/connectbot/util/HostDatabase.java index 0761c27..c383efe 100644 --- a/app/src/main/java/org/connectbot/util/HostDatabase.java +++ b/app/src/main/java/org/connectbot/util/HostDatabase.java @@ -434,9 +434,11 @@ public class HostDatabase extends RobustSQLiteOpenHelper implements HostStorage, return; } + String[] hostIdArg = new String[] {String.valueOf(host.getId())}; mDb.beginTransaction(); try { - mDb.delete(TABLE_HOSTS, "_id = ?", new String[] {String.valueOf(host.getId())}); + mDb.delete(TABLE_KNOWNHOSTS, FIELD_KNOWNHOSTS_HOSTID + " = ?", hostIdArg); + mDb.delete(TABLE_HOSTS, "_id = ?", hostIdArg); mDb.setTransactionSuccessful(); } finally { mDb.endTransaction(); @@ -590,10 +592,6 @@ public class HostDatabase extends RobustSQLiteOpenHelper implements HostStorage, * @param hostkey the bytes of the host key itself */ public void saveKnownHost(String hostname, int port, String hostkeyalgo, byte[] hostkey) { - ContentValues values = new ContentValues(); - values.put(FIELD_KNOWNHOSTS_HOSTKEYALGO, hostkeyalgo); - values.put(FIELD_KNOWNHOSTS_HOSTKEY, hostkey); - HashMap<String, String> selection = new HashMap<>(); selection.put(FIELD_HOST_HOSTNAME, hostname); selection.put(FIELD_HOST_PORT, String.valueOf(port)); @@ -605,18 +603,23 @@ public class HostDatabase extends RobustSQLiteOpenHelper implements HostStorage, return; } - int numUpdated; + ContentValues values = new ContentValues(); + values.put(FIELD_KNOWNHOSTS_HOSTKEYALGO, hostkeyalgo); + values.put(FIELD_KNOWNHOSTS_HOSTKEY, hostkey); + values.put(FIELD_KNOWNHOSTS_HOSTID, hostBean.getId()); + mDb.beginTransaction(); try { - numUpdated = mDb.update(TABLE_KNOWNHOSTS, values, - FIELD_KNOWNHOSTS_HOSTID + " = ?", - new String[] {String.valueOf(hostBean.getId())}); + mDb.delete(TABLE_KNOWNHOSTS, FIELD_KNOWNHOSTS_HOSTID + " = ? AND " + + FIELD_KNOWNHOSTS_HOSTKEYALGO + " = ?", + new String[] {String.valueOf(hostBean.getId()), hostkeyalgo}); + mDb.insert(TABLE_KNOWNHOSTS, null, values); mDb.setTransactionSuccessful(); } finally { mDb.endTransaction(); } - Log.d(TAG, String.format("Finished saving hostkey information for '%s' (affected %d entries)", - hostname, numUpdated)); + Log.d(TAG, String.format("Finished saving hostkey information for '%s:%d' algo %s", + hostname, port, hostkeyalgo)); } @Override |