asn1rs
asn1rs copied to clipboard
Port asn1c X.509 and LDAPv3 examples
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 :)
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:
- [x] Tags
- [x] SET and SET OF
- [x] OPTIONAL for tags
- [x] INTEGER without range (Can be treated like
INTEGER(0,MAX))
For LDAP, at least the following features are missing:
- [x] Constants
- [x]
WITH COMPONENTS - [ ]
COMPONENTS OF - [x]
DEFAULT - [x]
NULL - [x] Referencing constants
- [ ] Whatever this
filter Filterthing means - just an alias?
For X.509 Implicit, at least these features are missing:
- [ ]
OBJECT IDENTIFIERdata type - [x] Constants
- [ ]
GeneralizedTimedata type - [ ]
ANY DEFINED BY ... - [ ]
EXPLICIT ANY DEFINED BY ... - [ ] Constants list
- [x]
DEFAULT - [x]
VisibleStringdata type - [ ]
BmpStringdata type
For X.509 Explicit, at least these features are missing:
- [x] Constants
- [ ]
OBJECT IDENTIFIERdata type - [ ]
ANY - [ ]
TeletexStringdata type - [x]
PrintableStringdata type - [ ]
UniversalStringdata type - [ ]
BMPStringdata type - [ ]
UTCTimedata type - [ ]
GeneralizedTimedata type - [ ]
ANY DEFINED BY - [ ]
IMPLICIT - [ ]
EXPLICIT
(found by manually reading through the file)
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
@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.
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.
@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