Skip to content

Commit 25d4ca2

Browse files
authored
Add certificate content type checking to Signature.cs (#42025)
As per recommendation from dotnet/docs#41662 (comment)
1 parent 7fbff0f commit 25d4ca2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Cli/dotnet/Installer/Windows/Security/Signature.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ internal static class Signature
2929
/// <remarks>This method does not perform any other chain validation like revocation checks, timestamping, etc.</remarks>
3030
internal static unsafe int HasMicrosoftTrustedRoot(string path)
3131
{
32+
var certContentType = X509Certificate2.GetCertContentType(path);
33+
if (certContentType != X509ContentType.Authenticode)
34+
{
35+
throw new CryptographicException($"Unexpected certificate content type, got '{certContentType}' instead of Authenticode.");
36+
}
37+
3238
// Create an X509Certificate2 instance so we can access the certificate context and create a chain context.
33-
#pragma warning disable SYSLIB0057 // can't use X509CertificateLoader here since it tries to parse the file as a certificate
39+
#pragma warning disable SYSLIB0057 // we need Authenticode support which isn't available from X509CertificateLoader
3440
using X509Certificate2 certificate = new(path);
3541
#pragma warning restore SYSLIB0057
3642

0 commit comments

Comments
 (0)