crypto/pkcs12: default to UTF-8.
authorAndy Polyakov <appro@openssl.org>
Mon, 25 Jul 2016 23:48:01 +0000 (01:48 +0200)
committerAndy Polyakov <appro@openssl.org>
Mon, 22 Aug 2016 11:52:55 +0000 (13:52 +0200)
Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/pkcs12/p12_attr.c
include/openssl/pkcs12.h

index a16231f..c324f50 100644 (file)
@@ -45,6 +45,16 @@ int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
         return 0;
 }
 
+int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
+                                int namelen)
+{
+    if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
+                                MBSTRING_UTF8, (unsigned char *)name, namelen))
+        return 1;
+    else
+        return 0;
+}
+
 int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,
                                 const unsigned char *name, int namelen)
 {
@@ -82,8 +92,8 @@ char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag)
         return NULL;
     if (atype->type != V_ASN1_BMPSTRING)
         return NULL;
-    return OPENSSL_uni2asc(atype->value.bmpstring->data,
-                           atype->value.bmpstring->length);
+    return OPENSSL_uni2utf8(atype->value.bmpstring->data,
+                            atype->value.bmpstring->length);
 }
 
 const STACK_OF(X509_ATTRIBUTE) *
index f324bc1..37e2847 100644 (file)
@@ -40,8 +40,8 @@ extern "C" {
 #  define PKCS12_key_gen PKCS12_key_gen_uni
 #  define PKCS12_add_friendlyname PKCS12_add_friendlyname_uni
 # else
-#  define PKCS12_key_gen PKCS12_key_gen_asc
-#  define PKCS12_add_friendlyname PKCS12_add_friendlyname_asc
+#  define PKCS12_key_gen PKCS12_key_gen_utf8
+#  define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8
 # endif
 
 /* MS key usage constants */
@@ -141,6 +141,8 @@ int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
                           int namelen);
 int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
                                 int namelen);
+int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name,
+                                 int namelen);
 int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name,
                            int namelen);
 int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag,