-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdigest_asn1.h
475 lines (399 loc) · 13.3 KB
/
digest_asn1.h
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/* Generated from /usr/src/kerberos5/lib/libasn1/../../../crypto/heimdal/lib/asn1/digest.asn1 */
/* Do not edit */
#ifndef __digest_asn1_h__
#define __digest_asn1_h__
#include <stddef.h>
#include <time.h>
#ifndef __asn1_common_definitions__
#define __asn1_common_definitions__
typedef struct heim_integer {
size_t length;
void *data;
int negative;
} heim_integer;
typedef struct heim_octet_string {
size_t length;
void *data;
} heim_octet_string;
typedef char *heim_general_string;
typedef char *heim_utf8_string;
typedef char *heim_printable_string;
typedef char *heim_ia5_string;
typedef struct heim_bmp_string {
size_t length;
uint16_t *data;
} heim_bmp_string;
typedef struct heim_universal_string {
size_t length;
uint32_t *data;
} heim_universal_string;
typedef char *heim_visible_string;
typedef struct heim_oid {
size_t length;
unsigned *components;
} heim_oid;
typedef struct heim_bit_string {
size_t length;
void *data;
} heim_bit_string;
typedef struct heim_octet_string heim_any;
typedef struct heim_octet_string heim_any_set;
#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \
do { \
(BL) = length_##T((S)); \
(B) = malloc((BL)); \
if((B) == NULL) { \
(R) = ENOMEM; \
} else { \
(R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \
(S), (L)); \
if((R) != 0) { \
free((B)); \
(B) = NULL; \
} \
} \
} while (0)
struct units;
#endif
#include <krb5_asn1.h>
/*
DigestTypes ::= BIT STRING {
ntlm-v1(0),
ntlm-v1-session(1),
ntlm-v2(2),
digest-md5(3),
chap-md5(4),
ms-chap-v2(5)
}
*/
typedef struct DigestTypes {
unsigned int ntlm_v1:1;
unsigned int ntlm_v1_session:1;
unsigned int ntlm_v2:1;
unsigned int digest_md5:1;
unsigned int chap_md5:1;
unsigned int ms_chap_v2:1;
} DigestTypes;
int encode_DigestTypes(unsigned char *, size_t, const DigestTypes *, size_t *);
int decode_DigestTypes(const unsigned char *, size_t, DigestTypes *, size_t *);
void free_DigestTypes (DigestTypes *);
size_t length_DigestTypes(const DigestTypes *);
int copy_DigestTypes (const DigestTypes *, DigestTypes *);
unsigned DigestTypes2int(DigestTypes);
DigestTypes int2DigestTypes(unsigned);
#ifdef __PARSE_UNITS_H__
const struct units * asn1_DigestTypes_units(void);
#endif
/*
DigestInit ::= SEQUENCE {
type UTF8String,
channel [0] SEQUENCE {
cb-type UTF8String,
cb-binding UTF8String,
} OPTIONAL,
hostname [1] UTF8String OPTIONAL,
}
*/
typedef struct DigestInit {
heim_utf8_string type;
struct {
heim_utf8_string cb_type;
heim_utf8_string cb_binding;
} *channel;
heim_utf8_string *hostname;
} DigestInit;
int encode_DigestInit(unsigned char *, size_t, const DigestInit *, size_t *);
int decode_DigestInit(const unsigned char *, size_t, DigestInit *, size_t *);
void free_DigestInit (DigestInit *);
size_t length_DigestInit(const DigestInit *);
int copy_DigestInit (const DigestInit *, DigestInit *);
/*
DigestInitReply ::= SEQUENCE {
nonce UTF8String,
opaque UTF8String,
identifier [0] UTF8String OPTIONAL,
}
*/
typedef struct DigestInitReply {
heim_utf8_string nonce;
heim_utf8_string opaque;
heim_utf8_string *identifier;
} DigestInitReply;
int encode_DigestInitReply(unsigned char *, size_t, const DigestInitReply *, size_t *);
int decode_DigestInitReply(const unsigned char *, size_t, DigestInitReply *, size_t *);
void free_DigestInitReply (DigestInitReply *);
size_t length_DigestInitReply(const DigestInitReply *);
int copy_DigestInitReply (const DigestInitReply *, DigestInitReply *);
/*
DigestRequest ::= SEQUENCE {
type UTF8String,
digest UTF8String,
username UTF8String,
responseData UTF8String,
authid [0] UTF8String OPTIONAL,
authentication-user [1] Principal OPTIONAL,
realm [2] UTF8String OPTIONAL,
method [3] UTF8String OPTIONAL,
uri [4] UTF8String OPTIONAL,
serverNonce UTF8String,
clientNonce [5] UTF8String OPTIONAL,
nonceCount [6] UTF8String OPTIONAL,
qop [7] UTF8String OPTIONAL,
identifier [8] UTF8String OPTIONAL,
hostname [9] UTF8String OPTIONAL,
opaque UTF8String,
}
*/
typedef struct DigestRequest {
heim_utf8_string type;
heim_utf8_string digest;
heim_utf8_string username;
heim_utf8_string responseData;
heim_utf8_string *authid;
Principal *authentication_user;
heim_utf8_string *realm;
heim_utf8_string *method;
heim_utf8_string *uri;
heim_utf8_string serverNonce;
heim_utf8_string *clientNonce;
heim_utf8_string *nonceCount;
heim_utf8_string *qop;
heim_utf8_string *identifier;
heim_utf8_string *hostname;
heim_utf8_string opaque;
} DigestRequest;
int encode_DigestRequest(unsigned char *, size_t, const DigestRequest *, size_t *);
int decode_DigestRequest(const unsigned char *, size_t, DigestRequest *, size_t *);
void free_DigestRequest (DigestRequest *);
size_t length_DigestRequest(const DigestRequest *);
int copy_DigestRequest (const DigestRequest *, DigestRequest *);
/*
DigestError ::= SEQUENCE {
reason UTF8String,
code INTEGER (-2147483648..2147483647),
}
*/
typedef struct DigestError {
heim_utf8_string reason;
int code;
} DigestError;
int encode_DigestError(unsigned char *, size_t, const DigestError *, size_t *);
int decode_DigestError(const unsigned char *, size_t, DigestError *, size_t *);
void free_DigestError (DigestError *);
size_t length_DigestError(const DigestError *);
int copy_DigestError (const DigestError *, DigestError *);
/*
DigestResponse ::= SEQUENCE {
success BOOLEAN,
rsp [0] UTF8String OPTIONAL,
tickets [1] SEQUENCE OF OCTET STRING OPTIONAL,
channel [2] SEQUENCE {
cb-type UTF8String,
cb-binding UTF8String,
} OPTIONAL,
session-key [3] OCTET STRING OPTIONAL,
}
*/
typedef struct DigestResponse {
int success;
heim_utf8_string *rsp;
struct {
unsigned int len;
heim_octet_string *val;
} *tickets;
struct {
heim_utf8_string cb_type;
heim_utf8_string cb_binding;
} *channel;
heim_octet_string *session_key;
} DigestResponse;
int encode_DigestResponse(unsigned char *, size_t, const DigestResponse *, size_t *);
int decode_DigestResponse(const unsigned char *, size_t, DigestResponse *, size_t *);
void free_DigestResponse (DigestResponse *);
size_t length_DigestResponse(const DigestResponse *);
int copy_DigestResponse (const DigestResponse *, DigestResponse *);
/*
NTLMInit ::= SEQUENCE {
flags [0] INTEGER (0..-1),
hostname [1] UTF8String OPTIONAL,
domain [1] UTF8String OPTIONAL,
}
*/
typedef struct NTLMInit {
unsigned int flags;
heim_utf8_string *hostname;
heim_utf8_string *domain;
} NTLMInit;
int encode_NTLMInit(unsigned char *, size_t, const NTLMInit *, size_t *);
int decode_NTLMInit(const unsigned char *, size_t, NTLMInit *, size_t *);
void free_NTLMInit (NTLMInit *);
size_t length_NTLMInit(const NTLMInit *);
int copy_NTLMInit (const NTLMInit *, NTLMInit *);
/*
NTLMInitReply ::= SEQUENCE {
flags [0] INTEGER (0..-1),
opaque [1] OCTET STRING,
targetname [2] UTF8String,
challange [3] OCTET STRING,
targetinfo [4] OCTET STRING OPTIONAL,
}
*/
typedef struct NTLMInitReply {
unsigned int flags;
heim_octet_string opaque;
heim_utf8_string targetname;
heim_octet_string challange;
heim_octet_string *targetinfo;
} NTLMInitReply;
int encode_NTLMInitReply(unsigned char *, size_t, const NTLMInitReply *, size_t *);
int decode_NTLMInitReply(const unsigned char *, size_t, NTLMInitReply *, size_t *);
void free_NTLMInitReply (NTLMInitReply *);
size_t length_NTLMInitReply(const NTLMInitReply *);
int copy_NTLMInitReply (const NTLMInitReply *, NTLMInitReply *);
/*
NTLMRequest ::= SEQUENCE {
flags [0] INTEGER (0..-1),
opaque [1] OCTET STRING,
username [2] UTF8String,
targetname [3] UTF8String,
targetinfo [4] OCTET STRING OPTIONAL,
lm [5] OCTET STRING,
ntlm [6] OCTET STRING,
sessionkey [7] OCTET STRING OPTIONAL,
}
*/
typedef struct NTLMRequest {
unsigned int flags;
heim_octet_string opaque;
heim_utf8_string username;
heim_utf8_string targetname;
heim_octet_string *targetinfo;
heim_octet_string lm;
heim_octet_string ntlm;
heim_octet_string *sessionkey;
} NTLMRequest;
int encode_NTLMRequest(unsigned char *, size_t, const NTLMRequest *, size_t *);
int decode_NTLMRequest(const unsigned char *, size_t, NTLMRequest *, size_t *);
void free_NTLMRequest (NTLMRequest *);
size_t length_NTLMRequest(const NTLMRequest *);
int copy_NTLMRequest (const NTLMRequest *, NTLMRequest *);
/*
NTLMResponse ::= SEQUENCE {
success [0] BOOLEAN,
flags [1] INTEGER (0..-1),
sessionkey [2] OCTET STRING OPTIONAL,
tickets [3] SEQUENCE OF OCTET STRING OPTIONAL,
}
*/
typedef struct NTLMResponse {
int success;
unsigned int flags;
heim_octet_string *sessionkey;
struct {
unsigned int len;
heim_octet_string *val;
} *tickets;
} NTLMResponse;
int encode_NTLMResponse(unsigned char *, size_t, const NTLMResponse *, size_t *);
int decode_NTLMResponse(const unsigned char *, size_t, NTLMResponse *, size_t *);
void free_NTLMResponse (NTLMResponse *);
size_t length_NTLMResponse(const NTLMResponse *);
int copy_NTLMResponse (const NTLMResponse *, NTLMResponse *);
/*
DigestReqInner ::= CHOICE {
init [0] DigestInit,
digestRequest [1] DigestRequest,
ntlmInit [2] NTLMInit,
ntlmRequest [3] NTLMRequest,
supportedMechs [4] NULL,
}
*/
typedef struct DigestReqInner {
enum {
choice_DigestReqInner_init = 1,
choice_DigestReqInner_digestRequest,
choice_DigestReqInner_ntlmInit,
choice_DigestReqInner_ntlmRequest,
choice_DigestReqInner_supportedMechs
} element;
union {
DigestInit init;
DigestRequest digestRequest;
NTLMInit ntlmInit;
NTLMRequest ntlmRequest;
int supportedMechs;
} u;
} DigestReqInner;
int encode_DigestReqInner(unsigned char *, size_t, const DigestReqInner *, size_t *);
int decode_DigestReqInner(const unsigned char *, size_t, DigestReqInner *, size_t *);
void free_DigestReqInner (DigestReqInner *);
size_t length_DigestReqInner(const DigestReqInner *);
int copy_DigestReqInner (const DigestReqInner *, DigestReqInner *);
/*
DigestREQ ::= [APPLICATION 128] SEQUENCE {
apReq [0] OCTET STRING,
innerReq [1] EncryptedData,
}
*/
typedef struct DigestREQ {
heim_octet_string apReq;
EncryptedData innerReq;
} DigestREQ;
int encode_DigestREQ(unsigned char *, size_t, const DigestREQ *, size_t *);
int decode_DigestREQ(const unsigned char *, size_t, DigestREQ *, size_t *);
void free_DigestREQ (DigestREQ *);
size_t length_DigestREQ(const DigestREQ *);
int copy_DigestREQ (const DigestREQ *, DigestREQ *);
/*
DigestRepInner ::= CHOICE {
error [0] DigestError,
initReply [1] DigestInitReply,
response [2] DigestResponse,
ntlmInitReply [3] NTLMInitReply,
ntlmResponse [4] NTLMResponse,
supportedMechs [5] DigestTypes,
...,
}
*/
typedef struct DigestRepInner {
enum {
choice_DigestRepInner_asn1_ellipsis = 0,
choice_DigestRepInner_error,
choice_DigestRepInner_initReply,
choice_DigestRepInner_response,
choice_DigestRepInner_ntlmInitReply,
choice_DigestRepInner_ntlmResponse,
choice_DigestRepInner_supportedMechs
/* ... */
} element;
union {
DigestError error;
DigestInitReply initReply;
DigestResponse response;
NTLMInitReply ntlmInitReply;
NTLMResponse ntlmResponse;
DigestTypes supportedMechs;
heim_octet_string asn1_ellipsis;
} u;
} DigestRepInner;
int encode_DigestRepInner(unsigned char *, size_t, const DigestRepInner *, size_t *);
int decode_DigestRepInner(const unsigned char *, size_t, DigestRepInner *, size_t *);
void free_DigestRepInner (DigestRepInner *);
size_t length_DigestRepInner(const DigestRepInner *);
int copy_DigestRepInner (const DigestRepInner *, DigestRepInner *);
/*
DigestREP ::= [APPLICATION 129] SEQUENCE {
apRep [0] OCTET STRING,
innerRep [1] EncryptedData,
}
*/
typedef struct DigestREP {
heim_octet_string apRep;
EncryptedData innerRep;
} DigestREP;
int encode_DigestREP(unsigned char *, size_t, const DigestREP *, size_t *);
int decode_DigestREP(const unsigned char *, size_t, DigestREP *, size_t *);
void free_DigestREP (DigestREP *);
size_t length_DigestREP(const DigestREP *);
int copy_DigestREP (const DigestREP *, DigestREP *);
#endif /* __digest_asn1_h__ */