Skip to content

Commit

Permalink
call Close() on security keys before returning error (#1113)
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Sanders <jsand@google.com>
  • Loading branch information
Jake Sanders committed Nov 30, 2021
1 parent 2294fd4 commit ac7e33c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func signerFromSecurityKey(keySlot string) (*SignerVerifier, error) {
}
sv, err := sk.SignerVerifier()
if err != nil {
sk.Close()
return nil, err
}

Expand All @@ -276,6 +277,7 @@ func signerFromSecurityKey(keySlot string) (*SignerVerifier, error) {
} else {
pemBytes, err = cryptoutils.MarshalCertificateToPEM(certFromPIV)
if err != nil {
sk.Close()
return nil, err
}
}
Expand Down Expand Up @@ -305,6 +307,7 @@ func signerFromKeyRef(ctx context.Context, certPath, keyRef string, passFunc cos
} else {
pemBytes, err = cryptoutils.MarshalCertificateToPEM(certFromPKCS11)
if err != nil {
pkcs11Key.Close()
return nil, err
}
}
Expand Down

0 comments on commit ac7e33c

Please sign in to comment.