Skip to content

Commit

Permalink
feat: add verification required log
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
  • Loading branch information
JeyJeyGao committed Nov 30, 2022
1 parent 7ae1f5f commit d2b30c2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/notaryproject/notation-core-go/signature"
"github.com/notaryproject/notation-go/log"
"github.com/notaryproject/notation-go/registry"
"github.com/notaryproject/notation-go/verifier/trustpolicy"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -186,6 +187,8 @@ func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, re
var verificationOutcomes []*VerificationOutcome
errExceededMaxVerificationLimit := ErrorVerificationFailed{Msg: fmt.Sprintf("total number of signatures associated with an artifact should be less than: %d", remoteOpts.MaxSignatureAttempts)}
numOfSignatureProcessed := 0

logger := log.GetLogger(ctx)
err = repo.ListSignatures(ctx, artifactDescriptor, func(signatureManifests []ocispec.Descriptor) error {
// process signatures
for _, sigManifestDesc := range signatureManifests {
Expand All @@ -203,6 +206,18 @@ func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, re

// verify each signature
outcome, err := verifier.Verify(ctx, artifactDescriptor, sigBlob, opts)
// process verification items
for _, result := range outcome.VerificationResults {
if result.Error == nil {
continue
}
switch result.Action {
case trustpolicy.ActionLog:
logger.Warnf("verification failed on %v validation for signature %v but set to pass by verification action \"logged\". Reason: %v", result.Type, sigManifestDesc.Digest, result.Error)
case trustpolicy.ActionEnforce:
logger.Errorf("verification failed on %v validation for signature %v. Reason: %v", result.Type, sigManifestDesc.Digest, result.Error)
}
}
if err != nil {
if outcome == nil {
// TODO: log fatal error
Expand Down

0 comments on commit d2b30c2

Please sign in to comment.