rusticata / x509-parser

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

Added support for parsing challenge password attribute in CSR's #129

Closed bkstein closed 1 year ago

bkstein commented 1 year ago

This branch adds support for parsing a challenge password attribute in a CSR.

Please note: https://github.com/rusticata/oid-registry/pull/10 is a prerequisite, as it adds OID_PKCS9_CHALLENGE_PASSWORD. This PR is merged, but not yet released.

bkstein commented 1 year ago

A remark @chifflier: I think, the attribute parsing could be improved. Currently, X509CertificationRequest::from_der() parses the CSR and knows the (challenge password) attribute's value. This value is held in X509CriAttribute.parsed_attribute, which is not visible outside the crate:

pub struct X509CriAttribute<'a> {
    pub oid: Oid<'a>,
    pub value: &'a [u8],
    pub(crate) parsed_attribute: ParsedCriAttribute<'a>,
}

Why is that? A user of the x509-parser crate needs to re-parse X509CriAttribute.value instead. I think, the already parsed attribute value should be made available for users. What do you think?

bkstein commented 1 year ago

I just compared CriAttribute to X509Extension and found

impl<'a> X509Extension<'a> {
    ...
    /// Return the extension type or `UnsupportedExtension` if the extension is not implemented.
    #[inline]
    pub fn parsed_extension(&self) -> &ParsedExtension<'a> {
        &self.parsed_extension
    }
}

We could do that in a similar manner for attributes

impl<'a> CriAttribute<'a> {
    ...
    /// Return the attribute type or `UnsupportedAttribute` if the attribute is unknown.
    #[inline]
    pub fn parsed_attribute(&self) -> &ParsedCriAttribute<'a> {
        &self.parsed_attribute
    }
}
bkstein commented 1 year ago

I will check my proposal and set this request to draft.

bkstein commented 1 year ago

Seems to work.

bkstein commented 1 year ago

@chifflier The checks will fail until oid-registry with OID for challenge password is released.

chifflier commented 1 year ago

@chifflier The checks will fail until oid-registry with OID for challenge password is released.

oid-registry 0.6.1 has just been released with the required OID

bkstein commented 1 year ago

Changes are implemented. Thanks for reviewing!