| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | using System.Text; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.IdentityModel; |
| | | 9 | | using CoreWCF.IdentityModel.Selectors; |
| | | 10 | | using CoreWCF.IdentityModel.Tokens; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Security.Tokens |
| | | 13 | | { |
| | | 14 | | public class SslSecurityTokenParameters : SecurityTokenParameters |
| | | 15 | | { |
| | | 16 | | internal const bool defaultRequireClientCertificate = false; |
| | | 17 | | internal const bool defaultRequireCancellation = false; |
| | | 18 | | private BindingContext _issuerBindingContext; |
| | | 19 | | |
| | | 20 | | protected SslSecurityTokenParameters(SslSecurityTokenParameters other) |
| | 0 | 21 | | : base(other) |
| | | 22 | | { |
| | 0 | 23 | | RequireClientCertificate = other.RequireClientCertificate; |
| | 0 | 24 | | RequireCancellation = other.RequireCancellation; |
| | 0 | 25 | | if (other._issuerBindingContext != null) |
| | | 26 | | { |
| | 0 | 27 | | _issuerBindingContext = other._issuerBindingContext.Clone(); |
| | | 28 | | } |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | public SslSecurityTokenParameters() |
| | 0 | 32 | | : this(defaultRequireClientCertificate) |
| | | 33 | | { |
| | | 34 | | // empty |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public SslSecurityTokenParameters(bool requireClientCertificate) |
| | 0 | 38 | | : this(requireClientCertificate, defaultRequireCancellation) |
| | | 39 | | { |
| | | 40 | | // empty |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | public SslSecurityTokenParameters(bool requireClientCertificate, bool requireCancellation) |
| | 0 | 44 | | : base() |
| | | 45 | | { |
| | 0 | 46 | | RequireClientCertificate = requireClientCertificate; |
| | 0 | 47 | | RequireCancellation = requireCancellation; |
| | 0 | 48 | | } |
| | | 49 | | |
| | 0 | 50 | | protected internal override bool HasAsymmetricKey { get { return false; } } |
| | | 51 | | |
| | 0 | 52 | | public bool RequireCancellation { get; set; } = defaultRequireCancellation; |
| | | 53 | | |
| | 0 | 54 | | public bool RequireClientCertificate { get; set; } |
| | | 55 | | |
| | | 56 | | internal BindingContext IssuerBindingContext |
| | | 57 | | { |
| | | 58 | | get |
| | | 59 | | { |
| | 0 | 60 | | return _issuerBindingContext; |
| | | 61 | | } |
| | | 62 | | set |
| | | 63 | | { |
| | 0 | 64 | | if (value != null) |
| | | 65 | | { |
| | 0 | 66 | | value = value.Clone(); |
| | | 67 | | } |
| | 0 | 68 | | _issuerBindingContext = value; |
| | 0 | 69 | | } |
| | | 70 | | } |
| | | 71 | | |
| | 0 | 72 | | protected internal override bool SupportsClientAuthentication { get { return RequireClientCertificate; } } |
| | 0 | 73 | | protected internal override bool SupportsServerAuthentication { get { return true; } } |
| | 0 | 74 | | protected internal override bool SupportsClientWindowsIdentity { get { return RequireClientCertificate; } } |
| | | 75 | | |
| | | 76 | | protected override SecurityTokenParameters CloneCore() |
| | | 77 | | { |
| | 0 | 78 | | return new SslSecurityTokenParameters(this); |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | protected internal override SecurityKeyIdentifierClause CreateKeyIdentifierClause(SecurityToken token, SecurityT |
| | | 82 | | { |
| | 0 | 83 | | if (token is GenericXmlSecurityToken) |
| | | 84 | | { |
| | 0 | 85 | | return CreateGenericXmlTokenKeyIdentifierClause(token, referenceStyle); |
| | | 86 | | } |
| | | 87 | | else |
| | | 88 | | { |
| | 0 | 89 | | return CreateKeyIdentifierClause<SecurityContextKeyIdentifierClause, LocalIdKeyIdentifierClause>(token, |
| | | 90 | | } |
| | | 91 | | } |
| | | 92 | | |
| | | 93 | | protected internal override void InitializeSecurityTokenRequirement(SecurityTokenRequirement requirement) |
| | | 94 | | { |
| | 0 | 95 | | requirement.TokenType = (RequireClientCertificate) ? ServiceModelSecurityTokenTypes.MutualSslnego : ServiceM |
| | 0 | 96 | | requirement.RequireCryptographicToken = true; |
| | 0 | 97 | | requirement.KeyType = SecurityKeyType.SymmetricKey; |
| | 0 | 98 | | requirement.Properties[ServiceModelSecurityTokenRequirement.SupportSecurityContextCancellationProperty] = Re |
| | 0 | 99 | | if (IssuerBindingContext != null) |
| | | 100 | | { |
| | 0 | 101 | | requirement.Properties[ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty] = IssuerBindin |
| | | 102 | | } |
| | 0 | 103 | | requirement.Properties[ServiceModelSecurityTokenRequirement.IssuedSecurityTokenParametersProperty] = Clone() |
| | 0 | 104 | | } |
| | | 105 | | |
| | | 106 | | public override string ToString() |
| | | 107 | | { |
| | 0 | 108 | | StringBuilder sb = new StringBuilder(); |
| | 0 | 109 | | sb.AppendLine(base.ToString()); |
| | | 110 | | |
| | 0 | 111 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "RequireCancellation: {0}", RequireCancellation.To |
| | 0 | 112 | | sb.Append(string.Format(CultureInfo.InvariantCulture, "RequireClientCertificate: {0}", RequireClientCertific |
| | | 113 | | |
| | 0 | 114 | | return sb.ToString(); |
| | | 115 | | } |
| | | 116 | | } |
| | | 117 | | } |