Skip to content

Commit 88e0a2e

Browse files
committed
feat(build): add secret obfuscation during single file bundling
Add Confuser setup in CI pipeline and integrate obfuscation directly into MSBuild process for single-file bundles. This enhances security by automatically obfuscating KeyAsio.Secrets.dll before bundling when PublishSingleFile is true. The CI workflow is simplified by removing redundant obfuscation steps for single-file bundles.
1 parent dc8b609 commit 88e0a2e

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

.github/workflows/publish.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,25 @@ jobs:
4343
Set-Content -Path "src/Apps/KeyAsio/keyasio_private.key" -Value $env:OFFICIAL_PRIVATE_KEY
4444
}
4545
46+
- name: Setup Confuser
47+
shell: pwsh
48+
run: |
49+
mkdir Confuser -Force
50+
Invoke-WebRequest ${{ secrets.CONFUSER_DLURL }} -OutFile "Confuser/cli.zip"
51+
7z x "Confuser/cli.zip" -oConfuser/
52+
4653
- name: Publish
4754
run: |
4855
echo ${{ github.ref }}
49-
dotnet publish src/Apps/KeyAsio --framework net10.0 --runtime win-x64 --self-contained --configuration Release --output ci-publish-win64 -p:PublishReadyToRun=false
50-
dotnet publish src/Apps/KeyAsio --framework net10.0 --runtime win-x64 --self-contained --configuration Release --output ci-publish-win64-r2r -p:PublishReadyToRun=true
56+
$ConfuserExe = "$(Get-Location)\Confuser\${{ secrets.CONFUSER_EXE }}"
57+
dotnet publish src/Apps/KeyAsio --framework net10.0 --runtime win-x64 --self-contained --configuration Release --output ci-publish-win64 -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:ConfuserExe="$ConfuserExe"
58+
dotnet publish src/Apps/KeyAsio --framework net10.0 --runtime win-x64 --self-contained --configuration Release --output ci-publish-win64-r2r -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:ConfuserExe="$ConfuserExe"
5159
dotnet publish src/Apps/KeyAsio --framework net10.0 --runtime win-x64 --self-contained false --configuration Release --output ci-publish-win64-fd -p:PublishReadyToRun=false
5260
dotnet publish src/Apps/KeyAsio --framework net10.0 --runtime win-x64 --self-contained false --configuration Release --output ci-publish-win64-fd-r2r -p:PublishReadyToRun=true
5361
54-
- name: Confuser
62+
- name: Confuser (Framework Dependent)
5563
shell: pwsh
5664
run: |
57-
echo '<project outputDir="." baseDir=".\ci-publish-win64" xmlns="http://confuser.codeplex.com"><rule pattern="true" preset="maximum" inherit="false" /><module path="KeyAsio.Secrets.dll" /></project>'>confuse64.crproj
58-
mkdir Confuser -Force
59-
Invoke-WebRequest ${{ secrets.CONFUSER_DLURL }} -OutFile "Confuser/cli.zip"
60-
7z x "Confuser/cli.zip" -oConfuser/
61-
.\Confuser\${{ secrets.CONFUSER_EXE }} -file ".\ci-publish-win64\KeyAsio.Secrets.dll" -targetfile "<AssemblyLocation>\<AssemblyFileName>" -anti_debug 1 -hide_calls 1 -control_flow 1 -flow_level 9 -virtualization 1 -naming stealth
62-
del .\ci-publish-win64\KeyAsio.Secrets.pdb -Force
63-
64-
.\Confuser\${{ secrets.CONFUSER_EXE }} -file ".\ci-publish-win64-r2r\KeyAsio.Secrets.dll" -targetfile "<AssemblyLocation>\<AssemblyFileName>" -anti_debug 1 -hide_calls 1 -control_flow 1 -flow_level 9 -virtualization 1 -naming stealth
65-
del .\ci-publish-win64-r2r\KeyAsio.Secrets.pdb -Force
66-
6765
.\Confuser\${{ secrets.CONFUSER_EXE }} -file ".\ci-publish-win64-fd\KeyAsio.Secrets.dll" -targetfile "<AssemblyLocation>\<AssemblyFileName>" -anti_debug 1 -hide_calls 1 -control_flow 1 -flow_level 9 -virtualization 1 -naming stealth
6866
del .\ci-publish-win64-fd\KeyAsio.Secrets.pdb -Force
6967
@@ -73,11 +71,7 @@ jobs:
7371
- name: Set dll path
7472
shell: pwsh
7573
run: |
76-
copy .\src\Apps\KeyAsio\DotNetDllPathPatcher.ps1 .\DotNetDllPathPatcher.ps1
77-
.\src\Apps\KeyAsio\afterbuild.ps1 .\ci-publish-win64\KeyASIO.exe
78-
.\src\Apps\KeyAsio\afterbuild.ps1 .\ci-publish-win64-r2r\KeyASIO.exe
79-
.\src\Apps\KeyAsio\afterbuild.ps1 .\ci-publish-win64-fd\KeyASIO.exe
80-
.\src\Apps\KeyAsio\afterbuild.ps1 .\ci-publish-win64-fd-r2r\KeyASIO.exe
74+
echo "Skipping afterbuild.ps1"
8175
8276
- name: Upload Artifacts
8377
if: contains(github.ref_name, 'alpha')

src/Apps/KeyAsio/KeyAsio.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,13 @@
111111
<Message Text="Signing the published output assembly to $(PublishDir)..." Importance="High" />
112112
<Exec Command="pwsh -ExecutionPolicy Bypass -File &quot;$(MSBuildProjectDirectory)\..\..\Signer.ps1&quot; sign &quot;$(PublishDir)$(TargetFileName)&quot; &quot;$(MSBuildProjectDirectory)\keyasio_private.key&quot;" />
113113
</Target>
114+
115+
<Target Name="ObfuscateSecretsInBundle" BeforeTargets="GenerateSingleFileBundle" Condition="'$(ConfuserExe)' != '' And '$(PublishSingleFile)' == 'true'">
116+
<Message Text="Obfuscating KeyAsio.Secrets.dll before bundling..." Importance="High" />
117+
<PropertyGroup>
118+
<SecretsDllPath>$(PublishDir)KeyAsio.Secrets.dll</SecretsDllPath>
119+
</PropertyGroup>
120+
<Exec Command="&quot;$(ConfuserExe)&quot; -file &quot;$(SecretsDllPath)&quot; -targetfile &quot;$(SecretsDllPath)&quot; -anti_debug 1 -hide_calls 1 -control_flow 1 -flow_level 9 -virtualization 1 -naming stealth" />
121+
</Target>
122+
114123
</Project>

0 commit comments

Comments
 (0)