Skip to content

Commit 2ce7e1b

Browse files
ImdsV2: Implemented downlevel polyfill for CertificateRequest (#5454)
1 parent ea15d19 commit 2ce7e1b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/client/Microsoft.Identity.Client/ManagedIdentity/V2/CertificateRequest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
#if !NET7_0_OR_GREATER
45
using System;
56
using System.Collections.ObjectModel;
67
using System.Formats.Asn1;
@@ -10,6 +11,12 @@
1011

1112
namespace Microsoft.Identity.Client.ManagedIdentity.V2
1213
{
14+
/// <summary>
15+
/// Downlevel polyfill for System.Security.Cryptography.X509Certificates.CertificateRequest
16+
/// that provides OtherRequestAttributes support for frameworks prior to .NET 7.0.
17+
/// This file is conditionally included only for net462, net472, and netstandard2.0.
18+
/// For .NET 8.0+, the built-in CertificateRequest class is used instead.
19+
/// </summary>
1320
internal class CertificateRequest
1421
{
1522
private X500DistinguishedName _subjectName;
@@ -233,3 +240,4 @@ internal byte[] CreateSigningRequest()
233240
}
234241
}
235242
}
243+
#endif

src/client/Microsoft.Identity.Client/ManagedIdentity/V2/Csr.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ internal static string Generate(string clientId, string tenantId, CuidInfo cuid)
1414
{
1515
using (RSA rsa = CreateRsaKeyPair())
1616
{
17-
CertificateRequest req = new CertificateRequest(
17+
// Use custom polyfill for downlevel frameworks (net462, net472, netstandard2.0)
18+
// See CertificateRequest.cs
19+
var req = new CertificateRequest(
1820
new X500DistinguishedName($"CN={clientId}, DC={tenantId}"),
1921
rsa,
2022
HashAlgorithmName.SHA256,

0 commit comments

Comments
 (0)