Skip to content

x509-cert: Document (or improve) how to construct custom extensions #1490

Closed
@str4d

Description

@str4d

CertificateBuilder::add_extension has the following public interface:

/// Add an extension to this certificate
pub fn add_extension<E: AsExtension>(&mut self, extension: &E) -> Result<()> {

If I follow the breadcrumb trail to the AsExtension trait, I get this as the public API that needs implementing for a custom extension:

/// Trait to be implemented by extensions to allow them to be formatted as x509 v3 extensions by
/// builder.
pub trait AsExtension: AssociatedOid + der::Encode {
/// Should the extension be marked critical
fn critical(&self, subject: &crate::name::Name, extensions: &[Extension]) -> bool;

  • AssociatedOid makes enough sense to me.

  • der::Encode is somewhat confusing, because its documentation is just:

    Encoding trait.

    The method documentation is a little better:

    Encode this value as ASN.1 DER using the provided Writer.

    However, it is unclear how the output of this method will be treated. My particular example is the YubiKey PIV attestation policy extension, which is documented as:

    Extensions in the generated certificate:

    • ...
    • 1.3.6.1.4.1.41482.3.8: Two bytes, the first encoding pin policy and the second touch policy

    Should that map to two raw ASN.1 bytes? Is there some other ASN.1 DER wrapper around it that I need to know about? This should be handled in the yubikey crate (which I will upstream my impl to), but it is unclear what kind of verification happens on the output of der::Encode::encode.

  • AsExtension::critical makes zero sense to me. What is a "critical extension" and how should I decide whether mine is? There is no description here to guide me, or any references to external documentation I should read before deciding what to return here.

It would be helpful to improve documentation across the board here, but in particular:

  • CertificateBuilder::add_extension should document where to find existing extensions (a direct link to the list of AsExtension implementors would be ideal).
  • Either CertificateBuilder::add_extension or AsExtension should document how to go about implementing a custom extension, with considerations about correctness (how to ensure everyone can parse your extension), best practices, and whatever criticality is.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions