Sanitize signatures

This commit is contained in:
Paul Schaub 2024-12-27 14:30:33 +01:00
parent e85353a4f4
commit eca3ad56b8
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 19 additions and 11 deletions

View file

@ -3,6 +3,7 @@ package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.openpgp.PGPSessionKey; import org.bouncycastle.openpgp.PGPSessionKey;
import org.bouncycastle.openpgp.api.OpenPGPMessageInputStream; import org.bouncycastle.openpgp.api.OpenPGPMessageInputStream;
import org.bouncycastle.openpgp.api.OpenPGPSignature; import org.bouncycastle.openpgp.api.OpenPGPSignature;
import org.bouncycastle.openpgp.api.exception.MalformedPGPSignatureException;
import org.bouncycastle.util.encoders.Hex; import org.bouncycastle.util.encoders.Hex;
import sop.SessionKey; import sop.SessionKey;
import sop.Verification; import sop.Verification;
@ -27,6 +28,8 @@ public abstract class AbstractBCOperation
{ {
List<Verification> verifications = new ArrayList<>(); List<Verification> verifications = new ArrayList<>();
for (OpenPGPSignature.OpenPGPDocumentSignature sig : signatures) for (OpenPGPSignature.OpenPGPDocumentSignature sig : signatures)
{
try
{ {
if (sig.isValid()) if (sig.isValid())
{ {
@ -36,6 +39,11 @@ public abstract class AbstractBCOperation
verifications.add(verification); verifications.add(verification);
} }
} }
catch (MalformedPGPSignatureException e)
{
// ignore malformed sig
}
}
return verifications; return verifications;
} }
} }

View file

@ -24,8 +24,6 @@ public class BCDecrypt
extends AbstractBCOperation extends AbstractBCOperation
implements Decrypt { implements Decrypt {
private Date notBefore = new Date(Long.MAX_VALUE); // end of time
private Date notAfter = new Date(); // now
private char[] keyPassword; private char[] keyPassword;
private final OpenPGPMessageProcessor processor = new OpenPGPMessageProcessor(); private final OpenPGPMessageProcessor processor = new OpenPGPMessageProcessor();
@ -55,14 +53,14 @@ public class BCDecrypt
@NotNull @NotNull
@Override @Override
public Decrypt verifyNotBefore(@NotNull Date date) throws SOPGPException.UnsupportedOption { public Decrypt verifyNotBefore(@NotNull Date date) throws SOPGPException.UnsupportedOption {
this.notBefore = date; processor.verifyNotBefore(date);
return this; return this;
} }
@NotNull @NotNull
@Override @Override
public Decrypt verifyNotAfter(@NotNull Date date) throws SOPGPException.UnsupportedOption { public Decrypt verifyNotAfter(@NotNull Date date) throws SOPGPException.UnsupportedOption {
this.notAfter = date; processor.verifyNotAfter(date);
return this; return this;
} }

View file

@ -3,7 +3,6 @@ package org.pgpainless.bouncycastle.sop.operation;
import org.bouncycastle.openpgp.api.OpenPGPCertificate; import org.bouncycastle.openpgp.api.OpenPGPCertificate;
import org.bouncycastle.openpgp.api.OpenPGPDetachedSignatureProcessor; import org.bouncycastle.openpgp.api.OpenPGPDetachedSignatureProcessor;
import org.bouncycastle.openpgp.api.OpenPGPSignature; import org.bouncycastle.openpgp.api.OpenPGPSignature;
import org.bouncycastle.util.encoders.Hex;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import sop.Verification; import sop.Verification;
import sop.exception.SOPGPException; import sop.exception.SOPGPException;
@ -12,7 +11,6 @@ import sop.operation.VerifySignatures;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -37,11 +35,13 @@ public class BCDetachedVerify
@Override @Override
public DetachedVerify notBefore(@NotNull Date date) throws SOPGPException.UnsupportedOption { public DetachedVerify notBefore(@NotNull Date date) throws SOPGPException.UnsupportedOption {
processor.verifyNotBefore(date);
return this; return this;
} }
@Override @Override
public DetachedVerify notAfter(@NotNull Date date) throws SOPGPException.UnsupportedOption { public DetachedVerify notAfter(@NotNull Date date) throws SOPGPException.UnsupportedOption {
processor.verifyNotAfter(date);
return this; return this;
} }

View file

@ -49,11 +49,13 @@ public class BCInlineVerify
@Override @Override
public InlineVerify notBefore(@NotNull Date date) throws SOPGPException.UnsupportedOption { public InlineVerify notBefore(@NotNull Date date) throws SOPGPException.UnsupportedOption {
processor.verifyNotBefore(date);
return this; return this;
} }
@Override @Override
public InlineVerify notAfter(@NotNull Date date) throws SOPGPException.UnsupportedOption { public InlineVerify notAfter(@NotNull Date date) throws SOPGPException.UnsupportedOption {
processor.verifyNotAfter(date);
return this; return this;
} }