Skip to content

Commit 25ac07f

Browse files
authored
Allow files to ignore StrongName result (#15682)
1 parent 92341e4 commit 25ac07f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/SignCheck/Microsoft.SignCheck/Verification/Exclusions.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public bool Contains(Exclusion exclusion)
6969
return _exclusions.Contains(exclusion);
7070
}
7171

72-
public bool IsExcluded(string path, string parent, string virtualPath, string containerPath, IEnumerable<Exclusion> exclusions)
72+
private bool IsExcluded(string path, string parent, string virtualPath, string containerPath, IEnumerable<Exclusion> exclusions)
7373
{
7474
foreach (Exclusion e in exclusions)
7575
{
@@ -113,7 +113,8 @@ public bool IsExcluded(string path, string parent, string virtualPath, string co
113113
/// <returns></returns>
114114
public bool IsExcluded(string path, string parent, string virtualPath, string containerPath)
115115
{
116-
return IsExcluded(path, parent, virtualPath, containerPath, _exclusions);
116+
IEnumerable<Exclusion> exclusions = _exclusions.Where(e => !e.Comment.Contains("IGNORE-STRONG-NAME"));
117+
return IsExcluded(path, parent, virtualPath, containerPath, exclusions);
117118
}
118119

119120
/// <summary>
@@ -129,6 +130,14 @@ public bool IsDoNotSign(string path, string parent, string virtualPath, string c
129130
return (doNotSignExclusions.Count() > 0) && (IsExcluded(path, parent, virtualPath, containerPath, doNotSignExclusions));
130131
}
131132

133+
public bool IsIgnoreStrongName(string path, string parent, string virtualPath, string containerPath)
134+
{
135+
// Get all the exclusions with NO-STRONG-NAME markers and check only against those
136+
IEnumerable<Exclusion> noStrongNameExclusions = _exclusions.Where(e => e.Comment.Contains("IGNORE-STRONG-NAME"));
137+
138+
return (noStrongNameExclusions.Count() > 0) && (IsExcluded(path, parent, virtualPath, containerPath, noStrongNameExclusions));
139+
}
140+
132141
/// <summary>
133142
/// Returns true if any <see cref="Exclusion.FilePatterns"/> matches the value of <paramref name="path"/>.
134143
/// </summary>

src/SignCheck/Microsoft.SignCheck/Verification/PortableExecutableVerifier.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
5+
using System.IO;
46
using Microsoft.SignCheck.Interop.PortableExecutable;
57
using Microsoft.SignCheck.Logging;
68
using Microsoft.DotNet.StrongName;
@@ -40,9 +42,15 @@ public override SignatureVerificationResult VerifySignature(string path, string
4042
if (VerifyStrongNameSignature)
4143
{
4244
VerifyStrongName(svr);
45+
46+
svr.IsIgnoreStrongName = Exclusions.IsIgnoreStrongName(Path.GetFileName(svr.VirtualPath), parent, svr.VirtualPath, null);
47+
if (svr.IsIgnoreStrongName)
48+
{
49+
svr.AddDetail(DetailKeys.StrongName, $"Ignoring strong-name result because file is IGNORE-STRONG-NAME.");
50+
}
4351
}
4452

45-
svr.IsSigned = svr.IsAuthentiCodeSigned & ((svr.IsStrongNameSigned) || (!VerifyStrongNameSignature) || svr.IsNativeImage);
53+
svr.IsSigned = svr.IsAuthentiCodeSigned & (svr.IsStrongNameSigned || !VerifyStrongNameSignature || svr.IsNativeImage || svr.IsIgnoreStrongName);
4654
svr.AddDetail(DetailKeys.File, SignCheckResources.DetailSigned, svr.IsSigned);
4755

4856
return svr;

src/SignCheck/Microsoft.SignCheck/Verification/SignatureVerificationResult.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ public bool IsDoNotSign
7979
set;
8080
}
8181

82+
/// <summary>
83+
/// True if this file was marked as IGNORE-STRONG-NAME. This result can be used with IsStrongNameSigned
84+
/// </summary>
85+
public bool IsIgnoreStrongName
86+
{
87+
get;
88+
set;
89+
}
90+
8291
/// <summary>
8392
/// True if the file was excluded from verification, false otherwise.
8493
/// </summary>

0 commit comments

Comments
 (0)