| | | 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.Threading.Tasks; |
| | | 6 | | using CoreWCF.Security.Tokens; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Security |
| | | 9 | | { |
| | | 10 | | internal class SessionSymmetricTransportSecurityProtocolFactory : TransportSecurityProtocolFactory |
| | | 11 | | { |
| | | 12 | | private SecurityTokenParameters _securityTokenParameters; |
| | | 13 | | private SessionDerivedKeySecurityTokenParameters _derivedKeyTokenParameters; |
| | | 14 | | |
| | 22 | 15 | | public SessionSymmetricTransportSecurityProtocolFactory() : base() |
| | | 16 | | { |
| | 22 | 17 | | } |
| | | 18 | | |
| | 0 | 19 | | public override bool SupportsReplayDetection => true; |
| | | 20 | | |
| | | 21 | | public SecurityTokenParameters SecurityTokenParameters |
| | | 22 | | { |
| | | 23 | | get |
| | | 24 | | { |
| | 128 | 25 | | return _securityTokenParameters; |
| | | 26 | | } |
| | | 27 | | set |
| | | 28 | | { |
| | 44 | 29 | | ThrowIfImmutable(); |
| | 44 | 30 | | _securityTokenParameters = value; |
| | 44 | 31 | | } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | internal override SecurityProtocol OnCreateSecurityProtocol(EndpointAddress target, Uri via, TimeSpan timeout) |
| | | 35 | | { |
| | 10 | 36 | | if (SecurityTokenParameters == null) |
| | | 37 | | { |
| | 0 | 38 | | OnPropertySettingsError(nameof(SecurityTokenParameters), true); |
| | | 39 | | } |
| | 10 | 40 | | if (SecurityTokenParameters.RequireDerivedKeys) |
| | | 41 | | { |
| | 0 | 42 | | ExpectKeyDerivation = true; |
| | 0 | 43 | | _derivedKeyTokenParameters = new SessionDerivedKeySecurityTokenParameters(ActAsInitiator); |
| | | 44 | | } |
| | 10 | 45 | | return new AcceptorSessionSymmetricTransportSecurityProtocol(this); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public override Task OnOpenAsync(TimeSpan timeout) |
| | | 49 | | { |
| | 22 | 50 | | base.OnOpenAsync(timeout); |
| | 22 | 51 | | if (SecurityTokenParameters == null) |
| | | 52 | | { |
| | 0 | 53 | | OnPropertySettingsError(nameof(SecurityTokenParameters), true); |
| | | 54 | | } |
| | 22 | 55 | | if (SecurityTokenParameters.RequireDerivedKeys) |
| | | 56 | | { |
| | 0 | 57 | | ExpectKeyDerivation = true; |
| | 0 | 58 | | _derivedKeyTokenParameters = new SessionDerivedKeySecurityTokenParameters(ActAsInitiator); |
| | | 59 | | } |
| | 22 | 60 | | return Task.CompletedTask; |
| | | 61 | | } |
| | | 62 | | |
| | | 63 | | internal SecurityTokenParameters GetTokenParameters() |
| | | 64 | | { |
| | 0 | 65 | | if (_derivedKeyTokenParameters != null) |
| | | 66 | | { |
| | 0 | 67 | | return _derivedKeyTokenParameters; |
| | | 68 | | } |
| | | 69 | | else |
| | | 70 | | { |
| | 0 | 71 | | return _securityTokenParameters; |
| | | 72 | | } |
| | | 73 | | } |
| | | 74 | | } |
| | | 75 | | } |