Skip to content

Conversation

@mikeTWC1984
Copy link
Contributor

@mikeTWC1984 mikeTWC1984 commented Jan 21, 2020

PR Summary

This PR replaces cert provider (windows only) with X509Store class to resolve certificate by name/thumbprint on CmsUtils.

PR Work items:

  • ResolveFromSubjectName and ResolveFromThumbprint - remove cert: provider call and merge into single method ( both lookups can utilize X509Certificate2Collection.Find )
  • Remove GetCertEKU (that uses native calls). Use X509Certificate2 Extensions property instead in CertHasOId method.
  • LocalMachine/My store - Windows only
  • replace List<509Certificate2> with X509Certificate2Collection on related methods.
  • Update tests
  • test on Mac
  • add wildcard for subjectname lookup

PR Checklist

@ghost ghost assigned iSazonov Jan 21, 2020
@msftclas
Copy link

msftclas commented Jan 21, 2020

CLA assistant check
All CLA requirements met.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 22, 2020
@iSazonov iSazonov added this to the 7.1.0-preview.1 milestone Jan 22, 2020
@iSazonov
Copy link
Collaborator

iSazonov commented Jan 22, 2020

@mikeTWC1984 We should export the cmdlets on Unix-s:

Also please review tests https://github.com/PowerShell/PowerShell/tree/master/test/powershell/Modules/Microsoft.PowerShell.Security

GitHub
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
GitHub
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.

@iSazonov iSazonov changed the title updated CmsCommands to use Store vs cert provider WIP: Update CmsCommands to use Store vs cert provider Jan 23, 2020
@iSazonov
Copy link
Collaborator

I added WIP until the PR is ready to review.

@mikeTWC1984 mikeTWC1984 changed the title WIP: Update CmsCommands to use Store vs cert provider Update CmsCommands to use Store vs cert provider Jan 23, 2020
@mikeTWC1984 mikeTWC1984 changed the title Update CmsCommands to use Store vs cert provider WIP: Update CmsCommands to use Store vs cert provider Jan 23, 2020
@mikeTWC1984
Copy link
Contributor Author

OK. It's pretty much ready for review, but somehow Powershell-CI pester test is failing. I ran 3 tests today, all failed for linux, 2 for Mac and 1 for Windows. I also tried Start-PSPester locally for my branch and Powershell's master and got ~30 errors. A the moment it's not quite clear what's wrong. . Probably some temp issue, will keep experimenting. The build itself goes through, CMS commands seem to work, but I haven't done thorough testing yet.

@mikeTWC1984 mikeTWC1984 changed the title WIP: Update CmsCommands to use Store vs cert provider Update CmsCommands to use Store vs cert provider Jan 24, 2020
@iSazonov
Copy link
Collaborator

@mikeTWC1984 You should enable the cmdlets in DefaultCommands.Tests.ps1 too (See link above).

@xtqqczze
Copy link
Contributor

This PR does not appear to conflict with #11590

@mikeTWC1984 mikeTWC1984 changed the title WIP: Update CmsCommands to use Store vs cert provider Update CmsCommands to use Store vs cert provider Feb 4, 2020
@mikeTWC1984
Copy link
Contributor Author

OK, tests finally pass on Mac. Turns out certs got added to the store automatically during creation (X509Store.add actually doesn't work ) . I'll work on the Doc today or tomorrow.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Feb 4, 2020
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Feb 4, 2020
@mikeTWC1984
Copy link
Contributor Author

mikeTWC1984 commented Feb 4, 2020

Ok, applied all the latest changes. I was back and forth between using CertificateCollection.Find and foreach loop to match SubjectName, and I'm finally sticking with foreach, so it's the same approach as original version had. I realized find will always do "contains" match, but I guess mostly user would need exact match.

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

LGTM
We still need to do a security review, but the code changes look good.

Comment on lines 1273 to 1276
if (subjectNamePattern.IsMatch(cert.Subject))
{
certificatesToProcess.Add(cert);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@mikeTWC1984 If you ask about this IsMatch() it is ok to preserve the old behavior until we get a negative feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is OK. It's bit counterintuitive to use wildcard (and directory) when expecting single item, but helps when typing those names manually. After going back and forth with this, I realized omitting CN= prefix in subject name would be very useful, so I added one extra IsMatch for simple name too

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM with two minor comments.

@mikeTWC1984
Copy link
Contributor Author

@TravisEz13 I think this is ready for security review. I also filed Documentation issue.

@TravisEz13
Copy link
Member

@mikeTWC1984 Yes, I've already schedule the review. The reviews are Confidential and we have to decide how to communicate the results after the review.

@TravisEz13
Copy link
Member

@mikeTWC1984 Security review summary: we don't think the security footing of the cmdlet has changed.

@TravisEz13 TravisEz13 changed the title Update CmsCommands to use Store vs cert provider Update CmsCommands to use Store vs cert provider Feb 6, 2020
@TravisEz13 TravisEz13 merged commit 69bf704 into PowerShell:master Feb 6, 2020
@iSazonov
Copy link
Collaborator

iSazonov commented Feb 7, 2020

@mikeTWC1984 Thanks for your contribution!

@mikeTWC1984
Copy link
Contributor Author

Cool, thanks all. There are few enhancements we can add to those commands, I'll probably submit an issue or PR sometime soon. I guess it's also the time to update documentation, will work on that.

@iSazonov
Copy link
Collaborator

iSazonov commented Feb 7, 2020

@mikeTWC1984 Open new issue(s) if there is a field for discussion.

@ghost
Copy link

ghost commented Mar 26, 2020

🎉v7.1.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR Indicates that a PR is out for the issue label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log In-PR Indicates that a PR is out for the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants