LocalClientSecuritySettings.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System;
  7. using System.Runtime;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Security;
  10. public sealed class LocalClientSecuritySettings
  11. {
  12. bool detectReplays;
  13. int replayCacheSize;
  14. TimeSpan replayWindow;
  15. TimeSpan maxClockSkew;
  16. bool cacheCookies;
  17. TimeSpan maxCookieCachingTime;
  18. TimeSpan sessionKeyRenewalInterval;
  19. TimeSpan sessionKeyRolloverInterval;
  20. bool reconnectTransportOnFailure;
  21. TimeSpan timestampValidityDuration;
  22. IdentityVerifier identityVerifier;
  23. int cookieRenewalThresholdPercentage;
  24. NonceCache nonceCache = null;
  25. LocalClientSecuritySettings(LocalClientSecuritySettings other)
  26. {
  27. this.detectReplays = other.detectReplays;
  28. this.replayCacheSize = other.replayCacheSize;
  29. this.replayWindow = other.replayWindow;
  30. this.maxClockSkew = other.maxClockSkew;
  31. this.cacheCookies = other.cacheCookies;
  32. this.maxCookieCachingTime = other.maxCookieCachingTime;
  33. this.sessionKeyRenewalInterval = other.sessionKeyRenewalInterval;
  34. this.sessionKeyRolloverInterval = other.sessionKeyRolloverInterval;
  35. this.reconnectTransportOnFailure = other.reconnectTransportOnFailure;
  36. this.timestampValidityDuration = other.timestampValidityDuration;
  37. this.identityVerifier = other.identityVerifier;
  38. this.cookieRenewalThresholdPercentage = other.cookieRenewalThresholdPercentage;
  39. this.nonceCache = other.nonceCache;
  40. }
  41. public bool DetectReplays
  42. {
  43. get
  44. {
  45. return this.detectReplays;
  46. }
  47. set
  48. {
  49. this.detectReplays = value;
  50. }
  51. }
  52. public int ReplayCacheSize
  53. {
  54. get
  55. {
  56. return this.replayCacheSize;
  57. }
  58. set
  59. {
  60. if (value < 0)
  61. {
  62. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  63. SR.GetString(SR.ValueMustBeNonNegative)));
  64. }
  65. this.replayCacheSize = value;
  66. }
  67. }
  68. public TimeSpan ReplayWindow
  69. {
  70. get
  71. {
  72. return this.replayWindow;
  73. }
  74. set
  75. {
  76. if (value < TimeSpan.Zero)
  77. {
  78. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  79. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  80. }
  81. if (TimeoutHelper.IsTooLarge(value))
  82. {
  83. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  84. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  85. }
  86. this.replayWindow = value;
  87. }
  88. }
  89. public TimeSpan MaxClockSkew
  90. {
  91. get
  92. {
  93. return this.maxClockSkew;
  94. }
  95. set
  96. {
  97. if (value < TimeSpan.Zero)
  98. {
  99. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  100. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  101. }
  102. if (TimeoutHelper.IsTooLarge(value))
  103. {
  104. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  105. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  106. }
  107. this.maxClockSkew = value;
  108. }
  109. }
  110. public NonceCache NonceCache
  111. {
  112. get
  113. {
  114. return this.nonceCache;
  115. }
  116. set
  117. {
  118. this.nonceCache = value;
  119. }
  120. }
  121. public TimeSpan TimestampValidityDuration
  122. {
  123. get
  124. {
  125. return this.timestampValidityDuration;
  126. }
  127. set
  128. {
  129. if (value < TimeSpan.Zero)
  130. {
  131. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  132. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  133. }
  134. if (TimeoutHelper.IsTooLarge(value))
  135. {
  136. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  137. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  138. }
  139. this.timestampValidityDuration = value;
  140. }
  141. }
  142. public bool CacheCookies
  143. {
  144. get
  145. {
  146. return this.cacheCookies;
  147. }
  148. set
  149. {
  150. this.cacheCookies = value;
  151. }
  152. }
  153. public TimeSpan MaxCookieCachingTime
  154. {
  155. get
  156. {
  157. return this.maxCookieCachingTime;
  158. }
  159. set
  160. {
  161. if (value < TimeSpan.Zero)
  162. {
  163. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  164. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  165. }
  166. if (TimeoutHelper.IsTooLarge(value))
  167. {
  168. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  169. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  170. }
  171. this.maxCookieCachingTime = value;
  172. }
  173. }
  174. public int CookieRenewalThresholdPercentage
  175. {
  176. get
  177. {
  178. return this.cookieRenewalThresholdPercentage;
  179. }
  180. set
  181. {
  182. if (value < 0 || value > 100)
  183. {
  184. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  185. SR.GetString(SR.ValueMustBeInRange, 0, 100)));
  186. }
  187. this.cookieRenewalThresholdPercentage = value;
  188. }
  189. }
  190. public TimeSpan SessionKeyRenewalInterval
  191. {
  192. get
  193. {
  194. return this.sessionKeyRenewalInterval;
  195. }
  196. set
  197. {
  198. if (value < TimeSpan.Zero)
  199. {
  200. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  201. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  202. }
  203. if (TimeoutHelper.IsTooLarge(value))
  204. {
  205. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  206. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  207. }
  208. this.sessionKeyRenewalInterval = value;
  209. }
  210. }
  211. public TimeSpan SessionKeyRolloverInterval
  212. {
  213. get
  214. {
  215. return this.sessionKeyRolloverInterval;
  216. }
  217. set
  218. {
  219. if (value < TimeSpan.Zero)
  220. {
  221. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  222. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  223. }
  224. if (TimeoutHelper.IsTooLarge(value))
  225. {
  226. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  227. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  228. }
  229. this.sessionKeyRolloverInterval = value;
  230. }
  231. }
  232. public bool ReconnectTransportOnFailure
  233. {
  234. get
  235. {
  236. return this.reconnectTransportOnFailure;
  237. }
  238. set
  239. {
  240. this.reconnectTransportOnFailure = value;
  241. }
  242. }
  243. public IdentityVerifier IdentityVerifier
  244. {
  245. get
  246. {
  247. return this.identityVerifier;
  248. }
  249. set
  250. {
  251. this.identityVerifier = value;
  252. }
  253. }
  254. public LocalClientSecuritySettings()
  255. {
  256. this.DetectReplays = SecurityProtocolFactory.defaultDetectReplays;
  257. this.ReplayCacheSize = SecurityProtocolFactory.defaultMaxCachedNonces;
  258. this.ReplayWindow = SecurityProtocolFactory.defaultReplayWindow;
  259. this.MaxClockSkew = SecurityProtocolFactory.defaultMaxClockSkew;
  260. this.TimestampValidityDuration = SecurityProtocolFactory.defaultTimestampValidityDuration;
  261. this.CacheCookies = IssuanceTokenProviderBase<IssuanceTokenProviderState>.defaultClientCacheTokens;
  262. this.MaxCookieCachingTime = IssuanceTokenProviderBase<IssuanceTokenProviderState>.DefaultClientMaxTokenCachingTime;
  263. this.SessionKeyRenewalInterval = SecuritySessionClientSettings.defaultKeyRenewalInterval;
  264. this.SessionKeyRolloverInterval = SecuritySessionClientSettings.defaultKeyRolloverInterval;
  265. this.ReconnectTransportOnFailure = SecuritySessionClientSettings.defaultTolerateTransportFailures;
  266. this.CookieRenewalThresholdPercentage = SpnegoTokenProvider.defaultServiceTokenValidityThresholdPercentage;
  267. this.IdentityVerifier = IdentityVerifier.CreateDefault();
  268. this.nonceCache = null;
  269. }
  270. public LocalClientSecuritySettings Clone()
  271. {
  272. return new LocalClientSecuritySettings(this);
  273. }
  274. }
  275. }