Skip to content

Commit 6b3f3bd

Browse files
authored
Merge pull request #771 from sigstore/minor-updates
Add test with verification and bundle reader
2 parents e0ff9af + 90483ef commit 6b3f3bd

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

sigstore-cli/src/main/java/dev/sigstore/cli/Verify.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public Integer call() throws Exception {
130130
fetcher.getEntryFromRekor(digest, Certificates.getLeaf(certPath), signature))
131131
.build();
132132
} else {
133-
bundle =
134-
Bundle.from(Files.newBufferedReader(signatureFiles.bundleFile, StandardCharsets.UTF_8));
133+
bundle = Bundle.from(signatureFiles.bundleFile, StandardCharsets.UTF_8);
135134
}
136135

137136
var verificationOptionsBuilder = VerificationOptions.builder();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
import com.google.common.base.Preconditions;
1919
import dev.sigstore.rekor.client.RekorEntry;
20+
import java.io.IOException;
2021
import java.io.Reader;
22+
import java.nio.charset.Charset;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
2125
import java.security.cert.CertPath;
2226
import java.util.List;
2327
import java.util.Optional;
@@ -147,10 +151,16 @@ public interface Timestamp {
147151
byte[] getRfc3161Timestamp();
148152
}
149153

154+
/** Read a json formatted bundle. */
150155
public static Bundle from(Reader bundleJson) throws BundleParseException {
151156
return BundleReader.readBundle(bundleJson);
152157
}
153158

159+
/** Read a json formatted bundle from a file. */
160+
public static Bundle from(Path file, Charset cs) throws BundleParseException, IOException {
161+
return BundleReader.readBundle(Files.newBufferedReader(file, cs));
162+
}
163+
154164
@Lazy
155165
public String toJson() {
156166
return BundleWriter.writeBundle(this);

sigstore-java/src/test/java/dev/sigstore/KeylessVerifierTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ public void verifyBundle(String artifactResourcePath, String bundleResourcePath)
118118
Path.of(artifact), Bundle.from(new StringReader(bundleFile)), VerificationOptions.empty());
119119
}
120120

121+
@Test
122+
public void verifyWithVerificationOptions() throws Exception {
123+
var bundleFile =
124+
Resources.toString(
125+
Resources.getResource("dev/sigstore/samples/bundles/bundle.sigstore"),
126+
StandardCharsets.UTF_8);
127+
var artifact = Resources.getResource("dev/sigstore/samples/bundles/artifact.txt").getPath();
128+
129+
var verifier = KeylessVerifier.builder().sigstorePublicDefaults().build();
130+
verifier.verify(
131+
Path.of(artifact),
132+
Bundle.from(new StringReader(bundleFile)),
133+
VerificationOptions.builder()
134+
.addCertificateMatchers(
135+
CertificateMatcher.fulcio()
136+
.subjectAlternativeName(StringMatcher.string("[email protected]"))
137+
.issuer(StringMatcher.string("https://accounts.google.com"))
138+
.build())
139+
.build());
140+
}
141+
121142
@Test
122143
public void verifyCertificateMatches_noneProvided() throws Exception {
123144
var verifier = KeylessVerifier.builder().sigstorePublicDefaults().build();

0 commit comments

Comments
 (0)