File: DerivedKeySecurityToken.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (121 lines) | stat: -rw-r--r-- 2,790 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.ObjectModel;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Cryptography.Xml;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Text;

namespace System.ServiceModel.Security.Tokens
{
	internal class DerivedKeySecurityToken : SecurityToken
	{
		string algorithm;
		SecurityKeyIdentifierClause reference;
		SecurityToken resolved_token; // store resolved one.
		int? generation, offset, length;
		// properties
		string id, name, label;
		byte [] nonce;
		ReadOnlyCollection<SecurityKey> keys;
		ReferenceList reflist;

		public DerivedKeySecurityToken (string id, string algorithm,
			SecurityKeyIdentifierClause reference,
			SymmetricSecurityKey referencedKey,
			string name,
			int? generation,
			int? offset,
			int? length,
			string label,
			byte [] nonce)
		{
			algorithm = algorithm ?? SecurityAlgorithms.Psha1KeyDerivation;

			this.id = id;
			this.algorithm = algorithm;
			this.reference = reference;
			this.generation = generation;
			this.offset = offset;
			this.length = length;
			this.nonce = nonce;
			this.name = name;
			this.label = label;

			SecurityKey key = new InMemorySymmetricSecurityKey (
				referencedKey.GenerateDerivedKey (
					algorithm,
					Encoding.UTF8.GetBytes (label ?? Constants.WsscDefaultLabel),
					nonce,
					(length ?? 32) * 8,
					offset ?? 0));
			keys = new ReadOnlyCollection<SecurityKey> (
				new SecurityKey [] {key});
		}

		public override string Id {
			get { return id; }
		}

		public override ReadOnlyCollection<SecurityKey> SecurityKeys {
			get { return keys; }
		}

		public override DateTime ValidFrom {
			get { return resolved_token.ValidFrom; }
		}

		public override DateTime ValidTo {
			get { return resolved_token.ValidTo; }
		}

		internal ReferenceList ReferenceList {
			get { return reflist; }
			set { reflist = value; }
		}

		public SecurityKeyIdentifierClause TokenReference {
			get { return reference; }
		}

		public int? Generation {
			get { return generation; }
		}

		public int? Length {
			get { return length; }
		}

		public int? Offset {
			get { return offset; }
		}

		public string Label {
			get { return label; }
		}

		public byte [] Nonce {
			get { return nonce; }
		}

		public string Name {
			get { return name; }
		}

		public override bool MatchesKeyIdentifierClause (
			SecurityKeyIdentifierClause keyIdentifierClause)
		{
			LocalIdKeyIdentifierClause l = keyIdentifierClause
				as LocalIdKeyIdentifierClause;
			return l != null && l.LocalId == Id;
		}

		public override SecurityKey ResolveKeyIdentifierClause (
			SecurityKeyIdentifierClause keyIdentifierClause)
		{
			return MatchesKeyIdentifierClause (keyIdentifierClause) ?
				keys [0] : null;
		}
	}
}