@@ -553,6 +553,94 @@ public void testVerify_unsupportedRekorVersion_rekorV2() throws Exception {
553
553
Assertions .assertEquals ("Unsupported hashedrekord version" , ex .getMessage ());
554
554
}
555
555
556
+ @ Test
557
+ public void testVerify_validRfc3161Timestamp () throws Exception {
558
+ var artifactUrl = Resources .getResource ("dev/sigstore/samples/bundles/artifact.txt" );
559
+ var artifactBytes = Resources .toByteArray (artifactUrl );
560
+ var artifactDigest = Hashing .sha256 ().hashBytes (artifactBytes ).asBytes ();
561
+
562
+ var bundleFile =
563
+ Resources .toString (
564
+ Resources .getResource ("dev/sigstore/samples/bundles/bundle-with-timestamp.sigstore" ),
565
+ StandardCharsets .UTF_8 );
566
+ var verifier = KeylessVerifier .builder ().sigstoreStagingDefaults ().build ();
567
+
568
+ Assertions .assertDoesNotThrow (
569
+ () ->
570
+ verifier .verify (
571
+ artifactDigest ,
572
+ Bundle .from (new StringReader (bundleFile )),
573
+ VerificationOptions .empty ()));
574
+ }
575
+
576
+ @ Test
577
+ public void testVerify_invalidRfc3161Timestamp () throws Exception {
578
+ var tsRespBytesInvalid =
579
+ Resources .toByteArray (
580
+ Resources .getResource (
581
+ "dev/sigstore/samples/timestamp-response/invalid/sigstore_tsa_response_invalid.tsr" ));
582
+
583
+ var artifactUrl = Resources .getResource ("dev/sigstore/samples/bundles/artifact.txt" );
584
+ var artifactBytes = Resources .toByteArray (artifactUrl );
585
+ var artifactDigest = Hashing .sha256 ().hashBytes (artifactBytes ).asBytes ();
586
+
587
+ var bundleFile =
588
+ Resources .toString (
589
+ Resources .getResource ("dev/sigstore/samples/bundles/bundle.v3.sigstore" ),
590
+ StandardCharsets .UTF_8 );
591
+
592
+ var verifier = KeylessVerifier .builder ().sigstorePublicDefaults ().build ();
593
+
594
+ var baseBundle = Bundle .from (new StringReader (bundleFile ));
595
+ var testBundle =
596
+ ImmutableBundle .builder ()
597
+ .from (baseBundle )
598
+ .timestamps (List .of (createTimestamp (tsRespBytesInvalid )))
599
+ .build ();
600
+ var ex =
601
+ Assertions .assertThrows (
602
+ KeylessVerificationException .class ,
603
+ () -> verifier .verify (artifactDigest , testBundle , VerificationOptions .empty ()));
604
+ MatcherAssert .assertThat (
605
+ ex .getMessage (),
606
+ CoreMatchers .equalTo (
607
+ "RFC3161 timestamp verification failed: Failed to parse TimeStampResponse" ));
608
+ }
609
+
610
+ @ Test
611
+ public void testVerify_invalidTimestampGenTime () throws Exception {
612
+ var tsRespBytesInvalidGenTime =
613
+ Resources .toByteArray (
614
+ Resources .getResource (
615
+ "dev/sigstore/samples/timestamp-response/valid/sigstore_tsa_response_with_embedded_certs.tsr" ));
616
+
617
+ var artifactResourcePath = "dev/sigstore/samples/bundles/artifact.txt" ;
618
+ var artifactBytes = Resources .toByteArray (Resources .getResource (artifactResourcePath ));
619
+ var artifactDigest = Hashing .sha256 ().hashBytes (artifactBytes ).asBytes ();
620
+
621
+ var bundleFileContent =
622
+ Resources .toString (
623
+ Resources .getResource ("dev/sigstore/samples/bundles/bundle.v3.sigstore" ),
624
+ StandardCharsets .UTF_8 );
625
+ var verifier = KeylessVerifier .builder ().sigstorePublicDefaults ().build ();
626
+
627
+ var baseBundle = Bundle .from (new StringReader (bundleFileContent ));
628
+ var testBundle =
629
+ ImmutableBundle .builder ()
630
+ .from (baseBundle )
631
+ .timestamps (List .of (createTimestamp (tsRespBytesInvalidGenTime )))
632
+ .build ();
633
+
634
+ var ex =
635
+ Assertions .assertThrows (
636
+ KeylessVerificationException .class ,
637
+ () -> verifier .verify (artifactDigest , testBundle , VerificationOptions .empty ()));
638
+ MatcherAssert .assertThat (
639
+ ex .getMessage (),
640
+ CoreMatchers .startsWith (
641
+ "RFC3161 timestamp verification failed: Certificate was not verifiable against TSAs" ));
642
+ }
643
+
556
644
@ Test
557
645
public void testVerify_validRfc3161Timestamp_rekorV1 () throws Exception {
558
646
var artifact = Resources .getResource ("dev/sigstore/samples/bundles/artifact.txt" ).getPath ();
@@ -642,32 +730,6 @@ public void testVerify_invalidSet_validRfc3161Timestamp_rekorV1() throws Excepti
642
730
ex .getCause ().getMessage (), CoreMatchers .equalTo ("Entry SET was not valid" ));
643
731
}
644
732
645
- @ Test
646
- public void testVerify_validSet_invalidRfc3161Timestamp_rekorV1 () throws Exception {
647
- var bundleFile =
648
- Resources .toString (
649
- Resources .getResource ("dev/sigstore/samples/bundles/bundle.v3.sigstore" ),
650
- StandardCharsets .UTF_8 );
651
- var baseBundle = Bundle .from (new StringReader (bundleFile ));
652
-
653
- var tsRespBytesInvalid =
654
- Resources .toByteArray (
655
- Resources .getResource (
656
- "dev/sigstore/samples/timestamp-response/invalid/sigstore_tsa_response_invalid.tsr" ));
657
-
658
- var testBundle =
659
- ImmutableBundle .builder ()
660
- .from (baseBundle )
661
- .timestamps (List .of (createTimestamp (tsRespBytesInvalid )))
662
- .build ();
663
-
664
- var artifact = Resources .getResource ("dev/sigstore/samples/bundles/artifact.txt" ).getPath ();
665
- var verifier = KeylessVerifier .builder ().sigstorePublicDefaults ().build ();
666
-
667
- Assertions .assertDoesNotThrow (
668
- () -> verifier .verify (Path .of (artifact ), testBundle , VerificationOptions .empty ()));
669
- }
670
-
671
733
private Bundle .Timestamp createTimestamp (byte [] rfc3161Bytes ) {
672
734
return () -> rfc3161Bytes ;
673
735
}
0 commit comments