Closed sorensF5 closed 11 months ago
The signed attrs field is a CONTEXT SENSITIVE
tagged field, and .dump()
returns the version with those tags. Digest calculation, on the other hand, requires a universally tagged payload. You can easily obtain one of those by first calling .untag()
before .dump()
. :)
Thanks for the prompt reply, @MatthiasValvekens ! Will definitely try this out! Been side tracked with the workaround of adding the \x31
in place and have time today for the circle back.
Appears to work just fine with @MatthiasValvekens 's suggested:
extracted_attributes = loaded_cms["content"]["signer_infos"][0]["signed_attrs"].untag().dump()
Thanks for the information!
Closing as this has an implemented solution built in that I simply missed that matches RFC statements:
Only the octets comprising the value of the eContent OCTET STRING are input to the message digest algorithm, not the tag or the length octets.
Problem
CMSAttributes
whendump()
'ed results in a binary block that does not follow theDER
standard for aSET
orSETOF
as defined inASN1
andDER
and was wondering if this is intentional because it makes the message digest portion of the RFC harder to calculate. This seems to impact the version1.5.1
.Expected Behavior
Taking the modulus of the
CMSAttributes
within a loaded CMS block and calculating the expected content to a CMS for verification should just take acms_attributes.dump()
rather than transforming the first byte to\x31
as follows:Observed Behavior
When attempting the above, the signature is rejected with an exception until I add the step of:
This changes the tag given by
CMSAttributes
from\xa0\x81\xca0\x1c...
to\x31\x81\xca0\x1c...
- value truncated to keep this concise. Without this change, an error stating that the signature does not match is raised.Request
Either a "fix" where the
dump()
responds with a proper DER forSET
/SETOF
or an answer to the question of why this behaving in this way?Solution
Per comments below, the answer is to issue a
.untag().dump()
to theCMSAttributes
object when extracting the DER. This presents the untagged form for signing that is required for the CMS per the calculations of the Message Digest per the statement:Thus:
Becomes our solution.
Thanks to @MatthiasValvekens for the promptly-given solution!