Skip to content

Commit a16165d

Browse files
authored
Output unsigned (#31)
Gives us the ability to output the unsigned attestation and sign it using other tooling.
1 parent ff5db57 commit a16165d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

sourcetool/cmd/checklevel.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
)
1818

1919
type CheckLevelArgs struct {
20-
commit, owner, repo, branch, outputVsa string
21-
minDays int
20+
commit, owner, repo, branch, outputVsa, outputUnsignedVsa string
21+
minDays int
2222
}
2323

2424
// checklevelCmd represents the checklevel command
@@ -32,12 +32,12 @@ var (
3232
3333
This is meant to be run within the corresponding GitHub Actions workflow.`,
3434
Run: func(cmd *cobra.Command, args []string) {
35-
doCheckLevel(checkLevelArgs.commit, checkLevelArgs.owner, checkLevelArgs.repo, checkLevelArgs.branch, checkLevelArgs.minDays, checkLevelArgs.outputVsa)
35+
doCheckLevel(checkLevelArgs.commit, checkLevelArgs.owner, checkLevelArgs.repo, checkLevelArgs.branch, checkLevelArgs.minDays, checkLevelArgs.outputVsa, checkLevelArgs.outputUnsignedVsa)
3636
},
3737
}
3838
)
3939

40-
func doCheckLevel(commit, owner, repo, branch string, minDays int, outputVsa string) {
40+
func doCheckLevel(commit, owner, repo, branch string, minDays int, outputVsa, outputUnsignedVsa string) {
4141
if commit == "" || owner == "" || repo == "" || branch == "" {
4242
log.Fatal("Must set commit, owner, repo, and branch flags.")
4343
}
@@ -51,6 +51,17 @@ func doCheckLevel(commit, owner, repo, branch string, minDays int, outputVsa str
5151
}
5252
fmt.Print(sourceLevel)
5353

54+
if outputUnsignedVsa != "" {
55+
unsignedVsa, err := vsa.CreateUnsignedSourceVsa(owner, repo, commit, sourceLevel)
56+
if err != nil {
57+
log.Fatal(err)
58+
}
59+
err = os.WriteFile(outputUnsignedVsa, []byte(unsignedVsa), 0644)
60+
if err != nil {
61+
log.Fatal(err)
62+
}
63+
}
64+
5465
if outputVsa != "" {
5566
// This will output in the sigstore bundle format.
5667
signedVsa, err := vsa.CreateSignedSourceVsa(owner, repo, commit, sourceLevel)
@@ -75,4 +86,5 @@ func init() {
7586
checklevelCmd.Flags().StringVar(&checkLevelArgs.branch, "branch", "", "The branch within the repository - required.")
7687
checklevelCmd.Flags().IntVar(&checkLevelArgs.minDays, "min_days", 1, "The minimum duration that the rules need to have been enabled for.")
7788
checklevelCmd.Flags().StringVar(&checkLevelArgs.outputVsa, "output_vsa", "", "The path to write a signed VSA with the determined level.")
89+
checklevelCmd.Flags().StringVar(&checkLevelArgs.outputUnsignedVsa, "output_unsigned_vsa", "", "The path to write an unsigned vsa with the determined level.")
7890
}

sourcetool/pkg/vsa/vsa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"google.golang.org/protobuf/types/known/timestamppb"
1818
)
1919

20-
func createUnsignedSourceVsa(owner string, repo string, commit string, sourceLevel string) (string, error) {
20+
func CreateUnsignedSourceVsa(owner string, repo string, commit string, sourceLevel string) (string, error) {
2121
resourceUri := fmt.Sprintf("git+https://github.com/%s/%s", owner, repo)
2222
vsaPred := &vpb.VerificationSummary{
2323
Verifier: &vpb.VerificationSummary_Verifier{
@@ -106,7 +106,7 @@ func getSigningOpts(oidcToken string) (sign.BundleOptions, error) {
106106
// NOTE: This is experimental, and definitely not done. There's no way for folks to verify
107107
// what this produces.
108108
func CreateSignedSourceVsa(owner string, repo string, commit string, sourceLevel string) (string, error) {
109-
unsignedVsa, err := createUnsignedSourceVsa(owner, repo, commit, sourceLevel)
109+
unsignedVsa, err := CreateUnsignedSourceVsa(owner, repo, commit, sourceLevel)
110110
if err != nil {
111111
return "", err
112112
}

0 commit comments

Comments
 (0)