mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-23 06:12:20 -05:00
work on affirmations (begin rename to LinkedIdentity
This commit is contained in:
parent
8408113322
commit
9fe701c866
@ -1,163 +0,0 @@
|
||||
package org.sufficientlysecure.keychain.pgp.affirmation;
|
||||
|
||||
import org.spongycastle.bcpg.UserAttributeSubpacket;
|
||||
import org.spongycastle.util.BigIntegers;
|
||||
import org.spongycastle.util.Strings;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class Affirmation {
|
||||
|
||||
protected byte[] mData;
|
||||
public final String mNonce;
|
||||
public final URI mSubUri;
|
||||
final Set<String> mFlags;
|
||||
final HashMap<String,String> mParams;
|
||||
|
||||
protected Affirmation(byte[] data, String nonce, Set<String> flags,
|
||||
HashMap<String,String> params, URI subUri) {
|
||||
if ( ! nonce.matches("[0-9a-zA-Z]+")) {
|
||||
throw new AssertionError("bug: nonce must be hexstring!");
|
||||
}
|
||||
|
||||
mData = data;
|
||||
mNonce = nonce;
|
||||
mFlags = flags;
|
||||
mParams = params;
|
||||
mSubUri = subUri;
|
||||
}
|
||||
|
||||
Affirmation(String nonce, Set<String> flags,
|
||||
HashMap<String,String> params, URI subUri) {
|
||||
this(null, nonce, flags, params, subUri);
|
||||
}
|
||||
|
||||
public byte[] encode() {
|
||||
if (mData != null) {
|
||||
return mData;
|
||||
}
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("pgpid:");
|
||||
|
||||
// add flags
|
||||
if (mFlags != null) {
|
||||
boolean first = true;
|
||||
for (String flag : mFlags) {
|
||||
if (!first) {
|
||||
b.append(";");
|
||||
}
|
||||
first = false;
|
||||
b.append(flag);
|
||||
}
|
||||
}
|
||||
|
||||
// add parameters
|
||||
if (mParams != null) {
|
||||
boolean first = true;
|
||||
Iterator<Entry<String, String>> it = mParams.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
if (!first) {
|
||||
b.append(";");
|
||||
}
|
||||
first = false;
|
||||
Entry<String, String> entry = it.next();
|
||||
b.append(entry.getKey()).append("=").append(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
b.append("@");
|
||||
b.append(mSubUri);
|
||||
|
||||
byte[] nonceBytes = Hex.decode(mNonce);
|
||||
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);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** This method parses an affirmation from a UserAttributeSubpacket, or returns null if the
|
||||
* subpacket can not be parsed as a valid affirmation.
|
||||
*/
|
||||
public static Affirmation parseAffirmation(UserAttributeSubpacket subpacket) {
|
||||
if (subpacket.getType() != 100) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] data = subpacket.getData();
|
||||
String nonce = Hex.toHexString(data, 0, 12);
|
||||
|
||||
try {
|
||||
return parseUri(nonce, Strings.fromUTF8ByteArray(Arrays.copyOfRange(data, 12, data.length)));
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(Constants.TAG, "error parsing uri in (suspected) affirmation packet");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Affirmation parseUri (String nonce, String uriString) {
|
||||
URI uri = URI.create(uriString);
|
||||
|
||||
if ("pgpid".equals(uri.getScheme())) {
|
||||
Log.e(Constants.TAG, "unknown uri scheme in (suspected) affirmation packet");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!uri.isOpaque()) {
|
||||
Log.e(Constants.TAG, "non-opaque uri in (suspected) affirmation packet");
|
||||
return null;
|
||||
}
|
||||
|
||||
String specific = uri.getSchemeSpecificPart();
|
||||
if (!specific.contains("@")) {
|
||||
Log.e(Constants.TAG, "unknown uri scheme in affirmation packet");
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] pieces = specific.split("@", 2);
|
||||
URI subUri = URI.create(pieces[1]);
|
||||
|
||||
Set<String> flags = new HashSet<String>();
|
||||
HashMap<String,String> params = new HashMap<String,String>();
|
||||
{
|
||||
String[] rawParams = pieces[0].split(";");
|
||||
for (String param : rawParams) {
|
||||
String[] p = param.split("=", 2);
|
||||
if (p.length == 1) {
|
||||
flags.add(param);
|
||||
} else {
|
||||
params.put(p[0], p[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Affirmation(nonce, flags, params, subUri);
|
||||
|
||||
}
|
||||
|
||||
public static String generateNonce() {
|
||||
// TODO make this actually random
|
||||
// byte[] data = new byte[96];
|
||||
// new SecureRandom().nextBytes(data);
|
||||
// return Hex.toHexString(data);
|
||||
|
||||
// debug for now
|
||||
return "0123456789ABCDEF01234567";
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import org.spongycastle.util.encoders.Hex;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -14,7 +15,7 @@ import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class LinkedIdentity {
|
||||
public class LinkedIdentity implements Serializable {
|
||||
|
||||
protected byte[] mData;
|
||||
public final String mNonce;
|
||||
|
@ -6,21 +6,12 @@ import com.textuality.keybase.lib.Search;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.Affirmation;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.AffirmationResource;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.InputData;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
|
@ -21,7 +21,7 @@ package org.sufficientlysecure.keychain.service;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.Affi;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -51,6 +51,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
public ChangeUnlockParcel mNewUnlock;
|
||||
|
||||
public ArrayList<String> mAddUserIds;
|
||||
public ArrayList<LinkedIdentity> mAddLinkedIdentity;
|
||||
public ArrayList<SubkeyAdd> mAddSubKeys;
|
||||
|
||||
public ArrayList<SubkeyChange> mChangeSubKeys;
|
||||
@ -73,6 +74,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
public void reset() {
|
||||
mNewUnlock = null;
|
||||
mAddUserIds = new ArrayList<String>();
|
||||
mAddLinkedIdentity = new ArrayList<LinkedIdentity>();
|
||||
mAddSubKeys = new ArrayList<SubkeyAdd>();
|
||||
mChangePrimaryUserId = null;
|
||||
mChangeSubKeys = new ArrayList<SubkeyChange>();
|
||||
@ -164,6 +166,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
mNewUnlock = source.readParcelable(getClass().getClassLoader());
|
||||
|
||||
mAddUserIds = source.createStringArrayList();
|
||||
mAddLinkedIdentity = (ArrayList<LinkedIdentity>) source.readSerializable();
|
||||
mAddSubKeys = (ArrayList<SubkeyAdd>) source.readSerializable();
|
||||
|
||||
mChangeSubKeys = (ArrayList<SubkeyChange>) source.readSerializable();
|
||||
@ -186,6 +189,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
destination.writeParcelable(mNewUnlock, 0);
|
||||
|
||||
destination.writeStringList(mAddUserIds);
|
||||
destination.writeSerializable(mAddLinkedIdentity);
|
||||
destination.writeSerializable(mAddSubKeys);
|
||||
|
||||
destination.writeSerializable(mChangeSubKeys);
|
||||
@ -216,6 +220,7 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
String out = "mMasterKeyId: " + mMasterKeyId + "\n";
|
||||
out += "mNewUnlock: " + mNewUnlock + "\n";
|
||||
out += "mAddUserIds: " + mAddUserIds + "\n";
|
||||
out += "mAddLinkedIdentity: " + mAddLinkedIdentity + "\n";
|
||||
out += "mAddSubKeys: " + mAddSubKeys + "\n";
|
||||
out += "mChangeSubKeys: " + mChangeSubKeys + "\n";
|
||||
out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n";
|
||||
|
@ -29,7 +29,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.Affirmation;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity;
|
||||
import org.sufficientlysecure.keychain.pgp.affirmation.resources.GenericHttpsResource;
|
||||
|
||||
public class AffirmationCreateHttpsStep1Fragment extends Fragment {
|
||||
@ -72,7 +72,7 @@ public class AffirmationCreateHttpsStep1Fragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
|
||||
String proofNonce = Affirmation.generateNonce();
|
||||
String proofNonce = LinkedIdentity.generateNonce();
|
||||
String proofText = GenericHttpsResource.generateText(getActivity(),
|
||||
mAffirmationWizard.mFingerprint, proofNonce);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user