mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-14 21:05:09 -05:00
Revert "Replace PgpGeneralException with NotFoundException where appropriate"
This reverts commit 49b4ff6312
.
This commit is contained in:
parent
a13bcbbb5b
commit
b3f56c927b
@ -19,7 +19,7 @@
|
|||||||
package org.sufficientlysecure.keychain.pgp;
|
package org.sufficientlysecure.keychain.pgp;
|
||||||
|
|
||||||
import org.spongycastle.openpgp.PGPKeyRing;
|
import org.spongycastle.openpgp.PGPKeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -56,11 +56,11 @@ public abstract class CanonicalizedKeyRing extends KeyRing {
|
|||||||
return getRing().getPublicKey().getFingerprint();
|
return getRing().getPublicKey().getFingerprint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimaryUserId() throws NotFoundException {
|
public String getPrimaryUserId() throws PgpGeneralException {
|
||||||
return getPublicKey().getPrimaryUserId();
|
return getPublicKey().getPrimaryUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimaryUserIdWithFallback() throws NotFoundException {
|
public String getPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||||
return getPublicKey().getPrimaryUserIdWithFallback();
|
return getPublicKey().getPrimaryUserIdWithFallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,24 +87,24 @@ public abstract class CanonicalizedKeyRing extends KeyRing {
|
|||||||
return creationDate.after(now) || (expiryDate != null && expiryDate.before(now));
|
return creationDate.after(now) || (expiryDate != null && expiryDate.before(now));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCertify() throws NotFoundException {
|
public boolean canCertify() throws PgpGeneralException {
|
||||||
return getRing().getPublicKey().isEncryptionKey();
|
return getRing().getPublicKey().isEncryptionKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getEncryptId() throws NotFoundException {
|
public long getEncryptId() throws PgpGeneralException {
|
||||||
for(CanonicalizedPublicKey key : publicKeyIterator()) {
|
for(CanonicalizedPublicKey key : publicKeyIterator()) {
|
||||||
if (key.canEncrypt() && key.isValid()) {
|
if (key.canEncrypt() && key.isValid()) {
|
||||||
return key.getKeyId();
|
return key.getKeyId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new NotFoundException("No valid encryption key found!");
|
throw new PgpGeneralException("No valid encryption key found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEncrypt() throws NotFoundException {
|
public boolean hasEncrypt() throws PgpGeneralException {
|
||||||
try {
|
try {
|
||||||
getEncryptId();
|
getEncryptId();
|
||||||
return true;
|
return true;
|
||||||
} catch(NotFoundException e) {
|
} catch(PgpGeneralException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ package org.sufficientlysecure.keychain.pgp;
|
|||||||
import org.spongycastle.openpgp.PGPObjectFactory;
|
import org.spongycastle.openpgp.PGPObjectFactory;
|
||||||
import org.spongycastle.openpgp.PGPPublicKey;
|
import org.spongycastle.openpgp.PGPPublicKey;
|
||||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -61,16 +61,16 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Getter that returns the subkey that should be used for signing. */
|
/** Getter that returns the subkey that should be used for signing. */
|
||||||
CanonicalizedPublicKey getEncryptionSubKey() throws NotFoundException {
|
CanonicalizedPublicKey getEncryptionSubKey() throws PgpGeneralException {
|
||||||
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
||||||
if (key != null) {
|
if(key != null) {
|
||||||
CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key);
|
CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key);
|
||||||
if(!cKey.canEncrypt()) {
|
if(!cKey.canEncrypt()) {
|
||||||
throw new NotFoundException("key error");
|
throw new PgpGeneralException("key error");
|
||||||
}
|
}
|
||||||
return cKey;
|
return cKey;
|
||||||
}
|
}
|
||||||
throw new NotFoundException("no encryption key available");
|
throw new PgpGeneralException("no encryption key available");
|
||||||
}
|
}
|
||||||
|
|
||||||
public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() {
|
public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() {
|
||||||
|
@ -41,7 +41,6 @@ import org.spongycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
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.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
@ -255,10 +254,8 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey {
|
|||||||
spGen.setSignatureCreationTime(false, nfcCreationTimestamp);
|
spGen.setSignatureCreationTime(false, nfcCreationTimestamp);
|
||||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||||
return signatureGenerator;
|
return signatureGenerator;
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
|
||||||
// TODO: simply throw PGPException!
|
|
||||||
throw new PgpGeneralException("Error initializing signature!", e);
|
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
|
// TODO: simply throw PGPException!
|
||||||
throw new PgpGeneralException("Error initializing signature!", e);
|
throw new PgpGeneralException("Error initializing signature!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ package org.sufficientlysecure.keychain.pgp;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -38,25 +38,25 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
public abstract class KeyRing {
|
public abstract class KeyRing {
|
||||||
|
|
||||||
abstract public long getMasterKeyId() throws NotFoundException;
|
abstract public long getMasterKeyId() throws PgpGeneralException;
|
||||||
|
|
||||||
abstract public String getPrimaryUserId() throws NotFoundException;
|
abstract public String getPrimaryUserId() throws PgpGeneralException;
|
||||||
|
|
||||||
abstract public String getPrimaryUserIdWithFallback() throws NotFoundException;
|
abstract public String getPrimaryUserIdWithFallback() throws PgpGeneralException;
|
||||||
|
|
||||||
public String[] getSplitPrimaryUserIdWithFallback() throws NotFoundException {
|
public String[] getSplitPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||||
return splitUserId(getPrimaryUserIdWithFallback());
|
return splitUserId(getPrimaryUserIdWithFallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public boolean isRevoked() throws NotFoundException;
|
abstract public boolean isRevoked() throws PgpGeneralException;
|
||||||
|
|
||||||
abstract public boolean canCertify() throws NotFoundException;
|
abstract public boolean canCertify() throws PgpGeneralException;
|
||||||
|
|
||||||
abstract public long getEncryptId() throws NotFoundException;
|
abstract public long getEncryptId() throws PgpGeneralException;
|
||||||
|
|
||||||
abstract public boolean hasEncrypt() throws NotFoundException;
|
abstract public boolean hasEncrypt() throws PgpGeneralException;
|
||||||
|
|
||||||
abstract public int getVerified() throws NotFoundException;
|
abstract public int getVerified() throws PgpGeneralException;
|
||||||
|
|
||||||
private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");
|
private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$");
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.pgp;
|
|||||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -97,7 +96,7 @@ public class OpenPgpSignatureResultBuilder {
|
|||||||
setKeyId(signingRing.getMasterKeyId());
|
setKeyId(signingRing.getMasterKeyId());
|
||||||
try {
|
try {
|
||||||
setPrimaryUserId(signingRing.getPrimaryUserIdWithFallback());
|
setPrimaryUserId(signingRing.getPrimaryUserIdWithFallback());
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.d(Constants.TAG, "No primary user id in keyring with master key id " + signingRing.getMasterKeyId());
|
Log.d(Constants.TAG, "No primary user id in keyring with master key id " + signingRing.getMasterKeyId());
|
||||||
}
|
}
|
||||||
setSignatureKeyCertified(signingRing.getVerified() > 0);
|
setSignatureKeyCertified(signingRing.getVerified() > 0);
|
||||||
|
@ -385,22 +385,19 @@ public class PgpSignEncrypt {
|
|||||||
|
|
||||||
// Asymmetric encryption
|
// Asymmetric encryption
|
||||||
for (long id : mEncryptionMasterKeyIds) {
|
for (long id : mEncryptionMasterKeyIds) {
|
||||||
CanonicalizedPublicKeyRing keyRing = null;
|
|
||||||
try {
|
try {
|
||||||
keyRing = mProviderHelper.getCanonicalizedPublicKeyRing(
|
CanonicalizedPublicKeyRing keyRing = mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingUri(id));
|
KeyRings.buildUnifiedKeyRingUri(id));
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
|
||||||
log.add(LogType.MSG_SE_KEY_UNKNOWN, indent + 1,
|
|
||||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
CanonicalizedPublicKey key = keyRing.getEncryptionSubKey();
|
CanonicalizedPublicKey key = keyRing.getEncryptionSubKey();
|
||||||
cPk.addMethod(key.getPubKeyEncryptionGenerator());
|
cPk.addMethod(key.getPubKeyEncryptionGenerator());
|
||||||
log.add(LogType.MSG_SE_KEY_OK, indent + 1,
|
log.add(LogType.MSG_SE_KEY_OK, indent + 1,
|
||||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
KeyFormattingUtils.convertKeyIdToHex(id));
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
log.add(LogType.MSG_SE_KEY_WARN, indent + 1,
|
log.add(LogType.MSG_SE_KEY_WARN, indent + 1,
|
||||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
KeyFormattingUtils.convertKeyIdToHex(id));
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
log.add(LogType.MSG_SE_KEY_UNKNOWN, indent + 1,
|
||||||
|
KeyFormattingUtils.convertKeyIdToHex(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,21 +30,21 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
|
|||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
/**
|
/** This implementation of KeyRing provides a cached view of PublicKeyRing
|
||||||
* This implementation of KeyRing provides a cached view of PublicKeyRing
|
|
||||||
* objects based on database queries exclusively.
|
* objects based on database queries exclusively.
|
||||||
* <p/>
|
*
|
||||||
* This class should be used where only few points of data but no actual
|
* This class should be used where only few points of data but no actual
|
||||||
* cryptographic operations are required about a PublicKeyRing which is already
|
* cryptographic operations are required about a PublicKeyRing which is already
|
||||||
* in the database. This happens commonly in UI code, where parsing of a PGP
|
* in the database. This happens commonly in UI code, where parsing of a PGP
|
||||||
* key for examination would be a very expensive operation.
|
* key for examination would be a very expensive operation.
|
||||||
* <p/>
|
*
|
||||||
* Each getter method is implemented using a more or less expensive database
|
* Each getter method is implemented using a more or less expensive database
|
||||||
* query, while object construction is (almost) free. A common pattern is
|
* query, while object construction is (almost) free. A common pattern is
|
||||||
* mProviderHelper.getCachedKeyRing(uri).getterMethod()
|
* mProviderHelper.getCachedKeyRing(uri).getterMethod()
|
||||||
* <p/>
|
*
|
||||||
* TODO Ensure that the values returned here always match the ones returned by
|
* TODO Ensure that the values returned here always match the ones returned by
|
||||||
* the parsed KeyRing!
|
* the parsed KeyRing!
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class CachedPublicKeyRing extends KeyRing {
|
public class CachedPublicKeyRing extends KeyRing {
|
||||||
|
|
||||||
@ -57,17 +57,21 @@ public class CachedPublicKeyRing extends KeyRing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getMasterKeyId() throws NotFoundException {
|
public long getMasterKeyId() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER);
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
return (Long) data;
|
KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
|
return (Long) data;
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the master key id related to a given query. The id will either be extracted from the
|
* Find the master key id related to a given query. The id will either be extracted from the
|
||||||
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
||||||
*/
|
*/
|
||||||
public long extractOrGetMasterKeyId() throws NotFoundException {
|
public long extractOrGetMasterKeyId() throws PgpGeneralException {
|
||||||
// try extracting from the uri first
|
// try extracting from the uri first
|
||||||
String firstSegment = mUri.getPathSegments().get(1);
|
String firstSegment = mUri.getPathSegments().get(1);
|
||||||
if (!firstSegment.equals("find")) try {
|
if (!firstSegment.equals("find")) try {
|
||||||
@ -79,82 +83,114 @@ public class CachedPublicKeyRing extends KeyRing {
|
|||||||
return getMasterKeyId();
|
return getMasterKeyId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getFingerprint() throws NotFoundException {
|
public byte[] getFingerprint() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
return (byte[]) data;
|
KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
||||||
|
return (byte[]) data;
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryUserId() throws NotFoundException {
|
public String getPrimaryUserId() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.USER_ID,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_STRING);
|
KeychainContract.KeyRings.USER_ID,
|
||||||
return (String) data;
|
ProviderHelper.FIELD_TYPE_STRING);
|
||||||
|
return (String) data;
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimaryUserIdWithFallback() throws NotFoundException {
|
public String getPrimaryUserIdWithFallback() throws PgpGeneralException {
|
||||||
return getPrimaryUserId();
|
return getPrimaryUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRevoked() throws NotFoundException {
|
public boolean isRevoked() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.IS_REVOKED,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
KeychainContract.KeyRings.IS_REVOKED,
|
||||||
return (Long) data > 0;
|
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
|
return (Long) data > 0;
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canCertify() throws NotFoundException {
|
public boolean canCertify() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.HAS_CERTIFY,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_NULL);
|
KeychainContract.KeyRings.HAS_CERTIFY,
|
||||||
return !((Boolean) data);
|
ProviderHelper.FIELD_TYPE_NULL);
|
||||||
|
return !((Boolean) data);
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEncryptId() throws NotFoundException {
|
public long getEncryptId() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeyRings.HAS_ENCRYPT,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
KeyRings.HAS_ENCRYPT,
|
||||||
return (Long) data;
|
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
|
return (Long) data;
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasEncrypt() throws NotFoundException {
|
public boolean hasEncrypt() throws PgpGeneralException {
|
||||||
return getEncryptId() != 0;
|
return getEncryptId() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the key id which should be used for signing.
|
||||||
* Returns the key id which should be used for signing.
|
*
|
||||||
* <p/>
|
|
||||||
* This method returns keys which are actually available (ie. secret available, and not stripped,
|
* This method returns keys which are actually available (ie. secret available, and not stripped,
|
||||||
* revoked, or expired), hence only works on keyrings where a secret key is available!
|
* revoked, or expired), hence only works on keyrings where a secret key is available!
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public long getSecretSignId() throws NotFoundException {
|
public long getSecretSignId() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeyRings.HAS_SIGN,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
KeyRings.HAS_SIGN,
|
||||||
return (Long) data;
|
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
|
return (Long) data;
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getVerified() throws NotFoundException {
|
public int getVerified() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.VERIFIED,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
KeychainContract.KeyRings.VERIFIED,
|
||||||
return (Integer) data;
|
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
|
return (Integer) data;
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAnySecret() throws NotFoundException {
|
public boolean hasAnySecret() throws PgpGeneralException {
|
||||||
Object data = mProviderHelper.getGenericData(mUri,
|
try {
|
||||||
KeychainContract.KeyRings.HAS_ANY_SECRET,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
KeychainContract.KeyRings.HAS_ANY_SECRET,
|
||||||
return (Long) data > 0;
|
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
|
return (Long) data > 0;
|
||||||
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cursor getSubkeys() throws NotFoundException {
|
private Cursor getSubkeys() throws PgpGeneralException {
|
||||||
Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId());
|
Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId());
|
||||||
return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null);
|
return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
@ -272,24 +272,23 @@ public class OpenPgpService extends RemoteService {
|
|||||||
InputData inputData = new InputData(is, inputLength);
|
InputData inputData = new InputData(is, inputLength);
|
||||||
|
|
||||||
// Find the appropriate subkey to sign with
|
// Find the appropriate subkey to sign with
|
||||||
final long sigSubKeyId;
|
CachedPublicKeyRing signingRing =
|
||||||
try {
|
new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId());
|
||||||
CachedPublicKeyRing signingRing =
|
final long sigSubKeyId = signingRing.getSecretSignId();
|
||||||
new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId());
|
|
||||||
sigSubKeyId = signingRing.getSecretSignId();
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
// secret key that is set for this account is deleted?
|
|
||||||
// show account config again!
|
|
||||||
return getCreateAccountIntent(data, getAccountName(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get passphrase from cache, if key has "no" passphrase, this returns an empty String
|
// get passphrase from cache, if key has "no" passphrase, this returns an empty String
|
||||||
String passphrase;
|
String passphrase;
|
||||||
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
|
||||||
passphrase = data.getStringExtra(OpenPgpApi.EXTRA_PASSPHRASE);
|
passphrase = data.getStringExtra(OpenPgpApi.EXTRA_PASSPHRASE);
|
||||||
} else {
|
} else {
|
||||||
passphrase = PassphraseCacheService.getCachedPassphrase(getContext(),
|
try {
|
||||||
accSettings.getKeyId(), sigSubKeyId);
|
passphrase = PassphraseCacheService.getCachedPassphrase(getContext(),
|
||||||
|
accSettings.getKeyId(), sigSubKeyId);
|
||||||
|
} catch (PassphraseCacheService.KeyNotFoundException e) {
|
||||||
|
// secret key that is set for this account is deleted?
|
||||||
|
// show account config again!
|
||||||
|
return getCreateAccountIntent(data, getAccountName(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (passphrase == null) {
|
if (passphrase == null) {
|
||||||
// get PendingIntent for passphrase input, add it to given params and return to client
|
// get PendingIntent for passphrase input, add it to given params and return to client
|
||||||
|
@ -27,12 +27,13 @@ import android.view.View;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.ActionBarHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.remote.AccountSettings;
|
import org.sufficientlysecure.keychain.remote.AccountSettings;
|
||||||
import org.sufficientlysecure.keychain.service.results.OperationResult;
|
import org.sufficientlysecure.keychain.service.results.OperationResult;
|
||||||
|
import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel;
|
||||||
import org.sufficientlysecure.keychain.service.results.OperationResult.LogType;
|
import org.sufficientlysecure.keychain.service.results.OperationResult.LogType;
|
||||||
import org.sufficientlysecure.keychain.service.results.SingletonResult;
|
import org.sufficientlysecure.keychain.service.results.SingletonResult;
|
||||||
import org.sufficientlysecure.keychain.ui.util.ActionBarHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class AccountSettingsActivity extends ActionBarActivity {
|
public class AccountSettingsActivity extends ActionBarActivity {
|
||||||
|
@ -67,7 +67,7 @@ public class AccountSettingsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAccSettings(AccountSettings accountSettings) {
|
public void setAccSettings(AccountSettings accountSettings) {
|
||||||
mAccSettings = accountSettings;
|
this.mAccSettings = accountSettings;
|
||||||
|
|
||||||
mAccNameView.setText(accountSettings.getAccountName());
|
mAccNameView.setText(accountSettings.getAccountName());
|
||||||
mSelectKeySpinner.setSelectedKeyId(accountSettings.getKeyId());
|
mSelectKeySpinner.setSelectedKeyId(accountSettings.getKeyId());
|
||||||
|
@ -719,7 +719,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
builder.setNfcState(nfcHash, nfcTimestamp);
|
builder.setNfcState(nfcHash, nfcTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
// encrypt-only
|
// encrypt-only
|
||||||
// TODO Just silently drop the requested signature? Shouldn't we throw here?
|
// TODO Just silently drop the requested signature? Shouldn't we throw here?
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,9 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND);
|
finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
|
} catch (PgpGeneralException e) {
|
||||||
|
finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -139,7 +139,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
setSignatureKeyId(keyring.getMasterKeyId());
|
setSignatureKeyId(keyring.getMasterKeyId());
|
||||||
mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
|
mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
|
||||||
}
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(
|
CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(preselectedId));
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(preselectedId));
|
||||||
mEncryptKeyView.addObject(mEncryptKeyView.new EncryptionKey(ring));
|
mEncryptKeyView.addObject(mEncryptKeyView.new EncryptionKey(ring));
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class MultiCertifyKeyFragment extends LoaderFragment
|
|||||||
if (key.canCertify()) {
|
if (key.canCertify()) {
|
||||||
mCertifyKeySpinner.setSelectedKeyId(certifyKeyId);
|
mCertifyKeySpinner.setSelectedKeyId(certifyKeyId);
|
||||||
}
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "certify certify check failed", e);
|
Log.e(Constants.TAG, "certify certify check failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
// the catch clause doesn't return.
|
// the catch clause doesn't return.
|
||||||
try {
|
try {
|
||||||
userId = mSecretRing.getPrimaryUserIdWithFallback();
|
userId = mSecretRing.getPrimaryUserIdWithFallback();
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
userId = null;
|
userId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
||||||
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
|
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
|
||||||
mSecretRing.getPrimaryUserIdWithFallback());
|
mSecretRing.getPrimaryUserIdWithFallback());
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "adding of a passphrase failed", e);
|
Log.e(Constants.TAG, "adding of a passphrase failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ public class ViewCertActivity extends ActionBarActivity
|
|||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
|
||||||
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
|
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
|
||||||
startActivity(viewIntent);
|
startActivity(viewIntent);
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
// TODO notify user of this, maybe offer download?
|
// TODO notify user of this, maybe offer download?
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
// used instead of startActivity set actionbar based on callingPackage
|
// used instead of startActivity set actionbar based on callingPackage
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
} catch (NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
// the catch clause doesn't return.
|
// the catch clause doesn't return.
|
||||||
try {
|
try {
|
||||||
userId = mSecretRing.getPrimaryUserIdWithFallback();
|
userId = mSecretRing.getPrimaryUserIdWithFallback();
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
userId = null;
|
userId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +308,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
||||||
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
|
mSecretRing.getMasterKeyId(), mSubKeyId, passphrase,
|
||||||
mSecretRing.getPrimaryUserIdWithFallback());
|
mSecretRing.getPrimaryUserIdWithFallback());
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "adding of a passphrase failed", e);
|
Log.e(Constants.TAG, "adding of a passphrase failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ import com.tokenautocomplete.TokenCompleteTextView;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.ContactHelper;
|
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
@ -199,7 +198,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EncryptionKey(CachedPublicKeyRing ring) throws ProviderHelper.NotFoundException {
|
public EncryptionKey(CachedPublicKeyRing ring) throws PgpGeneralException {
|
||||||
this(ring.getPrimaryUserId(), ring.extractOrGetMasterKeyId(),
|
this(ring.getPrimaryUserId(), ring.extractOrGetMasterKeyId(),
|
||||||
KeyFormattingUtils.convertFingerprintToHex(ring.getFingerprint()));
|
KeyFormattingUtils.convertFingerprintToHex(ring.getFingerprint()));
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public class ExportHelper {
|
|||||||
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
||||||
new long[]{ masterKeyId });
|
new long[]{ masterKeyId });
|
||||||
deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
|
deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user