forked from dotnet/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip already signed packages (dotnet#1142)
- Loading branch information
1 parent
e49c019
commit 20bd340
Showing
5 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Collections.Concurrent; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Threading.Tasks; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace RepoTasks | ||
{ | ||
/// <summary> | ||
/// Determine which files are already signed. | ||
/// </summary> | ||
public class FilterSignedPackagesFiles : Microsoft.Build.Utilities.Task | ||
{ | ||
/// <summary> | ||
/// The files to be hashed. | ||
/// </summary> | ||
[Required] | ||
public ITaskItem[] Files { get; set; } | ||
|
||
/// <summary> | ||
/// The files which are signed. | ||
/// </summary> | ||
[Output] | ||
public ITaskItem[] Signed { get; set; } | ||
|
||
/// <summary> | ||
/// The files which are not | ||
/// </summary> | ||
[Output] | ||
public ITaskItem[] Unsigned { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
var signed = new ConcurrentBag<ITaskItem>(); | ||
var unsigned = new ConcurrentBag<ITaskItem>(); | ||
Parallel.ForEach(Files, file => | ||
{ | ||
if (IsPackageSigned(file.ItemSpec)) | ||
{ | ||
signed.Add(file); | ||
} | ||
else | ||
{ | ||
Log.LogMessage(MessageImportance.High, "Package {0} is not signed.", Path.GetFileName(file.ItemSpec)); | ||
unsigned.Add(file); | ||
} | ||
}); | ||
|
||
Signed = signed.ToArray(); | ||
Unsigned = unsigned.ToArray(); | ||
Log.LogMessage(MessageImportance.High, "Found {0} signed and {1} unsigned files", Signed.Length, Unsigned.Length); | ||
Debug.Assert(Signed.Length + Unsigned.Length == Files.Length, "Make sure all files are accounted for"); | ||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
private bool IsPackageSigned(string filePath) | ||
{ | ||
using (var file = File.OpenRead(filePath)) | ||
using (var zip = new ZipArchive(file, ZipArchiveMode.Read)) | ||
{ | ||
switch (Path.GetExtension(filePath).ToLowerInvariant()) | ||
{ | ||
case ".nupkg": | ||
return zip.GetEntry(".signature.p7s") != null; | ||
case ".vsix": | ||
return zip.GetEntry("package/services/digital-signature/_rels/origin.psdor.rels") != null; | ||
case ".jar": | ||
return zip.GetEntry("META-INF/MSFTSIG.RSA") != null; | ||
default: | ||
Log.LogError("Unrecognized package type: {0}", filePath); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RepoTasks", "RepoTasks.csproj", "{78054E53-3D57-4401-AFAA-B31F50E64CEC}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Debug|x64.Build.0 = Debug|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Debug|x86.Build.0 = Debug|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Release|x64.ActiveCfg = Release|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Release|x64.Build.0 = Release|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Release|x86.ActiveCfg = Release|Any CPU | ||
{78054E53-3D57-4401-AFAA-B31F50E64CEC}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |