rusticata / x509-parser

X.509 parser written in pure Rust. Fast, zero-copy, safe.
Other
207 stars 67 forks source link

Expose parsing functions, or provide more types that include them #85

Closed lilyball closed 3 years ago

lilyball commented 3 years ago

I'm trying to add parsing of more extensions myself. Right now I'm adding Subject Directory Attributes since this crate seems to have just forgotten about that entirely, though I need to add custom extensions too. Subject Directory Attributes is defined as

SubjectDirectoryAttributes ::= SEQUENCE SIZE (1..MAX) OF Attribute

Attribute               ::= SEQUENCE {
      type             AttributeType,
      values    SET OF AttributeValue }
            -- at least one value is required

This crate exposes AttributeTypeAndValue, which parses a sequence of a single type and value, but it doesn't have Attribute, and it doesn't expose its internal parse_attribute_value() (or the interesting part of that, which is the fallback alternative parser parse_malformed_string()).

This is annoying as I don't want to have to replicate things like parse_malformed_string(), but I want to match the behavior of this crate's existing parsers.

Ideally, every type definition in Appendix A of RFC 5280 would have some publicly-exposed parser in this crate, so I could use it to parse extensions that this crate doesn't itself support.

lilyball commented 3 years ago

For that matter, many existing types don't expose their parsers. For example, GeneralName has no from_der() method, instead being parsed by a private parse_generalname() function. This makes it very hard for me to add missing extensions like Issuer Alternative Name, even though its value type is identical to the supported SubjectAlternativeName.

Speaking of SubjectAlternativeName, it would ideally be defined in terms of a public GeneralNames type, which contains Vec<GeneralName> and exposes a from_der(). This is because giving the SubjectAlternativeName type itself a from_der() method seems odd as it's not meant to be a reusable type but rather just a typed wrapper for a specific extension's payload, which means it should itself be defined in terms of a standard type.