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
Binary file not shown.
35 changes: 35 additions & 0 deletions src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,41 @@ public void EmptyPKT()
});
}

[Fact]
public void CrossGenNative()
{
// List of files to be considered for signing
var itemsToSign = new[]
{
GetResourcePath("CoreLibCrossARM.dll")
};

// Default signing information
var strongNameSignInfo = new Dictionary<string, SignInfo>()
{
{ "581d91ccdfc4ea9c", new SignInfo("ArcadeCertTest", "ArcadeStrongTest") }
};

// Overriding information
var fileSignInfo = new Dictionary<ExplicitCertificateKey, string>()
{
{ new ExplicitCertificateKey("EmptyPKT.dll"), "3PartySHA2" }
};

ValidateFileSignInfos(itemsToSign, strongNameSignInfo, fileSignInfo, s_fileExtensionSignInfo, new[]
{
"File 'CoreLibCrossARM.dll' Certificate='Microsoft400'",
});

ValidateGeneratedProject(itemsToSign, strongNameSignInfo, fileSignInfo, s_fileExtensionSignInfo, new[]
{
$@"<FilesToSign Include=""{Path.Combine(_tmpDir, "CoreLibCrossARM.dll")}"">
<Authenticode>Microsoft400</Authenticode>
</FilesToSign>",
});
}


[Fact]
public void DefaultCertificateForAssemblyWithoutStrongName()
{
Expand Down
7 changes: 3 additions & 4 deletions src/Microsoft.DotNet.SignTool/src/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,20 +361,19 @@ private static bool IsThirdPartyCertificate(string name)

private static void GetPEInfo(string fullPath, out bool isManaged, out string publicKeyToken, out string targetFramework, out string copyright)
{
AssemblyName assemblyName = ContentUtil.GetAssemblyName(fullPath);
isManaged = ContentUtil.IsManaged(fullPath);

if (assemblyName == null)
if (!isManaged)
{
isManaged = false;
publicKeyToken = string.Empty;
targetFramework = string.Empty;
copyright = string.Empty;
return;
}

AssemblyName assemblyName = AssemblyName.GetAssemblyName(fullPath);
var pktBytes = assemblyName.GetPublicKeyToken();

isManaged = true;
publicKeyToken = (pktBytes == null || pktBytes.Length == 0) ? string.Empty : string.Join("", pktBytes.Select(b => b.ToString("x2")));
GetTargetFrameworkAndCopyright(fullPath, out targetFramework, out copyright);
}
Expand Down
13 changes: 6 additions & 7 deletions src/Microsoft.DotNet.SignTool/src/ContentUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ public static bool IsPublicSigned(PEReader peReader)
return (header.Flags & CorFlags.StrongNameSigned) == CorFlags.StrongNameSigned;
}

public static AssemblyName GetAssemblyName(string fullFilePath)
public static bool IsManaged(string filePath)
{
try
using (var stream = new FileStream(filePath, FileMode.Open))
using (var peReader = new PEReader(stream))
{
return AssemblyName.GetAssemblyName(fullFilePath);
}
catch
{
return null;
var corEntry = peReader.PEHeaders.PEHeader.CorHeaderTableDirectory;

return corEntry.RelativeVirtualAddress == 0x2008 && corEntry.Size == 0x48;
Comment thread
JohnTortugo marked this conversation as resolved.
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.DotNet.SignTool/src/FileSignInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal static bool IsZipContainer(string path)

internal bool IsPEFile() => IsPEFile(FileName);

internal bool IsManaged() => ContentUtil.GetAssemblyName(FullPath) != null;
internal bool IsManaged() => ContentUtil.IsManaged(FullPath);

internal bool IsVsix() => IsVsix(FileName);

Expand Down