-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bundle specific verification options Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
6146940
commit f879e24
Showing
5 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
sigstore-cli/src/main/java/dev/sigstore/cli/VerifyBundle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |