Skip to content

CmsCommands - simple fix for linux #11630

@mikeTWC1984

Description

@mikeTWC1984

At the moment CmsCommands (Encrypting/Decrypting text with X509 cert) are only available on Windows. Those commands can be implemented with standard .net libraries, the only reason it's not working on Linux systems is that Util function that resolves certificate from string is using Cert: provider (which only implemented for Windows). Replacing cert: with X509Store class will make it work on linix systems.

here is the Util:

There are few lines referring to Cert:, for example

           string certificatePath = sessionState.Path.Combine("Microsoft.PowerShell.Security\\Certificate::CurrentUser\\My", _identifier);
                if (sessionState.InvokeProvider.Item.Exists(certificatePath))
                {
                    foreach (PSObject certificateObject in sessionState.InvokeProvider.Item.Get(certificatePath))
                    {
                        certificates.Add(certificateObject);
                    }
                }

Issue can be fixed by replacing it with something like that:

X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
 certificatesToProcess = store.Certificates.Find(X509FindType.FindBySubjectName,_identifier,false);

This only affect ResolveFromSubjectName and ResolveFromThumbprint methods, so change is relatively small. I played with it on Ubuntu and didn't noticed any extra problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions