From 61622471557dc1f67a1465ca8fcace7604a8c1a7 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Wed, 14 May 2014 14:13:00 +0200 Subject: [PATCH] Add extraData property in ImportKeyListEntry This allows any KeyServer to store some extra data it might need. In the case of KeybaseKeyServer it is the username, which then can be grabbed directly, without the hack of storing it as userId. --- .../keychain/keyimport/ImportKeysListEntry.java | 11 +++++++++++ .../keychain/keyimport/KeybaseKeyServer.java | 13 +++++++------ .../keychain/service/KeychainIntentService.java | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java index 1199290e0..60416c3d0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java @@ -50,6 +50,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable { public String algorithm; public boolean secretKey; public String mPrimaryUserId; + private String mExtraData; private boolean mSelected; @@ -74,6 +75,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable { dest.writeByte((byte) (mSelected ? 1 : 0)); dest.writeInt(mBytes.length); dest.writeByteArray(mBytes); + dest.writeString(mExtraData); } public static final Creator CREATOR = new Creator() { @@ -93,6 +95,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable { vr.mSelected = source.readByte() == 1; vr.mBytes = new byte[source.readInt()]; source.readByteArray(vr.mBytes); + vr.mExtraData = source.readString(); return vr; } @@ -198,6 +201,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable { mPrimaryUserId = uid; } + public String getExtraData() { + return mExtraData; + } + + public void setExtraData(String extraData) { + mExtraData = extraData; + } + /** * Constructor for later querying from keyserver */ diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java index 6fd4c3975..d1755fa12 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java @@ -74,13 +74,13 @@ public class KeybaseKeyServer extends KeyServer { return results; } - private JSONObject getUser(String keybaseID) throws QueryException { + private JSONObject getUser(String keybaseId) throws QueryException { try { - return getFromKeybase("_/api/1.0/user/lookup.json?username=", keybaseID); + return getFromKeybase("_/api/1.0/user/lookup.json?username=", keybaseId); } catch (Exception e) { String detail = ""; - if (keybaseID != null) { - detail = ". Query was for user '" + keybaseID + "'"; + if (keybaseId != null) { + detail = ". Query was for user '" + keybaseId + "'"; } throw new QueryException(e.getMessage() + detail); } @@ -88,12 +88,14 @@ public class KeybaseKeyServer extends KeyServer { private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException { - String keybaseID = JWalk.getString(match, "components", "username", "val"); String key_fingerprint = JWalk.getString(match, "components", "key_fingerprint", "val"); key_fingerprint = key_fingerprint.replace(" ", "").toUpperCase(); match = getUser(keybaseID); final ImportKeysListEntry entry = new ImportKeysListEntry(); + String keybaseId = JWalk.getString(match, "components", "username", "val"); + // store extra info, so we can query for the keybase id directly + entry.setExtraData(keybaseId); // TODO: Fix; have suggested keybase provide this value to avoid search-time crypto calls entry.setBitStrength(4096); @@ -116,7 +118,6 @@ public class KeybaseKeyServer extends KeyServer { ArrayList userIds = new ArrayList(); String name = "keybase.io/" + keybaseID + " <" + keybaseID + "@keybase.io>"; userIds.add(name); - userIds.add(keybaseID); entry.setUserIds(userIds); entry.setPrimaryUserId(name); return entry; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index f1e30c560..ca4f5869b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -749,8 +749,8 @@ public class KeychainIntentService extends IntentService KeybaseKeyServer server = new KeybaseKeyServer(); for (ImportKeysListEntry entry : entries) { // the keybase handle is in userId(1) - String keybaseID = entry.getUserIds().get(1); - byte[] downloadedKeyBytes = server.get(keybaseID).getBytes(); + String keybaseId = entry.getExtraData(); + byte[] downloadedKeyBytes = server.get(keybaseId).getBytes(); // create PGPKeyRing object based on downloaded armored key PGPKeyRing downloadedKey = null;