mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-03-03 02:42:00 -05:00
Handle new exceptions in KeychainIntentService
This commit is contained in:
parent
194523303f
commit
9b1a4a456a
@ -238,7 +238,6 @@ public class PgpDecryptVerify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (enc == null) {
|
if (enc == null) {
|
||||||
// throw new PgpGeneralException(mContext.getString(R.string.error_invalid_data));
|
|
||||||
throw new InvalidDataException();
|
throw new InvalidDataException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,8 +307,6 @@ public class PgpDecryptVerify {
|
|||||||
if (mPassphrase == null) {
|
if (mPassphrase == null) {
|
||||||
// returns "" if key has no passphrase
|
// returns "" if key has no passphrase
|
||||||
mPassphrase = mPassphraseCache.getCachedPassphrase(masterKeyId);
|
mPassphrase = mPassphraseCache.getCachedPassphrase(masterKeyId);
|
||||||
// mPassphrase =
|
|
||||||
// PassphraseCacheService.getCachedPassphrase(mContext, masterKeyId);
|
|
||||||
|
|
||||||
// if passphrase was not cached, return here
|
// if passphrase was not cached, return here
|
||||||
// indicating that a passphrase is missing!
|
// indicating that a passphrase is missing!
|
||||||
@ -368,12 +365,9 @@ public class PgpDecryptVerify {
|
|||||||
mPassphrase.toCharArray());
|
mPassphrase.toCharArray());
|
||||||
privateKey = secretKey.extractPrivateKey(keyDecryptor);
|
privateKey = secretKey.extractPrivateKey(keyDecryptor);
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
// throw new PGPException(mContext.getString(R.string.error_wrong_passphrase));
|
|
||||||
throw new WrongPassphraseException();
|
throw new WrongPassphraseException();
|
||||||
}
|
}
|
||||||
if (privateKey == null) {
|
if (privateKey == null) {
|
||||||
// throw new PgpGeneralException(
|
|
||||||
// mContext.getString(R.string.error_could_not_extract_private_key));
|
|
||||||
throw new KeyExtractionException();
|
throw new KeyExtractionException();
|
||||||
}
|
}
|
||||||
currentProgress += 5;
|
currentProgress += 5;
|
||||||
@ -388,7 +382,6 @@ public class PgpDecryptVerify {
|
|||||||
currentProgress += 5;
|
currentProgress += 5;
|
||||||
} else {
|
} else {
|
||||||
// no packet has been found where we have the corresponding secret key in our db
|
// no packet has been found where we have the corresponding secret key in our db
|
||||||
// throw new PgpGeneralException(mContext.getString(R.string.error_no_secret_key_found));
|
|
||||||
throw new NoSecretKeyException();
|
throw new NoSecretKeyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,7 +532,6 @@ public class PgpDecryptVerify {
|
|||||||
} else {
|
} else {
|
||||||
// failed
|
// failed
|
||||||
Log.d(Constants.TAG, "Integrity verification: failed!");
|
Log.d(Constants.TAG, "Integrity verification: failed!");
|
||||||
// throw new PgpGeneralException(mContext.getString(R.string.error_integrity_check_failed));
|
|
||||||
throw new IntegrityCheckFailedException();
|
throw new IntegrityCheckFailedException();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -597,7 +589,6 @@ public class PgpDecryptVerify {
|
|||||||
|
|
||||||
PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
|
PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
|
||||||
if (sigList == null) {
|
if (sigList == null) {
|
||||||
// throw new PgpGeneralException(mContext.getString(R.string.error_corrupt_data));
|
|
||||||
throw new InvalidDataException();
|
throw new InvalidDataException();
|
||||||
}
|
}
|
||||||
PGPSignature signature = null;
|
PGPSignature signature = null;
|
||||||
|
@ -287,17 +287,13 @@ public class PgpSignEncrypt {
|
|||||||
signingKeyRing = mProviderHelper.getPGPSecretKeyRing(mSignatureMasterKeyId);
|
signingKeyRing = mProviderHelper.getPGPSecretKeyRing(mSignatureMasterKeyId);
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
throw new NoSigningKeyException();
|
throw new NoSigningKeyException();
|
||||||
// throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
|
||||||
}
|
}
|
||||||
signingKey = PgpKeyHelper.getFirstSigningSubkey(signingKeyRing);
|
signingKey = PgpKeyHelper.getFirstSigningSubkey(signingKeyRing);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new NoSigningKeyException();
|
throw new NoSigningKeyException();
|
||||||
// throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSignaturePassphrase == null) {
|
if (mSignaturePassphrase == null) {
|
||||||
// throw new PgpGeneralException(
|
|
||||||
// mContext.getString(R.string.error_no_signature_passphrase));
|
|
||||||
throw new NoPassphraseException();
|
throw new NoPassphraseException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,8 +303,6 @@ public class PgpSignEncrypt {
|
|||||||
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(mSignaturePassphrase.toCharArray());
|
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(mSignaturePassphrase.toCharArray());
|
||||||
signaturePrivateKey = signingKey.extractPrivateKey(keyDecryptor);
|
signaturePrivateKey = signingKey.extractPrivateKey(keyDecryptor);
|
||||||
if (signaturePrivateKey == null) {
|
if (signaturePrivateKey == null) {
|
||||||
// throw new PgpGeneralException(
|
|
||||||
// mContext.getString(R.string.error_could_not_extract_private_key));
|
|
||||||
throw new KeyExtractionException();
|
throw new KeyExtractionException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -862,15 +862,36 @@ public class KeychainIntentService extends IntentService
|
|||||||
if (this.mIsCanceled) {
|
if (this.mIsCanceled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: Implement a better exception handling here
|
||||||
// contextualize the exception, if necessary
|
// contextualize the exception, if necessary
|
||||||
|
String message;
|
||||||
if (e instanceof PgpGeneralMsgIdException) {
|
if (e instanceof PgpGeneralMsgIdException) {
|
||||||
e = ((PgpGeneralMsgIdException) e).getContextualized(this);
|
e = ((PgpGeneralMsgIdException) e).getContextualized(this);
|
||||||
|
message = e.getMessage();
|
||||||
|
} else if (e instanceof PgpSignEncrypt.KeyExtractionException) {
|
||||||
|
message = getString(R.string.error_could_not_extract_private_key);
|
||||||
|
} else if (e instanceof PgpSignEncrypt.NoPassphraseException) {
|
||||||
|
message = getString(R.string.error_no_signature_passphrase);
|
||||||
|
} else if (e instanceof PgpSignEncrypt.NoSigningKeyException) {
|
||||||
|
message = getString(R.string.error_signature_failed);
|
||||||
|
} else if (e instanceof PgpDecryptVerify.InvalidDataException) {
|
||||||
|
message = getString(R.string.error_invalid_data);
|
||||||
|
} else if (e instanceof PgpDecryptVerify.KeyExtractionException) {
|
||||||
|
message = getString(R.string.error_could_not_extract_private_key);
|
||||||
|
} else if (e instanceof PgpDecryptVerify.WrongPassphraseException) {
|
||||||
|
message = getString(R.string.error_wrong_passphrase);
|
||||||
|
} else if (e instanceof PgpDecryptVerify.NoSecretKeyException) {
|
||||||
|
message = getString(R.string.error_no_secret_key_found);
|
||||||
|
} else if (e instanceof PgpDecryptVerify.IntegrityCheckFailedException) {
|
||||||
|
message = getString(R.string.error_integrity_check_failed);
|
||||||
|
} else {
|
||||||
|
message = e.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.e(Constants.TAG, "KeychainIntentService Exception: ", e);
|
Log.e(Constants.TAG, "KeychainIntentService Exception: ", e);
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putString(KeychainIntentServiceHandler.DATA_ERROR, e.getMessage());
|
data.putString(KeychainIntentServiceHandler.DATA_ERROR, message);
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_EXCEPTION, null, data);
|
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_EXCEPTION, null, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user