mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 20:32:05 +01:00
Add support for PreferredAEADCiphersuites subpacket
Requires BC 1.77 See https://github.com/bcgit/bc-java/pull/1464
This commit is contained in:
parent
8cdb7ee4e0
commit
23e31a1483
3 changed files with 62 additions and 9 deletions
|
@ -13,15 +13,18 @@ import javax.annotation.Nullable;
|
||||||
import org.bouncycastle.bcpg.sig.Features;
|
import org.bouncycastle.bcpg.sig.Features;
|
||||||
import org.bouncycastle.bcpg.sig.KeyExpirationTime;
|
import org.bouncycastle.bcpg.sig.KeyExpirationTime;
|
||||||
import org.bouncycastle.bcpg.sig.KeyFlags;
|
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||||
|
import org.bouncycastle.bcpg.sig.PreferredAEADCiphersuites;
|
||||||
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
||||||
import org.bouncycastle.bcpg.sig.PrimaryUserID;
|
import org.bouncycastle.bcpg.sig.PrimaryUserID;
|
||||||
import org.bouncycastle.bcpg.sig.RevocationKey;
|
import org.bouncycastle.bcpg.sig.RevocationKey;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
|
import org.pgpainless.algorithm.AEADAlgorithm;
|
||||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||||
import org.pgpainless.algorithm.Feature;
|
import org.pgpainless.algorithm.Feature;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.algorithm.KeyFlag;
|
import org.pgpainless.algorithm.KeyFlag;
|
||||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||||
|
import org.pgpainless.util.Tuple;
|
||||||
|
|
||||||
public interface SelfSignatureSubpackets extends BaseSignatureSubpackets {
|
public interface SelfSignatureSubpackets extends BaseSignatureSubpackets {
|
||||||
|
|
||||||
|
@ -56,6 +59,14 @@ public interface SelfSignatureSubpackets extends BaseSignatureSubpackets {
|
||||||
|
|
||||||
SelfSignatureSubpackets setKeyExpirationTime(@Nullable KeyExpirationTime keyExpirationTime);
|
SelfSignatureSubpackets setKeyExpirationTime(@Nullable KeyExpirationTime keyExpirationTime);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredAEADCiphersuites(Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>... algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredAEADCiphersuites(Set<Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>> algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredAEADCiphersuites(boolean isCritical, Set<Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>> algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredAEADCiphersuites(@Nullable PreferredAEADCiphersuites algorithms);
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredCompressionAlgorithms(CompressionAlgorithm... algorithms);
|
SelfSignatureSubpackets setPreferredCompressionAlgorithms(CompressionAlgorithm... algorithms);
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredCompressionAlgorithms(Set<CompressionAlgorithm> algorithms);
|
SelfSignatureSubpackets setPreferredCompressionAlgorithms(Set<CompressionAlgorithm> algorithms);
|
||||||
|
@ -64,14 +75,6 @@ public interface SelfSignatureSubpackets extends BaseSignatureSubpackets {
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredCompressionAlgorithms(@Nullable PreferredAlgorithms algorithms);
|
SelfSignatureSubpackets setPreferredCompressionAlgorithms(@Nullable PreferredAlgorithms algorithms);
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(SymmetricKeyAlgorithm... algorithms);
|
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(Set<SymmetricKeyAlgorithm> algorithms);
|
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(boolean isCritical, Set<SymmetricKeyAlgorithm> algorithms);
|
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(@Nullable PreferredAlgorithms algorithms);
|
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredHashAlgorithms(HashAlgorithm... algorithms);
|
SelfSignatureSubpackets setPreferredHashAlgorithms(HashAlgorithm... algorithms);
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredHashAlgorithms(Set<HashAlgorithm> algorithms);
|
SelfSignatureSubpackets setPreferredHashAlgorithms(Set<HashAlgorithm> algorithms);
|
||||||
|
@ -80,6 +83,14 @@ public interface SelfSignatureSubpackets extends BaseSignatureSubpackets {
|
||||||
|
|
||||||
SelfSignatureSubpackets setPreferredHashAlgorithms(@Nullable PreferredAlgorithms algorithms);
|
SelfSignatureSubpackets setPreferredHashAlgorithms(@Nullable PreferredAlgorithms algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(SymmetricKeyAlgorithm... algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(Set<SymmetricKeyAlgorithm> algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(boolean isCritical, Set<SymmetricKeyAlgorithm> algorithms);
|
||||||
|
|
||||||
|
SelfSignatureSubpackets setPreferredSymmetricKeyAlgorithms(@Nullable PreferredAlgorithms algorithms);
|
||||||
|
|
||||||
SelfSignatureSubpackets addRevocationKey(@Nonnull PGPPublicKey revocationKey);
|
SelfSignatureSubpackets addRevocationKey(@Nonnull PGPPublicKey revocationKey);
|
||||||
|
|
||||||
SelfSignatureSubpackets addRevocationKey(boolean isCritical, @Nonnull PGPPublicKey revocationKey);
|
SelfSignatureSubpackets addRevocationKey(boolean isCritical, @Nonnull PGPPublicKey revocationKey);
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.bouncycastle.bcpg.sig.KeyExpirationTime;
|
||||||
import org.bouncycastle.bcpg.sig.KeyFlags;
|
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||||
import org.bouncycastle.bcpg.sig.NotationData;
|
import org.bouncycastle.bcpg.sig.NotationData;
|
||||||
import org.bouncycastle.bcpg.sig.PolicyURI;
|
import org.bouncycastle.bcpg.sig.PolicyURI;
|
||||||
|
import org.bouncycastle.bcpg.sig.PreferredAEADCiphersuites;
|
||||||
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
||||||
import org.bouncycastle.bcpg.sig.PrimaryUserID;
|
import org.bouncycastle.bcpg.sig.PrimaryUserID;
|
||||||
import org.bouncycastle.bcpg.sig.RegularExpression;
|
import org.bouncycastle.bcpg.sig.RegularExpression;
|
||||||
|
@ -42,6 +43,7 @@ import org.bouncycastle.bcpg.sig.TrustSignature;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
|
import org.bouncycastle.openpgp.PGPSignatureSubpacketVector;
|
||||||
|
import org.pgpainless.algorithm.AEADAlgorithm;
|
||||||
import org.pgpainless.algorithm.CompressionAlgorithm;
|
import org.pgpainless.algorithm.CompressionAlgorithm;
|
||||||
import org.pgpainless.algorithm.Feature;
|
import org.pgpainless.algorithm.Feature;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
|
@ -49,6 +51,7 @@ import org.pgpainless.algorithm.KeyFlag;
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||||
import org.pgpainless.key.util.RevocationAttributes;
|
import org.pgpainless.key.util.RevocationAttributes;
|
||||||
|
import org.pgpainless.util.Tuple;
|
||||||
|
|
||||||
public class SignatureSubpackets
|
public class SignatureSubpackets
|
||||||
implements BaseSignatureSubpackets, SelfSignatureSubpackets, CertificationSubpackets, RevocationSignatureSubpackets {
|
implements BaseSignatureSubpackets, SelfSignatureSubpackets, CertificationSubpackets, RevocationSignatureSubpackets {
|
||||||
|
@ -68,6 +71,7 @@ public class SignatureSubpackets
|
||||||
private PreferredAlgorithms preferredCompressionAlgorithms;
|
private PreferredAlgorithms preferredCompressionAlgorithms;
|
||||||
private PreferredAlgorithms preferredSymmetricKeyAlgorithms;
|
private PreferredAlgorithms preferredSymmetricKeyAlgorithms;
|
||||||
private PreferredAlgorithms preferredHashAlgorithms;
|
private PreferredAlgorithms preferredHashAlgorithms;
|
||||||
|
private PreferredAEADCiphersuites preferredAEADCiphersuites;
|
||||||
private final List<EmbeddedSignature> embeddedSignatureList = new ArrayList<>();
|
private final List<EmbeddedSignature> embeddedSignatureList = new ArrayList<>();
|
||||||
private SignerUserID signerUserId;
|
private SignerUserID signerUserId;
|
||||||
private KeyExpirationTime keyExpirationTime;
|
private KeyExpirationTime keyExpirationTime;
|
||||||
|
@ -313,6 +317,40 @@ public class SignatureSubpackets
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SelfSignatureSubpackets setPreferredAEADCiphersuites(Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>... algorithms) {
|
||||||
|
return setPreferredAEADCiphersuites(new LinkedHashSet<>(Arrays.asList(algorithms)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SelfSignatureSubpackets setPreferredAEADCiphersuites(Set<Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>> algorithms) {
|
||||||
|
return setPreferredAEADCiphersuites(false, algorithms);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SelfSignatureSubpackets setPreferredAEADCiphersuites(boolean isCritical, Set<Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>> algorithms) {
|
||||||
|
List<PreferredAEADCiphersuites.Combination> combinations = new ArrayList<>();
|
||||||
|
Iterator<Tuple<SymmetricKeyAlgorithm, AEADAlgorithm>> iterator = algorithms.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Tuple<SymmetricKeyAlgorithm, AEADAlgorithm> tuple = iterator.next();
|
||||||
|
combinations.add(new PreferredAEADCiphersuites.Combination(
|
||||||
|
tuple.getA().getAlgorithmId(), tuple.getB().getAlgorithmId()));
|
||||||
|
}
|
||||||
|
PreferredAEADCiphersuites subpacket = new PreferredAEADCiphersuites(
|
||||||
|
isCritical, combinations.toArray(new PreferredAEADCiphersuites.Combination[0]));
|
||||||
|
return setPreferredAEADCiphersuites(subpacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SelfSignatureSubpackets setPreferredAEADCiphersuites(@Nullable PreferredAEADCiphersuites algorithms) {
|
||||||
|
this.preferredAEADCiphersuites = algorithms;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreferredAEADCiphersuites getPreferredAEADCiphersuites() {
|
||||||
|
return preferredAEADCiphersuites;
|
||||||
|
}
|
||||||
|
|
||||||
public KeyExpirationTime getKeyExpirationTimeSubpacket() {
|
public KeyExpirationTime getKeyExpirationTimeSubpacket() {
|
||||||
return keyExpirationTime;
|
return keyExpirationTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.bouncycastle.bcpg.sig.KeyExpirationTime;
|
||||||
import org.bouncycastle.bcpg.sig.KeyFlags;
|
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||||
import org.bouncycastle.bcpg.sig.NotationData;
|
import org.bouncycastle.bcpg.sig.NotationData;
|
||||||
import org.bouncycastle.bcpg.sig.PolicyURI;
|
import org.bouncycastle.bcpg.sig.PolicyURI;
|
||||||
|
import org.bouncycastle.bcpg.sig.PreferredAEADCiphersuites;
|
||||||
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
|
||||||
import org.bouncycastle.bcpg.sig.PrimaryUserID;
|
import org.bouncycastle.bcpg.sig.PrimaryUserID;
|
||||||
import org.bouncycastle.bcpg.sig.RegularExpression;
|
import org.bouncycastle.bcpg.sig.RegularExpression;
|
||||||
|
@ -79,6 +80,9 @@ public class SignatureSubpacketsHelper {
|
||||||
case preferredCompressionAlgorithms:
|
case preferredCompressionAlgorithms:
|
||||||
subpackets.setPreferredCompressionAlgorithms((PreferredAlgorithms) subpacket);
|
subpackets.setPreferredCompressionAlgorithms((PreferredAlgorithms) subpacket);
|
||||||
break;
|
break;
|
||||||
|
case preferredAEADAlgorithms:
|
||||||
|
subpackets.setPreferredAEADCiphersuites((PreferredAEADCiphersuites) subpacket);
|
||||||
|
break;
|
||||||
case primaryUserId:
|
case primaryUserId:
|
||||||
PrimaryUserID primaryUserID = (PrimaryUserID) subpacket;
|
PrimaryUserID primaryUserID = (PrimaryUserID) subpacket;
|
||||||
subpackets.setPrimaryUserId(primaryUserID);
|
subpackets.setPrimaryUserId(primaryUserID);
|
||||||
|
@ -128,7 +132,6 @@ public class SignatureSubpacketsHelper {
|
||||||
case keyServerPreferences:
|
case keyServerPreferences:
|
||||||
case preferredKeyServers:
|
case preferredKeyServers:
|
||||||
case placeholder:
|
case placeholder:
|
||||||
case preferredAEADAlgorithms:
|
|
||||||
case attestedCertification:
|
case attestedCertification:
|
||||||
subpackets.addResidualSubpacket(subpacket);
|
subpackets.addResidualSubpacket(subpacket);
|
||||||
break;
|
break;
|
||||||
|
@ -161,6 +164,7 @@ public class SignatureSubpacketsHelper {
|
||||||
addSubpacket(generator, subpackets.getPreferredCompressionAlgorithmsSubpacket());
|
addSubpacket(generator, subpackets.getPreferredCompressionAlgorithmsSubpacket());
|
||||||
addSubpacket(generator, subpackets.getPreferredSymmetricKeyAlgorithmsSubpacket());
|
addSubpacket(generator, subpackets.getPreferredSymmetricKeyAlgorithmsSubpacket());
|
||||||
addSubpacket(generator, subpackets.getPreferredHashAlgorithmsSubpacket());
|
addSubpacket(generator, subpackets.getPreferredHashAlgorithmsSubpacket());
|
||||||
|
addSubpacket(generator, subpackets.getPreferredAEADCiphersuites());
|
||||||
for (EmbeddedSignature embeddedSignature : subpackets.getEmbeddedSignatureSubpackets()) {
|
for (EmbeddedSignature embeddedSignature : subpackets.getEmbeddedSignatureSubpackets()) {
|
||||||
addSubpacket(generator, embeddedSignature);
|
addSubpacket(generator, embeddedSignature);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue