certification of the first linked identity packet!
This commit is contained in:
@@ -13,13 +13,14 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AffirmationResource {
|
||||
|
||||
protected final URI mUri;
|
||||
protected final URI mSubUri;
|
||||
protected final Set<String> mFlags;
|
||||
protected final HashMap<String,String> mParams;
|
||||
|
||||
@@ -29,7 +30,19 @@ public abstract class AffirmationResource {
|
||||
protected AffirmationResource(Set<String> flags, HashMap<String,String> params, URI uri) {
|
||||
mFlags = flags;
|
||||
mParams = params;
|
||||
mUri = uri;
|
||||
mSubUri = uri;
|
||||
}
|
||||
|
||||
public Set<String> getFlags () {
|
||||
return new HashSet<String>(mFlags);
|
||||
}
|
||||
|
||||
public HashMap<String,String> getParams () {
|
||||
return new HashMap<String,String>(mParams);
|
||||
}
|
||||
|
||||
public URI getSubUri () {
|
||||
return mSubUri;
|
||||
}
|
||||
|
||||
public static String generate (Context context, byte[] fingerprint, String nonce) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package org.sufficientlysecure.keychain.pgp.affirmation;
|
||||
|
||||
import org.spongycastle.bcpg.UserAttributeSubpacket;
|
||||
import org.spongycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.spongycastle.util.Strings;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -15,7 +16,7 @@ import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class LinkedIdentity implements Serializable {
|
||||
public class LinkedIdentity {
|
||||
|
||||
protected byte[] mData;
|
||||
public final String mNonce;
|
||||
@@ -41,7 +42,7 @@ public class LinkedIdentity implements Serializable {
|
||||
this(null, nonce, flags, params, subUri);
|
||||
}
|
||||
|
||||
public byte[] encode() {
|
||||
public byte[] getEncoded() {
|
||||
if (mData != null) {
|
||||
return mData;
|
||||
}
|
||||
@@ -79,11 +80,14 @@ public class LinkedIdentity implements Serializable {
|
||||
b.append(mSubUri);
|
||||
|
||||
byte[] nonceBytes = Hex.decode(mNonce);
|
||||
if (nonceBytes.length != 12) {
|
||||
throw new AssertionError("nonce must be 12 bytes");
|
||||
}
|
||||
byte[] data = Strings.toUTF8ByteArray(b.toString());
|
||||
|
||||
byte[] result = new byte[data.length+12];
|
||||
System.arraycopy(nonceBytes, 0, result, 0, 12);
|
||||
System.arraycopy(data, 0, result, 12, result.length);
|
||||
System.arraycopy(data, 0, result, 12, data.length);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -91,7 +95,7 @@ public class LinkedIdentity implements Serializable {
|
||||
/** This method parses an affirmation from a UserAttributeSubpacket, or returns null if the
|
||||
* subpacket can not be parsed as a valid affirmation.
|
||||
*/
|
||||
public static LinkedIdentity parseAffirmation(UserAttributeSubpacket subpacket) {
|
||||
static LinkedIdentity parseAffirmation(UserAttributeSubpacket subpacket) {
|
||||
if (subpacket.getType() != 100) {
|
||||
return null;
|
||||
}
|
||||
@@ -148,6 +152,14 @@ public class LinkedIdentity implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public static LinkedIdentity fromResource (AffirmationResource res, String nonce) {
|
||||
return new LinkedIdentity(nonce, res.getFlags(), res.getParams(), res.getSubUri());
|
||||
}
|
||||
|
||||
public WrappedUserAttribute toUserAttribute () {
|
||||
return WrappedUserAttribute.fromSubpacket(WrappedUserAttribute.UAT_LINKED_ID, getEncoded());
|
||||
}
|
||||
|
||||
public static String generateNonce() {
|
||||
// TODO make this actually random
|
||||
// byte[] data = new byte[96];
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.AffirmationResource;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@@ -38,13 +39,13 @@ public class GenericHttpsResource extends AffirmationResource {
|
||||
@Override
|
||||
protected String fetchResource (OperationLog log, int indent) {
|
||||
|
||||
log.add(LogType.MSG_LV_FETCH, indent, mUri.toString());
|
||||
log.add(LogType.MSG_LV_FETCH, indent, mSubUri.toString());
|
||||
indent += 1;
|
||||
|
||||
try {
|
||||
|
||||
HttpsURLConnection conn = null;
|
||||
URL url = mUri.toURL();
|
||||
URL url = mSubUri.toURL();
|
||||
int status = 0;
|
||||
int redirects = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user