| | | 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.Collections.Generic; |
| | | 5 | | using CoreWCF.IdentityModel; |
| | | 6 | | using CoreWCF.IdentityModel.Tokens; |
| | | 7 | | using ISecurityElement = CoreWCF.IdentityModel.ISecurityElement; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Security |
| | | 10 | | { |
| | | 11 | | internal class SendSecurityHeaderElementContainer |
| | | 12 | | { |
| | | 13 | | private List<SecurityToken> _signedSupportingTokens = null; |
| | | 14 | | private List<SendSecurityHeaderElement> _basicSupportingTokens = null; |
| | | 15 | | private List<SecurityToken> _endorsingSupportingTokens = null; |
| | | 16 | | private List<SecurityToken> _endorsingDerivedSupportingTokens = null; |
| | | 17 | | private List<SecurityToken> _signedEndorsingSupportingTokens = null; |
| | | 18 | | private List<SecurityToken> _signedEndorsingDerivedSupportingTokens = null; |
| | | 19 | | private List<SendSecurityHeaderElement> _signatureConfirmations = null; |
| | | 20 | | private List<SendSecurityHeaderElement> _endorsingSignatures = null; |
| | | 21 | | private Dictionary<SecurityToken, SecurityKeyIdentifierClause> _securityTokenMappedToIdentifierClause = null; |
| | | 22 | | |
| | | 23 | | public SecurityTimestamp Timestamp; |
| | | 24 | | public SecurityToken PrerequisiteToken; |
| | | 25 | | public SecurityToken SourceSigningToken; |
| | | 26 | | public SecurityToken DerivedSigningToken; |
| | | 27 | | public SecurityToken SourceEncryptionToken; |
| | | 28 | | public SecurityToken WrappedEncryptionToken; |
| | | 29 | | public SecurityToken DerivedEncryptionToken; |
| | | 30 | | public ISecurityElement ReferenceList; |
| | | 31 | | public SendSecurityHeaderElement PrimarySignature; |
| | | 32 | | |
| | | 33 | | private void Add<T>(ref List<T> list, T item) |
| | | 34 | | { |
| | 0 | 35 | | if (list == null) |
| | | 36 | | { |
| | 0 | 37 | | list = new List<T>(); |
| | | 38 | | } |
| | 0 | 39 | | list.Add(item); |
| | 0 | 40 | | } |
| | | 41 | | |
| | | 42 | | public SecurityToken[] GetSignedSupportingTokens() |
| | | 43 | | { |
| | 126 | 44 | | return _signedSupportingTokens?.ToArray(); |
| | | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | public void AddSignedSupportingToken(SecurityToken token) => Add<SecurityToken>(ref _signedSupportingTokens, tok |
| | | 48 | | |
| | 0 | 49 | | public List<SecurityToken> EndorsingSupportingTokens => _endorsingSupportingTokens; |
| | | 50 | | |
| | 189 | 51 | | public SendSecurityHeaderElement[] GetBasicSupportingTokens() => _basicSupportingTokens?.ToArray(); |
| | | 52 | | |
| | 0 | 53 | | public void AddBasicSupportingToken(SendSecurityHeaderElement tokenElement) => Add<SendSecurityHeaderElement>(re |
| | | 54 | | |
| | | 55 | | public SecurityToken[] GetSignedEndorsingSupportingTokens() |
| | | 56 | | { |
| | 189 | 57 | | return _signedEndorsingSupportingTokens?.ToArray(); |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | public void AddSignedEndorsingSupportingToken(SecurityToken token) |
| | | 61 | | { |
| | 0 | 62 | | Add<SecurityToken>(ref _signedEndorsingSupportingTokens, token); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | public SecurityToken[] GetSignedEndorsingDerivedSupportingTokens() |
| | | 66 | | { |
| | 63 | 67 | | return _signedEndorsingDerivedSupportingTokens?.ToArray(); |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public void AddSignedEndorsingDerivedSupportingToken(SecurityToken token) |
| | | 71 | | { |
| | 0 | 72 | | Add<SecurityToken>(ref _signedEndorsingDerivedSupportingTokens, token); |
| | 0 | 73 | | } |
| | | 74 | | |
| | 126 | 75 | | public SecurityToken[] GetEndorsingSupportingTokens() => _endorsingSupportingTokens?.ToArray(); |
| | | 76 | | |
| | 0 | 77 | | public void AddEndorsingSupportingToken(SecurityToken token) => Add<SecurityToken>(ref _endorsingSupportingToken |
| | | 78 | | |
| | 63 | 79 | | public SecurityToken[] GetEndorsingDerivedSupportingTokens() => _endorsingDerivedSupportingTokens?.ToArray(); |
| | | 80 | | |
| | 0 | 81 | | public void AddEndorsingDerivedSupportingToken(SecurityToken token) => Add<SecurityToken>(ref _endorsingDerivedS |
| | | 82 | | |
| | 189 | 83 | | public SendSecurityHeaderElement[] GetSignatureConfirmations() => _signatureConfirmations?.ToArray(); |
| | | 84 | | |
| | 0 | 85 | | public void AddSignatureConfirmation(SendSecurityHeaderElement confirmation) => Add<SendSecurityHeaderElement>(r |
| | | 86 | | |
| | 126 | 87 | | public SendSecurityHeaderElement[] GetEndorsingSignatures() => _endorsingSignatures?.ToArray(); |
| | | 88 | | |
| | 0 | 89 | | public void AddEndorsingSignature(SendSecurityHeaderElement signature) => Add<SendSecurityHeaderElement>(ref _en |
| | | 90 | | |
| | | 91 | | public void MapSecurityTokenToStrClause(SecurityToken securityToken, SecurityKeyIdentifierClause keyIdentifierCl |
| | | 92 | | { |
| | 0 | 93 | | if (_securityTokenMappedToIdentifierClause == null) |
| | | 94 | | { |
| | 0 | 95 | | _securityTokenMappedToIdentifierClause = new Dictionary<SecurityToken, SecurityKeyIdentifierClause>(); |
| | | 96 | | } |
| | | 97 | | |
| | 0 | 98 | | if (!_securityTokenMappedToIdentifierClause.ContainsKey(securityToken)) |
| | | 99 | | { |
| | 0 | 100 | | _securityTokenMappedToIdentifierClause.Add(securityToken, keyIdentifierClause); |
| | | 101 | | } |
| | 0 | 102 | | } |
| | | 103 | | |
| | | 104 | | public bool TryGetIdentifierClauseFromSecurityToken(SecurityToken securityToken, out SecurityKeyIdentifierClause |
| | | 105 | | { |
| | 0 | 106 | | keyIdentifierClause = null; |
| | 0 | 107 | | if (securityToken == null |
| | 0 | 108 | | || _securityTokenMappedToIdentifierClause == null |
| | 0 | 109 | | || !_securityTokenMappedToIdentifierClause.TryGetValue(securityToken, out keyIdentifierClause)) |
| | | 110 | | { |
| | 0 | 111 | | return false; |
| | | 112 | | } |
| | 0 | 113 | | return true; |
| | | 114 | | } |
| | | 115 | | } |
| | | 116 | | } |