Skip to content

Commit

Permalink
Suppress nullability warnings
Browse files Browse the repository at this point in the history
Suppress some nullability warnings.
  • Loading branch information
martincostello committed Oct 31, 2023
1 parent 87e7177 commit ae44826
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AuthenticodeLint/Extraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Extraction
{
public static void ExtractToDisk(string file, CheckConfiguration configuration, IReadOnlyList<ICmsSignature> signatureGraph)
{
var fileDirectory = Path.Combine(configuration.ExtractPath, Path.GetFileName(file));
var fileDirectory = Path.Combine(configuration.ExtractPath!, Path.GetFileName(file));
if (Directory.Exists(fileDirectory))
{
Directory.Delete(fileDirectory, true);
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/Rules/10000-Sha1PrimarySignatureRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
return RuleResult.Fail;
}
var primary = graph[0];
if (primary.DigestAlgorithm.Value != KnownOids.SHA1)
if (primary.DigestAlgorithm!.Value != KnownOids.SHA1)
{
verboseWriter.LogSignatureMessage(primary, $"Expected {nameof(KnownOids.SHA1)} digest algorithm but is {primary.DigestAlgorithm.FriendlyName}.");
return RuleResult.Fail;
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/Rules/10001-Sha2SignatureExistsRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
{
var signatures = graph.VisitAll(SignatureKind.AnySignature);
if (signatures.Any(s =>
s.DigestAlgorithm.Value == KnownOids.SHA256 ||
s.DigestAlgorithm!.Value == KnownOids.SHA256 ||
s.DigestAlgorithm.Value == KnownOids.SHA384 ||
s.DigestAlgorithm.Value == KnownOids.SHA512))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
var result = RuleResult.Pass;
foreach(var signature in signatures)
{
if (signature.DigestAlgorithm.Value == KnownOids.MD2)
if (signature.DigestAlgorithm!.Value == KnownOids.MD2)
{
verboseWriter.LogSignatureMessage(signature, $"Uses the {nameof(KnownOids.MD2)} digest algorithm.");
result = RuleResult.Fail;
Expand Down
4 changes: 2 additions & 2 deletions AuthenticodeLint/Rules/10003-TimestampedRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
foreach (var counterSignature in counterSignatures)
{
isSigned = true;
if (counterSignature.DigestAlgorithm.Value == signature.DigestAlgorithm.Value)
if (counterSignature.DigestAlgorithm!.Value == signature.DigestAlgorithm!.Value)
{
strongSign = true;
break;
Expand All @@ -44,7 +44,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
}
else if (!strongSign)
{
verboseWriter.LogSignatureMessage(signature, $"Signature is not timestamped with the expected hash algorithm {signature.DigestAlgorithm.FriendlyName}.");
verboseWriter.LogSignatureMessage(signature, $"Signature is not timestamped with the expected hash algorithm {signature.DigestAlgorithm!.FriendlyName}.");
pass = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override bool ValidateChain(ICmsSignature signer, X509Chain chain, Sig

private static bool ValidateStrongChain(ICmsSignature signature, X509Chain chain, SignatureLogger verboseWriter)
{
var signatureStrength = GetHashStrenghForComparison(signature.DigestAlgorithm.Value!);
var signatureStrength = GetHashStrenghForComparison(signature.DigestAlgorithm!.Value!);
var strongShaChain = true;
var leafCertificateSignatureAlgorithm = chain.ChainElements[0].Certificate.SignatureAlgorithm;
var leafCertificateSignatureAlgorithmStrength = GetHashStrenghForComparison(leafCertificateSignatureAlgorithm.Value!);
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/Rules/10011-StrongKeyLengthRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
var result = RuleResult.Pass;
foreach (var signature in signatures)
{
var keyInfo = BitStrengthCalculator.CalculateStrength(signature.Certificate);
var keyInfo = BitStrengthCalculator.CalculateStrength(signature.Certificate!);
switch (keyInfo.AlgorithmName)
{
case PublicKeyAlgorithm.ECDSA when keyInfo.BitSize is null:
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/Rules/10012-RsaDsaPrimarySignatureRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
{
return RuleResult.Fail;
}
var info = BitStrengthCalculator.CalculateStrength(primary.Certificate);
var info = BitStrengthCalculator.CalculateStrength(primary.Certificate!);
if (info.AlgorithmName != PublicKeyAlgorithm.RSA && info.AlgorithmName != PublicKeyAlgorithm.DSA)
{
verboseWriter.LogSignatureMessage(primary, $"Primary signature should use RSA or DSA key but uses {info.AlgorithmName.ToString()}");
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/Rules/10013-MaxKeyLengthRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
var result = RuleResult.Pass;
foreach (var signature in signatures)
{
var keyInfo = BitStrengthCalculator.CalculateStrength(signature.Certificate);
var keyInfo = BitStrengthCalculator.CalculateStrength(signature.Certificate!);
switch (keyInfo.AlgorithmName)
{
case PublicKeyAlgorithm.ECDSA when keyInfo.BitSize is null:
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/Rules/10015-NoSha1Rule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
var result = RuleResult.Pass;
foreach(var signature in signatures)
{
if (signature.DigestAlgorithm.Value == KnownOids.SHA1)
if (signature.DigestAlgorithm!.Value == KnownOids.SHA1)
{
verboseWriter.LogSignatureMessage(signature, $"Uses the {nameof(KnownOids.SHA1)} digest algorithm.");
result = RuleResult.Fail;
Expand Down
4 changes: 2 additions & 2 deletions AuthenticodeLint/Rules/CertificateChainRuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public RuleResult Validate(IReadOnlyList<ICmsSignature> graph, SignatureLogger v
//It is possible to have a valid Authenticode signature if the certificate is expired but was
//timestamped while it was valid. In this case we still want to successfully build a chain to perform validation.
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.IgnoreNotTimeValid;
bool success = chain.Build(signature.Certificate);
bool success = chain.Build(signature.Certificate!);
if (!success)
{
verboseWriter.LogSignatureMessage(signature, $"Cannot build a chain successfully with signing certificate {signature.Certificate.SerialNumber}.");
verboseWriter.LogSignatureMessage(signature, $"Cannot build a chain successfully with signing certificate {signature.Certificate!.SerialNumber}.");
result = RuleResult.Fail;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion AuthenticodeLint/SignatureHasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class HashHelpers
public static string GetHashForSignature(ICmsSignature signature)
{
var digest = signature.SignatureDigest();
return digest.Aggregate(new StringBuilder(), (acc, b) => acc.AppendFormat("{0:x2}", b)).ToString();
return digest!.Aggregate(new StringBuilder(), (acc, b) => acc.AppendFormat("{0:x2}", b)).ToString();
}
}
}

0 comments on commit ae44826

Please sign in to comment.