| | | 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 CoreWCF.Runtime; |
| | | 6 | | using CoreWCF.Security; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public sealed class LocalServiceSecuritySettings |
| | | 11 | | { |
| | | 12 | | //Move these to NegotiationTokenAuthenticator |
| | | 13 | | internal const string defaultServerMaxNegotiationLifetimeString = "00:01:00"; |
| | | 14 | | internal const string defaultServerIssuedTokenLifetimeString = "10:00:00"; |
| | | 15 | | internal const string defaultServerIssuedTransitionTokenLifetimeString = "00:15:00"; |
| | | 16 | | internal const int defaultServerMaxActiveNegotiations = 128; |
| | | 17 | | private int _replayCacheSize; |
| | | 18 | | private TimeSpan _replayWindow; |
| | | 19 | | private TimeSpan _maxClockSkew; |
| | | 20 | | private TimeSpan _issuedCookieLifetime; |
| | | 21 | | private int _maxStatefulNegotiations; |
| | | 22 | | private TimeSpan _negotiationTimeout; |
| | | 23 | | private int _maxCachedCookies; |
| | | 24 | | private int _maxPendingSessions; |
| | | 25 | | private TimeSpan _inactivityTimeout; |
| | | 26 | | private TimeSpan _sessionKeyRenewalInterval; |
| | | 27 | | private TimeSpan _sessionKeyRolloverInterval; |
| | | 28 | | private TimeSpan _timestampValidityDuration; |
| | | 29 | | |
| | 1392 | 30 | | private LocalServiceSecuritySettings(LocalServiceSecuritySettings other) |
| | | 31 | | { |
| | 1392 | 32 | | DetectReplays = other.DetectReplays; |
| | 1392 | 33 | | _replayCacheSize = other._replayCacheSize; |
| | 1392 | 34 | | _replayWindow = other._replayWindow; |
| | 1392 | 35 | | _maxClockSkew = other._maxClockSkew; |
| | 1392 | 36 | | _issuedCookieLifetime = other._issuedCookieLifetime; |
| | 1392 | 37 | | _maxStatefulNegotiations = other._maxStatefulNegotiations; |
| | 1392 | 38 | | _negotiationTimeout = other._negotiationTimeout; |
| | 1392 | 39 | | _maxPendingSessions = other._maxPendingSessions; |
| | 1392 | 40 | | _inactivityTimeout = other._inactivityTimeout; |
| | 1392 | 41 | | _sessionKeyRenewalInterval = other._sessionKeyRenewalInterval; |
| | 1392 | 42 | | _sessionKeyRolloverInterval = other._sessionKeyRolloverInterval; |
| | 1392 | 43 | | ReconnectTransportOnFailure = other.ReconnectTransportOnFailure; |
| | 1392 | 44 | | _timestampValidityDuration = other._timestampValidityDuration; |
| | 1392 | 45 | | _maxCachedCookies = other._maxCachedCookies; |
| | 1392 | 46 | | NonceCache = other.NonceCache; |
| | 1392 | 47 | | } |
| | | 48 | | |
| | 3636 | 49 | | public bool DetectReplays { get; set; } |
| | | 50 | | |
| | | 51 | | public int ReplayCacheSize |
| | | 52 | | { |
| | | 53 | | get |
| | | 54 | | { |
| | 55 | 55 | | return _replayCacheSize; |
| | | 56 | | } |
| | | 57 | | set |
| | | 58 | | { |
| | 373 | 59 | | if (value < 0) |
| | | 60 | | { |
| | 0 | 61 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 62 | | SRCommon.ValueMustBeNonNegative)); |
| | | 63 | | } |
| | 373 | 64 | | _replayCacheSize = value; |
| | 373 | 65 | | } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | public TimeSpan ReplayWindow |
| | | 69 | | { |
| | | 70 | | get |
| | | 71 | | { |
| | 55 | 72 | | return _replayWindow; |
| | | 73 | | } |
| | | 74 | | set |
| | | 75 | | { |
| | 373 | 76 | | if (value < TimeSpan.Zero) |
| | | 77 | | { |
| | 0 | 78 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 79 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 80 | | } |
| | | 81 | | |
| | 373 | 82 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 83 | | { |
| | 0 | 84 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 85 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 86 | | } |
| | | 87 | | |
| | 373 | 88 | | _replayWindow = value; |
| | 373 | 89 | | } |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | public TimeSpan MaxClockSkew |
| | | 93 | | { |
| | | 94 | | get |
| | | 95 | | { |
| | 55 | 96 | | return _maxClockSkew; |
| | | 97 | | } |
| | | 98 | | set |
| | | 99 | | { |
| | 374 | 100 | | if (value < TimeSpan.Zero) |
| | | 101 | | { |
| | 0 | 102 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 103 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 104 | | } |
| | | 105 | | |
| | 374 | 106 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 107 | | { |
| | 0 | 108 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 109 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 110 | | } |
| | | 111 | | |
| | 374 | 112 | | _maxClockSkew = value; |
| | 374 | 113 | | } |
| | | 114 | | } |
| | | 115 | | |
| | 3156 | 116 | | public NonceCache NonceCache { get; set; } = null; |
| | | 117 | | |
| | | 118 | | public TimeSpan IssuedCookieLifetime |
| | | 119 | | { |
| | | 120 | | get |
| | | 121 | | { |
| | 1 | 122 | | return _issuedCookieLifetime; |
| | | 123 | | } |
| | | 124 | | set |
| | | 125 | | { |
| | 495 | 126 | | if (value < TimeSpan.Zero) |
| | | 127 | | { |
| | 0 | 128 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 129 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 130 | | } |
| | | 131 | | |
| | 495 | 132 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 133 | | { |
| | 0 | 134 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 135 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 136 | | } |
| | | 137 | | |
| | 495 | 138 | | _issuedCookieLifetime = value; |
| | 495 | 139 | | } |
| | | 140 | | } |
| | | 141 | | |
| | | 142 | | public int MaxStatefulNegotiations |
| | | 143 | | { |
| | | 144 | | get |
| | | 145 | | { |
| | 24 | 146 | | return _maxStatefulNegotiations; |
| | | 147 | | } |
| | | 148 | | set |
| | | 149 | | { |
| | 373 | 150 | | if (value < 0) |
| | | 151 | | { |
| | 0 | 152 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 153 | | SRCommon.ValueMustBeNonNegative)); |
| | | 154 | | } |
| | 373 | 155 | | _maxStatefulNegotiations = value; |
| | 373 | 156 | | } |
| | | 157 | | } |
| | | 158 | | |
| | | 159 | | public TimeSpan NegotiationTimeout |
| | | 160 | | { |
| | | 161 | | get |
| | | 162 | | { |
| | 23 | 163 | | return _negotiationTimeout; |
| | | 164 | | } |
| | | 165 | | set |
| | | 166 | | { |
| | 745 | 167 | | if (value < TimeSpan.Zero) |
| | | 168 | | { |
| | 0 | 169 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 170 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 171 | | } |
| | | 172 | | |
| | 745 | 173 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 174 | | { |
| | 0 | 175 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 176 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 177 | | } |
| | | 178 | | |
| | 745 | 179 | | _negotiationTimeout = value; |
| | 745 | 180 | | } |
| | | 181 | | } |
| | | 182 | | |
| | | 183 | | public int MaxPendingSessions |
| | | 184 | | { |
| | | 185 | | get |
| | | 186 | | { |
| | 22 | 187 | | return _maxPendingSessions; |
| | | 188 | | } |
| | | 189 | | set |
| | | 190 | | { |
| | 1 | 191 | | if (value < 0) |
| | | 192 | | { |
| | 0 | 193 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 194 | | SRCommon.ValueMustBeNonNegative)); |
| | | 195 | | } |
| | 1 | 196 | | _maxPendingSessions = value; |
| | 1 | 197 | | } |
| | | 198 | | } |
| | | 199 | | |
| | | 200 | | public TimeSpan InactivityTimeout |
| | | 201 | | { |
| | | 202 | | get |
| | | 203 | | { |
| | 22 | 204 | | return _inactivityTimeout; |
| | | 205 | | } |
| | | 206 | | set |
| | | 207 | | { |
| | 5 | 208 | | if (value < TimeSpan.Zero) |
| | | 209 | | { |
| | 0 | 210 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 211 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 212 | | } |
| | | 213 | | |
| | 5 | 214 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 215 | | { |
| | 0 | 216 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 217 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 218 | | } |
| | | 219 | | |
| | 5 | 220 | | _inactivityTimeout = value; |
| | 5 | 221 | | } |
| | | 222 | | } |
| | | 223 | | |
| | | 224 | | public TimeSpan SessionKeyRenewalInterval |
| | | 225 | | { |
| | | 226 | | get |
| | | 227 | | { |
| | 44 | 228 | | return _sessionKeyRenewalInterval; |
| | | 229 | | } |
| | | 230 | | set |
| | | 231 | | { |
| | 1 | 232 | | if (value < TimeSpan.Zero) |
| | | 233 | | { |
| | 0 | 234 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 235 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 236 | | } |
| | | 237 | | |
| | 1 | 238 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 239 | | { |
| | 0 | 240 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 241 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 242 | | } |
| | | 243 | | |
| | 1 | 244 | | _sessionKeyRenewalInterval = value; |
| | 1 | 245 | | } |
| | | 246 | | } |
| | | 247 | | |
| | | 248 | | public TimeSpan SessionKeyRolloverInterval |
| | | 249 | | { |
| | | 250 | | get |
| | | 251 | | { |
| | 22 | 252 | | return _sessionKeyRolloverInterval; |
| | | 253 | | } |
| | | 254 | | set |
| | | 255 | | { |
| | 1 | 256 | | if (value < TimeSpan.Zero) |
| | | 257 | | { |
| | 0 | 258 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 259 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 260 | | } |
| | | 261 | | |
| | 1 | 262 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 263 | | { |
| | 0 | 264 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 265 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 266 | | } |
| | | 267 | | |
| | 1 | 268 | | _sessionKeyRolloverInterval = value; |
| | 1 | 269 | | } |
| | | 270 | | } |
| | | 271 | | |
| | 3353 | 272 | | public bool ReconnectTransportOnFailure { get; set; } |
| | | 273 | | |
| | | 274 | | public TimeSpan TimestampValidityDuration |
| | | 275 | | { |
| | | 276 | | get |
| | | 277 | | { |
| | 55 | 278 | | return _timestampValidityDuration; |
| | | 279 | | } |
| | | 280 | | set |
| | | 281 | | { |
| | 373 | 282 | | if (value < TimeSpan.Zero) |
| | | 283 | | { |
| | 0 | 284 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 285 | | SR.Format(SRCommon.SFxTimeoutOutOfRange0))); |
| | | 286 | | } |
| | | 287 | | |
| | 373 | 288 | | if (TimeoutHelper.IsTooLarge(value)) |
| | | 289 | | { |
| | 0 | 290 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 291 | | SRCommon.SFxTimeoutOutOfRangeTooBig)); |
| | | 292 | | } |
| | | 293 | | |
| | 373 | 294 | | _timestampValidityDuration = value; |
| | 373 | 295 | | } |
| | | 296 | | } |
| | | 297 | | |
| | | 298 | | public int MaxCachedCookies |
| | | 299 | | { |
| | | 300 | | get |
| | | 301 | | { |
| | 1 | 302 | | return _maxCachedCookies; |
| | | 303 | | } |
| | | 304 | | set |
| | | 305 | | { |
| | 1 | 306 | | if (value < 0) |
| | | 307 | | { |
| | 0 | 308 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 309 | | SRCommon.ValueMustBeNonNegative)); |
| | | 310 | | } |
| | 1 | 311 | | _maxCachedCookies = value; |
| | 1 | 312 | | } |
| | | 313 | | } |
| | | 314 | | |
| | 372 | 315 | | public LocalServiceSecuritySettings() |
| | | 316 | | { |
| | 372 | 317 | | DetectReplays = SecurityProtocolFactory.defaultDetectReplays; |
| | 372 | 318 | | ReplayCacheSize = SecurityProtocolFactory.defaultMaxCachedNonces; |
| | 372 | 319 | | ReplayWindow = SecurityProtocolFactory.defaultReplayWindow; |
| | 372 | 320 | | MaxClockSkew = SecurityProtocolFactory.defaultMaxClockSkew; |
| | 372 | 321 | | NegotiationTimeout = TimeSpan.FromMinutes(1); |
| | 372 | 322 | | IssuedCookieLifetime = TimeSpan.FromHours(10); |
| | 372 | 323 | | MaxStatefulNegotiations = 128; //NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorState>.defaultSe |
| | 372 | 324 | | NegotiationTimeout = TimeSpan.FromMinutes(1);// NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorS |
| | 372 | 325 | | _maxPendingSessions = SecuritySessionServerSettings.DefaultMaximumPendingSessions; |
| | 372 | 326 | | _inactivityTimeout = SecuritySessionServerSettings.s_defaultInactivityTimeout; |
| | 372 | 327 | | _sessionKeyRenewalInterval = SecuritySessionServerSettings.s_defaultKeyRenewalInterval; |
| | 372 | 328 | | _sessionKeyRolloverInterval = SecuritySessionServerSettings.s_defaultKeyRolloverInterval; |
| | 372 | 329 | | ReconnectTransportOnFailure = SecuritySessionServerSettings.DefaultTolerateTransportFailures; |
| | 372 | 330 | | TimestampValidityDuration = SecurityProtocolFactory.defaultTimestampValidityDuration; |
| | 372 | 331 | | _maxCachedCookies = 1000; // NegotiationTokenAuthenticator<NegotiationTokenAuthenticatorState>.defaultServer |
| | 372 | 332 | | NonceCache = null; |
| | 372 | 333 | | } |
| | | 334 | | |
| | | 335 | | public LocalServiceSecuritySettings Clone() |
| | | 336 | | { |
| | 1392 | 337 | | return new LocalServiceSecuritySettings(this); |
| | | 338 | | } |
| | | 339 | | } |
| | | 340 | | } |