예제 #1
0
        // Token: 0x0600033F RID: 831 RVA: 0x0000CC2C File Offset: 0x0000AE2C
        private static bool CheckIfValveSigned(string filePath)
        {
            bool result;

            try
            {
                IntPtr zero  = IntPtr.Zero;
                IntPtr zero2 = IntPtr.Zero;
                IntPtr zero3 = IntPtr.Zero;
                int    num;
                int    num2;
                int    num3;
                if (!WinCrypt.CryptQueryObject(1, Marshal.StringToHGlobalUni(filePath), 16382, 14, 0, out num, out num2, out num3, ref zero, ref zero2, ref zero3))
                {
                    result = false;
                }
                else
                {
                    result = (num2 == 10);
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }
        private static X509Certificate2 GetDigitalCertificate(string filePath)
        {
            X509Certificate2 cert = null;

            int    encodingType;
            int    contentType;
            int    formatType;
            IntPtr certStore = IntPtr.Zero;
            IntPtr cryptMsg  = IntPtr.Zero;
            IntPtr context   = IntPtr.Zero;

            if (!WinCrypt.CryptQueryObject(
                    WinCrypt.CERT_QUERY_OBJECT_FILE,
                    Marshal.StringToHGlobalUni(filePath),
                    (WinCrypt.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED
                     | WinCrypt.CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED
                     | WinCrypt.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED),
                    WinCrypt.CERT_QUERY_FORMAT_FLAG_ALL,
                    0,
                    out encodingType,
                    out contentType,
                    out formatType,
                    ref certStore,
                    ref cryptMsg,
                    ref context))
            {
                Console.WriteLine("Can't read cert at all.");
                throw new InvalidOperationException($"{Marshal.GetLastWin32Error()} - Sigs ain't working.");
            }

            // Get size of the encoded message.
            int cbData = 0;

            if (!WinCrypt.CryptMsgGetParam(
                    cryptMsg,
                    WinCrypt.CMSG_ENCODED_MESSAGE,
                    0,
                    IntPtr.Zero,
                    ref cbData))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var vData = new byte[cbData];

            // Get the encoded message.
            if (!WinCrypt.CryptMsgGetParam(
                    cryptMsg,
                    WinCrypt.CMSG_ENCODED_MESSAGE,
                    0,
                    vData,
                    ref cbData))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var signedCms = new SignedCms();

            signedCms.Decode(vData);

            if (signedCms.SignerInfos.Count > 0)
            {
                var signerInfo = signedCms.SignerInfos[0];

                if (signerInfo.Certificate != null)
                {
                    cert = signerInfo.Certificate;
                }
            }

            return(cert);
        }