Skip to content

Commit 3d1402f

Browse files
committed
Updated signature verification to include DLLs
1 parent 483b34b commit 3d1402f

File tree

9 files changed

+209
-56
lines changed

9 files changed

+209
-56
lines changed

scripts/build/TestFx.Sign.props

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0">
3+
<PropertyGroup>
4+
<RepoRoot Condition=" '$(RepoRoot)' == '' ">$([MSBuild]::NormalizeDirectory('$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'LICENSE'))'))</RepoRoot>
5+
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(RepoRoot)packages</NuGetPackageRoot>
6+
<BuildConfiguration Condition=" '$(BuildConfiguration)' == '' ">Release</BuildConfiguration>
7+
8+
<TestFxSigningPropsImported>true</TestFxSigningPropsImported>
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
12+
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)key.snk</AssemblyOriginatorKeyFile>
13+
<SignAssembly>true</SignAssembly>
14+
<SignType Condition=" '$(SignType)' == '' ">Test</SignType>
15+
<PublicSign Condition=" '$(IsLocalizedBuild)' == '' or '$(IsLocalizedBuild)' != 'true'">true</PublicSign>
16+
17+
<!-- Temporarily turning on Delay signing for Localized builds because publickey = true is not passed on to the assembler to create resource assmblies.-->
18+
<DelaySign Condition=" '$(IsLocalizedBuild)' == 'true' ">true</DelaySign>
19+
<OutputPath Condition=" '$(OutputPath)' == '' ">$(RepoRoot)artifacts\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
20+
</PropertyGroup>
21+
</Project>

scripts/build/TestFx.Sign.targets

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<PropertyGroup>
4+
<TestFxSigningTargetsImported>true</TestFxSigningTargetsImported>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<None Include="$(MSBuildThisFileDirectory)key.snk">
9+
<!-- Do not have this show up in Solution Explorer in VS -->
10+
<InProject>false</InProject>
11+
</None>
12+
</ItemGroup>
13+
14+
<!-- Signing and Localization. -->
15+
<ItemGroup Condition=" '$(IsTest)' == '' or '$(IsTest)' == 'false' ">
16+
<FilesToSign Include="$(OutDir)\$(AssemblyName).dll" Condition=" '$(IsVsixProj)' == '' or '$(IsVsixProj)' != 'true' ">
17+
<Authenticode>Microsoft400</Authenticode>
18+
<StrongName>StrongName</StrongName>
19+
</FilesToSign>
20+
21+
<SignFilesDependsOn Include="GatherLocalizedOutputsForSigning">
22+
<!-- Do not have this show up in Solution Explorer in VS -->
23+
<InProject>false</InProject>
24+
</SignFilesDependsOn>
25+
</ItemGroup>
26+
27+
<Target Name="GatherLocalizedOutputsForSigning" DependsOnTargets="TestFxLocalization">
28+
<ItemGroup>
29+
<FilesToSign Include="$(OutDir)\**\$(AssemblyName).resources.dll">
30+
<Authenticode>Microsoft400</Authenticode>
31+
<StrongName>StrongName</StrongName>
32+
</FilesToSign>
33+
</ItemGroup>
34+
</Target>
35+
</Project>

scripts/build/TestFx.props

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77
</PropertyGroup>
88

99
<Import Project="$(RepoRoot)eng\Versions.props" />
10+
<Import Project="$(RepoRoot)scripts\build\TestFx.Sign.props" Condition=" '$(TestFxSigningPropsImported)' != 'true' " />
1011

1112
<PropertyGroup>
1213
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
1314
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
1415
<DefaultLanguage>en-US</DefaultLanguage>
1516
<FileAlignment>512</FileAlignment>
1617
<GenerateLCE>true</GenerateLCE>
17-
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)key.snk</AssemblyOriginatorKeyFile>
18-
<SignAssembly>true</SignAssembly>
19-
<PublicSign Condition=" '$(IsLocalizedBuild)' == '' or '$(IsLocalizedBuild)' != 'true'">true</PublicSign>
20-
<!-- Temporarily turning on Delay signing for Localized builds because publickey = true is not passed on to the assembler to create resource assmblies.-->
21-
<DelaySign Condition=" '$(IsLocalizedBuild)' == 'true' ">true</DelaySign>
22-
<OutputPath Condition=" '$(OutputPath)' == '' ">$(RepoRoot)artifacts\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
2318
<IntermediatePath Condition=" '$(IntermediatePath)' == '' ">$(RepoRoot)artifacts\$(Configuration)\$(MSBuildProjectName)\obj\</IntermediatePath>
2419
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2520
</PropertyGroup>

scripts/build/TestFx.targets

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<!-- Import localization specific Targets if enabled. -->
44
<Import Project="$(MSBuildThisFileDirectory)TestFx.Loc.props" Condition=" ('$(IsTest)' == '' or '$(IsTest)' == 'false') and '$(IsLocalizationEnabled)' == 'true' "/>
5-
6-
<ItemGroup>
7-
<None Include="$(MSBuildThisFileDirectory)key.snk">
8-
<!-- Do not have this show up in Solution Explorer in VS -->
9-
<InProject>false</InProject>
10-
</None>
11-
</ItemGroup>
5+
<Import Project="$(RepoRoot)scripts\build\TestFx.Sign.targets" Condition=" '$(TestFxSigningTargetsImported)' != 'true' " />
126

137
<!-- StyleCop settings. -->
148
<ItemGroup Condition=" '$(ShouldEnableStyleCop)' != 'false' and '$(IsVsixProj)' != 'true'">
@@ -21,28 +15,6 @@
2115
<Analyzer Include="$(NuGetPackageRoot)\StyleCop.Analyzers\$(StyleCopAnalyzersVersion)\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
2216
</ItemGroup>
2317

24-
<!-- Signing and Localization. -->
25-
<ItemGroup Condition=" '$(IsTest)' == '' or '$(IsTest)' == 'false' ">
26-
<FilesToSign Include="$(OutDir)\$(AssemblyName).dll" Condition=" '$(IsVsixProj)' == '' or '$(IsVsixProj)' != 'true' ">
27-
<Authenticode>Microsoft400</Authenticode>
28-
<StrongName>StrongName</StrongName>
29-
</FilesToSign>
30-
31-
<SignFilesDependsOn Include="GatherLocalizedOutputsForSigning">
32-
<!-- Do not have this show up in Solution Explorer in VS -->
33-
<InProject>false</InProject>
34-
</SignFilesDependsOn>
35-
</ItemGroup>
36-
37-
<Target Name="GatherLocalizedOutputsForSigning" DependsOnTargets="TestFxLocalization">
38-
<ItemGroup>
39-
<FilesToSign Include="$(OutDir)\**\$(AssemblyName).resources.dll">
40-
<Authenticode>Microsoft400</Authenticode>
41-
<StrongName>StrongName</StrongName>
42-
</FilesToSign>
43-
</ItemGroup>
44-
</Target>
45-
4618
<!-- Generate AssemblyInfo.cs -->
4719
<PropertyGroup>
4820
<TFBuildNumber Condition=" '$(TFBuildNumber)' == '' ">0.1</TFBuildNumber>

scripts/common.lib.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
Add-Type -AssemblyName System.IO.Compression.FileSystem
5+
46
# Common utilities for building solution and running tests
57

68
$TF_ROOT_DIR = (Get-Item (Split-Path $MyInvocation.MyCommand.Path)).Parent.FullName
@@ -294,4 +296,11 @@ function Install-DotNetCli {
294296
}
295297
catch {}
296298
Write-Log "Install-DotNetCli: Complete."
299+
}
300+
301+
function Unzip
302+
{
303+
param([string]$zipfile, [string]$outpath)
304+
305+
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
297306
}

scripts/verify-sign.ps1

Lines changed: 125 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,163 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
# Build script for Test Platform.
5-
64
[CmdletBinding()]
75
Param(
86
[Parameter(Mandatory=$false)]
97
[ValidateSet("Debug", "Release")]
108
[Alias("c")]
11-
[System.String] $Configuration = "Debug"
9+
[string] $Configuration = "Debug",
10+
[string] $ArtifactsDirectory = "",
11+
[switch] $Force
1212
)
1313

1414
. $PSScriptRoot\common.lib.ps1
1515

1616
#
1717
# Variables
1818
#
19-
$rootDirectory = (Get-Item (Split-Path $MyInvocation.MyCommand.Path)).Parent.FullName
19+
if(-not [string]::IsNullOrWhiteSpace($ArtifactsDirectory)) {
20+
$TF_OUT_DIR = $ArtifactsDirectory
21+
}
2022

2123
#
2224
# Signing configuration
2325
#
2426
Write-Verbose "Setup build configuration."
25-
$TPB_Configuration = $Configuration
2627

27-
function Verify-NugetPackages
28+
$TF_Configuration = $Configuration
29+
$TF_AssembliesPattern = @("Microsoft.VisualStudio.TestPlatform.*.dll", "Microsoft.TestPlatform.*.dll")
30+
$script:ErrorCount = 0
31+
32+
function Test-Assembly ([string] $Path)
2833
{
29-
Write-Log "Verify-NugetPackages: Start"
34+
$signature = Get-AuthenticodeSignature -FilePath $Path
3035

31-
$nugetInstallPath = Locate-NuGet
36+
if ($signature.Status -eq "Valid") {
37+
if ($signature.SignerCertificate.Subject -eq "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US") {
38+
Write-Debug "Valid ($($signature.SignerCertificate.Thumbprint)): $Path"
39+
}
40+
elseif ($signature.SignerCertificate.Subject -eq "CN=Microsoft 3rd Party Application Component, O=Microsoft Corporation, L=Redmond, S=Washington, C=US") {
41+
Write-Debug "Valid ($($signature.SignerCertificate.Thumbprint)): $Path [3rd Party]"
42+
}
43+
else {
44+
# For legacy components
45+
# CN=Microsoft Corporation, OU=AOC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US
46+
if ($signature.SignerCertificate.Thumbprint -eq "49D59D86505D82942A076388693F4FB7B21254EE") {
47+
Write-Debug "Valid ($($signature.SignerCertificate.Thumbprint)): $Path [Legacy Prod Signed]"
48+
}
49+
else {
50+
Write-FailLog "Invalid ($($signature.SignerCertificate.Thumbprint)). File: $Path. [$($signature.SignerCertificate.Subject)]"
51+
}
52+
}
53+
}
54+
else {
55+
Write-FailLog "Not signed. File: $Path."
56+
}
57+
}
58+
59+
function Test-Assemblies ([string] $Path)
60+
{
61+
foreach ($pattern in $TF_AssembliesPattern) {
62+
Get-ChildItem -Recurse -Include $pattern $Path | Where-Object { (!$_.PSIsContainer) } | ForEach-Object {
63+
Test-Assembly $_.FullName
64+
}
65+
}
66+
}
67+
68+
function Test-NugetPackage ([string] $Path) {
69+
$packageFolder = [System.IO.Path]::GetDirectoryName($Path)
70+
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($Path)
71+
$out = Join-Path $packageFolder $fileName
72+
73+
try {
74+
Write-ToCI "Verifing assemblies in $Path" -type "group"
75+
Write-Debug "Extracting..."
76+
if (Test-Path $out) {
77+
if (-not $Force) {
78+
Write-FailLog "Folder already exists: $out"
79+
return
80+
}
81+
82+
Remove-Item $out -Recurse -Force
83+
}
84+
85+
Unzip $Path $out
86+
87+
Test-Assemblies $out
88+
} finally {
89+
if (Test-Path $out) {
90+
Remove-Item $out -Recurse -Force
91+
}
92+
Write-ToCI -type "endgroup"
93+
}
94+
}
3295

33-
Write-Log "Using nuget.exe installed at $nugetInstallPath"
96+
function Test-NugetPackages
97+
{
98+
Write-Debug "Test-NugetPackages"
99+
100+
$nugetInstallPath = Locate-NuGet
101+
Write-Debug "Using nuget.exe installed at $nugetInstallPath"
34102

35-
$artifactsDirectory = Join-Path $rootDirectory "artifacts"
36-
$artifactsConfigDirectory = Join-Path $artifactsDirectory $TPB_Configuration
103+
$artifactsConfigDirectory = Join-Path $TF_OUT_DIR $TF_Configuration
37104
$packagesDirectory = Join-Path $artifactsConfigDirectory "MSTestPackages"
105+
38106
Get-ChildItem -Filter *.nupkg $packagesDirectory | ForEach-Object {
39-
& $nugetInstallPath verify -signature -CertificateFingerprint "3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE;AA12DA22A49BCE7D5C1AE64CC1F3D892F150DA76140F210ABD2CBFFCA2C18A27;" $_.FullName
107+
try {
108+
Write-ToCI "Verifing $($_.FullName)" -type "group"
109+
& $nugetInstallPath verify -signature -CertificateFingerprint "3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE;AA12DA22A49BCE7D5C1AE64CC1F3D892F150DA76140F210ABD2CBFFCA2C18A27;" $_.FullName
110+
Test-NugetPackage -path $_.FullName
111+
} finally {
112+
Write-ToCI -type "endgroup"
113+
}
40114
}
41115

42-
Write-Log "Verify-NugetPackages: Complete"
116+
Write-Debug "Test-NugetPackages: Complete"
43117
}
44118

45-
function Write-Log ([string] $message)
119+
function Write-FailLog ([string] $message)
120+
{
121+
$script:ErrorCount = $script:ErrorCount + 1
122+
Write-ToCI -message $message -type "error"
123+
}
124+
125+
function Write-Debug ([string] $message)
126+
{
127+
Write-ToCI -message $message -type "debug"
128+
}
129+
130+
function Write-ToCI ([string] $message, [string]$type, [switch]$vso)
46131
{
47132
$currentColor = $Host.UI.RawUI.ForegroundColor
48-
$Host.UI.RawUI.ForegroundColor = "Green"
49-
if ($message)
133+
134+
if($type -eq "error") {
135+
$Host.UI.RawUI.ForegroundColor = "Red"
136+
}
137+
138+
if ($message -or $vso -or $type)
50139
{
51-
Write-Output "... $message"
140+
$prefix = ""
141+
if ($vso) {
142+
$prefix = "vso"
143+
}
144+
145+
Write-Output "##$prefix[$type]$message"
52146
}
53147
$Host.UI.RawUI.ForegroundColor = $currentColor
54148
}
55149

56-
Verify-NugetPackages
150+
try {
151+
Write-ToCI "Variables used: " -type "group"
152+
Get-ChildItem variable:TF_*
153+
Write-Output ""
154+
Write-Output ""
155+
} finally {
156+
Write-ToCI -type "endgroup"
157+
}
158+
159+
Test-NugetPackages
160+
161+
if ($script:ErrorCount -gt 0) {
162+
Write-ToCI -message "Verification failed, $($script:ErrorCount) errors found!" -type "task.logissue" -vso
163+
}

src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<FrameworkIdentifier>NetCore</FrameworkIdentifier>
44
</PropertyGroup>
5+
56
<PropertyGroup>
67
<RootNamespace>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices</RootNamespace>
78
<AssemblyName>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices</AssemblyName>
@@ -14,6 +15,11 @@
1415
<SkipAppendingVersion>true</SkipAppendingVersion> <!-- TODO: remove after full arcade transition -->
1516
</PropertyGroup>
1617

18+
<ImportGroup>
19+
<Import Project="$(NuGetPackageRoot)\Microbuild.Core\$(MicroBuildCoreVersion)\build\Microbuild.Core.targets" />
20+
<Import Project="$(NuGetPackageRoot)\Microbuild.Core\$(MicroBuildCoreVersion)\build\Microbuild.Core.props" />
21+
</ImportGroup>
22+
1723
<ItemGroup>
1824
<ProjectReference Include="$(RepoRoot)src\TestFramework\Extension.Core\Extension.Core.csproj" />
1925
<ProjectReference Include="$(RepoRoot)src\TestFramework\MSTest.Core\MSTest.Core.csproj" />
@@ -77,5 +83,4 @@
7783
<CustomToolNamespace>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices</CustomToolNamespace>
7884
</EmbeddedResource>
7985
</ItemGroup>
80-
8186
</Project>

src/Adapter/PlatformServices.WinUI/PlatformServices.WinUI.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<FrameworkIdentifier>NetCore</FrameworkIdentifier>
44
</PropertyGroup>
5+
56
<PropertyGroup>
67
<RootNamespace>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices</RootNamespace>
78
<AssemblyName>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices</AssemblyName>
@@ -18,6 +19,11 @@
1819
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
1920
</PropertyGroup>
2021

22+
<ImportGroup>
23+
<Import Project="$(NuGetPackageRoot)\Microbuild.Core\$(MicroBuildCoreVersion)\build\Microbuild.Core.targets" />
24+
<Import Project="$(NuGetPackageRoot)\Microbuild.Core\$(MicroBuildCoreVersion)\build\Microbuild.Core.props" />
25+
</ImportGroup>
26+
2127
<ItemGroup>
2228
<ProjectReference Include="$(RepoRoot)src\Adapter\PlatformServices.Interface\PlatformServices.Interface.csproj" />
2329
<ProjectReference Include="$(RepoRoot)src\TestFramework\Extension.Core\Extension.Core.csproj" />
@@ -98,5 +104,4 @@
98104
<CustomToolNamespace>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices</CustomToolNamespace>
99105
</EmbeddedResource>
100106
</ItemGroup>
101-
102107
</Project>

0 commit comments

Comments
 (0)