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 80ed02663..99ac09169 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -116,7 +116,7 @@ public class OpenPgpService extends Service { Intent signKeyIdIntent = getSignKeyMasterId(data); // NOTE: Fallback to return account settings (Old API) - if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) + if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS) == OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED) { return signKeyIdIntent; } @@ -237,8 +237,12 @@ public class OpenPgpService extends Service { KeyIdResult keyIdResult = mKeyIdExtractor.returnKeyIdsFromIntent(data, false, mApiPermissionHelper.getCurrentCallingPackage()); + boolean isDryRun = data.getBooleanExtra(OpenPgpApi.EXTRA_DRY_RUN, false); boolean isOpportunistic = data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION, false); KeyIdResultStatus keyIdResultStatus = keyIdResult.getStatus(); + if (isDryRun) { + return getDryRunStatusResult(keyIdResult); + } if (keyIdResult.hasKeySelectionPendingIntent()) { if ((keyIdResultStatus == KeyIdResultStatus.MISSING || keyIdResultStatus == KeyIdResultStatus.NO_KEYS || @@ -298,6 +302,42 @@ public class OpenPgpService extends Service { } } + @NonNull + private Intent getDryRunStatusResult(KeyIdResult keyIdResult) { + switch (keyIdResult.getStatus()) { + case MISSING: { + 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 result; + } + case NO_KEYS: + case NO_KEYS_ERROR: { + Intent result = new Intent(); + result.putExtra(OpenPgpApi.RESULT_ERROR, + new OpenPgpError(OpenPgpError.NO_USER_IDS, "empty recipient list")); + result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); + return result; + } + case DUPLICATE: { + Intent result = new Intent(); + result.putExtra(OpenPgpApi.RESULT_KEYS_CONFIRMED, false); + result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); + return result; + } + case OK: { + Intent result = new Intent(); + result.putExtra(OpenPgpApi.RESULT_KEYS_CONFIRMED, keyIdResult.isAllKeysConfirmed()); + result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); + return result; + } + default: { + throw new IllegalStateException("unhandled case!"); + } + } + } + private Intent decryptAndVerifyImpl(Intent data, InputStream inputStream, OutputStream outputStream, boolean decryptMetadataOnly, Progressable progressable) { try { diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index 5aa2affb7..f28cb9294 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit 5aa2affb752c066232bd7e7bb7c22739fa9f3526 +Subproject commit f28cb92944efbf56fa0582769a97b23c4272f6ac