1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-15 17:02:06 +01:00

Allow hidden recipients using wildcard keyIDs

This commit is contained in:
Paul Schaub 2023-05-03 14:19:27 +02:00
parent 7234b42144
commit 8762eeeea6
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -20,6 +20,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator; import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator; import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
import org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator;
import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.EncryptionPurpose;
import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.exception.KeyException; import org.pgpainless.exception.KeyException;
@ -182,7 +183,7 @@ public class EncryptionOptions {
SubkeyIdentifier keyId = new SubkeyIdentifier(key, encryptionSubkey.getKeyID()); SubkeyIdentifier keyId = new SubkeyIdentifier(key, encryptionSubkey.getKeyID());
keyRingInfo.put(keyId, info); keyRingInfo.put(keyId, info);
keyViews.put(keyId, new KeyAccessor.ViaUserId(info, keyId, userId.toString())); keyViews.put(keyId, new KeyAccessor.ViaUserId(info, keyId, userId.toString()));
addRecipientKey(key, encryptionSubkey); addRecipientKey(key, encryptionSubkey, false);
} }
return this; return this;
@ -207,6 +208,18 @@ public class EncryptionOptions {
*/ */
public EncryptionOptions addRecipient(@Nonnull PGPPublicKeyRing key, public EncryptionOptions addRecipient(@Nonnull PGPPublicKeyRing key,
@Nonnull EncryptionKeySelector encryptionKeySelectionStrategy) { @Nonnull EncryptionKeySelector encryptionKeySelectionStrategy) {
return addAsRecipient(key, encryptionKeySelectionStrategy, false);
}
public EncryptionOptions addHiddenRecipient(@Nonnull PGPPublicKeyRing key) {
return addHiddenRecipient(key, encryptionKeySelector);
}
public EncryptionOptions addHiddenRecipient(PGPPublicKeyRing key, EncryptionKeySelector encryptionKeySelectionStrategy) {
return addAsRecipient(key, encryptionKeySelectionStrategy, true);
}
private EncryptionOptions addAsRecipient(PGPPublicKeyRing key, EncryptionKeySelector encryptionKeySelectionStrategy, boolean wildcardKeyId) {
Date evaluationDate = new Date(); Date evaluationDate = new Date();
KeyRingInfo info; KeyRingInfo info;
info = new KeyRingInfo(key, evaluationDate); info = new KeyRingInfo(key, evaluationDate);
@ -231,17 +244,19 @@ public class EncryptionOptions {
SubkeyIdentifier keyId = new SubkeyIdentifier(key, encryptionSubkey.getKeyID()); SubkeyIdentifier keyId = new SubkeyIdentifier(key, encryptionSubkey.getKeyID());
keyRingInfo.put(keyId, info); keyRingInfo.put(keyId, info);
keyViews.put(keyId, new KeyAccessor.ViaKeyId(info, keyId)); keyViews.put(keyId, new KeyAccessor.ViaKeyId(info, keyId));
addRecipientKey(key, encryptionSubkey); addRecipientKey(key, encryptionSubkey, wildcardKeyId);
} }
return this; return this;
} }
private void addRecipientKey(@Nonnull PGPPublicKeyRing keyRing, private void addRecipientKey(@Nonnull PGPPublicKeyRing keyRing,
@Nonnull PGPPublicKey key) { @Nonnull PGPPublicKey key,
boolean wildcardKeyId) {
encryptionKeys.add(new SubkeyIdentifier(keyRing, key.getKeyID())); encryptionKeys.add(new SubkeyIdentifier(keyRing, key.getKeyID()));
PGPKeyEncryptionMethodGenerator encryptionMethod = ImplementationFactory PublicKeyKeyEncryptionMethodGenerator encryptionMethod = ImplementationFactory
.getInstance().getPublicKeyKeyEncryptionMethodGenerator(key); .getInstance().getPublicKeyKeyEncryptionMethodGenerator(key);
encryptionMethod.setUseWildcardKeyID(wildcardKeyId);
addEncryptionMethod(encryptionMethod); addEncryptionMethod(encryptionMethod);
} }