| | | 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.Globalization; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | using CoreWCF.Description; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Security |
| | | 10 | | { |
| | | 11 | | internal abstract class SecurityHeader : MessageHeader |
| | | 12 | | { |
| | | 13 | | private readonly string _actor; |
| | 157 | 14 | | private bool _encryptedKeyContainsReferenceList = true; |
| | | 15 | | private readonly bool _mustUnderstand; |
| | | 16 | | private readonly bool _relay; |
| | 157 | 17 | | private bool _requireMessageProtection = true; |
| | | 18 | | private bool _processingStarted; |
| | | 19 | | private bool _maintainSignatureConfirmationState; |
| | | 20 | | private SecurityHeaderLayout _layout = SecurityHeaderLayout.Strict; |
| | | 21 | | |
| | 157 | 22 | | public SecurityHeader(Message message, |
| | 157 | 23 | | string actor, bool mustUnderstand, bool relay, |
| | 157 | 24 | | SecurityStandardsManager standardsManager |
| | 157 | 25 | | , SecurityAlgorithmSuite algorithmSuite, |
| | 157 | 26 | | MessageDirection transferDirection) |
| | | 27 | | { |
| | 157 | 28 | | Message = message ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message)); |
| | 157 | 29 | | _actor = actor ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(actor)); |
| | 157 | 30 | | _mustUnderstand = mustUnderstand; |
| | 157 | 31 | | _relay = relay; |
| | 157 | 32 | | StandardsManager = standardsManager ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(name |
| | 157 | 33 | | AlgorithmSuite = algorithmSuite ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(a |
| | 157 | 34 | | MessageDirection = transferDirection; |
| | 157 | 35 | | } |
| | | 36 | | |
| | 63 | 37 | | public override string Actor => _actor; |
| | | 38 | | |
| | 92 | 39 | | public SecurityAlgorithmSuite AlgorithmSuite { get; } |
| | | 40 | | |
| | | 41 | | public bool EncryptedKeyContainsReferenceList |
| | | 42 | | { |
| | 0 | 43 | | get { return _encryptedKeyContainsReferenceList; } |
| | | 44 | | set |
| | | 45 | | { |
| | 0 | 46 | | ThrowIfProcessingStarted(); |
| | 0 | 47 | | _encryptedKeyContainsReferenceList = value; |
| | 0 | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public bool RequireMessageProtection |
| | | 52 | | { |
| | 992 | 53 | | get { return _requireMessageProtection; } |
| | | 54 | | set |
| | | 55 | | { |
| | 157 | 56 | | ThrowIfProcessingStarted(); |
| | 157 | 57 | | _requireMessageProtection = value; |
| | 157 | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public bool MaintainSignatureConfirmationState |
| | | 62 | | { |
| | 22 | 63 | | get { return _maintainSignatureConfirmationState; } |
| | | 64 | | set |
| | | 65 | | { |
| | 0 | 66 | | ThrowIfProcessingStarted(); |
| | 0 | 67 | | _maintainSignatureConfirmationState = value; |
| | 0 | 68 | | } |
| | | 69 | | } |
| | | 70 | | |
| | 1084 | 71 | | protected Message Message { get; set; } |
| | | 72 | | |
| | 126 | 73 | | public override bool MustUnderstand => _mustUnderstand; |
| | | 74 | | |
| | 63 | 75 | | public override bool Relay => _relay; |
| | | 76 | | |
| | | 77 | | public SecurityHeaderLayout Layout |
| | | 78 | | { |
| | | 79 | | get |
| | | 80 | | { |
| | 220 | 81 | | return _layout; |
| | | 82 | | } |
| | | 83 | | set |
| | | 84 | | { |
| | 137 | 85 | | ThrowIfProcessingStarted(); |
| | 137 | 86 | | _layout = value; |
| | 137 | 87 | | } |
| | | 88 | | } |
| | | 89 | | |
| | 687 | 90 | | public SecurityStandardsManager StandardsManager { get; } |
| | | 91 | | |
| | 0 | 92 | | public MessageDirection MessageDirection { get; } |
| | | 93 | | |
| | 244 | 94 | | protected MessageVersion Version => Message.Version; |
| | | 95 | | |
| | | 96 | | protected void SetProcessingStarted() |
| | | 97 | | { |
| | 157 | 98 | | _processingStarted = true; |
| | 157 | 99 | | } |
| | | 100 | | |
| | | 101 | | protected void ThrowIfProcessingStarted() |
| | | 102 | | { |
| | 1004 | 103 | | if (_processingStarted) |
| | | 104 | | { |
| | 0 | 105 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.OperationCann |
| | | 106 | | } |
| | 1004 | 107 | | } |
| | | 108 | | |
| | | 109 | | public override string ToString() |
| | | 110 | | { |
| | 0 | 111 | | return string.Format(CultureInfo.InvariantCulture, "{0}(Actor = '{1}')", GetType().Name, Actor); |
| | | 112 | | } |
| | | 113 | | } |
| | | 114 | | } |