-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuthenticodeSignatureVerifier.cs
More file actions
46 lines (43 loc) · 1.39 KB
/
Copy pathAuthenticodeSignatureVerifier.cs
File metadata and controls
46 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* ThreadPilot - best-effort Authenticode signature detection.
*/
namespace ThreadPilot.Services
{
using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
public sealed class AuthenticodeSignatureVerifier : IUpdateSignatureVerifier
{
public UpdateSignatureStatus Verify(string installerPath)
{
if (!File.Exists(installerPath))
{
return UpdateSignatureStatus.Invalid;
}
try
{
using var certificate = new X509Certificate2(X509Certificate.CreateFromSignedFile(installerPath));
using var chain = new X509Chain
{
ChainPolicy =
{
RevocationMode = X509RevocationMode.Online,
RevocationFlag = X509RevocationFlag.ExcludeRoot,
},
};
return chain.Build(certificate)
? UpdateSignatureStatus.Valid
: UpdateSignatureStatus.Unknown;
}
catch (CryptographicException)
{
return UpdateSignatureStatus.Unknown;
}
catch (PlatformNotSupportedException)
{
return UpdateSignatureStatus.Unknown;
}
}
}
}