From 97df59f553b0cf9310162f8542038162f535c4bf Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 27 Jun 2016 11:41:07 -0700 Subject: [PATCH] Re-enable checking of assemblies with strong names This removes the `UsesCodeSignedAssemblies()` switch in `CorePsPlatform` and reverts the work-arounds skipping strong name checking. --- .../CoreCLR/CorePsPlatform.cs | 5 ----- .../engine/Utils.cs | 22 ++----------------- .../singleshell/config/MshSnapinInfo.cs | 22 ++----------------- test/csharp/test_CorePsPlatform.cs | 6 ----- test/csharp/test_MshSnapinInfo.cs | 2 +- 5 files changed, 5 insertions(+), 52 deletions(-) diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 1110b2623f..c9cd032176 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -208,11 +208,6 @@ namespace System.Management.Automation return IsWindows; } - internal static bool UsesCodeSignedAssemblies() - { - return !Platform.IsCore; - } - // This is mainly with respect to the auto-mounting of // disconnected network drives on Windows internal static bool HasDriveAutoMounting() diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 3662655137..8fb7d56631 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -1263,25 +1263,8 @@ namespace System.Management.Automation public static extern bool FindClose(IntPtr hFindFile); } - // Porting note: PublicKeyToken must be null if code signed - // assemblies aren't supported - private static string strongNamePublicKeyToken - { - get - { - if (Platform.UsesCodeSignedAssemblies()) - { - return "31bf3856ad364e35"; - } - else - { - return "null"; - } - } - } - internal static readonly string PowerShellAssemblyStrongNameFormat = - "{0}, Version=3.0.0.0, Culture=neutral, PublicKeyToken={1}"; + "{0}, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; internal static readonly HashSet PowerShellAssemblies = new HashSet(StringComparer.OrdinalIgnoreCase) @@ -1338,8 +1321,7 @@ namespace System.Management.Automation if ((fixedName != null) && PowerShellAssemblies.Contains(fixedName)) { - return string.Format(CultureInfo.InvariantCulture, PowerShellAssemblyStrongNameFormat, - fixedName, strongNamePublicKeyToken); + return string.Format(CultureInfo.InvariantCulture, PowerShellAssemblyStrongNameFormat, fixedName); } } diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs index 2baed477bf..33faeb13c1 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs @@ -1018,21 +1018,9 @@ namespace System.Management.Automation byte[] publicTokens = currentAssembly.GetName().GetPublicKeyToken(); if (publicTokens.Length == 0) { - if (Platform.UsesCodeSignedAssemblies()) - { - throw PSTraceSource.NewArgumentException("PublicKeyToken", MshSnapinInfo.PublicKeyTokenAccessFailed); - } - else - { - // Platform note: set this to null when code signed assemblies are - // unsupported (rather than blank) - publicKeyToken = "null"; - } - } - else - { - publicKeyToken = ConvertByteArrayToString(publicTokens); + throw PSTraceSource.NewArgumentException("PublicKeyToken", MshSnapinInfo.PublicKeyTokenAccessFailed); } + publicKeyToken = ConvertByteArrayToString(publicTokens); // save some cpu cycles by hardcoding the culture to neutral // assembly should never be targeted to a particular culture culture = "neutral"; @@ -1083,12 +1071,6 @@ namespace System.Management.Automation "Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml", "Registry.format.ps1xml"}); - // If code signing is not supported, the token must be set to "null" - if (!Platform.UsesCodeSignedAssemblies()) - { - publicKeyToken = "null"; - } - string strongName = string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}", CoreSnapin.AssemblyName, assemblyVersion, culture, publicKeyToken, architecture); diff --git a/test/csharp/test_CorePsPlatform.cs b/test/csharp/test_CorePsPlatform.cs index 2a3898e829..d0132b121d 100644 --- a/test/csharp/test_CorePsPlatform.cs +++ b/test/csharp/test_CorePsPlatform.cs @@ -27,12 +27,6 @@ namespace PSTests Assert.False(Platform.HasAmsi()); } - [Fact] - public static void TestUsesCodeSignedAssemblies() - { - Assert.False(Platform.UsesCodeSignedAssemblies()); - } - [Fact] public static void TestHasDriveAutoMounting() { diff --git a/test/csharp/test_MshSnapinInfo.cs b/test/csharp/test_MshSnapinInfo.cs index 8a14afb89b..ac755ec5af 100644 --- a/test/csharp/test_MshSnapinInfo.cs +++ b/test/csharp/test_MshSnapinInfo.cs @@ -22,7 +22,7 @@ namespace PSTests public void TestReadCoreEngineSnapIn() { PSSnapInInfo pSSnapInInfo = PSSnapInReader.ReadCoreEngineSnapIn(); - Assert.Contains("PublicKeyToken=null", pSSnapInInfo.AssemblyName); + Assert.Contains("PublicKeyToken=31bf3856ad364e35", pSSnapInInfo.AssemblyName); } } }