In order to fix an issue with our website test PowerShell script, we added the following code prior to Invoke-WebRequest call (per this and this:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$login = Invoke-WebRequest "https://...."
And then to add valid TLS policies we recently added:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'
My question is simple. How does this code affect the Invoke-webrequest? As far as I can see, it is not linked to the call in direct way. There's nothing applied to a session variable (in an obvious way).
I saw one reference to a callback function, but I still don't see how CheckValidationResult
gets passed as a callback. And yet it works.