Skip to content

Commit

Permalink
VerificationResult now has a proper mediaType field. (#14)
Browse files Browse the repository at this point in the history
* VerificationResult now has a proper mediaType field.

Signed-off-by: Phill MV <[email protected]>

* Linting.

I actually find the switch statement here MORE confusing than the if else,
so I have taken the liberty to disable gocritic for this particular if.

Signed-off-by: Phill MV <[email protected]>

* Moved VerificationResult mediaType value to a const.

Signed-off-by: Phill MV <[email protected]>

---------

Signed-off-by: Phill MV <[email protected]>
  • Loading branch information
phillmv authored Oct 10, 2023
1 parent b968f40 commit 0187552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/sigstore-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,21 @@ func run() error {
return err
}

if *artifactDigest != "" {
if *artifactDigest != "" { //nolint:gocritic
artifactDigestBytes, err := hex.DecodeString(*artifactDigest)
if err != nil {
return err
}
artifactPolicy = verify.WithArtifactDigest(*artifactDigestAlgorithm, artifactDigestBytes)
}
if *artifact != "" {
} else if *artifact != "" {
file, err := os.Open(*artifact)
if err != nil {
return err
}
artifactPolicy = verify.WithArtifact(file)
} else {
artifactPolicy = verify.WithoutArtifactUnsafe()
fmt.Fprintf(os.Stderr, "No artifact provided, skipping artifact verification. This is unsafe!\n")
}

res, err := sev.Verify(b, verify.NewPolicy(artifactPolicy, identityPolicies...))
Expand Down
12 changes: 9 additions & 3 deletions pkg/verify/signed_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/sigstore/sigstore-go/pkg/root"
)

const (
VerificationResultMediaType01 = "application/vnd.dev.sigstore.verificationresult+json;version=0.1"
)

type SignedEntityVerifier struct {
trustedMaterial root.TrustedMaterial
config VerifierConfig
Expand Down Expand Up @@ -154,7 +158,7 @@ func (c *VerifierConfig) Validate() error {
}

type VerificationResult struct {
Version int `json:"version"`
MediaType string `json:"mediaType"`
Statement *in_toto.Statement `json:"statement,omitempty"`
Signature *SignatureVerificationResult `json:"signature,omitempty"`
VerifiedTimestamps []TimestampVerificationResult `json:"verifiedTimestamps"`
Expand All @@ -174,7 +178,7 @@ type TimestampVerificationResult struct {

func NewVerificationResult() *VerificationResult {
return &VerificationResult{
Version: 20230823,
MediaType: VerificationResultMediaType01,
}
}

Expand All @@ -193,9 +197,11 @@ func (pc PolicyBuilder) Options() []PolicyOption {
}

func (pc PolicyBuilder) BuildConfig() (*PolicyConfig, error) {
var err error

policy := &PolicyConfig{}
for _, applyOption := range pc.Options() {
err := applyOption(policy)
err = applyOption(policy)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0187552

Please sign in to comment.