-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cole
committed
Nov 10, 2024
1 parent
88b78c0
commit b37f37e
Showing
3 changed files
with
29 additions
and
3 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 |
---|---|---|
|
@@ -16,12 +16,14 @@ package cmd | |
|
||
import ( | ||
"context" | ||
"crypto" | ||
"fmt" | ||
"os" | ||
|
||
witness "github.com/in-toto/go-witness" | ||
"github.com/in-toto/go-witness/cryptoutil" | ||
"github.com/in-toto/go-witness/dsse" | ||
Check failure on line 25 in cmd/sign.go GitHub Actions / Verify Docgen
Check failure on line 25 in cmd/sign.go GitHub Actions / unit-test / witness
Check failure on line 25 in cmd/sign.go GitHub Actions / sast / witness
Check failure on line 25 in cmd/sign.go GitHub Actions / e2e-test / witness
Check failure on line 25 in cmd/sign.go GitHub Actions / Analyze (go)
|
||
"github.com/in-toto/go-witness/log" | ||
"github.com/in-toto/go-witness/timestamp" | ||
"github.com/in-toto/witness/options" | ||
"github.com/spf13/cobra" | ||
|
@@ -81,5 +83,27 @@ func runSign(ctx context.Context, so options.SignOptions, signers ...cryptoutil. | |
} | ||
|
||
defer outFile.Close() | ||
return witness.Sign(inFile, so.DataType, outFile, dsse.SignWithSigners(signers[0]), dsse.SignWithTimestampers(timestampers...)) | ||
|
||
// Aggregate all user-defined subjects into a single map | ||
allSubjects := make(map[string]cryptoutil.DigestSet) | ||
|
||
// Iterate over user-defined subjects and add them to the aggregated map | ||
for _, userDefinedSubject := range so.UserDefinedSubjects { | ||
fmt.Printf("User-defined subject: %v\n", userDefinedSubject) | ||
ds, err := cryptoutil.CalculateDigestSetFromBytes([]byte(userDefinedSubject), | ||
[]cryptoutil.DigestValue{{ | ||
Hash: crypto.SHA256, | ||
GitOID: false, | ||
}}) | ||
|
||
if err != nil { | ||
log.Debugf("(witness) failed to record user-defined subject %v: %v", userDefinedSubject, err) | ||
continue | ||
} | ||
// Add the user-defined subject to the aggregated map | ||
allSubjects["https://witness.dev/internal/user:"+userDefinedSubject] = ds | ||
} | ||
|
||
return witness.Sign(inFile, so.DataType, outFile, dsse.SignWithSigners(signers[0]), | ||
dsse.SignWithTimestampers(timestampers...), dsse.SignWithUserDefinedSubject(allSubjects)) | ||
} |
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