From: Andy Polyakov Date: Mon, 25 Jul 2016 23:48:01 +0000 (+0200) Subject: crypto/pkcs12: default to UTF-8. X-Git-Tag: OpenSSL_1_1_0~95 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b799aef863a81c9a9d5dbffae12cca912ae348b2;p=oweals%2Fopenssl.git crypto/pkcs12: default to UTF-8. Reviewed-by: Richard Levitte --- diff --git a/crypto/pkcs12/p12_attr.c b/crypto/pkcs12/p12_attr.c index a16231f074..c324f50514 100644 --- a/crypto/pkcs12/p12_attr.c +++ b/crypto/pkcs12/p12_attr.c @@ -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) * diff --git a/include/openssl/pkcs12.h b/include/openssl/pkcs12.h index f324bc1996..37e2847b3f 100644 --- a/include/openssl/pkcs12.h +++ b/include/openssl/pkcs12.h @@ -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,