Skip to content

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

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

on-keyday
Copy link
Contributor

fix #342

@on-keyday on-keyday requested a review from a team as a code owner December 6, 2024 12:46
Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces modifications to the protocol/attestation.go and protocol/attestation_tpm.go files, enhancing the handling and verification of attestation certificates. The VerifyAttestation method is updated to support multiple certificates, improving the management of certificate chains. Additionally, a new function tpmRemoveEKU is added to manage Extended Key Usage (EKU) entries in certificates. The changes also refine error handling and ensure that EKU constraints are properly addressed during attestation validation.

Changes

Files Change Summary
protocol/attestation.go Enhanced VerifyAttestation to handle multiple certificates, refined error handling for certificate parsing.
protocol/attestation_tpm.go Added tpmRemoveEKU function for EKU management, defined oidKpPrivacyCA constant, and updated comments.

Assessment against linked issues

Objective Addressed Explanation
x509: trust chain validation fails when attestation certificate includes issuer URL (#342)

Possibly related issues

Possibly related PRs

Suggested reviewers

  • james-d-elliott: Suggested for review due to expertise in the relevant codebase.

🐰 "In the realm of code where certs do play,
We’ve added some magic to brighten the way.
With EKUs sorted and chains now aligned,
Attestation's journey is better defined.
Hoppy coding ahead, let the bugs take flight,
For our certificates now shine ever so bright!" 🐇


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 recommendations

The 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 the unknown slice for better performance

The static analysis tool (prealloc) suggests pre-allocating the unknown 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 in tpmRemoveEKU function

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a5f13c and 9d8c1a1.

📒 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)

Copy link
Member

@james-d-elliott james-d-elliott left a comment

Choose a reason for hiding this comment

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

LGTM

@james-d-elliott james-d-elliott merged commit 339114c into go-webauthn:master Dec 22, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x509: trust chain validation fails when attestation certificate includes issuer URL
2 participants