Skip to content

Commit 2b26d16

Browse files
committed
Merge branch 'keybase-proofs' of https://github.com/open-keychain/KeybaseLib into keybase-proofs
2 parents 1a252cc + b2a8fe1 commit 2b26d16

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

Lib/src/main/java/com/textuality/keybase/lib/Match.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.json.JSONObject;
2222

2323
import java.util.ArrayList;
24+
import java.util.Hashtable;
2425
import java.util.List;
26+
import java.util.Set;
2527

2628
public class Match {
2729
private final JSONObject mComponents;
@@ -86,18 +88,48 @@ public int getBitStrength() throws KeybaseException {
8688
public List<String> getProofLabels() {
8789
ArrayList<String> labels = new ArrayList<String>();
8890
try {
89-
labels.add("twitter.com/" + JWalk.getString(mComponents, "twitter", "val"));
91+
labels.add("Twitter: @" + JWalk.getString(mComponents, "twitter", "val"));
9092
} catch (JSONException e) {
9193
// s'OK
9294
}
9395
try {
94-
labels.add("github.com/" + JWalk.getString(mComponents, "github", "val"));
96+
labels.add("GitHub: " + JWalk.getString(mComponents, "github", "val"));
97+
} catch (JSONException e) {
98+
// s'OK
99+
}
100+
try {
101+
labels.add("Reddit: " + JWalk.getString(mComponents, "reddit", "val"));
102+
} catch (JSONException e) {
103+
// s'OK
104+
}
105+
try {
106+
labels.add("Hacker News: " + JWalk.getString(mComponents, "hackernews", "val"));
107+
} catch (JSONException e) {
108+
// s'OK
109+
}
110+
try {
111+
labels.add("Coinbase: " + JWalk.getString(mComponents, "coinbase", "val"));
95112
} catch (JSONException e) {
96113
// s'OK
97114
}
98115
try {
99116
JSONArray sites = JWalk.getArray(mComponents, "websites");
100-
labels.add(JWalk.getString(sites.getJSONObject(0), "val"));
117+
Hashtable<String, Integer> uniqueNames = new Hashtable<String, Integer>();
118+
int i;
119+
for (i = 0; i < sites.length(); i++) {
120+
uniqueNames.put(JWalk.getString(sites.getJSONObject(i), "val"), 1);
121+
}
122+
Set<String> names = uniqueNames.keySet();
123+
StringBuilder label = new StringBuilder("Web: ");
124+
i = 0;
125+
for (String name : names) {
126+
label.append(name);
127+
if (i < names.size() - 1) {
128+
label.append(", ");
129+
}
130+
i++;
131+
}
132+
labels.add(label.toString());
101133
} catch (JSONException e) {
102134
// s'OK
103135
}

Lib/src/main/java/com/textuality/keybase/lib/prover/Prover.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@
5252
* How to use:
5353
* 1. call fetchProofData(), which will exhibit network latency. If it returns false the proof
5454
* verification failed; an explanation can be found in the log.
55-
* 2. fetch the PGP message with getPgpMessage(), check that it’s signed with the right fingerprint
55+
* 2. call checkFingerprint(), passing it the fingerprint of the key you’re checking up on; if
56+
* if it returns false the verification failed.
57+
* 3. fetch the PGP message with getPgpMessage(), check that it’s signed with the right fingerprint
5658
* (see above).
57-
* 3. Call dnsTxtCheckRequired() and if it returns non-null, the return value is a domain name;
59+
* 4. Call dnsTxtCheckRequired() and if it returns non-null, the return value is a domain name;
5860
* retrieve TXT records from that domain and pass them to checkDnsTxt(); if it returns false
5961
* the proof verification failed; an explanation can be found in the log.
60-
* 4. call rawMessageCheckRequired() and if it returns true, feed the raw (de-armored) bytes
62+
* 5. call rawMessageCheckRequired() and if it returns true, feed the raw (de-armored) bytes
6163
* of the message to checkRawMessageBytes(). if it returns false the proof verification failed;
6264
* an explanation can be found in the log. This may exhibit crypto latency.
63-
* 5. Pass the message to validate(), which should have no real latency. If it returns false the
65+
* 6. Pass the message to validate(), which should have no real latency. If it returns false the
6466
* proof verification failed; an explanation can be found in the log.
6567
*/
6668
public abstract class Prover {
6769

6870
String mPgpMessage;
6971
String mPayload;
7072
String mShortenedMessageHash;
73+
String mFingerprintUsedInProof = null;
7174
final Proof mProof;
7275
final List<String> mLog = new ArrayList<String>();
7376

@@ -94,6 +97,10 @@ public String getPgpMessage() {
9497
return mPgpMessage;
9598
}
9699

100+
public boolean checkFingerprint(String fingerprint) {
101+
return fingerprint.equalsIgnoreCase(mFingerprintUsedInProof);
102+
}
103+
97104
public boolean validate(String decryptedMessage) {
98105
return mPayload.equals(decryptedMessage);
99106
}
@@ -111,6 +118,7 @@ JSONObject readSig(String sigId) throws JSONException, KeybaseException {
111118
sigJSON = JWalk.getArray(sigJSON, "sigs").getJSONObject(0);
112119
mPayload = JWalk.getString(sigJSON, "payload_json");
113120
mPgpMessage = JWalk.getString(sigJSON, "sig");
121+
mFingerprintUsedInProof = JWalk.getString(sigJSON, "fingerprint");
114122

115123
mLog.add("Extracted payload & message from sig");
116124

0 commit comments

Comments
 (0)