Skip to content

entropy: reject a truncated checksum in decode_structured - #2601

Open
danish293 wants to merge 1 commit into
rnpgp:mainfrom
danish293:entropy-checksum-truncation
Open

danish293 wants to merge 1 commit into
rnpgp:mainfrom
danish293:entropy-checksum-truncation

Conversation

@danish293

Copy link
Copy Markdown
Contributor

Truncated checksum group passes validation

decode_structured() cuts the expected checksum down to however many characters the input supplied and then compares only that prefix, so a checksum group reduced to its identifier character compares empty against empty and the check passes: rnp_entropy_encoding_validate() returns RNP_SUCCESS and rnp_entropy_decode_human_readable() hands back the corrupted entropy, where the documented result is RNP_ERROR_SIGNATURE_INVALID when the checksum does not match. Keeping one character reduces the check to a single character out of checksum_chars(). With the defaults (hex alphabet, 256 entropy bits, group_size 4, checksum_bits 16), !5973 0333B 11785 ... with one data-group payload character flipped and the checksum group cut to ! validates and decodes to the wrong 64 hex characters. The encoder pads the group to group_size, so trailing padding is still tolerated, but the checksum characters themselves now all have to be present and match.

Tested with the OpenSSL backend on macOS arm64, ENABLE_CRYPTO_REFRESH=ON: the new case in test_ffi_entropy_encoding_roundtrip fails on main at the first truncated-checksum assertion and passes with the fix. test_ffi_encrypt_pk and the cli_tests-* legs fail identically before and after on this machine (CAST5 off in this build, no GnuPG installed), so the Botan leg is left to CI.

decode_structured() cut the expected checksum down to however many
characters the input supplied and compared only that prefix, so a
checksum group reduced to its identifier compared empty against empty
and validated. Require every checksum character to be present and to
match, keeping the tolerance for the trailing padding the encoder adds
to fill the group.

@ronaldtse ronaldtse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this fix, @danish293 — the truncated-checksum bypass is real and the analysis is precise: the identifier-only checksum group compared empty against empty and let tampered entropy through validation.

The fix is correct as written: requiring every checksum character to be present closes the bypass, while the trailing group padding the encoder emits remains tolerated by the prefix comparison. The regression test is exactly what this needed — it walks every truncation length from the identifier alone up to the full checksum with a flipped payload character and asserts both validation and decoding fail in each case, then confirms the pristine form still validates.

Verified locally: the new test fails on main at the first truncated-checksum assertion and passes on this branch (338/338 full suite, OpenSSL backend).

This branch has not been deployed

No deployments
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.

2 participants