Ejemplo n.º 1
0
        public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
        {
            ThrowIfDisposed();
            X509SubjectKeyIdentifierClause subjectKeyIdentifierClause = keyIdentifierClause as X509SubjectKeyIdentifierClause;

            if (subjectKeyIdentifierClause != null)
            {
                return(subjectKeyIdentifierClause.Matches(certificate));
            }

            X509ThumbprintKeyIdentifierClause thumbprintKeyIdentifierClause = keyIdentifierClause as X509ThumbprintKeyIdentifierClause;

            if (thumbprintKeyIdentifierClause != null)
            {
                return(thumbprintKeyIdentifierClause.Matches(certificate));
            }

            X509IssuerSerialKeyIdentifierClause issuerKeyIdentifierClause = keyIdentifierClause as X509IssuerSerialKeyIdentifierClause;

            if (issuerKeyIdentifierClause != null)
            {
                return(issuerKeyIdentifierClause.Matches(certificate));
            }

            X509RawDataKeyIdentifierClause rawCertKeyIdentifierClause = keyIdentifierClause as X509RawDataKeyIdentifierClause;

            if (rawCertKeyIdentifierClause != null)
            {
                return(rawCertKeyIdentifierClause.Matches(certificate));
            }

            return(base.MatchesKeyIdentifierClause(keyIdentifierClause));
        }
Ejemplo n.º 2
0
        public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
        {
            this.ThrowIfDisposed();
            X509SubjectKeyIdentifierClause clause = keyIdentifierClause as X509SubjectKeyIdentifierClause;

            if (clause != null)
            {
                return(clause.Matches(this.certificate));
            }
            X509ThumbprintKeyIdentifierClause clause2 = keyIdentifierClause as X509ThumbprintKeyIdentifierClause;

            if (clause2 != null)
            {
                return(clause2.Matches(this.certificate));
            }
            X509IssuerSerialKeyIdentifierClause clause3 = keyIdentifierClause as X509IssuerSerialKeyIdentifierClause;

            if (clause3 != null)
            {
                return(clause3.Matches(this.certificate));
            }
            X509RawDataKeyIdentifierClause clause4 = keyIdentifierClause as X509RawDataKeyIdentifierClause;

            if (clause4 != null)
            {
                return(clause4.Matches(this.certificate));
            }
            return(base.MatchesKeyIdentifierClause(keyIdentifierClause));
        }
Ejemplo n.º 3
0
        public override bool MatchesKeyIdentifierClause(
            SecurityKeyIdentifierClause keyIdentifierClause)
        {
            LocalIdKeyIdentifierClause l =
                keyIdentifierClause as LocalIdKeyIdentifierClause;

            if (l != null)
            {
                return(l.LocalId == Id);
            }

            X509ThumbprintKeyIdentifierClause t =
                keyIdentifierClause as X509ThumbprintKeyIdentifierClause;

            if (t != null)
            {
                return(t.Matches(cert));
            }
            X509IssuerSerialKeyIdentifierClause i =
                keyIdentifierClause as X509IssuerSerialKeyIdentifierClause;

            if (i != null)
            {
                return(i.Matches(cert));
            }
            X509SubjectKeyIdentifierClause s =
                keyIdentifierClause as X509SubjectKeyIdentifierClause;

            if (s != null)
            {
                return(s.Matches(cert));
            }
            X509RawDataKeyIdentifierClause r =
                keyIdentifierClause as X509RawDataKeyIdentifierClause;

            if (r != null)
            {
                return(r.Matches(cert));
            }

            return(false);
        }
        /// <summary>
        /// Resolves the given SecurityKeyIdentifierClause to a SecurityToken.
        /// </summary>
        /// <param name="keyIdentifierClause">SecurityKeyIdentifierClause to resolve.</param>
        /// <param name="token">The resolved SecurityToken.</param>
        /// <returns>True if successfully resolved.</returns>
        /// <exception cref="ArgumentNullException">The input argument 'keyIdentifierClause' is null.</exception>
        protected override bool TryResolveTokenCore(SecurityKeyIdentifierClause keyIdentifierClause, out SecurityToken token)
        {
            if (keyIdentifierClause == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("keyIdentifierClause");
            }

            token = null;
            X509Store store = null;
            X509Certificate2Collection certs = null;

            try
            {
                store = new X509Store(this.storeName, this.storeLocation);
                store.Open(OpenFlags.ReadOnly);
                certs = store.Certificates;
                foreach (X509Certificate2 cert in certs)
                {
                    X509ThumbprintKeyIdentifierClause thumbprintKeyIdentifierClause = keyIdentifierClause as X509ThumbprintKeyIdentifierClause;
                    if (thumbprintKeyIdentifierClause != null && thumbprintKeyIdentifierClause.Matches(cert))
                    {
                        token = new X509SecurityToken(cert);
                        return(true);
                    }

                    X509IssuerSerialKeyIdentifierClause issuerSerialKeyIdentifierClause = keyIdentifierClause as X509IssuerSerialKeyIdentifierClause;
                    if (issuerSerialKeyIdentifierClause != null && issuerSerialKeyIdentifierClause.Matches(cert))
                    {
                        token = new X509SecurityToken(cert);
                        return(true);
                    }

                    X509SubjectKeyIdentifierClause subjectKeyIdentifierClause = keyIdentifierClause as X509SubjectKeyIdentifierClause;
                    if (subjectKeyIdentifierClause != null && subjectKeyIdentifierClause.Matches(cert))
                    {
                        token = new X509SecurityToken(cert);
                        return(true);
                    }

                    X509RawDataKeyIdentifierClause rawDataKeyIdentifierClause = keyIdentifierClause as X509RawDataKeyIdentifierClause;
                    if (rawDataKeyIdentifierClause != null && rawDataKeyIdentifierClause.Matches(cert))
                    {
                        token = new X509SecurityToken(cert);
                        return(true);
                    }
                }
            }
            finally
            {
                if (certs != null)
                {
                    for (int i = 0; i < certs.Count; i++)
                    {
                        certs[i].Reset();
                    }
                }

                if (store != null)
                {
                    store.Close();
                }
            }

            return(false);
        }