diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp')
4 files changed, 68 insertions, 29 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index 4b6aaaa4d..7b022b694 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -238,19 +238,19 @@ public class PgpDecryptVerify { PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj; - // get master key id for this encryption key id long masterKeyId = 0; + PGPSecretKeyRing secretKeyRing = null; try { + // get master key id for this encryption key id masterKeyId = ProviderHelper.getMasterKeyId(mContext, KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(encData.getKeyID())) ); + // get actual keyring object based on master key id + secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, masterKeyId); } catch (ProviderHelper.NotFoundException e) { - Log.e(Constants.TAG, "key not found!", e); // continue with the next packet in the while loop continue; } - // get actual keyring object based on master key id - PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, masterKeyId); if (secretKeyRing == null) { // continue with the next packet in the while loop continue; @@ -390,8 +390,14 @@ public class PgpDecryptVerify { PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk; for (int i = 0; i < sigList.size(); ++i) { signature = sigList.get(i); - signatureKey = ProviderHelper - .getPGPPublicKeyRingWithKeyId(mContext, signature.getKeyID()).getPublicKey(); + + // TODO: rework this code, seems wonky! + try { + signatureKey = ProviderHelper + .getPGPPublicKeyRingWithKeyId(mContext, signature.getKeyID()).getPublicKey(); + } catch (ProviderHelper.NotFoundException e) { + Log.d(Constants.TAG, "key not found!"); + } if (signatureKeyId == 0) { signatureKeyId = signature.getKeyID(); } @@ -401,10 +407,12 @@ public class PgpDecryptVerify { signatureIndex = i; signatureKeyId = signature.getKeyID(); String userId = null; - PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId( - mContext, signatureKeyId); - if (signKeyRing != null) { + try { + PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId( + mContext, signatureKeyId); userId = PgpKeyHelper.getMainUserId(signKeyRing.getPublicKey()); + } catch (ProviderHelper.NotFoundException e) { + Log.d(Constants.TAG, "key not found!"); } signatureResult.setUserId(userId); break; @@ -598,7 +606,11 @@ public class PgpDecryptVerify { } // this one can't fail now (yay database constraints) - signatureKey = ProviderHelper.getPGPPublicKeyRing(mContext, (Long) data.get(KeyRings.MASTER_KEY_ID)).getPublicKey(); + try { + signatureKey = ProviderHelper.getPGPPublicKeyRing(mContext, (Long) data.get(KeyRings.MASTER_KEY_ID)).getPublicKey(); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + } signatureResult.setUserId((String) data.get(KeyRings.USER_ID)); break; @@ -664,11 +676,13 @@ public class PgpDecryptVerify { long signatureKeyId = signature.getKeyID(); boolean validKeyBinding = false; - PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(context, - signatureKeyId); PGPPublicKey mKey = null; - if (signKeyRing != null) { + try { + PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(context, + signatureKeyId); mKey = signKeyRing.getPublicKey(); + } catch (ProviderHelper.NotFoundException e) { + Log.d(Constants.TAG, "key not found"); } if (signature.getKeyID() != mKey.getKeyID()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 89a949922..854f065ec 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -194,11 +194,14 @@ public class PgpImportExport { arOutStream.setHeader("Version", PgpHelper.getFullVersion(mContext)); updateProgress(progress * 100 / masterKeyIdsSize, 100); - PGPPublicKeyRing publicKeyRing = - ProviderHelper.getPGPPublicKeyRing(mContext, pubKeyMasterId); - if (publicKeyRing != null) { + try { + PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRing(mContext, pubKeyMasterId); + publicKeyRing.encode(arOutStream); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: inform user? } if (mKeychainServiceListener.hasServiceStopped()) { @@ -217,12 +220,15 @@ public class PgpImportExport { arOutStream.setHeader("Version", PgpHelper.getFullVersion(mContext)); updateProgress(progress * 100 / masterKeyIdsSize, 100); - PGPSecretKeyRing secretKeyRing = - ProviderHelper.getPGPSecretKeyRing(mContext, secretKeyMasterId); - if (secretKeyRing != null) { + try { + PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, secretKeyMasterId); secretKeyRing.encode(arOutStream); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: inform user? } + if (mKeychainServiceListener.hasServiceStopped()) { arOutStream.close(); return null; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java index d4311367f..cd00f000c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyHelper.java @@ -201,9 +201,12 @@ public class PgpKeyHelper { } public static PGPPublicKey getEncryptPublicKey(Context context, long masterKeyId) { - PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(context, masterKeyId); - if (keyRing == null) { - Log.e(Constants.TAG, "keyRing is null!"); + PGPPublicKeyRing keyRing = null; + try { + keyRing = ProviderHelper.getPGPPublicKeyRing(context, masterKeyId); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: throw exception here! return null; } Vector<PGPPublicKey> encryptKeys = getUsableEncryptKeys(keyRing); @@ -215,8 +218,12 @@ public class PgpKeyHelper { } public static PGPSecretKey getCertificationKey(Context context, long masterKeyId) { - PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId); - if (keyRing == null) { + PGPSecretKeyRing keyRing = null; + try { + keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: throw exception here! return null; } Vector<PGPSecretKey> signingKeys = getUsableCertificationKeys(keyRing); @@ -227,8 +234,12 @@ public class PgpKeyHelper { } public static PGPSecretKey getSigningKey(Context context, long masterKeyId) { - PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId); - if (keyRing == null) { + PGPSecretKeyRing keyRing = null; + try { + keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: throw exception here! return null; } Vector<PGPSecretKey> signingKeys = getUsableSigningKeys(keyRing); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index 653d8bce4..53444f739 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -235,7 +235,11 @@ public class PgpSignEncrypt { PGPSecretKeyRing signingKeyRing = null; PGPPrivateKey signaturePrivateKey = null; if (enableSignature) { - signingKeyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId); + try { + signingKeyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId); + } catch (ProviderHelper.NotFoundException e) { + throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed)); + } signingKey = PgpKeyHelper.getSigningKey(mContext, mSignatureKeyId); if (signingKey == null) { throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed)); @@ -464,8 +468,12 @@ public class PgpSignEncrypt { throw new PgpGeneralException(mContext.getString(R.string.error_no_signature_key)); } - PGPSecretKeyRing signingKeyRing = - ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId); + PGPSecretKeyRing signingKeyRing; + try { + signingKeyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId); + } catch (ProviderHelper.NotFoundException e) { + throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed)); + } PGPSecretKey signingKey = PgpKeyHelper.getSigningKey(mContext, mSignatureKeyId); if (signingKey == null) { throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed)); |