mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 06:12:06 +01:00
Delete unused KeyRingValidator class
This commit is contained in:
parent
7e0b1b344c
commit
b2a5351cc3
3 changed files with 0 additions and 595 deletions
|
@ -1,146 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.key;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.exception.SignatureValidationException;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.policy.Policy;
|
||||
import org.pgpainless.signature.consumer.SignatureCreationDateComparator;
|
||||
import org.pgpainless.signature.consumer.SignatureVerifier;
|
||||
import org.pgpainless.util.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class KeyRingValidator {
|
||||
|
||||
private KeyRingValidator() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(KeyRingValidator.class);
|
||||
|
||||
public static <R extends PGPKeyRing> R validate(R keyRing, Policy policy) {
|
||||
try {
|
||||
return validate(keyRing, policy, new Date());
|
||||
} catch (PGPException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <R extends PGPKeyRing> R validate(R keyRing, Policy policy, Date validationDate) throws PGPException {
|
||||
return getKeyRingAtDate(keyRing, policy, validationDate);
|
||||
}
|
||||
|
||||
private static <R extends PGPKeyRing> R getKeyRingAtDate(R keyRing, Policy policy, Date validationDate) throws PGPException {
|
||||
PGPPublicKey primaryKey = keyRing.getPublicKey();
|
||||
primaryKey = evaluatePrimaryKey(primaryKey, policy, validationDate);
|
||||
if (keyRing instanceof PGPPublicKeyRing) {
|
||||
PGPPublicKeyRing publicKeys = (PGPPublicKeyRing) keyRing;
|
||||
publicKeys = PGPPublicKeyRing.insertPublicKey(publicKeys, primaryKey);
|
||||
keyRing = (R) publicKeys;
|
||||
}
|
||||
|
||||
return keyRing;
|
||||
}
|
||||
|
||||
private static PGPPublicKey evaluatePrimaryKey(PGPPublicKey primaryKey, Policy policy, Date validationDate) throws PGPException {
|
||||
|
||||
PGPPublicKey blank = new PGPPublicKey(primaryKey.getPublicKeyPacket(), ImplementationFactory.getInstance().getKeyFingerprintCalculator());
|
||||
|
||||
Iterator<PGPSignature> directKeyIterator = primaryKey.getSignaturesOfType(SignatureType.DIRECT_KEY.getCode());
|
||||
List<PGPSignature> directKeyCertifications = CollectionUtils.iteratorToList(directKeyIterator);
|
||||
Collections.sort(directKeyCertifications, new SignatureCreationDateComparator(SignatureCreationDateComparator.Order.NEW_TO_OLD));
|
||||
for (PGPSignature signature : directKeyCertifications) {
|
||||
try {
|
||||
if (SignatureVerifier.verifyDirectKeySignature(signature, blank, policy, validationDate)) {
|
||||
blank = PGPPublicKey.addCertification(blank, signature);
|
||||
}
|
||||
} catch (SignatureValidationException e) {
|
||||
LOGGER.debug("Rejecting direct key signature: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<PGPSignature> revocationIterator = primaryKey.getSignaturesOfType(SignatureType.KEY_REVOCATION.getCode());
|
||||
List<PGPSignature> directKeyRevocations = CollectionUtils.iteratorToList(revocationIterator);
|
||||
Collections.sort(directKeyRevocations, new SignatureCreationDateComparator(SignatureCreationDateComparator.Order.NEW_TO_OLD));
|
||||
for (PGPSignature signature : directKeyRevocations) {
|
||||
try {
|
||||
if (SignatureVerifier.verifyKeyRevocationSignature(signature, primaryKey, policy, validationDate)) {
|
||||
blank = PGPPublicKey.addCertification(blank, signature);
|
||||
}
|
||||
} catch (SignatureValidationException e) {
|
||||
LOGGER.debug("Rejecting key revocation signature: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<String> userIdIterator = primaryKey.getUserIDs();
|
||||
while (userIdIterator.hasNext()) {
|
||||
String userId = userIdIterator.next();
|
||||
Iterator<PGPSignature> userIdSigs = primaryKey.getSignaturesForID(userId);
|
||||
List<PGPSignature> signatures = CollectionUtils.iteratorToList(userIdSigs);
|
||||
Collections.sort(signatures, new SignatureCreationDateComparator(SignatureCreationDateComparator.Order.NEW_TO_OLD));
|
||||
for (PGPSignature signature : signatures) {
|
||||
if (signature.getKeyID() != primaryKey.getKeyID()) {
|
||||
// Signature was not made by primary key
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (SignatureType.valueOf(signature.getSignatureType()) == SignatureType.CERTIFICATION_REVOCATION) {
|
||||
if (SignatureVerifier.verifyUserIdRevocation(userId, signature, primaryKey, policy, validationDate)) {
|
||||
blank = PGPPublicKey.addCertification(blank, userId, signature);
|
||||
}
|
||||
} else {
|
||||
if (SignatureVerifier.verifyUserIdCertification(userId, signature, primaryKey, policy, validationDate)) {
|
||||
blank = PGPPublicKey.addCertification(blank, userId, signature);
|
||||
}
|
||||
}
|
||||
} catch (SignatureValidationException e) {
|
||||
LOGGER.debug("Rejecting user-id certification for user-id {}: {}", userId, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<PGPUserAttributeSubpacketVector> userAttributes = primaryKey.getUserAttributes();
|
||||
while (userAttributes.hasNext()) {
|
||||
PGPUserAttributeSubpacketVector userAttribute = userAttributes.next();
|
||||
Iterator<PGPSignature> userAttributeSignatureIterator = primaryKey.getSignaturesForUserAttribute(userAttribute);
|
||||
while (userAttributeSignatureIterator.hasNext()) {
|
||||
PGPSignature signature = userAttributeSignatureIterator.next();
|
||||
if (signature.getKeyID() != primaryKey.getKeyID()) {
|
||||
// Signature was not made by primary key
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (SignatureType.valueOf(signature.getSignatureType()) == SignatureType.CERTIFICATION_REVOCATION) {
|
||||
if (SignatureVerifier.verifyUserAttributesRevocation(userAttribute, signature, primaryKey, policy, validationDate)) {
|
||||
blank = PGPPublicKey.addCertification(blank, userAttribute, signature);
|
||||
}
|
||||
} else {
|
||||
if (SignatureVerifier.verifyUserAttributesCertification(userAttribute, signature, primaryKey, policy, validationDate)) {
|
||||
blank = PGPPublicKey.addCertification(blank, userAttribute, signature);
|
||||
}
|
||||
}
|
||||
} catch (SignatureValidationException e) {
|
||||
LOGGER.debug("Rejecting user-attribute signature: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return blank;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,324 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.key;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bouncycastle.bcpg.attr.ImageAttribute;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
import org.pgpainless.util.CollectionUtils;
|
||||
import org.pgpainless.util.DateUtil;
|
||||
|
||||
public class KeyRingValidatorTest {
|
||||
|
||||
@Test
|
||||
public void testRevokedSubkey() throws IOException {
|
||||
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
|
||||
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
|
||||
"\n" +
|
||||
"xsBNBFpJegABCAC1ePFquP0135m8DYhcybhv7l+ecojitFOd/jRM7hCczIqKgalD\n" +
|
||||
"1Ro1gNr3VmH6FjRIKIvGT+sOzCKne1v3KyAAPoxtwxjkATTKdOGo15I6v5ZjmO1d\n" +
|
||||
"rLQOLSt1TF7XbQSt+ns6PUZWJL907DvECUU5b9FkNUqfQ14QqY+gi7MOyAQez3b7\n" +
|
||||
"Pg5Cyz/kVWQ6TSMW/myDEDEertQ4rDBsptEDFHCC2+iF4hO2LqfiCriu5qyLcKCQ\n" +
|
||||
"pd6dEuwJQ/jjT0D9A9Fwf+i04x6ZPKSU9oNAWqn8OSAq3/0B/hu9V+0U0iHPnJxe\n" +
|
||||
"quykvJk7maxhiGhxBWYXTvDJmoon0NOles7LABEBAAHCwHwEHwEKAA8Fgl4L4QAC\n" +
|
||||
"FQ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FSEtIRJrW5XVfg\n" +
|
||||
"3whc0XD+5J9RsHoL33ub9ZhQHFKsjrf0nGYbEFwMhSdysfTYYMbwKi0CcQeQtPP0\n" +
|
||||
"Y87zSryajDMFXQS0exdvhN4AXDlPlB3Rrkj7CQ==\n" +
|
||||
"=yTKS\n" +
|
||||
"-----END PGP ARMORED FILE-----\n";
|
||||
|
||||
PGPPublicKeyRing keyRing = PGPainless.readKeyRing().publicKeyRing(key);
|
||||
PGPPublicKeyRing validated = KeyRingValidator.validate(keyRing, PGPainless.getPolicy());
|
||||
|
||||
Iterator<PGPPublicKey> keys = validated.getPublicKeys();
|
||||
assertFalse(keys.next().hasRevocation());
|
||||
assertTrue(keys.next().hasRevocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void badSignatureTest() throws IOException {
|
||||
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"\n" +
|
||||
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
|
||||
"/seOXpgecTdOcVttfzC8ycIKrt3aQTiwOG/ctaR4Bk/t6ayNFfdUNxHWk4WCKzdz\n" +
|
||||
"/56fW2O0F23qIRd8UUJp5IIlN4RDdRCtdhVQIAuzvp2oVy/LaS2kxQoKvph/5pQ/\n" +
|
||||
"5whqsyroEWDJoSV0yOb25B/iwk/pLUFoyhDG9bj0kIzDxrEqW+7Ba8nocQlecMF3\n" +
|
||||
"X5KMN5kp2zraLv9dlBBpWW43XktjcCZgMy20SouraVma8Je/ECwUWYUiAZxLIlMv\n" +
|
||||
"9CurEOtxUw6N3RdOtLmYZS9uEnn5y1UkF88o8Nku890uk6BrewFzJyLAx5wRZ4F0\n" +
|
||||
"qV/yq36UWQ0JB/AUGhHVPdFf6pl6eaxBwT5GXvbBUibtf8YI2og5RsgTWtXfU7eb\n" +
|
||||
"SGXrl5ZMpbA6mbfhd0R8aPxWfmDWiIOhBufhMCvUHh1sApMKVZnv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XZRzaXZE2aAMcLA9gQYAQoAIBYhBNGmbhojsYLJmA94jPv8yCoBXnMwBQJd\n" +
|
||||
"pZzyAhsMAAoJEPv8yCoBXnMw6f8L/26C34dkjBffTzMj5Bdzm8MtF67OYneJ4TQM\n" +
|
||||
"w7+41IL4rVcSKhIhk/3Ud5knaRtP2ef1+5F66h9/RPQOJ5+tvBwhBAcUWSupKnUr\n" +
|
||||
"dVaZQanYmtSxcVV2PL9+QEiNN3tzluhaWO//rACxJ+K/ZXQlIzwQVTpNhfGzAaMV\n" +
|
||||
"V9zpf3u0k14itcv6alKY8+rLZvO1wIIeRZLmU0tZDD5HtWDvUV7rIFI1WuoLb+KZ\n" +
|
||||
"gbYn3OWjCPHVdTrdZ2CqnZbG3SXw6awH9bzRLV9EXkbhIMez0deCVdeo+wFFklh8\n" +
|
||||
"/5VK2b0vk/+wqMJxfpa1lHvJLobzOP9fvrswsr92MA2+k901WeISR7qEzcI0Fdg8\n" +
|
||||
"AyFAExaEK6VyjP7SXGLwvfisw34OxuZr3qmx1Sufu4toH3XrB7QJN8XyqqbsGxUC\n" +
|
||||
"BqWif9RSK4xjzRTe56iPeiSJJOIciMP9i2ldI+KgLycyeDvGoBj0HCLO3gVaBe4u\n" +
|
||||
"bVrj5KjhX2PVNEJd3XZRzaXZE2Z/MQ==\n" +
|
||||
"=6+l9\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(key);
|
||||
PGPPublicKeyRing validated = KeyRingValidator.validate(publicKeys, PGPainless.getPolicy());
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(ArmorUtils.toAsciiArmoredString(validated));
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unboundSubkey() throws IOException {
|
||||
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"\n" +
|
||||
"xsDNBF2lnPIBDAC5cL9PQoQLTM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41IL4rVcS\n" +
|
||||
"KhIhk/3Ud5knaRtP2ef1+5F66h9/RPQOJ5+tvBwhBAcUWSupKnUrdVaZQanYmtSx\n" +
|
||||
"cVV2PL9+QEiNN3tzluhaWO//rACxJ+K/ZXQlIzwQVTpNhfGzAaMVV9zpf3u0k14i\n" +
|
||||
"tcv6alKY8+rLZvO1wIIeRZLmU0tZDD5HtWDvUV7rIFI1WuoLb+KZgbYn3OWjCPHV\n" +
|
||||
"dTrdZ2CqnZbG3SXw6awH9bzRLV9EXkbhIMez0deCVdeo+wFFklh8/5VK2b0vk/+w\n" +
|
||||
"qMJxfpa1lHvJLobzOP9fvrswsr92MA2+k901WeISR7qEzcI0Fdg8AyFAExaEK6Vy\n" +
|
||||
"jP7SXGLwvfisw34OxuZr3qmx1Sufu4toH3XrB7QJN8XyqqbsGxUCBqWif9RSK4xj\n" +
|
||||
"zRTe56iPeiSJJOIciMP9i2ldI+KgLycyeDvGoBj0HCLO3gVaBe4ubVrj5KjhX2PV\n" +
|
||||
"NEJd3XZRzaXZE2aAMc7ATQRgSLpPAQgAx2jWKrOk6fGy2/KJGTs6vAN8c+fg+PgH\n" +
|
||||
"6xDkasqmGllG0xPVOTML+Ge3i025IezFp1BNApPLWVksFRnbTF/Aiwbpeax7mub0\n" +
|
||||
"PdFo4LeNxfUZhl/83+aZKYvT/j9AB7rjILhu+wqZmLY9UAkdvIO0SfEUIFf0mL5c\n" +
|
||||
"9UJm47IOpY0EPc8l7B5DkXpkA63BKGyMPle6XZV3r/VIltnMnQezY1TErjeEnFrE\n" +
|
||||
"KYxqMgDhPIEaBSK8tqf3POwY2mP42K8+yke/St9+FvLIAKOj2KpVp/0pxcNBBoHA\n" +
|
||||
"9oo0W4CQP6S0hQkFZy9iZ1/NIpU+YLy8miBpdTMYm4CZLz5mrT2mpwARAQAB\n" +
|
||||
"=T4QR\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
|
||||
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(key);
|
||||
PGPPublicKey unbound = CollectionUtils.iteratorToList(publicKeys.getPublicKeys()).get(2);
|
||||
assertNotNull(unbound);
|
||||
|
||||
Date validationDate = DateUtil.parseUTCDate("2019-10-15 10:18:26 UTC");
|
||||
KeyRingInfo info = new KeyRingInfo(publicKeys, validationDate);
|
||||
for (PGPPublicKey publicKey : publicKeys) {
|
||||
if (publicKey != unbound) {
|
||||
assertTrue(info.isKeyValidlyBound(publicKey.getKeyID()));
|
||||
} else {
|
||||
assertFalse(info.isKeyValidlyBound(publicKey.getKeyID()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expired() throws IOException {
|
||||
String key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"\n" +
|
||||
"xsDNBF2lnPIBDAC5cL9PQoQLTMuhjbYvb4Ncuuo0bfmgPRFywX53jPhoFf4Zg6mv\n" +
|
||||
"/seOXpgecTdOcVttfzC8ycIKrt3aQTiwOG/ctaR4Bk/t6ayNFfdUNxHWk4WCKzdz\n" +
|
||||
"/56fW2O0F23qIRd8UUJp5IIlN4RDdRCtdhVQIAuzvp2oVy/LaS2kxQoKvph/5pQ/\n" +
|
||||
"5whqsyroEWDJoSV0yOb25B/iwk/pLUFoyhDG9bj0kIzDxrEqW+7Ba8nocQlecMF3\n" +
|
||||
"X5KMN5kp2zraLv9dlBBpWW43XktjcCZgMy20SouraVma8Je/ECwUWYUiAZxLIlMv\n" +
|
||||
"9CurEOtxUw6N3RdOtLmYZS9uEnn5y1UkF88o8Nku890uk6BrewFzJyLAx5wRZ4F0\n" +
|
||||
"qV/yq36UWQ0JB/AUGhHVPdFf6pl6eaxBwT5GXvbBUibtf8YI2og5RsgTWtXfU7eb\n" +
|
||||
"SGXrl5ZMpbA6mbfhd0R8aPxWfmDWiIOhBufhMCvUHh1sApMKVZnvIff9/0Dca3wb\n" +
|
||||
"vLIwa3T4CyshfT0AEQEAAc0hQm9iIEJhYmJhZ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KgLycyeDvGoBj0HCLO3gVaBe4ubVrj5KjhX2PVNEJd3XZRzaXZE2aAMQ==\n" +
|
||||
"=LxAY\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
|
||||
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(key);
|
||||
PGPPublicKeyRing validated = KeyRingValidator.validate(publicKeys, PGPainless.getPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyWithUserAttributes() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice <alice@pgpainless.org>");
|
||||
PGPPublicKeyRing publicKeys = PGPainless.extractCertificate(secretKeys);
|
||||
PGPPublicKey publicKey = secretKeys.getPublicKey();
|
||||
PGPSecretKey secretKey = secretKeys.getSecretKey();
|
||||
PGPPrivateKey privateKey = UnlockSecretKey.unlockSecretKey(secretKey, SecretKeyRingProtector.unprotectedKeys());
|
||||
|
||||
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
|
||||
ImplementationFactory.getInstance().getPGPContentSignerBuilder(publicKey.getAlgorithm(), HashAlgorithm.SHA512.getAlgorithmId())
|
||||
);
|
||||
|
||||
signatureGenerator.init(SignatureType.CASUAL_CERTIFICATION.getCode(), privateKey);
|
||||
PGPUserAttributeSubpacketVectorGenerator userAttrGen = new PGPUserAttributeSubpacketVectorGenerator();
|
||||
byte[] image = new byte[100];
|
||||
new Random().nextBytes(image);
|
||||
userAttrGen.setImageAttribute(ImageAttribute.JPEG, image);
|
||||
PGPUserAttributeSubpacketVector userAttr = userAttrGen.generate();
|
||||
|
||||
PGPSignature certification = signatureGenerator.generateCertification(userAttr, publicKey);
|
||||
publicKey = PGPPublicKey.addCertification(publicKey, userAttr, certification);
|
||||
publicKeys = PGPPublicKeyRing.insertPublicKey(publicKeys, publicKey);
|
||||
secretKeys = PGPSecretKeyRing.replacePublicKeys(secretKeys, publicKeys);
|
||||
|
||||
secretKeys = KeyRingValidator.validate(secretKeys, PGPainless.getPolicy());
|
||||
assertTrue(secretKeys.getPublicKey().getUserAttributes().hasNext());
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.signature;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.HashAlgorithm;
|
||||
import org.pgpainless.key.KeyRingValidator;
|
||||
import org.pgpainless.policy.Policy;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
import org.pgpainless.util.DateUtil;
|
||||
|
||||
public class KeyRingValidationTest {
|
||||
|
||||
private static Policy.HashAlgorithmPolicy defaultSignatureHashAlgorithmPolicy;
|
||||
|
||||
@BeforeAll
|
||||
public static void setCustomPolicy() {
|
||||
Policy policy = PGPainless.getPolicy();
|
||||
defaultSignatureHashAlgorithmPolicy = policy.getSignatureHashAlgorithmPolicy();
|
||||
|
||||
policy.setSignatureHashAlgorithmPolicy(new Policy.HashAlgorithmPolicy(HashAlgorithm.SHA256, Collections.singletonList(HashAlgorithm.SHA256)));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void resetCustomPolicy() {
|
||||
PGPainless.getPolicy().setSignatureHashAlgorithmPolicy(defaultSignatureHashAlgorithmPolicy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignatureValidationOnPrimaryKey() throws IOException, PGPException {
|
||||
String key = "-----BEGIN PGP ARMORED FILE-----\n" +
|
||||
"Comment: ASCII Armor added by openpgp-interoperability-test-suite\n" +
|
||||
"\n" +
|
||||
"xsBNBFpJegABCAC1ePFquP0135m8DYhcybhv7l+ecojitFOd/jRM7hCczIqKgalD\n" +
|
||||
"1Ro1gNr3VmH6FjRIKIvGT+sOzCKne1v3KyAAPoxtwxjkATTKdOGo15I6v5ZjmO1d\n" +
|
||||
"rLQOLSt1TF7XbQSt+ns6PUZWJL907DvECUU5b9FkNUqfQ14QqY+gi7MOyAQez3b7\n" +
|
||||
"Pg5Cyz/kVWQ6TSMW/myDEDEertQ4rDBsptEDFHCC2+iF4hO2LqfiCriu5qyLcKCQ\n" +
|
||||
"pd6dEuwJQ/jjT0D9A9Fwf+i04x6ZPKSU9oNAWqn8OSAq3/0B/hu9V+0U0iHPnJxe\n" +
|
||||
"quykvJk7maxhiGhxBWYXTvDJmoon0NOles7LABEBAAHCwIcEIAEKABoFglwqrYAT\n" +
|
||||
"HQFLZXkgaXMgc3VwZXJzZWRlZAAhCRBoT61i3AOPuxYhBPLRUKT+mJJdUekVOWhP\n" +
|
||||
"rWLcA4+76+wH/1NmN/Qma5FTxmSWEcfH2ynKhwejKp8p8O7+y/uq1FlUwRzChzeX\n" +
|
||||
"kd9w099uODMasxGaNSJU1mh5N+1oulyHrSyWFRWqDnQUnDx3IiPapK/j85udkJdo\n" +
|
||||
"WfdTcxaS2C9Yo4S77cPwkbFLmEQ2Ovs5zjj0Q+mfoZNM+KJcsnOoJ+eeOE2GNA3x\n" +
|
||||
"5TWvw0QXBfyW74MZHc0UE82ixcG6g4KbrI6W544EixY5vu3IxVsxiL66zy27A8ha\n" +
|
||||
"EDdBWS8kc8UQ2cRveuqZwRsWcrh/2iHHShY/5zBOdQ1PL++ubwkteNSU9SsXjjDM\n" +
|
||||
"oWm1RGy7/bagPPtqBnRMQ20vvW+3oBYxyd7CwHwEHwEKAA8Fgl4L4QACFQoCmwMC\n" +
|
||||
"HgEAIQkQaE+tYtwDj7sWIQTy0VCk/piSX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
"J1ZV7nJarXVbuZDEcUDuDm3cA5tup7juB8fTz2BDcg3Ka+OcPEz0GgZfq9K40di3\n" +
|
||||
"r9IHLBhNPHieFVIj9j/JyMnTvVOceM3J/Rb0MCWJVbXNBKpRMDibCQh+7fbqyQEM\n" +
|
||||
"/zIpmk0TgBpTZZqMP0gxYdWImT1IFiEE8tFQpP6Ykl1R6RU5aE+tYtwDj7tOtggA\n" +
|
||||
"hgAqvOB142L2SkS3ZIdwuhAtWLPHCtEwBOqGtP8Z204rqAmbnJymzo77+OT+SScn\n" +
|
||||
"DTrwzOUJnCi0qPUxfuxhvHxnBxBIjaoMcF++iKsqF1vf6WuXOjbJ1N8I08pB2nih\n" +
|
||||
"t5MxIZ9rMGDeASj79X7I9Jjzsd30OVGfTZyy3VyYPxcJ6n/sZocNmaTv0/F8K3Ti\n" +
|
||||
"rSH6JDXdY5zirRi99GJ3R+AL6OzxrChuvLFSEtIRJrW5XVfg3whc0XD+5J9RsHoL\n" +
|
||||
"33ub9ZhQHFKsjrf0nGYbEFwMhSdysfTYYMbwKi0CcQeQtPP0Y87zSryajDMFXQS0\n" +
|
||||
"exdvhN4AXDlPlB3Rrkj7CQ==\n" +
|
||||
"=qQpG\n" +
|
||||
"-----END PGP ARMORED FILE-----\n";
|
||||
|
||||
PGPPublicKeyRing publicKeys = PGPainless.readKeyRing().publicKeyRing(key);
|
||||
|
||||
Date validationDate = DateUtil.parseUTCDate("2019-05-01 00:00:00 UTC");
|
||||
Policy policy = PGPainless.getPolicy();
|
||||
PGPPublicKeyRing evaluated = KeyRingValidator.validate(publicKeys, policy, validationDate);
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(ArmorUtils.toAsciiArmoredString(evaluated));
|
||||
// CHECKSTYLE:ON
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue