Skip to content

X509 certificates can be easily found by target hostname #59870

Closed

Description

@bartonjs

Given an X509Certificate2Collection and a host identifier, it should be easy to find certificates that would match that hostname under the TLS host matching rules.


There are a different aspects or interpretations to this problem:

  • Should the matching include wildcard evaluation? (Probably yes)
  • Should the matching consider name constraints by the CAs? (We probably need more tests here before we can have an informed opinion)
    • Depending on how things are reported, maybe we need both a "using just this cert" fast interpretation and a "using the chain" slow interpretation.
  • Should the matching include "the target looks like an IP Address, match san/[@type=ipAddress]? ("Yes" if wildcard is yes, since that is matching what SslStream would do. "Probably yes" irrespective)
  • Should there be options for most of these things?
  • Should there be an option for "only test in the SAN extension?" (with no Subject/CN fallback)?
  • Should we make it easier to ask if a cert is valid for a purpose?
    • Should that have an option of "require EKU"? (Yeah, probably, since things like RFC3161 claim enforcement of that)
  • Should we make an accelerator for TLS-Server-purpose+this host?
    • The original thought that prompted this was a new find type for X509Certificate2Collection.Find... so... maybe 😄.

sslServerOptions.ServerCertificateSelectionCallback =
    (sender, hostName) => _cuMy.Certificates.First(c => c.IsValidForTls(hostName);

Though that's possibly over-specialization on the instance. _cuMy.Certificates.Find(X509FindType.FindTlsServerCertificate, hostName, validOnly: whatever).First() might be more reasonable (note that both examples are bad in practice because of how much finalization they create)


This might just be the X509Certificate2::IsMatchForHostName from #28771 plus a similar X509Certificate2::IsValidForPurpose(oid, bool requireEku), and possibly the ease of use unifier as a collection Find option.

Activity

  1. added
    User Story
    on Oct 1, 2021
  2. added this to the 7.0.0 milestone on Oct 1, 2021
  3. ghost added
    untriaged
    on Oct 1, 2021
  4. removed
    untriaged
    on Oct 1, 2021
  5. changed the title [-]Scenario: Make it easy to find a certificate appropriate to a target hostname[/-] [+]X509 certificates can be easily found by target hostname[/+] on Jan 9, 2022
  6. StephenBonikowsky commented on Jun 6, 2022

    @StephenBonikowsky
    Contributor

    @jeffhandley do you think this will still land in .NET 7?

  7. bartonjs commented on Jun 13, 2022

    @bartonjs
    MemberAuthor

    X509Certificate2Collection.Find has some quirks around certificate cloning (it returns all new objects, not a filtered collection), making it a non-ideal API.

    The API proposal in #22699 includes adding a MatchesHostname to X509Certificate2, which addresses the hardest part of this feature request.

  8. ghost added
    in-pr
    on Jul 18, 2022
  9. ghost removed
    in-pr
    on Jul 20, 2022
  10. ghost locked as resolved and limited conversation to collaborators on Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Team:LibrariesUser Storyarea-System.Security

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions