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

parser claims "syntax error" for SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) with DEFAULT #174

Open
laf0rge opened this issue Jan 1, 2024 · 4 comments

Comments

@laf0rge
Copy link

laf0rge commented Jan 1, 2024

This specification does not use CLASS nor (as far as I can tell) any of the other unsupported constructs described in the known limitation section of the asn1tools documentation.

Sadly, asn1tools still fails to parse any version of their spec. I've tested v1.1 through v3.3.1 and they all fail with messages like

error: Invalid ASN.1 syntax at line 789, column 57: 'sqnInit SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) >!<DEFAULT {': .

or

error: Invalid ASN.1 syntax at line 511, column 65: 'sqnInit SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) >!<DEFAULT {'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,': .

so it somehow seems asn1tools doesen't understand a [size constrained] sequence of [size constrained] octet strings with default values?

and indeed the small reproducer below already triggers the problem

PEDefinitions {joint-iso-itu-t(2) international-organizations(23) tca(143) euicc-profile(1) spec-version(1) version-three(3)}
DEFINITIONS
AUTOMATIC TAGS
EXTENSIBILITY IMPLIED ::=
BEGIN
SqnInit ::= SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) DEFAULT {
/* Index 0 */'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H, '000000000000'H,'000000000000'H, '000000000000'H, '000000000000'H,
}
END

as soon as the DEFAULT clause is removed, it seems to work.

@laf0rge laf0rge changed the title parser claims "syntax error" for SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) with DEFAULT parser claims "syntax error" for SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6)) with DEFAULT Jan 1, 2024
osmocom-gerrit pushed a commit to osmocom/pysim that referenced this issue Jan 1, 2024
See eerimoq/asn1tools#174 for details

Change-Id: Ibc0330f3bc217fa38815c758033bc589ae665d8a
@laf0rge
Copy link
Author

laf0rge commented Jan 2, 2024

I can modufy the ASN.1 source to replace the DEFAULT { 00000000000'H, '000000000000'H, ... } clause with a simple DEFAULT 00000000000'H. Then asn1tools is able to parse the ASN.1 snyatx, and also parse actual (DER encoded) data in-line with the syntax.

However, (obviously) when the related field is not set and one expects the default value to be used during encode, there is an exception:

 File "/usr/local/lib/python3.11/dist-packages/asn1tools/compiler.py", line 137, in encode
    type_.check_types(data)
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/compiler.py", line 102, in check_types
    return self.type_checker.encode(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 311, in encode
    raise e
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 307, in encode
    self._type.encode(data)
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 247, in encode
    raise e
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 243, in encode
    member.encode(data[1])
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 142, in encode
    self.encode_members(data)
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 154, in encode_members
    raise e
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 150, in encode_members
    member.encode(data[name])
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 166, in encode
    super(List, self).encode(data)
  File "/usr/local/lib/python3.11/dist-packages/asn1tools/codecs/type_checker.py", line 45, in encode
    raise EncodeError(
asn1tools.codecs.EncodeError: ProfileElement.akaParameter.sqnInit: Expected data of type list, but got 0x000000000000.

Obviously the encoder is correct: It doesn't make sense to have a single value as a default for a "SEQUENCE OF", where one would need a list of values. So it looks a bit like the problem is just the parser which doesn't parse that construct?

The full ASN.1 syntax of the spec I'm working with can be found at https://gitea.osmocom.org/laforge/simalliance-tca-interoperable-format-asn1/src/branch/master/asn1/PEDefinitions.asn

@eerimoq
Copy link
Owner

eerimoq commented Jan 2, 2024

Sorry, but I'm not very active in maintaining this project anymore :(

osmocom-gerrit pushed a commit to osmocom/pysim that referenced this issue Jan 2, 2024
See eerimoq/asn1tools#174 for details

Change-Id: Ibc0330f3bc217fa38815c758033bc589ae665d8a
@laf0rge
Copy link
Author

laf0rge commented Jan 3, 2024

Sorry, but I'm not very active in maintaining this project anymore :(

I noticed, and that's all fine. It still is in my opinion the most powerful/complete python framework for ASN.1. I tried to look at debugging the specific problem further, but given I know very little about parser theory and have no idea about pyparsing, so I sadly didn't get very far :( If I should solve it, I'd for sure send a related PR.

Seeing that there are sponsoring opportunities avaialable: Would you consider debugging this in a paid/freelance capacity?

@eerimoq
Copy link
Owner

eerimoq commented Jan 3, 2024

I've other projects to work on that are far more interesting to me, so no.

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