Пример #1
0
        public static void DefaultStateBehavior()
        {
            SignedCms cms = new SignedCms();

            Assert.Equal(0, cms.Version);
            Assert.False(cms.Detached, "cms.Detached");

            X509Certificate2Collection certificates = cms.Certificates;
            X509Certificate2Collection certificates2 = cms.Certificates;

            Assert.NotSame(certificates, certificates2);
            Assert.Equal(0, certificates.Count);
            Assert.Equal(0, certificates2.Count);

            ContentInfo content = cms.ContentInfo;
            ContentInfo content2 = cms.ContentInfo;
            Assert.Same(content, content2);

            Assert.Equal("1.2.840.113549.1.7.1", content.ContentType.Value);
            Assert.Equal(Array.Empty<byte>(), content.Content);

            SignerInfoCollection signers = cms.SignerInfos;
            SignerInfoCollection signers2 = cms.SignerInfos;

            Assert.NotSame(signers, signers2);
            Assert.Equal(0, signers.Count);
            Assert.Equal(0, signers2.Count);

            Assert.Throws<InvalidOperationException>(() => cms.CheckSignature(true));
            Assert.Throws<InvalidOperationException>(() => cms.CheckHash());
            Assert.Throws<InvalidOperationException>(() => cms.RemoveSignature(0));
            Assert.Throws<InvalidOperationException>(() => cms.RemoveSignature(-1));
            Assert.Throws<InvalidOperationException>(() => cms.RemoveSignature(10000));
            Assert.Throws<InvalidOperationException>(() => cms.Encode());
        }
Пример #2
0
        public static void CheckSignatures_AllRemoved()
        {
            SignedCms cms = new SignedCms();
            cms.Decode(SignedDocuments.RsaPkcs1OneSignerIssuerAndSerialNumber);
            Assert.Single(cms.SignerInfos);

            cms.RemoveSignature(0);
            Assert.Empty(cms.SignerInfos);

            Assert.Throws<CryptographicException>(() => cms.CheckSignature(true));
        }
Пример #3
0
        public static void RemoveSignature_WithNoMatch()
        {
            SignedCms cms = new SignedCms();
            cms.Decode(SignedDocuments.RsaPkcs1OneSignerIssuerAndSerialNumber);
            SignerInfo wrongSignerInfo = cms.SignerInfos[0];
            cms.Decode(SignedDocuments.RsaPssDocument);
            Assert.Single(cms.SignerInfos);

            Assert.Throws<CryptographicException>(() => cms.RemoveSignature(wrongSignerInfo));
            Assert.Single(cms.SignerInfos);
            Assert.Single(cms.Certificates);
        }
Пример #4
0
        public static void RemoveSignature_Null()
        {
            SignedCms cms = new SignedCms();
            cms.Decode(SignedDocuments.RsaPkcs1OneSignerIssuerAndSerialNumber);

            AssertExtensions.Throws<ArgumentNullException>(
                "signerInfo",
                () => cms.RemoveSignature(null));

            Assert.Single(cms.SignerInfos);
            Assert.Single(cms.Certificates);
        }
Пример #5
0
        public static void RemoveSignature_MatchesNoSignature()
        {
            SignedCms cms = new SignedCms();
            cms.Decode(SignedDocuments.NoSignatureSignedWithAttributesAndCounterSignature);
            Assert.Single(cms.SignerInfos);

            SignerInfo signerInfo = cms.SignerInfos[0];
            Assert.Equal(SubjectIdentifierType.NoSignature, signerInfo.SignerIdentifier.Type);

            cms.RemoveSignature(signerInfo);
            Assert.Empty(cms.SignerInfos);
        }
Пример #6
0
        public static void RemoveCounterSignature_ByIndex_OnRemovedSigner()
        {
            SignedCms cms = new SignedCms();

            cms.Decode(SignedDocuments.OneRsaSignerTwoRsaCounterSigners);
            SignerInfo signer = cms.SignerInfos[0];

            cms.RemoveSignature(signer);
            Assert.NotEmpty(signer.CounterSignerInfos);

            Assert.Throws <CryptographicException>(
                () => signer.RemoveCounterSignature(0));
        }
Пример #7
0
        public static void RemoveSignature_OutOfRange()
        {
            SignedCms cms = new SignedCms();
            cms.Decode(SignedDocuments.RsaPkcs1OneSignerIssuerAndSerialNumber);

            ArgumentOutOfRangeException ex = AssertExtensions.Throws<ArgumentOutOfRangeException>(
                "index",
                () => cms.RemoveSignature(-1));

            Assert.Equal(null, ex.ActualValue);
            Assert.Single(cms.SignerInfos);
            Assert.Single(cms.Certificates);

            ex = AssertExtensions.Throws<ArgumentOutOfRangeException>(
                "index",
                () => cms.RemoveSignature(1));

            Assert.Equal(null, ex.ActualValue);

            Assert.Single(cms.SignerInfos);
            Assert.Single(cms.Certificates);
        }
Пример #8
0
        public static void RemoveSignature_MatchesSubjectKeyIdentifier()
        {
            SignedCms cms = new SignedCms();
            cms.Decode(SignedDocuments.RsaPssDocument);
            Assert.Single(cms.SignerInfos);

            SignerInfo signerInfo = cms.SignerInfos[0];
            Assert.Equal(SubjectIdentifierType.SubjectKeyIdentifier, signerInfo.SignerIdentifier.Type);

            int certCount = cms.Certificates.Count;
            cms.RemoveSignature(signerInfo);
            Assert.Empty(cms.SignerInfos);
            Assert.Equal(certCount, cms.Certificates.Count);
        }
        public static void SignerInfo_AddRemoveUnsignedAttributeWithDetachtedSigner_Throws()
        {
            SignedCms cms = new SignedCms();

            cms.Decode(SignedDocuments.OneRsaSignerTwoRsaCounterSigners);

            // Detatch signer (and its counter signers)
            SignerInfo counterSigner = cms.SignerInfos[0].CounterSignerInfos[0];

            cms.RemoveSignature(0);

            // we shouldn't throw
            Assert.Equal(0, counterSigner.UnsignedAttributes.Count);

            AsnEncodedData attribute = CreateTimestampToken(1);

            Assert.Throws <CryptographicException>(() => counterSigner.AddUnsignedAttribute(attribute));
            Assert.Throws <CryptographicException>(() => counterSigner.RemoveUnsignedAttribute(attribute));
        }
Пример #10
0
 /// <inheritdoc cref="SignedCms.RemoveSignature(int)"/>
 public void RemoveSignature(int index)
 {
     _signedCms.RemoveSignature(index);
 }