Beispiel #1
0
        internal static unsafe int GetSignerIndex(SafeCryptMsgHandle safeCrytpMsgHandle, SignerInfo signerInfo, int startIndex)
        {
            uint num1 = 0U;
            uint num2 = (uint)Marshal.SizeOf(typeof(uint));

            if (!CAPI.CAPISafe.CryptMsgGetParam(safeCrytpMsgHandle, 5U, 0U, new IntPtr((void *)&num1), new IntPtr((void *)&num2)))
            {
                PkcsUtils.checkErr(Marshal.GetLastWin32Error());
            }
            for (int index = startIndex; index < (int)num1; ++index)
            {
                uint num3 = 0U;
                if (!CAPI.CAPISafe.CryptMsgGetParam(safeCrytpMsgHandle, 6U, (uint)index, IntPtr.Zero, new IntPtr((void *)&num3)))
                {
                    PkcsUtils.checkErr(Marshal.GetLastWin32Error());
                }
                if (num3 > 0U)
                {
                    SafeLocalAllocHandle pvData = CAPI.LocalAlloc(0U, new IntPtr((long)num3));
                    if (!CAPI.CAPISafe.CryptMsgGetParam(safeCrytpMsgHandle, 6U, (uint)index, pvData, new IntPtr((void *)&num3)))
                    {
                        PkcsUtils.checkErr(Marshal.GetLastWin32Error());
                    }
                    CAPI.CMSG_SIGNER_INFO cmsgSignerInfo1 = signerInfo.GetCmsgSignerInfo();
                    CAPI.CMSG_SIGNER_INFO cmsgSignerInfo2 = (CAPI.CMSG_SIGNER_INFO)Marshal.PtrToStructure(pvData.DangerousGetHandle(), typeof(CAPI.CMSG_SIGNER_INFO));
                    if (X509Utils.MemEqual((byte *)(void *)cmsgSignerInfo1.Issuer.pbData, cmsgSignerInfo1.Issuer.cbData, (byte *)(void *)cmsgSignerInfo2.Issuer.pbData, cmsgSignerInfo2.Issuer.cbData) && X509Utils.MemEqual((byte *)(void *)cmsgSignerInfo1.SerialNumber.pbData, cmsgSignerInfo1.SerialNumber.cbData, (byte *)(void *)cmsgSignerInfo2.SerialNumber.pbData, cmsgSignerInfo2.SerialNumber.cbData))
                    {
                        return(index);
                    }
                    pvData.Dispose();
                }
            }
            throw new CryptographicException(-2146889714);
        }
Beispiel #2
0
        internal static unsafe X509Certificate2Collection GetCertificates(SafeCryptMsgHandle safeCryptMsgHandle)
        {
            uint num1 = 0U;
            uint num2 = (uint)Marshal.SizeOf(typeof(uint));
            X509Certificate2Collection certificate2Collection = new X509Certificate2Collection();

            if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 11U, 0U, new IntPtr((void *)&num1), new IntPtr((void *)&num2)))
            {
                PkcsUtils.checkErr(Marshal.GetLastWin32Error());
            }
            for (uint index = 0U; index < num1; ++index)
            {
                uint cbData = 0U;
                SafeLocalAllocHandle pvData = SafeLocalAllocHandle.InvalidHandle;
                PkcsUtils.GetParam(safeCryptMsgHandle, 12U, index, out pvData, out cbData);
                if (cbData > 0U)
                {
                    System.Security.Cryptography.SafeCertContextHandle certificateContext = CAPI.CAPISafe.CertCreateCertificateContext(65537U, pvData, cbData);
                    if (certificateContext == null || certificateContext.IsInvalid)
                    {
                        throw new CryptographicException(Marshal.GetLastWin32Error());
                    }
                    certificate2Collection.Add(new X509Certificate2(certificateContext.DangerousGetHandle()));
                    certificateContext.Dispose();
                }
            }
            return(certificate2Collection);
        }
Beispiel #3
0
        internal static unsafe uint GetVersion(SafeCryptMsgHandle safeCryptMsgHandle)
        {
            uint num1 = 0U;
            uint num2 = (uint)Marshal.SizeOf(typeof(uint));

            if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 30U, 0U, new IntPtr((void *)&num1), new IntPtr((void *)&num2)))
            {
                PkcsUtils.checkErr(Marshal.GetLastWin32Error());
            }
            return(num1);
        }
Beispiel #4
0
 internal static unsafe void GetParam(SafeCryptMsgHandle safeCryptMsgHandle, uint paramType, uint index, out SafeLocalAllocHandle pvData, out uint cbData)
 {
     cbData = 0U;
     pvData = SafeLocalAllocHandle.InvalidHandle;
     fixed(uint *numPtr = &cbData)
     {
         if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, paramType, index, pvData, new IntPtr((void *)numPtr)))
         {
             PkcsUtils.checkErr(Marshal.GetLastWin32Error());
         }
         if (cbData > 0U)
         {
             pvData = CAPI.LocalAlloc(64U, new IntPtr((long)cbData));
             if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, paramType, index, pvData, new IntPtr((void *)numPtr)))
             {
                 PkcsUtils.checkErr(Marshal.GetLastWin32Error());
             }
         }
     }
 }
Beispiel #5
0
        internal static unsafe AlgorithmIdentifier GetAlgorithmIdentifier(SafeCryptMsgHandle safeCryptMsgHandle)
        {
            AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier();
            uint num = 0U;

            if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 15U, 0U, IntPtr.Zero, new IntPtr((void *)&num)))
            {
                PkcsUtils.checkErr(Marshal.GetLastWin32Error());
            }
            if (num > 0U)
            {
                SafeLocalAllocHandle pvData = CAPI.LocalAlloc(0U, new IntPtr((long)num));
                if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 15U, 0U, pvData, new IntPtr((void *)&num)))
                {
                    PkcsUtils.checkErr(Marshal.GetLastWin32Error());
                }
                algorithmIdentifier = new AlgorithmIdentifier((CAPI.CRYPT_ALGORITHM_IDENTIFIER)Marshal.PtrToStructure(pvData.DangerousGetHandle(), typeof(CAPI.CRYPT_ALGORITHM_IDENTIFIER)));
                pvData.Dispose();
            }
            return(algorithmIdentifier);
        }
Beispiel #6
0
 internal static unsafe void GetParam(SafeCryptMsgHandle safeCryptMsgHandle, uint paramType, uint index, out byte[] pvData, out uint cbData)
 {
     cbData = 0U;
     pvData = new byte[0];
     fixed(uint *numPtr1 = &cbData)
     {
         if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, paramType, index, IntPtr.Zero, new IntPtr((void *)numPtr1)))
         {
             PkcsUtils.checkErr(Marshal.GetLastWin32Error());
         }
         if (cbData > 0U)
         {
             pvData = new byte[(IntPtr)cbData];
             fixed(byte *numPtr2 = &pvData[0])
             {
                 if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, paramType, index, new IntPtr((void *)numPtr2), new IntPtr((void *)numPtr1)))
                 {
                     PkcsUtils.checkErr(Marshal.GetLastWin32Error());
                 }
             }
         }
     }
 }
Beispiel #7
0
        internal static unsafe CryptographicAttributeObjectCollection GetUnprotectedAttributes(SafeCryptMsgHandle safeCryptMsgHandle)
        {
            uint num = 0U;
            CryptographicAttributeObjectCollection objectCollection = new CryptographicAttributeObjectCollection();
            SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;

            if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 37U, 0U, invalidHandle, new IntPtr((void *)&num)) && Marshal.GetLastWin32Error() != -2146889713)
            {
                PkcsUtils.checkErr(Marshal.GetLastWin32Error());
            }
            if (num > 0U)
            {
                SafeLocalAllocHandle localAllocHandle;
                using (localAllocHandle = CAPI.LocalAlloc(64U, new IntPtr((long)num)))
                {
                    if (!CAPI.CAPISafe.CryptMsgGetParam(safeCryptMsgHandle, 37U, 0U, localAllocHandle, new IntPtr((void *)&num)))
                    {
                        PkcsUtils.checkErr(Marshal.GetLastWin32Error());
                    }
                    objectCollection = new CryptographicAttributeObjectCollection(localAllocHandle);
                }
            }
            return(objectCollection);
        }