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

Workaround for unsupported RELATIVE-OID #97

Closed
scy opened this issue Nov 2, 2020 · 3 comments
Closed

Workaround for unsupported RELATIVE-OID #97

scy opened this issue Nov 2, 2020 · 3 comments

Comments

@scy
Copy link

scy commented Nov 2, 2020

Hi there! First of all, thanks for this library.

I have a DTD for a standard I don’t control. It uses the RELATIVE-OID type, which is not supported by asn1tools, probably because the underlying pyasn not supporting it yet.

For my application I need to be able to decode and encode messages with RELATIVE-OID fields. However, I could live with handling them as bytes values and splitting them on my own or whatever. Which is why I’ve tried simply hacking RELATIVE-OID ::= [UNIVERSAL 13] OCTET STRING into the DTD. This will parse successfully, but when I try to decode a message, I get:

[stack abridged to only include the asn1tools part]
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/compiler.py", line 163, in decode
    decoded = type_.decode(data)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1482, in decode
    return self._type.decode(bytearray(data), 0)[0]
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1423, in decode
    values, end_offset = self.inner.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1120, in decode
    decoded, offset = member.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 717, in decode
    decoded_element, offset = self.element_type.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1423, in decode
    values, end_offset = self.inner.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1120, in decode
    decoded, offset = member.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 594, in decode
    end_offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 659, in decode_member
    raise e
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 647, in decode_member
    value, offset = member.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1423, in decode
    values, end_offset = self.inner.decode(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 1412, in decode
    offset = self.decode_tag(data, offset)
  File "/home/scy/.local/lib/python3.6/site-packages/asn1tools/codecs/ber.py", line 397, in decode_tag
    offset)
asn1tools.codecs.DecodeTagError: path: Expected RELATIVE-OID with tag '2d' at offset 10, but got '0d'.

So, the message that I’m receiving encodes RELATIVE-OID with a tag of 0d (i.e. universal primitive 13), but asn1tools expects 2d (universal constructed 13), right?

My knowledge of ASN.1 is pretty limited and I openly admit that I don’t really know what I’m doing. Can you help me out?

My project is commercial but rather time-critical right now. (Read: I need to fix this somehow within the next 24 hours.) I’m open to discussing compensation for your time if you’d like and I’ve already tried to contact you via Twitter about it. Of course I know that this is an open source project and I can’t expect anything, I’m merely asking.

@eerimoq
Copy link
Owner

eerimoq commented Nov 2, 2020

Sorry, I'm not interested in helping out. Feel free to submit a PR if you implement support for them.

@scy
Copy link
Author

scy commented Nov 2, 2020

This is of course not what I was hoping for, but I’ll find a way. Thanks anyway for responding as quickly as you did.

@scy
Copy link
Author

scy commented Nov 2, 2020

Adding RELATIVE-OID ::= [UNIVERSAL 13] IMPLICIT OCTET STRING to the DTD solved it for me. Designating it as IMPLICIT was the key, since the tag is now 0d instead of 2d.

I now get the RELATIVE-OID as a simple bytes object, which works well enough for my purposes.

@scy scy closed this as completed Nov 2, 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