Skip to content

Commit 2723a86

Browse files
committed
Rely only on Authenticode to avoid possible signature hack
Fixes #415
1 parent 92bfbbc commit 2723a86

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

.idea/.idea.SoundSwitch/.idea/contentModel.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SoundSwitch/Framework/Updater/SignatureChecker.cs

+9-15
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,32 @@
1212
* GNU General Public License for more details.
1313
********************************************************************/
1414

15+
using System;
16+
using System.Linq;
1517
using System.Security.Cryptography.X509Certificates;
18+
using AuthenticodeExaminer;
1619

1720
namespace SoundSwitch.Framework.Updater
1821
{
1922
public static class SignatureChecker
2023
{
24+
private static string _certumSubject = "[email protected], CN=\"Open Source Developer, Antoine Aflalo\", O=Open Source Developer, S=Quebec, C=CA";
2125

22-
private static string _publicKey = "3082020A0282020100C9EAE3B1E873CE4F55AE1319171EED0B6B9D62DA5BC505BE864A98DC7C70C8B0AB2AD75644FB0E32176196F40A73CC2D1709F9F8C1FDF87732661D02C0C1F94956A57FA20A84408FA26BB46F59D581137257D3804EFBFA6B63CF7DF0F94E1060137FBC278D38EBCE304B9D73DF5D412DFF5BA2457130DD091C7059F73B3FC236BDB2F0A43DCD2F79843096D100CD7FFD35C282AE2AC0F716006EEB37BA832DF9758B7C2E1DCFC9D533472F01833E1C7AB46550B4C33D63A490E14FB5E3DDD1C505F590724FCA714E45DFE005CA52DBDF4272E54A3D27CDF4C0E08B4C991F48C77166197A44F1DB1A81C3D89E47F67E74C4265663BDC1332E438559EEB61056E57759F7A3D6576D6E9186C923E629B88D0C558C43ADA0C7CFB79E29993768CA9B6E81BACE389380E367E46C8E28077DA2C1FD02C50CF541ADBF05C170A13AFA80F66E8C7775D741C8D4F20FB990B934B9668BBE791F72367DB5D12E072BC692DAFDCF49327962B3E7904107EF3AA975C8524B3EB9F6F61E2B94F30292847559DD8A235DA7FF88F7F0B3CFF21D5BFD7452580FC8E24780C7EAB0E2B37791844522561392BA0F268641D25BF98E4EAA492B7563A1714505FEEDE82A560774A55E1C7D69B91328184607C3867E2E27D00E417CF6B8BC8B3A3B21CC1E775F7B655C39541342D492071AFBE5E2B89A136055429EA0A5E1C762AA5DE75A2625F78C4CD50203010001";
23-
private static string _serialNumber = "942A37BCA9A9889442F6710533CB5548";
2426
/// <summary>
2527
/// Does the given file have the right signature
2628
/// </summary>
2729
/// <param name="filename"></param>
2830
/// <returns></returns>
2931
public static bool IsValid(string filename)
3032
{
31-
var certificate = X509Certificate.CreateFromSignedFile(filename);
32-
return IsSelfSigned(certificate) || IsCertumSigned(certificate);
33+
return IsCertumSigned(filename);
3334
}
3435

35-
private static bool IsCertumSigned(X509Certificate certificate)
36+
private static bool IsCertumSigned(string filename)
3637
{
37-
return certificate.Issuer.Contains("Certum")
38-
&& certificate.Subject.Contains("Antoine Aflalo")
39-
&& certificate.Subject.Contains("soundswitch");
40-
}
41-
42-
private static bool IsSelfSigned(X509Certificate certificate)
43-
{
44-
return certificate.GetPublicKeyString() == _publicKey
45-
&& certificate.Issuer.Contains("CN=aaflalo.me")
46-
&& certificate.GetSerialNumberString() == _serialNumber;
38+
var inspector = new FileInspector(filename);
39+
return inspector.Validate() == SignatureCheckResult.Valid
40+
&& inspector.GetSignatures().FirstOrDefault(signature => signature.SigningCertificate.Subject == _certumSubject) != null;
4741
}
4842
}
4943
}

SoundSwitch/SoundSwitch.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@
130130
<PropertyGroup />
131131
<ItemGroup>
132132
<Reference Include="Accessibility" />
133+
<Reference Include="AuthenticodeExaminer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
134+
<HintPath>..\packages\AuthenticodeExaminer.0.3.0\lib\net461\AuthenticodeExaminer.dll</HintPath>
135+
<Private>True</Private>
136+
</Reference>
133137
<Reference Include="Microsoft.CSharp" />
134138
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.3.3, Culture=neutral, PublicKeyToken=8985beaab7ea3f04, processorArchitecture=MSIL">
135139
<HintPath>..\packages\Microsoft-WindowsAPICodePack-Core.1.1.3.3\lib\net452\Microsoft.WindowsAPICodePack.dll</HintPath>
@@ -179,6 +183,7 @@
179183
<Reference Include="System.IO.Compression.FileSystem" />
180184
<Reference Include="System.Runtime.Caching" />
181185
<Reference Include="System.Runtime.Remoting" />
186+
<Reference Include="System.Security" />
182187
<Reference Include="System.Windows.Forms" />
183188
<Reference Include="System.Xml" />
184189
<Reference Include="System.Xml.Linq" />

SoundSwitch/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="AuthenticodeExaminer" version="0.3.0" targetFramework="net472" />
34
<package id="Microsoft-WindowsAPICodePack-Core" version="1.1.3.3" targetFramework="net47" />
45
<package id="NAudio" version="1.9.0" targetFramework="net472" />
56
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />

0 commit comments

Comments
 (0)