From b90398d12fa57868910ab10566cd0f27cdd99aba Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 17 Sep 2017 17:37:25 +0700 Subject: Add testcase for RAW PKCS#1 signatures missing DER NULL --- crypto/crypto.csproj | 8 ++++++++ crypto/test/UnitTests.csproj | 2 ++ crypto/test/data/cms/sigs/SignedMSPkcs7.sig | Bin 0 -> 4927 bytes crypto/test/data/cms/sigs/rawsha256nonull.p7m | Bin 0 -> 1415 bytes crypto/test/src/cms/test/SignedDataTest.cs | 18 ++++++++++++++++++ 5 files changed, 28 insertions(+) create mode 100644 crypto/test/data/cms/sigs/SignedMSPkcs7.sig create mode 100644 crypto/test/data/cms/sigs/rawsha256nonull.p7m diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj index 2f16fa08b..e2ad3ea69 100644 --- a/crypto/crypto.csproj +++ b/crypto/crypto.csproj @@ -7596,6 +7596,14 @@ RelPath = "test\data\cms\sigs\PSSSignDataSHA512Enc.sig" BuildAction = "EmbeddedResource" /> + + + + diff --git a/crypto/test/data/cms/sigs/SignedMSPkcs7.sig b/crypto/test/data/cms/sigs/SignedMSPkcs7.sig new file mode 100644 index 000000000..df9a09b0d Binary files /dev/null and b/crypto/test/data/cms/sigs/SignedMSPkcs7.sig differ diff --git a/crypto/test/data/cms/sigs/rawsha256nonull.p7m b/crypto/test/data/cms/sigs/rawsha256nonull.p7m new file mode 100644 index 000000000..5d29760cb Binary files /dev/null and b/crypto/test/data/cms/sigs/rawsha256nonull.p7m differ diff --git a/crypto/test/src/cms/test/SignedDataTest.cs b/crypto/test/src/cms/test/SignedDataTest.cs index 89f7eea7d..29d0464c2 100644 --- a/crypto/test/src/cms/test/SignedDataTest.cs +++ b/crypto/test/src/cms/test/SignedDataTest.cs @@ -672,6 +672,24 @@ namespace Org.BouncyCastle.Cms.Tests VerifySignatures(s, hash); } + [Test] + public void TestRawSha256MissingNull() + { + byte[] document = GetInput("rawsha256nonull.p7m"); + + CmsSignedData s = new CmsSignedData(document); + + IX509Store certStore = s.GetCertificates("Collection"); + foreach (SignerInformation signerInformation in s.GetSignerInfos().GetSigners()) + { + ICollection certCollection = certStore.GetMatches(signerInformation.SignerID); + foreach (X509Certificate cert in certCollection) + { + Assert.IsTrue(signerInformation.Verify(cert), "raw sig failed"); + } + } + } + [Test] public void TestSha1WithRsaEncapsulated() { -- cgit 1.4.1