mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
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:
parent
d50e798c13
commit
6162247155
@ -50,6 +50,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
public String algorithm;
|
public String algorithm;
|
||||||
public boolean secretKey;
|
public boolean secretKey;
|
||||||
public String mPrimaryUserId;
|
public String mPrimaryUserId;
|
||||||
|
private String mExtraData;
|
||||||
|
|
||||||
private boolean mSelected;
|
private boolean mSelected;
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
dest.writeByte((byte) (mSelected ? 1 : 0));
|
dest.writeByte((byte) (mSelected ? 1 : 0));
|
||||||
dest.writeInt(mBytes.length);
|
dest.writeInt(mBytes.length);
|
||||||
dest.writeByteArray(mBytes);
|
dest.writeByteArray(mBytes);
|
||||||
|
dest.writeString(mExtraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
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.mSelected = source.readByte() == 1;
|
||||||
vr.mBytes = new byte[source.readInt()];
|
vr.mBytes = new byte[source.readInt()];
|
||||||
source.readByteArray(vr.mBytes);
|
source.readByteArray(vr.mBytes);
|
||||||
|
vr.mExtraData = source.readString();
|
||||||
|
|
||||||
return vr;
|
return vr;
|
||||||
}
|
}
|
||||||
@ -198,6 +201,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
mPrimaryUserId = uid;
|
mPrimaryUserId = uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExtraData() {
|
||||||
|
return mExtraData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraData(String extraData) {
|
||||||
|
mExtraData = extraData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for later querying from keyserver
|
* Constructor for later querying from keyserver
|
||||||
*/
|
*/
|
||||||
|
@ -74,13 +74,13 @@ public class KeybaseKeyServer extends KeyServer {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject getUser(String keybaseID) throws QueryException {
|
private JSONObject getUser(String keybaseId) throws QueryException {
|
||||||
try {
|
try {
|
||||||
return getFromKeybase("_/api/1.0/user/lookup.json?username=", keybaseID);
|
return getFromKeybase("_/api/1.0/user/lookup.json?username=", keybaseId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String detail = "";
|
String detail = "";
|
||||||
if (keybaseID != null) {
|
if (keybaseId != null) {
|
||||||
detail = ". Query was for user '" + keybaseID + "'";
|
detail = ". Query was for user '" + keybaseId + "'";
|
||||||
}
|
}
|
||||||
throw new QueryException(e.getMessage() + detail);
|
throw new QueryException(e.getMessage() + detail);
|
||||||
}
|
}
|
||||||
@ -88,12 +88,14 @@ public class KeybaseKeyServer extends KeyServer {
|
|||||||
|
|
||||||
private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException {
|
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");
|
String key_fingerprint = JWalk.getString(match, "components", "key_fingerprint", "val");
|
||||||
key_fingerprint = key_fingerprint.replace(" ", "").toUpperCase();
|
key_fingerprint = key_fingerprint.replace(" ", "").toUpperCase();
|
||||||
match = getUser(keybaseID);
|
match = getUser(keybaseID);
|
||||||
|
|
||||||
final ImportKeysListEntry entry = new ImportKeysListEntry();
|
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
|
// TODO: Fix; have suggested keybase provide this value to avoid search-time crypto calls
|
||||||
entry.setBitStrength(4096);
|
entry.setBitStrength(4096);
|
||||||
@ -116,7 +118,6 @@ public class KeybaseKeyServer extends KeyServer {
|
|||||||
ArrayList<String> userIds = new ArrayList<String>();
|
ArrayList<String> userIds = new ArrayList<String>();
|
||||||
String name = "keybase.io/" + keybaseID + " <" + keybaseID + "@keybase.io>";
|
String name = "keybase.io/" + keybaseID + " <" + keybaseID + "@keybase.io>";
|
||||||
userIds.add(name);
|
userIds.add(name);
|
||||||
userIds.add(keybaseID);
|
|
||||||
entry.setUserIds(userIds);
|
entry.setUserIds(userIds);
|
||||||
entry.setPrimaryUserId(name);
|
entry.setPrimaryUserId(name);
|
||||||
return entry;
|
return entry;
|
||||||
|
@ -749,8 +749,8 @@ public class KeychainIntentService extends IntentService
|
|||||||
KeybaseKeyServer server = new KeybaseKeyServer();
|
KeybaseKeyServer server = new KeybaseKeyServer();
|
||||||
for (ImportKeysListEntry entry : entries) {
|
for (ImportKeysListEntry entry : entries) {
|
||||||
// the keybase handle is in userId(1)
|
// the keybase handle is in userId(1)
|
||||||
String keybaseID = entry.getUserIds().get(1);
|
String keybaseId = entry.getExtraData();
|
||||||
byte[] downloadedKeyBytes = server.get(keybaseID).getBytes();
|
byte[] downloadedKeyBytes = server.get(keybaseId).getBytes();
|
||||||
|
|
||||||
// create PGPKeyRing object based on downloaded armored key
|
// create PGPKeyRing object based on downloaded armored key
|
||||||
PGPKeyRing downloadedKey = null;
|
PGPKeyRing downloadedKey = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user