-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ServerCertificateValidationCallback has no effect on Invoke-WebRequest #1753
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
Comments
@snobu This is what I typically use for non-core versions of PowerShell as @markekraus mentioned. 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 Perhaps you could verify the above and submit a PR to correct the 5.1 documentation. |
This has been removed from the documentation in #1870 |
Sorry to add on to this. I cannot seem to get it to work in any way whatsoever. Here is my script and output. http returns the expected outcome, but https does not. $url = "https://10.1.135.20/getxml?location=/Status"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}
$webclient = [System.Net.HttpWebRequest]::CreateHttp($url)
$webclient.Credentials = Import-Clixml cred.xml
$response = $webclient.GetResponse()
$psversiontable
|
I can't repro on If that works maybe there's something more to it, maybe the TLS version should be higher and that's why it breaks, not because of the chain verify - see this section here for a workaround. |
Closing due to changes in #1870 |
As stated in Example 2 here,
has no effect on
Invoke-WebRequest
orInvoke-RestMethod
, establishing the TLS session will still fail if the remote presents a self-signed certificate.Looks like it only works when calling straight into the assembly:
The TLS handshake is successful now.
This is not kosher, definitely needs to be addressed.
The text was updated successfully, but these errors were encountered: