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

Fail to parse Kerberos ASN.1 #41

Open
gollda opened this issue Sep 7, 2016 · 17 comments
Open

Fail to parse Kerberos ASN.1 #41

gollda opened this issue Sep 7, 2016 · 17 comments

Comments

@gollda
Copy link

gollda commented Sep 7, 2016

Hi, I have a problem with translate ASN.1 grammar of Kerberos from:
https://cwiki.apache.org/confluence/display/DIRxSRVx10/Kerberos+ASN.1+codec

when I put:
python pyasn1gen.py KrbGrammar.asn1 > rfc4120.py
output is:
Traceback (most recent call last):
File "pyasn1gen.py", line 628, in
sys.exit(main())
File "pyasn1gen.py", line 606, in main
parse_tree = parser.parse_asn1(asn1def)
File "/usr/local/lib/python2.7/dist-packages/asn1ate/parser.py", line 40, in parse_asn1
parse_result = grammar.parseString(asn1_definition)
File "/usr/local/lib/python2.7/dist-packages/pyparsing.py", line 1613, in parseString
raise exc
pyparsing.ParseException: Expected "END" (at char 908), (line:28, col:35)

I don't know, maybe doing something wrong.
Thank you for You help.

@kimgr
Copy link
Owner

kimgr commented Sep 8, 2016

I haven't seen the GeneralString (IA5String) constraint syntax before, and I'm not sure what it means. Do you know? If you're just interested in getting this to work on your end, I think you can remove the (IA5String) part, it appears it was added to constrain the range of allowed strings.

@gollda
Copy link
Author

gollda commented Sep 9, 2016

I removed (IA5String) part, but still doesn't work correctly.

@kimgr
Copy link
Owner

kimgr commented Sep 9, 2016

I think you need to be more specific for me to be able to help. It's quite possible that the Kerberos spec contains more constructs that asn1ate doesn't support.

@gollda
Copy link
Author

gollda commented Sep 9, 2016

I don't know. I'm just used official ASN.1 notation from Apache wiki. I'd love to tell you where is wrong but I don't know. Output from console is:
Traceback (most recent call last):
File "pyasn1gen.py", line 628, in
sys.exit(main())
File "pyasn1gen.py", line 606, in main
parse_tree = parser.parse_asn1(asn1def)
File "/usr/local/lib/python2.7/dist-packages/asn1ate/parser.py", line 40, in parse_asn1
parse_result = grammar.parseString(asn1_definition)
File "/usr/local/lib/python2.7/dist-packages/pyparsing.py", line 1613, in parseString
raise exc
pyparsing.ParseException: Expected "END" (at char 4113), (line:132, col:30)

thank you for your patience :)

@kimgr
Copy link
Owner

kimgr commented Sep 9, 2016

Here's a clue:

(line:132, col:30)

If you know your way around ASN.1, you may be able to change it to something simpler.

I wish asn1ate's parser error reporting was better, but I haven't investigated how to improve it.

@SuperXiaoxiong
Copy link

So, I wonder how you solve the problem @gollda ,I also want to translate ASN.1 grammar of Kerberos from, Could you give me some tips

@SuperXiaoxiong
Copy link

I think this ASN.1 file may be too long for pyparsing to handler this @kimgr

@gollda
Copy link
Author

gollda commented Dec 6, 2017

Hi, it is reaaaaally long time ago, so now I can't remember on ti. Anyway I stoped working on this beacause it was my subject of my diploma thesis and my tutor leave the company where I worked on this. So I didn't have anybody who lead me.

@SuperXiaoxiong
Copy link

Oh my god! Anyway ,thank you very much

@kimgr
Copy link
Owner

kimgr commented Dec 6, 2017

I don't think it's size-related, there's probably just some ASN.1 syntax in the file that isn't supported by asn1ate. I know most Kerberos specs use advanced ASN.1 features, so they're not easily translatable. If you can be more specific about what's going wrong (what does the ASN.1 look like, what does asn1ate say, what did you try, etc), I might be able to suggest a workaround.

@SuperXiaoxiong
Copy link

@kimgr Apologize for being late, I have met the same questions with gollda. When I remove the (IA5String) part, there is an error in (line:132, col:30)

132   KDC-REQ         ::= SEQUENCE {
133              -- NOTE: first tag is [1], not [0]
134               pvno            [1] INTEGER (5) ,
135               msg-type        [2] INTEGER (10 -- AS -- | 12 -- TGS --),
136              padata          [3] SEQUENCE OF PA-DATA OPTIONAL
137                                   -- NOTE: not empty --,
138               req-body        [4] KDC-REQ-BODY
139       }

there is the source of the asn.1 https://cwiki.apache.org/confluence/display/DIRxSRVx10/Kerberos+ASN.1+codec
If there any way to help us solve the problem ,Just tell me , Thank you for the reply

@SuperXiaoxiong
Copy link

@gollda I am so sorry for that , Could tell me your tutor's github or twitter , I am working on kerberos for a while . Congratulations on your graduation and having a good job, Thank you

@kimgr
Copy link
Owner

kimgr commented Dec 7, 2017

@SuperXiaoxiong

135 msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --),

I suspect this constrained integer isn't supported by asn1ate. you can just remove the constraint and say:

msg-type [2] INTEGER,

And make sure you validate in the application layer.

@SuperXiaoxiong
Copy link

SuperXiaoxiong commented Dec 7, 2017 via email

@SuperXiaoxiong
Copy link

Thanks, @kimgr You are right, and your work is very nice 。The problem solved while I only need to make a little adjustments , Thank you once again!

@kimgr
Copy link
Owner

kimgr commented Dec 8, 2017

@SuperXiaoxiong I'm glad to hear! Was this the only change you had to make to parse the Kerberos ASN.1? If so, it sounds like a priority to improve asn1ate support for constrained integers.

@SuperXiaoxiong
Copy link

SuperXiaoxiong commented Dec 10, 2017

@kimgr (⊙o⊙)… but maybe there are some little unknown problem .
AttributeError: 'Module' object has no attribute 'resolve_tag_implicitness'
I just use another version for convience https://github.com/etingof/asn1ate.git, etingof's asn1ate ,a fork of you, It's also very nice,For your information.
but thank you anyway,Help me solve my problem. I think the support for constrained integers is the next step too.
The most important, It's very amaing to do a such a big project alone , you deserve the world's praise

Traceback (most recent call last):
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 649, in <module>
    sys.exit(main())
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 640, in main
    generate_pyasn1(module, output_file, modules)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 523, in generate_pyasn1
    return Pyasn1Backend(sema_module, out_stream, referenced_modules).generate_c
ode()
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 145, in generate_code
    details = self.generate_definition(assignment)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 159, in generate_definition

    return self.generate_defn(assigned_type, type_decl)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 171, in generate_defn
    return generator(class_name, t)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 280, in defn_collection_typ
e
    fragment.write_line('%s.componentType = %s' % (class_name, self.generate_exp
r(t.type_decl)))
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 167, in generate_expr
    return generator(t)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 308, in inline_constructed_
type
    fragment.write_block(self.inline_component_types(t.components))
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 321, in inline_component_ty
pes
    component_exprs.append(self.generate_expr(c))
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 167, in generate_expr
    return generator(t)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 427, in inline_component_ty
pe
    return "namedtype.NamedType('%s', %s)" % (t.identifier, self.generate_expr(t
.type_decl))
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 167, in generate_expr
    return generator(t)
  File "./asn1ate-master/asn1ate/pyasn1gen.py", line 328, in inline_tagged_type
    implicitness = self.sema_module.resolve_tag_implicitness(t.implicitness, t.t
ype_decl)
AttributeError: 'Module' object has no attribute 'resolve_tag_implicitness'

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

3 participants