Re: [pyasn1-users] 0.2.3+ master branch DER encoding problems
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2017-04-09 18:38:05
|
I believe that was a weakness in pyasn1 which is now hardened. ;-) I guess you are trying to produce indefinite length encoding with DER codec, while with DER you are obliged to use definite length encoding at all times: https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf 10.1 Length forms The definite form of length encoding shall be used, encoded in the minimum number of octets. Where SHALL means absolute requirement in RFC parlance: https://www.ietf.org/rfc/rfc2119.txt 1. MUST This word, or the terms “REQUIRED” or "SHALL", mean that the definition is an absolute requirement of the specification. So simply switching to BER might fix this issue. Would that work for you? > On 9 Apr 2017, at 12:38, Sergey Matveev <sta...@st...> wrote: > > Greetings! > > I have got problems with DER-encoding of OctetString in current (0.2.3+) > master branch. > > I install pyasn1: > > % pip install 'git+https://github.com/etingof/pyasn1.git@7b0b4d28b98d26d03696a6b0e2c0fd5d85f004b7' > > and run that script: > > from os import urandom > from pyasn1.codec.der.encoder import encode > from pyasn1.type.univ import OctetString > > for i in range(1500): > print(i) > encode(OctetString(urandom(i))) > > and it always fails when input random string's length exceeds 1000 bytes: > > % python t.py > [...] > 1001 > Traceback (most recent call last): > File "t.py", line 6, in <module> > encode(OctetString(urandom(i))) > substrate += encodeFun(v, defMode, maxChunkSize) > [...] > raise error.PyAsn1Error('DER forbids indefinite length mode') > pyasn1.error.PyAsn1Error: DER forbids indefinite length mode > > No fail with version 0.2.3. > > -- > Sergey Matveev (http://www.stargrave.org/) > OpenPGP: CF60 E89A 5923 1E76 E263 6422 AE1A 8109 E498 57EF |