From 33ed33b9094f7aa64d94a56c77e7694c7a9a61ae Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Sun, 2 Mar 2025 09:30:41 +0100 Subject: [PATCH 1/6] Migrate from VSTest to MTP --- CoseHandler.Tests/CoseHandler.Tests.csproj | 6 +++--- .../CoseIndirectSignature.Tests.csproj | 6 +++--- .../CoseSign1.Certificates.Tests.csproj | 6 +++--- CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj | 6 +++--- CoseSign1.Tests/CoseSign1.Tests.csproj | 6 +++--- CoseSignTool.Tests/CoseSignTool.Tests.csproj | 6 +++--- Directory.Build.props | 10 ++++++++++ 7 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 Directory.Build.props diff --git a/CoseHandler.Tests/CoseHandler.Tests.csproj b/CoseHandler.Tests/CoseHandler.Tests.csproj index da0909ef..4c9e88c7 100644 --- a/CoseHandler.Tests/CoseHandler.Tests.csproj +++ b/CoseHandler.Tests/CoseHandler.Tests.csproj @@ -1,6 +1,7 @@  + Exe net8.0 enable enable @@ -22,10 +23,9 @@ - - - + + diff --git a/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj b/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj index bfaf4813..91a51f01 100644 --- a/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj +++ b/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj @@ -1,6 +1,7 @@  + Exe enable false true @@ -21,12 +22,11 @@ - - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj b/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj index 91ad2fc7..de50b75f 100644 --- a/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj +++ b/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj @@ -1,6 +1,7 @@  + Exe net8.0 enable false @@ -19,10 +20,9 @@ - - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj b/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj index 4fe80485..97820d25 100644 --- a/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj +++ b/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj @@ -1,6 +1,7 @@  + Exe net8.0 enable false @@ -18,10 +19,9 @@ - - + - + diff --git a/CoseSign1.Tests/CoseSign1.Tests.csproj b/CoseSign1.Tests/CoseSign1.Tests.csproj index f88281f0..0dfda2fd 100644 --- a/CoseSign1.Tests/CoseSign1.Tests.csproj +++ b/CoseSign1.Tests/CoseSign1.Tests.csproj @@ -1,6 +1,7 @@  + Exe net8.0 enable false @@ -18,12 +19,11 @@ - - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CoseSignTool.Tests/CoseSignTool.Tests.csproj b/CoseSignTool.Tests/CoseSignTool.Tests.csproj index f418733c..6145a700 100644 --- a/CoseSignTool.Tests/CoseSignTool.Tests.csproj +++ b/CoseSignTool.Tests/CoseSignTool.Tests.csproj @@ -1,5 +1,6 @@  + Exe net8.0 AnyCPU @@ -26,9 +27,8 @@ - - - + + diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..ae19387b --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,10 @@ + + + true + true + true + true + true + true + + \ No newline at end of file From 3604366bbc92c2c8849711024111932dd278ba34 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Sun, 2 Mar 2025 09:46:04 +0100 Subject: [PATCH 2/6] Fix build errors --- CoseHandler.Tests/CoseHandler.Tests.csproj | 1 + CoseHandler.Tests/CoseSignValidateTests.cs | 18 +++++++++--------- CoseHandler.Tests/TestsForTheUnderlyingAPI.cs | 3 ++- CoseSignTool.Tests/MainTests.cs | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CoseHandler.Tests/CoseHandler.Tests.csproj b/CoseHandler.Tests/CoseHandler.Tests.csproj index 4c9e88c7..9c86b004 100644 --- a/CoseHandler.Tests/CoseHandler.Tests.csproj +++ b/CoseHandler.Tests/CoseHandler.Tests.csproj @@ -13,6 +13,7 @@ True enable ..\StrongNameKeys\35MSSharedLib1024.snk + CoseSignUnitTests diff --git a/CoseHandler.Tests/CoseSignValidateTests.cs b/CoseHandler.Tests/CoseSignValidateTests.cs index b259dafb..a8d25b9f 100644 --- a/CoseHandler.Tests/CoseSignValidateTests.cs +++ b/CoseHandler.Tests/CoseSignValidateTests.cs @@ -11,12 +11,12 @@ public class CoseHandlerSignValidateTests // Certificates and chains as objects private static readonly X509Certificate2 SelfSignedCert = TestCertificateUtils.CreateCertificate(nameof(CoseHandlerSignValidateTests) + " self signed"); // A self-signed cert private static readonly X509Certificate2Collection CertChain1 = TestCertificateUtils.CreateTestChain(nameof(CoseHandlerSignValidateTests) + " set 1"); // Two complete cert chains - private static readonly X509Certificate2Collection CertChain2= TestCertificateUtils.CreateTestChain(nameof(CoseHandlerSignValidateTests) + " set 2"); + // private static readonly X509Certificate2Collection CertChain2 = TestCertificateUtils.CreateTestChain(nameof(CoseHandlerSignValidateTests) + " set 2"); private static readonly X509Certificate2 Root1Priv = CertChain1[0]; // Roots from the chains - private static readonly X509Certificate2 Root2Priv = CertChain2[0]; + // private static readonly X509Certificate2 Root2Priv = CertChain2[0]; private static readonly X509Certificate2 Int1Priv = CertChain1[1]; private static readonly X509Certificate2 Leaf1Priv = CertChain1[^1]; // Leaf node certs - private static readonly X509Certificate2 Leaf2Priv = CertChain2[^1]; + // private static readonly X509Certificate2 Leaf2Priv = CertChain2[^1]; // As byte arrays private static readonly byte[] Root1Cer = Root1Priv.Export(X509ContentType.Cert); @@ -49,9 +49,9 @@ public CoseHandlerSignValidateTests() { // export generated certs to files File.WriteAllBytes(PrivateKeyCertFileSelfSigned, SelfSignedCert.Export(X509ContentType.Pkcs12)); - File.WriteAllBytes(PublicKeyCertFileSelfSigned, SelfSignedCert.Export(X509ContentType.Cert)); - File.WriteAllBytes(PrivateKeyRootCertFile, Root1Priv.Export(X509ContentType.Pkcs12)); - File.WriteAllBytes(PublicKeyRootCertFile, Root1Priv.Export(X509ContentType.Cert)); + File.WriteAllBytes(PublicKeyCertFileSelfSigned, SelfSignedCert.Export(X509ContentType.Cert)); + File.WriteAllBytes(PrivateKeyRootCertFile, Root1Priv.Export(X509ContentType.Pkcs12)); + File.WriteAllBytes(PublicKeyRootCertFile, Root1Priv.Export(X509ContentType.Cert)); File.WriteAllBytes(PrivateKeyCertFileChained, Leaf1Priv.Export(X509ContentType.Pkcs12)); } @@ -103,7 +103,7 @@ public void PayloadFile_SignatureFile() { FileInfo f = new(FileSystemUtils.GeneratePayloadFile()); string signaturePath = f.FullName.Replace("spdx.json", "cose"); - FileInfo signatureFile = new (signaturePath); + FileInfo signatureFile = new(signaturePath); byte[] signedBytes = CoseHandler.Sign(f, Leaf1Priv, false, signatureFile).ToArray(); signedBytes.Should().NotBeNull(); @@ -116,7 +116,7 @@ public void PayloadFile_SignatureFile() .Success.Should().Be(true); // Validate from stream - FileInfo sigFile = new (signaturePath); + FileInfo sigFile = new(signaturePath); sigFile.Should().NotBeNull(); CoseHandler.Validate(sigFile.GetStreamResilient()!, Payload1Bytes, ValidRootSetPriv, RevMode) .Success.Should().Be(true); @@ -307,7 +307,7 @@ public void DetachedValidationWithoutPayload() public void SignWithoutPayload() { #pragma warning disable CS8600, CS8625 // Converting null literal -- deliberate null convetrsion for test purposes. - _ = CoseHandler.Sign((byte[]) null, Leaf1Priv); + _ = CoseHandler.Sign((byte[])null, Leaf1Priv); #pragma warning restore CS8600, CS8625 // Converting null literal or possible null value to non-nullable type. } diff --git a/CoseHandler.Tests/TestsForTheUnderlyingAPI.cs b/CoseHandler.Tests/TestsForTheUnderlyingAPI.cs index ab017a2b..61789853 100644 --- a/CoseHandler.Tests/TestsForTheUnderlyingAPI.cs +++ b/CoseHandler.Tests/TestsForTheUnderlyingAPI.cs @@ -3,7 +3,8 @@ namespace CoseSignUnitTests; -internal class TestsForTheUnderlyingAPI +[TestClass] +public class TestsForTheUnderlyingAPI { private readonly byte[] Payload1 = Encoding.ASCII.GetBytes("Payload1!"); private const string SubjectName1 = $"{nameof(TestsForTheUnderlyingAPI)}_Cert1"; diff --git a/CoseSignTool.Tests/MainTests.cs b/CoseSignTool.Tests/MainTests.cs index 45ed184c..e27ea590 100644 --- a/CoseSignTool.Tests/MainTests.cs +++ b/CoseSignTool.Tests/MainTests.cs @@ -9,12 +9,12 @@ public class MainTests // Certificates private static readonly X509Certificate2 SelfSignedCert = TestCertificateUtils.CreateCertificate(nameof(MainTests) + " self signed"); // A self-signed cert private static readonly X509Certificate2Collection CertChain1 = TestCertificateUtils.CreateTestChain(nameof(MainTests) + " set 1"); // Two complete cert chains - private static readonly X509Certificate2Collection CertChain2 = TestCertificateUtils.CreateTestChain(nameof(MainTests) + " set 2"); + // private static readonly X509Certificate2Collection CertChain2 = TestCertificateUtils.CreateTestChain(nameof(MainTests) + " set 2"); private static readonly X509Certificate2 Root1Priv = CertChain1[0]; // Roots from the chains - private static readonly X509Certificate2 Root2Priv = CertChain2[0]; + // private static readonly X509Certificate2 Root2Priv = CertChain2[0]; private static readonly X509Certificate2 Int1Priv = CertChain1[1]; private static readonly X509Certificate2 Leaf1Priv = CertChain1[^1]; // Leaf node certs - private static readonly X509Certificate2 Leaf2Priv = CertChain2[^1]; + // private static readonly X509Certificate2 Leaf2Priv = CertChain2[^1]; // File paths to export them to private static readonly string PrivateKeyCertFileSelfSigned = Path.GetTempFileName() + "_SelfSigned.pfx"; From c78ae5a09bdc7a8f3bd39bc3869b6e82235cb1fc Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Sun, 2 Mar 2025 09:50:36 +0100 Subject: [PATCH 3/6] Use .NET 9 SDK --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f855a677..35b452eb 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -34,7 +34,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 9.0.x # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From ac5fbf5c71f169500a0b0420e46cb997e93bb539 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 8 Jul 2025 22:15:39 +0200 Subject: [PATCH 4/6] Update to 3.9.3 Signed-off-by: Youssef Victor --- CoseHandler.Tests/CoseHandler.Tests.csproj | 5 +++-- .../CoseIndirectSignature.Tests.csproj | 2 +- .../CoseSign1.Certificates.Tests.csproj | 3 ++- CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj | 2 +- CoseSign1.Tests/CoseSign1.Tests.csproj | 3 ++- CoseSignTool.Tests/CoseSignTool.Tests.csproj | 5 +++-- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CoseHandler.Tests/CoseHandler.Tests.csproj b/CoseHandler.Tests/CoseHandler.Tests.csproj index 9c86b004..d4a473d8 100644 --- a/CoseHandler.Tests/CoseHandler.Tests.csproj +++ b/CoseHandler.Tests/CoseHandler.Tests.csproj @@ -25,8 +25,9 @@ - - + + + diff --git a/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj b/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj index 91a51f01..c7634ac2 100644 --- a/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj +++ b/CoseIndirectSignature.Tests/CoseIndirectSignature.Tests.csproj @@ -24,7 +24,7 @@ - + diff --git a/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj b/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj index de50b75f..12369ad7 100644 --- a/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj +++ b/CoseSign1.Certificates.Tests/CoseSign1.Certificates.Tests.csproj @@ -20,7 +20,8 @@ - + + diff --git a/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj b/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj index 97820d25..c8521455 100644 --- a/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj +++ b/CoseSign1.Headers.Tests/CoseSign1.Headers.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/CoseSign1.Tests/CoseSign1.Tests.csproj b/CoseSign1.Tests/CoseSign1.Tests.csproj index 0c689ace..6042b109 100644 --- a/CoseSign1.Tests/CoseSign1.Tests.csproj +++ b/CoseSign1.Tests/CoseSign1.Tests.csproj @@ -21,7 +21,8 @@ - + + diff --git a/CoseSignTool.Tests/CoseSignTool.Tests.csproj b/CoseSignTool.Tests/CoseSignTool.Tests.csproj index 6145a700..ef9d026b 100644 --- a/CoseSignTool.Tests/CoseSignTool.Tests.csproj +++ b/CoseSignTool.Tests/CoseSignTool.Tests.csproj @@ -27,8 +27,9 @@ - - + + + From 8394816b8bc72d4dba4e4a7d6cdc9ba1fe092b86 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 8 Jul 2025 22:16:54 +0200 Subject: [PATCH 5/6] Cleanup Signed-off-by: Youssef Victor --- Directory.Build.props | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index ae19387b..c54f4691 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,10 +1,8 @@  true - true - true true true true - \ No newline at end of file + From 39f71eafa3cdca36fd1e4d0ad5071129e87aa1cb Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 9 Jul 2025 03:21:41 +0200 Subject: [PATCH 6/6] Delete commented out code Signed-off-by: Youssef Victor --- CoseHandler.Tests/CoseSignValidateTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/CoseHandler.Tests/CoseSignValidateTests.cs b/CoseHandler.Tests/CoseSignValidateTests.cs index a8d25b9f..ae377dc8 100644 --- a/CoseHandler.Tests/CoseSignValidateTests.cs +++ b/CoseHandler.Tests/CoseSignValidateTests.cs @@ -11,12 +11,9 @@ public class CoseHandlerSignValidateTests // Certificates and chains as objects private static readonly X509Certificate2 SelfSignedCert = TestCertificateUtils.CreateCertificate(nameof(CoseHandlerSignValidateTests) + " self signed"); // A self-signed cert private static readonly X509Certificate2Collection CertChain1 = TestCertificateUtils.CreateTestChain(nameof(CoseHandlerSignValidateTests) + " set 1"); // Two complete cert chains - // private static readonly X509Certificate2Collection CertChain2 = TestCertificateUtils.CreateTestChain(nameof(CoseHandlerSignValidateTests) + " set 2"); private static readonly X509Certificate2 Root1Priv = CertChain1[0]; // Roots from the chains - // private static readonly X509Certificate2 Root2Priv = CertChain2[0]; private static readonly X509Certificate2 Int1Priv = CertChain1[1]; private static readonly X509Certificate2 Leaf1Priv = CertChain1[^1]; // Leaf node certs - // private static readonly X509Certificate2 Leaf2Priv = CertChain2[^1]; // As byte arrays private static readonly byte[] Root1Cer = Root1Priv.Export(X509ContentType.Cert);