aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-05-16 09:52:34 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2014-05-16 09:52:34 +0200
commit9025de2b74c18d45b7e1853964e8caa653db7432 (patch)
tree335fa8615608190d07d00b09af7c43fcf3860bed /OpenKeychain
parentbbc0694700ecc378692ec77d7966f7806ebc7258 (diff)
parent148a52269450e13a2c5db7670706beb86db8a631 (diff)
downloadopen-keychain-9025de2b74c18d45b7e1853964e8caa653db7432.tar.gz
open-keychain-9025de2b74c18d45b7e1853964e8caa653db7432.tar.bz2
open-keychain-9025de2b74c18d45b7e1853964e8caa653db7432.zip
Merge pull request #630 from timbray/master
Handle changed keybase.io search results format
Diffstat (limited to 'OpenKeychain')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java36
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/JWalk.java48
2 files changed, 60 insertions, 24 deletions
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 953cf3cbb..5f729a05c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyServer.java
@@ -21,6 +21,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.JWalk;
import org.sufficientlysecure.keychain.util.Log;
@@ -34,8 +35,6 @@ import java.util.WeakHashMap;
public class KeybaseKeyServer extends KeyServer {
- private WeakHashMap<String, String> mKeyCache = new WeakHashMap<String, String>();
-
@Override
public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses,
InsufficientQuery {
@@ -92,25 +91,18 @@ public class KeybaseKeyServer extends KeyServer {
String keybaseId = JWalk.getString(match, "components", "username", "val");
String fullName = JWalk.getString(match, "components", "full_name", "val");
String fingerprint = JWalk.getString(match, "components", "key_fingerprint", "val");
- fingerprint = fingerprint.replace(" ", "").toUpperCase();
+ fingerprint = fingerprint.replace(" ", "").toUpperCase(); // not strictly necessary but doesn't hurt
+ entry.setFingerprintHex(fingerprint);
// in anticipation of a full fingerprint, only use the last 16 chars as 64-bit key id
entry.setKeyIdHex("0x" + fingerprint.substring(Math.max(0, fingerprint.length() - 16)));
// 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);
- //entry.setAlgorithm("RSA");
-
- entry.setFingerprintHex(fingerprint);
-
- // key data
- // currently there's no need to query the user right away, and it should be avoided, so the
- // user doesn't experience lag and doesn't download many keys unnecessarily, but should we
- // require to do it at soe point:
- // (weakly) remember the key, in case the user tries to import it
- //mKeyCache.put(keybaseId, JWalk.getString(match, "them", "public_keys", "primary", "bundle"));
+ final int algorithmId = JWalk.getInt(match, "components", "key_fingerprint", "algo");
+ entry.setAlgorithm(PgpKeyHelper.getAlgorithmInfo(algorithmId));
+ final int bitStrength = JWalk.getInt(match, "components", "key_fingerprint", "nbits");
+ entry.setBitStrength(bitStrength);
ArrayList<String> userIds = new ArrayList<String>();
String name = fullName + " <keybase.io/" + keybaseId + ">";
@@ -171,16 +163,12 @@ public class KeybaseKeyServer extends KeyServer {
@Override
public String get(String id) throws QueryException {
- String key = mKeyCache.get(id);
- if (key == null) {
- try {
- JSONObject user = getUser(id);
- key = JWalk.getString(user, "them", "public_keys", "primary", "bundle");
- } catch (Exception e) {
- throw new QueryException(e.getMessage());
- }
+ try {
+ JSONObject user = getUser(id);
+ return JWalk.getString(user, "them", "public_keys", "primary", "bundle");
+ } catch (Exception e) {
+ throw new QueryException(e.getMessage());
}
- return key;
}
@Override
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/JWalk.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/JWalk.java
index 7ae1d8fab..76797811d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/JWalk.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/JWalk.java
@@ -23,29 +23,77 @@ import org.json.JSONObject;
/**
* Minimal hierarchy selector
+ *
+ * This is for picking out an item in a large multilevel JSON object, for example look at
+ * the Keybase.io User object, documentation at https://keybase.io/__/api-docs/1.0#user-objects
+ * an example available via
+ * curl https://keybase.io/_/api/1.0/user/lookup.json?username=timbray
+ *
+ * If you want to retrieve the ascii-armored key, you'd say
+ * String key = JWalk.getString(match,"them", "public_keys", "primary", "bundle");
*/
public class JWalk {
+ /**
+ * Returns an int member value from the JSON sub-object addressed by the path
+ *
+ * @param json The object
+ * @param path list of string object member selectors
+ * @return the int addressed by the path, assuming such a thing exists
+ * @throws JSONException if any step in the path doesn’t work
+ */
public static int getInt(JSONObject json, String... path) throws JSONException {
json = walk(json, path);
return json.getInt(path[path.length - 1]);
}
+ /**
+ * Returns a long member value from the JSON sub-object addressed by the path
+ *
+ * @param json The object
+ * @param path list of string object member selectors
+ * @return the int addressed by the path, assuming such a thing exists
+ * @throws JSONException if any step in the path doesn’t work
+ */
public static long getLong(JSONObject json, String... path) throws JSONException {
json = walk(json, path);
return json.getLong(path[path.length - 1]);
}
+ /**
+ * Returns a String member value from the JSON sub-object addressed by the path
+ *
+ * @param json The object
+ * @param path list of string object member selectors
+ * @return the int addressed by the path, assuming such a thing exists
+ * @throws JSONException if any step in the path doesn’t work
+ */
public static String getString(JSONObject json, String... path) throws JSONException {
json = walk(json, path);
return json.getString(path[path.length - 1]);
}
+ /**
+ * Returns a JSONArray member value from the JSON sub-object addressed by the path
+ *
+ * @param json The object
+ * @param path list of string object member selectors
+ * @return the int addressed by the path, assuming such a thing exists
+ * @throws JSONException if any step in the path doesn’t work
+ */
public static JSONArray getArray(JSONObject json, String... path) throws JSONException {
json = walk(json, path);
return json.getJSONArray(path[path.length - 1]);
}
+ /**
+ * Returns a JSONObject member value from the JSON sub-object addressed by the path, or null
+ *
+ * @param json The object
+ * @param path list of string object member selectors
+ * @return the int addressed by the path, assuming such a thing exists
+ * @throws JSONException if any step in the path, except for the last, doesn’t work
+ */
public static JSONObject optObject(JSONObject json, String... path) throws JSONException {
json = walk(json, path);
return json.optJSONObject(path[path.length - 1]);