Skip to content

Wrong C509 to X509 encoding for otherName #289

Description

@shmset

While testing the Rust encoding tool with cargo r l, I noticed that one of the certificates could not be encoded and reconstructed. The encoding for the Extension > GeneralName > OtherName seems to be wrong, in my case this was a PermanentIdentifer.

The DER encoded value of the x509 certificate is:

SEQUENCE: (2 elem)
  [0]: (2 elem)
    OBJECT_IDENTIFIER: 1.3.6.1.5.5.7.8.3|permanentIdentifier
    [0] : (1 elem)
      SEQUENCE: (2 elem)
        UTF8String: c85...
        OBJECT_IDENTIFIER: 2.23.133.12.2
  [0]: (2 elem)
    OBJECT_IDENTIFIER: 1.3.6.1.5.5.7.8.4|hwModuleName
    [0] : (1 elem)
      SEQUENCE : (2 elem)
        OBJECT_IDENTIFIER: 2.23.133.1.2
        OCTET_STRING: (57 byte)|4942...

After encoding it to CBOR and back, the value is this:

SEQUENCE: (2 elem)
  SEQUENCE : (2 elem)
    OBJECT_IDENTIFIER 1.3.6.1.5.5.7.8.3|permanentIdentifier
    SEQUENCE: (2 elem)
      UTF8String: c85...
      OBJECT_IDENTIFIER: 2.23.133.12.2
  [0] : (2 elem)
    OBJECT_IDENTIFIER: 1.3.6.1.5.5.7.8.4|hwModuleName
    [0]: (1 elem)
      SEQUENCE: (2 elem)
        OBJECT_IDENTIFIER: 2.23.133.1.2
        OCTET_STRING: (57 byte)|4942...

It seem the value of otherName is correctly encoded structure is not for the permanentIdentifier. The hwModuleName however is correct. From RFC 5280:

   OtherName ::= SEQUENCE {
        type-id    OBJECT IDENTIFIER,
        value      [0] EXPLICIT ANY DEFINED BY type-id }

I created another certificate to confirm this in Python, which resulted in the same behaviour described above.

Extension creation:

custom_oid = x509.ObjectIdentifier("1.2.3.4.5.6")
other_name_asn = OctetString( b"custom-identifier")
other_name = x509.OtherName(custom_oid, other_name_asn.dump())
cert_builder = cert_builder.add_extension(
    x509.SubjectAlternativeName([
        other_name
    ]), critical=False)

I'm unsure if the problem is in the X509 to C509 conversion or when converting it back.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions