|
61 | 61 | import java.security.cert.CertificateNotYetValidException; |
62 | 62 | import java.security.cert.X509Certificate; |
63 | 63 | import java.security.spec.InvalidKeySpecException; |
| 64 | +import java.time.Instant; |
64 | 65 | import java.util.Arrays; |
65 | 66 | import java.util.Base64; |
| 67 | +import java.util.Date; |
66 | 68 | import java.util.List; |
67 | 69 | import java.util.Objects; |
68 | 70 | import java.util.stream.Collectors; |
@@ -183,20 +185,37 @@ public void verify(byte[] artifactDigest, Bundle bundle, VerificationOptions opt |
183 | 185 | signature = dsseEnvelope.getSignature(); |
184 | 186 | } |
185 | 187 |
|
186 | | - verifyTimestamps(leafCert, bundle.getTimestamps(), signature); |
187 | | - |
188 | 188 | try { |
189 | 189 | rekorVerifier.verifyEntry(rekorEntry); |
190 | 190 | } catch (RekorVerificationException ex) { |
191 | 191 | throw new KeylessVerificationException("Transparency log entry could not be verified", ex); |
192 | 192 | } |
| 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); |
193 | 199 | } |
194 | 200 |
|
195 | 201 | 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) |
197 | 206 | 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 | + } |
200 | 219 | } |
201 | 220 | for (Bundle.Timestamp timestamp : timestamps) { |
202 | 221 | byte[] tsBytes = timestamp.getRfc3161Timestamp(); |
|
0 commit comments