You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is because Go always hex-encodes the asn.1 encoding of the value, even though RFC 2253 states that the value is supposed to just be used as its own string encoding. https://tools.ietf.org/html/rfc2253#section-2.4
Otherwise, if the AttributeValue is of a type which has a string
representation, the value is converted first to a UTF-8 string
according to its syntax specification (see for example section 6 of
[4]).
Note that OpenSSL gives the expected output when viewing a certificate or CSR with a custom name.
I read the previous spec paragraph as saying that this is the correct form when the type is unknown and expressed as a dotted decimal.
If the AttributeValue is of a type which does not have a string
representation defined for it, then it is simply encoded as an
octothorpe character ('#' ASCII 35) followed by the hexadecimal
representation of each of the bytes of the BER encoding of the X.500
AttributeValue. This form SHOULD be used if the AttributeType is of
the dotted-decimal form.
The example you copied is specifically for an "octet string", hence the 04 prefix. However, the custom DN in my example is actually a "printable string", hence the 13 prefix. It should thus be used as its own string representation
The type is UTF8String (not for example an octect string). Requoting @rittneje from RFC 2253:
Otherwise, if the AttributeValue is of a type which has a string
representation, the value is converted first to a UTF-8 string
according to its syntax specification (see for example section 6 of
[4]).
UTF8String has a string representation and does not even need conversion, so it should be printed as:
Unfortunately, we are bound to the RFC 2253 format by the docs and that format requires any non-standard attribute to be printed as a dotted OID and hex-encoded value.
But this is not what RFC 2253 says. RFC 2253 does not mention "non-standard attributes"; it says "does not have a string representation" which is a different thing:
If the AttributeValue is of a type which does not have a string
representation defined for it, then it is simply encoded as an
octothorpe character ('#' ASCII 35) followed by the hexadecimal
representation
Activity
dmitshur commentedon Jul 15, 2019
/cc @FiloSottile
FiloSottile commentedon Oct 1, 2019
I read the previous spec paragraph as saying that this is the correct form when the type is unknown and expressed as a dotted decimal.
There is even an example for it in Section 5.
Can you provide an example certificate?
rittneje commentedon Oct 2, 2019
Here is a sample CSR:
OpenSSL shows the custom distinguished name as a string:
The OpenSSL output is preferable over the current Go output because it is human readable.
rittneje commentedon Mar 19, 2021
@FiloSottile Wanted to follow up on this.
The example you copied is specifically for an "octet string", hence the
04prefix. However, the custom DN in my example is actually a "printable string", hence the13prefix. It should thus be used as its own string representationrittneje commentedon Jul 29, 2021
ping @FiloSottile
rittneje commentedon Aug 22, 2021
@FiloSottile Is this something you will consider fixing, given what I mentioned?
rittneje commentedon Oct 19, 2021
@FiloSottile is there someone else I should CC?
bjanders commentedon Apr 21, 2022
I agree with @rittneje . Here is a simple example. Create a certificate with openssl:
The ASN.1 structure of the Subject DN in cert.crt:
SEQUENCE (1 elem) SET (1 elem) SEQUENCE (2 elem) OBJECT IDENTIFIER 0.9.2342.19200300.100.1.1 userID UTF8String foobarThe type is UTF8String (not for example an octect string). Requoting @rittneje from RFC 2253:
UTF8String has a string representation and does not even need conversion, so it should be printed as:
Not like go1.18.1 does:
In #39924 @FiloSottile says:
But this is not what RFC 2253 says. RFC 2253 does not mention "non-standard attributes"; it says "does not have a string representation" which is a different thing:
rittneje commentedon Jun 28, 2022
cc @rolandshoemaker
rittneje commentedon Jan 16, 2023
ping @FiloSottile
bjanders commentedon Jan 16, 2023
I don't think @FiloSottile is working on this project anymore. I guess the fastest way to fix this is to fix it ourselves and request a pull.
12 remaining items
odeke-em commentedon Dec 18, 2025
Rolling over to Go1.27 as the CL didn't get a review.
gopherbot commentedon May 4, 2026
Change https://go.dev/cl/773800 mentions this issue:
crypto/x509/pkix: make Name.String correctly print ASN1 printable stringscrypto/x509/pkix: render string-typed attribute values as strings