mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-17 21:02:17 -05:00
Handle new exceptions in remote service
This commit is contained in:
parent
ad6ac28782
commit
004d4d5a97
@ -30,6 +30,7 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
|
|||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
import org.spongycastle.util.Arrays;
|
import org.spongycastle.util.Arrays;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
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;
|
||||||
@ -178,7 +179,17 @@ public class OpenPgpService extends RemoteService {
|
|||||||
// TODO: currently always assume cleartext input, no sign-only of binary currently!
|
// TODO: currently always assume cleartext input, no sign-only of binary currently!
|
||||||
builder.cleartextInput(true);
|
builder.cleartextInput(true);
|
||||||
|
|
||||||
|
try {
|
||||||
builder.build().execute();
|
builder.build().execute();
|
||||||
|
|
||||||
|
// throw exceptions upwards to client with meaningful messages
|
||||||
|
} catch (PgpSignEncrypt.KeyExtractionException e) {
|
||||||
|
throw new Exception(getString(R.string.error_could_not_extract_private_key));
|
||||||
|
} catch (PgpSignEncrypt.NoPassphraseException e) {
|
||||||
|
throw new Exception(getString(R.string.error_no_signature_passphrase));
|
||||||
|
} catch (PgpSignEncrypt.NoSigningKeyException e) {
|
||||||
|
throw new Exception(getString(R.string.error_signature_failed));
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
os.close();
|
os.close();
|
||||||
@ -270,8 +281,19 @@ public class OpenPgpService extends RemoteService {
|
|||||||
// encrypt only
|
// encrypt only
|
||||||
builder.signatureMasterKeyId(Constants.key.none);
|
builder.signatureMasterKeyId(Constants.key.none);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// execute PGP operation!
|
// execute PGP operation!
|
||||||
builder.build().execute();
|
builder.build().execute();
|
||||||
|
|
||||||
|
// throw exceptions upwards to client with meaningful messages
|
||||||
|
} catch (PgpSignEncrypt.KeyExtractionException e) {
|
||||||
|
throw new Exception(getString(R.string.error_could_not_extract_private_key));
|
||||||
|
} catch (PgpSignEncrypt.NoPassphraseException e) {
|
||||||
|
throw new Exception(getString(R.string.error_no_signature_passphrase));
|
||||||
|
} catch (PgpSignEncrypt.NoSigningKeyException e) {
|
||||||
|
throw new Exception(getString(R.string.error_signature_failed));
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
is.close();
|
is.close();
|
||||||
os.close();
|
os.close();
|
||||||
@ -318,8 +340,23 @@ public class OpenPgpService extends RemoteService {
|
|||||||
// accounts of this app
|
// accounts of this app
|
||||||
.passphrase(passphrase);
|
.passphrase(passphrase);
|
||||||
|
|
||||||
|
PgpDecryptVerifyResult decryptVerifyResult;
|
||||||
|
try {
|
||||||
// TODO: currently does not support binary signed-only content
|
// TODO: currently does not support binary signed-only content
|
||||||
PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute();
|
decryptVerifyResult = builder.build().execute();
|
||||||
|
|
||||||
|
// throw exceptions upwards to client with meaningful messages
|
||||||
|
} catch (PgpDecryptVerify.InvalidDataException e) {
|
||||||
|
throw new Exception(getString(R.string.error_invalid_data));
|
||||||
|
} catch (PgpDecryptVerify.KeyExtractionException e) {
|
||||||
|
throw new Exception(getString(R.string.error_could_not_extract_private_key));
|
||||||
|
} catch (PgpDecryptVerify.WrongPassphraseException e) {
|
||||||
|
throw new Exception(getString(R.string.error_wrong_passphrase));
|
||||||
|
} catch (PgpDecryptVerify.NoSecretKeyException e) {
|
||||||
|
throw new Exception(getString(R.string.error_no_secret_key_found));
|
||||||
|
} catch (PgpDecryptVerify.IntegrityCheckFailedException e) {
|
||||||
|
throw new Exception(getString(R.string.error_integrity_check_failed));
|
||||||
|
}
|
||||||
|
|
||||||
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
|
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
|
||||||
// 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
|
||||||
@ -333,6 +370,8 @@ public class OpenPgpService extends RemoteService {
|
|||||||
|
|
||||||
OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult();
|
OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult();
|
||||||
if (signatureResult != null) {
|
if (signatureResult != null) {
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult);
|
||||||
|
|
||||||
if (signatureResult.getStatus() == OpenPgpSignatureResult.SIGNATURE_UNKNOWN_PUB_KEY) {
|
if (signatureResult.getStatus() == OpenPgpSignatureResult.SIGNATURE_UNKNOWN_PUB_KEY) {
|
||||||
// If signature is unknown we return an _additional_ PendingIntent
|
// If signature is unknown we return an _additional_ PendingIntent
|
||||||
// to retrieve the missing key
|
// to retrieve the missing key
|
||||||
@ -347,8 +386,6 @@ public class OpenPgpService extends RemoteService {
|
|||||||
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_INTENT, pi);
|
result.putExtra(OpenPgpApi.RESULT_INTENT, pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_SIGNATURE, signatureResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
Reference in New Issue
Block a user