summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2016-03-10 17:34:15 (GMT)
committer Vincent Breitmoser <valodim@mugenguild.com>2016-03-10 17:34:39 (GMT)
commit69e6e404bf77305c80511bbc904734655cd8865c (patch)
tree15056cb2900a34d99c1804828d5a5f1a65abb2fb
parent48867e89bda3a816f120798f436a2740304b1d97 (diff)
downloadopen-keychain-69e6e404bf77305c80511bbc904734655cd8865c.zip
open-keychain-69e6e404bf77305c80511bbc904734655cd8865c.tar.gz
open-keychain-69e6e404bf77305c80511bbc904734655cd8865c.tar.bz2
service: add opportunistic mode to encryption
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java46
m---------extern/openpgp-api-lib0
2 files changed, 26 insertions, 20 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 0e807e9..02d9ba6 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java
@@ -103,20 +103,20 @@ public class OpenPgpService extends Service {
}
private static class KeyIdResult {
- final Intent mRequiredUserInteraction;
+ final Intent mResultIntent;
final HashSet<Long> mKeyIds;
- KeyIdResult(Intent requiredUserInteraction) {
- mRequiredUserInteraction = requiredUserInteraction;
+ KeyIdResult(Intent resultIntent) {
+ mResultIntent = resultIntent;
mKeyIds = null;
}
KeyIdResult(HashSet<Long> keyIds) {
- mRequiredUserInteraction = null;
+ mResultIntent = null;
mKeyIds = keyIds;
}
}
- private KeyIdResult returnKeyIdsFromEmails(Intent data, String[] encryptionUserIds) {
+ private KeyIdResult returnKeyIdsFromEmails(Intent data, String[] encryptionUserIds, boolean isOpportunistic) {
boolean noUserIdsCheck = (encryptionUserIds == null || encryptionUserIds.length == 0);
boolean missingUserIdsCheck = false;
boolean duplicateUserIdsCheck = false;
@@ -159,9 +159,15 @@ public class OpenPgpService extends Service {
}
}
- if (noUserIdsCheck || missingUserIdsCheck || duplicateUserIdsCheck) {
- // allow the user to verify pub key selection
+ if (isOpportunistic && (noUserIdsCheck || missingUserIdsCheck)) {
+ Intent result = new Intent();
+ result.putExtra(OpenPgpApi.RESULT_ERROR,
+ new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "missing keys in opportunistic mode"));
+ result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
+ return new KeyIdResult(result);
+ }
+ if (noUserIdsCheck || missingUserIdsCheck || duplicateUserIdsCheck) {
// convert ArrayList<Long> to long[]
long[] keyIdsArray = getUnboxedLongArray(keyIds);
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
@@ -173,15 +179,14 @@ public class OpenPgpService extends Service {
result.putExtra(OpenPgpApi.RESULT_INTENT, pi);
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
return new KeyIdResult(result);
- } else {
- // everything was easy, we have exactly one key for every email
-
- if (keyIds.isEmpty()) {
- Log.e(Constants.TAG, "keyIdsArray.length == 0, should never happen!");
- }
+ }
- return new KeyIdResult(keyIds);
+ // everything was easy, we have exactly one key for every email
+ if (keyIds.isEmpty()) {
+ Log.e(Constants.TAG, "keyIdsArray.length == 0, should never happen!");
}
+
+ return new KeyIdResult(keyIds);
}
private Intent signImpl(Intent data, InputStream inputStream,
@@ -302,11 +307,12 @@ public class OpenPgpService extends Service {
// get key ids based on given user ids
if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS)) {
String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS);
+ boolean isOpportunistic = data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION, false);
// give params through to activity...
- KeyIdResult result = returnKeyIdsFromEmails(data, userIds);
+ KeyIdResult result = returnKeyIdsFromEmails(data, userIds, isOpportunistic);
- if (result.mRequiredUserInteraction != null) {
- return result.mRequiredUserInteraction;
+ if (result.mResultIntent != null) {
+ return result.mResultIntent;
}
encryptKeyIds.addAll(result.mKeyIds);
}
@@ -694,9 +700,9 @@ public class OpenPgpService extends Service {
} else {
// get key ids based on given user ids
String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS);
- KeyIdResult keyResult = returnKeyIdsFromEmails(data, userIds);
- if (keyResult.mRequiredUserInteraction != null) {
- return keyResult.mRequiredUserInteraction;
+ KeyIdResult keyResult = returnKeyIdsFromEmails(data, userIds, false);
+ if (keyResult.mResultIntent != null) {
+ return keyResult.mResultIntent;
}
if (keyResult.mKeyIds == null) {
diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib
-Subproject 8ca0f578bb843db7744dbd5724b32f6664b5c3d
+Subproject 710a0d8fe8d89cb9a1f247007000a7f49a29c52