Exemplo n.º 1
0
        private bool VerifyTimeStamp(byte[] obj, bool timeCheck)
        {
            byte[] numArray1 = new byte[this.sdIndex.TimeHashObjectIdLen];
            Buffer.BlockCopy((Array)obj, (int)this.sdIndex.TimestampHashObjectId, (Array)numArray1, 0, numArray1.Length);
            HashAlgorithm hashAlgorithm;

            if (SignedObjectAsn.CompareByteArrays(numArray1, this.sha1Oid))
            {
                CryptoConfig.MapNameToOID("SHA1");
                hashAlgorithm = HashAlgorithm.Create("SHA1");
            }
            else if (SignedObjectAsn.CompareByteArrays(numArray1, this.sha256Oid))
            {
                hashAlgorithm = (HashAlgorithm) new WinSHA256();
            }
            else
            {
                if (!SignedObjectAsn.CompareByteArrays(numArray1, this.md5Oid))
                {
                    return(false);
                }
                CryptoConfig.MapNameToOID("MD5");
                hashAlgorithm = HashAlgorithm.Create("MD5");
            }
            if (this.sdIndex.TimeSignature == 0L)
            {
                hashAlgorithm.Clear();
                return(false);
            }
            byte[] numArray2 = new byte[this.sdIndex.TimeDigestLen];
            Buffer.BlockCopy((Array)obj, (int)this.sdIndex.TimeDigest, (Array)numArray2, 0, numArray2.Length);
            if (!SignedObjectAsn.CompareByteArrays(hashAlgorithm.ComputeHash(obj, (int)this.sdIndex.EncryptedDigestData, (int)this.sdIndex.EncryptedDigestLen), numArray2))
            {
                hashAlgorithm.Clear();
                return(false);
            }
            string hexString = SignedObjectAsn.CreateHexString(obj, this.sdIndex.TimeCertSerial, this.sdIndex.TimeCertSerialLen);
            RSACryptoServiceProvider rsaManaged  = new RSACryptoServiceProvider();
            RSAParameters            rsa         = new RSAParameters();
            X509Certificate2         certInStore = this.FindCertInStore(hexString);

            if (certInStore == null)
            {
                hashAlgorithm.Clear();
                return(false);
            }
            if (!SignedObjectAsn.ConvertX509PublicKey(certInStore, ref rsa))
            {
                hashAlgorithm.Clear();
                return(false);
            }
            try
            {
                ((RSA)rsaManaged).ImportParameters(rsa);
            }
            catch (CryptographicException ex)
            {
                hashAlgorithm.Clear();
                return(false);
            }
            switch (this.VerifyCertChain(this.memCertStore, certInStore.Handle, false))
            {
            case 0:
            case 1:
                byte[] numArray3 = new byte[this.sdIndex.TimeSignatureLen];
                Buffer.BlockCopy((Array)obj, (int)this.sdIndex.TimeSignature, (Array)numArray3, 0, numArray3.Length);
                byte[] buffer = new byte[this.sdIndex.TimeAuthAttributesLen];
                Buffer.BlockCopy((Array)obj, (int)this.sdIndex.TimeAuthAttributes, (Array)buffer, 0, buffer.Length);
                buffer[0] = (byte)49;
                hashAlgorithm.Initialize();
                hashAlgorithm.ComputeHash(buffer);
                //if (!rsaManaged.VerifyHash(hashAlgorithm.Hash, "MD5SHA1", numArray3))
                if (!rsaManaged.VerifyHash(hashAlgorithm.Hash, CryptoConfig.MapNameToOID("MD5SHA1"), numArray3))
                {
                    hashAlgorithm.Clear();
                    return(false);
                }
                hashAlgorithm.Clear();
                if (timeCheck)
                {
                    byte[] numArray4 = new byte[this.sdIndex.UtcTimeLen - 1L];
                    Buffer.BlockCopy((Array)obj, (int)this.sdIndex.UtcTime, (Array)numArray4, 0, numArray4.Length);
                    DateTime dateTime = new DateTime((int)SignedObjectAsn.CharsToInt(BitConverter.ToInt16(numArray4, 0)) + 2000, (int)SignedObjectAsn.CharsToInt(BitConverter.ToInt16(numArray4, 2)), (int)SignedObjectAsn.CharsToInt(BitConverter.ToInt16(numArray4, 4)), (int)SignedObjectAsn.CharsToInt(BitConverter.ToInt16(numArray4, 6)), (int)SignedObjectAsn.CharsToInt(BitConverter.ToInt16(numArray4, 8)), (int)SignedObjectAsn.CharsToInt(BitConverter.ToInt16(numArray4, 10)));
                    if (this.notAfter.CompareTo(dateTime) < 0 && this.notBefore.CompareTo(dateTime) > 0)
                    {
                        return(false);
                    }
                }
                return(true);

            default:
                hashAlgorithm.Clear();
                return(false);
            }
        }