Skip to content

Commit bd4a3f4

Browse files
committed
Basic setup for signing assemblies post-build
1 parent 3d0253f commit bd4a3f4

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ _Resharper*/
2020
.idea/
2121
.store/
2222
.vs/
23+
BC_codesign.p12
24+
BC_password.txt
2325

2426
*.nuget.props
2527
*.nuget.targets

BouncyCastle.sln

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
99
Directory.Build.props = Directory.Build.props
1010
LICENSE.md = LICENSE.md
1111
README.md = README.md
12+
signfile.bat = signfile.bat
1213
version.json = version.json
1314
EndProjectSection
1415
EndProject
@@ -19,15 +20,20 @@ EndProject
1920
Global
2021
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2122
Debug|Any CPU = Debug|Any CPU
23+
Publish|Any CPU = Publish|Any CPU
2224
Release|Any CPU = Release|Any CPU
2325
EndGlobalSection
2426
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2527
{25326952-177B-4D34-9448-3024AF0D7B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2628
{25326952-177B-4D34-9448-3024AF0D7B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{25326952-177B-4D34-9448-3024AF0D7B46}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
30+
{25326952-177B-4D34-9448-3024AF0D7B46}.Publish|Any CPU.Build.0 = Publish|Any CPU
2731
{25326952-177B-4D34-9448-3024AF0D7B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
2832
{25326952-177B-4D34-9448-3024AF0D7B46}.Release|Any CPU.Build.0 = Release|Any CPU
2933
{4C1B7AC6-C338-4DB4-BB3A-E6B2F1882E7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3034
{4C1B7AC6-C338-4DB4-BB3A-E6B2F1882E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{4C1B7AC6-C338-4DB4-BB3A-E6B2F1882E7E}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
36+
{4C1B7AC6-C338-4DB4-BB3A-E6B2F1882E7E}.Publish|Any CPU.Build.0 = Publish|Any CPU
3137
{4C1B7AC6-C338-4DB4-BB3A-E6B2F1882E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3238
{4C1B7AC6-C338-4DB4-BB3A-E6B2F1882E7E}.Release|Any CPU.Build.0 = Release|Any CPU
3339
EndGlobalSection

crypto/src/BouncyCastle.Crypto.csproj

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<Product>BouncyCastle.NET</Product>
2525
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2626
<Title>BouncyCastle.NET Cryptography</Title>
27+
<Configurations>Debug;Release;Publish</Configurations>
2728
</PropertyGroup>
2829

2930
<!-- CI systems other than GitLab might need different conditions -->
@@ -72,6 +73,13 @@
7273
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7374
</PropertyGroup>
7475

76+
<PropertyGroup Condition="'$(Configuration)'=='Publish'">
77+
<DefineConstants />
78+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
79+
<!-- Deterministic build. -->
80+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
81+
</PropertyGroup>
82+
7583
<ItemGroup>
7684
<None Remove="**\*.properties" />
7785
<None Remove="pqc\crypto\**\*.bz2" />
@@ -102,4 +110,7 @@
102110
<!-- Here we can override/use any MSBuild properties set by Nerdbank.GitVersioning -->
103111
</PropertyGroup>
104112
</Target>
113+
<Target Name="SignAssemblies" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Publish'">
114+
<Exec Command="call &quot;$(ProjectDir)..\..\signfile.bat&quot; &quot;$(TargetPath)&quot;" />
115+
</Target>
105116
</Project>

crypto/test/BouncyCastle.Crypto.Tests.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<NoWarn>618;1591</NoWarn>
99
<RootNamespace>Org.BouncyCastle</RootNamespace>
1010
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
11+
<Configurations>Debug;Release;Publish</Configurations>
1112
</PropertyGroup>
1213

1314
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
@@ -18,6 +19,10 @@
1819
<DefineConstants>DEBUG;TRACE</DefineConstants>
1920
</PropertyGroup>
2021

22+
<PropertyGroup Condition="'$(Configuration)'=='Publish'">
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
</PropertyGroup>
25+
2126
<ItemGroup>
2227
<Compile Include="src\**\*.cs" Exclude="**\examples\**\*.cs" />
2328
<EmbeddedResource Include="data\**\*.*" Exclude="**\README.txt" />

signfile.bat

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@echo off
2+
3+
set BatchDir=%~dp0
4+
set Target=%1
5+
6+
set CodesignFile=%BatchDir%BC_codesign.p12
7+
set PasswordFile=%BatchDir%BC_password.txt
8+
set TimestampUrl=http://timestamp.comodoca.com
9+
rem set TimestampUrl=http://timestamp.sectigo.com
10+
set /p CodesignPass=<"%PasswordFile%"
11+
12+
rem TODO Figure out how to locate this automatically, or somehow use the developer command prompt
13+
set SignToolDir=C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\
14+
set SignTool=%SignToolDir%signtool.exe
15+
16+
echo Preparing to sign %Target%
17+
echo "%SignTool%" sign /f "%CodesignFile%" /fd sha256 /tr "%TimestampUrl%" /td sha256 /p "%CodesignPass%" %Target% || exit /b 1
18+
echo Waiting for 20 seconds before issuing command (avoid timeserver rejection)
19+
20+
rem Timestamp server requires 15 seconds or more between signing requests
21+
rem When publishing need to limit parallel build tasks to 1 in Tools|Options|Projects and Solutions|Build and Run
22+
ping -n 20 127.0.0.1 >NUL
23+
24+
"%SignTool%" sign /f "%CodesignFile%" /fd sha256 /tr "%TimestampUrl%" /td sha256 /p "%CodesignPass%" %Target% || exit /b 1
25+
26+
"%SignTool%" verify /pa /tw %Target% || exit /b 1

0 commit comments

Comments
 (0)