diff --git a/src/libraries/System.Security.Cryptography.Encoding/src/Internal/Cryptography/OidLookup.cs b/src/libraries/System.Security.Cryptography.Encoding/src/Internal/Cryptography/OidLookup.cs index a3fb3cf9acda49..7a72349a042c78 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/src/Internal/Cryptography/OidLookup.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/src/Internal/Cryptography/OidLookup.cs @@ -14,8 +14,8 @@ internal static partial class OidLookup private static readonly ConcurrentDictionary s_lateBoundOidToFriendlyName = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary s_lateBoundFriendlyNameToOid = - new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private static readonly ConcurrentDictionary s_lateBoundFriendlyNameToOid = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); // // Attempts to map a friendly name to an OID. Returns null if not a known name. @@ -80,13 +80,19 @@ internal static partial class OidLookup mappedOid = NativeFriendlyNameToOid(friendlyName, oidGroup, fallBackToAllGroups); - if (shouldUseCache && mappedOid != null) + if (shouldUseCache) { s_lateBoundFriendlyNameToOid.TryAdd(friendlyName, mappedOid); // Don't add the reverse here. Friendly Name => OID is a case insensitive search, // so the casing provided as input here may not be the 'correct' one. Just let // ToFriendlyName capture the response and cache it itself. + + // Also, mappedOid could be null here if the lookup failed. Allowing storing null + // means we're able to cache that a lookup failed so we don't repeat it. It's + // theoretically possible, however, the failure could have been intermittent, e.g. + // if the call was forced to follow an AD fallback path and the relevant servers + // were offline. } return mappedOid; diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs index 10ac6e7480a1f6..3b01e58aa21780 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs @@ -377,7 +377,7 @@ public IEnumerable Extensions { CERT_EXTENSION* pCertExtension = pCertInfo->rgExtension + i; string oidValue = Marshal.PtrToStringAnsi(pCertExtension->pszObjId)!; - Oid oid = new Oid(oidValue); + Oid oid = new Oid(oidValue, friendlyName: null); bool critical = pCertExtension->fCritical != 0; byte[] rawData = pCertExtension->Value.ToByteArray();