Skip to content
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 CVD dsig verification when hash starts with zeros #1415

Conversation

micahsnyder
Copy link
Contributor

Occasionally the MD5 hash for RSA-based digital signature verification begins with zeros. A bug in how we convert the RSA decoded plain text from a big number back to a hex string causes it to write the number to the far left of the plain text buffer. If the number is smaller than a hash, then zero-padding ends up on the right when it should've been on the left.

Occasionally the MD5 hash for RSA-based digital signature
verification begins with zeros. A bug in how we convert the RSA
decoded plain text from a big number back to a hex string causes it
to write the number to the far left of the plain text buffer.
If the number is smaller than a hash, then zero-padding ends up on
the right when it should've been on the left.

Additional fix: BN_bn2bin() will write zero bytes if the bignum is 0.
So there is no point "error checking" the BN_bn2bin() call.
Thanks to Tom Judge for noticing these shenanigans.
Ref: openssl/openssl#2101

Side note: BN_num_bytes() will also return 0 if the bignum is 0,
which is fine.
@micahsnyder micahsnyder force-pushed the CLAM-2628-Fix-CVD-dsig-verification-when-hash-starts-with-zero branch from 2bb3f13 to b8795fd Compare December 4, 2024 14:51
tj-cisco
tj-cisco previously approved these changes Dec 4, 2024
@micahsnyder
Copy link
Contributor Author

Per discussion with @TheRaynMan and @tj-cisco will add a retry in case the md5 for signing has the 00 prefix. That way new sigtool doesn't make CVD's that fail to verify on older clamav.

Have --build retry if the tar.gz MD5 starts with 00.
@micahsnyder micahsnyder force-pushed the CLAM-2628-Fix-CVD-dsig-verification-when-hash-starts-with-zero branch from 46cfc0a to 4d389f3 Compare December 17, 2024 14:17
@rsundriyal rsundriyal self-requested a review January 10, 2025 15:42
@micahsnyder micahsnyder merged commit 7df9f85 into Cisco-Talos:main Jan 12, 2025
23 of 24 checks passed
@micahsnyder micahsnyder deleted the CLAM-2628-Fix-CVD-dsig-verification-when-hash-starts-with-zero branch January 12, 2025 18:24
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