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

Port asn1c X.509 and LDAPv3 examples #6

Open
awakecoding opened this issue May 31, 2019 · 6 comments
Open

Port asn1c X.509 and LDAPv3 examples #6

awakecoding opened this issue May 31, 2019 · 6 comments

Comments

@awakecoding
Copy link

asn1c (https://github.com/vlm/asn1c) is arguably one of the most known and complete ASN.1 compilers. It has a few examples for common ASN.1 modules, such as X.509 and LDAPv3. If you compile asn1c from source with the examples, there's a script that generates the .asn1 files from the RFCs directly.

I pre-generated those for X.509 and LDAP3 and added them here for reference:
https://github.com/Devolutions/asn1rs/tree/examples/examples

For X.509, both the explicit and implicit modules are generated, I don't know which one is better.

I know the current readme says asn1rs won't work with most elaborate ASN.1 modules, but if there are complex ones it should support first, it should be X.509 and LDAPv3 :) I tried and both fail at this point, but I don't know enough of ASN.1 and asn1rs to see which part of the file is not handled correctly.

In all cases, it should be a good thing to include "clean" .asn1 files for useful specifications, known to work with asn1rs. With no_std support, imagine being able to a complete X.509 certificate parser and writer that works in WebAssembly, that would be amazing :)

kellerkindt added a commit that referenced this issue Apr 6, 2020
This parses ENUMERATED with variants that have explicit variant numbers
and default markers (...) but it does not reflect those new information
in Rust, Protobuf or SQL yet. It just allows them to be parsed without
failing the parser. Trying to generate Rust, Protobuf or SQL will result
in a panic.
kellerkindt added a commit that referenced this issue Apr 8, 2020
Although UPER is used - which does not care about tags at all - protobuf
is using tags. Maybe it will be useful in the future, to remember the tags
when converting a Model<Asn> to a Model<Rust> or Model<Protobuf> - i.e. if
one is going to implement a BER or DER (de-)serializer.
@masihyeganeh
Copy link

masihyeganeh commented Apr 12, 2020

I have a small list of features that are needed for my project.
I'm sure that most of them should be implemented for X.509 but I'll write them anyway:

  • Tags
  • SET and SET OF
  • OPTIONAL for tags
  • INTEGER without range (Can be treated like INTEGER(0,MAX))

kellerkindt added a commit that referenced this issue Apr 14, 2020
Passing non-auto like tags or choice-indices will panic-fail the Model<Asn>
to Model<Rust> conversion, as well as having an extensible type.
kellerkindt added a commit that referenced this issue Apr 16, 2020
As just detected, the length determinant for the content of the
extended CHOICE variants are missing - which is the reason the
tests fail.
kellerkindt added a commit that referenced this issue Apr 17, 2020
This allows the caller to recover from a new/unknown variant waiting
to be deserialized by skipping it.
@masihyeganeh
Copy link

Hello @kellerkindt
I see that you are still actively developing.
Can I request implementation of these two?
These were stopper last time I wanted to implement DER encoding.
They are so straightforward and easy to implement but I couldn't find the right place for them in your architecture.
Thanks

@awakecoding
Copy link
Author

@masihyeganeh I haven't followed up on this ticket specifically, but since you're here, we've built our own ASN.1 framework in Rust called picky-rs since then. It is not an ASN.1 compiler, but it lets you define structures with serde that will automatically map to ASN.1 DER. I don't know what your use case it, but maybe it can fit your needs.

@masihyeganeh
Copy link

Thanks @awakecoding for your suggestion but actually asn1rs is better fit for my project.
I already have many complex asn1 files that needs to be converted to readable rust structs to parse der encoded traffic.
asn1rs can almost do all I need but lack of support for DER (that is really easy to implement) prevents me from using it.

@awakecoding
Copy link
Author

awakecoding commented Jun 11, 2021

@masihyeganeh sure, I totally understand. I haven't really given up on the ASN.1 compiler idea, but in order to get things working the serde_asn1_der approach worked very well for us. It's always difficult to find a compiler that handles all the types you need. I wonder if we couldn't attempt modifying asn1rs to generate code that picky-rs can consume, but that would be a project for another time :) is your project open source? I'm curious to see which ASN.1 data structures you have to deal with

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