Skip to content

Commit 1947ee1

Browse files
committed
Improve error handling in CAPI KMS.
1 parent bda16e3 commit 1947ee1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kms/capi/capi.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func (k *CAPIKMS) getCertContext(req *apiv1.LoadCertificateRequest) (*windows.Ce
441441
prevCert = handle
442442
}
443443
default:
444-
return nil, fmt.Errorf("%q, %q, or %q and %q is required to find a certificate", HashArg, KeyIDArg, IssuerNameArg, SerialNumberArg)
444+
return nil, fmt.Errorf("%q, %q, or %q and one of %q or %q is required to find a certificate", HashArg, KeyIDArg, IssuerNameArg, SerialNumberArg, SubjectCNArg)
445445
}
446446

447447
return handle, err
@@ -461,6 +461,9 @@ func (k *CAPIKMS) CreateSigner(req *apiv1.CreateSignerRequest) (crypto.Signer, e
461461
)
462462
if containerName = u.Get(ContainerNameArg); containerName != "" {
463463
kh, err = nCryptOpenKey(k.providerHandle, containerName, 0, 0)
464+
if err != nil {
465+
return nil, fmt.Errorf("unable to open key using %q=%q: %w", ContainerNameArg, containerName, err)
466+
}
464467
} else {
465468
// check if a certificate can be located using the URI
466469
certHandle, err = k.getCertContext(&apiv1.LoadCertificateRequest{
@@ -471,10 +474,9 @@ func (k *CAPIKMS) CreateSigner(req *apiv1.CreateSignerRequest) (crypto.Signer, e
471474
}
472475

473476
kh, err = cryptFindCertificatePrivateKey(certHandle)
474-
}
475-
476-
if err != nil {
477-
return nil, fmt.Errorf("unable to open key: %w", err)
477+
if err != nil {
478+
return nil, fmt.Errorf("unable to open key: %w", err)
479+
}
478480
}
479481

480482
pinOrPass := u.Pin()

0 commit comments

Comments
 (0)