Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d243970

Browse files
committed
Make Unix X500DistinguishedName tests pass if issue 1985 ("S=" vs "ST=") was the only issue.
By transforming the Windows/ITU "S=" into the OpenSSL "ST=" the rest of the test around X500DistinguishedName should proceed.
1 parent 73cbbdd commit d243970

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void TestIssuer()
1313
using (var c = new X509Certificate2(TestData.MsCertificate))
1414
{
1515
Assert.Equal(
16-
"CN=Microsoft Code Signing PCA, O=Microsoft Corporation, L=Redmond, S=Washington, C=US",
16+
TestData.NormalizeX500String("CN=Microsoft Code Signing PCA, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"),
1717
c.Issuer);
1818
}
1919
}
@@ -24,7 +24,7 @@ public static void TestSubject()
2424
using (var c = new X509Certificate2(TestData.MsCertificate))
2525
{
2626
Assert.Equal(
27-
"CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US",
27+
TestData.NormalizeX500String("CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"),
2828
c.Subject);
2929
}
3030
}
@@ -216,7 +216,7 @@ public static void TestSubjectName()
216216
using (var c = new X509Certificate2(TestData.MsCertificate))
217217
{
218218
Assert.Equal(
219-
"CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US",
219+
TestData.NormalizeX500String("CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"),
220220
c.SubjectName.Name);
221221
}
222222
}
@@ -227,7 +227,7 @@ public static void TestIssuerName()
227227
using (var c = new X509Certificate2(TestData.MsCertificate))
228228
{
229229
Assert.Equal(
230-
"CN=Microsoft Code Signing PCA, O=Microsoft Corporation, L=Redmond, S=Washington, C=US",
230+
TestData.NormalizeX500String("CN=Microsoft Code Signing PCA, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"),
231231
c.IssuerName.Name);
232232

233233
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,5 +370,20 @@ internal static class TestData
370370
"29008DE8B851E2C30B6BF73F219BCE651E5972E62D651BA171D1DA9831A449D99" +
371371
"AF4E2F4B9EE3FD0991EF305ADDA633C44EB5E4979751280B3F54F9CCD561AC27D" +
372372
"3426BC6FF32E8E1AAF9F7C0150A726B").HexToByteArray();
373+
374+
internal static string NormalizeX500String(string expected)
375+
{
376+
if (StringComparer.Ordinal.Equals("Windows_NT", Environment.GetEnvironmentVariable("OS")))
377+
{
378+
return expected;
379+
}
380+
381+
// Windows calls OID(2.5.4.8) "S", which matches ITU X.520.
382+
// OpenSSL calls it "ST", because RFC1327 calls "S" surname.
383+
//
384+
// This provides a test mitigation for issue 1985, allowing the
385+
// thrust of the test to proceed with this one known problem.
386+
return expected.Replace(" S=", " ST=");
387+
}
373388
}
374389
}

0 commit comments

Comments
 (0)