ImportKeys: Refactoring
- Avoid instanceof and duplicated code
This commit is contained in:
@@ -354,6 +354,7 @@ public class HkpKeyserver extends Keyserver {
|
|||||||
}
|
}
|
||||||
entry.setUserIds(userIds);
|
entry.setUserIds(userIds);
|
||||||
entry.setPrimaryUserId(userIds.get(0));
|
entry.setPrimaryUserId(userIds.get(0));
|
||||||
|
entry.setKeyserver(getUrlPrefix() + mHost + ":" + mPort);
|
||||||
|
|
||||||
results.add(entry);
|
results.add(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ public class ImportKeysList extends ArrayList<ImportKeysListEntry> {
|
|||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (incoming.getKeyserver() != null) {
|
||||||
|
existing.setKeyserver(incoming.getKeyserver());
|
||||||
|
}
|
||||||
|
|
||||||
// keep track if this key result is from a HKP keyserver
|
// keep track if this key result is from a HKP keyserver
|
||||||
boolean incomingFromHkpServer = true;
|
boolean incomingFromHkpServer = true;
|
||||||
// we’re going to want to try to fetch the key from everywhere we found it, so remember
|
// we’re going to want to try to fetch the key from everywhere we found it, so remember
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
|||||||
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
|
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -40,7 +41,8 @@ import java.util.Map;
|
|||||||
public class ImportKeysListEntry implements Serializable, Parcelable {
|
public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
private static final long serialVersionUID = -7797972103284992662L;
|
private static final long serialVersionUID = -7797972103284992662L;
|
||||||
|
|
||||||
private byte[] mEncodedRing;
|
private ParcelableKeyRing mParcelableKeyRing;
|
||||||
|
|
||||||
private ArrayList<String> mUserIds;
|
private ArrayList<String> mUserIds;
|
||||||
private HashMap<String, HashSet<String>> mMergedUserIds;
|
private HashMap<String, HashSet<String>> mMergedUserIds;
|
||||||
private ArrayList<Map.Entry<String, HashSet<String>>> mSortedUserIds;
|
private ArrayList<Map.Entry<String, HashSet<String>>> mSortedUserIds;
|
||||||
@@ -55,73 +57,19 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
private String mAlgorithm;
|
private String mAlgorithm;
|
||||||
private boolean mSecretKey;
|
private boolean mSecretKey;
|
||||||
private UserId mPrimaryUserId;
|
private UserId mPrimaryUserId;
|
||||||
|
private String mKeyserver;
|
||||||
private String mKeybaseName;
|
private String mKeybaseName;
|
||||||
private String mFbUsername;
|
private String mFbUsername;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
private ArrayList<String> mOrigins;
|
private ArrayList<String> mOrigins;
|
||||||
private Integer mHashCode = null;
|
private Integer mHashCode = null;
|
||||||
|
|
||||||
public int describeContents() {
|
public ParcelableKeyRing getParcelableKeyRing() {
|
||||||
return 0;
|
return mParcelableKeyRing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setParcelableKeyRing(ParcelableKeyRing parcelableKeyRing) {
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
this.mParcelableKeyRing = parcelableKeyRing;
|
||||||
dest.writeSerializable(mPrimaryUserId);
|
|
||||||
dest.writeStringList(mUserIds);
|
|
||||||
dest.writeSerializable(mMergedUserIds);
|
|
||||||
dest.writeByte((byte) (mRevoked ? 1 : 0));
|
|
||||||
dest.writeByte((byte) (mExpired ? 1 : 0));
|
|
||||||
dest.writeInt(mDate == null ? 0 : 1);
|
|
||||||
if (mDate != null) {
|
|
||||||
dest.writeLong(mDate.getTime());
|
|
||||||
}
|
|
||||||
dest.writeString(mFingerprintHex);
|
|
||||||
dest.writeString(mKeyIdHex);
|
|
||||||
dest.writeInt(mBitStrength == null ? 0 : 1);
|
|
||||||
if (mBitStrength != null) {
|
|
||||||
dest.writeInt(mBitStrength);
|
|
||||||
}
|
|
||||||
dest.writeString(mAlgorithm);
|
|
||||||
dest.writeByte((byte) (mSecretKey ? 1 : 0));
|
|
||||||
dest.writeString(mKeybaseName);
|
|
||||||
dest.writeString(mFbUsername);
|
|
||||||
dest.writeStringList(mOrigins);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
|
||||||
public ImportKeysListEntry createFromParcel(final Parcel source) {
|
|
||||||
ImportKeysListEntry vr = new ImportKeysListEntry();
|
|
||||||
vr.mPrimaryUserId = (UserId) source.readSerializable();
|
|
||||||
vr.mUserIds = new ArrayList<>();
|
|
||||||
source.readStringList(vr.mUserIds);
|
|
||||||
vr.mMergedUserIds = (HashMap<String, HashSet<String>>) source.readSerializable();
|
|
||||||
vr.mRevoked = source.readByte() == 1;
|
|
||||||
vr.mExpired = source.readByte() == 1;
|
|
||||||
vr.mDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
|
||||||
vr.mFingerprintHex = source.readString();
|
|
||||||
vr.mKeyIdHex = source.readString();
|
|
||||||
vr.mBitStrength = source.readInt() != 0 ? source.readInt() : null;
|
|
||||||
vr.mAlgorithm = source.readString();
|
|
||||||
vr.mSecretKey = source.readByte() == 1;
|
|
||||||
vr.mKeybaseName = source.readString();
|
|
||||||
vr.mFbUsername = source.readString();
|
|
||||||
vr.mOrigins = new ArrayList<>();
|
|
||||||
source.readStringList(vr.mOrigins);
|
|
||||||
|
|
||||||
return vr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImportKeysListEntry[] newArray(final int size) {
|
|
||||||
return new ImportKeysListEntry[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
if (mHashCode != null) {
|
|
||||||
return mHashCode;
|
|
||||||
}
|
|
||||||
return super.hashCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSameKeyAs(ImportKeysListEntry other) {
|
public boolean hasSameKeyAs(ImportKeysListEntry other) {
|
||||||
@@ -163,10 +111,6 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
return mRevoked || mExpired;
|
return mRevoked || mExpired;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getEncodedRing() {
|
|
||||||
return mEncodedRing;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDate() {
|
public Date getDate() {
|
||||||
return mDate;
|
return mDate;
|
||||||
}
|
}
|
||||||
@@ -227,18 +171,26 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
mPrimaryUserId = primaryUserId;
|
mPrimaryUserId = primaryUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKeyserver() {
|
||||||
|
return mKeyserver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyserver(String keyserver) {
|
||||||
|
mKeyserver = keyserver;
|
||||||
|
}
|
||||||
|
|
||||||
public String getKeybaseName() {
|
public String getKeybaseName() {
|
||||||
return mKeybaseName;
|
return mKeybaseName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFbUsername() {
|
|
||||||
return mFbUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeybaseName(String keybaseName) {
|
public void setKeybaseName(String keybaseName) {
|
||||||
mKeybaseName = keybaseName;
|
mKeybaseName = keybaseName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFbUsername() {
|
||||||
|
return mFbUsername;
|
||||||
|
}
|
||||||
|
|
||||||
public void setFbUsername(String fbUsername) {
|
public void setFbUsername(String fbUsername) {
|
||||||
mFbUsername = fbUsername;
|
mFbUsername = fbUsername;
|
||||||
}
|
}
|
||||||
@@ -259,6 +211,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
mOrigins.add(origin);
|
mOrigins.add(origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return mHashCode != null ? mHashCode : super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getUserIds() {
|
public List<String> getUserIds() {
|
||||||
// To ensure choerency, use methods of this class to edit the list
|
// To ensure choerency, use methods of this class to edit the list
|
||||||
return Collections.unmodifiableList(mUserIds);
|
return Collections.unmodifiableList(mUserIds);
|
||||||
@@ -314,14 +270,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Constructor based on key object, used for import from NFC, QR Codes, files
|
* Constructor based on key object, used for import from NFC, QR Codes, files
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public ImportKeysListEntry(Context ctx, UncachedKeyRing ring) {
|
||||||
public ImportKeysListEntry(Context context, UncachedKeyRing ring, byte[] encodedRing) {
|
|
||||||
mEncodedRing = encodedRing;
|
|
||||||
mSecretKey = ring.isSecret();
|
mSecretKey = ring.isSecret();
|
||||||
|
|
||||||
UncachedPublicKey key = ring.getPublicKey();
|
UncachedPublicKey key = ring.getPublicKey();
|
||||||
|
|
||||||
mHashCode = key.hashCode();
|
|
||||||
|
|
||||||
setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
||||||
setKeyId(key.getKeyId());
|
setKeyId(key.getKeyId());
|
||||||
setFingerprint(key.getFingerprint());
|
setFingerprint(key.getFingerprint());
|
||||||
@@ -332,10 +284,17 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
|
|
||||||
mBitStrength = key.getBitStrength();
|
mBitStrength = key.getBitStrength();
|
||||||
mCurveOid = key.getCurveOid();
|
mCurveOid = key.getCurveOid();
|
||||||
final int algorithm = key.getAlgorithm();
|
int algorithm = key.getAlgorithm();
|
||||||
mAlgorithm = KeyFormattingUtils.getAlgorithmInfo(context, algorithm, mBitStrength, mCurveOid);
|
mAlgorithm = KeyFormattingUtils.getAlgorithmInfo(ctx, algorithm, mBitStrength, mCurveOid);
|
||||||
|
mHashCode = key.hashCode();
|
||||||
|
|
||||||
setUserIds(key.getUnorderedUserIds());
|
setUserIds(key.getUnorderedUserIds());
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] encoded = ring.getEncoded();
|
||||||
|
mParcelableKeyRing = new ParcelableKeyRing(encoded);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMergedUserIds() {
|
private void updateMergedUserIds() {
|
||||||
@@ -386,4 +345,62 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeParcelable(mParcelableKeyRing, flags);
|
||||||
|
dest.writeSerializable(mPrimaryUserId);
|
||||||
|
dest.writeStringList(mUserIds);
|
||||||
|
dest.writeSerializable(mMergedUserIds);
|
||||||
|
dest.writeByte((byte) (mRevoked ? 1 : 0));
|
||||||
|
dest.writeByte((byte) (mExpired ? 1 : 0));
|
||||||
|
dest.writeInt(mDate == null ? 0 : 1);
|
||||||
|
if (mDate != null) {
|
||||||
|
dest.writeLong(mDate.getTime());
|
||||||
|
}
|
||||||
|
dest.writeString(mFingerprintHex);
|
||||||
|
dest.writeString(mKeyIdHex);
|
||||||
|
dest.writeInt(mBitStrength == null ? 0 : 1);
|
||||||
|
if (mBitStrength != null) {
|
||||||
|
dest.writeInt(mBitStrength);
|
||||||
|
}
|
||||||
|
dest.writeString(mAlgorithm);
|
||||||
|
dest.writeByte((byte) (mSecretKey ? 1 : 0));
|
||||||
|
dest.writeString(mKeybaseName);
|
||||||
|
dest.writeString(mFbUsername);
|
||||||
|
dest.writeStringList(mOrigins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
||||||
|
public ImportKeysListEntry createFromParcel(final Parcel source) {
|
||||||
|
ImportKeysListEntry vr = new ImportKeysListEntry();
|
||||||
|
vr.mParcelableKeyRing = source.readParcelable(ParcelableKeyRing.class.getClassLoader());
|
||||||
|
vr.mPrimaryUserId = (UserId) source.readSerializable();
|
||||||
|
vr.mUserIds = new ArrayList<>();
|
||||||
|
source.readStringList(vr.mUserIds);
|
||||||
|
vr.mMergedUserIds = (HashMap<String, HashSet<String>>) source.readSerializable();
|
||||||
|
vr.mRevoked = source.readByte() == 1;
|
||||||
|
vr.mExpired = source.readByte() == 1;
|
||||||
|
vr.mDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
||||||
|
vr.mFingerprintHex = source.readString();
|
||||||
|
vr.mKeyIdHex = source.readString();
|
||||||
|
vr.mBitStrength = source.readInt() != 0 ? source.readInt() : null;
|
||||||
|
vr.mAlgorithm = source.readString();
|
||||||
|
vr.mSecretKey = source.readByte() == 1;
|
||||||
|
vr.mKeybaseName = source.readString();
|
||||||
|
vr.mFbUsername = source.readString();
|
||||||
|
vr.mOrigins = new ArrayList<>();
|
||||||
|
source.readStringList(vr.mOrigins);
|
||||||
|
|
||||||
|
return vr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportKeysListEntry[] newArray(final int size) {
|
||||||
|
return new ImportKeysListEntry[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ package org.sufficientlysecure.keychain.keyimport;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
/** This class is a parcelable representation of either a keyring as raw data,
|
/**
|
||||||
|
* This class is a parcelable representation of either a keyring as raw data,
|
||||||
* or a (unique) reference to one as a fingerprint, keyid, or keybase name.
|
* or a (unique) reference to one as a fingerprint, keyid, or keybase name.
|
||||||
*/
|
*/
|
||||||
public class ParcelableKeyRing implements Parcelable {
|
public class ParcelableKeyRing implements Parcelable {
|
||||||
@@ -35,36 +36,23 @@ public class ParcelableKeyRing implements Parcelable {
|
|||||||
public final String mFbUsername;
|
public final String mFbUsername;
|
||||||
|
|
||||||
public ParcelableKeyRing(byte[] bytes) {
|
public ParcelableKeyRing(byte[] bytes) {
|
||||||
this(null, bytes, false);
|
this(bytes, null, null, null, null);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param disAmbiguator useless parameter intended to distinguish this overloaded constructor
|
|
||||||
* for when null is passed as first two arguments
|
|
||||||
*/
|
|
||||||
public ParcelableKeyRing(String expectedFingerprint, byte[] bytes, boolean disAmbiguator) {
|
|
||||||
mBytes = bytes;
|
|
||||||
mExpectedFingerprint = expectedFingerprint;
|
|
||||||
mKeyIdHex = null;
|
|
||||||
mKeybaseName = null;
|
|
||||||
mFbUsername = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParcelableKeyRing(String expectedFingerprint, String keyIdHex) {
|
|
||||||
mBytes = null;
|
|
||||||
mExpectedFingerprint = expectedFingerprint;
|
|
||||||
mKeyIdHex = keyIdHex;
|
|
||||||
mKeybaseName = null;
|
|
||||||
mFbUsername = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParcelableKeyRing(String expectedFingerprint, String keyIdHex, String keybaseName,
|
public ParcelableKeyRing(String expectedFingerprint, String keyIdHex, String keybaseName,
|
||||||
String fbUsername) {
|
String fbUsername) {
|
||||||
mBytes = null;
|
|
||||||
mExpectedFingerprint = expectedFingerprint;
|
this(null, expectedFingerprint, keyIdHex, keybaseName, fbUsername);
|
||||||
mKeyIdHex = keyIdHex;
|
}
|
||||||
mKeybaseName = keybaseName;
|
|
||||||
mFbUsername = fbUsername;
|
public ParcelableKeyRing(byte[] bytes, String expectedFingerprint, String keyIdHex,
|
||||||
|
String keybaseName, String fbUsername) {
|
||||||
|
|
||||||
|
this.mBytes = bytes;
|
||||||
|
this.mExpectedFingerprint = expectedFingerprint;
|
||||||
|
this.mKeyIdHex = keyIdHex;
|
||||||
|
this.mKeybaseName = keybaseName;
|
||||||
|
this.mFbUsername = fbUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParcelableKeyRing(Parcel source) {
|
private ParcelableKeyRing(Parcel source) {
|
||||||
@@ -78,6 +66,7 @@ public class ParcelableKeyRing implements Parcelable {
|
|||||||
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeByteArray(mBytes);
|
dest.writeByteArray(mBytes);
|
||||||
|
|
||||||
dest.writeString(mExpectedFingerprint);
|
dest.writeString(mExpectedFingerprint);
|
||||||
dest.writeString(mKeyIdHex);
|
dest.writeString(mKeyIdHex);
|
||||||
dest.writeString(mKeybaseName);
|
dest.writeString(mKeybaseName);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.keyimport.CloudSearch;
|
import org.sufficientlysecure.keychain.keyimport.CloudSearch;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||||
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
||||||
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
import org.sufficientlysecure.keychain.operations.results.GetKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.GetKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
@@ -38,11 +39,11 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class ImportKeysListCloudLoader
|
public class ImportKeysListCloudLoader
|
||||||
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
|
||||||
Context mContext;
|
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
Preferences.CloudSearchPrefs mCloudPrefs;
|
private String mServerQuery;
|
||||||
String mServerQuery;
|
private Preferences.CloudSearchPrefs mCloudPrefs;
|
||||||
private ParcelableProxy mParcelableProxy;
|
private ParcelableProxy mParcelableProxy;
|
||||||
|
|
||||||
private ArrayList<ImportKeysListEntry> mEntryList = new ArrayList<>();
|
private ArrayList<ImportKeysListEntry> mEntryList = new ArrayList<>();
|
||||||
@@ -57,8 +58,10 @@ public class ImportKeysListCloudLoader
|
|||||||
* and whether to search keybase.io
|
* and whether to search keybase.io
|
||||||
* @param parcelableProxy explicit proxy to use. If null, will retrieve from preferences
|
* @param parcelableProxy explicit proxy to use. If null, will retrieve from preferences
|
||||||
*/
|
*/
|
||||||
public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs,
|
public ImportKeysListCloudLoader(Context context, String serverQuery,
|
||||||
|
Preferences.CloudSearchPrefs cloudPrefs,
|
||||||
@Nullable ParcelableProxy parcelableProxy) {
|
@Nullable ParcelableProxy parcelableProxy) {
|
||||||
|
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mServerQuery = serverQuery;
|
mServerQuery = serverQuery;
|
||||||
@@ -82,6 +85,12 @@ public class ImportKeysListCloudLoader
|
|||||||
queryServer(false);
|
queryServer(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now we have all the data needed to build the parcelable key ring for this key
|
||||||
|
for (ImportKeysListEntry e : mEntryList) {
|
||||||
|
e.setParcelableKeyRing(new ParcelableKeyRing(e.getFingerprintHex(), e.getKeyIdHex(),
|
||||||
|
e.getKeybaseName(), e.getFbUsername()));
|
||||||
|
}
|
||||||
|
|
||||||
return mEntryListWrapper;
|
return mEntryListWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class ImportKeysListLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputData inputData = getInputData(getContext(), mLoaderState);
|
InputData inputData = getInputData(mLoaderState);
|
||||||
generateListOfKeyrings(inputData);
|
generateListOfKeyrings(inputData);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
@@ -133,10 +133,11 @@ public class ImportKeysListLoader
|
|||||||
IteratorWithIOThrow<UncachedKeyRing> it = UncachedKeyRing.fromStream(bufferedInput);
|
IteratorWithIOThrow<UncachedKeyRing> it = UncachedKeyRing.fromStream(bufferedInput);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
UncachedKeyRing ring = it.next();
|
UncachedKeyRing ring = it.next();
|
||||||
byte[] encodedRing = ring.getEncoded();
|
|
||||||
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), ring, encodedRing);
|
ImportKeysListEntry item = new ImportKeysListEntry(mContext, ring);
|
||||||
mData.add(item);
|
mData.add(item);
|
||||||
mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(encodedRing));
|
|
||||||
|
mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(ring.getEncoded()));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "IOException on parsing key file! Return NoValidKeysException!", e);
|
Log.e(Constants.TAG, "IOException on parsing key file! Return NoValidKeysException!", e);
|
||||||
@@ -149,13 +150,15 @@ public class ImportKeysListLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static InputData getInputData(Context context, BytesLoaderState loaderState) throws FileNotFoundException {
|
private InputData getInputData(BytesLoaderState ls)
|
||||||
|
throws FileNotFoundException {
|
||||||
|
|
||||||
InputData inputData;
|
InputData inputData;
|
||||||
if (loaderState.mKeyBytes != null) {
|
if (ls.mKeyBytes != null) {
|
||||||
inputData = new InputData(new ByteArrayInputStream(loaderState.mKeyBytes), loaderState.mKeyBytes.length);
|
inputData = new InputData(new ByteArrayInputStream(ls.mKeyBytes), ls.mKeyBytes.length);
|
||||||
} else if (loaderState.mDataUri != null) {
|
} else if (ls.mDataUri != null) {
|
||||||
InputStream inputStream = context.getContentResolver().openInputStream(loaderState.mDataUri);
|
InputStream inputStream = mContext.getContentResolver().openInputStream(ls.mDataUri);
|
||||||
long length = FileHelper.getFileSize(context, loaderState.mDataUri, -1);
|
long length = FileHelper.getFileSize(mContext, ls.mDataUri, -1);
|
||||||
|
|
||||||
inputData = new InputData(inputStream, length);
|
inputData = new InputData(inputStream, length);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ImportKeyringParcel implements Parcelable {
|
public class ImportKeyringParcel implements Parcelable {
|
||||||
// if null, keys are expected to be read from a cache file in ImportExportOperations
|
// If null, keys are expected to be read from a cache file in ImportExportOperations
|
||||||
public ArrayList<ParcelableKeyRing> mKeyList;
|
public ArrayList<ParcelableKeyRing> mKeyList;
|
||||||
public String mKeyserver; // must be set if keys are to be imported from a keyserver
|
public String mKeyserver;
|
||||||
public boolean mSkipSave = false; // don't save the key, only return it as part of result
|
// If false, don't save the key, only return it as part of result
|
||||||
|
public boolean mSkipSave = false;
|
||||||
|
|
||||||
public ImportKeyringParcel(ArrayList<ParcelableKeyRing> keyList, String keyserver) {
|
public ImportKeyringParcel(ArrayList<ParcelableKeyRing> keyList, String keyserver) {
|
||||||
mKeyList = keyList;
|
mKeyList = keyList;
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
String hexKeyId = KeyFormattingUtils
|
String hexKeyId = KeyFormattingUtils
|
||||||
.convertKeyIdToHex(keyId);
|
.convertKeyIdToHex(keyId);
|
||||||
// we aren't updating from keybase as of now
|
// we aren't updating from keybase as of now
|
||||||
keyList.add(new ParcelableKeyRing(fingerprint, hexKeyId));
|
keyList.add(new ParcelableKeyRing(fingerprint, hexKeyId, null, null));
|
||||||
}
|
}
|
||||||
keyCursor.close();
|
keyCursor.close();
|
||||||
|
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ public class CreateSecurityTokenImportResetFragment
|
|||||||
public void importKey() {
|
public void importKey() {
|
||||||
|
|
||||||
ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
|
||||||
keyList.add(new ParcelableKeyRing(mTokenFingerprint, null));
|
keyList.add(new ParcelableKeyRing(mTokenFingerprint, null, null, null));
|
||||||
mKeyList = keyList;
|
mKeyList = keyList;
|
||||||
|
|
||||||
mKeyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver();
|
mKeyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver();
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
|
|||||||
|
|
||||||
{
|
{
|
||||||
ParcelableKeyRing keyEntry = new ParcelableKeyRing(null,
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(null,
|
||||||
KeyFormattingUtils.convertKeyIdToHex(unknownKeyId));
|
KeyFormattingUtils.convertKeyIdToHex(unknownKeyId), null, null);
|
||||||
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
||||||
selectedEntries.add(keyEntry);
|
selectedEntries.add(keyEntry);
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ import android.widget.Toast;
|
|||||||
import android.widget.ViewAnimator;
|
import android.widget.ViewAnimator;
|
||||||
|
|
||||||
import com.cocosw.bottomsheet.BottomSheet;
|
import com.cocosw.bottomsheet.BottomSheet;
|
||||||
|
|
||||||
import org.openintents.openpgp.OpenPgpMetadata;
|
import org.openintents.openpgp.OpenPgpMetadata;
|
||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
import org.sufficientlysecure.keychain.BuildConfig;
|
import org.sufficientlysecure.keychain.BuildConfig;
|
||||||
@@ -97,24 +98,24 @@ import org.sufficientlysecure.keychain.util.ParcelableHashMap;
|
|||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
|
|
||||||
/** Displays a list of decrypted inputs.
|
/**
|
||||||
*
|
* Displays a list of decrypted inputs.
|
||||||
|
* <p/>
|
||||||
* This class has a complex control flow to manage its input URIs. Each URI
|
* This class has a complex control flow to manage its input URIs. Each URI
|
||||||
* which is in mInputUris is also in exactly one of mPendingInputUris,
|
* which is in mInputUris is also in exactly one of mPendingInputUris,
|
||||||
* mCancelledInputUris, mCurrentInputUri, or a key in mInputDataResults.
|
* mCancelledInputUris, mCurrentInputUri, or a key in mInputDataResults.
|
||||||
*
|
* <p/>
|
||||||
* Processing of URIs happens using a looping approach:
|
* Processing of URIs happens using a looping approach:
|
||||||
* - There is always exactly one method running which works on mCurrentInputUri
|
* - There is always exactly one method running which works on mCurrentInputUri
|
||||||
* - Processing starts in cryptoOperation(), which pops a new mCurrentInputUri
|
* - Processing starts in cryptoOperation(), which pops a new mCurrentInputUri
|
||||||
* from the list of mPendingInputUris.
|
* from the list of mPendingInputUris.
|
||||||
* - Once a mCurrentInputUri is finished processing, it should be set to null and
|
* - Once a mCurrentInputUri is finished processing, it should be set to null and
|
||||||
* control handed back to cryptoOperation()
|
* control handed back to cryptoOperation()
|
||||||
* - Control flow can move through asynchronous calls, and resume in callbacks
|
* - Control flow can move through asynchronous calls, and resume in callbacks
|
||||||
* like onActivityResult() or onPermissionRequestResult().
|
* like onActivityResult() or onPermissionRequestResult().
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class DecryptListFragment
|
public class DecryptListFragment
|
||||||
extends QueueingCryptoOperationFragment<InputDataParcel,InputDataResult>
|
extends QueueingCryptoOperationFragment<InputDataParcel, InputDataResult>
|
||||||
implements OnMenuItemClickListener {
|
implements OnMenuItemClickListener {
|
||||||
|
|
||||||
public static final String ARG_INPUT_URIS = "input_uris";
|
public static final String ARG_INPUT_URIS = "input_uris";
|
||||||
@@ -188,7 +189,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
outState.putParcelableArrayList(ARG_INPUT_URIS, mInputUris);
|
outState.putParcelableArrayList(ARG_INPUT_URIS, mInputUris);
|
||||||
|
|
||||||
HashMap<Uri,InputDataResult> results = new HashMap<>(mInputUris.size());
|
HashMap<Uri, InputDataResult> results = new HashMap<>(mInputUris.size());
|
||||||
for (Uri uri : mInputUris) {
|
for (Uri uri : mInputUris) {
|
||||||
if (mPendingInputUris.contains(uri)) {
|
if (mPendingInputUris.contains(uri)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -218,7 +219,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
ArrayList<Uri> inputUris = getArguments().getParcelableArrayList(ARG_INPUT_URIS);
|
ArrayList<Uri> inputUris = getArguments().getParcelableArrayList(ARG_INPUT_URIS);
|
||||||
ArrayList<Uri> cancelledUris = args.getParcelableArrayList(ARG_CANCELLED_URIS);
|
ArrayList<Uri> cancelledUris = args.getParcelableArrayList(ARG_CANCELLED_URIS);
|
||||||
ParcelableHashMap<Uri,InputDataResult> results = args.getParcelable(ARG_RESULTS);
|
ParcelableHashMap<Uri, InputDataResult> results = args.getParcelable(ARG_RESULTS);
|
||||||
|
|
||||||
mCanDelete = args.getBoolean(ARG_CAN_DELETE, false);
|
mCanDelete = args.getBoolean(ARG_CAN_DELETE, false);
|
||||||
|
|
||||||
@@ -230,11 +231,11 @@ public class DecryptListFragment
|
|||||||
private void displayInputUris(
|
private void displayInputUris(
|
||||||
ArrayList<Uri> inputUris,
|
ArrayList<Uri> inputUris,
|
||||||
ArrayList<Uri> cancelledUris,
|
ArrayList<Uri> cancelledUris,
|
||||||
HashMap<Uri,InputDataResult> results) {
|
HashMap<Uri, InputDataResult> results) {
|
||||||
|
|
||||||
mInputUris = inputUris;
|
mInputUris = inputUris;
|
||||||
mCurrentInputUri = null;
|
mCurrentInputUri = null;
|
||||||
mInputDataResults = results != null ? results : new HashMap<Uri,InputDataResult>(inputUris.size());
|
mInputDataResults = results != null ? results : new HashMap<Uri, InputDataResult>(inputUris.size());
|
||||||
mCancelledInputUris = cancelledUris != null ? cancelledUris : new ArrayList<Uri>();
|
mCancelledInputUris = cancelledUris != null ? cancelledUris : new ArrayList<Uri>();
|
||||||
|
|
||||||
mPendingInputUris = new ArrayList<>();
|
mPendingInputUris = new ArrayList<>();
|
||||||
@@ -294,7 +295,7 @@ public class DecryptListFragment
|
|||||||
String filename = metadata.getFilename();
|
String filename = metadata.getFilename();
|
||||||
if (TextUtils.isEmpty(filename)) {
|
if (TextUtils.isEmpty(filename)) {
|
||||||
String ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(metadata.getMimeType());
|
String ext = MimeTypeMap.getSingleton().getExtensionFromMimeType(metadata.getMimeType());
|
||||||
filename = "decrypted" + (ext != null ? "."+ext : "");
|
filename = "decrypted" + (ext != null ? "." + ext : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// requires >=kitkat
|
// requires >=kitkat
|
||||||
@@ -394,7 +395,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<Uri,Drawable> mIconCache = new HashMap<>();
|
HashMap<Uri, Drawable> mIconCache = new HashMap<>();
|
||||||
|
|
||||||
private void processResult(final Uri uri) {
|
private void processResult(final Uri uri) {
|
||||||
|
|
||||||
@@ -561,7 +562,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
|
||||||
new Parcelable[] { internalIntent });
|
new Parcelable[]{internalIntent});
|
||||||
|
|
||||||
startActivity(chooserIntent);
|
startActivity(chooserIntent);
|
||||||
|
|
||||||
@@ -605,7 +606,7 @@ public class DecryptListFragment
|
|||||||
.putExtra(DisplayTextActivity.EXTRA_METADATA, metadata),
|
.putExtra(DisplayTextActivity.EXTRA_METADATA, metadata),
|
||||||
BuildConfig.APPLICATION_ID, R.string.view_internal, R.mipmap.ic_launcher);
|
BuildConfig.APPLICATION_ID, R.string.view_internal, R.mipmap.ic_launcher);
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
|
||||||
new Parcelable[] { internalIntent });
|
new Parcelable[]{internalIntent});
|
||||||
}
|
}
|
||||||
|
|
||||||
startActivity(chooserIntent);
|
startActivity(chooserIntent);
|
||||||
@@ -632,7 +633,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
Log.d(Constants.TAG, "mCurrentInputUri=" + mCurrentInputUri);
|
Log.d(Constants.TAG, "mCurrentInputUri=" + mCurrentInputUri);
|
||||||
|
|
||||||
if ( ! checkAndRequestReadPermission(activity, mCurrentInputUri)) {
|
if (!checkAndRequestReadPermission(activity, mCurrentInputUri)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -644,15 +645,15 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Request READ_EXTERNAL_STORAGE permission on Android >= 6.0 to read content from "file" Uris.
|
* Request READ_EXTERNAL_STORAGE permission on Android >= 6.0 to read content from "file" Uris.
|
||||||
*
|
* <p/>
|
||||||
* This method returns true on Android < 6, or if permission is already granted. It
|
* This method returns true on Android < 6, or if permission is already granted. It
|
||||||
* requests the permission and returns false otherwise, taking over responsibility
|
* requests the permission and returns false otherwise, taking over responsibility
|
||||||
* for mCurrentInputUri.
|
* for mCurrentInputUri.
|
||||||
*
|
* <p/>
|
||||||
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
* see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html
|
||||||
*/
|
*/
|
||||||
private boolean checkAndRequestReadPermission(Activity activity, final Uri uri) {
|
private boolean checkAndRequestReadPermission(Activity activity, final Uri uri) {
|
||||||
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,7 +668,7 @@ public class DecryptListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestPermissions(
|
requestPermissions(
|
||||||
new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||||
REQUEST_PERMISSION_READ_EXTERNAL_STORAGE);
|
REQUEST_PERMISSION_READ_EXTERNAL_STORAGE);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -676,8 +677,8 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode,
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
@NonNull String[] permissions,
|
@NonNull String[] permissions,
|
||||||
@NonNull int[] grantResults) {
|
@NonNull int[] grantResults) {
|
||||||
|
|
||||||
if (requestCode != REQUEST_PERMISSION_READ_EXTERNAL_STORAGE) {
|
if (requestCode != REQUEST_PERMISSION_READ_EXTERNAL_STORAGE) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
@@ -693,7 +694,7 @@ public class DecryptListFragment
|
|||||||
Iterator<Uri> it = mCancelledInputUris.iterator();
|
Iterator<Uri> it = mCancelledInputUris.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Uri uri = it.next();
|
Uri uri = it.next();
|
||||||
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
@@ -711,7 +712,7 @@ public class DecryptListFragment
|
|||||||
Iterator<Uri> it = mPendingInputUris.iterator();
|
Iterator<Uri> it = mPendingInputUris.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Uri uri = it.next();
|
Uri uri = it.next();
|
||||||
if ( ! ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
@@ -766,7 +767,7 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
{
|
{
|
||||||
ParcelableKeyRing keyEntry = new ParcelableKeyRing(null,
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(null,
|
||||||
KeyFormattingUtils.convertKeyIdToHex(unknownKeyId));
|
KeyFormattingUtils.convertKeyIdToHex(unknownKeyId), null, null);
|
||||||
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
||||||
selectedEntries.add(keyEntry);
|
selectedEntries.add(keyEntry);
|
||||||
|
|
||||||
@@ -974,7 +975,7 @@ public class DecryptListFragment
|
|||||||
String filename;
|
String filename;
|
||||||
if (metadata == null) {
|
if (metadata == null) {
|
||||||
filename = getString(R.string.filename_unknown);
|
filename = getString(R.string.filename_unknown);
|
||||||
} else if ( ! TextUtils.isEmpty(metadata.getFilename())) {
|
} else if (!TextUtils.isEmpty(metadata.getFilename())) {
|
||||||
filename = metadata.getFilename();
|
filename = metadata.getFilename();
|
||||||
} else if (ClipDescription.compareMimeTypes(metadata.getMimeType(), Constants.MIME_TYPE_KEYS)) {
|
} else if (ClipDescription.compareMimeTypes(metadata.getMimeType(), Constants.MIME_TYPE_KEYS)) {
|
||||||
filename = getString(R.string.filename_keys);
|
filename = getString(R.string.filename_keys);
|
||||||
@@ -1226,7 +1227,7 @@ public class DecryptListFragment
|
|||||||
vSigStatusText = (TextView) itemView.findViewById(R.id.result_signature_text);
|
vSigStatusText = (TextView) itemView.findViewById(R.id.result_signature_text);
|
||||||
vSignatureLayout = itemView.findViewById(R.id.result_signature_layout);
|
vSignatureLayout = itemView.findViewById(R.id.result_signature_layout);
|
||||||
vSignatureName = (TextView) itemView.findViewById(R.id.result_signature_name);
|
vSignatureName = (TextView) itemView.findViewById(R.id.result_signature_name);
|
||||||
vSignatureMail= (TextView) itemView.findViewById(R.id.result_signature_email);
|
vSignatureMail = (TextView) itemView.findViewById(R.id.result_signature_email);
|
||||||
vSignatureAction = (ViewAnimator) itemView.findViewById(R.id.result_signature_action);
|
vSignatureAction = (ViewAnimator) itemView.findViewById(R.id.result_signature_action);
|
||||||
|
|
||||||
vFileList = (LinearLayout) itemView.findViewById(R.id.file_list);
|
vFileList = (LinearLayout) itemView.findViewById(R.id.file_list);
|
||||||
|
|||||||
@@ -362,12 +362,11 @@ public class ImportKeysListFragment extends Fragment implements
|
|||||||
ArrayList<ImportKeysListEntry> result = data.getResult();
|
ArrayList<ImportKeysListEntry> result = data.getResult();
|
||||||
binding.setStatus(result.size() > 0 ? STATUS_LOADED : STATUS_EMPTY);
|
binding.setStatus(result.size() > 0 ? STATUS_LOADED : STATUS_EMPTY);
|
||||||
|
|
||||||
mAdapter.setLoaderState(mLoaderState);
|
|
||||||
mAdapter.setData(result);
|
|
||||||
|
|
||||||
// free old cached key data
|
// free old cached key data
|
||||||
mCachedKeyData = null;
|
mCachedKeyData = null;
|
||||||
|
|
||||||
|
mAdapter.setData(result);
|
||||||
|
|
||||||
GetKeyResult getKeyResult = (GetKeyResult) data.getOperationResult();
|
GetKeyResult getKeyResult = (GetKeyResult) data.getOperationResult();
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_BYTES:
|
case LOADER_ID_BYTES:
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class ImportKeysProxyActivity extends FragmentActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void importKeys(String fingerprint) {
|
public void importKeys(String fingerprint) {
|
||||||
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null);
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null);
|
||||||
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<>();
|
||||||
selectedEntries.add(keyEntry);
|
selectedEntries.add(keyEntry);
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import android.widget.ViewAnimator;
|
|||||||
|
|
||||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||||
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
@@ -77,6 +78,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
|||||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
|
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
|
||||||
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||||
|
|
||||||
@@ -244,7 +246,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
|
||||||
boolean checked) {
|
boolean checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
mAdapter.setNewSelection(position, true);
|
mAdapter.setNewSelection(position, true);
|
||||||
} else {
|
} else {
|
||||||
@@ -333,7 +335,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
headerCursor.addRow(row);
|
headerCursor.addRow(row);
|
||||||
|
|
||||||
Cursor dataCursor = data;
|
Cursor dataCursor = data;
|
||||||
data = new MergeCursor(new Cursor[] {
|
data = new MergeCursor(new Cursor[]{
|
||||||
headerCursor, dataCursor
|
headerCursor, dataCursor
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -575,7 +577,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
byte[] blob = cursor.getBlob(0);//fingerprint column is 0
|
byte[] blob = cursor.getBlob(0);//fingerprint column is 0
|
||||||
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
|
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
|
||||||
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null);
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null);
|
||||||
keyList.add(keyEntry);
|
keyList.add(keyEntry);
|
||||||
}
|
}
|
||||||
mKeyList = keyList;
|
mKeyList = keyList;
|
||||||
|
|||||||
@@ -19,11 +19,6 @@
|
|||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
@@ -89,10 +84,10 @@ import org.sufficientlysecure.keychain.ui.ViewKeyFragment.PostponeType;
|
|||||||
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.ContentDescriptionHint;
|
||||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||||
import org.sufficientlysecure.keychain.ui.util.ContentDescriptionHint;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
@@ -103,6 +98,11 @@ import org.sufficientlysecure.keychain.util.NfcHelper;
|
|||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
||||||
LoaderManager.LoaderCallbacks<Cursor>,
|
LoaderManager.LoaderCallbacks<Cursor>,
|
||||||
@@ -114,7 +114,9 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({REQUEST_QR_FINGERPRINT, REQUEST_BACKUP, REQUEST_CERTIFY, REQUEST_DELETE})
|
@IntDef({REQUEST_QR_FINGERPRINT, REQUEST_BACKUP, REQUEST_CERTIFY, REQUEST_DELETE})
|
||||||
private @interface RequestType {}
|
private @interface RequestType {
|
||||||
|
}
|
||||||
|
|
||||||
static final int REQUEST_QR_FINGERPRINT = 1;
|
static final int REQUEST_QR_FINGERPRINT = 1;
|
||||||
static final int REQUEST_BACKUP = 2;
|
static final int REQUEST_BACKUP = 2;
|
||||||
static final int REQUEST_CERTIFY = 3;
|
static final int REQUEST_CERTIFY = 3;
|
||||||
@@ -564,7 +566,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
|
|
||||||
private void startBackupActivity() {
|
private void startBackupActivity() {
|
||||||
Intent intent = new Intent(this, BackupActivity.class);
|
Intent intent = new Intent(this, BackupActivity.class);
|
||||||
intent.putExtra(BackupActivity.EXTRA_MASTER_KEY_IDS, new long[] { mMasterKeyId });
|
intent.putExtra(BackupActivity.EXTRA_MASTER_KEY_IDS, new long[]{mMasterKeyId});
|
||||||
intent.putExtra(BackupActivity.EXTRA_SECRET, true);
|
intent.putExtra(BackupActivity.EXTRA_SECRET, true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@@ -721,7 +723,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
manager.beginTransaction()
|
manager.beginTransaction()
|
||||||
.addToBackStack("security_token")
|
.addToBackStack("security_token")
|
||||||
.replace(R.id.view_key_fragment, frag)
|
.replace(R.id.view_key_fragment, frag)
|
||||||
// if this is called while the activity wasn't resumed, just forget it happened
|
// if this is called while the activity wasn't resumed, just forget it happened
|
||||||
.commitAllowingStateLoss();
|
.commitAllowingStateLoss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1104,7 +1106,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
|
|||||||
KeychainContract.Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
KeychainContract.Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
||||||
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
|
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
|
||||||
|
|
||||||
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null);
|
ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null);
|
||||||
ArrayList<ParcelableKeyRing> entries = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> entries = new ArrayList<>();
|
||||||
entries.add(keyEntry);
|
entries.add(keyEntry);
|
||||||
mKeyList = entries;
|
mKeyList = entries;
|
||||||
|
|||||||
@@ -29,12 +29,9 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.databinding.ImportKeysListItemBinding;
|
import org.sufficientlysecure.keychain.databinding.ImportKeysListItemBinding;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
import org.sufficientlysecure.keychain.keyimport.processing.BytesLoaderState;
|
|
||||||
import org.sufficientlysecure.keychain.keyimport.processing.CloudLoaderState;
|
|
||||||
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListener;
|
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysListener;
|
||||||
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysOperationCallback;
|
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysOperationCallback;
|
||||||
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysResultListener;
|
import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysResultListener;
|
||||||
import org.sufficientlysecure.keychain.keyimport.processing.LoaderState;
|
|
||||||
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||||
@@ -54,7 +51,6 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
private ImportKeysResultListener mListener;
|
private ImportKeysResultListener mListener;
|
||||||
private boolean mAdvanced, mNonInteractive;
|
private boolean mAdvanced, mNonInteractive;
|
||||||
|
|
||||||
private LoaderState mLoaderState;
|
|
||||||
private List<ImportKeysListEntry> mData;
|
private List<ImportKeysListEntry> mData;
|
||||||
|
|
||||||
private KeyState[] mKeyStates;
|
private KeyState[] mKeyStates;
|
||||||
@@ -73,11 +69,6 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoaderState(LoaderState loaderState) {
|
|
||||||
this.mLoaderState = loaderState;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(List<ImportKeysListEntry> data) {
|
public void setData(List<ImportKeysListEntry> data) {
|
||||||
this.mData = data;
|
this.mData = data;
|
||||||
this.mKeyStates = new KeyState[data.size()];
|
this.mKeyStates = new KeyState[data.size()];
|
||||||
@@ -145,7 +136,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
b.importKey.setOnClickListener(new View.OnClickListener() {
|
b.importKey.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
getKey(getParcelableKeyRing(entry), false);
|
getKey(entry, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -154,7 +145,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mCurrent = position;
|
mCurrent = position;
|
||||||
if (!showed && !downloaded) {
|
if (!showed && !downloaded) {
|
||||||
getKey(getParcelableKeyRing(entry), true);
|
getKey(entry, true);
|
||||||
} else {
|
} else {
|
||||||
changeState(position, !showed);
|
changeState(position, !showed);
|
||||||
}
|
}
|
||||||
@@ -179,8 +170,8 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
return mData != null ? mData.size() : 0;
|
return mData != null ? mData.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getKey(ParcelableKeyRing keyRing, boolean skipSave) {
|
public void getKey(ImportKeysListEntry entry, boolean skipSave) {
|
||||||
ImportKeyringParcel inputParcel = prepareKeyOperation(keyRing, skipSave);
|
ImportKeyringParcel inputParcel = prepareKeyOperation(entry, skipSave);
|
||||||
ImportKeysResultListener listener = skipSave ? this : mListener;
|
ImportKeysResultListener listener = skipSave ? this : mListener;
|
||||||
ImportKeysOperationCallback cb = new ImportKeysOperationCallback(listener, inputParcel);
|
ImportKeysOperationCallback cb = new ImportKeysOperationCallback(listener, inputParcel);
|
||||||
int message = skipSave ? R.string.progress_downloading : R.string.progress_importing;
|
int message = skipSave ? R.string.progress_downloading : R.string.progress_importing;
|
||||||
@@ -188,22 +179,12 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
opHelper.cryptoOperation();
|
opHelper.cryptoOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParcelableKeyRing getParcelableKeyRing(ImportKeysListEntry entry) {
|
private ImportKeyringParcel prepareKeyOperation(ImportKeysListEntry entry, boolean skipSave) {
|
||||||
ParcelableKeyRing keyRing = null;
|
|
||||||
if (mLoaderState instanceof BytesLoaderState) {
|
|
||||||
keyRing = new ParcelableKeyRing(entry.getEncodedRing());
|
|
||||||
} else if (mLoaderState instanceof CloudLoaderState) {
|
|
||||||
keyRing = new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex(),
|
|
||||||
entry.getKeybaseName(), entry.getFbUsername());
|
|
||||||
}
|
|
||||||
return keyRing;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImportKeyringParcel prepareKeyOperation(ParcelableKeyRing keyRing, boolean skipSave) {
|
|
||||||
ArrayList<ParcelableKeyRing> keysList = null;
|
ArrayList<ParcelableKeyRing> keysList = null;
|
||||||
String keyserver = null;
|
String keyserver = null;
|
||||||
|
|
||||||
if (mLoaderState instanceof BytesLoaderState) {
|
ParcelableKeyRing keyRing = entry.getParcelableKeyRing();
|
||||||
|
if (keyRing.mBytes != null) {
|
||||||
// instead of giving the entries by Intent extra, cache them into a
|
// instead of giving the entries by Intent extra, cache them into a
|
||||||
// file to prevent Java Binder problems on heavy imports
|
// file to prevent Java Binder problems on heavy imports
|
||||||
// read FileImportCache for more info.
|
// read FileImportCache for more info.
|
||||||
@@ -217,10 +198,10 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
Log.e(Constants.TAG, "Problem writing cache file", e);
|
Log.e(Constants.TAG, "Problem writing cache file", e);
|
||||||
Notify.create(mActivity, "Problem writing cache file!", Notify.Style.ERROR).show();
|
Notify.create(mActivity, "Problem writing cache file!", Notify.Style.ERROR).show();
|
||||||
}
|
}
|
||||||
} else if (mLoaderState instanceof CloudLoaderState) {
|
} else {
|
||||||
keysList = new ArrayList<>();
|
keysList = new ArrayList<>();
|
||||||
keysList.add(keyRing);
|
keysList.add(keyRing);
|
||||||
keyserver = ((CloudLoaderState) mLoaderState).mCloudPrefs.keyserver;
|
keyserver = entry.getKeyserver();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImportKeyringParcel(keysList, keyserver, skipSave);
|
return new ImportKeyringParcel(keysList, keyserver, skipSave);
|
||||||
|
|||||||
@@ -57,11 +57,13 @@ public class EmailKeyHelper {
|
|||||||
// Put them in a list and import
|
// Put them in a list and import
|
||||||
ArrayList<ParcelableKeyRing> keys = new ArrayList<>(entries.size());
|
ArrayList<ParcelableKeyRing> keys = new ArrayList<>(entries.size());
|
||||||
for (ImportKeysListEntry entry : entries) {
|
for (ImportKeysListEntry entry : entries) {
|
||||||
keys.add(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex()));
|
keys.add(new ParcelableKeyRing(entry.getFingerprintHex(), entry.getKeyIdHex(), null,
|
||||||
|
null));
|
||||||
}
|
}
|
||||||
mKeyList = keys;
|
mKeyList = keys;
|
||||||
mKeyserver = keyserver;
|
mKeyserver = keyserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImportKeyringParcel createOperationInput() {
|
public ImportKeyringParcel createOperationInput() {
|
||||||
return new ImportKeyringParcel(mKeyList, mKeyserver);
|
return new ImportKeyringParcel(mKeyList, mKeyserver);
|
||||||
|
|||||||
Reference in New Issue
Block a user