internal AuthenticodeSignatureInformation(X509Native.AXL_AUTHENTICODE_SIGNER_INFO signer, X509Chain signatureChain, TimestampInformation timestamp)
 {
     this.m_verificationResult = (SignatureVerificationResult)signer.dwError;
     this.m_hashAlgorithmId    = signer.algHash;
     if (signer.pwszDescription != IntPtr.Zero)
     {
         this.m_description = Marshal.PtrToStringUni(signer.pwszDescription);
     }
     if (signer.pwszDescriptionUrl != IntPtr.Zero)
     {
         Uri.TryCreate(Marshal.PtrToStringUni(signer.pwszDescriptionUrl), UriKind.RelativeOrAbsolute, out this.m_descriptionUrl);
     }
     this.m_signatureChain = signatureChain;
     if ((timestamp != null) && (timestamp.VerificationResult != SignatureVerificationResult.MissingSignature))
     {
         if (timestamp.IsValid)
         {
             this.m_timestamp = timestamp;
         }
         else
         {
             this.m_verificationResult = SignatureVerificationResult.InvalidTimestamp;
         }
     }
     else
     {
         this.m_timestamp = null;
     }
 }
        internal AuthenticodeSignatureInformation(X509Native.AXL_AUTHENTICODE_SIGNER_INFO signer,
                                                  X509Chain signatureChain,
                                                  TimestampInformation timestamp) {
            m_verificationResult = (SignatureVerificationResult)signer.dwError;
            m_hashAlgorithmId = signer.algHash;

            if (signer.pwszDescription != IntPtr.Zero) {
                m_description = Marshal.PtrToStringUni(signer.pwszDescription);
            }
            if (signer.pwszDescriptionUrl != IntPtr.Zero) {
                string descriptionUrl = Marshal.PtrToStringUni(signer.pwszDescriptionUrl);
                Uri.TryCreate(descriptionUrl, UriKind.RelativeOrAbsolute, out m_descriptionUrl);
            }

            m_signatureChain = signatureChain;

            // If there was a timestamp, and it was not valid we need to invalidate the entire Authenticode
            // signature as well, since we cannot assume that the signature would have verified without
            // the timestamp.
            if (timestamp != null && timestamp.VerificationResult != SignatureVerificationResult.MissingSignature) {
                if (timestamp.IsValid) {
                    m_timestamp = timestamp;
                }
                else {
                    m_verificationResult = SignatureVerificationResult.InvalidTimestamp;
                }
            }
            else {
                m_timestamp = null;
            }
        }
Ejemplo n.º 3
0
        internal TimestampInformation(X509Native.AXL_AUTHENTICODE_TIMESTAMPER_INFO timestamper)
        {
            this.m_hashAlgorithmId    = timestamper.algHash;
            this.m_verificationResult = (SignatureVerificationResult)timestamper.dwError;
            ulong num = (((ulong)timestamper.ftTimestamp.dwHighDateTime) << 0x20) | ((ulong)timestamper.ftTimestamp.dwLowDateTime);

            this.m_timestamp = DateTime.FromFileTimeUtc((long)num);
            if (timestamper.pChainContext != IntPtr.Zero)
            {
                this.m_timestampChain = new X509Chain(timestamper.pChainContext);
            }
        }
        internal TimestampInformation(X509Native.AXL_AUTHENTICODE_TIMESTAMPER_INFO timestamper) {
            m_hashAlgorithmId = timestamper.algHash;
            m_verificationResult = (SignatureVerificationResult)timestamper.dwError;

            ulong filetime = ((ulong)((uint)timestamper.ftTimestamp.dwHighDateTime) << 32)  |
                              (ulong)((uint)timestamper.ftTimestamp.dwLowDateTime);
            m_timestamp = DateTime.FromFileTimeUtc((long)filetime);

            if (timestamper.pChainContext != IntPtr.Zero) {
                m_timestampChain = new X509Chain(timestamper.pChainContext);
            }
        }
Ejemplo n.º 5
0
        /*
         * SafeCritical - we're not exposing out anything that we want to prevent untrusted code from getting at
         */
        public CapiHashAlgorithm(
            string provider,
            CapiNative.ProviderType providerType,
            CapiNative.AlgorithmId algorithm)
        {
            Contract.Requires(!string.IsNullOrEmpty(provider));
            Contract.Requires((CapiNative.AlgorithmClass)((uint)algorithm & (uint)CapiNative.AlgorithmClass.Hash) == CapiNative.AlgorithmClass.Hash);

            m_algorithmId = algorithm;
            m_cspHandle   = CapiNative.AcquireCsp(null,
                                                  provider,
                                                  providerType,
                                                  CapiNative.CryptAcquireContextFlags.VerifyContext,
                                                  true);
            m_hashHandle = Initialize();
        }
        // SafeCritical - we're not exposing out anything that we want to prevent untrusted code from getting at
        public CapiHashAlgorithm(string provider,
                                 CapiNative.ProviderType providerType,
                                 CapiNative.AlgorithmId algorithm) {
            Contract.Requires(!String.IsNullOrEmpty(provider));
            Contract.Requires((CapiNative.AlgorithmClass)((uint)algorithm & (uint)CapiNative.AlgorithmClass.Hash) == CapiNative.AlgorithmClass.Hash);
            Contract.Ensures(m_cspHandle != null && !m_cspHandle.IsInvalid && !m_cspHandle.IsClosed);
            Contract.Ensures(m_hashHandle != null && !m_hashHandle.IsInvalid && !m_hashHandle.IsClosed);

            m_algorithmId = algorithm;
            m_cspHandle = CapiNative.AcquireCsp(null,
                                                provider,
                                                providerType,
                                                CapiNative.CryptAcquireContextFlags.VerifyContext,
                                                true);
            Initialize();
        }
        internal AuthenticodeSignatureInformation(X509Native.AXL_AUTHENTICODE_SIGNER_INFO signer,
                                                  X509Chain signatureChain,
                                                  TimestampInformation timestamp)
        {
            m_verificationResult = (SignatureVerificationResult)signer.dwError;
            m_hashAlgorithmId    = signer.algHash;

            if (signer.pwszDescription != IntPtr.Zero)
            {
                m_description = Marshal.PtrToStringUni(signer.pwszDescription);
            }
            if (signer.pwszDescriptionUrl != IntPtr.Zero)
            {
                string descriptionUrl = Marshal.PtrToStringUni(signer.pwszDescriptionUrl);
                Uri.TryCreate(descriptionUrl, UriKind.RelativeOrAbsolute, out m_descriptionUrl);
            }

            m_signatureChain = signatureChain;

            // If there was a timestamp, and it was not valid we need to invalidate the entire Authenticode
            // signature as well, since we cannot assume that the signature would have verified without
            // the timestamp.
            if (timestamp != null && timestamp.VerificationResult != SignatureVerificationResult.MissingSignature)
            {
                if (timestamp.IsValid)
                {
                    m_timestamp = timestamp;
                }
                else
                {
                    m_verificationResult = SignatureVerificationResult.InvalidTimestamp;
                }
            }
            else
            {
                m_timestamp = null;
            }
        }
Ejemplo n.º 8
0
 public static extern bool CryptGenKey(SafeCspHandle hProv, CapiNative.AlgorithmId Algid, CapiNative.KeyFlags dwFlags, out SafeCapiKeyHandle phKey);
Ejemplo n.º 9
0
 public static extern bool CryptCreateHash(SafeCspHandle hProv, CapiNative.AlgorithmId Algid, SafeCapiKeyHandle hKey, int dwFlags, out SafeCapiHashHandle phHash);
Ejemplo n.º 10
0
 public CapiHashAlgorithm(string provider, CapiNative.ProviderType providerType, CapiNative.AlgorithmId algorithm)
 {
     this.m_algorithmId = algorithm;
     this.m_cspHandle   = CapiNative.AcquireCsp(null, provider, providerType, CapiNative.CryptAcquireContextFlags.None | CapiNative.CryptAcquireContextFlags.VerifyContext, true);
     this.Initialize();
 }
 public CapiHashAlgorithm(string provider, CapiNative.ProviderType providerType, CapiNative.AlgorithmId algorithm)
 {
     this.m_algorithmId = algorithm;
     this.m_cspHandle = CapiNative.AcquireCsp(null, provider, providerType, CapiNative.CryptAcquireContextFlags.None | CapiNative.CryptAcquireContextFlags.VerifyContext, true);
     this.Initialize();
 }