Exemple #1
0
        void decodeUnauthAttr(Wincrypt.CRYPT_ATTRIBUTES unauthAttrs)
        {
            if (unauthAttrs.cAttr == 0)
            {
                return;
            }
            IntPtr rgValue = unauthAttrs.rgAttr;
            Int32  size    = Marshal.SizeOf(typeof(Wincrypt.CRYPT_ATTRIBUTE));

            UnauthenticatedAttributes = new X509AttributeCollection();
            for (Int32 index = 0; index < unauthAttrs.cAttr; index++)
            {
                Wincrypt.CRYPT_ATTRIBUTE attr = (Wincrypt.CRYPT_ATTRIBUTE)Marshal.PtrToStructure(rgValue, typeof(Wincrypt.CRYPT_ATTRIBUTE));
                UnauthenticatedAttributes.Add(new X509Attribute(attr));
                rgValue += size;
            }
        }
        void decode(Byte[] rawData)
        {
            var asn = new Asn1Reader(rawData);

            asn.MoveNextAndExpectTags((Byte)Asn1Type.OCTET_STRING);
            Thumbprint = AsnFormatter.BinaryToString(asn.GetPayload(), format: EncodingFormat.NOCRLF, forceUpperCase: true);
            // check if there are attributes
            if (asn.MoveNext() && asn.Tag == 49)
            {
                Byte[] attrBytes = asn.GetTagRawData();
                // in CTL attributes are encoded as SET, but we need SEQUENCE, so change first byte to SEQUENCE (48)
                attrBytes[0] = 48;
                var attributes = new X509AttributeCollection();
                // decode attributes into collection
                attributes.Decode(attrBytes);
                // and then add decoded attributes to internal list.
                _attributes.AddRange(attributes);
            }
        }
Exemple #3
0
        void get_ctlentries()
        {
            if (CTLInfo.cCTLEntry > 0)
            {
                Entries = new X509CTLEntryCollection();
                IntPtr rgCTLEntry = CTLInfo.rgCTLEntry;
                for (Int32 index = 0; index < CTLInfo.cCTLEntry; index++)
                {
                    StringBuilder           SB         = new StringBuilder();
                    X509AttributeCollection attributes = new X509AttributeCollection();

                    Wincrypt.CTL_ENTRY CTLEntry = (Wincrypt.CTL_ENTRY)Marshal.PtrToStructure(rgCTLEntry, typeof(Wincrypt.CTL_ENTRY));
                    byte[]             bytes    = new Byte[CTLEntry.SubjectIdentifier.cbData];
                    Marshal.Copy(CTLEntry.SubjectIdentifier.pbData, bytes, 0, bytes.Length);
                    foreach (Byte item in bytes)
                    {
                        SB.Append($"{item:X2}");
                    }
                    String thumbprint = SB.ToString();
                    if (CTLEntry.cAttribute > 0)
                    {
                        IntPtr rgAttribute = CTLEntry.rgAttribute;
                        for (Int32 indexx = 0; indexx < CTLEntry.cAttribute; indexx++)
                        {
                            Wincrypt.CRYPT_ATTRIBUTE attrib = (Wincrypt.CRYPT_ATTRIBUTE)Marshal.PtrToStructure(rgAttribute, typeof(Wincrypt.CRYPT_ATTRIBUTE));
                            Oid pszOid = new Oid(attrib.pszObjId);
                            Wincrypt.CRYPTOAPI_BLOB blob = (Wincrypt.CRYPTOAPI_BLOB)Marshal.PtrToStructure(attrib.rgValue, typeof(Wincrypt.CRYPTOAPI_BLOB));
                            bytes = new Byte[blob.cbData];
                            Marshal.Copy(blob.pbData, bytes, 0, bytes.Length);
                            attributes.Add(new X509Attribute(pszOid, bytes));
                            rgAttribute = (IntPtr)((UInt64)rgAttribute + (UInt32)Marshal.SizeOf(typeof(Wincrypt.CRYPT_ATTRIBUTE)));
                        }
                    }
                    Entries.Add(new X509CTLEntry(thumbprint, attributes));
                    rgCTLEntry = (IntPtr)((UInt64)rgCTLEntry + (UInt32)Marshal.SizeOf(typeof(Wincrypt.CTL_ENTRY)));
                }
            }
        }
 internal X509CTLEntry(String thumbprint, X509AttributeCollection attributes)
 {
     m_initialize(thumbprint, attributes);
 }
 void m_initialize(String thumprint, X509AttributeCollection attributes)
 {
     Thumbprint = thumprint;
     Attributes = attributes;
     get_cert();
 }