Skip to content

Commit bb151c1

Browse files
author
Cam Soper
committed
issue 43284
1 parent 871f312 commit bb151c1

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
3131
|-------------------------------------------------------------------------------------------------------|-------------------|--------------------|
3232
| [Environment variable renamed to DOTNET_ICU_VERSION_OVERRIDE](globalization/10.0/version-override.md) | Behavioral change | Preview 1 |
3333

34+
## Cryptography
35+
36+
| Title | Type of change | Introduced version |
37+
|--------------------------------------------------------------------------------------------------------|-------------------|--------------------|
38+
| [X500DistinguishedName validation is stricter](cryptography/10.0/x500distinguishedname-validation.md) | Behavioral change | Preview 1 |
39+
3440
## Windows Forms
3541

3642
| Title | Type of change | Introduced version |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "Breaking change: X500DistinguishedName validation is stricter"
3+
description: Learn about the .NET 10 breaking change in core .NET libraries where X500DistinguishedName validation is stricter.
4+
ms.date: 01/30/2025
5+
---
6+
# X500DistinguishedName validation is stricter
7+
8+
Starting in .NET 10, the <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedName.%23ctor*> constructor that accepts a string-encoded distinguished name may reject previously accepted invalid input or encode it differently on non-Windows systems. This aligns with encoding specifications and Windows behavior.
9+
10+
## Previous behavior
11+
12+
Previous versions of .NET on non-Windows systems would permit incorrect distinguished names or encode them in a way not permitted by X.520 encoding rules. The <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags.ForceUTF8Encoding?displayProperty=nameWithType> flag would force components to use a UTF8String even if it was not a valid representation.
13+
14+
## New behavior
15+
16+
Starting in .NET 10, components violating encoding rules will throw a `CryptographicException` on non-Windows systems, matching Windows behavior. The <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags.ForceUTF8Encoding?displayProperty=nameWithType> flag will only UTF-8 encode components when permissible.
17+
18+
## Version introduced
19+
20+
.NET 10 Preview 1
21+
22+
## Type of breaking change
23+
24+
This change is a [behavioral change](../../categories.md#behavioral-change).
25+
26+
## Reason for change
27+
28+
Different X.500 components have specific encoding rules. For example, `id-at-telephoneNumber` must be encoded as an ASN.1 <xref:System.Formats.Asn1.UniversalTagNumber.PrintableString>. The exclamation point character is invalid for a PrintableString, so:
29+
30+
```C#
31+
new X500DistinguishedName("Phone=!!");
32+
```
33+
34+
This would throw an exception on Windows but was encoded as a UTF8String on non-Windows. Similarly, using <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags.ForceUTF8Encoding?displayProperty=nameWithType> would force UTF8String encoding even when not permitted:
35+
36+
```C#
37+
new X500DistinguishedName("Phone=000-555-1234", X500DistinguishedNameFlags.ForceUTF8Encoding);
38+
```
39+
40+
This change ensures encoding aligns with specifications and Windows behavior.
41+
42+
## Recommended action
43+
44+
Generally, no action is needed unless compatibility with incorrect encoding is required. Use <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedNameBuilder?displayProperty=nameWithType> to create instances with desired encoding:
45+
46+
```C#
47+
using System.Formats.Asn1;
48+
using System.Security.Cryptography.X509Certificates;
49+
50+
X500DistinguishedNameBuilder builder = new();
51+
builder.Add("2.5.4.20", "000-555-1234", UniversalTagNumber.UTF8String);
52+
X500DistinguishedName dn = builder.Build();
53+
```
54+
55+
## Affected APIs
56+
57+
- <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedName.%23ctor(System.String)>
58+
- <xref:System.Security.Cryptography.X509Certificates.X500DistinguishedName.%23ctor(System.String,System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags)>
59+

docs/core/compatibility/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ items:
2020
href: core-libraries/10.0/generic-math.md
2121
- name: LDAP DirectoryControl parsing is now more stringent
2222
href: core-libraries/10.0/ldap-directorycontrol-parsing.md
23+
- name: Cryptography
24+
items:
25+
- name: X500DistinguishedName validation is stricter
26+
href: cryptography/10.0/x500distinguishedname-validation.md
2327
- name: Globalization
2428
items:
2529
- name: Environment variable renamed to DOTNET_ICU_VERSION_OVERRIDE
@@ -1570,6 +1574,10 @@ items:
15701574
href: corefx.md
15711575
- name: Cryptography
15721576
items:
1577+
- name: .NET 10
1578+
items:
1579+
- name: X500DistinguishedName validation is stricter
1580+
href: cryptography/10.0/x500distinguishedname-validation.md
15731581
- name: .NET 9
15741582
items:
15751583
- name: SafeEvpPKeyHandle.DuplicateHandle up-refs the handle

0 commit comments

Comments
 (0)