Skip to content

Commit 87e2876

Browse files
committed
Re-add and enhance SET verification in KeylessVerifier
Signed-off-by: Aaron Lew <64337293+aaronlew02@users.noreply.github.com>
1 parent f6934e5 commit 87e2876

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

sigstore-java/src/main/java/dev/sigstore/KeylessVerifier.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@
6161
import java.security.cert.CertificateNotYetValidException;
6262
import java.security.cert.X509Certificate;
6363
import java.security.spec.InvalidKeySpecException;
64+
import java.time.Instant;
6465
import java.util.Arrays;
6566
import java.util.Base64;
67+
import java.util.Date;
6668
import java.util.List;
6769
import java.util.Objects;
6870
import java.util.stream.Collectors;
@@ -183,20 +185,37 @@ public void verify(byte[] artifactDigest, Bundle bundle, VerificationOptions opt
183185
signature = dsseEnvelope.getSignature();
184186
}
185187

186-
verifyTimestamps(leafCert, bundle.getTimestamps(), signature);
187-
188188
try {
189189
rekorVerifier.verifyEntry(rekorEntry);
190190
} catch (RekorVerificationException ex) {
191191
throw new KeylessVerificationException("Transparency log entry could not be verified", ex);
192192
}
193+
194+
// if entry was verified and has a SET, get time from it
195+
var set = rekorEntry.getVerification().getSignedEntryTimestamp();
196+
var entryTime = set != null ? rekorEntry.getIntegratedTimeInstant() : null;
197+
198+
verifyTimestamps(leafCert, bundle.getTimestamps(), entryTime, signature);
193199
}
194200

195201
private void verifyTimestamps(
196-
X509Certificate leafCert, List<Bundle.Timestamp> timestamps, byte[] signature)
202+
X509Certificate leafCert,
203+
List<Bundle.Timestamp> timestamps,
204+
Instant entryTime,
205+
byte[] signature)
197206
throws KeylessVerificationException {
198-
if (timestamps == null || timestamps.isEmpty()) {
199-
return;
207+
if (timestamps.isEmpty() && entryTime == null) {
208+
throw new KeylessVerificationException("No valid timestamps found in bundle");
209+
}
210+
if (entryTime != null) {
211+
var entryDate = Date.from(entryTime);
212+
try {
213+
leafCert.checkValidity(entryDate);
214+
} catch (CertificateNotYetValidException e) {
215+
throw new KeylessVerificationException("Signing time was before certificate validity", e);
216+
} catch (CertificateExpiredException e) {
217+
throw new KeylessVerificationException("Signing time was after certificate expiry", e);
218+
}
200219
}
201220
for (Bundle.Timestamp timestamp : timestamps) {
202221
byte[] tsBytes = timestamp.getRfc3161Timestamp();

sigstore-java/src/main/java/dev/sigstore/bundle/Bundle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ protected void checkOnlyOneSignature() {
7171
@Value.Check
7272
protected void checkAtLeastOneTimestamp() {
7373
for (var entry : getEntries()) {
74-
if (entry.getVerification().getSignedEntryTimestamp() != null) {
74+
if (entry.getVerification().getSignedEntryTimestamp() != null
75+
&& entry.getIntegratedTime() > 0) {
7576
return;
7677
}
7778
}

0 commit comments

Comments
 (0)