Skip to content

Commit dcefc6c

Browse files
darkfronzaclaude
andcommitted
Fix cert lookup fallback when findCertificateBySubjectKeyID returns NotFoundError
Previously, any error from findCertificateBySubjectKeyID would cause an immediate return, preventing the issuer-based fallback from running. Now only non-NotFoundError errors (or NotFoundError when issuer lookup is unavailable) are returned early. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c899aeb commit dcefc6c

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

kms/capi/capi.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,9 @@ func (k *CAPIKMS) getCertContext(u *uriAttributes) (*windows.CertContext, error)
433433
}
434434
case len(u.keyID) > 0:
435435
if handle, err = findCertificateBySubjectKeyID(st, u.keyID); err != nil {
436-
return nil, err
437-
}
438-
439-
if handle == nil && !canLookupByIssuer {
440-
return nil, apiv1.NotFoundError{Message: fmt.Sprintf("certificate with %s=%s not found", KeyIDArg, u.keyID)}
436+
if !errors.Is(err, apiv1.NotFoundError{}) || !canLookupByIssuer {
437+
return nil, err
438+
}
441439
}
442440
case u.containerName != "":
443441
key, err := k.GetPublicKey(&apiv1.GetPublicKeyRequest{
@@ -453,11 +451,9 @@ func (k *CAPIKMS) getCertContext(u *uriAttributes) (*windows.CertContext, error)
453451
return nil, fmt.Errorf("error generating SubjectKeyID: %w", err)
454452
}
455453
if handle, err = findCertificateBySubjectKeyID(st, keyID); err != nil {
456-
return nil, err
457-
}
458-
459-
if handle == nil && !canLookupByIssuer {
460-
return nil, apiv1.NotFoundError{Message: fmt.Sprintf("certificate with %s=%s not found", KeyIDArg, u.keyID)}
454+
if !errors.Is(err, apiv1.NotFoundError{}) || !canLookupByIssuer {
455+
return nil, err
456+
}
461457
}
462458
}
463459

0 commit comments

Comments
 (0)