refactor(tpm2_getekcertificate): harden Intel EK cert parsing#3574
Merged
JuergenReppSIT merged 1 commit intoApr 22, 2026
Merged
Conversation
f00c8ed to
4d4c8e9
Compare
Extract a reusable get_json_field() helper to look up named fields in
JSON strings, and use it to replace fragile ad-hoc parsing:
- Check for "pubhash" field presence instead of matching a raw prefix
string ("{\"pubhash"), making detection resilient to whitespace and
field ordering variations.
- Replace base64_decode() with convert_base64url_to_base64(): extract
the "certificate" field via get_json_field(), then perform Base64URL
to Base64 conversion separately.
No new external dependencies (e.g. json-c) are introduced.
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
4d4c8e9 to
9026cf3
Compare
Member
|
Hi @hyperfinitism That looks good. If you remove the draft marking, I would close my PR and merge yours. |
JuergenReppSIT
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces fragile ad-hoc string parsing of Intel EK certificate responses with a small reusable helper,
get_json_field().Previously, the code relied on prefix matching (e.g.
{"pubhash) and fixed-offset string manipulation to extract fields from JSON responses. This is brittle and can break with minor variations such as whitespace changes or different field ordering.This change introduces a minimal JSON field lookup helper and uses it to:
"pubhash"field, instead of relying on a raw string prefix."certificate"field explicitly, and then perform Base64URL-to-Base64 conversion viaconvert_base64url_to_base64().This makes the parsing more robust while keeping the implementation lightweight, and also makes the code semantically clear.
In addition to improving robustness, the new code avoids the previous
curl_easy_unescape()+strdup()sequence when extracting the certificate field. That reduces unnecessary heap allocation/copying in this path (2 alloc + 2 copy → 1 alloc + 1 copy).No new external dependencies (e.g.
json-c) are introduced.Related issue/PR
Once PR #3573 is merged, issue #3559 will be resolved. This PR makes the parsing logic more robust and refactors the code to ensure maintainability.