Skip to content

[Https] Fix for issue getting private key after having previously exported it - #21734

Closed
javiercn wants to merge 1 commit into
release/5.0-preview5from
javiercn/trust-export-candidate-workaround
Closed

[Https] Fix for issue getting private key after having previously exported it#21734
javiercn wants to merge 1 commit into
release/5.0-preview5from
javiercn/trust-export-candidate-workaround

Conversation

@javiercn

@javiercn javiercn commented May 12, 2020

Copy link
Copy Markdown
Member

Fixes #21733

The fix here is to cache the results for each certificate we check for exportable keys the first time so as to avoid running into the issue mentioned in .NET Core.

This is a workaround for an underlying runtime issue, which will be fixed in .NET 5.0: dotnet/runtime#36273

@Pilchie Pilchie added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label May 12, 2020
@mkArtakMSFT mkArtakMSFT added this to the 5.0.0-preview5 milestone May 12, 2020
@mkArtakMSFT mkArtakMSFT linked an issue May 12, 2020 that may be closed by this pull request
@Pilchie

Pilchie commented May 12, 2020

Copy link
Copy Markdown
Member

👀

@javiercn
javiercn requested a review from pranavkm May 12, 2020 18:48

@dougbu dougbu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we get dotnet/runtime#36287 into preview5 (not sure why that currently targets 'master'), would this change be needed?

// Cache to store the result of validating whether a key is exportable or not.
// This avoid requesting the key multiple times and avoids an issue when we try to access
// the key after it has been exported.
private Dictionary<string, bool> _areKeysExportable = new Dictionary<string, bool>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What prevents this dictionary from unbounded growth?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we get dotnet/runtime#36287 into preview5 (not sure why that currently targets 'master'), would this change be needed?

From our last tactics discussion dotnet/runtime were planning to do this after preview5. Given that this seems to be happening in preview5, we can pause on this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just confirmed with the runtime team - they'll be taking the fix later in 5.0. So this is still needed!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And it seems I've been overruled by the higher powers and the runtime fix will be brought into 5.0-preview5!

// Cache to store the result of validating whether a key is exportable or not.
// This avoid requesting the key multiple times and avoids an issue when we try to access
// the key after it has been exported.
private Dictionary<string, bool> _areKeysExportable = new Dictionary<string, bool>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this need to be OrdinalIgnoreCase \ Ordinal?

rsaPrivateKey.CspKeyContainerInfo.Exportable) ||
(c.GetRSAPrivateKey() is RSACng cngPrivateKey &&
cngPrivateKey.Key.ExportPolicy == CngExportPolicies.AllowExport);
if (_areKeysExportable.TryGetValue(c.Thumbprint,out var result))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (_areKeysExportable.TryGetValue(c.Thumbprint,out var result))
if (_areKeysExportable.TryGetValue(c.Thumbprint, out var result))

@mkArtakMSFT mkArtakMSFT added the * NO MERGE * Do not merge this PR as long as this label is present. label May 12, 2020
@javiercn javiercn closed this May 20, 2020
@javiercn
javiercn deleted the javiercn/trust-export-candidate-workaround branch May 20, 2020 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI * NO MERGE * Do not merge this PR as long as this label is present.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Https] Issue when getting private key after being exported

5 participants