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:
parent
c73905d179
commit
0cc884523c
2 changed files with 24 additions and 2 deletions
|
@ -36,6 +36,7 @@ import org.pgpainless.algorithm.EncryptionPurpose;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.algorithm.KeyFlag;
|
import org.pgpainless.algorithm.KeyFlag;
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||||
|
import org.pgpainless.algorithm.RevocationState;
|
||||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
|
||||||
import org.pgpainless.exception.KeyException;
|
import org.pgpainless.exception.KeyException;
|
||||||
import org.pgpainless.key.OpenPgpFingerprint;
|
import org.pgpainless.key.OpenPgpFingerprint;
|
||||||
|
@ -58,6 +59,7 @@ public class KeyRingInfo {
|
||||||
private final Signatures signatures;
|
private final Signatures signatures;
|
||||||
private final Date referenceDate;
|
private final Date referenceDate;
|
||||||
private final String primaryUserId;
|
private final String primaryUserId;
|
||||||
|
private final RevocationState revocationState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate the key ring at creation time of the given signature.
|
* 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.signatures = new Signatures(keys, validationDate, policy);
|
||||||
this.referenceDate = validationDate;
|
this.referenceDate = validationDate;
|
||||||
this.primaryUserId = findPrimaryUserId();
|
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;
|
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 the date on which the primary key was revoked, or null if it has not yet been revoked.
|
||||||
*
|
*
|
||||||
* @return revocation date or null
|
* @return revocation date or null
|
||||||
*/
|
*/
|
||||||
public @Nullable Date getRevocationDate() {
|
public @Nullable Date getRevocationDate() {
|
||||||
return getRevocationSelfSignature() == null ? null : getRevocationSelfSignature().getCreationTime();
|
return getRevocationState().isSoftRevocation() ? getRevocationState().getDate() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
import org.pgpainless.key.protection.UnprotectedKeysProtector;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
|
import org.pgpainless.key.util.RevocationAttributes;
|
||||||
import org.pgpainless.key.util.UserId;
|
import org.pgpainless.key.util.UserId;
|
||||||
import org.pgpainless.util.DateUtil;
|
import org.pgpainless.util.DateUtil;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
|
@ -105,7 +106,12 @@ public class KeyRingInfoTest {
|
||||||
assertNull(sInfo.getRevocationDate());
|
assertNull(sInfo.getRevocationDate());
|
||||||
assertNull(pInfo.getRevocationDate());
|
assertNull(pInfo.getRevocationDate());
|
||||||
Date revocationDate = DateUtil.now();
|
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);
|
KeyRingInfo rInfo = PGPainless.inspectKeyRing(revoked);
|
||||||
assertNotNull(rInfo.getRevocationDate());
|
assertNotNull(rInfo.getRevocationDate());
|
||||||
assertEquals(revocationDate.getTime(), rInfo.getRevocationDate().getTime(), 5);
|
assertEquals(revocationDate.getTime(), rInfo.getRevocationDate().getTime(), 5);
|
||||||
|
|
Loading…
Reference in a new issue