forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Messages.cs
334 lines (275 loc) · 14.1 KB
/
Messages.cs
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
//
// Copyright © Microsoft Corporation, All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache License, Version 2.0 for the specific language
// governing permissions and limitations under the License.
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using Microsoft.Azure.KeyVault.WebKey;
using Microsoft.Azure.KeyVault.WebKey.Json;
using Newtonsoft.Json;
namespace Microsoft.Azure.KeyVault
{
public static class MessagePropertyNames
{
public const string Algorithm = "alg";
public const string Attributes = "attributes";
public const string Digest = "digest";
public const string Hsm = "hsm";
public const string Key = "key";
public const string KeyOps = "key_ops";
public const string KeySize = "key_size";
public const string Kid = "kid";
public const string Kty = "kty";
public const string Result = "result";
public const string Signature = "signature";
public const string Value = "value";
public const string Id = "id";
public const string NextLink = "nextLink";
public const string Tags = "tags";
public const string ContentType = "contentType";
}
#region Error Response Messages
[JsonObject]
public class Error
{
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = "code", Required = Required.Default)]
public string Code { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = "message", Required = Required.Default)]
public string Message { get; set; }
[JsonExtensionData]
public Dictionary<string, object> AdditionalInfo { get; set; }
}
[JsonObject]
public class ErrorResponseMessage
{
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = "error", Required = Required.Default)]
public Error Error { get; set; }
[JsonExtensionData]
public Dictionary<string, object> AdditionalInfo { get; set; }
}
#endregion
#region Key Management
[JsonObject]
public class BackupKeyResponseMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Value, Required = Required.Always )]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[] Value { get; set; }
}
[JsonObject]
public class GetKeyResponseMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Key, Required = Required.Always )]
public JsonWebKey Key { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Attributes, Required = Required.Always )]
public KeyAttributes Attributes { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Tags, Required = Required.Default)]
public Dictionary<string, string> Tags { get; set; }
}
[JsonObject]
public class CreateKeyRequestMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Kty, Required = Required.Always )]
public string Kty { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.KeySize, Required = Required.Default )]
public int? KeySize { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.KeyOps, Required = Required.Default )]
public string[] KeyOps { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Attributes, Required = Required.Default )]
public KeyAttributes Attributes { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Tags, Required = Required.Default)]
public Dictionary<string, string> Tags { get; set; }
}
[JsonObject]
public class ImportKeyRequestMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Key, Required = Required.Always )]
public JsonWebKey Key { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Hsm, Required = Required.Default )]
public bool? Hsm { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Attributes, Required = Required.Default )]
public KeyAttributes Attributes { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Tags, Required = Required.Default)]
public Dictionary<string, string> Tags { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class KeyItem
{
private KeyIdentifier _identifier;
public KeyIdentifier Identifier
{
get
{
return _identifier;
}
}
private string _kid;
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
PropertyName = MessagePropertyNames.Kid, Required = Required.Always)]
public string Kid
{
get
{
return _kid;
}
set
{
_kid = value;
_identifier = !string.IsNullOrWhiteSpace(value) ? new KeyIdentifier(value) : null;
}
}
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Attributes, Required = Required.Always )]
public KeyAttributes Attributes { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Tags, Required = Required.Default)]
public Dictionary<string, string> Tags { get; set; }
}
[JsonObject]
public class ListKeysResponseMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Include, PropertyName = MessagePropertyNames.Value, Required = Required.Default )]
public IEnumerable<KeyItem> Value { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Include, PropertyName = MessagePropertyNames.NextLink, Required = Required.Default )]
public string NextLink { get; set; }
}
[JsonObject]
public class RestoreKeyRequestMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Value, Required = Required.Always )]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[] Value { get; set; }
}
[JsonObject]
public class UpdateKeyRequestMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.KeyOps, Required = Required.Default )]
public string[] KeyOps { get; set; }
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Attributes, Required = Required.Default )]
public KeyAttributes Attributes { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Tags, Required = Required.Default)]
public Dictionary<string, string> Tags { get; set; }
}
[JsonObject]
public class DeleteKeyRequestMessage
{
// Since DELETE is a POST operation, it must have a body.
// But so far there is no field.
}
#endregion
#region Key Operations
[JsonObject]
public class KeyOpRequestMessage
{
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Algorithm, Required = Required.Always )]
public string Alg { get; set; }
// Data to be encrypted.
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Value, Required = Required.Always )]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[] Value { get; set; }
}
[JsonObject(MemberSerialization.OptIn)]
public class KeyOpResponseMessage
{
private KeyIdentifier _identifier;
public KeyIdentifier Identifier
{
get
{
return _identifier;
}
}
private string _kid;
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
PropertyName = MessagePropertyNames.Kid, Required = Required.Always)]
public string Kid
{
get
{
return _kid;
}
set
{
_kid = value;
_identifier = new KeyIdentifier(value);
}
}
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Value, Required = Required.Default)]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[] Value
{
get;
set;
}
}
[JsonObject]
public class VerifyRequestMessage : KeyOpRequestMessage
{
// Digest to be verified, in Base64URL.
[JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Digest, Required = Required.Always )]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[] Digest;
}
[JsonObject]
public class VerifyResponseMessage
{
// true if signature was verified, false otherwise.
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Value, Required = Required.Always)]
public bool Value;
}
#endregion
#region Secret Messages
[JsonObject(MemberSerialization.OptIn)]
public class SecretItem
{
private SecretIdentifier _identifier;
public SecretIdentifier Identifier
{
get
{
return _identifier;
}
}
private string _id;
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
PropertyName = MessagePropertyNames.Id, Required = Required.Always)]
public string Id
{
get
{
return _id;
}
set
{
_id = value;
_identifier = !string.IsNullOrWhiteSpace(value) ? new SecretIdentifier(value) : null;
}
}
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Attributes, Required = Required.Always)]
public SecretAttributes Attributes { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.Tags, Required = Required.Default)]
public Dictionary<string, string> Tags { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = MessagePropertyNames.ContentType, Required = Required.Default)]
public string ContentType { get; set; }
}
[JsonObject]
public class ListSecretsResponseMessage
{
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Include, PropertyName = MessagePropertyNames.Value, Required = Required.Default)]
public IEnumerable<SecretItem> Value { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Include, PropertyName = MessagePropertyNames.NextLink, Required = Required.Default)]
public string NextLink { get; set; }
}
#endregion
}