ImportKeys: Integrate more features in ImportKeysListEntry
This commit is contained in:
parent
0325c27987
commit
9bf06e216b
|
@ -160,10 +160,7 @@ public class FacebookKeyserver extends Keyserver {
|
||||||
entry.setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
entry.setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
||||||
|
|
||||||
entry.setKeyId(key.getKeyId());
|
entry.setKeyId(key.getKeyId());
|
||||||
entry.setKeyIdHex(KeyFormattingUtils.convertKeyIdToHex(key.getKeyId()));
|
entry.setFingerprint(key.getFingerprint());
|
||||||
|
|
||||||
entry.setFingerprintHex(KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint()));
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (key.isEC()) { // unsupported key format (ECDH or ECDSA)
|
if (key.isEC()) { // unsupported key format (ECDH or ECDSA)
|
||||||
|
|
|
@ -21,7 +21,7 @@ import android.content.Context;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
|
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
|
||||||
|
@ -45,7 +45,6 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
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;
|
||||||
|
|
||||||
private long mKeyId;
|
|
||||||
private String mKeyIdHex;
|
private String mKeyIdHex;
|
||||||
private boolean mRevoked;
|
private boolean mRevoked;
|
||||||
private boolean mExpired;
|
private boolean mExpired;
|
||||||
|
@ -55,7 +54,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
private String mCurveOid;
|
private String mCurveOid;
|
||||||
private String mAlgorithm;
|
private String mAlgorithm;
|
||||||
private boolean mSecretKey;
|
private boolean mSecretKey;
|
||||||
private String mPrimaryUserId;
|
private UserId mPrimaryUserId;
|
||||||
private String mKeybaseName;
|
private String mKeybaseName;
|
||||||
private String mFbUsername;
|
private String mFbUsername;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
|
@ -68,10 +67,9 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeString(mPrimaryUserId);
|
dest.writeSerializable(mPrimaryUserId);
|
||||||
dest.writeStringList(mUserIds);
|
dest.writeStringList(mUserIds);
|
||||||
dest.writeSerializable(mMergedUserIds);
|
dest.writeSerializable(mMergedUserIds);
|
||||||
dest.writeLong(mKeyId);
|
|
||||||
dest.writeByte((byte) (mRevoked ? 1 : 0));
|
dest.writeByte((byte) (mRevoked ? 1 : 0));
|
||||||
dest.writeByte((byte) (mExpired ? 1 : 0));
|
dest.writeByte((byte) (mExpired ? 1 : 0));
|
||||||
dest.writeInt(mDate == null ? 0 : 1);
|
dest.writeInt(mDate == null ? 0 : 1);
|
||||||
|
@ -94,11 +92,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
public static final Creator<ImportKeysListEntry> CREATOR = new Creator<ImportKeysListEntry>() {
|
||||||
public ImportKeysListEntry createFromParcel(final Parcel source) {
|
public ImportKeysListEntry createFromParcel(final Parcel source) {
|
||||||
ImportKeysListEntry vr = new ImportKeysListEntry();
|
ImportKeysListEntry vr = new ImportKeysListEntry();
|
||||||
vr.mPrimaryUserId = source.readString();
|
vr.mPrimaryUserId = (UserId) source.readSerializable();
|
||||||
vr.mUserIds = new ArrayList<>();
|
vr.mUserIds = new ArrayList<>();
|
||||||
source.readStringList(vr.mUserIds);
|
source.readStringList(vr.mUserIds);
|
||||||
vr.mMergedUserIds = (HashMap<String, HashSet<String>>) source.readSerializable();
|
vr.mMergedUserIds = (HashMap<String, HashSet<String>>) source.readSerializable();
|
||||||
vr.mKeyId = source.readLong();
|
|
||||||
vr.mRevoked = source.readByte() == 1;
|
vr.mRevoked = source.readByte() == 1;
|
||||||
vr.mExpired = source.readByte() == 1;
|
vr.mExpired = source.readByte() == 1;
|
||||||
vr.mDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
vr.mDate = source.readInt() != 0 ? new Date(source.readLong()) : null;
|
||||||
|
@ -138,6 +135,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
return mKeyIdHex;
|
return mKeyIdHex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setKeyIdHex(String keyIdHex) {
|
||||||
|
mKeyIdHex = keyIdHex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyId(long keyId) {
|
||||||
|
mKeyIdHex = KeyFormattingUtils.convertKeyIdToHex(keyId);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isExpired() {
|
public boolean isExpired() {
|
||||||
return mExpired;
|
return mExpired;
|
||||||
}
|
}
|
||||||
|
@ -146,22 +151,6 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
mExpired = expired;
|
mExpired = expired;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getEncodedRing() {
|
|
||||||
return mEncodedRing;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getKeyId() {
|
|
||||||
return mKeyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyId(long keyId) {
|
|
||||||
mKeyId = keyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyIdHex(String keyIdHex) {
|
|
||||||
mKeyIdHex = keyIdHex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRevoked() {
|
public boolean isRevoked() {
|
||||||
return mRevoked;
|
return mRevoked;
|
||||||
}
|
}
|
||||||
|
@ -170,6 +159,14 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
mRevoked = revoked;
|
mRevoked = revoked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRevokedOrExpired() {
|
||||||
|
return mRevoked || mExpired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getEncodedRing() {
|
||||||
|
return mEncodedRing;
|
||||||
|
}
|
||||||
|
|
||||||
public Date getDate() {
|
public Date getDate() {
|
||||||
return mDate;
|
return mDate;
|
||||||
}
|
}
|
||||||
|
@ -186,6 +183,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
mFingerprintHex = fingerprintHex;
|
mFingerprintHex = fingerprintHex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFingerprint(byte[] fingerprint) {
|
||||||
|
mFingerprintHex = KeyFormattingUtils.convertFingerprintToHex(fingerprint);
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getBitStrength() {
|
public Integer getBitStrength() {
|
||||||
return mBitStrength;
|
return mBitStrength;
|
||||||
}
|
}
|
||||||
|
@ -214,12 +215,16 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
mSecretKey = secretKey;
|
mSecretKey = secretKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimaryUserId() {
|
public UserId getPrimaryUserId() {
|
||||||
return mPrimaryUserId;
|
return mPrimaryUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrimaryUserId(String uid) {
|
public void setPrimaryUserId(String userId) {
|
||||||
mPrimaryUserId = uid;
|
mPrimaryUserId = KeyRing.splitUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrimaryUserId(UserId primaryUserId) {
|
||||||
|
mPrimaryUserId = primaryUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeybaseName() {
|
public String getKeybaseName() {
|
||||||
|
@ -317,27 +322,26 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
|
||||||
|
|
||||||
mHashCode = key.hashCode();
|
mHashCode = key.hashCode();
|
||||||
|
|
||||||
mPrimaryUserId = key.getPrimaryUserIdWithFallback();
|
setPrimaryUserId(key.getPrimaryUserIdWithFallback());
|
||||||
mUserIds = key.getUnorderedUserIds();
|
setKeyId(key.getKeyId());
|
||||||
updateMergedUserIds();
|
setFingerprint(key.getFingerprint());
|
||||||
|
|
||||||
mKeyId = key.getKeyId();
|
|
||||||
mKeyIdHex = KeyFormattingUtils.convertKeyIdToHex(mKeyId);
|
|
||||||
|
|
||||||
// NOTE: Dont use maybe methods for now, they can be wrong.
|
// NOTE: Dont use maybe methods for now, they can be wrong.
|
||||||
mRevoked = false; //key.isMaybeRevoked();
|
mRevoked = false; //key.isMaybeRevoked();
|
||||||
mExpired = false; //key.isMaybeExpired();
|
mExpired = false; //key.isMaybeExpired();
|
||||||
mFingerprintHex = KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint());
|
|
||||||
mBitStrength = key.getBitStrength();
|
mBitStrength = key.getBitStrength();
|
||||||
mCurveOid = key.getCurveOid();
|
mCurveOid = key.getCurveOid();
|
||||||
final int algorithm = key.getAlgorithm();
|
final int algorithm = key.getAlgorithm();
|
||||||
mAlgorithm = KeyFormattingUtils.getAlgorithmInfo(context, algorithm, mBitStrength, mCurveOid);
|
mAlgorithm = KeyFormattingUtils.getAlgorithmInfo(context, algorithm, mBitStrength, mCurveOid);
|
||||||
|
|
||||||
|
setUserIds(key.getUnorderedUserIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMergedUserIds() {
|
private void updateMergedUserIds() {
|
||||||
mMergedUserIds = new HashMap<>();
|
mMergedUserIds = new HashMap<>();
|
||||||
for (String userId : mUserIds) {
|
for (String userId : mUserIds) {
|
||||||
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
UserId userIdSplit = KeyRing.splitUserId(userId);
|
||||||
|
|
||||||
// TODO: comment field?
|
// TODO: comment field?
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.databinding.ImportKeysListItemBinding;
|
import org.sufficientlysecure.keychain.databinding.ImportKeysListItemBinding;
|
||||||
|
@ -43,7 +42,6 @@ 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;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||||
|
@ -135,9 +133,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(mActivity);
|
LayoutInflater inflater = LayoutInflater.from(mActivity);
|
||||||
View v = inflater.inflate(R.layout.import_keys_list_item, parent, false);
|
return new ViewHolder(inflater.inflate(R.layout.import_keys_list_item, parent, false));
|
||||||
ViewHolder vh = new ViewHolder(v);
|
|
||||||
return vh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,12 +144,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||||
Highlighter highlighter = new Highlighter(mActivity, entry.getQuery());
|
Highlighter highlighter = new Highlighter(mActivity, entry.getQuery());
|
||||||
b.setHighlighter(highlighter);
|
b.setHighlighter(highlighter);
|
||||||
|
|
||||||
String userId = entry.getPrimaryUserId();
|
|
||||||
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
|
|
||||||
|
|
||||||
b.setEntry(entry);
|
b.setEntry(entry);
|
||||||
b.setUserId(userIdSplit.name);
|
|
||||||
b.setUserIdEmail(userIdSplit.email);
|
|
||||||
|
|
||||||
if (entry.isRevoked()) {
|
if (entry.isRevoked()) {
|
||||||
KeyFormattingUtils.setStatusImage(mActivity, b.status, null,
|
KeyFormattingUtils.setStatusImage(mActivity, b.status, null,
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ImportUserIdsView extends LinearLayout {
|
||||||
uidView.setText(highlighter.highlight(cUserId));
|
uidView.setText(highlighter.highlight(cUserId));
|
||||||
uidView.setPadding(0, 0, FormattingUtils.dpToPx(context, 8), 0);
|
uidView.setPadding(0, 0, FormattingUtils.dpToPx(context, 8), 0);
|
||||||
|
|
||||||
if (entry.isRevoked() || entry.isExpired()) {
|
if (entry.isRevokedOrExpired()) {
|
||||||
uidView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
uidView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
||||||
} else {
|
} else {
|
||||||
uidView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
uidView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
||||||
|
@ -57,7 +57,7 @@ public class ImportUserIdsView extends LinearLayout {
|
||||||
FormattingUtils.dpToPx(context, 8), 0);
|
FormattingUtils.dpToPx(context, 8), 0);
|
||||||
emailView.setText(highlighter.highlight(email));
|
emailView.setText(highlighter.highlight(email));
|
||||||
|
|
||||||
if (entry.isRevoked() || entry.isExpired()) {
|
if (entry.isRevokedOrExpired()) {
|
||||||
emailView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
emailView.setTextColor(context.getResources().getColor(R.color.key_flag_gray));
|
||||||
} else {
|
} else {
|
||||||
emailView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
emailView.setTextColor(FormattingUtils.getColorFromAttr(context, R.attr.colorText));
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class EmailKeyHelper {
|
||||||
Set<ImportKeysListEntry> keys = new HashSet<>();
|
Set<ImportKeysListEntry> keys = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
for (ImportKeysListEntry key : keyServer.search(mail)) {
|
for (ImportKeysListEntry key : keyServer.search(mail)) {
|
||||||
if (key.isRevoked() || key.isExpired()) continue;
|
if (key.isRevokedOrExpired()) continue;
|
||||||
for (String userId : key.getUserIds()) {
|
for (String userId : key.getUserIds()) {
|
||||||
if (userId.toLowerCase().contains(mail.toLowerCase(Locale.ENGLISH))) {
|
if (userId.toLowerCase().contains(mail.toLowerCase(Locale.ENGLISH))) {
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
<variable name="highlighter" type="Highlighter" />
|
<variable name="highlighter" type="Highlighter" />
|
||||||
|
|
||||||
<variable name="entry" type="ImportKeysListEntry" />
|
<variable name="entry" type="ImportKeysListEntry" />
|
||||||
<variable name="userId" type="String" />
|
|
||||||
<variable name="userIdEmail" type="String" />
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
|
@ -61,23 +59,23 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text='@{entry.secretKey ? @string/secret_key + " " + (userId ?? @string/user_id_no_name) : highlighter.highlight(userId ?? @string/user_id_no_name)}'
|
android:text='@{entry.secretKey ? @string/secret_key + " " + (entry.primaryUserId.name ?? @string/user_id_no_name) : highlighter.highlight(entry.primaryUserId.name ?? @string/user_id_no_name)}'
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : (entry.secretKey ? secretColor : standardColor)}" />
|
android:textColor="@{entry.revokedOrExpired ? revokedExpiredColor : (entry.secretKey ? secretColor : standardColor)}" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:text="@{highlighter.highlight(userIdEmail)}"
|
android:text="@{highlighter.highlight(entry.primaryUserId.email)}"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : standardColor}" />
|
android:textColor="@{entry.revokedOrExpired ? revokedExpiredColor : standardColor}" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textColor="@{entry.revoked || entry.expired ? revokedExpiredColor : standardColor}"
|
android:textColor="@{entry.revokedOrExpired ? revokedExpiredColor : standardColor}"
|
||||||
app:keyId='@{entry.keyIdHex ?? ""}' />
|
app:keyId='@{entry.keyIdHex ?? ""}' />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -88,7 +86,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:visibility="@{entry.revoked || entry.expired ? View.VISIBLE : View.GONE}" />
|
android:visibility="@{entry.revokedOrExpired ? View.VISIBLE : View.GONE}" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue