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

Updated witness to use changes made to cryptoutil.DigestValue implemented in go-witness #371

Merged
merged 3 commits into from
Feb 3, 2024
Merged
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
5 changes: 2 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package cmd

import (
"context"
"crypto"
"encoding/json"
"fmt"

Expand Down Expand Up @@ -116,13 +115,13 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .
}
}

var roHashes []crypto.Hash
var roHashes []cryptoutil.DigestValue
for _, hashStr := range ro.Hashes {
hash, err := cryptoutil.HashFromString(hashStr)
if err != nil {
return fmt.Errorf("failed to parse hash: %w", err)
}
roHashes = append(roHashes, hash)
roHashes = append(roHashes, cryptoutil.DigestValue{Hash: hash, GitOID: false})
}

defer out.Close()
Expand Down
5 changes: 1 addition & 4 deletions cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func runVerify(ctx context.Context, vo options.VerifyOptions) error {

subjects := []cryptoutil.DigestSet{}
if len(vo.ArtifactFilePath) > 0 {
artifactDigestSet, err := cryptoutil.CalculateDigestSetFromFile(vo.ArtifactFilePath, []crypto.Hash{crypto.SHA256})
artifactDigestSet, err := cryptoutil.CalculateDigestSetFromFile(vo.ArtifactFilePath, []cryptoutil.DigestValue{{Hash: crypto.SHA256, GitOID: false}})
if err != nil {
return fmt.Errorf("failed to calculate artifact digest: %w", err)
}
Expand Down Expand Up @@ -125,10 +125,8 @@ func runVerify(ctx context.Context, vo options.VerifyOptions) error {
witness.VerifyWithSubjectDigests(subjects),
witness.VerifyWithCollectionSource(collectionSource),
)

if err != nil {
return fmt.Errorf("failed to verify policy: %w", err)

}

log.Info("Verification succeeded")
Expand All @@ -142,5 +140,4 @@ func runVerify(ctx context.Context, vo options.VerifyOptions) error {
}

return nil

}
10 changes: 4 additions & 6 deletions cmd/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestRunVerifyCA(t *testing.T) {
require.NoError(t, runRun(context.Background(), s1RunOptions, step1Args, signers...))

subjects := []string{}
artifactDigest, err := cryptoutil.CalculateDigestSetFromFile(artifactPath, []crypto.Hash{crypto.SHA256})
artifactDigest, err := cryptoutil.CalculateDigestSetFromFile(artifactPath, []cryptoutil.DigestValue{{Hash: crypto.SHA256}})
require.NoError(t, err)

for _, digest := range artifactDigest {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestRunVerifyCA(t *testing.T) {
require.NoError(t, runVerify(context.Background(), vo))

// test that verify works without artifactfilepath but the subject of the modified articact also provided
artifactDigest, err = cryptoutil.CalculateDigestSetFromFile(artifactPath, []crypto.Hash{crypto.SHA256})
artifactDigest, err = cryptoutil.CalculateDigestSetFromFile(artifactPath, []cryptoutil.DigestValue{{Hash: crypto.SHA256}})
require.NoError(t, err)
for _, digest := range artifactDigest {
subjects = append(subjects, digest)
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestRunVerifyKeyPair(t *testing.T) {
require.NoError(t, runRun(context.Background(), s1RunOptions, step1Args, signers...))

subjects := []string{}
artifactDigest, err := cryptoutil.CalculateDigestSetFromFile(artifactPath, []crypto.Hash{crypto.SHA256})
artifactDigest, err := cryptoutil.CalculateDigestSetFromFile(artifactPath, []cryptoutil.DigestValue{{Hash: crypto.SHA256}})
require.NoError(t, err)

for _, digest := range artifactDigest {
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestRunVerifyKeyPair(t *testing.T) {
require.NoError(t, runVerify(context.Background(), vo))

// test that verify works without artifactfilepath but the subject of the modified articact also provided
artifactDigest, err = cryptoutil.CalculateDigestSetFromFile(artifactPath, []crypto.Hash{crypto.SHA256})
artifactDigest, err = cryptoutil.CalculateDigestSetFromFile(artifactPath, []cryptoutil.DigestValue{{Hash: crypto.SHA256}})
require.NoError(t, err)
for _, digest := range artifactDigest {
subjects = append(subjects, digest)
Expand Down Expand Up @@ -328,9 +328,7 @@ func makepolicy(t *testing.T, functionary policy.Functionary, publicKey policy.P
p.Steps[step02.Name] = step02

if publicKey.KeyID != "" {

p.PublicKeys[publicKey.KeyID] = publicKey

}

pb, err := json.MarshalIndent(p, "", " ")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/in-toto/witness
go 1.19

require (
github.com/in-toto/go-witness v0.2.2
github.com/in-toto/go-witness v0.2.3
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/in-toto/go-witness v0.2.1 h1:eAxMBWUPbz3oPU3lsfEYi/Kdj6weej2umm59bOXP
github.com/in-toto/go-witness v0.2.1/go.mod h1:xURJVj4QRD3xnzOJps7gT0pMCFPpAHcPqDC3EyuLuUE=
github.com/in-toto/go-witness v0.2.2 h1:oyiqyzzKwX8j5zjBVdxoo0LxjMV13ujOF0l/hu5uYp8=
github.com/in-toto/go-witness v0.2.2/go.mod h1:b5ocF+eHUYnQgQncM6nK0g5TIoUzA94gs50fS7g+uNk=
github.com/in-toto/go-witness v0.2.3 h1:KjiaRHxW2VSyouXUW0Zrpc+7LXfFKilB86a1lqNDsAU=
github.com/in-toto/go-witness v0.2.3/go.mod h1:b5ocF+eHUYnQgQncM6nK0g5TIoUzA94gs50fS7g+uNk=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
Expand Down
Loading