コード例 #1
0
 public PkixCertPathBuilderResult(PkixCertPath certPath, TrustAnchor trustAnchor, PkixPolicyNode policyTree, AsymmetricKeyParameter subjectPublicKey)
     : base(trustAnchor, policyTree, subjectPublicKey)
 {
     if (certPath == null)
     {
         throw new ArgumentNullException("certPath");
     }
     this.certPath = certPath;
 }
コード例 #2
0
 public PkixCertPathValidatorResult(TrustAnchor trustAnchor, PkixPolicyNode policyTree, AsymmetricKeyParameter subjectPublicKey)
 {
     if (subjectPublicKey == null)
     {
         throw new NullReferenceException("subjectPublicKey must be non-null");
     }
     if (trustAnchor == null)
     {
         throw new NullReferenceException("trustAnchor must be non-null");
     }
     this.trustAnchor      = trustAnchor;
     this.policyTree       = policyTree;
     this.subjectPublicKey = subjectPublicKey;
 }
コード例 #3
0
        public virtual void SetUp(MessageFamily handler)
        {
            _handler        = handler;
            _messageHandler = async(messageName, message) =>
            {
                if ("public-identifier-created".Equals(messageName))
                {
                    var json_identifier = message.GetValue("identifier");
                    var issuerDID       = json_identifier["did"];
                    var issuerVerKey    = json_identifier["verKey"];

                    var trustAnchor = new TrustAnchor(issuerDID.ToString(), issuerVerKey.ToString());
                    await _repository.Add(trustAnchor);

                    await _unitOfWork.Commit();
                }
            };
        }
コード例 #4
0
    internal static TrustAnchor FindTrustAnchor(X509Certificate cert, ISet trustAnchors)
    {
        IEnumerator            enumerator             = trustAnchors.GetEnumerator();
        TrustAnchor            trustAnchor            = null;
        AsymmetricKeyParameter asymmetricKeyParameter = null;
        Exception             ex = null;
        X509CertStoreSelector x509CertStoreSelector = new X509CertStoreSelector();

        try
        {
            x509CertStoreSelector.Subject = GetIssuerPrincipal(cert);
        }
        catch (IOException innerException)
        {
            throw new Exception("Cannot set subject search criteria for trust anchor.", innerException);
        }
        while (enumerator.MoveNext() && trustAnchor == null)
        {
            trustAnchor = (TrustAnchor)enumerator.Current;
            if (trustAnchor.TrustedCert != null)
            {
                if (x509CertStoreSelector.Match(trustAnchor.TrustedCert))
                {
                    asymmetricKeyParameter = trustAnchor.TrustedCert.GetPublicKey();
                }
                else
                {
                    trustAnchor = null;
                }
            }
            else if (trustAnchor.CAName != null && trustAnchor.CAPublicKey != null)
            {
                try
                {
                    X509Name issuerPrincipal = GetIssuerPrincipal(cert);
                    X509Name other           = new X509Name(trustAnchor.CAName);
                    if (issuerPrincipal.Equivalent(other, inOrder: true))
                    {
                        asymmetricKeyParameter = trustAnchor.CAPublicKey;
                    }
                    else
                    {
                        trustAnchor = null;
                    }
                }
                catch (InvalidParameterException)
                {
                    trustAnchor = null;
                }
            }
            else
            {
                trustAnchor = null;
            }
            if (asymmetricKeyParameter != null)
            {
                try
                {
                    cert.Verify(asymmetricKeyParameter);
                }
                catch (Exception ex3)
                {
                    ex          = ex3;
                    trustAnchor = null;
                }
            }
        }
        if (trustAnchor == null && ex != null)
        {
            throw new Exception("TrustAnchor found but certificate validation failed.", ex);
        }
        return(trustAnchor);
    }