Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revoke-Certificate - Throwing exception Cannot find an appropriate constructor #210

Open
PsCustomObject opened this issue Mar 11, 2024 · 5 comments
Labels
Investigate The item’s status is investigated (issue or not)

Comments

@PsCustomObject
Copy link

PsCustomObject commented Mar 11, 2024

Hello,

I've tried to find something but could not find anything close to what I'm experiencing when trying to use the Revoke-Certificate cmdlet the following exception is being thrown:

New-Object : A constructor was not found. Cannot find an appropriate constructor for type 
SysadminsLV.PKI.Utils.ServiceOperationResult.
At C:\Program Files\WindowsPowerShell\Modules\PSPKI\4.2.0\Server\Revoke-Certificate.ps1:52 char:13
+             New-Object SysadminsLV.PKI.Utils.ServiceOperationResult $ ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand

As it is stated in the exception message module version in use is 4.2.0, I did not have the time to properly debug the whole thing but exception is being thrown at line 49 of the Revoke-Certificate function where code reads:

            $CertAdmin.RevokeCertificate($Request.ConfigString,$Request.SerialNumber,$Reasons[$Reason],$RevocationDate.ToUniversalTime())
            New-Object SysadminsLV.PKI.Utils.ServiceOperationResult 0,
                "Successfully revoked certificate with ID=$($Request.RequestID) and reason: '$Reason'"
        } catch {
            New-Object SysadminsLV.PKI.Utils.ServiceOperationResult $($_.Exception.InnerException.InnerException.HResult)
        }

I will try to find some time to further troubleshoot this but if someone experienced this issue or has any pointer I would really appreciate it.

@PsCustomObject
Copy link
Author

Adding to my own report I've tried running the same script using module version 3.7.2 and it woks as intended.

I have an interim fix and that is perfect but still I would like to troubleshoot this in 4.2.0 at least to isolate what is causing it.

@hmiller10
Copy link

@PsCustomObject
Copy link
Author

Thanks but the logic to revoke cert is already in place it is just the cmdlet throwing the exception I've reported, I've now been able to fix the issue so I?m kind of set but still would like to go to the bottom of this to understamd

@Crypt32 Crypt32 added the bug Bug. An issue exist in our code. label Mar 13, 2024
@Crypt32 Crypt32 added Investigate The item’s status is investigated (issue or not) and removed bug Bug. An issue exist in our code. labels May 13, 2024
@Crypt32
Copy link
Collaborator

Crypt32 commented May 13, 2024

I've tried to repro the issue by attempting to generate both, successful and unsuccessful responses and it works fine for me in 4.2.0:

PS C:\> $req = connect-ca | get-issuedrequest -RequestID 1006744
PS C:\> $req | Revoke-Certificate

HResult      StatusMessage
-------      -------------
-2147023174  The RPC server is unavailable.


PS C:\> $req | Revoke-Certificate

HResult      StatusMessage
-------      -------------
0            Successfully revoked certificate with ID=1006744 and reason: 'Unspecified'


PS C:\>

@chrizzlibaer
Copy link

I faced the same issue and found that when I ran the script on the certification authority without adminrights it will show this error.
When running the script with adminrights, everything runs fine.

That totally makes sense, the resulting error is just quite confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate The item’s status is investigated (issue or not)
Projects
None yet
Development

No branches or pull requests

4 participants