-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Asn1Value._new_instance
doesn't copy the value of member method
#225
Comments
Hi, got a small example to demonstrate why this is actually bad? This could then serve as a test case to prevent regressions. |
While I'm not the OP, I'd wager that this is never a problem when dealing with DER, where all (universal) types have a fixed encoding method. However, in BER, most string-like types can be either primitive or constructed. More to the point, CER even requires strings to be encoded as constructed (with primitive subsequences) in some cases:
(Source ITU-T Rec. X.690 | ISO/IEC 8825-1:2015 clause 9.2) Long story short: I'm curious how Unfortunately I don't have time to test the behaviour myself right now, but I can take a look later if no-one else gets to it by then. |
While @MatthiasValvekens has great point where this could potential be a real problem, I unfortunately only have python semantic case i.e. changing the value of In theory where this could lead to an issue, for example is when digital signature was made over different encoding than parsed object (e.g. class TestValue(Asn1Value):
class_ = 1
method = 1
tag = 23
t = TestValue()
t.method = 0
t.tag = 22
t_cpy = t.copy()
assert t_cpy.tag == 22
assert t_cpy.method == 0 # <-- should fail |
I'm not disagreeing with you, but I have one small nitpick:
While that could happen, a strict reading of the CMS spec will tell you that by definition, the signature has to be computed over the DER encoding of the signed attributes, thus ruling out this particular class of bugs since it'd render all signatures that would be affected by an issue like this invalid out of the gate :). That said, in practice many validators tolerate non-DER encodings and compute their digests over whatever happens to be within the In the meantime, I tried running this:
So I guess my example doesn't apply, since apparently |
In the past I had cases with some biometric passports where |
At this point between the asn1crypto and other modularcrypto packages, there is a decent corpus of tests. While I likely never ran into a use case for customizing the method per instance, I am fine with adding some tests for this use case and making sure nothing existing breaks. |
When copying
Asn1Value
object the value ofAsn1Value.method
is not copied over to the new instance inAsn1Value._new_instance
method.asn1crypto/asn1crypto/core.py
Lines 484 to 497 in 5a24aed
The text was updated successfully, but these errors were encountered: