Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support skipping certificate private key check on request #475

Merged
merged 16 commits into from
Apr 16, 2024

Conversation

hslatman
Copy link
Member

@hslatman hslatman commented Apr 5, 2024

To support certificates that (usually) don't have a key present, skip-find-certificate-key=true can now be provided to an individual call for storing a certificate (chain). This can be helpful when storing an intermediate or root certificate in a specific store / store location.

@hslatman hslatman requested a review from a team April 5, 2024 09:02
@@ -786,7 +790,7 @@ func (k *TPMKMS) storeCertificateChainToWindowsCertificateStore(req *apiv1.Store
}

if err := k.windowsCertificateManager.StoreCertificate(&apiv1.StoreCertificateRequest{
Name: fmt.Sprintf("capi:sha1=%s;store-location=%s;store=%s;", fp, location, store),
Name: fmt.Sprintf("capi:sha1=%s;store-location=%s;store=%s;skip-find-certificate-key=%s", fp, location, store, skipFindCertificatKey),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are location and store properly encoded to work on a URI?

Copy link
Member Author

@hslatman hslatman Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For existing and valid values they are, as they are plain strings and those are checked in the CAPI implementation. But I can change the implementation to uv.Set, or something similar, if preferred

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4d88201

@hslatman hslatman requested a review from maraino April 8, 2024 18:30
@hslatman hslatman enabled auto-merge April 12, 2024 12:16
Add support for removing certificates from TPM and CAPI KMS
Copy link
Contributor

@maraino maraino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not freeing all the certHandles, and I've also added another optional suggestion.

kms/capi/capi.go Outdated
Comment on lines 770 to 775
sha1Hash = strings.TrimPrefix(sha1Hash, "0x") // Support specifying the hash as 0x like with serial

sha1Bytes, err := hex.DecodeString(sha1Hash)
if err != nil {
return fmt.Errorf("%s must be in hex format: %w", HashArg, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a func (u *URI) GetHexEncoded(key string) ([]byte, error) to the URI package we already have GetEncoded, but it is not strict and fallback to []byte(v). GetEncoded could use GetHexEncoded`.

We are using this several times in this package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we could validate the number of bytes, as a SHA1 is known. It will probably fail with an obscure error later.

kms/capi/capi.go Show resolved Hide resolved
@hslatman hslatman requested a review from maraino April 15, 2024 20:51
Copy link
Contributor

@maraino maraino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetHexEncoded should return an error if it is present but invalid. Nil if it is not present or empty.

kms/uri/uri.go Outdated Show resolved Hide resolved
kms/capi/capi.go Show resolved Hide resolved
kms/capi/capi.go Outdated Show resolved Hide resolved
kms/capi/capi.go Outdated Show resolved Hide resolved
kms/capi/capi.go Outdated Show resolved Hide resolved
@hslatman hslatman requested a review from maraino April 16, 2024 15:37
Copy link
Contributor

@maraino maraino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hslatman hslatman merged commit 1d8dca8 into master Apr 16, 2024
11 checks passed
@hslatman hslatman deleted the herman/windows-tpm-certificate-stores branch April 16, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants