Skip to content

Commit

Permalink
Merge branch 'keybase-proofs' of https://github.com/open-keychain/Key…
Browse files Browse the repository at this point in the history
…baseLib into keybase-proofs
  • Loading branch information
Dominik Schürmann committed Dec 4, 2014
2 parents 1a252cc + b2a8fe1 commit 2b26d16
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
38 changes: 35 additions & 3 deletions Lib/src/main/java/com/textuality/keybase/lib/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;

public class Match {
private final JSONObject mComponents;
Expand Down Expand Up @@ -86,18 +88,48 @@ public int getBitStrength() throws KeybaseException {
public List<String> getProofLabels() {
ArrayList<String> labels = new ArrayList<String>();
try {
labels.add("twitter.com/" + JWalk.getString(mComponents, "twitter", "val"));
labels.add("Twitter: @" + JWalk.getString(mComponents, "twitter", "val"));
} catch (JSONException e) {
// s'OK
}
try {
labels.add("github.com/" + JWalk.getString(mComponents, "github", "val"));
labels.add("GitHub: " + JWalk.getString(mComponents, "github", "val"));
} catch (JSONException e) {
// s'OK
}
try {
labels.add("Reddit: " + JWalk.getString(mComponents, "reddit", "val"));
} catch (JSONException e) {
// s'OK
}
try {
labels.add("Hacker News: " + JWalk.getString(mComponents, "hackernews", "val"));
} catch (JSONException e) {
// s'OK
}
try {
labels.add("Coinbase: " + JWalk.getString(mComponents, "coinbase", "val"));
} catch (JSONException e) {
// s'OK
}
try {
JSONArray sites = JWalk.getArray(mComponents, "websites");
labels.add(JWalk.getString(sites.getJSONObject(0), "val"));
Hashtable<String, Integer> uniqueNames = new Hashtable<String, Integer>();
int i;
for (i = 0; i < sites.length(); i++) {
uniqueNames.put(JWalk.getString(sites.getJSONObject(i), "val"), 1);
}
Set<String> names = uniqueNames.keySet();
StringBuilder label = new StringBuilder("Web: ");
i = 0;
for (String name : names) {
label.append(name);
if (i < names.size() - 1) {
label.append(", ");
}
i++;
}
labels.add(label.toString());
} catch (JSONException e) {
// s'OK
}
Expand Down
16 changes: 12 additions & 4 deletions Lib/src/main/java/com/textuality/keybase/lib/prover/Prover.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@
* How to use:
* 1. call fetchProofData(), which will exhibit network latency. If it returns false the proof
* verification failed; an explanation can be found in the log.
* 2. fetch the PGP message with getPgpMessage(), check that it’s signed with the right fingerprint
* 2. call checkFingerprint(), passing it the fingerprint of the key you’re checking up on; if
* if it returns false the verification failed.
* 3. fetch the PGP message with getPgpMessage(), check that it’s signed with the right fingerprint
* (see above).
* 3. Call dnsTxtCheckRequired() and if it returns non-null, the return value is a domain name;
* 4. Call dnsTxtCheckRequired() and if it returns non-null, the return value is a domain name;
* retrieve TXT records from that domain and pass them to checkDnsTxt(); if it returns false
* the proof verification failed; an explanation can be found in the log.
* 4. call rawMessageCheckRequired() and if it returns true, feed the raw (de-armored) bytes
* 5. call rawMessageCheckRequired() and if it returns true, feed the raw (de-armored) bytes
* of the message to checkRawMessageBytes(). if it returns false the proof verification failed;
* an explanation can be found in the log. This may exhibit crypto latency.
* 5. Pass the message to validate(), which should have no real latency. If it returns false the
* 6. Pass the message to validate(), which should have no real latency. If it returns false the
* proof verification failed; an explanation can be found in the log.
*/
public abstract class Prover {

String mPgpMessage;
String mPayload;
String mShortenedMessageHash;
String mFingerprintUsedInProof = null;
final Proof mProof;
final List<String> mLog = new ArrayList<String>();

Expand All @@ -94,6 +97,10 @@ public String getPgpMessage() {
return mPgpMessage;
}

public boolean checkFingerprint(String fingerprint) {
return fingerprint.equalsIgnoreCase(mFingerprintUsedInProof);
}

public boolean validate(String decryptedMessage) {
return mPayload.equals(decryptedMessage);
}
Expand All @@ -111,6 +118,7 @@ JSONObject readSig(String sigId) throws JSONException, KeybaseException {
sigJSON = JWalk.getArray(sigJSON, "sigs").getJSONObject(0);
mPayload = JWalk.getString(sigJSON, "payload_json");
mPgpMessage = JWalk.getString(sigJSON, "sig");
mFingerprintUsedInProof = JWalk.getString(sigJSON, "fingerprint");

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

Expand Down

0 comments on commit 2b26d16

Please sign in to comment.