Merge branch 'master' into automatic-contact-discovery

Conflicts:
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java
	OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
This commit is contained in:
mar-v-in 2014-06-05 23:56:29 +02:00
commit e2164f571e
37 changed files with 214 additions and 340 deletions

View File

@ -19,16 +19,13 @@ package org.sufficientlysecure.keychain.helper;
import android.app.Activity; import android.app.Activity;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log;
public class ActionBarHelper { public class ActionBarHelper {

View File

@ -32,17 +32,17 @@ import java.util.Date;
public class ImportKeysListEntry implements Serializable, Parcelable { public class ImportKeysListEntry implements Serializable, Parcelable {
private static final long serialVersionUID = -7797972103284992662L; private static final long serialVersionUID = -7797972103284992662L;
public ArrayList<String> userIds; private ArrayList<String> mUserIds;
public long keyId; private long mKeyId;
public String keyIdHex; private String mKeyIdHex;
public boolean revoked; private boolean mRevoked;
public boolean expired; private boolean mExpired;
public Date date; // TODO: not displayed private Date mDate; // TODO: not displayed
public String fingerprintHex; private String mFingerprintHex;
public int bitStrength; private int mBitStrength;
public String algorithm; private String mAlgorithm;
public boolean secretKey; private boolean mSecretKey;
public String mPrimaryUserId; private String mPrimaryUserId;
private String mExtraData; private String mExtraData;
private String mQuery; private String mQuery;
private String mOrigin; private String mOrigin;
@ -56,16 +56,16 @@ 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.writeString(mPrimaryUserId);
dest.writeStringList(userIds); dest.writeStringList(mUserIds);
dest.writeLong(keyId); dest.writeLong(mKeyId);
dest.writeByte((byte) (revoked ? 1 : 0)); dest.writeByte((byte) (mRevoked ? 1 : 0));
dest.writeByte((byte) (expired ? 1 : 0)); dest.writeByte((byte) (mExpired ? 1 : 0));
dest.writeSerializable(date); dest.writeSerializable(mDate);
dest.writeString(fingerprintHex); dest.writeString(mFingerprintHex);
dest.writeString(keyIdHex); dest.writeString(mKeyIdHex);
dest.writeInt(bitStrength); dest.writeInt(mBitStrength);
dest.writeString(algorithm); dest.writeString(mAlgorithm);
dest.writeByte((byte) (secretKey ? 1 : 0)); dest.writeByte((byte) (mSecretKey ? 1 : 0));
dest.writeByte((byte) (mSelected ? 1 : 0)); dest.writeByte((byte) (mSelected ? 1 : 0));
dest.writeString(mExtraData); dest.writeString(mExtraData);
dest.writeString(mOrigin); dest.writeString(mOrigin);
@ -75,17 +75,17 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
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 = source.readString();
vr.userIds = new ArrayList<String>(); vr.mUserIds = new ArrayList<String>();
source.readStringList(vr.userIds); source.readStringList(vr.mUserIds);
vr.keyId = source.readLong(); vr.mKeyId = source.readLong();
vr.revoked = source.readByte() == 1; vr.mRevoked = source.readByte() == 1;
vr.expired = source.readByte() == 1; vr.mExpired = source.readByte() == 1;
vr.date = (Date) source.readSerializable(); vr.mDate = (Date) source.readSerializable();
vr.fingerprintHex = source.readString(); vr.mFingerprintHex = source.readString();
vr.keyIdHex = source.readString(); vr.mKeyIdHex = source.readString();
vr.bitStrength = source.readInt(); vr.mBitStrength = source.readInt();
vr.algorithm = source.readString(); vr.mAlgorithm = source.readString();
vr.secretKey = source.readByte() == 1; vr.mSecretKey = source.readByte() == 1;
vr.mSelected = source.readByte() == 1; vr.mSelected = source.readByte() == 1;
vr.mExtraData = source.readString(); vr.mExtraData = source.readString();
vr.mOrigin = source.readString(); vr.mOrigin = source.readString();
@ -99,7 +99,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
}; };
public String getKeyIdHex() { public String getKeyIdHex() {
return keyIdHex; return mKeyIdHex;
} }
public boolean isSelected() { public boolean isSelected() {
@ -111,79 +111,79 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
} }
public boolean isExpired() { public boolean isExpired() {
return expired; return mExpired;
} }
public void setExpired(boolean expired) { public void setExpired(boolean expired) {
this.expired = expired; this.mExpired = expired;
} }
public long getKeyId() { public long getKeyId() {
return keyId; return mKeyId;
} }
public void setKeyId(long keyId) { public void setKeyId(long keyId) {
this.keyId = keyId; this.mKeyId = keyId;
} }
public void setKeyIdHex(String keyIdHex) { public void setKeyIdHex(String keyIdHex) {
this.keyIdHex = keyIdHex; this.mKeyIdHex = keyIdHex;
} }
public boolean isRevoked() { public boolean isRevoked() {
return revoked; return mRevoked;
} }
public void setRevoked(boolean revoked) { public void setRevoked(boolean revoked) {
this.revoked = revoked; this.mRevoked = revoked;
} }
public Date getDate() { public Date getDate() {
return date; return mDate;
} }
public void setDate(Date date) { public void setDate(Date date) {
this.date = date; this.mDate = date;
} }
public String getFingerprintHex() { public String getFingerprintHex() {
return fingerprintHex; return mFingerprintHex;
} }
public void setFingerprintHex(String fingerprintHex) { public void setFingerprintHex(String fingerprintHex) {
this.fingerprintHex = fingerprintHex; this.mFingerprintHex = fingerprintHex;
} }
public int getBitStrength() { public int getBitStrength() {
return bitStrength; return mBitStrength;
} }
public void setBitStrength(int bitStrength) { public void setBitStrength(int bitStrength) {
this.bitStrength = bitStrength; this.mBitStrength = bitStrength;
} }
public String getAlgorithm() { public String getAlgorithm() {
return algorithm; return mAlgorithm;
} }
public void setAlgorithm(String algorithm) { public void setAlgorithm(String algorithm) {
this.algorithm = algorithm; this.mAlgorithm = algorithm;
} }
public boolean isSecretKey() { public boolean isSecretKey() {
return secretKey; return mSecretKey;
} }
public void setSecretKey(boolean secretKey) { public void setSecretKey(boolean secretKey) {
this.secretKey = secretKey; this.mSecretKey = secretKey;
} }
public ArrayList<String> getUserIds() { public ArrayList<String> getUserIds() {
return userIds; return mUserIds;
} }
public void setUserIds(ArrayList<String> userIds) { public void setUserIds(ArrayList<String> userIds) {
this.userIds = userIds; this.mUserIds = userIds;
} }
public String getPrimaryUserId() { public String getPrimaryUserId() {
@ -223,10 +223,10 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
*/ */
public ImportKeysListEntry() { public ImportKeysListEntry() {
// keys from keyserver are always public keys; from keybase too // keys from keyserver are always public keys; from keybase too
secretKey = false; mSecretKey = false;
// do not select by default // do not select by default
mSelected = false; mSelected = false;
userIds = new ArrayList<String>(); mUserIds = new ArrayList<String>();
} }
/** /**
@ -237,24 +237,24 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
// selected is default // selected is default
this.mSelected = true; this.mSelected = true;
secretKey = ring.isSecret(); mSecretKey = ring.isSecret();
UncachedPublicKey key = ring.getPublicKey(); UncachedPublicKey key = ring.getPublicKey();
mPrimaryUserId = key.getPrimaryUserId(); mPrimaryUserId = key.getPrimaryUserId();
userIds = key.getUnorderedUserIds(); mUserIds = key.getUnorderedUserIds();
// if there was no user id flagged as primary, use the first one // if there was no user id flagged as primary, use the first one
if (mPrimaryUserId == null) { if (mPrimaryUserId == null) {
mPrimaryUserId = userIds.get(0); mPrimaryUserId = mUserIds.get(0);
} }
this.keyId = key.getKeyId(); this.mKeyId = key.getKeyId();
this.keyIdHex = PgpKeyHelper.convertKeyIdToHex(keyId); this.mKeyIdHex = PgpKeyHelper.convertKeyIdToHex(mKeyId);
this.revoked = key.maybeRevoked(); this.mRevoked = key.maybeRevoked();
this.fingerprintHex = PgpKeyHelper.convertFingerprintToHex(key.getFingerprint()); this.mFingerprintHex = PgpKeyHelper.convertFingerprintToHex(key.getFingerprint());
this.bitStrength = key.getBitStrength(); this.mBitStrength = key.getBitStrength();
final int algorithm = key.getAlgorithm(); final int algorithm = key.getAlgorithm();
this.algorithm = PgpKeyHelper.getAlgorithmInfo(context, algorithm); this.mAlgorithm = PgpKeyHelper.getAlgorithmInfo(context, algorithm);
} }
} }

View File

@ -146,7 +146,8 @@ public class KeybaseKeyserver extends Keyserver {
try { try {
JSONObject json = new JSONObject(text); JSONObject json = new JSONObject(text);
if (JWalk.getInt(json, "status", "code") != 0) { if (JWalk.getInt(json, "status", "code") != 0) {
throw new QueryFailedException("Keybase autocomplete search failed"); throw new QueryFailedException("Keybase.io query failed: " + path + "?" +
query);
} }
return json; return json;
} catch (JSONException e) { } catch (JSONException e) {

View File

@ -3,11 +3,6 @@ package org.sufficientlysecure.keychain.keyimport;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import java.io.IOException;
/** This is a trivial wrapper around UncachedKeyRing which implements Parcelable. It exists /** This is a trivial wrapper around UncachedKeyRing which implements Parcelable. It exists
* for the sole purpose of keeping spongycastle and android imports in separate packages. * for the sole purpose of keeping spongycastle and android imports in separate packages.
*/ */
@ -40,12 +35,15 @@ public class ParcelableKeyRing implements Parcelable {
} }
}; };
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
public UncachedKeyRing getUncachedKeyRing() throws PgpGeneralException, IOException { public byte[] getBytes() {
return UncachedKeyRing.decodeFromData(mBytes); return mBytes;
}
public String getExpectedFingerprint() {
return mExpectedFingerprint;
} }
} }

View File

@ -2,6 +2,9 @@ package org.sufficientlysecure.keychain.pgp;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** An abstract KeyRing. /** An abstract KeyRing.
* *
* This is an abstract class for all KeyRing constructs. It serves as a common * This is an abstract class for all KeyRing constructs. It serves as a common
@ -19,6 +22,10 @@ public abstract class KeyRing {
abstract public String getPrimaryUserId() throws PgpGeneralException; abstract public String getPrimaryUserId() throws PgpGeneralException;
public String[] getSplitPrimaryUserId() throws PgpGeneralException {
return splitUserId(getPrimaryUserId());
}
abstract public boolean isRevoked() throws PgpGeneralException; abstract public boolean isRevoked() throws PgpGeneralException;
abstract public boolean canCertify() throws PgpGeneralException; abstract public boolean canCertify() throws PgpGeneralException;
@ -33,4 +40,39 @@ public abstract class KeyRing {
abstract public int getVerified() throws PgpGeneralException; abstract public int getVerified() throws PgpGeneralException;
private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");
/**
* Splits userId string into naming part, email part, and comment part
*
* @param userId
* @return array with naming (0), email (1), comment (2)
*/
public static String[] splitUserId(String userId) {
String[] result = new String[]{null, null, null};
if (userId == null || userId.equals("")) {
return result;
}
/*
* User ID matching:
* http://fiddle.re/t4p6f
*
* test cases:
* "Max Mustermann (this is a comment) <max@example.com>"
* "Max Mustermann <max@example.com>"
* "Max Mustermann (this is a comment)"
* "Max Mustermann [this is nothing]"
*/
Matcher matcher = USER_ID_PATTERN.matcher(userId);
if (matcher.matches()) {
result[0] = matcher.group(1);
result[1] = matcher.group(3);
result[2] = matcher.group(2);
}
return result;
}
} }

View File

@ -17,7 +17,6 @@
package org.sufficientlysecure.keychain.pgp; package org.sufficientlysecure.keychain.pgp;
import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPObjectFactory; import org.spongycastle.openpgp.PGPObjectFactory;
import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;

View File

@ -24,7 +24,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.io.File; import java.io.File;

View File

@ -26,13 +26,13 @@ import org.spongycastle.bcpg.ArmoredOutputStream;
import org.spongycastle.openpgp.PGPException; import org.spongycastle.openpgp.PGPException;
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.HkpKeyserver;
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -139,7 +139,18 @@ public class PgpImportExport {
int position = 0; int position = 0;
for (ParcelableKeyRing entry : entries) { for (ParcelableKeyRing entry : entries) {
try { try {
UncachedKeyRing key = entry.getUncachedKeyRing(); UncachedKeyRing key = UncachedKeyRing.decodeFromData(entry.getBytes());
String expectedFp = entry.getExpectedFingerprint();
if(expectedFp != null) {
if(!PgpKeyHelper.convertFingerprintToHex(key.getFingerprint()).equals(expectedFp)) {
Log.e(Constants.TAG, "Actual key fingerprint is not the same as expected!");
badKeys += 1;
continue;
} else {
Log.d(Constants.TAG, "Actual key fingerprint matches expected one.");
}
}
mProviderHelper.savePublicKeyRing(key); mProviderHelper.savePublicKeyRing(key);
/*switch(status) { /*switch(status) {

View File

@ -24,151 +24,19 @@ import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPSignature;
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.security.DigestException; import java.security.DigestException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale; import java.util.Locale;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PgpKeyHelper { public class PgpKeyHelper {
private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");
@Deprecated
public static Date getCreationDate(PGPPublicKey key) {
return key.getCreationTime();
}
@Deprecated
public static Date getExpiryDate(PGPPublicKey key) {
Date creationDate = getCreationDate(key);
if (key.getValidDays() == 0) {
// no expiry
return null;
}
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(creationDate);
calendar.add(Calendar.DATE, key.getValidDays());
return calendar.getTime();
}
@SuppressWarnings("unchecked")
public static boolean isEncryptionKey(PGPPublicKey key) {
if (!key.isEncryptionKey()) {
return false;
}
if (key.getVersion() <= 3) {
// this must be true now
return key.isEncryptionKey();
}
// special cases
if (key.getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT) {
return true;
}
if (key.getAlgorithm() == PGPPublicKey.RSA_ENCRYPT) {
return true;
}
for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) {
continue;
}
PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
if (hashed != null
&& (hashed.getKeyFlags() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0) {
return true;
}
PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();
if (unhashed != null
&& (unhashed.getKeyFlags() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked")
public static boolean isSigningKey(PGPPublicKey key) {
if (key.getVersion() <= 3) {
return true;
}
// special case
if (key.getAlgorithm() == PGPPublicKey.RSA_SIGN) {
return true;
}
for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) {
continue;
}
PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
if (hashed != null && (hashed.getKeyFlags() & KeyFlags.SIGN_DATA) != 0) {
return true;
}
PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();
if (unhashed != null && (unhashed.getKeyFlags() & KeyFlags.SIGN_DATA) != 0) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked")
public static boolean isCertificationKey(PGPPublicKey key) {
if (key.getVersion() <= 3) {
return true;
}
for (PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
if (key.isMasterKey() && sig.getKeyID() != key.getKeyID()) {
continue;
}
PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
if (hashed != null && (hashed.getKeyFlags() & KeyFlags.CERTIFY_OTHER) != 0) {
return true;
}
PGPSignatureSubpacketVector unhashed = sig.getUnhashedSubPackets();
if (unhashed != null && (unhashed.getKeyFlags() & KeyFlags.CERTIFY_OTHER) != 0) {
return true;
}
}
return false;
}
/** /**
* TODO: Only used in HkpKeyServer. Get rid of this one! * TODO: Only used in HkpKeyServer. Get rid of this one!
*/ */
@ -358,37 +226,4 @@ public class PgpKeyHelper {
return result; return result;
} }
/**
* Splits userId string into naming part, email part, and comment part
*
* @param userId
* @return array with naming (0), email (1), comment (2)
*/
public static String[] splitUserId(String userId) {
String[] result = new String[]{null, null, null};
if (userId == null || userId.equals("")) {
return result;
}
/*
* User ID matching:
* http://fiddle.re/t4p6f
*
* test cases:
* "Max Mustermann (this is a comment) <max@example.com>"
* "Max Mustermann <max@example.com>"
* "Max Mustermann (this is a comment)"
* "Max Mustermann [this is nothing]"
*/
Matcher matcher = USER_ID_PATTERN.matcher(userId);
if (matcher.matches()) {
result[0] = matcher.group(1);
result[1] = matcher.group(3);
result[2] = matcher.group(2);
}
return result;
}
} }

View File

@ -14,7 +14,6 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class UncachedPublicKey { public class UncachedPublicKey {
protected final PGPPublicKey mPublicKey; protected final PGPPublicKey mPublicKey;

View File

@ -1,7 +1,6 @@
package org.sufficientlysecure.keychain.pgp; package org.sufficientlysecure.keychain.pgp;
import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPPublicKey;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.IterableIterator;
@ -53,9 +52,9 @@ public abstract class WrappedKeyRing extends KeyRing {
} }
public long getEncryptId() throws PgpGeneralException { public long getEncryptId() throws PgpGeneralException {
for(PGPPublicKey key : new IterableIterator<PGPPublicKey>(getRing().getPublicKeys())) { for(WrappedPublicKey key : publicKeyIterator()) {
if(PgpKeyHelper.isEncryptionKey(key)) { if(key.canEncrypt()) {
return key.getKeyID(); return key.getKeyId();
} }
} }
throw new PgpGeneralException("No valid encryption key found!"); throw new PgpGeneralException("No valid encryption key found!");
@ -71,9 +70,9 @@ public abstract class WrappedKeyRing extends KeyRing {
} }
public long getSignId() throws PgpGeneralException { public long getSignId() throws PgpGeneralException {
for(PGPPublicKey key : new IterableIterator<PGPPublicKey>(getRing().getPublicKeys())) { for(WrappedPublicKey key : publicKeyIterator()) {
if(PgpKeyHelper.isSigningKey(key)) { if(key.canSign()) {
return key.getKeyID(); return key.getKeyId();
} }
} }
throw new PgpGeneralException("No valid signing key found!"); throw new PgpGeneralException("No valid signing key found!");
@ -94,4 +93,6 @@ public abstract class WrappedKeyRing extends KeyRing {
abstract PGPKeyRing getRing(); abstract PGPKeyRing getRing();
abstract public IterableIterator<WrappedPublicKey> publicKeyIterator();
} }

View File

@ -169,7 +169,7 @@ public class WrappedPublicKeyRing extends WrappedKeyRing {
return validPrimaryKeyBinding; return validPrimaryKeyBinding;
} }
public IterableIterator<WrappedPublicKey> iterator() { public IterableIterator<WrappedPublicKey> publicKeyIterator() {
final Iterator<PGPPublicKey> it = getRing().getPublicKeys(); final Iterator<PGPPublicKey> it = getRing().getPublicKeys();
return new IterableIterator<WrappedPublicKey>(new Iterator<WrappedPublicKey>() { return new IterableIterator<WrappedPublicKey>(new Iterator<WrappedPublicKey>() {
@Override @Override

View File

@ -4,7 +4,7 @@ import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPObjectFactory; import org.spongycastle.openpgp.PGPObjectFactory;
import org.spongycastle.openpgp.PGPPrivateKey; import org.spongycastle.openpgp.PGPPrivateKey;
import org.spongycastle.openpgp.PGPPublicKeyRing; import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor; import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
@ -114,7 +114,7 @@ public class WrappedSecretKeyRing extends WrappedKeyRing {
} }
public IterableIterator<WrappedSecretKey> iterator() { public IterableIterator<WrappedSecretKey> secretKeyIterator() {
final Iterator<PGPSecretKey> it = mRing.getSecretKeys(); final Iterator<PGPSecretKey> it = mRing.getSecretKeys();
return new IterableIterator<WrappedSecretKey>(new Iterator<WrappedSecretKey>() { return new IterableIterator<WrappedSecretKey>(new Iterator<WrappedSecretKey>() {
@Override @Override
@ -134,6 +134,26 @@ public class WrappedSecretKeyRing extends WrappedKeyRing {
}); });
} }
public IterableIterator<WrappedPublicKey> publicKeyIterator() {
final Iterator<PGPPublicKey> it = getRing().getPublicKeys();
return new IterableIterator<WrappedPublicKey>(new Iterator<WrappedPublicKey>() {
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public WrappedPublicKey next() {
return new WrappedPublicKey(WrappedSecretKeyRing.this, it.next());
}
@Override
public void remove() {
it.remove();
}
});
}
public UncachedKeyRing getUncached() { public UncachedKeyRing getUncached() {
return new UncachedKeyRing(mRing); return new UncachedKeyRing(mRing);
} }

View File

@ -29,12 +29,12 @@ import android.support.v4.util.LongSparseArray;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedPublicKey;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.WrappedSignature;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
@ -150,11 +150,11 @@ public class ProviderHelper {
if (data != null) { if (data != null) {
try { try {
result.put(masterKeyId, result.put(masterKeyId,
UncachedKeyRing.decodePublicFromData(data).getPublicKey()); UncachedKeyRing.decodeFromData(data).getPublicKey());
} catch(PgpGeneralException e) { } catch(PgpGeneralException e) {
Log.e(Constants.TAG, "Error parsing keyring, skipping."); Log.e(Constants.TAG, "Error parsing keyring, skipping " + masterKeyId, e);
} catch(IOException e) { } catch(IOException e) {
Log.e(Constants.TAG, "IO error, skipping keyring"); Log.e(Constants.TAG, "IO error, skipping keyring" + masterKeyId, e);
} }
} }
} while (cursor.moveToNext()); } while (cursor.moveToNext());

View File

@ -33,11 +33,9 @@ import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
@ -46,14 +44,16 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;

View File

@ -34,6 +34,7 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
@ -111,7 +112,7 @@ public class DecryptFragment extends Fragment {
mSignatureKeyId = signatureResult.getKeyId(); mSignatureKeyId = signatureResult.getKeyId();
String userId = signatureResult.getUserId(); String userId = signatureResult.getUserId();
String[] userIdSplit = PgpKeyHelper.splitUserId(userId); String[] userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit[0] != null) { if (userIdSplit[0] != null) {
mUserId.setText(userIdSplit[0]); mUserId.setText(userIdSplit[0]);
} else { } else {

View File

@ -28,7 +28,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;

View File

@ -47,11 +47,11 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey; import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.UncachedSecretKey;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -289,7 +289,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
WrappedSecretKeyRing keyRing = new ProviderHelper(this).getWrappedSecretKeyRing(secretUri); WrappedSecretKeyRing keyRing = new ProviderHelper(this).getWrappedSecretKeyRing(secretUri);
mMasterCanSign = keyRing.getSubKey().canCertify(); mMasterCanSign = keyRing.getSubKey().canCertify();
for (WrappedSecretKey key : keyRing.iterator()) { for (WrappedSecretKey key : keyRing.secretKeyIterator()) {
// Turn into uncached instance // Turn into uncached instance
mKeys.add(key.getUncached()); mKeys.add(key.getUncached());
mKeysUsages.add(key.getKeyUsage()); // get usage when view is created mKeysUsages.add(key.getKeyUsage()); // get usage when view is created
@ -300,7 +300,7 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Log.d(Constants.TAG, "Added userId " + userId); Log.d(Constants.TAG, "Added userId " + userId);
if (!isSet) { if (!isSet) {
isSet = true; isSet = true;
String[] parts = PgpKeyHelper.splitUserId(userId); String[] parts = KeyRing.splitUserId(userId);
if (parts[0] != null) { if (parts[0] != null) {
setTitle(parts[0]); setTitle(parts[0]);
} }

View File

@ -32,7 +32,6 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
@ -199,10 +198,9 @@ public class EncryptAsymmetricFragment extends Fragment {
// See if we can get a user_id from a unified query // See if we can get a user_id from a unified query
String[] userId; String[] userId;
try { try {
String userIdResult = (String) mProviderHelper.getUnifiedData( userId = mProviderHelper.getCachedPublicKeyRing(
mSecretKeyId, KeyRings.USER_ID, ProviderHelper.FIELD_TYPE_STRING); KeyRings.buildUnifiedKeyRingUri(mSecretKeyId)).getSplitPrimaryUserId();
userId = PgpKeyHelper.splitUserId(userIdResult); } catch (PgpGeneralException e) {
} catch (ProviderHelper.NotFoundException e) {
userId = null; userId = null;
} }
if (userId != null && userId[0] != null) { if (userId != null && userId[0] != null) {

View File

@ -25,7 +25,6 @@ import android.support.v7.app.ActionBarActivity;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
import org.sufficientlysecure.keychain.ui.adapter.TabsAdapter;
import org.sufficientlysecure.keychain.util.SlidingTabLayout; import org.sufficientlysecure.keychain.util.SlidingTabLayout;
public class HelpActivity extends ActionBarActivity { public class HelpActivity extends ActionBarActivity {

View File

@ -42,11 +42,11 @@ import com.devspark.appmsg.AppMsg;
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.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.ui.dialog.BadImportKeyDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.BadImportKeyDialogFragment;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;

View File

@ -18,8 +18,8 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.content.Context; import android.content.Context;
import android.support.v4.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -31,9 +31,7 @@ import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log;
/** /**
* Import public keys from the Keybase.io directory. First cut: just raw search. * Import public keys from the Keybase.io directory. First cut: just raw search.

View File

@ -32,15 +32,15 @@ import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper; import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListServerLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListServerLoader;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;

View File

@ -17,7 +17,6 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -33,8 +32,8 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.CursorAdapter;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.ActionMode; import android.view.ActionMode;
@ -59,7 +58,7 @@ import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
@ -475,7 +474,7 @@ public class KeyListFragment extends LoaderFragment
{ // set name and stuff, common to both key types { // set name and stuff, common to both key types
String userId = cursor.getString(INDEX_USER_ID); String userId = cursor.getString(INDEX_USER_ID);
String[] userIdSplit = PgpKeyHelper.splitUserId(userId); String[] userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit[0] != null) { if (userIdSplit[0] != null) {
h.mMainUserId.setText(highlighter.highlight(userIdSplit[0])); h.mMainUserId.setText(highlighter.highlight(userIdSplit[0]));
} else { } else {

View File

@ -35,6 +35,7 @@ import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
@ -158,7 +159,7 @@ public class SelectSecretKeyLayoutFragment extends Fragment implements LoaderMan
String userID = data.getString(INDEX_USER_ID); String userID = data.getString(INDEX_USER_ID);
long masterKeyID = data.getLong(INDEX_MASTER_KEY_ID); long masterKeyID = data.getLong(INDEX_MASTER_KEY_ID);
String splitUserID[] = PgpKeyHelper.splitUserId(userID); String splitUserID[] = KeyRing.splitUserId(userID);
if (splitUserID[0] != null) { if (splitUserID[0] != null) {
userName = splitUserID[0]; userName = splitUserID[0];

View File

@ -34,8 +34,8 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.WrappedSignature;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;

View File

@ -51,6 +51,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ContactHelper; import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -58,7 +59,6 @@ import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.SlidingTabLayout; import org.sufficientlysecure.keychain.util.SlidingTabLayout;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -420,7 +420,7 @@ public class ViewKeyActivity extends ActionBarActivity implements
case LOADER_ID_UNIFIED: { case LOADER_ID_UNIFIED: {
if (data.moveToFirst()) { if (data.moveToFirst()) {
// get name, email, and comment from USER_ID // get name, email, and comment from USER_ID
String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(INDEX_UNIFIED_USER_ID)); String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_UNIFIED_USER_ID));
if (mainUserId[0] != null) { if (mainUserId[0] != null) {
setTitle(mainUserId[0]); setTitle(mainUserId[0]);
} else { } else {

View File

@ -35,6 +35,7 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.WrappedSignature;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
@ -218,7 +219,7 @@ public class ViewKeyCertsFragment extends LoaderFragment
TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus); TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus);
String signerKeyId = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexSignerKeyId)); String signerKeyId = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexSignerKeyId));
String[] userId = PgpKeyHelper.splitUserId(cursor.getString(mIndexSignerUserId)); String[] userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId));
if (userId[0] != null) { if (userId[0] != null) {
wSignerName.setText(userId[0]); wSignerName.setText(userId[0]);
} else { } else {

View File

@ -18,31 +18,22 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.text.format.DateFormat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.ui.adapter.ViewKeyKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ViewKeyKeysAdapter;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.util.Date;
public class ViewKeyKeysFragment extends LoaderFragment implements public class ViewKeyKeysFragment extends LoaderFragment implements
LoaderManager.LoaderCallbacks<Cursor> { LoaderManager.LoaderCallbacks<Cursor> {

View File

@ -169,18 +169,10 @@ public class ViewKeyMainFragment extends LoaderFragment implements
case LOADER_ID_UNIFIED: { case LOADER_ID_UNIFIED: {
if (data.moveToFirst()) { if (data.moveToFirst()) {
if (data.getInt(INDEX_UNIFIED_HAS_ANY_SECRET) != 0) { if (data.getInt(INDEX_UNIFIED_HAS_ANY_SECRET) != 0) {
// certify button
mActionCertify.setVisibility(View.GONE);
mActionCertifyDivider.setVisibility(View.GONE);
// edit button // edit button
mActionEdit.setVisibility(View.VISIBLE); mActionEdit.setVisibility(View.VISIBLE);
mActionEditDivider.setVisibility(View.VISIBLE); mActionEditDivider.setVisibility(View.VISIBLE);
} else { } else {
// certify button
mActionCertify.setVisibility(View.VISIBLE);
mActionCertifyDivider.setVisibility(View.VISIBLE);
// edit button // edit button
mActionEdit.setVisibility(View.GONE); mActionEdit.setVisibility(View.GONE);
mActionEditDivider.setVisibility(View.GONE); mActionEditDivider.setVisibility(View.GONE);

View File

@ -24,7 +24,6 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
@ -32,7 +31,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;

View File

@ -32,8 +32,7 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Highlighter; import org.sufficientlysecure.keychain.util.Highlighter;
import java.util.ArrayList; import java.util.ArrayList;
@ -120,13 +119,13 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
} }
// main user id // main user id
String userId = entry.userIds.get(0); String userId = entry.getUserIds().get(0);
String[] userIdSplit = PgpKeyHelper.splitUserId(userId); String[] userIdSplit = KeyRing.splitUserId(userId);
// name // name
if (userIdSplit[0] != null) { if (userIdSplit[0] != null) {
// show red user id if it is a secret key // show red user id if it is a secret key
if (entry.secretKey) { if (entry.isSecretKey()) {
holder.mainUserId.setText(mActivity.getString(R.string.secret_key) holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
+ " " + userIdSplit[0]); + " " + userIdSplit[0]);
holder.mainUserId.setTextColor(Color.RED); holder.mainUserId.setTextColor(Color.RED);
@ -147,30 +146,26 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
holder.mainUserIdRest.setVisibility(View.GONE); holder.mainUserIdRest.setVisibility(View.GONE);
} }
holder.keyId.setText(entry.keyIdHex); holder.keyId.setText(entry.getKeyIdHex());
if (entry.fingerprintHex != null) { // don't show full fingerprint on key import
holder.fingerprint.setVisibility(View.VISIBLE); holder.fingerprint.setVisibility(View.GONE);
holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerprintHex));
} else {
holder.fingerprint.setVisibility(View.GONE);
}
if (entry.bitStrength != 0 && entry.algorithm != null) { if (entry.getBitStrength() != 0 && entry.getAlgorithm() != null) {
holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm); holder.algorithm.setText("" + entry.getBitStrength() + "/" + entry.getAlgorithm());
holder.algorithm.setVisibility(View.VISIBLE); holder.algorithm.setVisibility(View.VISIBLE);
} else { } else {
holder.algorithm.setVisibility(View.INVISIBLE); holder.algorithm.setVisibility(View.INVISIBLE);
} }
if (entry.revoked) { if (entry.isRevoked()) {
holder.status.setVisibility(View.VISIBLE); holder.status.setVisibility(View.VISIBLE);
holder.status.setText(R.string.revoked); holder.status.setText(R.string.revoked);
} else { } else {
holder.status.setVisibility(View.GONE); holder.status.setVisibility(View.GONE);
} }
if (entry.userIds.size() == 1) { if (entry.getUserIds().size() == 1) {
holder.userIdsList.setVisibility(View.GONE); holder.userIdsList.setVisibility(View.GONE);
} else { } else {
holder.userIdsList.setVisibility(View.VISIBLE); holder.userIdsList.setVisibility(View.VISIBLE);
@ -178,7 +173,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
// clear view from holder // clear view from holder
holder.userIdsList.removeAllViews(); holder.userIdsList.removeAllViews();
Iterator<String> it = entry.userIds.iterator(); Iterator<String> it = entry.getUserIds().iterator();
// skip primary user id // skip primary user id
it.next(); it.next();
while (it.hasNext()) { while (it.hasNext()) {

View File

@ -22,8 +22,8 @@ import android.support.v4.content.AsyncTaskLoader;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver; import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -28,6 +28,7 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.util.Highlighter; import org.sufficientlysecure.keychain.util.Highlighter;
@ -112,7 +113,7 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
ViewHolderItem h = (ViewHolderItem) view.getTag(); ViewHolderItem h = (ViewHolderItem) view.getTag();
String userId = cursor.getString(mIndexUserId); String userId = cursor.getString(mIndexUserId);
String[] userIdSplit = PgpKeyHelper.splitUserId(userId); String[] userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit[0] != null) { if (userIdSplit[0] != null) {
h.mainUserId.setText(highlighter.highlight(userIdSplit[0])); h.mainUserId.setText(highlighter.highlight(userIdSplit[0]));

View File

@ -27,12 +27,11 @@ import android.widget.AdapterView;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.OtherHelper; import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
@ -112,7 +111,7 @@ public class ViewKeyUserIdsAdapter extends CursorAdapter implements AdapterView.
TextView vComment = (TextView) view.findViewById(R.id.comment); TextView vComment = (TextView) view.findViewById(R.id.comment);
ImageView vVerified = (ImageView) view.findViewById(R.id.certified); ImageView vVerified = (ImageView) view.findViewById(R.id.certified);
String[] userId = PgpKeyHelper.splitUserId(cursor.getString(mIndexUserId)); String[] userId = KeyRing.splitUserId(cursor.getString(mIndexUserId));
if (userId[0] != null) { if (userId[0] != null) {
vName.setText(userId[0]); vName.setText(userId[0]);
} else { } else {

View File

@ -199,7 +199,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
WrappedSecretKey unlockedSecretKey = null; WrappedSecretKey unlockedSecretKey = null;
for(WrappedSecretKey clickSecretKey : secretRing.iterator()) { for(WrappedSecretKey clickSecretKey : secretRing.secretKeyIterator()) {
try { try {
boolean unlocked = clickSecretKey.unlock(passphrase); boolean unlocked = clickSecretKey.unlock(passphrase);
if (unlocked) { if (unlocked) {

View File

@ -36,7 +36,7 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ContactHelper; import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.KeyRing;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -164,7 +164,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
mIsNewId = isNewId; mIsNewId = isNewId;
mOriginalID = userId; mOriginalID = userId;
String[] result = PgpKeyHelper.splitUserId(userId); String[] result = KeyRing.splitUserId(userId);
if (result[0] != null) { if (result[0] != null) {
mName.setText(result[0]); mName.setText(result[0]);
mOriginalName = result[0]; mOriginalName = result[0];