| | | 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 System.Diagnostics.Contracts; |
| | | 7 | | using System.Runtime.InteropServices; |
| | | 8 | | using CoreWCF.Channels; |
| | | 9 | | using CoreWCF.Runtime; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF |
| | | 12 | | { |
| | | 13 | | public sealed class UnixDomainSocketSecurity |
| | | 14 | | { |
| | 1 | 15 | | private static UnixDomainSocketSecurityMode s_defaultMode = |
| | 1 | 16 | | RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? |
| | 1 | 17 | | UnixDomainSocketSecurityMode.Transport : UnixDomainSocketSecurityMode.TransportCredentialOnly; |
| | | 18 | | |
| | | 19 | | |
| | | 20 | | private UnixDomainSocketSecurityMode _mode; |
| | | 21 | | |
| | 9 | 22 | | public UnixDomainSocketSecurity() |
| | | 23 | | { |
| | 9 | 24 | | _mode = s_defaultMode; |
| | 9 | 25 | | Transport = new UnixDomainSocketTransportSecurity(); |
| | 9 | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | private UnixDomainSocketSecurity(UnixDomainSocketSecurityMode mode, UnixDomainSocketTransportSecurity transportS |
| | | 29 | | { |
| | | 30 | | Fx.Assert(UnixDomainSocketSecurityModeHelper.IsDefined(mode), |
| | | 31 | | string.Format("Invalid SecurityMode value: {0} = {1} (default is {2} = {3}).", |
| | | 32 | | (int)mode, |
| | | 33 | | mode.ToString(), |
| | | 34 | | (int)s_defaultMode, |
| | | 35 | | s_defaultMode.ToString())); |
| | | 36 | | |
| | 0 | 37 | | _mode = mode; |
| | 0 | 38 | | Transport = transportSecurity ?? new UnixDomainSocketTransportSecurity(); |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | |
| | | 42 | | public UnixDomainSocketSecurityMode Mode |
| | | 43 | | { |
| | 0 | 44 | | get { return _mode; } |
| | | 45 | | set |
| | | 46 | | { |
| | 6 | 47 | | if (!UnixDomainSocketSecurityModeHelper.IsDefined(value)) |
| | | 48 | | { |
| | 0 | 49 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 50 | | } |
| | 6 | 51 | | _mode = value; |
| | 6 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | 81 | 55 | | public UnixDomainSocketTransportSecurity Transport { get; set; } |
| | | 56 | | |
| | | 57 | | internal BindingElement CreateTransportSecurity() |
| | | 58 | | { |
| | 50 | 59 | | if (_mode == UnixDomainSocketSecurityMode.Transport || _mode == UnixDomainSocketSecurityMode.TransportCreden |
| | | 60 | | { |
| | 35 | 61 | | if ((_mode == UnixDomainSocketSecurityMode.TransportCredentialOnly && Transport.ClientCredentialType != |
| | 35 | 62 | | || |
| | 35 | 63 | | (_mode == UnixDomainSocketSecurityMode.Transport && Transport.ClientCredentialType == UnixDomainSock |
| | | 64 | | { |
| | 3 | 65 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.Uns |
| | | 66 | | } |
| | 32 | 67 | | return Transport.CreateTransportProtectionAndAuthentication(); |
| | | 68 | | } |
| | 15 | 69 | | else if (_mode == UnixDomainSocketSecurityMode.None) |
| | | 70 | | { |
| | 15 | 71 | | return null; |
| | | 72 | | } |
| | | 73 | | else |
| | | 74 | | { |
| | 0 | 75 | | throw new NotSupportedException(); |
| | | 76 | | } |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | } |
| | | 80 | | } |