| | | 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.Net.Security; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public sealed class MsmqTransportSecurity |
| | | 11 | | { |
| | | 12 | | private MsmqAuthenticationMode _msmqAuthenticationMode; |
| | | 13 | | private MsmqEncryptionAlgorithm _msmqEncryptionAlgorithm; |
| | | 14 | | private MsmqSecureHashAlgorithm _msmqHashAlgorithm; |
| | | 15 | | private ProtectionLevel _msmqProtectionLevel; |
| | | 16 | | |
| | 0 | 17 | | public MsmqTransportSecurity() |
| | | 18 | | { |
| | 0 | 19 | | _msmqAuthenticationMode = MsmqDefaults.MsmqAuthenticationMode1; |
| | 0 | 20 | | _msmqEncryptionAlgorithm = MsmqDefaults.MsmqEncryptionAlgorithm1; |
| | 0 | 21 | | _msmqHashAlgorithm = MsmqDefaults.MsmqSecureHashAlgorithm; |
| | 0 | 22 | | _msmqProtectionLevel = MsmqDefaults.MsmqProtectionLevel; |
| | 0 | 23 | | } |
| | | 24 | | |
| | 0 | 25 | | public MsmqTransportSecurity(MsmqTransportSecurity other) |
| | | 26 | | { |
| | 0 | 27 | | if (null == other) |
| | 0 | 28 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(other)); |
| | 0 | 29 | | _msmqAuthenticationMode = other.MsmqAuthenticationMode; |
| | 0 | 30 | | _msmqEncryptionAlgorithm = other.MsmqEncryptionAlgorithm; |
| | 0 | 31 | | _msmqHashAlgorithm = other.MsmqSecureHashAlgorithm; |
| | 0 | 32 | | _msmqProtectionLevel = other.MsmqProtectionLevel; |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | internal bool Enabled |
| | | 36 | | { |
| | | 37 | | get |
| | | 38 | | { |
| | 0 | 39 | | return _msmqAuthenticationMode != MsmqAuthenticationMode.None && _msmqProtectionLevel != ProtectionLevel |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | [DefaultValue(MsmqDefaults.MsmqAuthenticationMode1)] |
| | | 44 | | public MsmqAuthenticationMode MsmqAuthenticationMode |
| | | 45 | | { |
| | 0 | 46 | | get { return _msmqAuthenticationMode; } |
| | | 47 | | set |
| | | 48 | | { |
| | 0 | 49 | | if (!MsmqAuthenticationModeHelper.IsDefined(value)) |
| | 0 | 50 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 51 | | _msmqAuthenticationMode = value; |
| | 0 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | [DefaultValue(MsmqDefaults.MsmqEncryptionAlgorithm1)] |
| | | 56 | | public MsmqEncryptionAlgorithm MsmqEncryptionAlgorithm |
| | | 57 | | { |
| | 0 | 58 | | get { return _msmqEncryptionAlgorithm; } |
| | | 59 | | set |
| | | 60 | | { |
| | 0 | 61 | | if (!MsmqEncryptionAlgorithmHelper.IsDefined(value)) |
| | 0 | 62 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 63 | | _msmqEncryptionAlgorithm = value; |
| | 0 | 64 | | } |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | [DefaultValue(MsmqDefaults.DefaultMsmqSecureHashAlgorithm)] |
| | | 68 | | public MsmqSecureHashAlgorithm MsmqSecureHashAlgorithm |
| | | 69 | | { |
| | 0 | 70 | | get { return _msmqHashAlgorithm; } |
| | | 71 | | set |
| | | 72 | | { |
| | 0 | 73 | | if (!MsmqSecureHashAlgorithmHelper.IsDefined(value)) |
| | 0 | 74 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 75 | | _msmqHashAlgorithm = value; |
| | 0 | 76 | | } |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | [DefaultValue(MsmqDefaults.MsmqProtectionLevel)] |
| | | 80 | | public ProtectionLevel MsmqProtectionLevel |
| | | 81 | | { |
| | 0 | 82 | | get { return _msmqProtectionLevel; } |
| | | 83 | | set |
| | | 84 | | { |
| | 0 | 85 | | if (!ProtectionLevelHelper.IsDefined(value)) |
| | 0 | 86 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 87 | | _msmqProtectionLevel = value; |
| | 0 | 88 | | } |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | internal void Disable() |
| | | 92 | | { |
| | 0 | 93 | | _msmqAuthenticationMode = MsmqAuthenticationMode.None; |
| | 0 | 94 | | _msmqProtectionLevel = ProtectionLevel.None; |
| | 0 | 95 | | } |
| | | 96 | | } |
| | | 97 | | } |