void m_initialize2(Wincrypt.CRYPT_ATTRIBUTE blob) { Oid = new Oid(blob.pszObjId); Wincrypt.CRYPTOAPI_BLOB attrStruct = (Wincrypt.CRYPTOAPI_BLOB)Marshal.PtrToStructure(blob.rgValue, typeof(Wincrypt.CRYPTOAPI_BLOB)); RawData = new Byte[attrStruct.cbData]; Marshal.Copy(attrStruct.pbData, RawData, 0, RawData.Length); }
void getAttributes() { if (reqData.cAttribute <= 0) { return; } IntPtr rgAttribute = reqData.rgAttribute; for (Int32 index = 0; index < reqData.cAttribute; index++) { Wincrypt.CRYPT_ATTRIBUTE attrib = (Wincrypt.CRYPT_ATTRIBUTE)Marshal.PtrToStructure(rgAttribute, typeof(Wincrypt.CRYPT_ATTRIBUTE)); Oid attriboid = new Oid(attrib.pszObjId); Wincrypt.CRYPTOAPI_BLOB blob = (Wincrypt.CRYPTOAPI_BLOB)Marshal.PtrToStructure(attrib.rgValue, typeof(Wincrypt.CRYPTOAPI_BLOB)); Byte[] bytes = new Byte[blob.cbData]; Marshal.Copy(blob.pbData, bytes, 0, (Int32)blob.cbData); if (attrib.pszObjId == "1.2.840.113549.1.9.14") { getExtensions(bytes); } else { _attribs.Add(new X509Attribute(attriboid, bytes)); } rgAttribute = (IntPtr)((UInt64)rgAttribute + (UInt32)Marshal.SizeOf(typeof(Wincrypt.CRYPT_ATTRIBUTE))); } }
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; } }
static Wincrypt.CRYPT_ATTRIBUTE create_attribute(IntPtr handle, UInt32 propId) { UInt32 pcbData = 0; Wincrypt.CRYPT_ATTRIBUTE attrib = new Wincrypt.CRYPT_ATTRIBUTE(); if (Crypt32.CertGetCertificateContextProperty(handle, propId, IntPtr.Zero, ref pcbData)) { attrib.rgValue = Marshal.AllocHGlobal((Int32)pcbData); attrib.pszObjId = "1.3.6.1.4.1.311.10.11." + propId; attrib.cValue = pcbData; Crypt32.CertGetCertificateContextProperty(handle, propId, attrib.rgValue, ref pcbData); } else { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(attrib); }
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 X509Attribute(Wincrypt.CRYPT_ATTRIBUTE blob) { m_initialize2(blob); }