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

Integrate RevocationState into KeyRingInfo class

This commit is contained in:
Paul Schaub 2022-08-29 11:30:10 +02:00
parent c73905d179
commit 0cc884523c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 24 additions and 2 deletions

View file

@ -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;
}
/**

View file

@ -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);