internal unsafe X509ChainElement(IntPtr pChainElement) { CAPI.CERT_CHAIN_ELEMENT chainElement = new CAPI.CERT_CHAIN_ELEMENT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_ELEMENT))); uint cbSize = (uint)Marshal.ReadInt32(pChainElement); if (cbSize > Marshal.SizeOf(chainElement)) { cbSize = (uint)Marshal.SizeOf(chainElement); } X509Utils.memcpy(pChainElement, new IntPtr(&chainElement), cbSize); m_certificate = new X509Certificate2(chainElement.pCertContext); if (chainElement.pwszExtendedErrorInfo == IntPtr.Zero) { m_description = String.Empty; } else { m_description = Marshal.PtrToStringUni(chainElement.pwszExtendedErrorInfo); } // We give the user a reference to the array since we'll never access it. if (chainElement.dwErrorStatus == 0) { m_chainStatus = new X509ChainStatus[0]; // empty array } else { m_chainStatus = X509Chain.GetChainStatusInformation(chainElement.dwErrorStatus); } }
internal unsafe X509ChainElementCollection(IntPtr pSimpleChain) { CAPI.CERT_SIMPLE_CHAIN simpleChain = new CAPI.CERT_SIMPLE_CHAIN(Marshal.SizeOf(typeof(CAPI.CERT_SIMPLE_CHAIN))); uint cbSize = (uint)Marshal.ReadInt32(pSimpleChain); if (cbSize > Marshal.SizeOf(simpleChain)) { cbSize = (uint)Marshal.SizeOf(simpleChain); } X509Utils.memcpy(pSimpleChain, new IntPtr(&simpleChain), cbSize); m_elements = new X509ChainElement[simpleChain.cElement]; for (int index = 0; index < m_elements.Length; index++) { m_elements[index] = new X509ChainElement(Marshal.ReadIntPtr(new IntPtr((long)simpleChain.rgpElement + index * Marshal.SizeOf(typeof(IntPtr))))); } }
private unsafe void Init() { using (SafeCertChainHandle safeCertChainHandle = CAPI.CertDuplicateCertificateChain(m_safeCertChainHandle)) { CAPI.CERT_CHAIN_CONTEXT pChain = new CAPI.CERT_CHAIN_CONTEXT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_CONTEXT))); uint cbSize = (uint)Marshal.ReadInt32(safeCertChainHandle.DangerousGetHandle()); if (cbSize > Marshal.SizeOf(pChain)) { cbSize = (uint)Marshal.SizeOf(pChain); } X509Utils.memcpy(m_safeCertChainHandle.DangerousGetHandle(), new IntPtr(&pChain), cbSize); m_status = pChain.dwErrorStatus; Debug.Assert(pChain.cChain > 0); m_chainElementCollection = new X509ChainElementCollection(Marshal.ReadIntPtr(pChain.rgpChain)); } }