Пример #1
0
 internal static bool HasUnsupportedCriticalExtension(X509Certificate cert)
 {
     foreach (String oid in cert.GetCriticalExtensionOids())
     {
         if (oid == X509Extensions.KeyUsage.Id ||
             oid == X509Extensions.CertificatePolicies.Id ||
             oid == X509Extensions.PolicyMappings.Id ||
             oid == X509Extensions.InhibitAnyPolicy.Id ||
             oid == X509Extensions.CrlDistributionPoints.Id ||
             oid == X509Extensions.IssuingDistributionPoint.Id ||
             oid == X509Extensions.DeltaCrlIndicator.Id ||
             oid == X509Extensions.PolicyConstraints.Id ||
             oid == X509Extensions.BasicConstraints.Id ||
             oid == X509Extensions.SubjectAlternativeName.Id ||
             oid == X509Extensions.NameConstraints.Id)
         {
             continue;
         }
         try {
             // EXTENDED KEY USAGE and TIMESTAMPING is ALLOWED
             if (oid == X509Extensions.ExtendedKeyUsage.Id && cert.GetExtendedKeyUsage().Contains("1.3.6.1.5.5.7.3.8"))
             {
                 continue;
             }
         } catch (CertificateParsingException) {
             // DO NOTHING;
         }
         return(true);
     }
     return(false);
 }
Пример #2
0
        /**
         * Validate the passed in certificate as being of the correct type to be used
         * for time stamping. To be valid it must have an ExtendedKeyUsage extension
         * which has a key purpose identifier of id-kp-timeStamping.
         *
         * @param cert the certificate of interest.
         * @throws TspValidationException if the certicate fails on one of the check points.
         */
        public static void ValidateCertificate(
            X509Certificate cert)
        {
            if (cert.Version != 3)
            {
                throw new ArgumentException("Certificate must have an ExtendedKeyUsage extension.");
            }

            Asn1OctetString ext = cert.GetExtensionValue(X509Extensions.ExtendedKeyUsage);

            if (ext == null)
            {
                throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension.");
            }

            if (!cert.GetCriticalExtensionOids().Contains(X509Extensions.ExtendedKeyUsage.Id))
            {
                throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
            }

            try
            {
                ExtendedKeyUsage extKey = ExtendedKeyUsage.GetInstance(
                    Asn1Object.FromByteArray(ext.GetOctets()));

                if (!extKey.HasKeyPurposeId(KeyPurposeID.IdKPTimeStamping) || extKey.Count != 1)
                {
                    throw new TspValidationException("ExtendedKeyUsage not solely time stamping.");
                }
            }
            catch (IOException)
            {
                throw new TspValidationException("cannot process ExtendedKeyUsage extension");
            }
        }
Пример #3
0
        public static void ValidateCertificate(X509Certificate cert)
        {
            //IL_000e: Unknown result type (might be due to invalid IL or missing references)
            if (cert.Version != 3)
            {
                throw new ArgumentException("Certificate must have an ExtendedKeyUsage extension.");
            }
            Asn1OctetString extensionValue = cert.GetExtensionValue(X509Extensions.ExtendedKeyUsage);

            if (extensionValue == null)
            {
                throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension.");
            }
            if (!cert.GetCriticalExtensionOids().Contains(X509Extensions.ExtendedKeyUsage.Id))
            {
                throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");
            }
            try
            {
                ExtendedKeyUsage instance = ExtendedKeyUsage.GetInstance(Asn1Object.FromByteArray(extensionValue.GetOctets()));
                if (!instance.HasKeyPurposeId(KeyPurposeID.IdKPTimeStamping) || instance.Count != 1)
                {
                    throw new TspValidationException("ExtendedKeyUsage not solely time stamping.");
                }
            }
            catch (IOException)
            {
                throw new TspValidationException("cannot process ExtendedKeyUsage extension");
            }
        }
Пример #4
0
        /// <summary>
        /// Parses and checks contents of the DICE extension
        /// </summary>
        /// <param name="c">Certificate to validate</param>
        /// <returns>Extension is well formed</returns>
        bool CheckDICEExtension(X509Certificate c)
        {
            var criticalOids = c.GetCriticalExtensionOids();

            if (criticalOids.Contains(DICEExtensionOid))
            {
                Error("DICE extension is marked critical and should be non-critical");
                return(false);
            }

            var nonCriticalOids = c.GetNonCriticalExtensionOids();

            if (!nonCriticalOids.Contains(DICEExtensionOid))
            {
                Error("DICE extension not found");
                return(false);
            }
            var diceExtension = c.GetExtensionValue(new DerObjectIdentifier(DICEExtensionOid));

            try
            {
                DerOctetString envelope = (DerOctetString)DerOctetString.FromByteArray(diceExtension.GetEncoded());
                DerSequence    seq      = (DerSequence)DerSequence.FromByteArray(envelope.GetOctets());
                // first field is version number
                var versionNumber = (DerInteger)seq[0];
                if (versionNumber.PositiveValue.IntValue != 1)
                {
                    Error($"DICE Extension has Wrong version number.  Expecing {DICEExtensionVersionNumber}, cert contains {versionNumber.ToString()}");
                    return(false);
                }
                // second field is DeviceID
                var devIdPubKey = SubjectPublicKeyInfo.GetInstance(seq[1]);
                // will check it's good later
                PubKeyInfoFromDICEExtension = devIdPubKey;

                // third field contains {hashOid, hashVal}
                var hashEnvelope = (DerSequence)seq[2];
                var hashAlg      = (DerObjectIdentifier)hashEnvelope[0];
                if (hashAlg.Id != NistObjectIdentifiers.IdSha256.ToString())
                {
                    Error("DICE Extension hash alg is wrong.  ");
                    return(false);
                }
                var hashVal = (DerOctetString)hashEnvelope[1];
                if (hashVal.GetOctets().Length != 32)
                {
                    Error("DICE Extension hash value length is wrong.  ");
                    return(false);
                }
            }
            catch (Exception e)
            {
                Error($"Failed to parse the DICE extension.  Parsing exception was {e.ToString()}");
                return(false);
            }

            return(true);
        }
        /**
         * Verifies a single certificate.
         * @param cert the certificate to verify
         * @param crls the certificate revocation list or <CODE>null</CODE>
         * @param calendar the date or <CODE>null</CODE> for the current date
         * @return a <CODE>String</CODE> with the error description or <CODE>null</CODE>
         * if no error
         */
        public static String VerifyCertificate(X509Certificate cert, ICollection <X509Crl> crls, DateTime calendar)
        {
            foreach (String oid in cert.GetCriticalExtensionOids())
            {
                if (oid == X509Extensions.KeyUsage.Id ||
                    oid == X509Extensions.CertificatePolicies.Id ||
                    oid == X509Extensions.PolicyMappings.Id ||
                    oid == X509Extensions.InhibitAnyPolicy.Id ||
                    oid == X509Extensions.CrlDistributionPoints.Id ||
                    oid == X509Extensions.IssuingDistributionPoint.Id ||
                    oid == X509Extensions.DeltaCrlIndicator.Id ||
                    oid == X509Extensions.PolicyConstraints.Id ||
                    oid == X509Extensions.BasicConstraints.Id ||
                    oid == X509Extensions.SubjectAlternativeName.Id ||
                    oid == X509Extensions.NameConstraints.Id)
                {
                    continue;
                }
                try {
                    // EXTENDED KEY USAGE and TIMESTAMPING is ALLOWED
                    if (oid == X509Extensions.ExtendedKeyUsage.Id && cert.GetExtendedKeyUsage().Contains("1.3.6.1.5.5.7.3.8"))
                    {
                        continue;
                    }
                }
                catch (CertificateParsingException) {
                    // DO NOTHING;
                }
                return("Has unsupported critical extension");
            }

            try {
                if (!cert.IsValid(calendar.ToUniversalTime()))
                {
                    return("The certificate has expired or is not yet valid");
                }
                if (crls != null)
                {
                    foreach (X509Crl crl in crls)
                    {
                        if (crl.IsRevoked(cert))
                        {
                            return("Certificate revoked");
                        }
                    }
                }
            }
            catch (Exception e) {
                return(e.ToString());
            }
            return(null);
        }
Пример #6
0
        public void Validate(X509Certificate certificate)
        {
            ISet oids = certificate.GetCriticalExtensionOids();

            if (oids == null)
            {
                throw new FailedValidationException("Certificate doesn't contain critical OIDs.");
            }

            foreach (string oid in this.requiredExtensions)
            {
                if (!oids.Contains(oid))
                {
                    throw new FailedValidationException($"Certificate doesn't contain critical OID '{oid}'.");
                }
            }
        }
        /**
         * Verifies a single certificate.
         * @param cert the certificate to verify
         * @param crls the certificate revocation list or <CODE>null</CODE>
         * @param calendar the date or <CODE>null</CODE> for the current date
         * @return a <CODE>String</CODE> with the error description or <CODE>null</CODE>
         * if no error
         */
        public static String VerifyCertificate(X509Certificate cert, ICollection <X509Crl> crls, DateTime calendar)
        {
            foreach (String oid in cert.GetCriticalExtensionOids())
            {
                // KEY USAGE and DIGITAL SIGNING is ALLOWED
                if ("2.5.29.15".Equals(oid) && cert.GetKeyUsage()[0])
                {
                    continue;
                }
                try
                {
                    // EXTENDED KEY USAGE and TIMESTAMPING is ALLOWED
                    if ("2.5.29.37".Equals(oid) && cert.GetExtendedKeyUsage().Contains("1.3.6.1.5.5.7.3.8"))
                    {
                        continue;
                    }
                }
                catch (CertificateParsingException)
                {
                    // DO NOTHING;
                }
                return("Has unsupported critical extension");
            }

            try {
                if (!cert.IsValid(calendar))
                {
                    return("The certificate has expired or is not yet valid");
                }
                if (crls != null)
                {
                    foreach (X509Crl crl in crls)
                    {
                        if (crl.IsRevoked(cert))
                        {
                            return("Certificate revoked");
                        }
                    }
                }
            }
            catch (Exception e) {
                return(e.ToString());
            }
            return(null);
        }
        public void Validate(X509Certificate certificate)
        {
            ISet oids = certificate.GetCriticalExtensionOids();

            if (oids == null)
            {
                return;
            }

            foreach (string oid in oids)
            {
                if (!this.recognizedExtensions.Contains(oid))
                {
                    throw new FailedValidationException(
                              $"X509 certificate {certificate.SerialNumber} specifies a critical extension {oid} which is not recognized");
                }
            }
        }
Пример #9
0
        public virtual PkixCertPathValidatorResult Validate(
            PkixCertPath certPath,
            PkixParameters paramsPkix)
        {
            if (paramsPkix.GetTrustAnchors() == null)
            {
                throw new ArgumentException(
                          "trustAnchors is null, this is not allowed for certification path validation.",
                          "parameters");
            }

            //
            // 6.1.1 - inputs
            //

            //
            // (a)
            //
            IList certs = certPath.Certificates;
            int   n     = certs.Count;

            if (certs.Count == 0)
            {
                throw new PkixCertPathValidatorException("Certification path is empty.", null, certPath, 0);
            }

            //
            // (b)
            //
            // DateTime validDate = PkixCertPathValidatorUtilities.GetValidDate(paramsPkix);

            //
            // (c)
            //
            ISet userInitialPolicySet = paramsPkix.GetInitialPolicies();

            //
            // (d)
            //
            TrustAnchor trust;

            try
            {
                trust = PkixCertPathValidatorUtilities.FindTrustAnchor(
                    (X509Certificate)certs[certs.Count - 1],
                    paramsPkix.GetTrustAnchors());
            }
            catch (Exception e)
            {
                throw new PkixCertPathValidatorException(e.Message, e, certPath, certs.Count - 1);
            }

            if (trust == null)
            {
                throw new PkixCertPathValidatorException("Trust anchor for certification path not found.", null, certPath, -1);
            }

            //
            // (e), (f), (g) are part of the paramsPkix object.
            //
            IEnumerator certIter;
            int         index = 0;
            int         i;

            // Certificate for each interation of the validation loop
            // Signature information for each iteration of the validation loop
            //
            // 6.1.2 - setup
            //

            //
            // (a)
            //
            IList[] policyNodes = new IList[n + 1];
            for (int j = 0; j < policyNodes.Length; j++)
            {
                policyNodes[j] = Platform.CreateArrayList();
            }

            ISet policySet = new HashSet();

            policySet.Add(Rfc3280CertPathUtilities.ANY_POLICY);

            PkixPolicyNode validPolicyTree = new PkixPolicyNode(Platform.CreateArrayList(), 0, policySet, null, new HashSet(),
                                                                Rfc3280CertPathUtilities.ANY_POLICY, false);

            policyNodes[0].Add(validPolicyTree);

            //
            // (b) and (c)
            //
            PkixNameConstraintValidator nameConstraintValidator = new PkixNameConstraintValidator();

            // (d)
            //
            int  explicitPolicy;
            ISet acceptablePolicies = new HashSet();

            if (paramsPkix.IsExplicitPolicyRequired)
            {
                explicitPolicy = 0;
            }
            else
            {
                explicitPolicy = n + 1;
            }

            //
            // (e)
            //
            int inhibitAnyPolicy;

            if (paramsPkix.IsAnyPolicyInhibited)
            {
                inhibitAnyPolicy = 0;
            }
            else
            {
                inhibitAnyPolicy = n + 1;
            }

            //
            // (f)
            //
            int policyMapping;

            if (paramsPkix.IsPolicyMappingInhibited)
            {
                policyMapping = 0;
            }
            else
            {
                policyMapping = n + 1;
            }

            //
            // (g), (h), (i), (j)
            //
            AsymmetricKeyParameter workingPublicKey;
            X509Name workingIssuerName;

            X509Certificate sign = trust.TrustedCert;

            try
            {
                if (sign != null)
                {
                    workingIssuerName = sign.SubjectDN;
                    workingPublicKey  = sign.GetPublicKey();
                }
                else
                {
                    workingIssuerName = new X509Name(trust.CAName);
                    workingPublicKey  = trust.CAPublicKey;
                }
            }
            catch (ArgumentException ex)
            {
                throw new PkixCertPathValidatorException("Subject of trust anchor could not be (re)encoded.", ex, certPath,
                                                         -1);
            }

            AlgorithmIdentifier workingAlgId = null;

            try
            {
                workingAlgId = PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(workingPublicKey);
            }
            catch (PkixCertPathValidatorException e)
            {
                throw new PkixCertPathValidatorException(
                          "Algorithm identifier of public key of trust anchor could not be read.", e, certPath, -1);
            }

//			DerObjectIdentifier workingPublicKeyAlgorithm = workingAlgId.ObjectID;
//			Asn1Encodable workingPublicKeyParameters = workingAlgId.Parameters;

            //
            // (k)
            //
            int maxPathLength = n;

            //
            // 6.1.3
            //

            X509CertStoreSelector certConstraints = paramsPkix.GetTargetCertConstraints();

            if (certConstraints != null && !certConstraints.Match((X509Certificate)certs[0]))
            {
                throw new PkixCertPathValidatorException(
                          "Target certificate in certification path does not match targetConstraints.", null, certPath, 0);
            }

            //
            // initialize CertPathChecker's
            //
            IList pathCheckers = paramsPkix.GetCertPathCheckers();

            certIter = pathCheckers.GetEnumerator();

            while (certIter.MoveNext())
            {
                ((PkixCertPathChecker)certIter.Current).Init(false);
            }

            X509Certificate cert = null;

            for (index = certs.Count - 1; index >= 0; index--)
            {
                // try
                // {
                //
                // i as defined in the algorithm description
                //
                i = n - index;

                //
                // set certificate to be checked in this round
                // sign and workingPublicKey and workingIssuerName are set
                // at the end of the for loop and initialized the
                // first time from the TrustAnchor
                //
                cert = (X509Certificate)certs[index];

                //
                // 6.1.3
                //

                Rfc3280CertPathUtilities.ProcessCertA(certPath, paramsPkix, index, workingPublicKey,
                                                      workingIssuerName, sign);

                Rfc3280CertPathUtilities.ProcessCertBC(certPath, index, nameConstraintValidator);

                validPolicyTree = Rfc3280CertPathUtilities.ProcessCertD(certPath, index,
                                                                        acceptablePolicies, validPolicyTree, policyNodes, inhibitAnyPolicy);

                validPolicyTree = Rfc3280CertPathUtilities.ProcessCertE(certPath, index, validPolicyTree);

                Rfc3280CertPathUtilities.ProcessCertF(certPath, index, validPolicyTree, explicitPolicy);

                //
                // 6.1.4
                //

                if (i != n)
                {
                    if (cert != null && cert.Version == 1)
                    {
                        throw new PkixCertPathValidatorException(
                                  "Version 1 certificates can't be used as CA ones.", null, certPath, index);
                    }

                    Rfc3280CertPathUtilities.PrepareNextCertA(certPath, index);

                    validPolicyTree = Rfc3280CertPathUtilities.PrepareCertB(certPath, index, policyNodes,
                                                                            validPolicyTree, policyMapping);

                    Rfc3280CertPathUtilities.PrepareNextCertG(certPath, index, nameConstraintValidator);

                    // (h)
                    explicitPolicy   = Rfc3280CertPathUtilities.PrepareNextCertH1(certPath, index, explicitPolicy);
                    policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertH2(certPath, index, policyMapping);
                    inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertH3(certPath, index, inhibitAnyPolicy);

                    //
                    // (i)
                    //
                    explicitPolicy = Rfc3280CertPathUtilities.PrepareNextCertI1(certPath, index, explicitPolicy);
                    policyMapping  = Rfc3280CertPathUtilities.PrepareNextCertI2(certPath, index, policyMapping);

                    // (j)
                    inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertJ(certPath, index, inhibitAnyPolicy);

                    // (k)
                    Rfc3280CertPathUtilities.PrepareNextCertK(certPath, index);

                    // (l)
                    maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertL(certPath, index, maxPathLength);

                    // (m)
                    maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertM(certPath, index, maxPathLength);

                    // (n)
                    Rfc3280CertPathUtilities.PrepareNextCertN(certPath, index);

                    ISet criticalExtensions1 = cert.GetCriticalExtensionOids();

                    if (criticalExtensions1 != null)
                    {
                        criticalExtensions1 = new HashSet(criticalExtensions1);

                        // these extensions are handled by the algorithm
                        criticalExtensions1.Remove(X509Extensions.KeyUsage.Id);
                        criticalExtensions1.Remove(X509Extensions.CertificatePolicies.Id);
                        criticalExtensions1.Remove(X509Extensions.PolicyMappings.Id);
                        criticalExtensions1.Remove(X509Extensions.InhibitAnyPolicy.Id);
                        criticalExtensions1.Remove(X509Extensions.IssuingDistributionPoint.Id);
                        criticalExtensions1.Remove(X509Extensions.DeltaCrlIndicator.Id);
                        criticalExtensions1.Remove(X509Extensions.PolicyConstraints.Id);
                        criticalExtensions1.Remove(X509Extensions.BasicConstraints.Id);
                        criticalExtensions1.Remove(X509Extensions.SubjectAlternativeName.Id);
                        criticalExtensions1.Remove(X509Extensions.NameConstraints.Id);
                    }
                    else
                    {
                        criticalExtensions1 = new HashSet();
                    }

                    // (o)
                    Rfc3280CertPathUtilities.PrepareNextCertO(certPath, index, criticalExtensions1, pathCheckers);

                    // set signing certificate for next round
                    sign = cert;

                    // (c)
                    workingIssuerName = sign.SubjectDN;

                    // (d)
                    try
                    {
                        workingPublicKey = PkixCertPathValidatorUtilities.GetNextWorkingKey(certPath.Certificates, index);
                    }
                    catch (PkixCertPathValidatorException e)
                    {
                        throw new PkixCertPathValidatorException("Next working key could not be retrieved.", e, certPath, index);
                    }

                    workingAlgId = PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(workingPublicKey);
                    // (f)
//                    workingPublicKeyAlgorithm = workingAlgId.ObjectID;
                    // (e)
//                    workingPublicKeyParameters = workingAlgId.Parameters;
                }
            }

            //
            // 6.1.5 Wrap-up procedure
            //

            explicitPolicy = Rfc3280CertPathUtilities.WrapupCertA(explicitPolicy, cert);

            explicitPolicy = Rfc3280CertPathUtilities.WrapupCertB(certPath, index + 1, explicitPolicy);

            //
            // (c) (d) and (e) are already done
            //

            //
            // (f)
            //
            ISet criticalExtensions = cert.GetCriticalExtensionOids();

            if (criticalExtensions != null)
            {
                criticalExtensions = new HashSet(criticalExtensions);

                // Requires .Id
                // these extensions are handled by the algorithm
                criticalExtensions.Remove(X509Extensions.KeyUsage.Id);
                criticalExtensions.Remove(X509Extensions.CertificatePolicies.Id);
                criticalExtensions.Remove(X509Extensions.PolicyMappings.Id);
                criticalExtensions.Remove(X509Extensions.InhibitAnyPolicy.Id);
                criticalExtensions.Remove(X509Extensions.IssuingDistributionPoint.Id);
                criticalExtensions.Remove(X509Extensions.DeltaCrlIndicator.Id);
                criticalExtensions.Remove(X509Extensions.PolicyConstraints.Id);
                criticalExtensions.Remove(X509Extensions.BasicConstraints.Id);
                criticalExtensions.Remove(X509Extensions.SubjectAlternativeName.Id);
                criticalExtensions.Remove(X509Extensions.NameConstraints.Id);
                criticalExtensions.Remove(X509Extensions.CrlDistributionPoints.Id);
            }
            else
            {
                criticalExtensions = new HashSet();
            }

            Rfc3280CertPathUtilities.WrapupCertF(certPath, index + 1, pathCheckers, criticalExtensions);

            PkixPolicyNode intersection = Rfc3280CertPathUtilities.WrapupCertG(certPath, paramsPkix, userInitialPolicySet,
                                                                               index + 1, policyNodes, validPolicyTree, acceptablePolicies);

            if ((explicitPolicy > 0) || (intersection != null))
            {
                return(new PkixCertPathValidatorResult(trust, intersection, cert.GetPublicKey()));
            }

            throw new PkixCertPathValidatorException("Path processing failed on policy.", null, certPath, index);
        }
        internal static void PrepareNextCertB1(
            int i,
            IList[] policyNodes,
            string id_p,
            IDictionary m_idp,
            X509Certificate cert)
        {
            bool        idp_found = false;
            IEnumerator nodes_i   = policyNodes[i].GetEnumerator();

            while (nodes_i.MoveNext())
            {
                PkixPolicyNode node = (PkixPolicyNode)nodes_i.Current;
                if (node.ValidPolicy.Equals(id_p))
                {
                    idp_found             = true;
                    node.ExpectedPolicies = (ISet)m_idp[id_p];
                    break;
                }
            }

            if (!idp_found)
            {
                nodes_i = policyNodes[i].GetEnumerator();
                while (nodes_i.MoveNext())
                {
                    PkixPolicyNode node = (PkixPolicyNode)nodes_i.Current;
                    if (ANY_POLICY.Equals(node.ValidPolicy))
                    {
                        ISet         pq       = null;
                        Asn1Sequence policies = null;
                        try
                        {
                            policies = DerSequence.GetInstance(GetExtensionValue(cert, X509Extensions.CertificatePolicies));
                        }
                        catch (Exception e)
                        {
                            throw new Exception("Certificate policies cannot be decoded.", e);
                        }

                        IEnumerator enm = policies.GetEnumerator();
                        while (enm.MoveNext())
                        {
                            PolicyInformation pinfo = null;

                            try
                            {
                                pinfo = PolicyInformation.GetInstance(enm.Current);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("Policy information cannot be decoded.", ex);
                            }

                            if (ANY_POLICY.Equals(pinfo.PolicyIdentifier.Id))
                            {
                                try
                                {
                                    pq = GetQualifierSet(pinfo.PolicyQualifiers);
                                }
                                catch (PkixCertPathValidatorException ex)
                                {
                                    throw new PkixCertPathValidatorException(
                                              "Policy qualifier info set could not be built.", ex);
                                }
                                break;
                            }
                        }
                        bool ci          = false;
                        ISet critExtOids = cert.GetCriticalExtensionOids();
                        if (critExtOids != null)
                        {
                            ci = critExtOids.Contains(X509Extensions.CertificatePolicies.Id);
                        }

                        PkixPolicyNode p_node = (PkixPolicyNode)node.Parent;
                        if (ANY_POLICY.Equals(p_node.ValidPolicy))
                        {
                            PkixPolicyNode c_node = new PkixPolicyNode(
                                Platform.CreateArrayList(), i,
                                (ISet)m_idp[id_p],
                                p_node, pq, id_p, ci);
                            p_node.AddChild(c_node);
                            policyNodes[i].Add(c_node);
                        }
                        break;
                    }
                }
            }
        }
Пример #11
0
        public void TestCreationECDSA()
        {
            BigInteger ECParraGX = new BigInteger(Base64.Decode("D/qWPNyogWzMM7hkK+35BcPTWFc9Pyf7vTs8uaqv"));
            BigInteger ECParraGY = new BigInteger(Base64.Decode("AhQXGxb1olGRv6s1LPRfuatMF+cx3ZTGgzSE/Q5R"));
            BigInteger ECParraH  = new BigInteger(Base64.Decode("AQ=="));
            BigInteger ECParraN  = new BigInteger(Base64.Decode("f///////////////f///nl6an12QcfvRUiaIkJ0L"));
            BigInteger ECPubQX   = new BigInteger(Base64.Decode("HWWi17Yb+Bm3PYr/DMjLOYNFhyOwX1QY7ZvqqM+l"));
            BigInteger ECPubQY   = new BigInteger(Base64.Decode("JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx"));
            BigInteger ECPrivD   = new BigInteger(Base64.Decode("GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo"));

            X9ECParameters     x9       = ECNamedCurveTable.GetByName("prime239v1");
            ECCurve            curve    = x9.Curve;
            ECDomainParameters ecDomain = new ECDomainParameters(curve, curve.ValidatePoint(ECParraGX, ECParraGY), ECParraN, ECParraH);

            ECPublicKeyParameters ecPub = new ECPublicKeyParameters("ECDSA",
                                                                    curve.ValidatePoint(ECPubQX, ECPubQY), ecDomain);
            ECPrivateKeyParameters ecPriv = new ECPrivateKeyParameters("ECDSA", ECPrivD, ecDomain);

            IDictionary attrs = new Hashtable();

            attrs[X509Name.C]  = "AU";
            attrs[X509Name.O]  = "The Legion of the Bouncy Castle";
            attrs[X509Name.L]  = "Melbourne";
            attrs[X509Name.ST] = "Victoria";
            attrs[X509Name.E]  = "*****@*****.**";

            IList ord = new ArrayList();

            ord.Add(X509Name.C);
            ord.Add(X509Name.O);
            ord.Add(X509Name.L);
            ord.Add(X509Name.ST);
            ord.Add(X509Name.E);

            IList values = new ArrayList();

            values.Add("AU");
            values.Add("The Legion of the Bouncy Castle");
            values.Add("Melbourne");
            values.Add("Victoria");
            values.Add("*****@*****.**");

            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

            certGen.SetSerialNumber(BigInteger.One);

            certGen.SetIssuerDN(new X509Name(ord, attrs));
            certGen.SetNotBefore(DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0)));
            certGen.SetNotAfter(DateTime.Today.AddDays(1));
            certGen.SetSubjectDN(new X509Name(ord, attrs));
            certGen.SetPublicKey(ecPub);
            certGen.SetSignatureAlgorithm("SHA1WITHECDSA");

            certGen.AddExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(false));

            X509Certificate cert = certGen.Generate(ecPriv);

//            Assert.IsTrue((cert.IsValidNow && cert.Verify(ecPub)), "Certificate failed to be valid (ECDSA)");
            cert.CheckValidity();
            cert.Verify(ecPub);

            ISet extOidSet = cert.GetCriticalExtensionOids();

            if (extOidSet.Count != 1)
            {
                Fail("wrong number of oids");
            }
            //if (dummySet != null)
            //{
            //    foreach (string key in dummySet)
            //    {
            //        Console.WriteLine("\t{0}:\t{1}", key);
            //    }
            //}

            //Console.WriteLine();

            //dummySet = cert.GetNonCriticalExtensionOids();

            //if (dummySet != null)
            //{
            //    foreach (string key in dummySet)
            //    {
            //        Console.WriteLine("\t{0}:\t{1}", key);
            //    }
            //}

            //Console.WriteLine();
        }
Пример #12
0
        public virtual PkixCertPathValidatorResult Validate(PkixCertPath certPath, PkixParameters paramsPkix)
        {
            if (paramsPkix.GetTrustAnchors() == null)
            {
                throw new ArgumentException("trustAnchors is null, this is not allowed for certification path validation.", "parameters");
            }
            IList certificates = certPath.Certificates;
            int   count        = certificates.Count;

            if (certificates.Count == 0)
            {
                throw new PkixCertPathValidatorException("Certification path is empty.", null, certPath, 0);
            }
            ISet        initialPolicies = paramsPkix.GetInitialPolicies();
            TrustAnchor trustAnchor;

            try
            {
                trustAnchor = PkixCertPathValidatorUtilities.FindTrustAnchor((X509Certificate)certificates[certificates.Count - 1], paramsPkix.GetTrustAnchors());
            }
            catch (Exception ex)
            {
                throw new PkixCertPathValidatorException(ex.Message, ex, certPath, certificates.Count - 1);
            }
            if (trustAnchor == null)
            {
                throw new PkixCertPathValidatorException("Trust anchor for certification path not found.", null, certPath, -1);
            }
            int i = 0;

            IList[] array = new IList[count + 1];
            for (int j = 0; j < array.Length; j++)
            {
                array[j] = Platform.CreateArrayList();
            }
            ISet set = new HashSet();

            set.Add(Rfc3280CertPathUtilities.ANY_POLICY);
            PkixPolicyNode pkixPolicyNode = new PkixPolicyNode(Platform.CreateArrayList(), 0, set, null, new HashSet(), Rfc3280CertPathUtilities.ANY_POLICY, false);

            array[0].Add(pkixPolicyNode);
            PkixNameConstraintValidator nameConstraintValidator = new PkixNameConstraintValidator();
            ISet acceptablePolicies = new HashSet();
            int  num;

            if (paramsPkix.IsExplicitPolicyRequired)
            {
                num = 0;
            }
            else
            {
                num = count + 1;
            }
            int inhibitAnyPolicy;

            if (paramsPkix.IsAnyPolicyInhibited)
            {
                inhibitAnyPolicy = 0;
            }
            else
            {
                inhibitAnyPolicy = count + 1;
            }
            int policyMapping;

            if (paramsPkix.IsPolicyMappingInhibited)
            {
                policyMapping = 0;
            }
            else
            {
                policyMapping = count + 1;
            }
            X509Certificate        x509Certificate = trustAnchor.TrustedCert;
            X509Name               workingIssuerName;
            AsymmetricKeyParameter asymmetricKeyParameter;

            try
            {
                if (x509Certificate != null)
                {
                    workingIssuerName      = x509Certificate.SubjectDN;
                    asymmetricKeyParameter = x509Certificate.GetPublicKey();
                }
                else
                {
                    workingIssuerName      = new X509Name(trustAnchor.CAName);
                    asymmetricKeyParameter = trustAnchor.CAPublicKey;
                }
            }
            catch (ArgumentException cause)
            {
                throw new PkixCertPathValidatorException("Subject of trust anchor could not be (re)encoded.", cause, certPath, -1);
            }
            try
            {
                PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(asymmetricKeyParameter);
            }
            catch (PkixCertPathValidatorException cause2)
            {
                throw new PkixCertPathValidatorException("Algorithm identifier of public key of trust anchor could not be read.", cause2, certPath, -1);
            }
            int maxPathLength = count;
            X509CertStoreSelector targetCertConstraints = paramsPkix.GetTargetCertConstraints();

            if (targetCertConstraints != null && !targetCertConstraints.Match((X509Certificate)certificates[0]))
            {
                throw new PkixCertPathValidatorException("Target certificate in certification path does not match targetConstraints.", null, certPath, 0);
            }
            IList       certPathCheckers = paramsPkix.GetCertPathCheckers();
            IEnumerator enumerator       = certPathCheckers.GetEnumerator();

            while (enumerator.MoveNext())
            {
                ((PkixCertPathChecker)enumerator.Current).Init(false);
            }
            X509Certificate x509Certificate2 = null;

            for (i = certificates.Count - 1; i >= 0; i--)
            {
                int num2 = count - i;
                x509Certificate2 = (X509Certificate)certificates[i];
                Rfc3280CertPathUtilities.ProcessCertA(certPath, paramsPkix, i, asymmetricKeyParameter, workingIssuerName, x509Certificate);
                Rfc3280CertPathUtilities.ProcessCertBC(certPath, i, nameConstraintValidator);
                pkixPolicyNode = Rfc3280CertPathUtilities.ProcessCertD(certPath, i, acceptablePolicies, pkixPolicyNode, array, inhibitAnyPolicy);
                pkixPolicyNode = Rfc3280CertPathUtilities.ProcessCertE(certPath, i, pkixPolicyNode);
                Rfc3280CertPathUtilities.ProcessCertF(certPath, i, pkixPolicyNode, num);
                if (num2 != count)
                {
                    if (x509Certificate2 != null && x509Certificate2.Version == 1)
                    {
                        throw new PkixCertPathValidatorException("Version 1 certificates can't be used as CA ones.", null, certPath, i);
                    }
                    Rfc3280CertPathUtilities.PrepareNextCertA(certPath, i);
                    pkixPolicyNode = Rfc3280CertPathUtilities.PrepareCertB(certPath, i, array, pkixPolicyNode, policyMapping);
                    Rfc3280CertPathUtilities.PrepareNextCertG(certPath, i, nameConstraintValidator);
                    num              = Rfc3280CertPathUtilities.PrepareNextCertH1(certPath, i, num);
                    policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertH2(certPath, i, policyMapping);
                    inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertH3(certPath, i, inhibitAnyPolicy);
                    num              = Rfc3280CertPathUtilities.PrepareNextCertI1(certPath, i, num);
                    policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertI2(certPath, i, policyMapping);
                    inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertJ(certPath, i, inhibitAnyPolicy);
                    Rfc3280CertPathUtilities.PrepareNextCertK(certPath, i);
                    maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertL(certPath, i, maxPathLength);
                    maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertM(certPath, i, maxPathLength);
                    Rfc3280CertPathUtilities.PrepareNextCertN(certPath, i);
                    ISet set2 = x509Certificate2.GetCriticalExtensionOids();
                    if (set2 != null)
                    {
                        set2 = new HashSet(set2);
                        set2.Remove(X509Extensions.KeyUsage.Id);
                        set2.Remove(X509Extensions.CertificatePolicies.Id);
                        set2.Remove(X509Extensions.PolicyMappings.Id);
                        set2.Remove(X509Extensions.InhibitAnyPolicy.Id);
                        set2.Remove(X509Extensions.IssuingDistributionPoint.Id);
                        set2.Remove(X509Extensions.DeltaCrlIndicator.Id);
                        set2.Remove(X509Extensions.PolicyConstraints.Id);
                        set2.Remove(X509Extensions.BasicConstraints.Id);
                        set2.Remove(X509Extensions.SubjectAlternativeName.Id);
                        set2.Remove(X509Extensions.NameConstraints.Id);
                    }
                    else
                    {
                        set2 = new HashSet();
                    }
                    Rfc3280CertPathUtilities.PrepareNextCertO(certPath, i, set2, certPathCheckers);
                    x509Certificate   = x509Certificate2;
                    workingIssuerName = x509Certificate.SubjectDN;
                    try
                    {
                        asymmetricKeyParameter = PkixCertPathValidatorUtilities.GetNextWorkingKey(certPath.Certificates, i);
                    }
                    catch (PkixCertPathValidatorException cause3)
                    {
                        throw new PkixCertPathValidatorException("Next working key could not be retrieved.", cause3, certPath, i);
                    }
                    PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(asymmetricKeyParameter);
                }
            }
            num = Rfc3280CertPathUtilities.WrapupCertA(num, x509Certificate2);
            num = Rfc3280CertPathUtilities.WrapupCertB(certPath, i + 1, num);
            ISet set3 = x509Certificate2.GetCriticalExtensionOids();

            if (set3 != null)
            {
                set3 = new HashSet(set3);
                set3.Remove(X509Extensions.KeyUsage.Id);
                set3.Remove(X509Extensions.CertificatePolicies.Id);
                set3.Remove(X509Extensions.PolicyMappings.Id);
                set3.Remove(X509Extensions.InhibitAnyPolicy.Id);
                set3.Remove(X509Extensions.IssuingDistributionPoint.Id);
                set3.Remove(X509Extensions.DeltaCrlIndicator.Id);
                set3.Remove(X509Extensions.PolicyConstraints.Id);
                set3.Remove(X509Extensions.BasicConstraints.Id);
                set3.Remove(X509Extensions.SubjectAlternativeName.Id);
                set3.Remove(X509Extensions.NameConstraints.Id);
                set3.Remove(X509Extensions.CrlDistributionPoints.Id);
            }
            else
            {
                set3 = new HashSet();
            }
            Rfc3280CertPathUtilities.WrapupCertF(certPath, i + 1, certPathCheckers, set3);
            PkixPolicyNode pkixPolicyNode2 = Rfc3280CertPathUtilities.WrapupCertG(certPath, paramsPkix, initialPolicies, i + 1, array, pkixPolicyNode, acceptablePolicies);

            if (num > 0 || pkixPolicyNode2 != null)
            {
                return(new PkixCertPathValidatorResult(trustAnchor, pkixPolicyNode2, x509Certificate2.GetPublicKey()));
            }
            throw new PkixCertPathValidatorException("Path processing failed on policy.", null, certPath, i);
        }
Пример #13
0
        public virtual PkixCertPathValidatorResult Validate(PkixCertPath certPath, PkixParameters paramsPkix)
        {
            //IL_0012: Unknown result type (might be due to invalid IL or missing references)
            //IL_0170: Expected O, but got Unknown
            if (paramsPkix.GetTrustAnchors() == null)
            {
                throw new ArgumentException("trustAnchors is null, this is not allowed for certification path validation.", "parameters");
            }
            global::System.Collections.IList certificates = certPath.Certificates;
            int count = ((global::System.Collections.ICollection)certificates).get_Count();

            if (((global::System.Collections.ICollection)certificates).get_Count() == 0)
            {
                throw new PkixCertPathValidatorException("Certification path is empty.", null, certPath, 0);
            }
            ISet        initialPolicies = paramsPkix.GetInitialPolicies();
            TrustAnchor trustAnchor;

            try
            {
                trustAnchor = PkixCertPathValidatorUtilities.FindTrustAnchor((X509Certificate)certificates.get_Item(((global::System.Collections.ICollection)certificates).get_Count() - 1), paramsPkix.GetTrustAnchors());
            }
            catch (global::System.Exception ex)
            {
                throw new PkixCertPathValidatorException(ex.get_Message(), ex, certPath, ((global::System.Collections.ICollection)certificates).get_Count() - 1);
            }
            if (trustAnchor == null)
            {
                throw new PkixCertPathValidatorException("Trust anchor for certification path not found.", null, certPath, -1);
            }
            int num = 0;

            global::System.Collections.IList[] array = new global::System.Collections.IList[count + 1];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Platform.CreateArrayList();
            }
            ISet set = new HashSet();

            set.Add(Rfc3280CertPathUtilities.ANY_POLICY);
            PkixPolicyNode pkixPolicyNode = new PkixPolicyNode(Platform.CreateArrayList(), 0, set, null, new HashSet(), Rfc3280CertPathUtilities.ANY_POLICY, critical: false);

            array[0].Add((object)pkixPolicyNode);
            PkixNameConstraintValidator nameConstraintValidator = new PkixNameConstraintValidator();
            ISet                   acceptablePolicies           = new HashSet();
            int                    explicitPolicy   = ((!paramsPkix.IsExplicitPolicyRequired) ? (count + 1) : 0);
            int                    inhibitAnyPolicy = ((!paramsPkix.IsAnyPolicyInhibited) ? (count + 1) : 0);
            int                    policyMapping    = ((!paramsPkix.IsPolicyMappingInhibited) ? (count + 1) : 0);
            X509Certificate        x509Certificate  = trustAnchor.TrustedCert;
            X509Name               workingIssuerName;
            AsymmetricKeyParameter asymmetricKeyParameter;

            try
            {
                if (x509Certificate != null)
                {
                    workingIssuerName      = x509Certificate.SubjectDN;
                    asymmetricKeyParameter = x509Certificate.GetPublicKey();
                }
                else
                {
                    workingIssuerName      = new X509Name(trustAnchor.CAName);
                    asymmetricKeyParameter = trustAnchor.CAPublicKey;
                }
            }
            catch (ArgumentException val)
            {
                ArgumentException cause = val;
                throw new PkixCertPathValidatorException("Subject of trust anchor could not be (re)encoded.", (global::System.Exception)(object) cause, certPath, -1);
            }
            try
            {
                PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(asymmetricKeyParameter);
            }
            catch (PkixCertPathValidatorException cause2)
            {
                throw new PkixCertPathValidatorException("Algorithm identifier of public key of trust anchor could not be read.", cause2, certPath, -1);
            }
            int maxPathLength = count;
            X509CertStoreSelector targetCertConstraints = paramsPkix.GetTargetCertConstraints();

            if (targetCertConstraints != null && !targetCertConstraints.Match((X509Certificate)certificates.get_Item(0)))
            {
                throw new PkixCertPathValidatorException("Target certificate in certification path does not match targetConstraints.", null, certPath, 0);
            }
            global::System.Collections.IList       certPathCheckers = paramsPkix.GetCertPathCheckers();
            global::System.Collections.IEnumerator enumerator       = ((global::System.Collections.IEnumerable)certPathCheckers).GetEnumerator();
            while (enumerator.MoveNext())
            {
                ((PkixCertPathChecker)enumerator.get_Current()).Init(forward: false);
            }
            X509Certificate x509Certificate2 = null;

            for (num = ((global::System.Collections.ICollection)certificates).get_Count() - 1; num >= 0; num--)
            {
                int num2 = count - num;
                x509Certificate2 = (X509Certificate)certificates.get_Item(num);
                Rfc3280CertPathUtilities.ProcessCertA(certPath, paramsPkix, num, asymmetricKeyParameter, workingIssuerName, x509Certificate);
                Rfc3280CertPathUtilities.ProcessCertBC(certPath, num, nameConstraintValidator);
                pkixPolicyNode = Rfc3280CertPathUtilities.ProcessCertD(certPath, num, acceptablePolicies, pkixPolicyNode, array, inhibitAnyPolicy);
                pkixPolicyNode = Rfc3280CertPathUtilities.ProcessCertE(certPath, num, pkixPolicyNode);
                Rfc3280CertPathUtilities.ProcessCertF(certPath, num, pkixPolicyNode, explicitPolicy);
                if (num2 != count)
                {
                    if (x509Certificate2 != null && x509Certificate2.Version == 1)
                    {
                        throw new PkixCertPathValidatorException("Version 1 certificates can't be used as CA ones.", null, certPath, num);
                    }
                    Rfc3280CertPathUtilities.PrepareNextCertA(certPath, num);
                    pkixPolicyNode = Rfc3280CertPathUtilities.PrepareCertB(certPath, num, array, pkixPolicyNode, policyMapping);
                    Rfc3280CertPathUtilities.PrepareNextCertG(certPath, num, nameConstraintValidator);
                    explicitPolicy   = Rfc3280CertPathUtilities.PrepareNextCertH1(certPath, num, explicitPolicy);
                    policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertH2(certPath, num, policyMapping);
                    inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertH3(certPath, num, inhibitAnyPolicy);
                    explicitPolicy   = Rfc3280CertPathUtilities.PrepareNextCertI1(certPath, num, explicitPolicy);
                    policyMapping    = Rfc3280CertPathUtilities.PrepareNextCertI2(certPath, num, policyMapping);
                    inhibitAnyPolicy = Rfc3280CertPathUtilities.PrepareNextCertJ(certPath, num, inhibitAnyPolicy);
                    Rfc3280CertPathUtilities.PrepareNextCertK(certPath, num);
                    maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertL(certPath, num, maxPathLength);
                    maxPathLength = Rfc3280CertPathUtilities.PrepareNextCertM(certPath, num, maxPathLength);
                    Rfc3280CertPathUtilities.PrepareNextCertN(certPath, num);
                    ISet criticalExtensionOids = x509Certificate2.GetCriticalExtensionOids();
                    if (criticalExtensionOids != null)
                    {
                        criticalExtensionOids = new HashSet(criticalExtensionOids);
                        criticalExtensionOids.Remove(X509Extensions.KeyUsage.Id);
                        criticalExtensionOids.Remove(X509Extensions.CertificatePolicies.Id);
                        criticalExtensionOids.Remove(X509Extensions.PolicyMappings.Id);
                        criticalExtensionOids.Remove(X509Extensions.InhibitAnyPolicy.Id);
                        criticalExtensionOids.Remove(X509Extensions.IssuingDistributionPoint.Id);
                        criticalExtensionOids.Remove(X509Extensions.DeltaCrlIndicator.Id);
                        criticalExtensionOids.Remove(X509Extensions.PolicyConstraints.Id);
                        criticalExtensionOids.Remove(X509Extensions.BasicConstraints.Id);
                        criticalExtensionOids.Remove(X509Extensions.SubjectAlternativeName.Id);
                        criticalExtensionOids.Remove(X509Extensions.NameConstraints.Id);
                    }
                    else
                    {
                        criticalExtensionOids = new HashSet();
                    }
                    Rfc3280CertPathUtilities.PrepareNextCertO(certPath, num, criticalExtensionOids, certPathCheckers);
                    x509Certificate   = x509Certificate2;
                    workingIssuerName = x509Certificate.SubjectDN;
                    try
                    {
                        asymmetricKeyParameter = PkixCertPathValidatorUtilities.GetNextWorkingKey(certPath.Certificates, num);
                    }
                    catch (PkixCertPathValidatorException cause3)
                    {
                        throw new PkixCertPathValidatorException("Next working key could not be retrieved.", cause3, certPath, num);
                    }
                    PkixCertPathValidatorUtilities.GetAlgorithmIdentifier(asymmetricKeyParameter);
                }
            }
            explicitPolicy = Rfc3280CertPathUtilities.WrapupCertA(explicitPolicy, x509Certificate2);
            explicitPolicy = Rfc3280CertPathUtilities.WrapupCertB(certPath, num + 1, explicitPolicy);
            ISet criticalExtensionOids2 = x509Certificate2.GetCriticalExtensionOids();

            if (criticalExtensionOids2 != null)
            {
                criticalExtensionOids2 = new HashSet(criticalExtensionOids2);
                criticalExtensionOids2.Remove(X509Extensions.KeyUsage.Id);
                criticalExtensionOids2.Remove(X509Extensions.CertificatePolicies.Id);
                criticalExtensionOids2.Remove(X509Extensions.PolicyMappings.Id);
                criticalExtensionOids2.Remove(X509Extensions.InhibitAnyPolicy.Id);
                criticalExtensionOids2.Remove(X509Extensions.IssuingDistributionPoint.Id);
                criticalExtensionOids2.Remove(X509Extensions.DeltaCrlIndicator.Id);
                criticalExtensionOids2.Remove(X509Extensions.PolicyConstraints.Id);
                criticalExtensionOids2.Remove(X509Extensions.BasicConstraints.Id);
                criticalExtensionOids2.Remove(X509Extensions.SubjectAlternativeName.Id);
                criticalExtensionOids2.Remove(X509Extensions.NameConstraints.Id);
                criticalExtensionOids2.Remove(X509Extensions.CrlDistributionPoints.Id);
            }
            else
            {
                criticalExtensionOids2 = new HashSet();
            }
            Rfc3280CertPathUtilities.WrapupCertF(certPath, num + 1, certPathCheckers, criticalExtensionOids2);
            PkixPolicyNode pkixPolicyNode2 = Rfc3280CertPathUtilities.WrapupCertG(certPath, paramsPkix, initialPolicies, num + 1, array, pkixPolicyNode, acceptablePolicies);

            if (explicitPolicy > 0 || pkixPolicyNode2 != null)
            {
                return(new PkixCertPathValidatorResult(trustAnchor, pkixPolicyNode2, x509Certificate2.GetPublicKey()));
            }
            throw new PkixCertPathValidatorException("Path processing failed on policy.", null, certPath, num);
        }
Пример #14
0
        internal static void PrepareNextCertB1(int i, global::System.Collections.IList[] policyNodes, string id_p, IDictionary m_idp, X509Certificate cert)
        {
            bool flag = false;

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)policyNodes[i]).GetEnumerator();
            while (enumerator.MoveNext())
            {
                PkixPolicyNode pkixPolicyNode = (PkixPolicyNode)enumerator.get_Current();
                if (pkixPolicyNode.ValidPolicy.Equals(id_p))
                {
                    flag = true;
                    pkixPolicyNode.ExpectedPolicies = (ISet)m_idp.get_Item((object)id_p);
                    break;
                }
            }
            if (flag)
            {
                return;
            }
            enumerator = ((global::System.Collections.IEnumerable)policyNodes[i]).GetEnumerator();
            while (enumerator.MoveNext())
            {
                PkixPolicyNode pkixPolicyNode2 = (PkixPolicyNode)enumerator.get_Current();
                if (!ANY_POLICY.Equals(pkixPolicyNode2.ValidPolicy))
                {
                    continue;
                }
                ISet         policyQualifiers = null;
                Asn1Sequence asn1Sequence     = null;
                try
                {
                    asn1Sequence = Asn1Sequence.GetInstance(GetExtensionValue(cert, X509Extensions.CertificatePolicies));
                }
                catch (global::System.Exception ex)
                {
                    throw new global::System.Exception("Certificate policies cannot be decoded.", ex);
                }
                global::System.Collections.IEnumerator enumerator2 = asn1Sequence.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    PolicyInformation policyInformation = null;
                    try
                    {
                        policyInformation = PolicyInformation.GetInstance(enumerator2.get_Current());
                    }
                    catch (global::System.Exception ex2)
                    {
                        throw new global::System.Exception("Policy information cannot be decoded.", ex2);
                    }
                    if (ANY_POLICY.Equals(policyInformation.PolicyIdentifier.Id))
                    {
                        try
                        {
                            policyQualifiers = GetQualifierSet(policyInformation.PolicyQualifiers);
                        }
                        catch (PkixCertPathValidatorException cause)
                        {
                            throw new PkixCertPathValidatorException("Policy qualifier info set could not be built.", cause);
                        }
                        break;
                    }
                }
                bool critical = false;
                ISet criticalExtensionOids = cert.GetCriticalExtensionOids();
                if (criticalExtensionOids != null)
                {
                    critical = criticalExtensionOids.Contains(X509Extensions.CertificatePolicies.Id);
                }
                PkixPolicyNode parent = pkixPolicyNode2.Parent;
                if (ANY_POLICY.Equals(parent.ValidPolicy))
                {
                    PkixPolicyNode pkixPolicyNode3 = new PkixPolicyNode(Platform.CreateArrayList(), i, (ISet)m_idp.get_Item((object)id_p), parent, policyQualifiers, id_p, critical);
                    parent.AddChild(pkixPolicyNode3);
                    policyNodes[i].Add((object)pkixPolicyNode3);
                }
                break;
            }
        }
Пример #15
0
        internal static void PrepareNextCertB1(int i, IList[] policyNodes, string id_p, IDictionary m_idp, X509Certificate cert)
        {
            bool        flag       = false;
            IEnumerator enumerator = policyNodes[i].GetEnumerator();

            while (enumerator.MoveNext())
            {
                PkixPolicyNode pkixPolicyNode = (PkixPolicyNode)enumerator.Current;
                if (pkixPolicyNode.ValidPolicy.Equals(id_p))
                {
                    flag = true;
                    pkixPolicyNode.ExpectedPolicies = (ISet)m_idp[id_p];
                    break;
                }
            }
            if (!flag)
            {
                enumerator = policyNodes[i].GetEnumerator();
                while (enumerator.MoveNext())
                {
                    PkixPolicyNode pkixPolicyNode2 = (PkixPolicyNode)enumerator.Current;
                    if (PkixCertPathValidatorUtilities.ANY_POLICY.Equals(pkixPolicyNode2.ValidPolicy))
                    {
                        ISet         policyQualifiers = null;
                        Asn1Sequence asn1Sequence     = null;
                        try
                        {
                            asn1Sequence = Asn1Sequence.GetInstance(PkixCertPathValidatorUtilities.GetExtensionValue(cert, X509Extensions.CertificatePolicies));
                        }
                        catch (Exception innerException)
                        {
                            throw new Exception("Certificate policies cannot be decoded.", innerException);
                        }
                        IEnumerator enumerator2 = asn1Sequence.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            PolicyInformation policyInformation = null;
                            try
                            {
                                policyInformation = PolicyInformation.GetInstance(enumerator2.Current);
                            }
                            catch (Exception innerException2)
                            {
                                throw new Exception("Policy information cannot be decoded.", innerException2);
                            }
                            if (PkixCertPathValidatorUtilities.ANY_POLICY.Equals(policyInformation.PolicyIdentifier.Id))
                            {
                                try
                                {
                                    policyQualifiers = PkixCertPathValidatorUtilities.GetQualifierSet(policyInformation.PolicyQualifiers);
                                    break;
                                }
                                catch (PkixCertPathValidatorException cause)
                                {
                                    throw new PkixCertPathValidatorException("Policy qualifier info set could not be built.", cause);
                                }
                            }
                        }
                        bool critical = false;
                        ISet criticalExtensionOids = cert.GetCriticalExtensionOids();
                        if (criticalExtensionOids != null)
                        {
                            critical = criticalExtensionOids.Contains(X509Extensions.CertificatePolicies.Id);
                        }
                        PkixPolicyNode parent = pkixPolicyNode2.Parent;
                        if (PkixCertPathValidatorUtilities.ANY_POLICY.Equals(parent.ValidPolicy))
                        {
                            PkixPolicyNode pkixPolicyNode3 = new PkixPolicyNode(Platform.CreateArrayList(), i, (ISet)m_idp[id_p], parent, policyQualifiers, id_p, critical);
                            parent.AddChild(pkixPolicyNode3);
                            policyNodes[i].Add(pkixPolicyNode3);
                            return;
                        }
                        break;
                    }
                }
            }
        }