Skip to content

Commit 31bfcd6

Browse files
committed
Updated pipeline for new sign mechanism.
1 parent fb64571 commit 31bfcd6

File tree

4 files changed

+125
-43
lines changed

4 files changed

+125
-43
lines changed

CodeGen.sln

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
142142
Documentation\Release Procedure.txt = Documentation\Release Procedure.txt
143143
SendMsiToDownloads.bat = SendMsiToDownloads.bat
144144
SignFile.bat = SignFile.bat
145+
signfile.ps1 = signfile.ps1
145146
EndProjectSection
146147
EndProject
147148
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SampleRepository", "SampleRepository", "{240CAFC0-11EF-4040-82ED-17B3B7870810}"

SignFile.bat

+25-37
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
1-
rem @echo off
2-
setlocal
3-
pushd %~dp0
4-
5-
if "%1"=="" goto usage
6-
7-
set FILE_TO_SIGN=%1
8-
9-
if not exist "%FILE_TO_SIGN%" (
10-
echo ERROR: File %FILE_TO_SIGN% was not found!
11-
goto done
12-
)
13-
14-
set TIMESTAMP_URL=http://timestamp.entrust.net/TSS/RFC3161sha2TS
15-
16-
echo.
17-
for %%F in ("%FILE_TO_SIGN%") do echo Signing %%~nxF
18-
19-
rem Should be able to use %WindowsSdkDir% but it looks like Visual Studio clears it for some reason!
20-
21-
rem This is the command used with the certificate on the physical USB device.
22-
"C:\Program Files (x86)\Windows Kits\10\bin\x86\signtool.exe" sign /fd SHA256 /a /tr "%TIMESTAMP_URL%" "%FILE_TO_SIGN%"
23-
24-
if "%ERRORLEVEL%"=="0" (
25-
echo SUCCESS!
26-
)
27-
28-
goto done
29-
30-
:usage
31-
echo.
32-
echo Usage: SignFile <fileSpec>
33-
echo.
34-
35-
:done
36-
popd
37-
endlocal
1+
@echo off
2+
setlocal
3+
4+
set SignTarget=%~1
5+
set CertFile=%~2
6+
set Secret=%~3
7+
set Description=%~4
8+
set AzureAppId=%~5
9+
set AzureDirId=%~6
10+
11+
if NOT DEFINED SignTarget goto usage
12+
if NOT DEFINED CertFile goto usage
13+
if NOT DEFINED Secret goto usage
14+
15+
powershell -NoLogo -NoProfile -Command "Import-Module %SYNERGY%\bat\signfile.ps1; Azure-Signfile -CertFile \"%CertFile%\" -SignSecret \"%Secret%\" -Description \"%Description%\" -TargetFile \"%SignTarget%\" -AzureAppId \"%AzureAppId%\" -AzureDirId \"%AzureDirId%\""
16+
endlocal
17+
goto exit
18+
19+
:usage
20+
echo *** usage: signfile filename certificate_name password description
21+
echo *** example: signfile dbr.exe SomeCert MySecret "Synergy/DE Runtime"
22+
endlocal
23+
24+
:exit
25+

azure-pipelines.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,11 @@ jobs:
6363
platform: '$(buildPlatform)'
6464
configuration: '$(buildConfiguration)'
6565

66-
- task: DownloadSecureFile@1
67-
displayName: 'Doanload AuthentiCode certificate'
68-
name: cert
69-
inputs:
70-
secureFile: dbd7ae8f-724a-49a3-a66a-662e9d6fe82b
7166

7267
- task: CmdLine@2
7368
displayName: 'Sign MSI file'
7469
inputs:
75-
script: '"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86\signtool.exe" sign /v /td sha256 /tr http://timestamp.digicert.com /fd sha256 /f $(cert.secureFilePath) /p "$(SigPass)" /d "CodeGen" /du "www.synergex.com" bin\release\CodeGen_$(currentVersion).msi'
70+
script: 'signfile.bat bin\release\CodeGen_$(currentVersion).msi "$(SigDrive)" "$(SigPass)" "CodeGen" "$(AzureAppId)" "$(AzureDirId)"'
7671

7772
- task: PublishBuildArtifacts@1
7873
displayName: 'Save MSI file as artifact'

signfile.ps1

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<#
2+
.SYNOPSIS
3+
Signs a file using AzureSignTool.
4+
5+
.DESCRIPTION
6+
This function wraps AzureSignTool to sign files using Azure Key Vault. It supports different verbosity levels and allows for application authentication.
7+
More information for AzureSignTool can be found here: https://github.com/vcsjones/AzureSignTool
8+
Examples for using AzureSignTool directly for pipelines can be found here: https://github.com/vcsjones/AzureSignTool/blob/main/WALKTHROUGH.md
9+
10+
.PARAMETER Description
11+
The description to be embedded in the signed file.
12+
13+
.PARAMETER TargetFile
14+
The path of one or more files to be signed.
15+
16+
.PARAMETER CertFile
17+
The name of the certificate in Azure Key Vault to use for signing.
18+
19+
.PARAMETER SignSecret
20+
The secret associated with the Azure Key Vault.
21+
22+
.PARAMETER Verbosity
23+
Controls the verbosity level of the output. Valid values are 0, 1, or 2.
24+
25+
.PARAMETER ApplicationId
26+
The GUID of the Azure application to be authenticated. Default value is the ID of rg-devops-prod
27+
28+
.PARAMETER DirectoryId
29+
The GUID of the Azure directory for the application. Default value is the directory of rg-devops-prod
30+
31+
.EXAMPLE
32+
Azure-SignFile -Description "My Application" -TargetFile "path\to\file.exe" -CertFile "myCert" -SignSecret "secret" -Verbosity 1
33+
#>
34+
35+
function Azure-SignFile
36+
{
37+
param (
38+
[Parameter(Mandatory)]
39+
[string] $CertFile,
40+
[Parameter(Mandatory)]
41+
[string] $SignSecret,
42+
[Parameter(Mandatory)]
43+
[string] $Description,
44+
[Parameter(Mandatory)]
45+
[string[]] $TargetFile,
46+
[Parameter()]
47+
[int] $Verbosity,
48+
[Parameter()]
49+
[string] $ApplicationId,
50+
[Parameter()]
51+
[string] $DirectoryId
52+
)
53+
54+
$signtool = "$env:userprofile\.dotnet\tools\AzureSignTool.exe"
55+
if (!(Test-Path "$signtool" -PathType leaf))
56+
{
57+
$toolInstall = Start-Process -FilePath "dotnet.exe" -ArgumentList "tool install --global azuresigntool" -Wait -NoNewWindow -PassThru
58+
if ($toolInstall.ExitCode -ne 0)
59+
{
60+
Write-Host "Failed to install azuresigntool"
61+
return;
62+
}
63+
}
64+
65+
$sVerbosity = "-q"
66+
if ($Verbosity -eq 1)
67+
{
68+
$sVerbosity = ""
69+
}
70+
elseif ($Verbosity -eq 2)
71+
{
72+
$sVerbosity = "-v"
73+
}
74+
75+
if ($Verbosity -eq 2)
76+
{
77+
Write-Host "Signing $TargetFile"
78+
}
79+
$arguments = "sign
80+
$sVerbosity
81+
-tr `"http://timestamp.digicert.com`"
82+
-td sha256
83+
-fd sha256
84+
-d `"$Description`"
85+
-du `"https://www.synergex.com`"
86+
-kvu `"https://kv-synergex-premium-prod.vault.azure.net`"
87+
-kvs `"$SignSecret`"
88+
-kvi `"$ApplicationId`"
89+
-kvt `"$DirectoryId`"
90+
-kvc `"$CertFile`"
91+
$TargetFile" -replace "`n","" -replace "`r","";
92+
93+
$signResult = Start-Process -FilePath "$signtool" -Wait -NoNewWindow -PassThru -ArgumentList $arguments
94+
if ($signResult.ExitCode -ne 0)
95+
{
96+
Write-Error "Failed to sign files";
97+
}
98+
}

0 commit comments

Comments
 (0)