Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<StyleCopAnalyzersVersion>1.2.0-beta.304</StyleCopAnalyzersVersion>
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
<SystemCollectionsVersion>4.3.0</SystemCollectionsVersion>
<SystemCollectionsImmutableVersion>5.0.0</SystemCollectionsImmutableVersion>
<SystemComponentModelAnnotationsVersion>5.0.0</SystemComponentModelAnnotationsVersion>
<SystemDataSqlClientVersion>4.8.2</SystemDataSqlClientVersion>
<SystemDataDataSetExtensionsVersion>4.5.0</SystemDataDataSetExtensionsVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
<Configurations>Debug;Release;Checked</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Xml.ReaderWriter">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="System.Collections.Immutable">
<Version>1.3.1</Version>
<Version>$(SystemCollectionsImmutableVersion)</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.IO.MemoryMappedFiles">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="System.Reflection.Metadata">
<Version>$(SystemReflectionMetadataVersion)</Version>
</PackageReference>
Expand Down
25 changes: 13 additions & 12 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
Expand Down Expand Up @@ -696,13 +697,13 @@ private void RunSingleCompilation(Dictionary<string, string> inFilePaths, Instru

if (_commandLineOptions.CompositeKeyFile != null)
{
ImmutableArray<byte> compositeStrongNameKey = File.ReadAllBytes(_commandLineOptions.CompositeKeyFile).ToImmutableArray();
byte[] compositeStrongNameKey = File.ReadAllBytes(_commandLineOptions.CompositeKeyFile);
if (!IsValidPublicKey(compositeStrongNameKey))
{
throw new Exception(string.Format(SR.ErrorCompositeKeyFileNotPublicKey));
}

compositeImageSettings.PublicKey = compositeStrongNameKey;
compositeImageSettings.PublicKey = compositeStrongNameKey.ToImmutableArray();
}

//
Expand Down Expand Up @@ -954,7 +955,7 @@ public AlgorithmId(uint flags)
}
}

private static readonly ImmutableArray<byte> s_ecmaKey = ImmutableArray.Create(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0 });
private static ReadOnlySpan<byte> s_ecmaKey => new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0 };

private const int SnPublicKeyBlobSize = 13;

Expand All @@ -968,15 +969,21 @@ public AlgorithmId(uint flags)
// From StrongNameInternal.cpp
// Checks to see if a public key is a valid instance of a PublicKeyBlob as
// defined in StongName.h
internal static bool IsValidPublicKey(ImmutableArray<byte> blob)
internal static bool IsValidPublicKey(byte[] blob)
{
// The number of public key bytes must be at least large enough for the header and one byte of data.
if (blob.IsDefault || blob.Length < s_publicKeyHeaderSize + 1)
if (blob.Length < s_publicKeyHeaderSize + 1)
{
return false;
}

var blobReader = new BinaryReader(new MemoryStream(blob.ToArray()));
// Check for the ECMA key, which does not obey the invariants checked below.
if (blob.AsSpan().SequenceEqual(s_ecmaKey))
{
return true;
}

var blobReader = new BinaryReader(new MemoryStream(blob, writable: false));

// Signature algorithm ID
var sigAlgId = blobReader.ReadUInt32();
Expand All @@ -993,12 +1000,6 @@ internal static bool IsValidPublicKey(ImmutableArray<byte> blob)
return false;
}

// Check for the ECMA key, which does not obey the invariants checked below.
if (System.Linq.Enumerable.SequenceEqual(blob, s_ecmaKey))
{
return true;
}

// The public key must be in the wincrypto PUBLICKEYBLOB format
if (publicKey != PublicKeyBlobId)
{
Expand Down