Skip to content

Conversation

@simon-curtis
Copy link
Contributor

CertificateLoader loading wrong certificate

Fixes certificate selection by subject name

Description

The check for exact match to certificate subject fails as the forIssuer flag is set to true. This returns the issuer and not the subject this means that if two certificates have a partial match, it will just select the first one that has the search value in the name.

Fixes #49062 (in this specific format)

@ghost ghost added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member labels Sep 1, 2023
@ghost
Copy link

ghost commented Sep 1, 2023

Thanks for your PR, @simon-curtis. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@martincostello
Copy link
Member

I imagine the team would want a test to be added for this if the change is taken 😃

@simon-curtis
Copy link
Contributor Author

I would tend to agree, but how do you provide a unit test for something to environment specific? I.e. there aren't any tests covering this now.

@amcasey
Copy link
Member

amcasey commented Sep 2, 2023

I would tend to agree, but how do you provide a unit test for something to environment specific? I.e. there aren't any tests covering this now.

It's possible we have a way to mock the store. Let me see if I can find a test that does that (there may not be one).

@amcasey
Copy link
Member

amcasey commented Sep 2, 2023

This looks correct to me, but let's see if we can figure out a way to test this.

@amcasey
Copy link
Member

amcasey commented Sep 2, 2023

Re-running the tests, since the failure is unrelated.
/azp run

@amcasey
Copy link
Member

amcasey commented Sep 2, 2023

There's one test in HttpsConnectionMiddlewareTests, but it's not great. Given that the original PR didn't add a test and the fix seems self-explanatory (after making it a named argument 😉), I can live without one, assuming there's been some manual validation.

@halter73 @martincostello If you happen to know how to add test coverage for this, feel free to jump in.

@simon-curtis simon-curtis force-pushed the patch-1 branch 2 times, most recently from e3e3061 to 28567c9 Compare September 2, 2023 08:29
@simon-curtis
Copy link
Contributor Author

Im just trying to load the solution up in Rider, and oh boy it's taking a while.

Is it just the certificate.GetNameInfo(..., false) behaivour we need to test rather then the whole method inside CertificateLoader.LoadFromStoreCert?

The check for exact match to certificate subject fails as the `forIssuer` flag is set to true. This returns the `issuer` and not the `subject` this means that if two certificates have a partial match, it will just select the first one that has the search value in the name.

[https://github.com/dotnet/aspnetcore/issues/49062](https://github.com/dotnet/aspnetcore/issues/49062)
Copy link
Contributor Author

@simon-curtis simon-curtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change flag to named argument

@Tratcher
Copy link
Member

Tratcher commented Sep 5, 2023

@amcasey can you do a manual test for this change?

@amcasey
Copy link
Member

amcasey commented Sep 5, 2023

Im just trying to load the solution up in Rider, and oh boy it's taking a while.

Don't forget about Codespaces. 😉

@amcasey
Copy link
Member

amcasey commented Sep 6, 2023

Sorry, it took me a little while to remember how to create certs with just the right properties. LGTM

@amcasey
Copy link
Member

amcasey commented Sep 6, 2023

Any remaining concerns @Tratcher?

@Tratcher Tratcher merged commit 045afcd into dotnet:main Sep 6, 2023
@ghost ghost added this to the 9.0-preview1 milestone Sep 6, 2023
@simon-curtis simon-curtis deleted the patch-1 branch September 6, 2023 21:20
@dan-olsen
Copy link

@Tratcher Anyway this could be back ported to .NET 8? We only use LTS versions and I would not like to have to continue to have the workaround @simon-curtis mentioned in #49062 until .NET 10.

@ghost
Copy link

ghost commented Oct 31, 2023

Hi @dan-olsen. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@Tratcher
Copy link
Member

@dan-olsen it looks like the regression happened in 6.0 (#34582). Given the availability of a workaround, and so few reports of the issue, it's unlikely to qualify for an 8.0 patch. If this is a significant blocker for you, please open a new issue and explain why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTPS certificate exact match using Issuer's SimpleName instead of Certificate's

6 participants