Skip to content

Commit cc2f09e

Browse files
authored
CP-308539: Updated certificate validation to support .NET 8.0 in PowerShell. (#6642)
2 parents 1d83693 + ddaf4ce commit cc2f09e

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.github/workflows/generate-and-build-sdks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
strategy:
206206
fail-fast: false
207207
matrix:
208-
dotnet: ["6", "8"]
208+
dotnet: ["8"]
209209
needs: build-csharp-sdk
210210
runs-on: windows-2022
211211
permissions:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
- name: Retrieve PowerShell 7.x SDK distribution artifacts
8787
uses: actions/download-artifact@v4
8888
with:
89-
name: SDK_Binaries_XenServerPowerShell_NET6
89+
name: SDK_Binaries_XenServerPowerShell_NET8
9090
path: sdk_powershell_7x/
9191

9292
- name: Package C SDK artifacts for deployment

ocaml/sdk-gen/powershell/autogen/src/Connect-XenServer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
using System.IO;
3333
using System.Management.Automation;
3434
using System.Net;
35+
#if NET8_0_OR_GREATER
36+
using System.Net.Http;
37+
#endif
3538
using System.Net.Security;
3639
using System.Runtime.InteropServices;
3740
using System.Security;
@@ -159,7 +162,7 @@ protected override void ProcessRecord()
159162
}
160163

161164
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
162-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
165+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
163166

164167
if (Url == null || Url.Length == 0)
165168
{
@@ -209,7 +212,7 @@ protected override void ProcessRecord()
209212
throw;
210213
}
211214
}
212-
catch (WebException e)
215+
catch (Exception e)
213216
{
214217
var inner = e.InnerException?.InnerException ?? //.NET case
215218
e.InnerException; //.NET Framework case
@@ -271,8 +274,13 @@ private bool ValidateServerCertificate(object sender, X509Certificate certificat
271274
bool ignoreChanged = Force || NoWarnCertificates || (bool)GetVariableValue("NoWarnCertificates", false);
272275
bool ignoreNew = Force || NoWarnNewCertificates || (bool)GetVariableValue("NoWarnNewCertificates", false);
273276

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
276284
string fingerprint = CommonCmdletFunctions.FingerprintPrettyString(certificate.GetCertHashString());
277285

278286
bool trusted = VerifyInAllStores(new X509Certificate2(certificate));

ocaml/sdk-gen/powershell/autogen/src/XenServerPowerShell.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Version>0.0.0</Version>
4-
<TargetFrameworks>net8.0;net6.0;net45</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net45</TargetFrameworks>
55
<OutputType>Library</OutputType>
66
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
77
</PropertyGroup>
@@ -12,9 +12,6 @@
1212
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
1313
<PackageReference Include="System.Management.Automation" Version="7.4.1" />
1414
</ItemGroup>
15-
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
16-
<PackageReference Include="System.Management.Automation" Version="7.2.18" />
17-
</ItemGroup>
1815
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
1916
<PackageReference Include="Microsoft.PowerShell.5.ReferenceAssemblies" Version="1.1.0" />
2017
</ItemGroup>

0 commit comments

Comments
 (0)