WTHelperGetProvSignerFromChain() private méthode

private WTHelperGetProvSignerFromChain ( IntPtr pProvData, uint idxSigner, [ fCounterSigner, uint idxCounterSigner ) : IntPtr
pProvData System.IntPtr
idxSigner uint
fCounterSigner [
idxCounterSigner uint
Résultat System.IntPtr
Exemple #1
0
        private CryptoError GetCertInfo(IntPtr hWVTStateData, out Native.CERT_INFO certInfo, out string failedApiName)
        {
            certInfo = new Native.CERT_INFO();

            failedApiName = "WTHelperProvDataFromStateData";
            IntPtr providerData = Native.WTHelperProvDataFromStateData(hWVTStateData);

            if (providerData == IntPtr.Zero)
            {
                return((CryptoError)Marshal.GetLastWin32Error());
            }

            failedApiName = "WTHelperGetProvSignerFromChain";
            IntPtr providerSigner = Native.WTHelperGetProvSignerFromChain(providerData, 0, false, 0);

            if (providerSigner == IntPtr.Zero)
            {
                return((CryptoError)Marshal.GetLastWin32Error());
            }

            var cryptProviderSigner = (Native.CRYPT_PROVIDER_SGNR)Marshal.PtrToStructure(providerSigner, typeof(Native.CRYPT_PROVIDER_SGNR));

            var cryptoError = (CryptoError)cryptProviderSigner.dwError;

            if (cryptProviderSigner.pChainContext != IntPtr.Zero)
            {
                var chainContext = (Native.CERT_CHAIN_CONTEXT)Marshal.PtrToStructure(cryptProviderSigner.pChainContext, typeof(Native.CERT_CHAIN_CONTEXT));

                IntPtr[] simpleChains = new IntPtr[chainContext.cChain];
                Marshal.Copy(chainContext.rgpChain, simpleChains, 0, simpleChains.Length);
                var certChain = (Native.CERT_SIMPLE_CHAIN)Marshal.PtrToStructure(simpleChains[0], typeof(Native.CERT_SIMPLE_CHAIN));

                IntPtr[] chainElements = new IntPtr[certChain.cElement];
                Marshal.Copy(certChain.rgpElement, chainElements, 0, chainElements.Length);
                var certElement = (Native.CERT_CHAIN_ELEMENT)Marshal.PtrToStructure(chainElements[0], typeof(Native.CERT_CHAIN_ELEMENT));

                var certContext = (Native.CERT_CONTEXT)Marshal.PtrToStructure(certElement.pCertContext, typeof(Native.CERT_CONTEXT));
                certInfo = (Native.CERT_INFO)Marshal.PtrToStructure(certContext.pCertInfo, typeof(Native.CERT_INFO));
            }

            if (cryptoError == CryptoError.ERROR_SUCCESS)
            {
                failedApiName = null;
            }

            return(cryptoError);
        }
Exemple #2
0
        private CryptoError GetSignerHashAlgorithms(IntPtr hWVTStateData, out string hashAlgorithm, out string hashEncryptionAlgorithm, out string failedApiName)
        {
            hashAlgorithm = hashEncryptionAlgorithm = null;

            failedApiName = "WTHelperProvDataFromStateData";
            IntPtr providerData = Native.WTHelperProvDataFromStateData(hWVTStateData);

            if (providerData == IntPtr.Zero)
            {
                return((CryptoError)Marshal.GetLastWin32Error());
            }

            failedApiName = "WTHelperGetProvSignerFromChain";
            IntPtr providerSigner = Native.WTHelperGetProvSignerFromChain(providerData, 0, false, 0);

            if (providerSigner == IntPtr.Zero)
            {
                return((CryptoError)Marshal.GetLastWin32Error());
            }

            var cryptProviderSigner = (Native.CRYPT_PROVIDER_SGNR)Marshal.PtrToStructure(providerSigner, typeof(Native.CRYPT_PROVIDER_SGNR));

            var cryptoError = (CryptoError)cryptProviderSigner.dwError;

            if (cryptProviderSigner.psSigner != IntPtr.Zero)
            {
                var psSigner = (Native.CMSG_SIGNER_INFO)Marshal.PtrToStructure(cryptProviderSigner.psSigner, typeof(Native.CMSG_SIGNER_INFO));
                hashAlgorithm           = GetAlgorithmName(psSigner.HashAlgorithm.pszObjId);
                hashEncryptionAlgorithm = GetAlgorithmName(psSigner.HashEncryptionAlgorithm.pszObjId);
            }

            if (cryptoError == CryptoError.ERROR_SUCCESS)
            {
                failedApiName = null;
            }

            return(cryptoError);
        }