TrustDriver.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Description;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Diagnostics;
  13. using System.Runtime.Serialization;
  14. using System.IdentityModel.Claims;
  15. using System.IdentityModel.Policy;
  16. using System.IdentityModel.Selectors;
  17. using System.IdentityModel.Tokens;
  18. using System.Security.Principal;
  19. using System.Security.Cryptography;
  20. using System.ServiceModel.Security.Tokens;
  21. using System.Xml;
  22. abstract class TrustDriver
  23. {
  24. // issued tokens control
  25. public virtual bool IsIssuedTokensSupported
  26. {
  27. get
  28. {
  29. return false;
  30. }
  31. }
  32. // issued tokens feature
  33. public virtual string IssuedTokensHeaderName
  34. {
  35. get
  36. {
  37. // PreSharp Bug: Property get methods should not throw exceptions.
  38. #pragma warning suppress 56503
  39. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TrustDriverVersionDoesNotSupportIssuedTokens)));
  40. }
  41. }
  42. // issued tokens feature
  43. public virtual string IssuedTokensHeaderNamespace
  44. {
  45. get
  46. {
  47. // PreSharp Bug: Property get methods should not throw exceptions.
  48. #pragma warning suppress 56503
  49. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TrustDriverVersionDoesNotSupportIssuedTokens)));
  50. }
  51. }
  52. // session control
  53. public virtual bool IsSessionSupported
  54. {
  55. get
  56. {
  57. return false;
  58. }
  59. }
  60. public abstract XmlDictionaryString RequestSecurityTokenAction { get; }
  61. public abstract XmlDictionaryString RequestSecurityTokenResponseAction { get; }
  62. public abstract XmlDictionaryString RequestSecurityTokenResponseFinalAction { get; }
  63. // session feature
  64. public virtual string RequestTypeClose
  65. {
  66. get
  67. {
  68. // PreSharp Bug: Property get methods should not throw exceptions.
  69. #pragma warning suppress 56503
  70. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TrustDriverVersionDoesNotSupportSession)));
  71. }
  72. }
  73. public abstract string RequestTypeIssue { get; }
  74. // session feature
  75. public virtual string RequestTypeRenew
  76. {
  77. get
  78. {
  79. // PreSharp Bug: Property get methods should not throw exceptions.
  80. #pragma warning suppress 56503
  81. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TrustDriverVersionDoesNotSupportSession)));
  82. }
  83. }
  84. public abstract string ComputedKeyAlgorithm { get; }
  85. public abstract SecurityStandardsManager StandardsManager { get; }
  86. public abstract XmlDictionaryString Namespace { get; }
  87. // RST specific method
  88. public abstract RequestSecurityToken CreateRequestSecurityToken(XmlReader reader);
  89. // RSTR specific method
  90. public abstract RequestSecurityTokenResponse CreateRequestSecurityTokenResponse(XmlReader reader);
  91. // RSTRC specific method
  92. public abstract RequestSecurityTokenResponseCollection CreateRequestSecurityTokenResponseCollection(XmlReader xmlReader);
  93. public abstract bool IsAtRequestSecurityTokenResponse(XmlReader reader);
  94. public abstract bool IsAtRequestSecurityTokenResponseCollection(XmlReader reader);
  95. public abstract bool IsRequestedSecurityTokenElement(string name, string nameSpace);
  96. public abstract bool IsRequestedProofTokenElement(string name, string nameSpace);
  97. public abstract T GetAppliesTo<T>(RequestSecurityToken rst, XmlObjectSerializer serializer);
  98. public abstract T GetAppliesTo<T>(RequestSecurityTokenResponse rstr, XmlObjectSerializer serializer);
  99. public abstract void GetAppliesToQName(RequestSecurityToken rst, out string localName, out string namespaceUri);
  100. public abstract void GetAppliesToQName(RequestSecurityTokenResponse rstr, out string localName, out string namespaceUri);
  101. public abstract bool IsAppliesTo(string localName, string namespaceUri);
  102. // RSTR specific method
  103. public abstract byte[] GetAuthenticator(RequestSecurityTokenResponse rstr);
  104. // RST specific method
  105. public abstract BinaryNegotiation GetBinaryNegotiation(RequestSecurityToken rst);
  106. // RSTR specific method
  107. public abstract BinaryNegotiation GetBinaryNegotiation(RequestSecurityTokenResponse rstr);
  108. // RST specific method
  109. public abstract SecurityToken GetEntropy(RequestSecurityToken rst, SecurityTokenResolver resolver);
  110. // RSTR specific method
  111. public abstract SecurityToken GetEntropy(RequestSecurityTokenResponse rstr, SecurityTokenResolver resolver);
  112. // RSTR specific method
  113. public abstract GenericXmlSecurityToken GetIssuedToken(RequestSecurityTokenResponse rstr, SecurityTokenResolver resolver, IList<SecurityTokenAuthenticator> allowedAuthenticators, SecurityKeyEntropyMode keyEntropyMode, byte[] requestorEntropy,
  114. string expectedTokenType, ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies, int defaultKeySize, bool isBearerKeyType);
  115. public abstract GenericXmlSecurityToken GetIssuedToken(RequestSecurityTokenResponse rstr, string expectedTokenType, ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies, RSA clientKey);
  116. public abstract void OnRSTRorRSTRCMissingException();
  117. // RST specific method
  118. public abstract void WriteRequestSecurityToken(RequestSecurityToken rst, XmlWriter w);
  119. // RSTR specific method
  120. public abstract void WriteRequestSecurityTokenResponse(RequestSecurityTokenResponse rstr, XmlWriter w);
  121. // RSTR Collection method
  122. public abstract void WriteRequestSecurityTokenResponseCollection(RequestSecurityTokenResponseCollection rstrCollection, XmlWriter writer);
  123. // Federation proxy creation
  124. public abstract IChannelFactory<IRequestChannel> CreateFederationProxy(EndpointAddress address, Binding binding, KeyedByTypeCollection<IEndpointBehavior> channelBehaviors);
  125. public abstract XmlElement CreateKeySizeElement(int keySize);
  126. public abstract XmlElement CreateKeyTypeElement(SecurityKeyType keyType);
  127. public abstract XmlElement CreateTokenTypeElement(string tokenTypeUri);
  128. public abstract XmlElement CreateRequiredClaimsElement(IEnumerable<XmlElement> claimsList);
  129. public abstract XmlElement CreateUseKeyElement(SecurityKeyIdentifier keyIdentifier, SecurityStandardsManager standardsManager);
  130. public abstract XmlElement CreateSignWithElement(string signatureAlgorithm);
  131. public abstract XmlElement CreateEncryptWithElement(string encryptionAlgorithm);
  132. public abstract XmlElement CreateEncryptionAlgorithmElement(string encryptionAlgorithm);
  133. public abstract XmlElement CreateCanonicalizationAlgorithmElement(string canonicalicationAlgorithm);
  134. public abstract XmlElement CreateComputedKeyAlgorithmElement(string computedKeyAlgorithm);
  135. public abstract Collection<XmlElement> ProcessUnknownRequestParameters(Collection<XmlElement> unknownRequestParameters, Collection<XmlElement> originalRequestParameters);
  136. public abstract bool TryParseKeySizeElement(XmlElement element, out int keySize);
  137. public abstract bool TryParseKeyTypeElement(XmlElement element, out SecurityKeyType keyType);
  138. public abstract bool TryParseTokenTypeElement(XmlElement element, out string tokenType);
  139. public abstract bool TryParseRequiredClaimsElement(XmlElement element, out Collection<XmlElement> requiredClaims);
  140. // helper methods for the parsing standard binding elements
  141. internal virtual bool IsSignWithElement(XmlElement element, out string signatureAlgorithm) { signatureAlgorithm = null; return false; }
  142. internal virtual bool IsEncryptWithElement(XmlElement element, out string encryptWithAlgorithm) { encryptWithAlgorithm = null; return false; }
  143. internal virtual bool IsEncryptionAlgorithmElement(XmlElement element, out string encryptionAlgorithm) { encryptionAlgorithm = null; return false; }
  144. internal virtual bool IsCanonicalizationAlgorithmElement(XmlElement element, out string canonicalizationAlgorithm) { canonicalizationAlgorithm = null; return false; }
  145. internal virtual bool IsKeyWrapAlgorithmElement(XmlElement element, out string keyWrapAlgorithm) { keyWrapAlgorithm = null; return false; }
  146. }
  147. }