ebekker / ACMESharp

An ACME client library and PowerShell client for the .NET platform (Let's Encrypt)
https://pkisharp.github.io/ACMESharp-docs/
1.21k stars 184 forks source link

Get-ACMEExtensionModule throws an error if one or both extension folders are empty or do not exist #290

Open exchange12rocks opened 7 years ago

exchange12rocks commented 7 years ago
PS C:\Windows\system32> Get-ACMEExtensionModule 
Get-ChildItem : Cannot find path 'C:\Users\kf\AppData\Local\ACMESharp\user-exts' because it does not exist.
At C:\Program Files\WindowsPowerShell\Modules\ACMESharp\ACMESharp-Extensions\ACMESharp-Extensions.psm1:153 char:19
+         $userExtLinks = Get-ChildItem $extPath
+                         ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\kf...Sharp\user-exts:String) [Get-ChildItem], ItemNotFound
   Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

This prevents the function from displaying enabled extensions in another folder.

EdgarTorresNYC commented 7 years ago

Hi, I'm having the same problem, and getting the exact same message as @exchange12rocks.

Funny thing is that it seems the function is looking in my user profile (C:\Users\ma...\AppData\Local\ACMESharp\user-exts), but the link was written to C:\ProgramData\ACMESharp\sys-exts\ACMESharp.Providers.IIS.extlnk. To boot, the link points to C:\Program Files\WindowsPowerShell\Modules\ACMESharp.Providers.IIS\0.9.0.321.

I see a comment about an update that corrects the issue, but I just installed the 0.9 module. Is it possible the update didn't make its way to the PSGet repo?

How can I get this working, before my cert expires in the next couple days? Any help will be appreciated.

ebekker commented 7 years ago

I just merged in the change from @exchange12rocks, once the CI builds and tests successfully, I'll promote it to the main release. If you need it sooner, you can get the pre-release as soon as the CI is done.

EdgarTorresNYC commented 7 years ago

Thanks, @ebekker! 👍 I got past the ItemNotFound exception, but now I'm getting the following error:

PS C:\Windows\system32> Initialize-ACMEVault
Initialize-ACMEVault : failed to resolve extension link
At line:1 char:1
+ Initialize-ACMEVault
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Initialize-ACMEVault], Exception
    + FullyQualifiedErrorId : System.Exception,ACMESharp.POSH.InitializeVault

I tried initializing the vault for both the :sys and :user profiles. I'm running the PS-ISE as Administrator. Any other thoughts? I'm happy to test the next pre-release build.

ebekker commented 7 years ago

@EdgarTorresNYC -- can you try the command again, and after you get the error, type this:

PS> $Error[0].Exception.GetBaseException().ToString()

And then paste the output here?

EdgarTorresNYC commented 7 years ago

Good stuff, @ebekker! 🥇

While copying the exception details you asked for, I got the idea to check the contents of the extension link file. It turns out the extension link was still pointing to version 0.9.0.321, so all I had to do was update both version and path to 0.9.0.322.

All's working, now. 👍 Here are the details that gave me the clue:

PS C:\Windows\system32> $Error[0].Exception.GetBaseException().tostring()
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\PROGRAM FILES\WINDOWSPOWERSHELL\MODULES\ACMESHARP
.PROVIDERS.IIS\0.9.0.321'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.Directory.GetFiles(String path, String searchPattern)
   at System.ComponentModel.Composition.Hosting.DirectoryCatalog.GetFiles()
   at System.ComponentModel.Composition.Hosting.DirectoryCatalog.Initialize(String path, String searchPattern)
   at ACMESharp.Ext.ExtCommon.InitExtConfig[TExtConfig]() in C:\projects\acmesharp\ACMESharp\ACMESharp\Ext\ExtCommon.cs:line 
113

PS C:\Windows\system32> Get-Content C:\ProgramData\ACMESharp\sys-exts\ACMESharp.Providers.IIS.extlnk
{
    "Version":  "0.9.0.321",
    "Path":  "C:\\Program Files\\WindowsPowerShell\\Modules\\ACMESharp.Providers.IIS\\0.9.0.321"
}
ebekker commented 7 years ago

Cool, this type of thing will hopefully be handled by improvements from #269.

dankennedy24 commented 6 years ago

I have the same issue as @EdgarTorresNYC 's last post, but I'm not sure how to "check the extension link file". Can you point me in the right direction?

Also, I'm trying to create a new IIS cert from Lets Encrypt and see references in step 2 to both 'Initialize-ACMESharp" as seen at https://pkisharp.github.io/ACMESharp-docs/User-Guide.html

and

'Initialize-ACMEVault' as seen at https://github.com/ebekker/ACMESharp/wiki/Quick-Start

Which one is correct?

dankennedy24 commented 6 years ago

Apparently I spoke to soon, I found the files and I see both referencing 0.9.0.321.

That appears to be correct based on below, but I absolutely see references to ver 326 and am guessing that's actually what's installed as this is a fresh install.

Name Scope Version


ACMESharp.Providers.IIS Global 0.9.0.321 ACMESharp.Providers.Windows Global 0.9.0.321

I ran the command from @ebekker 's last post and realized I needed to install the windows provider since that was the error being thrown. I'm past that, but now getting an error that the Vault root path contains existing data. Best way to get around that?

realsircodesalot commented 6 years ago

I just ran into the issue and I've been at it for a while now trying to figure it out. Thanks @ebekker for suggesting how to get the exception details! I got the same error as you @EdgarTorresNYC so I decided to try this and it seemed to work - I had previous versions installed, but I cleaned those up after having issues upgrade to 0.9.1.326:

PS> Disable-ACMEExtensionModule ACMESharp.Providers.IIS

Which asked me to confirm:


Confirm
Are you sure you want to perform this action?
Performing the operation "Remove File" on target "C:\ProgramData\ACMESharp\sys-exts\ACMESharp.Providers.IIS.extlnk".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

I entered Y, after it was completed, I ran: PS> Enable-ACMEExtensionModule ACMESharp.Providers.IIS

At this point I can call ACME powershell commandlets w/o it throwing an exception.

HTH