PKISharp / ACME-PS

PowerShell module supporting ACME v2 certificate management
MIT License
104 stars 31 forks source link

[BUG] Import-AccountKey : Object reference not set to an instance of an object #112

Closed raymix closed 3 years ago

raymix commented 3 years ago

Hi

Looks like I caught another one :)

I am trying to complete challenge and I get below error. For some reason Import-AccountKey method is not seeing path to Account.xml file

PS C:\> $GLOBAL:VerbosePreference = "Continue"
    New-ACMENonce -State $ACMEState
    Complete-ACMEChallenge -State $ACMEState -Challenge $challenge
    $GLOBAL:VerbosePreference = "SilentlyContinue"
VERBOSE: Sending HttpRequest (Head) to https://acme-staging-v02.api.letsencrypt.org/acme/new-nonce
VERBOSE: Importing object from CLIXML file C:\Users\redacted\Documents\ACME-PS\LetsEncrypt-Staging\AccountKey.xml
VERBOSE: Converted input object to type RSAKeyExport
Complete-ACMEChallenge : Cannot validate argument on parameter 'State'. Object reference not set to an instance of an object.
At line:3 char:35
+     Complete-ACMEChallenge -State $ACMEState -Challenge $challenge
+                                   ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Complete-ACMEChallenge], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Complete-ACMEChallenge

The weird thing is that, as you see above, the AccountKey.xml was loaded correctly, but if I run below 2 methods on loaded state, they throw me errors. However, if I run GetAccount() method, it detects the account correctly

PS C:\> $ACMEState = Get-ACMEState -Path $ACMEWorkingDir
PS C:\> New-ACMENonce -State $ACMEState
PS C:\> $ACMEState.AccountExists()
Import-AccountKey : Object reference not set to an instance of an object.
At C:\Users\redacted\Documents\WindowsPowerShell\Modules\ACME-PS\1.3.4\ACME-PS.psm1:1070 char:23
+             $result = Import-AccountKey -Path $fileName;
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Import-AccountKey], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Import-AccountKey

PS C:\> $ACMEState.AccountKeyExists()
Import-AccountKey : Object reference not set to an instance of an object.
At C:\Users\redacted\Documents\WindowsPowerShell\Modules\ACME-PS\1.3.4\ACME-PS.psm1:1070 char:23
+             $result = Import-AccountKey -Path $fileName;
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Import-AccountKey], NullReferenceException 
    + FullyQualifiedErrorId : System.NullReferenceException,Import-AccountKey

PS C:\> $ACMEState.DirectoryExists()
True    

PS C:\> $ACMEState.GetAccount()           
ResourceUrl  : https://acme-staging-v02.api.letsencrypt.org/acme/acct/18061058
KeyId        : https://acme-staging-v02.api.letsencrypt.org/acme/acct/18061058
Status       : valid
Id           :
Contact      : {mailto:redacted@redacted.com, mailto:redacted@redacted.com}
InitialIp    : redacted
CreatedAt    : 2021-02-12T18:14:35.844613584Z
OrderListUrl :

PS C:\>

What do you think?

raymix commented 3 years ago

Ok, I was able to get it working by deleting everything and creating new account. However, this time I kept the session alive after creating variable using New-ACMEState Looks like either Account.xml was corrupt or there's something wrong with Get-ACMEState cmdlet

I'll do more testing next week and let you know if I find anything else

raymix commented 3 years ago

Ok it looks like it might have been a corrupted Account.xml file after all I am not able to replicate issue again.

glatzert commented 3 years ago

Sorry, I had no time during the weekend, but as you could not reproduce it, it's probably some hick-up of the earlier error.