Skip to content

Conversation

@sarroutbi
Copy link
Contributor

@sarroutbi sarroutbi commented Jul 17, 2025

This patch refactors the resilient_client to fix a JSON double-encoding bug that caused the verifier to reject requests.

The root cause of the "malformed parameters" error from Verifier was that the get_json_request function was being called with a String that already contained JSON. The function would then re-serialize this string, wrapping it in an extra layer of quotes and escaping its contents, leading to a double-encoded payload.

This PR resolves the issue by improving the client's API to be more explicit and prevent this error by design.

  • keylime/src/resilient_client.rs:

The original get_json_request function has been refactored. Its signature is changed to accept a pre-serialized string slice (json_string: &str) and it now uses this string directly as the request body without further serialization.

A new function, get_json_request_from_struct<T: Serialize>, has been introduced. This function now contains the original logic: it takes a serializable Rust struct, converts it to a JSON string, and then calls the new get_json_request to build the request.

  • keylime-push-model-agent/src/attestation.rs & keylime/src/registrar_client.rs:

All call sites have been updated to use the new, more descriptive get_json_request_from_struct function, clarifying the intent to serialize a struct.

A test case in the push-model agent was also corrected to assert against the properly single-encoded JSON body.

@sarroutbi sarroutbi force-pushed the 202507171227-fix-body-sending branch 2 times, most recently from cdde57a to 666f101 Compare July 17, 2025 10:36
Signed-off-by: Sergio Arroutbi <sarroutb@redhat.com>
@sarroutbi sarroutbi force-pushed the 202507171227-fix-body-sending branch from 666f101 to 3bb71bc Compare July 17, 2025 10:36
@sarroutbi sarroutbi changed the title Fix body sending Fix body sending by allowing serializing strings Jul 17, 2025
@sarroutbi sarroutbi marked this pull request as ready for review July 17, 2025 10:49
@sarroutbi sarroutbi requested a review from ansasaki July 17, 2025 10:49
@codecov
Copy link

codecov bot commented Jul 17, 2025

Codecov Report

Attention: Patch coverage is 38.46154% with 16 lines in your changes missing coverage. Please review.

Project coverage is 58.37%. Comparing base (f050222) to head (3bb71bc).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
keylime/src/resilient_client.rs 50.00% 10 Missing ⚠️
keylime/src/registrar_client.rs 0.00% 5 Missing ⚠️
keylime-push-model-agent/src/attestation.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
Flag Coverage Δ
e2e-testsuite 58.37% <38.46%> (-0.07%) ⬇️
upstream-unit-tests 58.37% <38.46%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
keylime-push-model-agent/src/attestation.rs 41.13% <0.00%> (ø)
keylime/src/registrar_client.rs 78.70% <0.00%> (-1.22%) ⬇️
keylime/src/resilient_client.rs 48.68% <50.00%> (+0.35%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@sergio-correia sergio-correia left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@sarroutbi sarroutbi merged commit b3300fb into keylime:master Jul 17, 2025
15 of 16 checks passed
@sarroutbi sarroutbi deleted the 202507171227-fix-body-sending branch July 17, 2025 12:35
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.

3 participants