本文整理汇总了C#中System.IdentityModel.Tokens.X509SecurityToken类的典型用法代码示例。如果您正苦于以下问题:C# X509SecurityToken类的具体用法?C# X509SecurityToken怎么用?C# X509SecurityToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509SecurityToken类属于System.IdentityModel.Tokens命名空间,在下文中一共展示了X509SecurityToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchesKeyIdentifierClause
public void MatchesKeyIdentifierClause ()
{
UniqueId id = new UniqueId ();
X509SecurityToken t = new X509SecurityToken (cert, id.ToString ());
LocalIdKeyIdentifierClause l =
new LocalIdKeyIdentifierClause (id.ToString ());
Assert.IsTrue (t.MatchesKeyIdentifierClause (l), "#1-1");
l = new LocalIdKeyIdentifierClause ("#" + id.ToString ());
Assert.IsFalse (t.MatchesKeyIdentifierClause (l), "#1-2");
X509ThumbprintKeyIdentifierClause h =
new X509ThumbprintKeyIdentifierClause (cert);
Assert.IsTrue (t.MatchesKeyIdentifierClause (h), "#2-1");
h = new X509ThumbprintKeyIdentifierClause (cert2);
Assert.IsFalse (t.MatchesKeyIdentifierClause (h), "#2-2");
X509IssuerSerialKeyIdentifierClause i =
new X509IssuerSerialKeyIdentifierClause (cert);
Assert.IsTrue (t.MatchesKeyIdentifierClause (i), "#3-1");
i = new X509IssuerSerialKeyIdentifierClause (cert2);
Assert.IsFalse (t.MatchesKeyIdentifierClause (i), "#3-2");
X509RawDataKeyIdentifierClause s =
new X509RawDataKeyIdentifierClause (cert);
Assert.IsTrue (t.MatchesKeyIdentifierClause (s), "#4-1");
s = new X509RawDataKeyIdentifierClause (cert2);
Assert.IsFalse (t.MatchesKeyIdentifierClause (s), "#4-2");
}
示例2: X509EncryptingCredentials
/// <summary>
/// Constructs an encrypting credential based on the x509 token.
/// </summary>
/// <param name="token">The x509 security token.</param>
internal X509EncryptingCredentials(X509SecurityToken token)
: this(
token,
new SecurityKeyIdentifier(token.CreateKeyIdentifierClause<X509IssuerSerialKeyIdentifierClause>()),
SecurityAlgorithms.DefaultAsymmetricKeyWrapAlgorithm)
{
}
示例3: Context_PostAuthenticateRequest
void Context_PostAuthenticateRequest(object sender, EventArgs e)
{
var context = ((HttpApplication)sender).Context;
// no need to call transformation if session already exists
if (FederatedAuthentication.SessionAuthenticationModule != null &&
FederatedAuthentication.SessionAuthenticationModule.ContainsSessionTokenCookie(context.Request.Cookies))
{
return;
}
var transformer = FederatedAuthentication.ServiceConfiguration.ClaimsAuthenticationManager;
if (transformer != null)
{
var principal = context.User as ClaimsPrincipal;
if (context.Request.ClientCertificate.IsPresent && context.Request.ClientCertificate.IsValid)
{
var cert = new X509Certificate2(context.Request.ClientCertificate.Certificate);
var token = new X509SecurityToken(cert);
var certId = new HttpsSecurityTokenHandler().ValidateToken(token).First();
principal.Identities.Add(certId);
}
var transformedPrincipal = transformer.Authenticate(context.Request.RawUrl, principal);
context.User = transformedPrincipal;
Thread.CurrentPrincipal = transformedPrincipal;
}
}
示例4: GetX509TokenFromCert
/// <summary>
/// Utility method to get a X509 Token from a given certificate
/// </summary>
/// <param name="storeName">Name of certificate store (e.g. My, TrustedPeople)</param>
/// <param name="storeLocation">Location of certificate store (e.g. LocalMachine, CurrentUser)</param>
/// <param name="subjectDistinguishedName">The Subject Distinguished Name of the certificate</param>
/// <returns>The corresponding X509 Token</returns>
public static X509SecurityToken GetX509TokenFromCert(StoreName storeName,
StoreLocation storeLocation,
string subjectDistinguishedName)
{
X509Certificate2 certificate = LookupCertificate(storeName, storeLocation, subjectDistinguishedName);
X509SecurityToken t = new X509SecurityToken(certificate);
return t;
}
示例5: DefaultValues
public void DefaultValues ()
{
UniqueId id = new UniqueId ();
X509SecurityToken t = new X509SecurityToken (cert, id.ToString ());
Assert.AreEqual (id.ToString (), t.Id, "#1");
Assert.AreEqual (cert, t.Certificate, "#2");
Assert.AreEqual (cert.NotBefore.ToUniversalTime (), t.ValidFrom, "#3");
Assert.AreEqual (cert.NotAfter.ToUniversalTime (), t.ValidTo, "#4");
Assert.AreEqual (1, t.SecurityKeys.Count, "#5");
}
示例6: GetSigningKeyDescriptor
private KeyDescriptor GetSigningKeyDescriptor()
{
var certificate = _options.SigningCertificate;
var clause = new X509SecurityToken(certificate).CreateKeyIdentifierClause<X509RawDataKeyIdentifierClause>();
var key = new KeyDescriptor(new SecurityKeyIdentifier(clause));
key.Use = KeyType.Signing;
return key;
}
示例7: Properties
public void Properties ()
{
X509ThumbprintKeyIdentifierClause ic =
new X509ThumbprintKeyIdentifierClause (cert);
Assert.AreEqual (cert.GetCertHash (), ic.GetX509Thumbprint (), "#1-1");
Assert.AreEqual (null, ic.ClauseType, "#1-2");
ic = new X509SecurityToken (cert).CreateKeyIdentifierClause<X509ThumbprintKeyIdentifierClause> ();
Assert.AreEqual (cert.GetCertHash (), ic.GetX509Thumbprint (), "#2-1");
Assert.AreEqual (null, ic.ClauseType, "#2-2");
}
示例8: AddDecryptingToken
public void AddDecryptingToken(X509Certificate2 certificate) {
Requires.NotNull(certificate, "certificate");
Requires.True(certificate.HasPrivateKey, "certificate");
var cert = new X509SecurityToken(certificate);
try {
this.AddDecryptingToken(cert);
} catch {
cert.Dispose();
throw;
}
}
示例9: GetReferent
WrappedKeySecurityToken GetReferent ()
{
string id = "referent";
byte [] key = new byte [32];
X509SecurityToken token = new X509SecurityToken (cert);
SecurityKeyIdentifierClause kic =
new X509ThumbprintKeyIdentifierClause (cert);
string alg = SecurityAlgorithms.RsaOaepKeyWrap;
return new WrappedKeySecurityToken (id, key, alg, token,
new SecurityKeyIdentifier (kic));
}
示例10: AddDecryptingToken
public void AddDecryptingToken(X509Certificate2 certificate) {
Contract.Requires<ArgumentNullException>(certificate != null);
Contract.Requires<ArgumentException>(certificate.HasPrivateKey);
var cert = new X509SecurityToken(certificate);
try {
this.AddDecryptingToken(cert);
} catch {
cert.Dispose();
throw;
}
}
示例11: GetValidationParameters
private static TokenValidationParameters GetValidationParameters()
{
var bytes = Convert.FromBase64String(_securityKey.Value);
var token = new X509SecurityToken(new X509Certificate2(bytes));
return new TokenValidationParameters
{
ValidAudience = _authority + "/resources",
ValidIssuer = _authority,
IssuerSigningKeyResolver = (arbitrarily, declaring, these, parameters) => { return token.SecurityKeys.First(); },
IssuerSigningToken = token
};
}
示例12: X509CertTokenVerificationKey
public X509CertTokenVerificationKey(X509Certificate2 cert)
{
lock (_lock)
{
if (_x509Certificate == null)
{
_x509Certificate = cert;
_securityToken = new X509SecurityToken(_x509Certificate);
base.RawBody = _x509Certificate.RawData;
}
}
}
示例13: CreateTlsSspiState
SspiNegotiationTokenProviderState CreateTlsSspiState(X509SecurityToken token)
{
X509Certificate2 clientCertificate;
if (token == null)
{
clientCertificate = null;
}
else
{
clientCertificate = token.Certificate;
}
TlsSspiNegotiation tlsNegotiation = new TlsSspiNegotiation(String.Empty, SchProtocols.Ssl3Client | SchProtocols.TlsClient, clientCertificate);
return new SspiNegotiationTokenProviderState(tlsNegotiation);
}
示例14: ValidateTokenCore
/// <summary>
/// Validates the token using the wrapped token handler and generates IAuthorizationPolicy
/// wrapping the returned ClaimsIdentities.
/// </summary>
/// <param name="token">Token to be validated.</param>
/// <returns>Read-only collection of IAuthorizationPolicy</returns>
protected override ReadOnlyCollection<IAuthorizationPolicy> ValidateTokenCore( SecurityToken token )
{
ReadOnlyCollection<ClaimsIdentity> identities = null;
try
{
identities = _wrappedX509SecurityTokenHandler.ValidateToken(token);
}
catch ( Exception ex )
{
if ( !_exceptionMapper.HandleSecurityTokenProcessingException( ex ) )
{
throw;
}
}
// tlsnego will dispose of the x509, when we write out the bootstrap we will get a dispose error.
bool shouldSaveBootstrapContext = SecurityTokenHandlerConfiguration.DefaultSaveBootstrapContext;
if ( _wrappedX509SecurityTokenHandler.Configuration != null )
{
shouldSaveBootstrapContext = _wrappedX509SecurityTokenHandler.Configuration.SaveBootstrapContext;
}
if ( shouldSaveBootstrapContext )
{
X509SecurityToken x509Token = token as X509SecurityToken;
SecurityToken tokenToCache;
if ( x509Token != null )
{
tokenToCache = new X509SecurityToken( x509Token.Certificate );
}
else
{
tokenToCache = token;
}
BootstrapContext bootstrapContext = new BootstrapContext(tokenToCache, _wrappedX509SecurityTokenHandler);
foreach (ClaimsIdentity identity in identities)
{
identity.BootstrapContext = bootstrapContext;
}
}
List<IAuthorizationPolicy> policies = new List<IAuthorizationPolicy>(1);
policies.Add(new AuthorizationPolicy(identities));
return policies.AsReadOnly();
}
示例15: GetRemoteSecurity
public override SecurityMessageProperty GetRemoteSecurity()
{
if (this.clientSecurity.TransportToken != null)
{
return this.clientSecurity;
}
if (this.clientCertificate != null)
{
SecurityToken token = new X509SecurityToken(this.clientCertificate);
ReadOnlyCollection<IAuthorizationPolicy> tokenPolicies = System.ServiceModel.Security.SecurityUtils.NonValidatingX509Authenticator.ValidateToken(token);
this.clientSecurity = new SecurityMessageProperty();
this.clientSecurity.TransportToken = new SecurityTokenSpecification(token, tokenPolicies);
this.clientSecurity.ServiceSecurityContext = new ServiceSecurityContext(tokenPolicies);
return this.clientSecurity;
}
return base.GetRemoteSecurity();
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:SslStreamSecurityUpgradeAcceptor.cs