diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 67bfd6f41f..95b2af7c70 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -39,7 +39,7 @@ jobs: - name: Setup .NET 9.0.x uses: actions/setup-dotnet@v4.0.0 with: - dotnet-version: 9.0.100-preview.4.24267.66 + dotnet-version: 9.0.100-preview.7.24407.12 - name: Run the tests run: dotnet test Wilson.sln diff --git a/build/template-Build-run-tests-sign.yml b/build/template-Build-run-tests-sign.yml index 039ec07aea..ad92d2abf9 100644 --- a/build/template-Build-run-tests-sign.yml +++ b/build/template-Build-run-tests-sign.yml @@ -28,7 +28,7 @@ steps: - task: UseDotNet@2 displayName: 'Use .Net Core SDK 9.x' inputs: - version: 9.0.100-preview.4.24267.66 + version: 9.0.100-preview.7.24407.12 includePreviewVersions: true condition: eq(variables['TargetNet9'], 'True') @@ -174,7 +174,7 @@ steps: - task: securedevelopmentteam.vss-secure-development-tools.build-task-uploadtotsa.TSAUpload@2 displayName: 'TSA upload to Codebase: WILSON Stamp: Azure' inputs: - GdnPublishTsaOnboard: false + GdnPublishTsaOnboard: false GdnPublishTsaConfigFile: '$(Build.SourcesDirectory)/build/tsaConfig.json' continueOnError: true condition: and(succeeded(), eq(variables['PipelineType'], 'legacy')) diff --git a/test/Microsoft.IdentityModel.TestUtils/X509Helper.cs b/test/Microsoft.IdentityModel.TestUtils/X509Helper.cs new file mode 100644 index 0000000000..457b324b1b --- /dev/null +++ b/test/Microsoft.IdentityModel.TestUtils/X509Helper.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Security.Cryptography.X509Certificates; + +namespace Microsoft.IdentityModel.TestUtils +{ + public static class X509Helper + { + public static X509Certificate2 ConvertToX509Certificate(string base64Data) + { + var base64Bytes = Convert.FromBase64String(base64Data); + +#if NET9_0_OR_GREATER + return X509CertificateLoader.LoadCertificate(base64Bytes); +#else + return new X509Certificate2(base64Bytes); +#endif + } + + public static X509Certificate2 ConvertToX509Certificate(string base64Data, SecureString securePassword, X509KeyStorageFlags flags = X509KeyStorageFlags.DefaultKeySet) + { + var password = ConvertFromSecureString(securePassword); + return ConvertToX509Certificate(base64Data, password, flags); + } + + public static X509Certificate2 ConvertToX509Certificate(string base64Data, string password, X509KeyStorageFlags flags = X509KeyStorageFlags.DefaultKeySet) + { + var base64Bytes = Convert.FromBase64String(base64Data); +#if NET9_0_OR_GREATER + return X509CertificateLoader.LoadPkcs12(base64Bytes, password, flags); +#else + return new X509Certificate2(base64Bytes, password); +#endif + } + + private static string ConvertFromSecureString(SecureString secureString) + { + IntPtr valuePtr = IntPtr.Zero; + try + { + valuePtr = Marshal.SecureStringToGlobalAllocUnicode(secureString); + return Marshal.PtrToStringUni(valuePtr); + } + finally + { + Marshal.ZeroFreeGlobalAllocUnicode(valuePtr); + } + } + } +}