mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 22:32:07 +01:00
Fix test and add temporary workaround
This commit is contained in:
parent
23e31a1483
commit
8f8b8f534b
2 changed files with 29 additions and 5 deletions
|
@ -32,6 +32,9 @@ import org.pgpainless.algorithm.KeyFlag;
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||||
import org.pgpainless.key.util.RevocationAttributes;
|
import org.pgpainless.key.util.RevocationAttributes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class SignatureSubpacketsHelper {
|
public class SignatureSubpacketsHelper {
|
||||||
|
|
||||||
public static SignatureSubpackets applyFrom(PGPSignatureSubpacketVector vector, SignatureSubpackets subpackets) {
|
public static SignatureSubpackets applyFrom(PGPSignatureSubpacketVector vector, SignatureSubpackets subpackets) {
|
||||||
|
@ -81,6 +84,19 @@ public class SignatureSubpacketsHelper {
|
||||||
subpackets.setPreferredCompressionAlgorithms((PreferredAlgorithms) subpacket);
|
subpackets.setPreferredCompressionAlgorithms((PreferredAlgorithms) subpacket);
|
||||||
break;
|
break;
|
||||||
case preferredAEADAlgorithms:
|
case preferredAEADAlgorithms:
|
||||||
|
// Workaround for https://github.com/pgpainless/pgpainless/pull/399
|
||||||
|
// TODO: Remove when BC 1.77 is released
|
||||||
|
if (subpacket instanceof PreferredAlgorithms) {
|
||||||
|
List<PreferredAEADCiphersuites.Combination> combinationList = new ArrayList<>();
|
||||||
|
int[] algorithms = ((PreferredAlgorithms) subpacket).getPreferences();
|
||||||
|
for (int i = 0; i < algorithms.length; i += 2) {
|
||||||
|
combinationList.add(new PreferredAEADCiphersuites.Combination(algorithms[i], algorithms[i + 1]));
|
||||||
|
}
|
||||||
|
PreferredAEADCiphersuites aead = new PreferredAEADCiphersuites(
|
||||||
|
subpacket.isCritical(), combinationList.toArray(new PreferredAEADCiphersuites.Combination[0]));
|
||||||
|
subpackets.setPreferredAEADCiphersuites(aead);
|
||||||
|
break;
|
||||||
|
}
|
||||||
subpackets.setPreferredAEADCiphersuites((PreferredAEADCiphersuites) subpacket);
|
subpackets.setPreferredAEADCiphersuites((PreferredAEADCiphersuites) subpacket);
|
||||||
break;
|
break;
|
||||||
case primaryUserId:
|
case primaryUserId:
|
||||||
|
|
|
@ -17,12 +17,15 @@ import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bouncycastle.bcpg.AEADAlgorithmTags;
|
||||||
import org.bouncycastle.bcpg.SignatureSubpacket;
|
import org.bouncycastle.bcpg.SignatureSubpacket;
|
||||||
import org.bouncycastle.bcpg.SignatureSubpacketTags;
|
import org.bouncycastle.bcpg.SignatureSubpacketTags;
|
||||||
|
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
|
||||||
import org.bouncycastle.bcpg.sig.Exportable;
|
import org.bouncycastle.bcpg.sig.Exportable;
|
||||||
import org.bouncycastle.bcpg.sig.Features;
|
import org.bouncycastle.bcpg.sig.Features;
|
||||||
import org.bouncycastle.bcpg.sig.IssuerFingerprint;
|
import org.bouncycastle.bcpg.sig.IssuerFingerprint;
|
||||||
import org.bouncycastle.bcpg.sig.NotationData;
|
import org.bouncycastle.bcpg.sig.NotationData;
|
||||||
|
import org.bouncycastle.bcpg.sig.PreferredAEADCiphersuites;
|
||||||
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
||||||
import org.bouncycastle.bcpg.sig.Revocable;
|
import org.bouncycastle.bcpg.sig.Revocable;
|
||||||
import org.bouncycastle.bcpg.sig.RevocationKey;
|
import org.bouncycastle.bcpg.sig.RevocationKey;
|
||||||
|
@ -481,9 +484,14 @@ public class SignatureSubpacketsTest {
|
||||||
new Random().nextBytes(hash);
|
new Random().nextBytes(hash);
|
||||||
subpackets.setSignatureTarget(false, publicKeys.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId(), hash);
|
subpackets.setSignatureTarget(false, publicKeys.getPublicKey().getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId(), hash);
|
||||||
subpackets.addIntendedRecipientFingerprint(true, publicKeys.getPublicKey());
|
subpackets.addIntendedRecipientFingerprint(true, publicKeys.getPublicKey());
|
||||||
PreferredAlgorithms aead = new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS, false, new int[] {2});
|
PreferredAEADCiphersuites.Combination[] aead = new PreferredAEADCiphersuites.Combination[] {
|
||||||
subpackets.addCustomSubpacket(aead);
|
new PreferredAEADCiphersuites.Combination(SymmetricKeyAlgorithmTags.AES_256, AEADAlgorithmTags.OCB),
|
||||||
|
new PreferredAEADCiphersuites.Combination(SymmetricKeyAlgorithmTags.AES_128, AEADAlgorithmTags.EAX)
|
||||||
|
};
|
||||||
|
subpackets.setPreferredAEADAlgorithms(false, new int[] {
|
||||||
|
aead[0].getSymmetricAlgorithm(), aead[0].getAeadAlgorithm(),
|
||||||
|
aead[1].getSymmetricAlgorithm(), aead[1].getAeadAlgorithm()
|
||||||
|
});
|
||||||
|
|
||||||
SignatureSubpackets wrapper = SignatureSubpackets.createSubpacketsFrom(subpackets.generate());
|
SignatureSubpackets wrapper = SignatureSubpackets.createSubpacketsFrom(subpackets.generate());
|
||||||
PGPSignatureSubpacketVector vector = SignatureSubpacketsHelper.toVector(wrapper);
|
PGPSignatureSubpacketVector vector = SignatureSubpacketsHelper.toVector(wrapper);
|
||||||
|
@ -530,7 +538,7 @@ public class SignatureSubpacketsTest {
|
||||||
assertEquals(HashAlgorithm.SHA512.getAlgorithmId(), signatureTarget.getHashAlgorithm());
|
assertEquals(HashAlgorithm.SHA512.getAlgorithmId(), signatureTarget.getHashAlgorithm());
|
||||||
assertArrayEquals(hash, signatureTarget.getHashData());
|
assertArrayEquals(hash, signatureTarget.getHashData());
|
||||||
assertArrayEquals(publicKeys.getPublicKey().getFingerprint(), vector.getIntendedRecipientFingerprint().getFingerprint());
|
assertArrayEquals(publicKeys.getPublicKey().getFingerprint(), vector.getIntendedRecipientFingerprint().getFingerprint());
|
||||||
PreferredAlgorithms aeadAlgorithms = (PreferredAlgorithms) vector.getSubpacket(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
|
PreferredAEADCiphersuites aeadAlgorithms = (PreferredAEADCiphersuites) vector.getSubpacket(SignatureSubpacketTags.PREFERRED_AEAD_ALGORITHMS);
|
||||||
assertArrayEquals(aead.getPreferences(), aeadAlgorithms.getPreferences());
|
assertArrayEquals(aead, aeadAlgorithms.getRawAlgorithms());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue