Description
Background and motivation
I'm the maintainer of a small ACME compatible server software, that connects ACME to ADCS.
Currently the implementation uses CERTENROLLLib to validate data around CSRs.
I now tried to move that CSR validation into managed code, to have only small code snippets that need COM interop at all and else have a generic ACME server, that might support multiple backends.
While src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509SubjectAlternativeNameExtension.cs would contain lots of the code, that is necessary to read CSRs (and especially the SANs), all besides DnsNames and IPAddresses is marked internal, which leads to duplicating code from some of those classes into my own project.
API Proposal
namespace System.Security.Cryptography.X509Certificates
{
public sealed class X509SubjectAlternativeNameExtension : X509Extension
{
// existing API omitted
public IEnumerable<GeneralNameAsn> EnumerateAlternativeNames();
}
}
API Usage
var certificateRequest = CertificateRequest.LoadSigningRequest(
Convert.FromBase64String(order.CertificateSigningRequest),
HashAlgorithmName.SHA256,
CertificateRequestLoadOptions.UnsafeLoadCertificateExtensions
);
var alternativeNames = certificateRequset.CertificateExtensions.OfType<X509SubjectAlternativeNameExtension>().SelectMany(x => x.AlternativeNames);
Alternative Designs
Since there are already methods for DnsNames and IPAddresses EnumerateDnsNames()
, EnumerateIPAddresses()
There could be enumeration by type
namespace System.Security.Cryptography.X509Certificates
{
public sealed class X509SubjectAlternativeNameExtension : X509Extension
{
// existing API omitted
public IEnumerable<OtherNameAsn> EnumerateOtherNames();
public IEnumerable<string> EnumerateRfc822Names();
public IEnumerable<byte[]> EnumerateX400Addresses();
public IEnumerable<byte[]> EnumerateDirectoryNames();
public IEnumerable<EdiPartyNameAsn> EnumerateEdiPartyNames();
public IEnumerable<string> EnumerateUris();
public IEnumerable<string> EnumerateRegisteredIds();
}
}
Risks
This entails making a bunch of classes public
, that currently are internal