SecurityElementBase.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //
  2. // SecurityElementBase.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Collections.ObjectModel;
  32. using System.ComponentModel;
  33. using System.Configuration;
  34. using System.Net;
  35. using System.Net.Security;
  36. using System.Reflection;
  37. using System.Security.Cryptography.X509Certificates;
  38. using System.Security.Principal;
  39. using System.IdentityModel.Claims;
  40. using System.IdentityModel.Policy;
  41. using System.IdentityModel.Tokens;
  42. using System.ServiceModel;
  43. using System.ServiceModel.Channels;
  44. using System.ServiceModel.Description;
  45. using System.ServiceModel.Diagnostics;
  46. using System.ServiceModel.Dispatcher;
  47. using System.ServiceModel.MsmqIntegration;
  48. using System.ServiceModel.PeerResolvers;
  49. using System.ServiceModel.Security;
  50. using System.Runtime.Serialization;
  51. using System.Text;
  52. using System.Xml;
  53. namespace System.ServiceModel.Configuration
  54. {
  55. public class SecurityElementBase
  56. : BindingElementExtensionElement
  57. {
  58. ConfigurationPropertyCollection _properties;
  59. public SecurityElementBase () {
  60. }
  61. // Properties
  62. [ConfigurationProperty ("allowSerializedSigningTokenOnReply",
  63. Options = ConfigurationPropertyOptions.None,
  64. DefaultValue = false)]
  65. public bool AllowSerializedSigningTokenOnReply {
  66. get { return (bool) base ["allowSerializedSigningTokenOnReply"]; }
  67. set { base ["allowSerializedSigningTokenOnReply"] = value; }
  68. }
  69. [ConfigurationProperty ("authenticationMode",
  70. Options = ConfigurationPropertyOptions.None,
  71. DefaultValue = "SspiNegotiated")]
  72. public AuthenticationMode AuthenticationMode {
  73. get { return (AuthenticationMode) base ["authenticationMode"]; }
  74. set { base ["authenticationMode"] = value; }
  75. }
  76. public override Type BindingElementType {
  77. get { return typeof (SecurityBindingElement); }
  78. }
  79. [ConfigurationProperty ("defaultAlgorithmSuite",
  80. Options = ConfigurationPropertyOptions.None,
  81. DefaultValue = "Default")]
  82. [TypeConverter (typeof (SecurityAlgorithmSuiteConverter))]
  83. public SecurityAlgorithmSuite DefaultAlgorithmSuite {
  84. get { return (SecurityAlgorithmSuite) base ["defaultAlgorithmSuite"]; }
  85. set { base ["defaultAlgorithmSuite"] = value; }
  86. }
  87. [ConfigurationProperty ("includeTimestamp",
  88. Options = ConfigurationPropertyOptions.None,
  89. DefaultValue = true)]
  90. public bool IncludeTimestamp {
  91. get { return (bool) base ["includeTimestamp"]; }
  92. set { base ["includeTimestamp"] = value; }
  93. }
  94. [ConfigurationProperty ("issuedTokenParameters",
  95. Options = ConfigurationPropertyOptions.None)]
  96. public IssuedTokenParametersElement IssuedTokenParameters {
  97. get { return (IssuedTokenParametersElement) base ["issuedTokenParameters"]; }
  98. }
  99. [ConfigurationProperty ("keyEntropyMode",
  100. Options = ConfigurationPropertyOptions.None,
  101. DefaultValue = "CombinedEntropy")]
  102. public SecurityKeyEntropyMode KeyEntropyMode {
  103. get { return (SecurityKeyEntropyMode) base ["keyEntropyMode"]; }
  104. set { base ["keyEntropyMode"] = value; }
  105. }
  106. [ConfigurationProperty ("localClientSettings",
  107. Options = ConfigurationPropertyOptions.None)]
  108. public LocalClientSecuritySettingsElement LocalClientSettings {
  109. get { return (LocalClientSecuritySettingsElement) base ["localClientSettings"]; }
  110. }
  111. [ConfigurationProperty ("localServiceSettings",
  112. Options = ConfigurationPropertyOptions.None)]
  113. public LocalServiceSecuritySettingsElement LocalServiceSettings {
  114. get { return (LocalServiceSecuritySettingsElement) base ["localServiceSettings"]; }
  115. }
  116. [ConfigurationProperty ("messageProtectionOrder",
  117. Options = ConfigurationPropertyOptions.None,
  118. DefaultValue = "SignBeforeEncryptAndEncryptSignature")]
  119. public MessageProtectionOrder MessageProtectionOrder {
  120. get { return (MessageProtectionOrder) base ["messageProtectionOrder"]; }
  121. set { base ["messageProtectionOrder"] = value; }
  122. }
  123. [ConfigurationProperty ("messageSecurityVersion",
  124. Options = ConfigurationPropertyOptions.None,
  125. DefaultValue = "Default")]
  126. [TypeConverter (typeof (MessageSecurityVersionConverter))]
  127. public MessageSecurityVersion MessageSecurityVersion {
  128. get { return (MessageSecurityVersion) base ["messageSecurityVersion"]; }
  129. set { base ["messageSecurityVersion"] = value; }
  130. }
  131. protected override ConfigurationPropertyCollection Properties {
  132. get {
  133. if (_properties == null) {
  134. _properties = new ConfigurationPropertyCollection ();
  135. _properties.Add (new ConfigurationProperty ("allowSerializedSigningTokenOnReply", typeof (bool), "false", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
  136. _properties.Add (new ConfigurationProperty ("authenticationMode", typeof (AuthenticationMode), "SspiNegotiated", null, null, ConfigurationPropertyOptions.None));
  137. _properties.Add (new ConfigurationProperty ("defaultAlgorithmSuite", typeof (SecurityAlgorithmSuite), "Default", new SecurityAlgorithmSuiteConverter (), null, ConfigurationPropertyOptions.None));
  138. _properties.Add (new ConfigurationProperty ("includeTimestamp", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
  139. _properties.Add (new ConfigurationProperty ("issuedTokenParameters", typeof (IssuedTokenParametersElement), null, null, null, ConfigurationPropertyOptions.None));
  140. _properties.Add (new ConfigurationProperty ("keyEntropyMode", typeof (SecurityKeyEntropyMode), "CombinedEntropy", null, null, ConfigurationPropertyOptions.None));
  141. _properties.Add (new ConfigurationProperty ("localClientSettings", typeof (LocalClientSecuritySettingsElement), null, null, null, ConfigurationPropertyOptions.None));
  142. _properties.Add (new ConfigurationProperty ("localServiceSettings", typeof (LocalServiceSecuritySettingsElement), null, null, null, ConfigurationPropertyOptions.None));
  143. _properties.Add (new ConfigurationProperty ("messageProtectionOrder", typeof (MessageProtectionOrder), "SignBeforeEncryptAndEncryptSignature", null, null, ConfigurationPropertyOptions.None));
  144. _properties.Add (new ConfigurationProperty ("messageSecurityVersion", typeof (MessageSecurityVersion), "Default", new MessageSecurityVersionConverter (), null, ConfigurationPropertyOptions.None));
  145. _properties.Add (new ConfigurationProperty ("requireDerivedKeys", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
  146. _properties.Add (new ConfigurationProperty ("requireSecurityContextCancellation", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
  147. _properties.Add (new ConfigurationProperty ("requireSignatureConfirmation", typeof (bool), "false", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
  148. _properties.Add (new ConfigurationProperty ("securityHeaderLayout", typeof (SecurityHeaderLayout), "Strict", null, null, ConfigurationPropertyOptions.None));
  149. }
  150. return _properties;
  151. }
  152. }
  153. [ConfigurationProperty ("requireDerivedKeys",
  154. Options = ConfigurationPropertyOptions.None,
  155. DefaultValue = true)]
  156. public bool RequireDerivedKeys {
  157. get { return (bool) base ["requireDerivedKeys"]; }
  158. set { base ["requireDerivedKeys"] = value; }
  159. }
  160. [ConfigurationProperty ("requireSecurityContextCancellation",
  161. Options = ConfigurationPropertyOptions.None,
  162. DefaultValue = true)]
  163. public bool RequireSecurityContextCancellation {
  164. get { return (bool) base ["requireSecurityContextCancellation"]; }
  165. set { base ["requireSecurityContextCancellation"] = value; }
  166. }
  167. [ConfigurationProperty ("requireSignatureConfirmation",
  168. Options = ConfigurationPropertyOptions.None,
  169. DefaultValue = false)]
  170. public bool RequireSignatureConfirmation {
  171. get { return (bool) base ["requireSignatureConfirmation"]; }
  172. set { base ["requireSignatureConfirmation"] = value; }
  173. }
  174. [ConfigurationProperty ("securityHeaderLayout",
  175. Options = ConfigurationPropertyOptions.None,
  176. DefaultValue = "Strict")]
  177. public SecurityHeaderLayout SecurityHeaderLayout {
  178. get { return (SecurityHeaderLayout) base ["securityHeaderLayout"]; }
  179. set { base ["securityHeaderLayout"] = value; }
  180. }
  181. [MonoTODO]
  182. protected internal override BindingElement CreateBindingElement () {
  183. throw new NotImplementedException ();
  184. }
  185. }
  186. }