-
Notifications
You must be signed in to change notification settings - Fork 98
FIx TPM attestation certificate problem #345
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
FIx TPM attestation certificate problem #345
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
protocol/attestation.go (1)
248-248
: Adjust code formatting to meet linter recommendationsThe static analysis tool (
wsl
) suggests that assignments should only be cuddled with other assignments at line 248. Consider adjusting the code formatting for consistency.Apply this diff to align with the linter's suggestions:
- x5cParsed, err := x509.ParseCertificate(x5cRaw) - if err != nil { + x5cParsed, err := x509.ParseCertificate(x5cRaw) + if err != nil {🧰 Tools
🪛 golangci-lint (1.62.2)
248-248: assignments should only be cuddled with other assignments
(wsl)
protocol/attestation_tpm.go (2)
412-412
: Consider pre-allocating theunknown
slice for better performanceThe static analysis tool (
prealloc
) suggests pre-allocating theunknown
slice to improve performance by minimizing allocations.Apply this diff to pre-allocate the slice based on the length of
x5c.UnknownExtKeyUsage
:-func tpmRemoveEKU(x5c *x509.Certificate) error { - var unknown []asn1.ObjectIdentifier +func tpmRemoveEKU(x5c *x509.Certificate) error { + unknown := make([]asn1.ObjectIdentifier, 0, len(x5c.UnknownExtKeyUsage))🧰 Tools
🪛 golangci-lint (1.62.2)
412-412: Consider pre-allocating
unknown
(prealloc)
412-429
: Ensure proper handling of EKUs intpmRemoveEKU
functionThe
tpmRemoveEKU
function correctly checks for the presence of the AIK EKU (tcgKpAIKCertificate
) and excludes unknown EKUs. However, consider the following improvements:
- Error Message Consistency: The error message returned when the AIK EKU is missing could provide more context.
- EKU Validation: Double-check that all necessary EKUs are accounted for according to the TPM specifications.
🧰 Tools
🪛 golangci-lint (1.62.2)
412-412: Consider pre-allocating
unknown
(prealloc)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
protocol/attestation.go
(1 hunks)protocol/attestation_tpm.go
(1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
protocol/attestation.go
248-248: assignments should only be cuddled with other assignments
(wsl)
252-252: if statements should only be cuddled with assignments
(wsl)
277-277: assignments should only be cuddled with other assignments
(wsl)
284-284: if statements should only be cuddled with assignments
(wsl)
249-249: only one cuddle assignment allowed before if statement
(wsl)
263-263: if statements should only be cuddled with assignments
(wsl)
266-266: only one cuddle assignment allowed before range statement
(wsl)
278-278: only one cuddle assignment allowed before if statement
(wsl)
protocol/attestation_tpm.go
412-412: Consider pre-allocating unknown
(prealloc)
🔇 Additional comments (3)
protocol/attestation.go (3)
235-256
: Proper handling of multiple attestation certificates
The code correctly iterates over x5cs
to parse each certificate. The first certificate is assigned to x5c
(the leaf certificate), and the subsequent certificates are added to the parents
slice (intermediate certificates). Error handling is appropriately managed for parsing failures.
🧰 Tools
🪛 golangci-lint (1.62.2)
248-248: assignments should only be cuddled with other assignments
(wsl)
252-252: if statements should only be cuddled with assignments
(wsl)
249-249: only one cuddle assignment allowed before if statement
(wsl)
263-270
: Correct application of tpmRemoveEKU
to certificates
The invocation of tpmRemoveEKU
on both the primary certificate (x5c
) and all parent certificates ensures that Extended Key Usage (EKU) entries are properly managed. This enhances the security and compliance of attestation validation.
🧰 Tools
🪛 golangci-lint (1.62.2)
263-263: if statements should only be cuddled with assignments
(wsl)
266-266: only one cuddle assignment allowed before range statement
(wsl)
277-284
: Proper setup of certificate verifier and chain verification
The code accurately sets up the verifier
using the metadata statement. It adds intermediate certificates to verifier.Intermediates
when available and performs the certificate chain verification using x5c.Verify(verifier)
. This approach ensures the attestation certificate is validated against the correct trust anchors.
🧰 Tools
🪛 golangci-lint (1.62.2)
277-277: assignments should only be cuddled with other assignments
(wsl)
284-284: if statements should only be cuddled with assignments
(wsl)
278-278: only one cuddle assignment allowed before if statement
(wsl)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fix #342