diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java b/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java index cb328300..995bded4 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/info/KeyRingInfo.java @@ -36,6 +36,7 @@ import org.pgpainless.algorithm.EncryptionPurpose; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.PublicKeyAlgorithm; +import org.pgpainless.algorithm.RevocationState; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; import org.pgpainless.exception.KeyException; import org.pgpainless.key.OpenPgpFingerprint; @@ -58,6 +59,7 @@ public class KeyRingInfo { private final Signatures signatures; private final Date referenceDate; private final String primaryUserId; + private final RevocationState revocationState; /** * Evaluate the key ring at creation time of the given signature. @@ -101,6 +103,16 @@ public class KeyRingInfo { this.signatures = new Signatures(keys, validationDate, policy); this.referenceDate = validationDate; this.primaryUserId = findPrimaryUserId(); + this.revocationState = findRevocationState(); + } + + private RevocationState findRevocationState() { + PGPSignature revocation = signatures.primaryKeyRevocation; + if (revocation != null) { + return SignatureUtils.isHardRevocation(revocation) ? + RevocationState.hardRevoked() : RevocationState.softRevoked(revocation.getCreationTime()); + } + return RevocationState.notRevoked(); } /** @@ -650,13 +662,17 @@ public class KeyRingInfo { return mostRecent; } + public RevocationState getRevocationState() { + return revocationState; + } + /** * Return the date on which the primary key was revoked, or null if it has not yet been revoked. * * @return revocation date or null */ public @Nullable Date getRevocationDate() { - return getRevocationSelfSignature() == null ? null : getRevocationSelfSignature().getCreationTime(); + return getRevocationState().isSoftRevocation() ? getRevocationState().getDate() : null; } /** diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java index f49d5a46..61e09477 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/info/KeyRingInfoTest.java @@ -49,6 +49,7 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.UnprotectedKeysProtector; import org.pgpainless.key.util.KeyRingUtils; +import org.pgpainless.key.util.RevocationAttributes; import org.pgpainless.key.util.UserId; import org.pgpainless.util.DateUtil; import org.pgpainless.util.Passphrase; @@ -105,7 +106,12 @@ public class KeyRingInfoTest { assertNull(sInfo.getRevocationDate()); assertNull(pInfo.getRevocationDate()); Date revocationDate = DateUtil.now(); - PGPSecretKeyRing revoked = PGPainless.modifyKeyRing(secretKeys).revoke(new UnprotectedKeysProtector()).done(); + PGPSecretKeyRing revoked = PGPainless.modifyKeyRing(secretKeys).revoke( + new UnprotectedKeysProtector(), + RevocationAttributes.createKeyRevocation() + .withReason(RevocationAttributes.Reason.KEY_RETIRED) + .withoutDescription() + ).done(); KeyRingInfo rInfo = PGPainless.inspectKeyRing(revoked); assertNotNull(rInfo.getRevocationDate()); assertEquals(revocationDate.getTime(), rInfo.getRevocationDate().getTime(), 5);