Repository navigation
Closed
Labels
Milestone
Description
SubjectAltName is an extension from RFC 3280 that's fairly important to the people who need it. Currently applications make programmatic decisions for it via ToString() which has a couple of problems:
- It's localized on Windows
- It's not the same on Windows and !Windows.
Rather than exposing the whole GeneralName concept (and dealing with X400Address) the type would
- Exist
- Allow enumerating the DNSName entries
- Maybe allow enumerating the IPAddress entries
- Probably have a
MatchesHostname(string)method - Maybe have a
MatchesIPAddress(IPAddress)method.
It might make sense to put MatchesHostname on X509Certificate2, just to make things easier.
API Proposal
namespace System.Security.Cryptography.X509Certificates
{
public partial class X509Certificate2
{
// Performs RFC 6125 matching of a hostname against a certificate and the
// Subject Alternative Names.
//
// Uses IPAddress.TryParse to determine DNS match vs IP match
public bool MatchesHostname(string hostname) { throw null; }
public bool MatchesHostname(string hostname, bool allowWildcards = true, bool allowCommonName = true) { throw null; }
}
public sealed class X509SubjectAlternativeNameExtension : X509Extension
{
public X509SubjectAlternativeNameExtension() { }
public X509SubjectAlternativeNameExtension(byte[] rawData, bool critical = false) { }
public X509SubjectAlternativeNameExtension(ReadOnlySpan<byte> rawData, bool critical = false) { }
public IEnumerable<string> EnumerateDnsNames() { throw null; }
public IEnumerable<IPAddress> EnumerateIPAddresses() { throw null; }
}
}Reacted by Joseph Musser, Eugene Bekker, Anderson Matos, Dan F, Nate McMaster, Simon-Gregory-LG, Stephen Just and campersau
Activity
morganbr commentedon Jul 11, 2017
What should they do if the SubjectAltName contains a URI, email address, or other annoying kind of name?
bartonjs commentedon Jul 11, 2017
A EnumerateDnsNames() method would skip them, as would EnumerateIPAddresses().
If someone wanted to read any kind of extra name they'd need to use #22610.
danmoseley commentedon Dec 1, 2017
@bartonjs estimates 1 week remaining
bartonjs commentedon Jul 7, 2020
Related to #28771. (This issue focuses more on "make the extension type for the cert.Extensions collection", that issue focuses more on "be able to answer the question from a certificate").
stephenjust commentedon Jan 27, 2022
Would it make sense to support enumerating each of the names that SubjectAlternativeNameBuilder allows you to specify? I do think DnsName and IP Address cover the most common use cases, but from a consistency point of view it seems like we should at least support easily reading the values that we can write.
bartonjs commentedon Jan 27, 2022
I can understand it from a consistency perspective, but what's the scenario? Assuming we go the typed enumerators route (
EnumerateDnsNames(),EnumerateIPAddresses(), etc) there's always going to be data that you need to drop to AsnReader to recover (e.g. I have both dnsName and iPAddress values, but how were they interleaved?). The nice thing about accepting that is that we get to focus on what's actually useful (and making it easy to use) instead of what's just completionist.For UPN, the only thing I know of that uses/used it is Windows Active Directory Certificate Services, issuing a smartcard-style cert to a user... and it only supports one UPN value. So if AD logon felt like using .NET to achieve their results, they'd be served enough with cert.GetNameInfo; thus there's not really a scenario for UPN.
If there's a scenario for Uri/Email/etc, we could add them.
stephenjust commentedon Jan 27, 2022
Can we specify that when enumerating DNS names and IP addresses, sort order will be maintained? i.e. the records may be interleaved in the raw data, but the first returned DNS name will be the first record if that type specified in raw data?
We definitely have some scenarios where services only look at the first DNS Name specified in the alternative names, I think to match the behavior of win32. It's a niche use case, but it seems like a desirable property in general for ordering to be predictable.
In contrast, X509Certificate2.GetNameInfo does not define which of multiple names will be returned, and the ambiguity can lead to incorrect assumptions.
1 remaining item
deeprobin commentedon Jun 14, 2022
Is there any reason not to seal this type?
bartonjs commentedon Jun 14, 2022
@deeprobin Just a transcription error, thanks for noticing.
bartonjs commentedon Jul 14, 2022
Video
Looks good as proposed