0

I have a DER Sequence which I was able to parse using asn1 module from pycrypto. Now that pycrypto was deprecated, I want to move to pyasn1.

Below is my code snippet:

x = "308201cc04080c000000000000000408a80de7c97e000000161036633533346433323334333337653533308201a0301e040804000000000000000408240000000000000004089f86010000000000301e040804000000000000000408400d0300000000000408df93040000000000301e040805000000000000000408180000000000000004089f86010000000000301e040805000000000000000408e09304000000000004087f1a060000000000301e040806000000000000000408000000000000000004089f86010000000000301e040807000000000000000408240000000000000004089f86010000000000301e040808000000000000000408000000000000000004089f86010000000000301e040809000000000000000408000000000000000004089f86010000000000301e04080a000000000000000408000000000000000004089f86010000000000301e04080b000000000000000408000000000000000004089f86010000000000301e04080c000000000000000408000000000000000004089f86010000000000301e04080d000000000000000408000000000000000004089f86010000000000301e04080e000000000000000408000000000000000004089f860100000000003000"

from pyasn1.codec.der import decoder
decoder.decode(bytes.fromhex(x))

The decode resulted in the error:

"attributeError("'NoneType' object has no attribute 'tagSet'")"

I know the error is due to the last sequence (representing NULL without value): 3000.

This was working previously with asn1 from pycrypto (which was deprecated). I wanted to switch my code to pyasn1. Any help?

OpenSSL works fine:

echo "<hex string>" | xxd -p -r | openssl asn1parse -inform dev

So, the error is only with pyasn1. Is there any workaround for this? Or any options that we can pass while decoding?

7
  • Sorry, it works for me. Commented Jul 2, 2024 at 9:44
  • FWIW on Ubuntu 18.04 (python3 3.8.2-0ubuntu2 and python3-pyasn1 0.4.2-3build1) I get what looks like the correct result but on 20.04 (3.10.6-1~22.04 and 0.4.8-1) I get no error and only a single <Sequence schema object ...> (not "value") with no trace of the contents, which is clearly wrong. Also you do realize that even though pycrypto is dead, pycryptodome is healthy and claims API compatibility? Commented Jul 2, 2024 at 10:17
  • @Armali can you please try the above code with the exact input string given ? Commented Jul 2, 2024 at 12:50
  • @dave_thompson_085 the asn1 functionality from pycryptodome is heavily changed when compared to the one from pycrypto. The same was mentioned in the pycryptodome docs. Since pyasn1 is popular for asn1, wanted to take steps towards pyasn1 Commented Jul 2, 2024 at 12:53
  • @theLearner – I already did. Commented Jul 2, 2024 at 13:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.