PKISolutions / PSPKI

PowerShell PKI Module
Microsoft Public License
389 stars 59 forks source link

New-Object PKI.OCSP.OCSPRequest not supported in recent versions #211

Closed hkelley closed 6 months ago

hkelley commented 6 months ago

As recently as v3.7.2, the cmdlets exposed this namespace:

New-Object PKI.OCSP.OCSPRequest

This let us do things like the following. Is there a 4.x equivalent?

# Load the test cert from a file
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $testCerFile

# Build a request object from the revoked cert
$Request = New-Object PKI.OCSP.OCSPRequest $cert

# The the cert didn't specify a URL as an attribute then explicitly set one
if($Request.URL -eq $null) {
    $Request.URL = "http://{0}/{1}/" -f $hostname,$ocspDir
}

Write-Warning ("Checking CRL for cert {0} [{1}] against OCSP at {2}<br/>" -f $cert.Subject,$cert.Thumbprint,$Request.URL)

try {
    Invoke-RestMethod $Request.URL -ErrorAction Ignore
} catch [System.Net.WebException] {

    if( [int]$_.Exception.Response.StatusCode -eq 500)  {
        Write-Warning ("{0} responds to HTTP<br/>" -f $Request.URL)
    } else {
        throw $_
    }
}

$result = $Request.SendRequest()

$certStatus = $result.Responses[0].CertStatus
Crypt32 commented 6 months ago

PKI.OCSP.OCSPRequest is replaced with SysadminsLV.PKI.OcspClient.OCSPRequest. Semantic is unchanged. It was part of PSPKI 4.0.0 underlying library overhaul: https://www.pkisolutions.com/tools/pspki/release-notes-for-pspki-v400/

hkelley commented 6 months ago

Sorry I missed that in the release notes. This works:

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $testCerFile

$request = New-Object SysadminsLV.PKI.OcspClient.OCSPRequest $cert

$result = $request.SendRequest()

$certStatus = $result.Responses[0].CertStatus