Exemple #1
0
        private void Count(int count)
        {
            Assert.AreEqual(count, coll.Count, "Count");
            int i = 0;

            foreach (CryptographicAttributeObject cao in coll)
            {
                i++;
            }
            Assert.AreEqual(count, i, "foreach");

            i = 0;
            CryptographicAttributeObjectEnumerator e = coll.GetEnumerator();

            while (e.MoveNext())
            {
                if (e.Current is CryptographicAttributeObject)
                {
                    i++;
                }
            }
            Assert.AreEqual(count, i, "GetEnumerator");

            i = 0;
            e.Reset();
            while (e.MoveNext())
            {
                if (e.Current is CryptographicAttributeObject)
                {
                    i++;
                }
            }
            Assert.AreEqual(count, i, "Reset");
        }
        internal SignerInfoCollection(SignedCms signedCms, SignerInfo signerInfo)
        {
            SignerInfo[] infoArray = new SignerInfo[0];
            int          num       = 0;
            int          num2      = 0;
            CryptographicAttributeObjectEnumerator enumerator = signerInfo.UnsignedAttributes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CryptographicAttributeObject current = enumerator.Current;
                if (current.Oid.Value == "1.2.840.113549.1.9.6")
                {
                    num += current.Values.Count;
                }
            }
            infoArray = new SignerInfo[num];
            CryptographicAttributeObjectEnumerator enumerator2 = signerInfo.UnsignedAttributes.GetEnumerator();

            while (enumerator2.MoveNext())
            {
                CryptographicAttributeObject obj3 = enumerator2.Current;
                if (obj3.Oid.Value == "1.2.840.113549.1.9.6")
                {
                    for (int i = 0; i < obj3.Values.Count; i++)
                    {
                        AsnEncodedData data = obj3.Values[i];
                        infoArray[num2++] = new SignerInfo(signedCms, signerInfo, data.RawData);
                    }
                }
            }
            this.m_signerInfos = infoArray;
        }
        internal static unsafe IntPtr CreateCryptAttributes(CryptographicAttributeObjectCollection attributes)
        {
            if (attributes.Count == 0)
            {
                return(IntPtr.Zero);
            }
            uint num  = 0;
            uint num2 = AlignedLength((uint)Marshal.SizeOf(typeof(I_CRYPT_ATTRIBUTE)));
            uint num3 = AlignedLength((uint)Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB)));
            CryptographicAttributeObjectEnumerator enumerator = attributes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CryptographicAttributeObject current = enumerator.Current;
                num += num2;
                num += AlignedLength((uint)(current.Oid.Value.Length + 1));
                AsnEncodedDataEnumerator enumerator2 = current.Values.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    AsnEncodedData data = enumerator2.Current;
                    num += num3;
                    num += AlignedLength((uint)data.RawData.Length);
                }
            }
            System.Security.Cryptography.SafeLocalAllocHandle handle = System.Security.Cryptography.CAPI.LocalAlloc(0x40, new IntPtr((long)num));
            I_CRYPT_ATTRIBUTE *i_crypt_attributePtr = (I_CRYPT_ATTRIBUTE *)handle.DangerousGetHandle();
            IntPtr             ptr = new IntPtr(((long)handle.DangerousGetHandle()) + (num2 * attributes.Count));
            CryptographicAttributeObjectEnumerator enumerator3 = attributes.GetEnumerator();

            while (enumerator3.MoveNext())
            {
                CryptographicAttributeObject obj3 = enumerator3.Current;
                byte * numPtr = (byte *)ptr;
                byte[] bytes  = new byte[obj3.Oid.Value.Length + 1];
                System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB *cryptoapi_blobPtr = (System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB *)(numPtr + AlignedLength((uint)bytes.Length));
                i_crypt_attributePtr->pszObjId = (IntPtr)numPtr;
                i_crypt_attributePtr->cValue   = (uint)obj3.Values.Count;
                i_crypt_attributePtr->rgValue  = (IntPtr)cryptoapi_blobPtr;
                Encoding.ASCII.GetBytes(obj3.Oid.Value, 0, obj3.Oid.Value.Length, bytes, 0);
                Marshal.Copy(bytes, 0, i_crypt_attributePtr->pszObjId, bytes.Length);
                IntPtr destination = new IntPtr(((long)((ulong)cryptoapi_blobPtr)) + (obj3.Values.Count * num3));
                AsnEncodedDataEnumerator enumerator4 = obj3.Values.GetEnumerator();
                while (enumerator4.MoveNext())
                {
                    byte[] rawData = enumerator4.Current.RawData;
                    if (rawData.Length > 0)
                    {
                        cryptoapi_blobPtr->cbData = (uint)rawData.Length;
                        cryptoapi_blobPtr->pbData = destination;
                        Marshal.Copy(rawData, 0, destination, rawData.Length);
                        destination = new IntPtr(((long)destination) + AlignedLength((uint)rawData.Length));
                    }
                    cryptoapi_blobPtr++;
                }
                i_crypt_attributePtr++;
                ptr = destination;
            }
            GC.SuppressFinalize(handle);
            return(handle.DangerousGetHandle());
        }
Exemple #4
0
        public void RemoveCounterSignature(SignerInfo counterSignerInfo)
        {
            if (this.m_parentSignerInfo != null)
            {
                throw new CryptographicException(-2147483647);
            }
            if (counterSignerInfo == null)
            {
                throw new ArgumentNullException("counterSignerInfo");
            }
            CryptographicAttributeObjectEnumerator enumerator = this.UnsignedAttributes.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CryptographicAttributeObject current = enumerator.Current;
                if (string.Compare(current.Oid.Value, "1.2.840.113549.1.9.6", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    for (int i = 0; i < current.Values.Count; i++)
                    {
                        AsnEncodedData data = current.Values[i];
                        SignerInfo     info = new SignerInfo(this.m_signedCms, this.m_parentSignerInfo, data.RawData);
                        if ((counterSignerInfo.SignerIdentifier.Type == SubjectIdentifierType.IssuerAndSerialNumber) && (info.SignerIdentifier.Type == SubjectIdentifierType.IssuerAndSerialNumber))
                        {
                            X509IssuerSerial serial  = (X509IssuerSerial)counterSignerInfo.SignerIdentifier.Value;
                            X509IssuerSerial serial2 = (X509IssuerSerial)info.SignerIdentifier.Value;
                            if ((string.Compare(serial.IssuerName, serial2.IssuerName, StringComparison.OrdinalIgnoreCase) != 0) || (string.Compare(serial.SerialNumber, serial2.SerialNumber, StringComparison.OrdinalIgnoreCase) != 0))
                            {
                                continue;
                            }
                            this.RemoveCounterSignature(PkcsUtils.GetSignerIndex(this.m_signedCms.GetCryptMsgHandle(), this, 0), i);
                            return;
                        }
                        if ((counterSignerInfo.SignerIdentifier.Type == SubjectIdentifierType.SubjectKeyIdentifier) && (info.SignerIdentifier.Type == SubjectIdentifierType.SubjectKeyIdentifier))
                        {
                            string strA = counterSignerInfo.SignerIdentifier.Value as string;
                            string strB = info.SignerIdentifier.Value as string;
                            if (string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                this.RemoveCounterSignature(PkcsUtils.GetSignerIndex(this.m_signedCms.GetCryptMsgHandle(), this, 0), i);
                                return;
                            }
                        }
                    }
                }
            }
            throw new CryptographicException(-2146889714);
        }