Skip to content

Commit 6618671

Browse files
committed
only saving signatures verified successfully into verificationOutcomes
Signed-off-by: Patrick Zheng <[email protected]>
1 parent 86cb8ec commit 6618671

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

notation.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type Verifier interface {
145145

146146
// Verify performs signature verification on each of the notation supported
147147
// verification types (like integrity, authenticity, etc.) and return the
148-
// verification outcomes.
148+
// successful signature verification outcomes.
149149
// For more details on signature verification, see
150150
// https://github.com/notaryproject/notaryproject/blob/main/specs/trust-store-trust-policy.md#signature-verification
151151
func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, opts VerifyOptions) (ocispec.Descriptor, []*VerificationOutcome, error) {
@@ -171,14 +171,14 @@ func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, op
171171
opts.MaxSignatureAttempts = maxVerificationLimitDefault
172172
}
173173
errExceededMaxVerificationLimit := ErrorVerificationFailed{Msg: fmt.Sprintf("total number of signatures associated with an artifact should be less than: %d", opts.MaxSignatureAttempts)}
174-
count := 0
174+
numOfSignatureProcessed := 0
175175
err = repo.ListSignatures(ctx, artifactDescriptor, func(signatureManifests []ocispec.Descriptor) error {
176176
// process signatures
177177
for _, sigManifestDesc := range signatureManifests {
178-
if count >= opts.MaxSignatureAttempts {
178+
if numOfSignatureProcessed >= opts.MaxSignatureAttempts {
179179
break
180180
}
181-
count++
181+
numOfSignatureProcessed++
182182
// get signature envelope
183183
sigBlob, _, err := repo.FetchSignatureBlob(ctx, sigManifestDesc)
184184
if err != nil {
@@ -190,17 +190,17 @@ func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, op
190190
// TODO: log fatal error
191191
return err
192192
}
193-
verificationOutcomes = append(verificationOutcomes, outcome)
194193
continue
195194
}
196195

197-
// At this point, we've found a signature verified successfully
196+
// At this point, the signature is verified successfully. Add
197+
// it to the verificationOutcomes.
198198
verificationOutcomes = append(verificationOutcomes, outcome)
199199

200200
return errDoneVerification
201201
}
202202

203-
if count >= opts.MaxSignatureAttempts {
203+
if numOfSignatureProcessed >= opts.MaxSignatureAttempts {
204204
return errExceededMaxVerificationLimit
205205
}
206206

@@ -215,15 +215,16 @@ func Verify(ctx context.Context, verifier Verifier, repo registry.Repository, op
215215
}
216216

217217
// If there's no signature associated with the reference
218-
if len(verificationOutcomes) == 0 {
218+
if numOfSignatureProcessed == 0 {
219219
return ocispec.Descriptor{}, nil, ErrorSignatureRetrievalFailed{Msg: fmt.Sprintf("no signature is associated with %q, make sure the image was signed successfully", artifactRef)}
220220
}
221221

222-
// check whether verification was successful or not
223-
if verificationOutcomes[len(verificationOutcomes)-1].Error != nil {
222+
// Verification Failed
223+
if len(verificationOutcomes) == 0 {
224224
return ocispec.Descriptor{}, verificationOutcomes, ErrorVerificationFailed{}
225225
}
226226

227+
// Verification Succeeded
227228
return artifactDescriptor, verificationOutcomes, nil
228229
}
229230

0 commit comments

Comments
 (0)