X509 subject attributes are encoded as PRINTABLESTRING instead of UTF8STRING

126 views
Skip to first unread message

Atul Mundlik

unread,
Nov 17, 2022, 11:22:50 AM11/17/22
to golang-nuts
Hi All,
First post on the group,

I am using  go version go1.18.4 darwin/arm64.
I am trying to create X509 certificate with following code.

var COMMON_NAME = asn1.ObjectIdentifier([]int{2, 5, 4, 3})
 serial := new(big.Int).SetUint64(1)

subjectExtraNames = append(subjectExtraNames, pkix.AttributeTypeAndValue{Type: COMMON_NAME, Value: "golang"})

caCertTemplate := &x509.Certificate{
SerialNumber: 1,
IsCA: true,
NotBefore: time.Now(),
Subject: pkix.Name{ExtraNames: pkixAttrTypeValue},
NotAfter: time.Now().AddDate(10, 0, 0),

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
BasicConstraintsValid: true,
}

when I inspect the created certificate using asn1parse -in <PathToPemFile>

   31:d=4  hl=2 l=  13 cons: SEQUENCE          
   33:d=5  hl=2 l=   3 prim: OBJECT            :commonName
   38:d=5  hl=2 l=   6 prim: PRINTABLESTRING   :golang
the common name is PRINTABLESTRING and not the UTF8STRING.

As i understand, golang strings are utf8 default then why it is not UTF8STRING ?

However, in above code when i use below to create certificate
subjectExtraNames = append(subjectExtraNames, pkix.AttributeTypeAndValue{Type: COMMON_NAME, Value: "é um"})
and when I inspect certificate then it shows UTF8STRING for é um"

If this is how it is then is there a way to get a string without special characters as UTF8STRING in certificate?




Reply all
Reply to author
Forward
0 new messages