Skip to content
Open
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
3 changes: 1 addition & 2 deletions verifier/trustpolicy/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package trustpolicy
import (
"errors"
"fmt"
"reflect"
"strings"

"github.com/notaryproject/notation-go/dir"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (policyDoc *BlobDocument) Validate() error {
}

// verificationLevel is skip
if reflect.DeepEqual(statement.SignatureVerification.VerificationLevel, LevelSkip) {
if statement.SignatureVerification.VerificationLevel == LevelSkip.Name {
return errors.New("global blob trust policy statement cannot have verification level set to skip")
}
foundGlobalPolicy = true
Expand Down
26 changes: 26 additions & 0 deletions verifier/trustpolicy/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ func TestValidate_BlobDocument_Error(t *testing.T) {
t.Fatalf("multiple global blob policy should return error")
}

// global policy with verification level skip
policyDoc = dummyBlobPolicyDocument()
policyStatement1 = policyDoc.TrustPolicies[0].clone()
policyStatement1.GlobalPolicy = true
policyStatement1.SignatureVerification = SignatureVerification{VerificationLevel: "skip"}
// validatePolicyCore permits skip only without trust stores or identities,
// so this is the shape that reaches the global policy check.
policyStatement1.TrustStores = nil
policyStatement1.TrustedIdentities = nil
policyDoc.TrustPolicies = []BlobTrustPolicy{*policyStatement1}
err = policyDoc.Validate()
if err == nil || err.Error() != "global blob trust policy statement cannot have verification level set to skip" {
t.Fatalf("global blob policy with skip should return an error, got %v", err)
}

// a non-global statement may still use skip
policyDoc = dummyBlobPolicyDocument()
policyStatement1 = policyDoc.TrustPolicies[0].clone()
policyStatement1.SignatureVerification = SignatureVerification{VerificationLevel: "skip"}
policyStatement1.TrustStores = nil
policyStatement1.TrustedIdentities = nil
policyDoc.TrustPolicies = []BlobTrustPolicy{*policyStatement1}
if err := policyDoc.Validate(); err != nil {
t.Fatalf("non-global statement with skip should be allowed, got %v", err)
}

// Policy Document with duplicate policy statement names
policyDoc = dummyBlobPolicyDocument()
policyStatement1 = policyDoc.TrustPolicies[0].clone()
Expand Down