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

Issues with BER indefinite-length decoding #190

Open
ktptemfau opened this issue Feb 5, 2020 · 1 comment
Open

Issues with BER indefinite-length decoding #190

ktptemfau opened this issue Feb 5, 2020 · 1 comment

Comments

@ktptemfau
Copy link

ktptemfau commented Feb 5, 2020

Hi,

I am not sure what I am doing wrong or if I am hitting a bug
The data I'm trying to decode is an CMS envelopedData blob which openssl decodes as following

  0:d=0  hl=2 l=inf  cons: SEQUENCE          
  2:d=1  hl=2 l=  11 prim: OBJECT            :id-smime-ct-authEnvelopedData
 15:d=1  hl=2 l=inf  cons: cont [ 0 ]        
 17:d=2  hl=2 l=inf  cons: SEQUENCE                      
 19:d=3  hl=2 l=   1 prim: INTEGER           :00
 22:d=3  hl=4 l= 471 cons: SET                                                                                              
 26:d=4  hl=4 l= 467 cons: SEQUENCE             
 30:d=5  hl=2 l=   1 prim: INTEGER           :00
 ...
 ..,
958:d=3  hl=2 l=  16 prim: OCTET STRING      [HEX DUMP]:ABA7DBB789D8FE7B137D3370E58007B6
976:d=3  hl=2 l=   0 prim: EOC               
978:d=2  hl=2 l=   0 prim: EOC               
980:d=1  hl=2 l=   0 prim: EOC  

When I decode the data like this

with open(self.filename,'r') as file:
    data = file.read()
obj, rest  = ber_decoder(base64.b64decode(data), asn1Spec=rfc5652.ContentInfo(), decodeOpenTypes=False)

and print obj this is what I get

<class 'pyasn1_modules.rfc5652.ContentInfo'>
ContentInfo:
 contentType=1.2.840.113549.1.9.16.1.23
 content=0x3080.....
  ...
  ...
  ....a0410aba7dbb789d8fe7b137d3370e58007b6

If I decode this way

  obj, rest  = ber_decoder(base64.b64decode(data), asn1Spec=rfc5652.ContentInfo(), decodeOpenTypes=True)

I end up with

SubstrateUnderrunError: No EOO seen before substrate ends

Looking at the printout of the decoded data, I can understand the exeception as the EOC bytes of 'content' is missing.

Any hints or pointers on how I can resolve this issue?

Thanks for your time!

@qsqa
Copy link

qsqa commented Mar 28, 2020

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

No branches or pull requests

2 participants