mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Re-enable checking of assemblies with strong names
This removes the `UsesCodeSignedAssemblies()` switch in `CorePsPlatform` and reverts the work-arounds skipping strong name checking.
This commit is contained in:
1 parent
ee96212fb6
commit
97df59f553
5 files changed
+5
-52
No files matched your search
@@ -208,11 +208,6 @@ namespace System.Management.Automation
|
|||||||
return IsWindows;
|
return IsWindows;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool UsesCodeSignedAssemblies()
|
|
||||||
{
|
|
||||||
return !Platform.IsCore;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is mainly with respect to the auto-mounting of
|
// This is mainly with respect to the auto-mounting of
|
||||||
// disconnected network drives on Windows
|
// disconnected network drives on Windows
|
||||||
internal static bool HasDriveAutoMounting()
|
internal static bool HasDriveAutoMounting()
|
||||||
|
|||||||
@@ -1263,25 +1263,8 @@ namespace System.Management.Automation
|
|||||||
public static extern bool FindClose(IntPtr hFindFile);
|
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 =
|
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<string> PowerShellAssemblies =
|
internal static readonly HashSet<string> PowerShellAssemblies =
|
||||||
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||||
@@ -1338,8 +1321,7 @@ namespace System.Management.Automation
|
|||||||
|
|
||||||
if ((fixedName != null) && PowerShellAssemblies.Contains(fixedName))
|
if ((fixedName != null) && PowerShellAssemblies.Contains(fixedName))
|
||||||
{
|
{
|
||||||
return string.Format(CultureInfo.InvariantCulture, PowerShellAssemblyStrongNameFormat,
|
return string.Format(CultureInfo.InvariantCulture, PowerShellAssemblyStrongNameFormat, fixedName);
|
||||||
fixedName, strongNamePublicKeyToken);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1018,21 +1018,9 @@ namespace System.Management.Automation
|
|||||||
byte[] publicTokens = currentAssembly.GetName().GetPublicKeyToken();
|
byte[] publicTokens = currentAssembly.GetName().GetPublicKeyToken();
|
||||||
if (publicTokens.Length == 0)
|
if (publicTokens.Length == 0)
|
||||||
{
|
{
|
||||||
if (Platform.UsesCodeSignedAssemblies())
|
throw PSTraceSource.NewArgumentException("PublicKeyToken", MshSnapinInfo.PublicKeyTokenAccessFailed);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
publicKeyToken = ConvertByteArrayToString(publicTokens);
|
||||||
// save some cpu cycles by hardcoding the culture to neutral
|
// save some cpu cycles by hardcoding the culture to neutral
|
||||||
// assembly should never be targeted to a particular culture
|
// assembly should never be targeted to a particular culture
|
||||||
culture = "neutral";
|
culture = "neutral";
|
||||||
@@ -1083,12 +1071,6 @@ namespace System.Management.Automation
|
|||||||
"Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml",
|
"Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml",
|
||||||
"Registry.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}",
|
string strongName = string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}",
|
||||||
CoreSnapin.AssemblyName, assemblyVersion, culture, publicKeyToken, architecture);
|
CoreSnapin.AssemblyName, assemblyVersion, culture, publicKeyToken, architecture);
|
||||||
|
|
||||||
|
|||||||
@@ -27,12 +27,6 @@ namespace PSTests
|
|||||||
Assert.False(Platform.HasAmsi());
|
Assert.False(Platform.HasAmsi());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public static void TestUsesCodeSignedAssemblies()
|
|
||||||
{
|
|
||||||
Assert.False(Platform.UsesCodeSignedAssemblies());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void TestHasDriveAutoMounting()
|
public static void TestHasDriveAutoMounting()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace PSTests
|
|||||||
public void TestReadCoreEngineSnapIn()
|
public void TestReadCoreEngineSnapIn()
|
||||||
{
|
{
|
||||||
PSSnapInInfo pSSnapInInfo = PSSnapInReader.ReadCoreEngineSnapIn();
|
PSSnapInInfo pSSnapInInfo = PSSnapInReader.ReadCoreEngineSnapIn();
|
||||||
Assert.Contains("PublicKeyToken=null", pSSnapInInfo.AssemblyName);
|
Assert.Contains("PublicKeyToken=31bf3856ad364e35", pSSnapInInfo.AssemblyName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user