3737import java .security .cert .X509Certificate ;
3838import java .util .List ;
3939import java .util .stream .Stream ;
40- import java .util .zip .ZipEntry ;
41- import java .util .zip .ZipInputStream ;
4240import org .hamcrest .CoreMatchers ;
4341import org .hamcrest .MatcherAssert ;
4442import org .junit .jupiter .api .Assertions ;
@@ -421,9 +419,7 @@ public void verifyCertificateMatches_noneMatch() throws Exception {
421419 .issuer (StringMatcher .string ("not-match-again" ))
422420 .build ())));
423421 Assertions .assertEquals (
424- "No provided certificate identities matched values in certificate: [{issuer:'String:"
425- + " not-match',san:'String: not-match'},{issuer:'String: not-match-again',san:'String:"
426- + " not-match-again'}]" ,
422+ "No provided certificate identities matched values in certificate: [{issuer:'String: not-match',san:'String: not-match'},{issuer:'String: not-match-again',san:'String: not-match-again'}]" ,
427423 ex .getMessage ());
428424 }
429425
@@ -887,22 +883,11 @@ public void testVerify_wrongArtifactHashAlgorithm() throws Exception {
887883 "Provided artifact digest does not match digest used for verification" ));
888884 }
889885
890- // The fixture below is a real SLSA build-provenance attestation produced by GitHub Actions for a
891- // *private* repository. Attestations for private repositories are signed by GitHub's own Sigstore
892- // instance, which (unlike the public-good instance) does not publish to a transparency log and
893- // does not use certificate transparency: the bundle carries zero tlog entries and relies on a
894- // signed RFC 3161 timestamp for trusted time, and the trust root that GitHub distributes for it
895- // (via `gh attestation trusted-root`) contains zero CT logs. Verifying such a bundle therefore
896- // requires a policy that disables both transparency-log and certificate-transparency checks.
897- //
898- // The zip file contains two files:
899- // - attestation.sigstore.json : the sigstore bundle (DSSE, in-toto SLSA provenance predicate)
900- // - trusted_root.jsonl : the trust roots as JSON Lines. `gh attestation trusted-root`
901- // emits more than one (public-good and GitHub); sigstore-java
902- // consumes a single trust root, so the tests below select the
903- // GitHub one (the line describing the fulcio.githubapp.com CA).
904- private static final String GH_PRIVATE_ATTESTATION_ZIP =
905- "dev/sigstore/samples/bundles/bundle-github-private-no-tlog.zip" ;
886+ // A real SLSA build-provenance attestation from a GitHub *private* repository: no
887+ // transparency-log entry, no CT log, signed RFC 3161 timestamp only. See the README in the
888+ // fixture directory for provenance and how it was obtained.
889+ private static final String GH_PRIVATE_DIR =
890+ "dev/sigstore/samples/bundles/github-private-no-tlog/" ;
906891 private static final String GH_PRIVATE_SIGNER_SAN =
907892 "https://github.com/neverendingsupport/slsa-attestations/.github/workflows/attest.yml@9f6d9dc1bfc02986955721eb15f89ad618f1cedb" ;
908893 private static final String GH_PRIVATE_OIDC_ISSUER =
@@ -980,15 +965,15 @@ private static ImmutableVerificationOptions.Builder gitHubPrivateOptions() {
980965 private static Bundle gitHubPrivateBundle () throws Exception {
981966 return Bundle .from (
982967 new StringReader (
983- new String (
984- readZipEntry ( GH_PRIVATE_ATTESTATION_ZIP , "attestation.sigstore.json" ),
968+ Resources . toString (
969+ Resources . getResource ( GH_PRIVATE_DIR + "attestation.sigstore.json" ),
985970 StandardCharsets .UTF_8 )));
986971 }
987972
988973 private static KeylessVerifier gitHubPrivateVerifier (Path tempDir ) throws Exception {
989974 var jsonl =
990- new String (
991- readZipEntry ( GH_PRIVATE_ATTESTATION_ZIP , "trusted_root.jsonl" ), StandardCharsets .UTF_8 );
975+ Resources . toString (
976+ Resources . getResource ( GH_PRIVATE_DIR + "trusted_root.jsonl" ), StandardCharsets .UTF_8 );
992977 var gitHubTrustedRoot =
993978 jsonl
994979 .lines ()
@@ -1003,16 +988,4 @@ private static KeylessVerifier gitHubPrivateVerifier(Path tempDir) throws Except
1003988 .trustedRootProvider (TrustedRootProvider .from (trustedRootPath ))
1004989 .build ();
1005990 }
1006-
1007- private static byte [] readZipEntry (String zipResource , String entryName ) throws Exception {
1008- try (var zis = new ZipInputStream (Resources .getResource (zipResource ).openStream ())) {
1009- ZipEntry entry ;
1010- while ((entry = zis .getNextEntry ()) != null ) {
1011- if (entry .getName ().equals (entryName )) {
1012- return zis .readAllBytes ();
1013- }
1014- }
1015- }
1016- throw new IllegalStateException ("entry '" + entryName + "' not found in " + zipResource );
1017- }
1018991}
0 commit comments