encrypt to all encryption subkeys, rather than just the first
This commit is contained in:
@@ -27,6 +27,9 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
/** A generic wrapped PGPKeyRing object.
|
/** A generic wrapped PGPKeyRing object.
|
||||||
*
|
*
|
||||||
@@ -91,6 +94,16 @@ public abstract class CanonicalizedKeyRing extends KeyRing {
|
|||||||
return getRing().getPublicKey().isEncryptionKey();
|
return getRing().getPublicKey().isEncryptionKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Long> getEncryptIds() {
|
||||||
|
HashSet<Long> result = new HashSet<>();
|
||||||
|
for(CanonicalizedPublicKey key : publicKeyIterator()) {
|
||||||
|
if (key.canEncrypt() && key.isValid()) {
|
||||||
|
result.add(key.getKeyId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public long getEncryptId() throws PgpKeyNotFoundException {
|
public long getEncryptId() throws PgpKeyNotFoundException {
|
||||||
for(CanonicalizedPublicKey key : publicKeyIterator()) {
|
for(CanonicalizedPublicKey key : publicKeyIterator()) {
|
||||||
if (key.canEncrypt() && key.isValid()) {
|
if (key.canEncrypt() && key.isValid()) {
|
||||||
|
|||||||
@@ -62,19 +62,6 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing {
|
|||||||
return mRing;
|
return mRing;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Getter that returns the subkey that should be used for signing. */
|
|
||||||
CanonicalizedPublicKey getEncryptionSubKey() throws PgpKeyNotFoundException {
|
|
||||||
PGPPublicKey key = getRing().getPublicKey(getEncryptId());
|
|
||||||
if(key != null) {
|
|
||||||
CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key);
|
|
||||||
if(!cKey.canEncrypt()) {
|
|
||||||
throw new PgpKeyNotFoundException("key error");
|
|
||||||
}
|
|
||||||
return cKey;
|
|
||||||
}
|
|
||||||
throw new PgpKeyNotFoundException("no encryption key available");
|
|
||||||
}
|
|
||||||
|
|
||||||
public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() {
|
public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Iterator<PGPPublicKey> it = getRing().getPublicKeys();
|
final Iterator<PGPPublicKey> it = getRing().getPublicKeys();
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import java.security.SignatureException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -273,15 +274,19 @@ public class PgpSignEncryptOperation extends BaseOperation {
|
|||||||
try {
|
try {
|
||||||
CanonicalizedPublicKeyRing keyRing = mProviderHelper.getCanonicalizedPublicKeyRing(
|
CanonicalizedPublicKeyRing keyRing = mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||||
KeyRings.buildUnifiedKeyRingUri(id));
|
KeyRings.buildUnifiedKeyRingUri(id));
|
||||||
CanonicalizedPublicKey key = keyRing.getEncryptionSubKey();
|
Set<Long> encryptSubKeyIds = keyRing.getEncryptIds();
|
||||||
cPk.addMethod(key.getPubKeyEncryptionGenerator(input.isHiddenRecipients()));
|
for (Long subKeyId : encryptSubKeyIds) {
|
||||||
log.add(LogType.MSG_PSE_KEY_OK, indent + 1,
|
CanonicalizedPublicKey key = keyRing.getPublicKey(subKeyId);
|
||||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
cPk.addMethod(key.getPubKeyEncryptionGenerator(input.isHiddenRecipients()));
|
||||||
} catch (PgpKeyNotFoundException e) {
|
log.add(LogType.MSG_PSE_KEY_OK, indent + 1,
|
||||||
log.add(LogType.MSG_PSE_KEY_WARN, indent + 1,
|
KeyFormattingUtils.convertKeyIdToHex(id));
|
||||||
KeyFormattingUtils.convertKeyIdToHex(id));
|
}
|
||||||
if (input.isFailOnMissingEncryptionKeyIds()) {
|
if (encryptSubKeyIds.isEmpty()) {
|
||||||
return new PgpSignEncryptResult(PgpSignEncryptResult.RESULT_ERROR, log);
|
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) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
log.add(LogType.MSG_PSE_KEY_UNKNOWN, indent + 1,
|
log.add(LogType.MSG_PSE_KEY_UNKNOWN, indent + 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user