Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update sigstore-conformance tests #512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
- name: Unpack sigstore-java distribution
run: tar -xvf ${{ github.workspace }}/sigstore-cli/build/distributions/sigstore-cli-*.tar --strip-components 1

- uses: sigstore/sigstore-conformance@064fb32a890c30235f305281f3509c5e65e6f9e5 # tag=v0.0.4
- uses: sigstore/sigstore-conformance@1abc82cdefe80bd907855d8447f903ba8b4918e0 # v0.0.6
with:
entrypoint: ${{ github.workspace }}/bin/sigstore-cli
32 changes: 32 additions & 0 deletions sigstore-cli/src/main/java/dev/sigstore/cli/Policy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2023 The Sigstore Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.sigstore.cli;

import picocli.CommandLine.Option;

public class Policy {
@Option(
names = {"--certificate-identity"},
description = "subject alternative name in certificate",
required = true)
String certificateSan;

@Option(
names = {"--certificate-oidc-issuer"},
description = "sigstore issuer in certificate",
required = true)
String certificateIssuer;
}
2 changes: 1 addition & 1 deletion sigstore-cli/src/main/java/dev/sigstore/cli/Sigstore.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Command(
name = "sigstore",
mixinStandardHelpOptions = true,
subcommands = {Sign.class, Verify.class})
subcommands = {Sign.class, Verify.class, VerifyBundle.class})
public class Sigstore {
@Spec CommandSpec spec;

Expand Down
15 changes: 0 additions & 15 deletions sigstore-cli/src/main/java/dev/sigstore/cli/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.concurrent.Callable;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

@Command(name = "verify", description = "verify an artifact")
Expand All @@ -47,20 +46,6 @@ public class Verify implements Callable<Integer> {
@ArgGroup(multiplicity = "0..1", exclusive = false)
Policy policy;

static class Policy {
@Option(
names = {"--certificate-identity"},
description = "subject alternative name in certificate",
required = true)
private String certificateSan;

@Option(
names = {"--certificate-oidc-issuer"},
description = "sigstore issuer in certificate",
required = true)
private String certificateIssuer;
}

@Override
public Integer call() throws Exception {
byte[] digest = asByteSource(artifact.toFile()).hash(Hashing.sha256()).asBytes();
Expand Down
72 changes: 72 additions & 0 deletions sigstore-cli/src/main/java/dev/sigstore/cli/VerifyBundle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2023 The Sigstore Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.sigstore.cli;

import static com.google.common.io.Files.newReader;

import dev.sigstore.KeylessSignature;
import dev.sigstore.KeylessVerificationRequest;
import dev.sigstore.KeylessVerificationRequest.CertificateIdentity;
import dev.sigstore.KeylessVerificationRequest.VerificationOptions;
import dev.sigstore.KeylessVerifier;
import dev.sigstore.bundle.BundleFactory;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

@Command(name = "verify-bundle", description = "verify an artifact using a sigstore bundle")
public class VerifyBundle implements Callable<Integer> {
@Parameters(arity = "1", paramLabel = "<artifact>", description = "artifact to verify")
Path artifact;

@Option(
names = {"--bundle"},
description = "path to bundle file",
required = true)
Path bundleFile;

@ArgGroup(multiplicity = "0..1", exclusive = false)
Policy policy;

@Override
public Integer call() throws Exception {
KeylessSignature keylessSignature =
BundleFactory.readBundle(newReader(bundleFile.toFile(), StandardCharsets.UTF_8));

var verificationOptionsBuilder = VerificationOptions.builder();
if (policy != null) {
verificationOptionsBuilder.addCertificateIdentities(
CertificateIdentity.builder()
.issuer(policy.certificateIssuer)
.subjectAlternativeName(policy.certificateSan)
.build());
}
var verificationOptions = verificationOptionsBuilder.isOnline(true).build();

var verifier = new KeylessVerifier.Builder().sigstorePublicDefaults().build();
verifier.verify(
artifact,
KeylessVerificationRequest.builder()
.keylessSignature(keylessSignature)
.verificationOptions(verificationOptions)
.build());
return 0;
}
}