Skip to content

LoadFromStoreCert method of the CertificateLoader class does not load a certificate with an exact subject match #48545

@firerain-fd

Description

@firerain-fd

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The description of the LoadFromStoreCert method says:
Exact subject match is loaded if present, otherwise best matching certificate with the subject name that contains supplied subject. Subject comparison is case-insensitive. But it is not, the certificate with the exact value of the subject is not loaded.

The certificate.GetNameInfo(X509NameType.SimpleName, true) method returns the name of the issuer and not the subject of the certificate.
For the GetNameInfo method to return the full name of the certificate subject, you need to call the method with parameters: nameType: X509NameType.SimpleName, forIssuer: false. => certificate.GetNameInfo(X509NameType.SimpleName, false).

if (certificate.GetNameInfo(X509NameType.SimpleName, true).Equals(subject, StringComparison.InvariantCultureIgnoreCase))
{
foundCertificate = certificate;
break;
}

Expected Behavior

Load a certificate with an exact subject match if such a certificate exists.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7.0.302

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-kestrelpending-ci-rerunWhen assigned to a PR indicates that the CI checks should be rerun

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions