Skip to content

[7.0-rc1] Fix PopulateCertificatesFromStore on macOS to only return store certs #43358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

adityamandaleeka
Copy link
Member

@adityamandaleeka adityamandaleeka commented Aug 18, 2022

Some certificate export scenarios (exporting to a PEM file for instance) will lead us to try to export an RSA private key. Without this change, the first one of these exports works, and then subsequent ones fail with a vague crypto exception from SecKeyCopyExternalRepresentation.

The fix is simple; we have code in the certificate manager that takes the union of certificates in the new on-disk location and the store (keychain).

The code was previously doing:

var onDiskAndKeychain = certsFromDisk.Intersect(certsFromStore, ThumbprintComparer.Instance);

which meant that the actual certs returned were the ones loaded from disk (and also happened to be in the keychain), whereas what we want to return is the certs from the keychain that also have on-disk versions. The reason why it works the first time is that the on-disk versions don't exist yet.

This change flips the Intersect call and adds a comment about all of this. While I was here I also noticed a typo on a nearby store location check so I fixed that too.

Fixes #43335

@adityamandaleeka
Copy link
Member Author

@MackinnonBuck this fixes the issue we were looking at.

@adityamandaleeka
Copy link
Member Author

@HaoK PTAL

// Note that the actual certs we populate need to be the ones from the store location, and
// not the version from disk, since we may do other operations with these certs later (such
// as exporting) which would fail with crypto errors otherwise.
var onDiskAndKeychain = certsFromStore.Intersect(certsFromDisk, ThumbprintComparer.Instance);
Copy link
Member

Choose a reason for hiding this comment

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

We should probably consider at least starting a list of some of these things for maybe a single CTI scenario for to do some ad hoc verification every once in a while, given that we don't have any test coverage for these kinds of things, (for our future selves)

Copy link
Member Author

Choose a reason for hiding this comment

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

This was actually caught by the WebTools CTI team (see linked issue) as part of their RC 1 pass.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, so we do have coverage, that makes me feel better that they are exercising things then

Copy link
Member

@HaoK HaoK left a comment

Choose a reason for hiding this comment

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

Its good that CTI catches this :)

@adityamandaleeka
Copy link
Member Author

Filed #43374 for the failing H3 test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants