4 * Copyright (C) 2006, 2007 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: spnego_asn1.c,v 1.4 2007/06/19 23:47:16 tbox Exp */
22 * \brief Method routines generated from SPNEGO ASN.1 module.
23 * See spnego_asn1.pl for details. Do not edit.
26 /* Generated from spnego.asn1 */
33 #ifndef __asn1_common_definitions__
34 #define __asn1_common_definitions__
36 typedef struct octet_string
{
41 typedef char *general_string
;
43 typedef char *utf8_string
;
50 #define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \
52 (BL) = length_##T((S)); \
57 (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \
69 * MechType ::= OBJECT IDENTIFIER
74 static int encode_MechType(unsigned char *, size_t, const MechType
*, size_t *);
75 static int decode_MechType(const unsigned char *, size_t, MechType
*, size_t *);
76 static void free_MechType(MechType
*);
77 /* unused declaration: length_MechType */
78 /* unused declaration: copy_MechType */
82 * MechTypeList ::= SEQUENCE OF MechType
85 typedef struct MechTypeList
{
90 static int encode_MechTypeList(unsigned char *, size_t, const MechTypeList
*, size_t *);
91 static int decode_MechTypeList(const unsigned char *, size_t, MechTypeList
*, size_t *);
92 static void free_MechTypeList(MechTypeList
*);
93 /* unused declaration: length_MechTypeList */
94 /* unused declaration: copy_MechTypeList */
98 * ContextFlags ::= BIT STRING { delegFlag(0), mutualFlag(1), replayFlag(2),
99 * sequenceFlag(3), anonFlag(4), confFlag(5), integFlag(6) }
102 typedef struct ContextFlags
{
103 unsigned int delegFlag
:1;
104 unsigned int mutualFlag
:1;
105 unsigned int replayFlag
:1;
106 unsigned int sequenceFlag
:1;
107 unsigned int anonFlag
:1;
108 unsigned int confFlag
:1;
109 unsigned int integFlag
:1;
113 static int encode_ContextFlags(unsigned char *, size_t, const ContextFlags
*, size_t *);
114 static int decode_ContextFlags(const unsigned char *, size_t, ContextFlags
*, size_t *);
115 static void free_ContextFlags(ContextFlags
*);
116 /* unused declaration: length_ContextFlags */
117 /* unused declaration: copy_ContextFlags */
118 /* unused declaration: ContextFlags2int */
119 /* unused declaration: int2ContextFlags */
120 /* unused declaration: asn1_ContextFlags_units */
123 * NegTokenInit ::= SEQUENCE { mechTypes[0] MechTypeList, reqFlags[1]
124 * ContextFlags OPTIONAL, mechToken[2] OCTET STRING OPTIONAL,
125 * mechListMIC[3] OCTET STRING OPTIONAL }
128 typedef struct NegTokenInit
{
129 MechTypeList mechTypes
;
130 ContextFlags
*reqFlags
;
131 octet_string
*mechToken
;
132 octet_string
*mechListMIC
;
135 static int encode_NegTokenInit(unsigned char *, size_t, const NegTokenInit
*, size_t *);
136 static int decode_NegTokenInit(const unsigned char *, size_t, NegTokenInit
*, size_t *);
137 static void free_NegTokenInit(NegTokenInit
*);
138 /* unused declaration: length_NegTokenInit */
139 /* unused declaration: copy_NegTokenInit */
143 * NegTokenResp ::= SEQUENCE { negState[0] ENUMERATED {
144 * accept-completed(0), accept-incomplete(1), reject(2), request-mic(3) }
145 * OPTIONAL, supportedMech[1] MechType OPTIONAL, responseToken[2] OCTET
146 * STRING OPTIONAL, mechListMIC[3] OCTET STRING OPTIONAL }
149 typedef struct NegTokenResp
{
151 accept_completed
= 0,
152 accept_incomplete
= 1,
157 MechType
*supportedMech
;
158 octet_string
*responseToken
;
159 octet_string
*mechListMIC
;
162 static int encode_NegTokenResp(unsigned char *, size_t, const NegTokenResp
*, size_t *);
163 static int decode_NegTokenResp(const unsigned char *, size_t, NegTokenResp
*, size_t *);
164 static void free_NegTokenResp(NegTokenResp
*);
165 /* unused declaration: length_NegTokenResp */
166 /* unused declaration: copy_NegTokenResp */
171 #endif /* __asn1_h__ */
172 /* Generated from spnego.asn1 */
176 #define BACK if (e) return e; p -= l; len -= l; ret += l
179 encode_MechType(unsigned char *p
, size_t len
, const MechType
* data
, size_t * size
)
186 e
= encode_oid(p
, len
, data
, &l
);
192 #define FORW if(e) goto fail; p += l; len -= l; ret += l
195 decode_MechType(const unsigned char *p
, size_t len
, MechType
* data
, size_t * size
)
197 size_t ret
= 0, reallen
;
201 memset(data
, 0, sizeof(*data
));
203 e
= decode_oid(p
, len
, data
, &l
);
214 free_MechType(MechType
* data
)
219 /* unused function: length_MechType */
222 /* unused function: copy_MechType */
224 /* Generated from spnego.asn1 */
228 #define BACK if (e) return e; p -= l; len -= l; ret += l
231 encode_MechTypeList(unsigned char *p
, size_t len
, const MechTypeList
* data
, size_t * size
)
238 for (i
= (data
)->len
- 1; i
>= 0; --i
) {
241 e
= encode_MechType(p
, len
, &(data
)->val
[i
], &l
);
245 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_UNIV
, CONS
, UT_Sequence
, &l
);
251 #define FORW if(e) goto fail; p += l; len -= l; ret += l
254 decode_MechTypeList(const unsigned char *p
, size_t len
, MechTypeList
* data
, size_t * size
)
256 size_t ret
= 0, reallen
;
260 memset(data
, 0, sizeof(*data
));
262 e
= der_match_tag_and_length(p
, len
, ASN1_C_UNIV
, CONS
, UT_Sequence
, &reallen
, &l
);
268 size_t origlen
= len
;
273 while (ret
< origlen
) {
275 (data
)->val
= realloc((data
)->val
, sizeof(*((data
)->val
)) * (data
)->len
);
276 e
= decode_MechType(p
, len
, &(data
)->val
[(data
)->len
- 1], &l
);
286 free_MechTypeList(data
);
291 free_MechTypeList(MechTypeList
* data
)
293 while ((data
)->len
) {
294 free_MechType(&(data
)->val
[(data
)->len
- 1]);
301 /* unused function: length_MechTypeList */
304 /* unused function: copy_MechTypeList */
306 /* Generated from spnego.asn1 */
310 #define BACK if (e) return e; p -= l; len -= l; ret += l
313 encode_ContextFlags(unsigned char *p
, size_t len
, const ContextFlags
* data
, size_t * size
)
340 if (data
->sequenceFlag
)
342 if (data
->replayFlag
)
344 if (data
->mutualFlag
)
354 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_UNIV
, PRIM
, UT_BitString
, &l
);
360 #define FORW if(e) goto fail; p += l; len -= l; ret += l
363 decode_ContextFlags(const unsigned char *p
, size_t len
, ContextFlags
* data
, size_t * size
)
365 size_t ret
= 0, reallen
;
369 memset(data
, 0, sizeof(*data
));
371 e
= der_match_tag_and_length(p
, len
, ASN1_C_UNIV
, PRIM
, UT_BitString
, &reallen
, &l
);
379 data
->delegFlag
= (*p
>> 7) & 1;
380 data
->mutualFlag
= (*p
>> 6) & 1;
381 data
->replayFlag
= (*p
>> 5) & 1;
382 data
->sequenceFlag
= (*p
>> 4) & 1;
383 data
->anonFlag
= (*p
>> 3) & 1;
384 data
->confFlag
= (*p
>> 2) & 1;
385 data
->integFlag
= (*p
>> 1) & 1;
393 free_ContextFlags(data
);
398 free_ContextFlags(ContextFlags
* data
)
403 /* unused function: length_ContextFlags */
406 /* unused function: copy_ContextFlags */
409 /* unused function: ContextFlags2int */
412 /* unused function: int2ContextFlags */
415 /* unused variable: ContextFlags_units */
417 /* unused function: asn1_ContextFlags_units */
419 /* Generated from spnego.asn1 */
423 #define BACK if (e) return e; p -= l; len -= l; ret += l
426 encode_NegTokenInit(unsigned char *p
, size_t len
, const NegTokenInit
* data
, size_t * size
)
433 if ((data
)->mechListMIC
) {
436 e
= encode_octet_string(p
, len
, (data
)->mechListMIC
, &l
);
438 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 3, &l
);
442 if ((data
)->mechToken
) {
445 e
= encode_octet_string(p
, len
, (data
)->mechToken
, &l
);
447 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 2, &l
);
451 if ((data
)->reqFlags
) {
454 e
= encode_ContextFlags(p
, len
, (data
)->reqFlags
, &l
);
456 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 1, &l
);
462 e
= encode_MechTypeList(p
, len
, &(data
)->mechTypes
, &l
);
464 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 0, &l
);
468 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_UNIV
, CONS
, UT_Sequence
, &l
);
474 #define FORW if(e) goto fail; p += l; len -= l; ret += l
477 decode_NegTokenInit(const unsigned char *p
, size_t len
, NegTokenInit
* data
, size_t * size
)
479 size_t ret
= 0, reallen
;
483 memset(data
, 0, sizeof(*data
));
485 e
= der_match_tag_and_length(p
, len
, ASN1_C_UNIV
, CONS
, UT_Sequence
, &reallen
, &l
);
489 if ((dce_fix
= fix_dce(reallen
, &len
)) < 0)
490 return ASN1_BAD_FORMAT
;
492 size_t newlen
, oldlen
;
494 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 0, &l
);
501 e
= der_get_length(p
, len
, &newlen
, &l
);
506 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
507 return ASN1_BAD_FORMAT
;
508 e
= decode_MechTypeList(p
, len
, &(data
)->mechTypes
, &l
);
511 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
514 len
= oldlen
- newlen
;
519 size_t newlen
, oldlen
;
521 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 1, &l
);
523 (data
)->reqFlags
= NULL
;
528 e
= der_get_length(p
, len
, &newlen
, &l
);
533 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
534 return ASN1_BAD_FORMAT
;
535 (data
)->reqFlags
= malloc(sizeof(*(data
)->reqFlags
));
536 if ((data
)->reqFlags
== NULL
)
538 e
= decode_ContextFlags(p
, len
, (data
)->reqFlags
, &l
);
541 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
544 len
= oldlen
- newlen
;
549 size_t newlen
, oldlen
;
551 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 2, &l
);
553 (data
)->mechToken
= NULL
;
558 e
= der_get_length(p
, len
, &newlen
, &l
);
563 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
564 return ASN1_BAD_FORMAT
;
565 (data
)->mechToken
= malloc(sizeof(*(data
)->mechToken
));
566 if ((data
)->mechToken
== NULL
)
568 e
= decode_octet_string(p
, len
, (data
)->mechToken
, &l
);
571 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
574 len
= oldlen
- newlen
;
579 size_t newlen
, oldlen
;
581 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 3, &l
);
583 (data
)->mechListMIC
= NULL
;
588 e
= der_get_length(p
, len
, &newlen
, &l
);
593 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
594 return ASN1_BAD_FORMAT
;
595 (data
)->mechListMIC
= malloc(sizeof(*(data
)->mechListMIC
));
596 if ((data
)->mechListMIC
== NULL
)
598 e
= decode_octet_string(p
, len
, (data
)->mechListMIC
, &l
);
601 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
604 len
= oldlen
- newlen
;
609 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
617 free_NegTokenInit(data
);
622 free_NegTokenInit(NegTokenInit
* data
)
624 free_MechTypeList(&(data
)->mechTypes
);
625 if ((data
)->reqFlags
) {
626 free_ContextFlags((data
)->reqFlags
);
627 free((data
)->reqFlags
);
628 (data
)->reqFlags
= NULL
;
630 if ((data
)->mechToken
) {
631 free_octet_string((data
)->mechToken
);
632 free((data
)->mechToken
);
633 (data
)->mechToken
= NULL
;
635 if ((data
)->mechListMIC
) {
636 free_octet_string((data
)->mechListMIC
);
637 free((data
)->mechListMIC
);
638 (data
)->mechListMIC
= NULL
;
642 /* unused function: length_NegTokenInit */
645 /* unused function: copy_NegTokenInit */
647 /* Generated from spnego.asn1 */
651 #define BACK if (e) return e; p -= l; len -= l; ret += l
654 encode_NegTokenResp(unsigned char *p
, size_t len
, const NegTokenResp
* data
, size_t * size
)
661 if ((data
)->mechListMIC
) {
664 e
= encode_octet_string(p
, len
, (data
)->mechListMIC
, &l
);
666 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 3, &l
);
670 if ((data
)->responseToken
) {
673 e
= encode_octet_string(p
, len
, (data
)->responseToken
, &l
);
675 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 2, &l
);
679 if ((data
)->supportedMech
) {
682 e
= encode_MechType(p
, len
, (data
)->supportedMech
, &l
);
684 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 1, &l
);
688 if ((data
)->negState
) {
691 e
= encode_enumerated(p
, len
, (data
)->negState
, &l
);
693 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_CONTEXT
, CONS
, 0, &l
);
697 e
= der_put_length_and_tag(p
, len
, ret
, ASN1_C_UNIV
, CONS
, UT_Sequence
, &l
);
703 #define FORW if(e) goto fail; p += l; len -= l; ret += l
706 decode_NegTokenResp(const unsigned char *p
, size_t len
, NegTokenResp
* data
, size_t * size
)
708 size_t ret
= 0, reallen
;
712 memset(data
, 0, sizeof(*data
));
714 e
= der_match_tag_and_length(p
, len
, ASN1_C_UNIV
, CONS
, UT_Sequence
, &reallen
, &l
);
718 if ((dce_fix
= fix_dce(reallen
, &len
)) < 0)
719 return ASN1_BAD_FORMAT
;
721 size_t newlen
, oldlen
;
723 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 0, &l
);
725 (data
)->negState
= NULL
;
730 e
= der_get_length(p
, len
, &newlen
, &l
);
735 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
736 return ASN1_BAD_FORMAT
;
737 (data
)->negState
= malloc(sizeof(*(data
)->negState
));
738 if ((data
)->negState
== NULL
)
740 e
= decode_enumerated(p
, len
, (data
)->negState
, &l
);
743 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
746 len
= oldlen
- newlen
;
751 size_t newlen
, oldlen
;
753 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 1, &l
);
755 (data
)->supportedMech
= NULL
;
760 e
= der_get_length(p
, len
, &newlen
, &l
);
765 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
766 return ASN1_BAD_FORMAT
;
767 (data
)->supportedMech
= malloc(sizeof(*(data
)->supportedMech
));
768 if ((data
)->supportedMech
== NULL
)
770 e
= decode_MechType(p
, len
, (data
)->supportedMech
, &l
);
773 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
776 len
= oldlen
- newlen
;
781 size_t newlen
, oldlen
;
783 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 2, &l
);
785 (data
)->responseToken
= NULL
;
790 e
= der_get_length(p
, len
, &newlen
, &l
);
795 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
796 return ASN1_BAD_FORMAT
;
797 (data
)->responseToken
= malloc(sizeof(*(data
)->responseToken
));
798 if ((data
)->responseToken
== NULL
)
800 e
= decode_octet_string(p
, len
, (data
)->responseToken
, &l
);
803 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
806 len
= oldlen
- newlen
;
811 size_t newlen
, oldlen
;
813 e
= der_match_tag(p
, len
, ASN1_C_CONTEXT
, CONS
, 3, &l
);
815 (data
)->mechListMIC
= NULL
;
820 e
= der_get_length(p
, len
, &newlen
, &l
);
825 if ((dce_fix
= fix_dce(newlen
, &len
)) < 0)
826 return ASN1_BAD_FORMAT
;
827 (data
)->mechListMIC
= malloc(sizeof(*(data
)->mechListMIC
));
828 if ((data
)->mechListMIC
== NULL
)
830 e
= decode_octet_string(p
, len
, (data
)->mechListMIC
, &l
);
833 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
836 len
= oldlen
- newlen
;
841 e
= der_match_tag_and_length(p
, len
, (Der_class
) 0, (Der_type
) 0, 0, &reallen
, &l
);
849 free_NegTokenResp(data
);
854 free_NegTokenResp(NegTokenResp
* data
)
856 if ((data
)->negState
) {
857 free((data
)->negState
);
858 (data
)->negState
= NULL
;
860 if ((data
)->supportedMech
) {
861 free_MechType((data
)->supportedMech
);
862 free((data
)->supportedMech
);
863 (data
)->supportedMech
= NULL
;
865 if ((data
)->responseToken
) {
866 free_octet_string((data
)->responseToken
);
867 free((data
)->responseToken
);
868 (data
)->responseToken
= NULL
;
870 if ((data
)->mechListMIC
) {
871 free_octet_string((data
)->mechListMIC
);
872 free((data
)->mechListMIC
);
873 (data
)->mechListMIC
= NULL
;
877 /* unused function: length_NegTokenResp */
880 /* unused function: copy_NegTokenResp */
882 /* Generated from spnego.asn1 */
887 /* unused variable: asn1_NegotiationToken_dummy_holder */