Exemple #1
0
 internal X509SigningCredentials(
     X509SecurityToken token,
     SecurityKeyIdentifier ski,
     string signatureAlgorithm,
     string digestAlgorithm)
     : base(token.SecurityKeys[0], signatureAlgorithm, digestAlgorithm, ski)
 {
     this.certificate = token.Certificate;
     if (!this.certificate.HasPrivateKey)
     {
         throw new Exception("Certificate has no private key");
     }
 }
Exemple #2
0
        /// <summary>Returns the issuer name associated with the specified <see cref="T:System.IdentityModel.Tokens.X509SecurityToken" /> by mapping the certificate thumbprint to a name in the trusted issuers dictionary.</summary>
        /// <param name="securityToken">The security token for which the issuer name is requested. Should be assignable as <see cref="T:System.IdentityModel.Tokens.X509SecurityToken" />.</param>
        /// <returns>The issuer name if an entry for the certificate thumbprint of the token exists in the <see cref="P:System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry.ConfiguredTrustedIssuers" /> dictionary; otherwise, <see langword="null" />.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="securityToken" /> is <see langword="null" />.</exception>
        public override string GetIssuerName(SecurityToken securityToken)
        {
            if (securityToken == null)
            {
                throw new ArgumentNullException(nameof(securityToken));
            }
            X509SecurityToken x509SecurityToken = securityToken as X509SecurityToken;

            if (x509SecurityToken != null)
            {
                string thumbprint = x509SecurityToken.Certificate.Thumbprint;
                if (this._configuredTrustedIssuers.ContainsKey(thumbprint))
                {
                    string configuredTrustedIssuer = this._configuredTrustedIssuers[thumbprint];
                    string issuerName = string.IsNullOrEmpty(configuredTrustedIssuer) ? x509SecurityToken.Certificate.Subject : configuredTrustedIssuer;
                    return(issuerName);
                }
            }
            return((string)null);
        }