Skip to content

Commit 687c51d

Browse files
authored
Require UTF8 encoding in GetX509NameInfo.
1 parent 3a59145 commit 687c51d

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/libraries/Native/Unix/System.Security.Cryptography.Native/openssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ BIO* CryptoNative_GetX509NameInfo(X509* x509, int32_t nameType, int32_t forIssue
564564
if (answer)
565565
{
566566
BIO* b = BIO_new(BIO_s_mem());
567-
ASN1_STRING_print_ex(b, answer, 0);
567+
ASN1_STRING_print_ex(b, answer, ASN1_STRFLGS_UTF8_CONVERT);
568568
return b;
569569
}
570570
}
@@ -646,7 +646,7 @@ BIO* CryptoNative_GetX509NameInfo(X509* x509, int32_t nameType, int32_t forIssue
646646
if (str)
647647
{
648648
BIO* b = BIO_new(BIO_s_mem());
649-
ASN1_STRING_print_ex(b, str, 0);
649+
ASN1_STRING_print_ex(b, str, ASN1_STRFLGS_UTF8_CONVERT);
650650
sk_GENERAL_NAME_free(altNames);
651651
return b;
652652
}

src/libraries/System.Security.Cryptography.X509Certificates/tests/PropsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,20 @@ public static void TestGetNameInfo()
389389
}
390390
}
391391

392+
[Theory]
393+
[InlineData(true)]
394+
[InlineData(false)]
395+
public static void GetNameInfo_HandlesUtf8Encoding(bool issuer)
396+
{
397+
using (X509Certificate2 c = new X509Certificate2(TestData.CertificateWithUtf8))
398+
{
399+
// Russian word for "potato" in Cyrillic, kartoshka.
400+
string expected = "\u043A\u0430\u0440\u0442\u043E\u0448\u043A\u0430";
401+
string cn = c.GetNameInfo(X509NameType.SimpleName, issuer);
402+
Assert.Equal(expected, cn);
403+
}
404+
}
405+
392406
[Fact]
393407
public static void ComplexGetNameInfo_SimpleName_Cert()
394408
{

src/libraries/System.Security.Cryptography.X509Certificates/tests/TestData.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,33 @@ internal struct ECDsaCngKeyValues
24632463
"028bedeefab9a2be80466fe278fdc50db1b9530e1796b23271b4df2cddd9" +
24642464
"4769c8a21a8f66c6d4bc181713").HexToByteArray();
24652465

2466+
internal static byte[] CertificateWithUtf8 = (
2467+
"30820315308201fda003020102020900e48b784d93645921300d06092a864886" +
2468+
"f70d01010b0500301b3119301706035504030c10d0bad0b0d180d182d0bed188" +
2469+
"d0bad0b0301e170d3231303931343230353635365a170d333230383237323035" +
2470+
"3635365a301b3119301706035504030c10d0bad0b0d180d182d0bed188d0bad0" +
2471+
"b030820122300d06092a864886f70d01010105000382010f003082010a028201" +
2472+
"0100c394711b3839a612aaadafde855ccc3479bc1dbe253a29e508cc46464efb" +
2473+
"ab09b16b85fb67e4be0ab8b09fa6ff73cb3ec5d8f8b7d2869a79c414d025a43e" +
2474+
"4c158c9711638dbfb070ef92b3633037d5e633a870ed024ab9017c97e26f02de" +
2475+
"2273dd92c0837a95ff12229981cd661b140afd841671d3397fd44aea05878dd0" +
2476+
"9362bd2de8da17225dd3caf0181aadf2c9e13faefbbce3ce80ef355dcc15c1b9" +
2477+
"c6e86bb1cddf32b3113e7a72ad3799cc67f64ea34c0518c22727972802084801" +
2478+
"e6565b2323e87fd20019a9db151e87b2b1db004583e15dd64c5393439a0ba5ed" +
2479+
"3b9fd262c8d8bf0263dcba092ca5591d4d34f990daa9ee41811cec6229f2121b" +
2480+
"582f0203010001a35c305a301b0603551d11041430128210786e2d2d38306161" +
2481+
"326162746c6f3363301d0603551d250416301406082b0601050507030106082b" +
2482+
"06010505070302300f0603551d130101ff040530030101ff300b0603551d0f04" +
2483+
"040302028c300d06092a864886f70d01010b050003820101001c0512d3d99267" +
2484+
"4ca3a1fdf942052064ffbda824aaeff07d9869eefa86e592102afca0dba4e267" +
2485+
"e54753552fc23da97b18f739ea437794aac5bb2ae7413ae54ce921b4b96fe420" +
2486+
"f3fd86f922adcab202589823c4095fc6e7904e61be1716faec7e09ce2d1bf431" +
2487+
"fa9fc2d7284689d2c940f7d027e16b9c3305f9cd6d5dc6bfee9089d85d342f5b" +
2488+
"d07920c51899288674a1732708a7e3a39fb11c152417d50a3bb9b09975852baa" +
2489+
"39767c289baea9330902ea38388932964c410cd22049415712223fb5710a21ef" +
2490+
"153ac22391a1603547ffb3f9b328c59e59b5d64568b9c451df233fe9a581116f" +
2491+
"05be8c67b92bc7df9984f30535ad53817cb4abcd77cb521856").HexToByteArray();
2492+
24662493
internal static byte[] ConcatenatedPemFile = ByteUtils.AsciiBytes(
24672494
@"-----BEGIN CERTIFICATE-----
24682495
MIIFcDCCBFigAwIBAgIQB6krbZc11OZ5l2/FnU3CpTANBgkqhkiG9w0BAQsFADBG

0 commit comments

Comments
 (0)