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.
This commit is contained in:
Thialfihar 2014-05-14 14:13:00 +02:00
parent d50e798c13
commit 6162247155
3 changed files with 20 additions and 8 deletions

View File

@ -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<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
@ -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
*/

View File

@ -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<String> userIds = new ArrayList<String>();
String name = "keybase.io/" + keybaseID + " <" + keybaseID + "@keybase.io>";
userIds.add(name);
userIds.add(keybaseID);
entry.setUserIds(userIds);
entry.setPrimaryUserId(name);
return entry;

View File

@ -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;