public CertificateConfirmationContent Build()
        {
            Asn1EncodableVector v = new Asn1EncodableVector();

            for (int i = 0; i != acceptedCerts.Count; i++)
            {
                X509Certificate cert  = (X509Certificate)acceptedCerts[i];
                BigInteger      reqId = (BigInteger)acceptedReqIds[i];



                AlgorithmIdentifier algorithmIdentifier = sigAlgFinder.Find(cert.SigAlgName);

                AlgorithmIdentifier digAlg = digestAlgFinder.find(algorithmIdentifier);
                if (digAlg == null)
                {
                    throw new CmpException("cannot find algorithm for digest from signature");
                }

                DigestSink sink = new DigestSink(DigestUtilities.GetDigest(digAlg.Algorithm));

                sink.Write(cert.GetEncoded());

                byte[] dig = new byte[sink.Digest.GetDigestSize()];
                sink.Digest.DoFinal(dig, 0);

                v.Add(new CertStatus(dig, reqId));
            }

            return(new CertificateConfirmationContent(CertConfirmContent.GetInstance(new DerSequence(v)),
                                                      digestAlgFinder));
        }
        public CertificateConfirmationContent Build()
        {
            Asn1EncodableVector v = new Asn1EncodableVector();

            for (int i = 0; i != acceptedCerts.Count; i++)
            {
                X509Certificate cert  = (X509Certificate)acceptedCerts[i];
                BigInteger      reqId = (BigInteger)acceptedReqIds[i];


                AlgorithmIdentifier algorithmIdentifier = sigAlgFinder.Find(cert.SigAlgName);

                AlgorithmIdentifier digAlg = digestAlgFinder.find(algorithmIdentifier);
                if (null == digAlg)
                {
                    throw new CmpException("cannot find algorithm for digest from signature");
                }

                byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());

                v.Add(new CertStatus(digest, reqId));
            }

            return(new CertificateConfirmationContent(CertConfirmContent.GetInstance(new DerSequence(v)),
                                                      digestAlgFinder));
        }
示例#3
0
 private static AlgorithmIdentifier GetAlgorithmIdentifier(string mechanism, DefaultSignatureAlgorithmIdentifierFinder finder)
 {
     try
     {
         return(finder.Find(mechanism));
     }
     catch
     {
         return(null);
     }
 }
示例#4
0
        public bool IsVerified(X509Certificate cert)
        {
            AlgorithmIdentifier digAlg = digestAlgFinder.find(sigAlgFinder.Find(cert.SigAlgName));

            if (null == digAlg)
            {
                throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName);
            }

            byte[] digest = DigestUtilities.CalculateDigest(digAlg.Algorithm, cert.GetEncoded());

            return(Arrays.ConstantTimeAreEqual(certStatus.CertHash.GetOctets(), digest));
        }
示例#5
0
        public bool IsVerified(X509Certificate cert)
        {
            AlgorithmIdentifier digAlg = digestAlgFinder.find(sigAlgFinder.Find(cert.SigAlgName));

            if (digAlg == null)
            {
                throw new CmpException("cannot find algorithm for digest from signature " + cert.SigAlgName);
            }

            DigestSink digestSink = new DigestSink(DigestUtilities.GetDigest(digAlg.Algorithm));

            digestSink.Write(cert.GetEncoded());

            byte[] digest = new byte[digestSink.Digest.GetDigestSize()];
            digestSink.Digest.DoFinal(digest, 0);
            return(Arrays.ConstantTimeAreEqual(certStatus.CertHash.GetOctets(), digest));
        }
示例#6
0
        private static void Test2()
        {
            List <string> hashs = new List <string>();
            Type          type  = typeof(HashAlgorithmHelper);

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.Public);
            foreach (PropertyInfo property in properties)
            {
                if (property.GetValue(type, null) is IHashAlgorithm algorithm)
                {
                    hashs.Add(algorithm.Mechanism);
                }
            }
            List <string> algorithms = new List <string>();

            string[] suffixs = new string[] { "CVC-ECDSA", "PLAIN-ECDSA", "DSA", "RSA", "ECDSA", "ECGOST3410", "ECNR", "GOST3410", "RSA/X9.31", "ISO9796-2", "RSAANDMGF1", "SM2" };
            foreach (string suffix in suffixs)
            {
                foreach (string prefix in hashs)
                {
                    algorithms.Add(prefix + "with" + suffix);
                }
            }
            SecureRandom random = SecureRandom.GetInstance("MD5PRNG");
            var          rsa    = new LH.BouncyCastle.Helpers.Security.Crypto.Asymmetric.RSA(768, 8);
            var          key    = rsa.GenerateKeyPair().Private;
            DefaultSignatureAlgorithmIdentifierFinder finder = new DefaultSignatureAlgorithmIdentifierFinder();

            foreach (string algorithm in algorithms)
            {
                _total++;
                _execute++;
                string tag1 = "------------------------------- ";
                string tag2 = "x";
                string tag3 = "x";
                bool   oidy = false;
                try
                {
                    var identifier = finder.Find(algorithm);
                    tag1 = identifier.Algorithm.Id;
                    oidy = true;
                }
                catch { }
                try
                {
                    _    = new Asn1SignatureFactory(algorithm, key, random);
                    tag2 = "X509 name availabled.";
                }
                catch { }
                if (oidy)
                {
                    try
                    {
                        _    = new Asn1SignatureFactory(tag1, key, random);
                        tag3 = "X509 oid availabled.";
                    }
                    catch { }
                }
                Console.WriteLine("{0}{1}{2}{3}", algorithm.PadRight(38), tag1.PadRight(32), tag2.PadRight(24), tag3);
            }
        }