Allow overriding evluation date in SigningOptions

This commit is contained in:
Paul Schaub 2023-08-03 14:57:31 +02:00
parent 16a4836f8a
commit db7e1ce942
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 16 additions and 4 deletions

View File

@ -97,12 +97,24 @@ public final class SigningOptions {
private final Map<SubkeyIdentifier, SigningMethod> signingMethods = new HashMap<>(); private final Map<SubkeyIdentifier, SigningMethod> signingMethods = new HashMap<>();
private HashAlgorithm hashAlgorithmOverride; private HashAlgorithm hashAlgorithmOverride;
private Date evaluationDate = new Date();
@Nonnull @Nonnull
public static SigningOptions get() { public static SigningOptions get() {
return new SigningOptions(); return new SigningOptions();
} }
/**
* Override the evaluation date for signing keys with the given date.
*
* @param evaluationDate new evaluation date
* @return this
*/
public SigningOptions setEvaluationDate(@Nonnull Date evaluationDate) {
this.evaluationDate = evaluationDate;
return this;
}
/** /**
* Sign the message using an inline signature made by the provided signing key. * Sign the message using an inline signature made by the provided signing key.
* *
@ -212,7 +224,7 @@ public final class SigningOptions {
@Nonnull DocumentSignatureType signatureType, @Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketsCallback) @Nullable BaseSignatureSubpackets.Callback subpacketsCallback)
throws KeyException, PGPException { throws KeyException, PGPException {
KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date()); KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
if (userId != null && !keyRingInfo.isUserIdValid(userId)) { if (userId != null && !keyRingInfo.isUserIdValid(userId)) {
throw new KeyException.UnboundUserIdException( throw new KeyException.UnboundUserIdException(
OpenPgpFingerprint.of(secretKey), OpenPgpFingerprint.of(secretKey),
@ -280,7 +292,7 @@ public final class SigningOptions {
long keyId, long keyId,
@Nonnull DocumentSignatureType signatureType, @Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketsCallback) throws PGPException { @Nullable BaseSignatureSubpackets.Callback subpacketsCallback) throws PGPException {
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey); KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys(); List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
if (signingPubKeys.isEmpty()) { if (signingPubKeys.isEmpty()) {
@ -418,7 +430,7 @@ public final class SigningOptions {
@Nonnull DocumentSignatureType signatureType, @Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketCallback) @Nullable BaseSignatureSubpackets.Callback subpacketCallback)
throws PGPException { throws PGPException {
KeyRingInfo keyRingInfo = new KeyRingInfo(secretKey, new Date()); KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
if (userId != null && !keyRingInfo.isUserIdValid(userId)) { if (userId != null && !keyRingInfo.isUserIdValid(userId)) {
throw new KeyException.UnboundUserIdException( throw new KeyException.UnboundUserIdException(
OpenPgpFingerprint.of(secretKey), OpenPgpFingerprint.of(secretKey),
@ -485,7 +497,7 @@ public final class SigningOptions {
long keyId, long keyId,
@Nonnull DocumentSignatureType signatureType, @Nonnull DocumentSignatureType signatureType,
@Nullable BaseSignatureSubpackets.Callback subpacketsCallback) throws PGPException { @Nullable BaseSignatureSubpackets.Callback subpacketsCallback) throws PGPException {
KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey); KeyRingInfo keyRingInfo = PGPainless.inspectKeyRing(secretKey, evaluationDate);
List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys(); List<PGPPublicKey> signingPubKeys = keyRingInfo.getSigningSubkeys();
if (signingPubKeys.isEmpty()) { if (signingPubKeys.isEmpty()) {