Skip to content

Commit fbc0780

Browse files
authored
Run SignCheck on .NET Core (#15470)
1 parent ccd609b commit fbc0780

27 files changed

+869
-581
lines changed

Arcade.sln

+39-25
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.SwaggerGen
3535
EndProject
3636
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.GenAPI", "src\Microsoft.DotNet.GenAPI\Microsoft.DotNet.GenAPI.csproj", "{9427265E-C224-4B40-8157-F05529D084D3}"
3737
EndProject
38-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SignCheck", "SignCheck", "{A704E5B2-86A4-4D4F-902D-C10EA18C12DF}"
3938
EndProject
40-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.SignCheck", "src\SignCheck\SignCheck\Microsoft.DotNet.SignCheck.csproj", "{AF298985-511F-476A-8F62-79908BE8DF01}"
39+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.SignCheckLibrary", "src\SignCheck\Microsoft.SignCheck\Microsoft.DotNet.SignCheckLibrary.csproj", "{2A62655C-1AE0-480E-9F1A-E21F21C1D095}"
4140
EndProject
42-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.SignCheckLibrary", "src\SignCheck\Microsoft.SignCheck\Microsoft.DotNet.SignCheckLibrary.csproj", "{39B69A56-43E9-480D-9A60-8E0917795FE8}"
41+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.SignCheck", "src\SignCheck\SignCheck\Microsoft.DotNet.SignCheck.csproj", "{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}"
4342
EndProject
43+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.SignCheckTask", "src\SignCheck\SignCheckTask\Microsoft.DotNet.SignCheckTask.csproj", "{F6F5E649-F477-44ED-BAB2-11D4F0E87402}"
4444
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinShimmer", "src\WinShimmer\WinShimmer.csproj", "{39C3FC42-21E8-40BF-AE3F-CB9C4CC226D7}"
4545
EndProject
4646
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Build.Tasks.Packaging", "src\Microsoft.DotNet.Build.Tasks.Packaging\src\Microsoft.DotNet.Build.Tasks.Packaging.csproj", "{EFC8C541-1DC4-40DA-B6E5-FBF44F6DD8BC}"
@@ -327,26 +327,6 @@ Global
327327
{9427265E-C224-4B40-8157-F05529D084D3}.Release|x64.Build.0 = Release|Any CPU
328328
{9427265E-C224-4B40-8157-F05529D084D3}.Release|x86.ActiveCfg = Release|Any CPU
329329
{9427265E-C224-4B40-8157-F05529D084D3}.Release|x86.Build.0 = Release|Any CPU
330-
{AF298985-511F-476A-8F62-79908BE8DF01}.Debug|Any CPU.ActiveCfg = Debug|x86
331-
{AF298985-511F-476A-8F62-79908BE8DF01}.Debug|Any CPU.Build.0 = Debug|x86
332-
{AF298985-511F-476A-8F62-79908BE8DF01}.Debug|x64.ActiveCfg = Debug|x86
333-
{AF298985-511F-476A-8F62-79908BE8DF01}.Debug|x86.ActiveCfg = Debug|x86
334-
{AF298985-511F-476A-8F62-79908BE8DF01}.Debug|x86.Build.0 = Debug|x86
335-
{AF298985-511F-476A-8F62-79908BE8DF01}.Release|Any CPU.ActiveCfg = Release|x86
336-
{AF298985-511F-476A-8F62-79908BE8DF01}.Release|Any CPU.Build.0 = Release|x86
337-
{AF298985-511F-476A-8F62-79908BE8DF01}.Release|x64.ActiveCfg = Release|x86
338-
{AF298985-511F-476A-8F62-79908BE8DF01}.Release|x86.ActiveCfg = Release|x86
339-
{AF298985-511F-476A-8F62-79908BE8DF01}.Release|x86.Build.0 = Release|x86
340-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Debug|Any CPU.ActiveCfg = Debug|x86
341-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Debug|Any CPU.Build.0 = Debug|x86
342-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Debug|x64.ActiveCfg = Debug|x86
343-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Debug|x86.ActiveCfg = Debug|x86
344-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Debug|x86.Build.0 = Debug|x86
345-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Release|Any CPU.ActiveCfg = Release|x86
346-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Release|Any CPU.Build.0 = Release|x86
347-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Release|x64.ActiveCfg = Release|x86
348-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Release|x86.ActiveCfg = Release|x86
349-
{39B69A56-43E9-480D-9A60-8E0917795FE8}.Release|x86.Build.0 = Release|x86
350330
{39C3FC42-21E8-40BF-AE3F-CB9C4CC226D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
351331
{39C3FC42-21E8-40BF-AE3F-CB9C4CC226D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
352332
{39C3FC42-21E8-40BF-AE3F-CB9C4CC226D7}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -971,6 +951,42 @@ Global
971951
{1F5118A8-A5C5-4D18-AF34-FFB60FECCD45}.Release|x64.Build.0 = Release|Any CPU
972952
{1F5118A8-A5C5-4D18-AF34-FFB60FECCD45}.Release|x86.ActiveCfg = Release|Any CPU
973953
{1F5118A8-A5C5-4D18-AF34-FFB60FECCD45}.Release|x86.Build.0 = Release|Any CPU
954+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
955+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Debug|Any CPU.Build.0 = Debug|Any CPU
956+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Debug|x64.ActiveCfg = Debug|Any CPU
957+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Debug|x64.Build.0 = Debug|Any CPU
958+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Debug|x86.ActiveCfg = Debug|Any CPU
959+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Debug|x86.Build.0 = Debug|Any CPU
960+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Release|Any CPU.ActiveCfg = Release|Any CPU
961+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Release|Any CPU.Build.0 = Release|Any CPU
962+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Release|x64.ActiveCfg = Release|Any CPU
963+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Release|x64.Build.0 = Release|Any CPU
964+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Release|x86.ActiveCfg = Release|Any CPU
965+
{2A62655C-1AE0-480E-9F1A-E21F21C1D095}.Release|x86.Build.0 = Release|Any CPU
966+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
967+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
968+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Debug|x64.ActiveCfg = Debug|Any CPU
969+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Debug|x64.Build.0 = Debug|Any CPU
970+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Debug|x86.ActiveCfg = Debug|Any CPU
971+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Debug|x86.Build.0 = Debug|Any CPU
972+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
973+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Release|Any CPU.Build.0 = Release|Any CPU
974+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Release|x64.ActiveCfg = Release|Any CPU
975+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Release|x64.Build.0 = Release|Any CPU
976+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Release|x86.ActiveCfg = Release|Any CPU
977+
{40CB2592-3B06-4D0D-9878-7DFD5C4B3E9E}.Release|x86.Build.0 = Release|Any CPU
978+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
979+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Debug|Any CPU.Build.0 = Debug|Any CPU
980+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Debug|x64.ActiveCfg = Debug|Any CPU
981+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Debug|x64.Build.0 = Debug|Any CPU
982+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Debug|x86.ActiveCfg = Debug|Any CPU
983+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Debug|x86.Build.0 = Debug|Any CPU
984+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Release|Any CPU.ActiveCfg = Release|Any CPU
985+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Release|Any CPU.Build.0 = Release|Any CPU
986+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Release|x64.ActiveCfg = Release|Any CPU
987+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Release|x64.Build.0 = Release|Any CPU
988+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Release|x86.ActiveCfg = Release|Any CPU
989+
{F6F5E649-F477-44ED-BAB2-11D4F0E87402}.Release|x86.Build.0 = Release|Any CPU
974990
EndGlobalSection
975991
GlobalSection(SolutionProperties) = preSolution
976992
HideSolutionNode = FALSE
@@ -982,8 +998,6 @@ Global
982998
{FF9DA4D9-3A84-441B-8AAE-B73B6D1EE8B3} = {BB99CE55-AD68-484A-9474-B8BACED247AB}
983999
{697EB593-3277-4C43-B8F3-C578E21B051B} = {BB99CE55-AD68-484A-9474-B8BACED247AB}
9841000
{4FA6B420-53A3-4956-9C02-8649A720A9F5} = {BB99CE55-AD68-484A-9474-B8BACED247AB}
985-
{AF298985-511F-476A-8F62-79908BE8DF01} = {A704E5B2-86A4-4D4F-902D-C10EA18C12DF}
986-
{39B69A56-43E9-480D-9A60-8E0917795FE8} = {A704E5B2-86A4-4D4F-902D-C10EA18C12DF}
9871001
{F23ED302-7451-4D40-85C3-FACFCF884661} = {C53DD924-C212-49EA-9BC4-1827421361EF}
9881002
{BA4250FD-9258-4469-A16D-48A0CAF5A2F8} = {C53DD924-C212-49EA-9BC4-1827421361EF}
9891003
{DC0D0EE5-1C0C-4D3E-BA0B-D6A59717DA94} = {6BE49638-F842-4329-BE8A-30C0F30CCAA5}

eng/common/sdk-task.sh

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bash
2+
3+
show_usage() {
4+
echo "Common settings:"
5+
echo " --task <value> Name of Arcade task (name of a project in SdkTasks directory of the Arcade SDK package)"
6+
echo " --restore Restore dependencies"
7+
echo " --verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]"
8+
echo " --help Print help and exit"
9+
echo ""
10+
echo "Command line arguments not listed above are passed thru to msbuild."
11+
}
12+
13+
source="${BASH_SOURCE[0]}"
14+
15+
# resolve $source until the file is no longer a symlink
16+
while [[ -h "$source" ]]; do
17+
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
18+
source="$(readlink "$source")"
19+
# if $source was a relative symlink, we need to resolve it relative to the path where the
20+
# symlink file was located
21+
[[ $source != /* ]] && source="$scriptroot/$source"
22+
done
23+
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
24+
25+
Build() {
26+
local target=$1
27+
local log_suffix=""
28+
[[ "$target" != "Execute" ]] && log_suffix=".$target"
29+
local log="$log_dir/$task$log_suffix.binlog"
30+
local output_path="$toolset_dir/$task/"
31+
32+
MSBuild "$taskProject" \
33+
/bl:"$log" \
34+
/t:"$target" \
35+
/p:Configuration="$configuration" \
36+
/p:RepoRoot="$repo_root" \
37+
/p:BaseIntermediateOutputPath="$output_path" \
38+
/v:"$verbosity" \
39+
$properties
40+
}
41+
42+
configuration="Debug"
43+
verbosity="minimal"
44+
restore=false
45+
help=false
46+
properties=''
47+
48+
while (($# > 0)); do
49+
lowerI="$(echo $1 | tr "[:upper:]" "[:lower:]")"
50+
case $lowerI in
51+
--task)
52+
task=$2
53+
shift 2
54+
;;
55+
--restore)
56+
restore=true
57+
shift 1
58+
;;
59+
--verbosity)
60+
verbosity=$2
61+
shift 2
62+
;;
63+
--help)
64+
help=true
65+
shift 1
66+
;;
67+
*)
68+
properties="$properties $1"
69+
shift 1
70+
;;
71+
esac
72+
done
73+
74+
ci=true
75+
binaryLog=true
76+
warnAsError=true
77+
78+
if $help; then
79+
show_usage
80+
exit 0
81+
fi
82+
83+
. "$scriptroot/tools.sh"
84+
InitializeToolset
85+
86+
if [[ -z "$task" ]]; then
87+
Write-PipelineTelemetryError -Category 'Task' -Name 'MissingTask' -Message "Missing required parameter '-task <value>'"
88+
ExitWithExitCode 1
89+
fi
90+
91+
taskProject=$(GetSdkTaskProject "$task")
92+
if [[ ! -e "$taskProject" ]]; then
93+
Write-PipelineTelemetryError -Category 'Task' -Name 'UnknownTask' -Message "Unknown task: $task"
94+
ExitWithExitCode 1
95+
fi
96+
97+
if $restore; then
98+
Build "Restore"
99+
fi
100+
101+
Build "Execute"
102+
103+
104+
ExitWithExitCode 0

eng/common/tools.sh

+6
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ function GetDarc {
528528
"$eng_root/common/darc-init.sh" --toolpath "$darc_path" $version
529529
}
530530

531+
# Returns a full path to an Arcade SDK task project file.
532+
function GetSdkTaskProject {
533+
taskName=$1
534+
echo "$(dirname $_InitializeToolset)/SdkTasks/$taskName.proj"
535+
}
536+
531537
ResolvePath "${BASH_SOURCE[0]}"
532538
_script_dir=`dirname "$_ResolvePath"`
533539

src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/SigningValidation.proj

+4-9
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
<PropertyGroup>
2222
<TargetFramework>$(NetToolCurrent)</TargetFramework>
2323
<NETCORE_ENGINEERING_TELEMETRY>Build</NETCORE_ENGINEERING_TELEMETRY>
24-
<SignCheckTaskAssembly>$(NuGetPackageRoot)Microsoft.DotNet.SignCheck\$(MicrosoftDotNetSignCheckVersion)\tools\Microsoft.DotNet.SignCheck.exe</SignCheckTaskAssembly>
2524
</PropertyGroup>
2625

27-
<UsingTask TaskName="SignCheck.SignCheckTask" AssemblyFile="$(SignCheckTaskAssembly)" />
26+
<ItemGroup>
27+
<PackageReference Include="Microsoft.DotNet.SignCheckTask" Version="$(MicrosoftDotNetSignCheckTaskVersion)" />
28+
</ItemGroup>
2829

2930
<Target Name="Execute">
3031
<PropertyGroup>
@@ -35,14 +36,12 @@
3536
<InputFiles Condition="'$(BuildManifestFile)' != ''">@(ItemsToSign)</InputFiles>
3637
</PropertyGroup>
3738

38-
<Error Condition="'$(MSBuildRuntimeType)' == 'Core'" Text="Signing validation task does not run on core." />
39-
4039
<Message Text="Using build manifest file '$(BuildManifestFile)'" Condition="Exists('$(BuildManifestFile)')" />
4140
<!--
4241
Documentation for these arguments is available here:
4342
https://github.com/dotnet/arcade/tree/master/src/SignCheck
4443
-->
45-
<SignCheckTask
44+
<Microsoft.DotNet.SignCheckTask.SignCheckTask
4645
Recursive="true"
4746
FileStatus="UnsignedFiles"
4847
InputFiles="$(InputFiles)"
@@ -62,8 +61,4 @@
6261
Condition="Exists($(SignCheckErrorLog)) and '$([System.IO.File]::ReadAllText($(SignCheckErrorLog)))' != ''" />
6362
</Target>
6463

65-
<ItemGroup>
66-
<PackageReference Include="Microsoft.DotNet.SignCheck" Version="$(MicrosoftDotNetSignCheckVersion)" />
67-
</ItemGroup>
68-
6964
</Project>

src/Microsoft.DotNet.Arcade.Sdk/tools/SdkTasks/Versions.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<MicrosoftDotNetMaestroTasksVersion>$(MicrosoftDotNetMaestroTasksVersion)</MicrosoftDotNetMaestroTasksVersion>
88
<MicrosoftDotNetBuildTasksVisualStudioVersion>$(ArcadeSdkVersion)</MicrosoftDotNetBuildTasksVisualStudioVersion>
99
<MicrosoftDotNetBuildTasksFeedVersion Condition="'$(MicrosoftDotNetBuildTasksFeedVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetBuildTasksFeedVersion>
10-
<MicrosoftDotNetSignCheckVersion Condition="'$(MicrosoftDotNetSignCheckVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetSignCheckVersion>
10+
<MicrosoftDotNetSignCheckTaskVersion Condition="'$(MicrosoftDotNetSignCheckTaskVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetSignCheckTaskVersion>
1111
<MicrosoftSymbolUploaderBuildTaskVersion>$(MicrosoftSymbolUploaderBuildTaskVersion)</MicrosoftSymbolUploaderBuildTaskVersion>
1212
</PropertyGroup>
1313

src/SignCheck/Microsoft.SignCheck/Microsoft.DotNet.SignCheckLibrary.csproj

+25-3
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
<Import Project="ResxWorkaround.props" />
44

55
<PropertyGroup>
6-
<TargetFramework>$(NetFrameworkMinimum)</TargetFramework>
7-
<Platforms>x86</Platforms>
6+
<TargetFrameworks>$(NetToolCurrent);$(NetFrameworkMinimum)</TargetFrameworks>
87
<SignAssembly>false</SignAssembly>
98
<RootNamespace>Microsoft.SignCheck</RootNamespace>
109
<!-- This assembly is bundled in the Microsoft.DotNet.SignCheck package and is not mean to be used as a class library package. -->
1110
<IsPackable>false</IsPackable>
1211
<IsTool>true</IsTool>
12+
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
1313
</PropertyGroup>
1414

1515
<ItemGroup>
1616
<PackageReference Include="LZMA-SDK" />
17-
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop" />
17+
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop" Condition="$(TargetFramework) != $(NetToolCurrent)"/>
1818
<PackageReference Include="NuGet.Frameworks" />
1919
<PackageReference Include="NuGet.Packaging" />
2020
<PackageReference Include="System.IO.Packaging" />
2121
<PackageReference Include="Microsoft.Signed.Wix" />
22+
<PackageReference Include="System.Security.Cryptography.Xml" />
2223
</ItemGroup>
2324

2425
<ItemGroup>
@@ -35,6 +36,27 @@
3536
CopyToOutputDirectory="PreserveNewest" />
3637
</ItemGroup>
3738

39+
<ItemGroup Condition="'$(TargetFramework)' == '$(NetToolCurrent)'">
40+
<!-- Interop -->
41+
<Compile Remove="Interop\**" />
42+
<EmbeddedResource Remove="Interop\**" />
43+
44+
<!-- Unsupported file types -->
45+
<Compile Remove="Verification\AuthentiCode.cs" />
46+
<Compile Remove="Verification\AuthentiCodeVerifier.cs" />
47+
<Compile Remove="Verification\CabVerifier.cs" />
48+
<Compile Remove="Verification\ExeVerifier.cs" />
49+
<Compile Remove="Verification\JarVerifier.cs" />
50+
<Compile Remove="Verification\MsiVerifier.cs" />
51+
<Compile Remove="Verification\MspVerifier.cs" />
52+
<Compile Remove="Verification\MsuVerifier.cs" />
53+
<Compile Remove="Verification\PortableExecutableVerifier.cs" />
54+
<Compile Remove="Verification\StrongName.cs" />
55+
<Compile Remove="Verification\VsixVerifier.cs" />
56+
<Compile Remove="Verification\Jar\JarFile.cs" />
57+
<Compile Remove="Verification\Jar\JarSignatureFile.cs" />
58+
</ItemGroup>
59+
3860
<ItemGroup>
3961
<Compile Update="SignCheckResources.Designer.cs"
4062
DesignTime="True"

src/SignCheck/Microsoft.SignCheck/Utils.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Utils
1919
public static string GetHash(string value, string hashName)
2020
{
2121
byte[] bytes = Encoding.UTF8.GetBytes(value);
22-
HashAlgorithm ha = HashAlgorithm.Create(hashName);
22+
HashAlgorithm ha = CreateHashAlgorithm(hashName);
2323
byte[] hash = ha.ComputeHash(bytes);
2424

2525
var sb = new StringBuilder();
@@ -31,6 +31,25 @@ public static string GetHash(string value, string hashName)
3131
return sb.ToString();
3232
}
3333

34+
public static HashAlgorithm CreateHashAlgorithm(string hashName)
35+
{
36+
switch (hashName.ToUpperInvariant())
37+
{
38+
case "SHA256":
39+
return SHA256.Create();
40+
case "SHA1":
41+
return SHA1.Create();
42+
case "MD5":
43+
return MD5.Create();
44+
case "SHA384":
45+
return SHA384.Create();
46+
case "SHA512":
47+
return SHA512.Create();
48+
default:
49+
throw new ArgumentException("Unsupported hash algorithm name", nameof(hashName));
50+
}
51+
}
52+
3453
/// <summary>
3554
/// Converts a string containing wildcards (*, ?) into a regular expression pattern string.
3655
/// </summary>

src/SignCheck/Microsoft.SignCheck/Verification/AuthentiCode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,6 @@ public static IEnumerable<Timestamp> GetTimestamps(string path)
200200

201201
return timestamps;
202202
}
203-
203+
204204
}
205205
}

src/SignCheck/Microsoft.SignCheck/Verification/Jar/JarManifestFile.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private bool Verify(JarIndividualEntry entry, ZipArchiveEntry archiveEntry)
4848
{
4949
using (Stream stream = archiveEntry.Open())
5050
{
51-
HashAlgorithm ha = HashAlgorithm.Create(entry.HashAlgorithmName);
51+
HashAlgorithm ha = Utils.CreateHashAlgorithm(entry.HashAlgorithmName);
5252
byte[] computedHash = ha.ComputeHash(stream);
5353
string hashDigest = Convert.ToBase64String(computedHash);
5454

@@ -65,7 +65,7 @@ private bool Verify(JarIndividualEntry entry, ZipArchiveEntry archiveEntry)
6565

6666
private string GetHashDigest(string input, string algorithmName)
6767
{
68-
using (HashAlgorithm hashAlgorithm = HashAlgorithm.Create(algorithmName))
68+
using (HashAlgorithm hashAlgorithm = Utils.CreateHashAlgorithm(algorithmName))
6969
{
7070
byte[] hashValue = hashAlgorithm.ComputeHash(new UTF8Encoding().GetBytes(input.ToCharArray()));
7171
return Convert.ToBase64String(hashValue);

src/SignCheck/Microsoft.SignCheck/Verification/Jar/JarManifestFileBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public JarManifestFileBase(string archivePath, string manifestPath)
130130
/// <returns>A base64 encoded string of the manifest hash.</returns>
131131
public string GetManifestDigest(string algorithmName)
132132
{
133-
using (HashAlgorithm hashAlgorithm = HashAlgorithm.Create(algorithmName))
133+
using (HashAlgorithm hashAlgorithm = Utils.CreateHashAlgorithm(algorithmName))
134134
{
135135
byte[] hashValue = hashAlgorithm.ComputeHash(new UTF8Encoding().GetBytes(ManifestText.ToCharArray()));
136136
return Convert.ToBase64String(hashValue);

0 commit comments

Comments
 (0)