|
32 | 32 | using System.IO;
|
33 | 33 | using System.Management.Automation;
|
34 | 34 | using System.Net;
|
| 35 | +#if NET8_0_OR_GREATER |
| 36 | +using System.Net.Http; |
| 37 | +#endif |
35 | 38 | using System.Net.Security;
|
36 | 39 | using System.Runtime.InteropServices;
|
37 | 40 | using System.Security;
|
@@ -159,7 +162,7 @@ protected override void ProcessRecord()
|
159 | 162 | }
|
160 | 163 |
|
161 | 164 | ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
|
162 |
| - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; |
| 165 | + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; |
163 | 166 |
|
164 | 167 | if (Url == null || Url.Length == 0)
|
165 | 168 | {
|
@@ -209,7 +212,7 @@ protected override void ProcessRecord()
|
209 | 212 | throw;
|
210 | 213 | }
|
211 | 214 | }
|
212 |
| - catch (WebException e) |
| 215 | + catch (Exception e) |
213 | 216 | {
|
214 | 217 | var inner = e.InnerException?.InnerException ?? //.NET case
|
215 | 218 | e.InnerException; //.NET Framework case
|
@@ -271,8 +274,13 @@ private bool ValidateServerCertificate(object sender, X509Certificate certificat
|
271 | 274 | bool ignoreChanged = Force || NoWarnCertificates || (bool)GetVariableValue("NoWarnCertificates", false);
|
272 | 275 | bool ignoreNew = Force || NoWarnNewCertificates || (bool)GetVariableValue("NoWarnNewCertificates", false);
|
273 | 276 |
|
274 |
| - HttpWebRequest webreq = (HttpWebRequest)sender; |
275 |
| - string hostname = webreq.Address.Host; |
| 277 | +#if NET8_0_OR_GREATER |
| 278 | + var requestMessage = sender as HttpRequestMessage; |
| 279 | + string hostname = requestMessage?.RequestUri?.Host ?? string.Empty; |
| 280 | +#else |
| 281 | + var webreq = sender as HttpWebRequest; |
| 282 | + string hostname = webreq?.Address?.Host ?? string.Empty; |
| 283 | +#endif |
276 | 284 | string fingerprint = CommonCmdletFunctions.FingerprintPrettyString(certificate.GetCertHashString());
|
277 | 285 |
|
278 | 286 | bool trusted = VerifyInAllStores(new X509Certificate2(certificate));
|
|
0 commit comments