From 7648602fc876df3ec5827f3bba1ebbb8ae92eaae Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 6 Jul 2015 02:18:34 +0200 Subject: encrypt to all encryption subkeys, rather than just the first --- .../keychain/pgp/PgpSignEncryptOperation.java | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java index c2349d80b..a411292af 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java @@ -66,6 +66,7 @@ import java.security.SignatureException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -273,15 +274,19 @@ public class PgpSignEncryptOperation extends BaseOperation { try { CanonicalizedPublicKeyRing keyRing = mProviderHelper.getCanonicalizedPublicKeyRing( KeyRings.buildUnifiedKeyRingUri(id)); - CanonicalizedPublicKey key = keyRing.getEncryptionSubKey(); - cPk.addMethod(key.getPubKeyEncryptionGenerator(input.isHiddenRecipients())); - log.add(LogType.MSG_PSE_KEY_OK, indent + 1, - KeyFormattingUtils.convertKeyIdToHex(id)); - } catch (PgpKeyNotFoundException e) { - log.add(LogType.MSG_PSE_KEY_WARN, indent + 1, - KeyFormattingUtils.convertKeyIdToHex(id)); - if (input.isFailOnMissingEncryptionKeyIds()) { - return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log); + Set encryptSubKeyIds = keyRing.getEncryptIds(); + for (Long subKeyId : encryptSubKeyIds) { + CanonicalizedPublicKey key = keyRing.getPublicKey(subKeyId); + cPk.addMethod(key.getPubKeyEncryptionGenerator(input.isHiddenRecipients())); + log.add(LogType.MSG_PSE_KEY_OK, indent + 1, + KeyFormattingUtils.convertKeyIdToHex(id)); + } + if (encryptSubKeyIds.isEmpty()) { + log.add(LogType.MSG_PSE_KEY_WARN, indent + 1, + KeyFormattingUtils.convertKeyIdToHex(id)); + if (input.isFailOnMissingEncryptionKeyIds()) { + return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log); + } } } catch (ProviderHelper.NotFoundException e) { log.add(LogType.MSG_PSE_KEY_UNKNOWN, indent + 1, -- cgit v1.2.3