aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-04-30 18:45:43 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2015-04-30 18:45:43 +0200
commit7c275fed9d93e0c45b2fb00d94bde702b44c8811 (patch)
treecf1141e16c47a6e7d15e2ccde93fb25d3d40ef7c /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
parentf623411fb635f106946960b5e6a05767f15fb598 (diff)
downloadopen-keychain-7c275fed9d93e0c45b2fb00d94bde702b44c8811.tar.gz
open-keychain-7c275fed9d93e0c45b2fb00d94bde702b44c8811.tar.bz2
open-keychain-7c275fed9d93e0c45b2fb00d94bde702b44c8811.zip
API: Allow selection of decryption keys when decryption fails
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java34
1 files changed, 28 insertions, 6 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
index c51edf59c..badc3c131 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
@@ -34,6 +34,7 @@ import org.openintents.openpgp.util.OpenPgpApi;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
+import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel;
import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
import org.sufficientlysecure.keychain.pgp.PgpConstants;
@@ -47,6 +48,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote.ui.RemoteServiceActivity;
+import org.sufficientlysecure.keychain.remote.ui.SelectAllowedKeysActivity;
import org.sufficientlysecure.keychain.remote.ui.SelectSignKeyIdActivity;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
@@ -205,6 +207,18 @@ public class OpenPgpService extends RemoteService {
PendingIntent.FLAG_CANCEL_CURRENT);
}
+ private PendingIntent getSelectAllowedKeysIntent(Intent data) {
+ // If signature is unknown we return an _additional_ PendingIntent
+ // to retrieve the missing key
+ Intent intent = new Intent(getBaseContext(), SelectAllowedKeysActivity.class);
+ intent.putExtra(SelectAllowedKeysActivity.EXTRA_SERVICE_INTENT, data);
+ intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(getCurrentCallingPackage()));
+
+ return PendingIntent.getActivity(getBaseContext(), 0,
+ intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ }
+
private PendingIntent getShowKeyPendingIntent(long masterKeyId) {
Intent intent = new Intent(getBaseContext(), ViewKeyActivity.class);
intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));
@@ -476,13 +490,12 @@ public class OpenPgpService extends RemoteService {
}
String currentPkg = getCurrentCallingPackage();
- Set<Long> allowedKeyIds;
+ Set<Long> allowedKeyIds = mProviderHelper.getAllowedKeyIdsForApp(
+ KeychainContract.ApiAllowedKeys.buildBaseUri(currentPkg));
+
if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) < 7) {
- allowedKeyIds = mProviderHelper.getAllKeyIdsForApp(
- ApiAccounts.buildBaseUri(currentPkg));
- } else {
- allowedKeyIds = mProviderHelper.getAllowedKeyIdsForApp(
- KeychainContract.ApiAllowedKeys.buildBaseUri(currentPkg));
+ allowedKeyIds.addAll(mProviderHelper.getAllKeyIdsForApp(
+ ApiAccounts.buildBaseUri(currentPkg)));
}
long inputLength = is.available();
@@ -575,6 +588,15 @@ public class OpenPgpService extends RemoteService {
return result;
} else {
LogEntryParcel errorMsg = pgpResult.getLog().getLast();
+
+ if (errorMsg.mType == OperationResult.LogType.MSG_DC_ERROR_NO_KEY) {
+ // allow user to select allowed keys
+ Intent result = new Intent();
+ result.putExtra(OpenPgpApi.RESULT_INTENT, getSelectAllowedKeysIntent(data));
+ result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
+ return result;
+ }
+
throw new Exception(getString(errorMsg.mType.getMsgId()));
}