| | | 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.ComponentModel; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | using CoreWCF.Runtime; |
| | | 8 | | using CoreWCF.Security; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF |
| | | 11 | | { |
| | | 12 | | public sealed partial class NetTcpSecurity |
| | | 13 | | { |
| | | 14 | | internal const SecurityMode DefaultMode = SecurityMode.Transport; |
| | | 15 | | private SecurityMode _mode; |
| | | 16 | | |
| | | 17 | | public NetTcpSecurity() |
| | 117 | 18 | | : this(DefaultMode, new TcpTransportSecurity(), new MessageSecurityOverTcp()) |
| | | 19 | | { |
| | 117 | 20 | | } |
| | | 21 | | |
| | 117 | 22 | | private NetTcpSecurity(SecurityMode mode, TcpTransportSecurity transportSecurity, MessageSecurityOverTcp message |
| | | 23 | | { |
| | | 24 | | Fx.Assert(SecurityModeHelper.IsDefined(mode), string.Format("Invalid SecurityMode value: {0}.", mode.ToStrin |
| | | 25 | | |
| | 117 | 26 | | _mode = mode; |
| | 117 | 27 | | Transport = transportSecurity ?? new TcpTransportSecurity(); |
| | 117 | 28 | | Message = messageSecurity ?? new MessageSecurityOverTcp(); |
| | 117 | 29 | | } |
| | | 30 | | |
| | | 31 | | [DefaultValue(DefaultMode)] |
| | | 32 | | public SecurityMode Mode |
| | | 33 | | { |
| | 2247 | 34 | | get { return _mode; } |
| | | 35 | | set |
| | | 36 | | { |
| | 109 | 37 | | if (!SecurityModeHelper.IsDefined(value)) |
| | | 38 | | { |
| | 0 | 39 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 40 | | } |
| | 109 | 41 | | _mode = value; |
| | 109 | 42 | | } |
| | | 43 | | } |
| | | 44 | | |
| | 1495 | 45 | | public TcpTransportSecurity Transport { get; set; } |
| | | 46 | | |
| | 166 | 47 | | public MessageSecurityOverTcp Message { get; set; } |
| | | 48 | | |
| | | 49 | | internal BindingElement CreateTransportSecurity() |
| | | 50 | | { |
| | 1159 | 51 | | if (_mode == SecurityMode.TransportWithMessageCredential) |
| | | 52 | | { |
| | 74 | 53 | | return Transport.CreateTransportProtectionOnly(); |
| | | 54 | | } |
| | 1085 | 55 | | else if (_mode == SecurityMode.Transport) |
| | | 56 | | { |
| | 172 | 57 | | return Transport.CreateTransportProtectionAndAuthentication(); |
| | | 58 | | } |
| | | 59 | | else |
| | | 60 | | { |
| | 913 | 61 | | return null; |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | internal SecurityBindingElement CreateMessageSecurity(bool isReliableSessionEnabled) |
| | | 66 | | { |
| | 37 | 67 | | if (_mode == SecurityMode.Message) |
| | | 68 | | { |
| | 0 | 69 | | return Message.CreateSecurityBindingElement(false, isReliableSessionEnabled, null); |
| | | 70 | | } |
| | 37 | 71 | | else if (_mode == SecurityMode.TransportWithMessageCredential) |
| | | 72 | | { |
| | 37 | 73 | | return Message.CreateSecurityBindingElement(true, isReliableSessionEnabled, CreateTransportSecurity()); |
| | | 74 | | } |
| | | 75 | | else |
| | | 76 | | { |
| | 0 | 77 | | return null; |
| | | 78 | | } |
| | | 79 | | } |
| | | 80 | | } |
| | | 81 | | } |