-
Notifications
You must be signed in to change notification settings - Fork 292
Fix binary signature expiry check to validate signing time against certificate validity period #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
9
commits into
release/v2.3
Choose a base branch
from
copilot/update-binary-signature-checks
base: release/v2.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
−12
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7073fd2
Initial plan
Copilot 1095c71
Initial plan for updating binary signature expiry check logic
Copilot 85f2fe8
Update signature validity check to compare signing time against certi…
Copilot e57e98e
Restore original nuget.config, address code review feedback
Copilot fc66c21
Simplify GetSigningTime: use framework type checking instead of manua…
Copilot 7cbed87
Improve comment clarity in GetSigningTime
Copilot 8788376
Address PR review: add RFC 3161 timestamp handling, improve logging a…
Copilot 688b610
Update GetSigningTime XML doc and filter RFC 3161 by OID before decoding
Copilot 8e2f890
Narrow signature validity rule to only flag signed binaries
gfs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. | ||
| using Microsoft.CST.AttackSurfaceAnalyzer.Objects; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using System; | ||
|
|
||
| namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests | ||
| { | ||
| [TestClass, TestCategory("PipelineSafeTests")] | ||
| public class SignatureTests | ||
| { | ||
| [TestMethod] | ||
| public void IsTimeValid_SignedDuringCertValidity_ReturnsTrue() | ||
| { | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| new DateTime(2025, 12, 31), // NotAfter | ||
| new DateTime(2020, 1, 1), // NotBefore | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = new DateTime(2023, 6, 15) // Signed within validity | ||
| }; | ||
| Assert.IsTrue(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_SignedAfterCertExpiry_ReturnsFalse() | ||
| { | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| new DateTime(2022, 12, 31), // NotAfter | ||
| new DateTime(2020, 1, 1), // NotBefore | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = new DateTime(2023, 6, 15) // Signed after expiry | ||
| }; | ||
| Assert.IsFalse(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_SignedBeforeCertNotBefore_ReturnsFalse() | ||
| { | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| new DateTime(2025, 12, 31), // NotAfter | ||
| new DateTime(2020, 1, 1), // NotBefore | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = new DateTime(2019, 6, 15) // Signed before NotBefore | ||
| }; | ||
| Assert.IsFalse(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_NullSigningTime_ReturnsFalse() | ||
| { | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| new DateTime(2025, 12, 31), | ||
| new DateTime(2020, 1, 1), | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = null | ||
| }; | ||
| Assert.IsFalse(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_NullSigningCertificate_ReturnsFalse() | ||
| { | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = null, | ||
| SigningTime = new DateTime(2023, 6, 15) | ||
| }; | ||
| Assert.IsFalse(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_CertExpiredNow_ButSignedDuringValidity_ReturnsTrue() | ||
| { | ||
| // This is the key scenario: cert is currently expired, but was valid when signing occurred | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| new DateTime(2020, 12, 31), // NotAfter - expired now | ||
| new DateTime(2018, 1, 1), // NotBefore | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = new DateTime(2019, 6, 15) // Signed while cert was valid | ||
| }; | ||
| Assert.IsTrue(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_SignedExactlyAtNotBefore_ReturnsTrue() | ||
| { | ||
| var notBefore = new DateTime(2020, 1, 1); | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| new DateTime(2025, 12, 31), | ||
| notBefore, | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = notBefore // Signed exactly at NotBefore boundary | ||
| }; | ||
| Assert.IsTrue(sig.IsTimeValid); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void IsTimeValid_SignedExactlyAtNotAfter_ReturnsTrue() | ||
| { | ||
| var notAfter = new DateTime(2025, 12, 31); | ||
| var sig = new Signature() | ||
| { | ||
| SigningCertificate = new SerializableCertificate( | ||
| "thumbprint", "CN=Test", "key", | ||
| notAfter, | ||
| new DateTime(2020, 1, 1), | ||
| "CN=Issuer", "serial", "hash", "pkcs7"), | ||
| SigningTime = notAfter // Signed exactly at NotAfter boundary | ||
| }; | ||
| Assert.IsTrue(sig.IsTimeValid); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <packageSources> | ||
| <clear /> | ||
| <add key="PublicRegistriesFeed" value="https://pkgs.dev.azure.com/microsoft-sdl/General/_packaging/PublicRegistriesFeed/nuget/v3/index.json" /> | ||
| </packageSources> | ||
| </configuration> | ||
| </configuration> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.