@@ -10,6 +10,7 @@ import (
1010 "fmt"
1111 "math/big"
1212
13+ "go.step.sm/crypto/internal/utils"
1314 "golang.org/x/crypto/cryptobyte"
1415)
1516
@@ -99,8 +100,13 @@ type certCN struct {
99100 CommonName string `asn1:"printable"`
100101}
101102
103+ type certCNUTF8 struct {
104+ OID asn1.ObjectIdentifier
105+ CommonName string `asn1:"utf8"`
106+ }
107+
102108type privateKeySubject struct {
103- List []certCN `asn1:"set"`
109+ List []any `asn1:"set"`
104110}
105111
106112func ecPrivKeyToObject (priv * ecdsa.PrivateKey , name string , id []byte , certCNs ... string ) (* Object , error ) {
@@ -141,10 +147,17 @@ func ecPrivKeyToObject(priv *ecdsa.PrivateKey, name string, id []byte, certCNs .
141147 if len (certCNs ) > 0 {
142148 sub := privateKeySubject {}
143149 for _ , cn := range certCNs {
144- sub .List = append (sub .List , certCN {
145- OID : asn1.ObjectIdentifier {2 , 5 , 4 , 3 },
146- CommonName : cn ,
147- })
150+ if utils .IsPrintableString (cn , false , false ) {
151+ sub .List = append (sub .List , certCN {
152+ OID : asn1.ObjectIdentifier {2 , 5 , 4 , 3 },
153+ CommonName : cn ,
154+ })
155+ } else {
156+ sub .List = append (sub .List , certCNUTF8 {
157+ OID : asn1.ObjectIdentifier {2 , 5 , 4 , 3 },
158+ CommonName : cn ,
159+ })
160+ }
148161 }
149162 subASN1 , err := asn1 .Marshal (sub )
150163 if err != nil {
0 commit comments