2 * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #include <asn1-common.h>
45 #include <krb5_asn1.h>
46 #include <heim_asn1.h>
47 #include <rfc2459_asn1.h>
48 #include <x690sample_asn1.h>
49 #include <test_asn1.h>
52 #include "check-common.h"
54 static int my_copy_vers_called
;
55 static int my_free_vers_called
;
58 #if UINT_MAX == 0xffffffff
60 #define DISABLE_TEST_64
64 my_copy_vers(const my_vers
*from
, my_vers
*to
)
66 my_copy_vers_called
++;
72 my_free_vers(my_vers
*v
)
74 my_free_vers_called
++;
78 static char *lha_principal
[] = { "lha" };
79 static char *lharoot_princ
[] = { "lha", "root" };
80 static char *datan_princ
[] = { "host", "nutcracker.e.kth.se" };
81 static char *nada_tgt_principal
[] = { "krbtgt", "NADA.KTH.SE" };
84 cmp_principal (void *a
, void *b
)
90 COMPARE_STRING(pa
,pb
,realm
);
91 COMPARE_INTEGER(pa
,pb
,name
.name_type
);
92 COMPARE_INTEGER(pa
,pb
,name
.name_string
.len
);
94 for (i
= 0; i
< pa
->name
.name_string
.len
; i
++)
95 COMPARE_STRING(pa
,pb
,name
.name_string
.val
[i
]);
101 test_principal (void)
104 struct test_case tests
[] = {
106 "\x30\x1b\xa0\x10\x30\x0e\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b"
107 "\x03\x6c\x68\x61\xa1\x07\x1b\x05\x53\x55\x2e\x53\x45",
111 "\x30\x21\xa0\x16\x30\x14\xa0\x03\x02\x01\x01\xa1\x0d\x30\x0b\x1b"
112 "\x03\x6c\x68\x61\x1b\x04\x72\x6f\x6f\x74\xa1\x07\x1b\x05\x53\x55"
117 "\x30\x34\xa0\x26\x30\x24\xa0\x03\x02\x01\x03\xa1\x1d\x30\x1b\x1b"
118 "\x04\x68\x6f\x73\x74\x1b\x13\x6e\x75\x74\x63\x72\x61\x63\x6b\x65"
119 "\x72\x2e\x65\x2e\x6b\x74\x68\x2e\x73\x65\xa1\x0a\x1b\x08\x45\x2e"
120 "\x4b\x54\x48\x2e\x53\x45",
126 Principal values
[] = {
127 { { KRB5_NT_PRINCIPAL
, { 1, lha_principal
} }, "SU.SE", NULL
},
128 { { KRB5_NT_PRINCIPAL
, { 2, lharoot_princ
} }, "SU.SE", NULL
},
129 { { KRB5_NT_SRV_HST
, { 2, datan_princ
} }, "E.KTH.SE", NULL
}
132 int ntests
= sizeof(tests
) / sizeof(*tests
);
134 for (i
= 0; i
< ntests
; ++i
) {
135 tests
[i
].val
= &values
[i
];
136 if (asprintf (&tests
[i
].name
, "Principal %d", i
) < 0)
138 if (tests
[i
].name
== NULL
)
142 ret
= generic_test (tests
, ntests
, sizeof(Principal
),
143 (generic_encode
)encode_Principal
,
144 (generic_length
)length_Principal
,
145 (generic_decode
)decode_Principal
,
146 (generic_free
)free_Principal
,
149 for (i
= 0; i
< ntests
; ++i
)
150 free (tests
[i
].name
);
156 cmp_authenticator (void *a
, void *b
)
158 Authenticator
*aa
= a
;
159 Authenticator
*ab
= b
;
162 COMPARE_INTEGER(aa
,ab
,authenticator_vno
);
163 COMPARE_STRING(aa
,ab
,crealm
);
165 COMPARE_INTEGER(aa
,ab
,cname
.name_type
);
166 COMPARE_INTEGER(aa
,ab
,cname
.name_string
.len
);
168 for (i
= 0; i
< aa
->cname
.name_string
.len
; i
++)
169 COMPARE_STRING(aa
,ab
,cname
.name_string
.val
[i
]);
175 test_authenticator (void)
177 struct test_case tests
[] = {
179 "\x62\x3d\x30\x3b\xa0\x03\x02\x01\x05\xa1\x0a\x1b\x08"
180 "\x45\x2e\x4b\x54\x48\x2e\x53\x45\xa2\x10\x30\x0e\xa0"
181 "\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61"
182 "\xa4\x03\x02\x01\x0a\xa5\x11\x18\x0f\x31\x39\x37\x30"
183 "\x30\x31\x30\x31\x30\x30\x30\x31\x33\x39\x5a",
187 "\x62\x41\x30\x3f\xa0\x03\x02\x01\x05\xa1\x07\x1b\x05"
188 "\x53\x55\x2e\x53\x45\xa2\x16\x30\x14\xa0\x03\x02\x01"
189 "\x01\xa1\x0d\x30\x0b\x1b\x03\x6c\x68\x61\x1b\x04\x72"
190 "\x6f\x6f\x74\xa4\x04\x02\x02\x01\x24\xa5\x11\x18\x0f"
191 "\x31\x39\x37\x30\x30\x31\x30\x31\x30\x30\x31\x36\x33"
197 Authenticator values
[] = {
198 { 5, "E.KTH.SE", { KRB5_NT_PRINCIPAL
, { 1, lha_principal
} },
199 NULL
, 10, 99, NULL
, NULL
, NULL
},
200 { 5, "SU.SE", { KRB5_NT_PRINCIPAL
, { 2, lharoot_princ
} },
201 NULL
, 292, 999, NULL
, NULL
, NULL
}
204 int ntests
= sizeof(tests
) / sizeof(*tests
);
206 for (i
= 0; i
< ntests
; ++i
) {
207 tests
[i
].val
= &values
[i
];
208 if (asprintf (&tests
[i
].name
, "Authenticator %d", i
) < 0)
210 if (tests
[i
].name
== NULL
)
214 ret
= generic_test (tests
, ntests
, sizeof(Authenticator
),
215 (generic_encode
)encode_Authenticator
,
216 (generic_length
)length_Authenticator
,
217 (generic_decode
)decode_Authenticator
,
218 (generic_free
)free_Authenticator
,
220 (generic_copy
)copy_Authenticator
);
221 for (i
= 0; i
< ntests
; ++i
)
228 cmp_KRB_ERROR (void *a
, void *b
)
234 COMPARE_INTEGER(aa
,ab
,pvno
);
235 COMPARE_INTEGER(aa
,ab
,msg_type
);
237 IF_OPT_COMPARE(aa
,ab
,ctime
) {
238 COMPARE_INTEGER(aa
,ab
,ctime
);
240 IF_OPT_COMPARE(aa
,ab
,cusec
) {
241 COMPARE_INTEGER(aa
,ab
,cusec
);
243 COMPARE_INTEGER(aa
,ab
,stime
);
244 COMPARE_INTEGER(aa
,ab
,susec
);
245 COMPARE_INTEGER(aa
,ab
,error_code
);
247 IF_OPT_COMPARE(aa
,ab
,crealm
) {
248 COMPARE_OPT_STRING(aa
,ab
,crealm
);
251 IF_OPT_COMPARE(aa
,ab
,cname
) {
252 COMPARE_OPT_STRING(aa
,ab
,cname
);
255 COMPARE_STRING(aa
,ab
,realm
);
257 COMPARE_INTEGER(aa
,ab
,sname
.name_string
.len
);
258 for (i
= 0; i
< aa
->sname
.name_string
.len
; i
++)
259 COMPARE_STRING(aa
,ab
,sname
.name_string
.val
[i
]);
261 IF_OPT_COMPARE(aa
,ab
,e_text
) {
262 COMPARE_OPT_STRING(aa
,ab
,e_text
);
264 IF_OPT_COMPARE(aa
,ab
,e_data
) {
265 /* COMPARE_OPT_OCTET_STRING(aa,ab,e_data); */
272 test_krb_error (void)
274 struct test_case tests
[] = {
276 "\x7e\x7d\x30\x7b\xa0\x03\x02\x01\x05\xa1\x03\x02\x01\x1e\xa4\x11"
277 "\x18\x0f\x32\x30\x30\x33\x31\x31\x32\x34\x30\x30\x31\x31\x31\x39"
278 "\x5a\xa5\x05\x02\x03\x04\xed\xa5\xa6\x03\x02\x01\x1f\xa7\x0d\x1b"
279 "\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xa8\x10\x30\x0e"
280 "\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61\xa9\x0d"
281 "\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xaa\x20\x30"
282 "\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15\x1b\x06\x6b\x72\x62\x74"
283 "\x67\x74\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45",
287 int ntests
= sizeof(tests
) / sizeof(*tests
);
289 PrincipalName lhaprincipalname
= { 1, { 1, lha_principal
} };
290 PrincipalName tgtprincipalname
= { 1, { 2, nada_tgt_principal
} };
291 char *realm
= "NADA.KTH.SE";
297 e1
.stime
= 1069632679;
301 e1
.cname
= &lhaprincipalname
;
302 e1
.realm
= "NADA.KTH.SE";
303 e1
.sname
= tgtprincipalname
;
309 return generic_test (tests
, ntests
, sizeof(KRB_ERROR
),
310 (generic_encode
)encode_KRB_ERROR
,
311 (generic_length
)length_KRB_ERROR
,
312 (generic_decode
)decode_KRB_ERROR
,
313 (generic_free
)free_KRB_ERROR
,
315 (generic_copy
)copy_KRB_ERROR
);
319 cmp_Name (void *a
, void *b
)
324 COMPARE_INTEGER(aa
,ab
,element
);
332 struct test_case tests
[] = {
334 "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76"
335 "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48"
337 "Name CN=Love+L=STOCKHOLM"
340 "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76"
341 "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48"
343 "Name L=STOCKHOLM+CN=Love"
347 int ntests
= sizeof(tests
) / sizeof(*tests
);
349 RelativeDistinguishedName rdn1
[1];
350 RelativeDistinguishedName rdn2
[1];
351 AttributeTypeAndValue atv1
[2];
352 AttributeTypeAndValue atv2
[2];
353 unsigned cmp_CN
[] = { 2, 5, 4, 3 };
354 unsigned cmp_L
[] = { 2, 5, 4, 7 };
357 n1
.element
= choice_Name_rdnSequence
;
358 n1
.u
.rdnSequence
.val
= rdn1
;
359 n1
.u
.rdnSequence
.len
= sizeof(rdn1
)/sizeof(rdn1
[0]);
361 rdn1
[0].len
= sizeof(atv1
)/sizeof(atv1
[0]);
363 atv1
[0].type
.length
= sizeof(cmp_CN
)/sizeof(cmp_CN
[0]);
364 atv1
[0].type
.components
= cmp_CN
;
365 atv1
[0].value
.element
= choice_DirectoryString_printableString
;
366 atv1
[0].value
.u
.printableString
.data
= "Love";
367 atv1
[0].value
.u
.printableString
.length
= 4;
369 atv1
[1].type
.length
= sizeof(cmp_L
)/sizeof(cmp_L
[0]);
370 atv1
[1].type
.components
= cmp_L
;
371 atv1
[1].value
.element
= choice_DirectoryString_printableString
;
372 atv1
[1].value
.u
.printableString
.data
= "STOCKHOLM";
373 atv1
[1].value
.u
.printableString
.length
= 9;
376 n2
.element
= choice_Name_rdnSequence
;
377 n2
.u
.rdnSequence
.val
= rdn2
;
378 n2
.u
.rdnSequence
.len
= sizeof(rdn2
)/sizeof(rdn2
[0]);
380 rdn2
[0].len
= sizeof(atv2
)/sizeof(atv2
[0]);
382 atv2
[0].type
.length
= sizeof(cmp_L
)/sizeof(cmp_L
[0]);
383 atv2
[0].type
.components
= cmp_L
;
384 atv2
[0].value
.element
= choice_DirectoryString_printableString
;
385 atv2
[0].value
.u
.printableString
.data
= "STOCKHOLM";
386 atv2
[0].value
.u
.printableString
.length
= 9;
388 atv2
[1].type
.length
= sizeof(cmp_CN
)/sizeof(cmp_CN
[0]);
389 atv2
[1].type
.components
= cmp_CN
;
390 atv2
[1].value
.element
= choice_DirectoryString_printableString
;
391 atv2
[1].value
.u
.printableString
.data
= "Love";
392 atv2
[1].value
.u
.printableString
.length
= 4;
398 return generic_test (tests
, ntests
, sizeof(Name
),
399 (generic_encode
)encode_Name
,
400 (generic_length
)length_Name
,
401 (generic_decode
)decode_Name
,
402 (generic_free
)free_Name
,
404 (generic_copy
)copy_Name
);
408 cmp_KeyUsage (void *a
, void *b
)
413 return KeyUsage2int(*aa
) != KeyUsage2int(*ab
);
417 test_bit_string (void)
419 struct test_case tests
[] = {
429 "\x03\x03\x07\x00\x80",
438 int ntests
= sizeof(tests
) / sizeof(*tests
);
439 KeyUsage ku1
, ku2
, ku3
, ku4
;
441 memset(&ku1
, 0, sizeof(ku1
));
442 ku1
.digitalSignature
= 1;
445 memset(&ku2
, 0, sizeof(ku2
));
446 ku2
.digitalSignature
= 1;
447 ku2
.keyEncipherment
= 1;
450 memset(&ku3
, 0, sizeof(ku3
));
451 ku3
.decipherOnly
= 1;
454 memset(&ku4
, 0, sizeof(ku4
));
458 return generic_test (tests
, ntests
, sizeof(KeyUsage
),
459 (generic_encode
)encode_KeyUsage
,
460 (generic_length
)length_KeyUsage
,
461 (generic_decode
)decode_KeyUsage
,
462 (generic_free
)free_KeyUsage
,
464 (generic_copy
)copy_KeyUsage
);
468 cmp_TicketFlags (void *a
, void *b
)
473 return TicketFlags2int(*aa
) != TicketFlags2int(*ab
);
477 test_bit_string_rfc1510 (void)
479 struct test_case tests
[] = {
481 "\x03\x05\x00\x80\x00\x00\x00",
485 "\x03\x05\x00\x40\x20\x00\x00",
489 "\x03\x05\x00\x00\x20\x00\x00",
493 "\x03\x05\x00\x00\x00\x00\x00",
498 int ntests
= sizeof(tests
) / sizeof(*tests
);
499 TicketFlags tf1
, tf2
, tf3
, tf4
;
501 memset(&tf1
, 0, sizeof(tf1
));
505 memset(&tf2
, 0, sizeof(tf2
));
510 memset(&tf3
, 0, sizeof(tf3
));
514 memset(&tf4
, 0, sizeof(tf4
));
518 return generic_test (tests
, ntests
, sizeof(TicketFlags
),
519 (generic_encode
)encode_TicketFlags
,
520 (generic_length
)length_TicketFlags
,
521 (generic_decode
)decode_TicketFlags
,
522 (generic_free
)free_TicketFlags
,
524 (generic_copy
)copy_TicketFlags
);
528 cmp_KerberosTime (void *a
, void *b
)
530 KerberosTime
*aa
= a
;
531 KerberosTime
*ab
= b
;
539 struct test_case tests
[] = {
541 "\x18\x0f\x31\x39\x37\x30\x30\x31\x30\x31\x30\x31\x31\x38\x33\x31"
545 "\x18\x0f\x32\x30\x30\x39\x30\x35\x32\x34\x30\x32\x30\x32\x34\x30"
550 int ntests
= sizeof(tests
) / sizeof(*tests
);
551 KerberosTime times
[] = {
556 tests
[0].val
= ×
[0];
557 tests
[1].val
= ×
[1];
559 return generic_test (tests
, ntests
, sizeof(KerberosTime
),
560 (generic_encode
)encode_KerberosTime
,
561 (generic_length
)length_KerberosTime
,
562 (generic_decode
)decode_KerberosTime
,
563 (generic_free
)free_KerberosTime
,
565 (generic_copy
)copy_KerberosTime
);
573 "\x30\x82\x02\x6c\x30\x82\x01\xd5\xa0\x03\x02\x01\x02\x02\x09\x00"
574 "\x99\x32\xde\x61\x0e\x40\x19\x8a\x30\x0d\x06\x09\x2a\x86\x48\x86"
575 "\xf7\x0d\x01\x01\x05\x05\x00\x30\x2a\x31\x1b\x30\x19\x06\x03\x55"
576 "\x04\x03\x0c\x12\x68\x78\x35\x30\x39\x20\x54\x65\x73\x74\x20\x52"
577 "\x6f\x6f\x74\x20\x43\x41\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13"
578 "\x02\x53\x45\x30\x1e\x17\x0d\x30\x39\x30\x34\x32\x36\x32\x30\x32"
579 "\x39\x34\x30\x5a\x17\x0d\x31\x39\x30\x34\x32\x34\x32\x30\x32\x39"
580 "\x34\x30\x5a\x30\x2a\x31\x1b\x30\x19\x06\x03\x55\x04\x03\x0c\x12"
581 "\x68\x78\x35\x30\x39\x20\x54\x65\x73\x74\x20\x52\x6f\x6f\x74\x20"
582 "\x43\x41\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x30"
583 "\x81\x9f\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05"
584 "\x00\x03\x81\x8d\x00\x30\x81\x89\x02\x81\x81\x00\xb9\xd3\x1b\x67"
585 "\x1c\xf7\x5e\x26\x81\x3b\x82\xff\x03\xa4\x43\xb5\xb2\x63\x0b\x89"
586 "\x58\x43\xfe\x3d\xe0\x38\x7d\x93\x74\xbb\xad\x21\xa4\x29\xd9\x34"
587 "\x79\xf3\x1c\x8c\x5a\xd6\xb0\xd7\x19\xea\xcc\xaf\xe0\xa8\x40\x02"
588 "\x1d\x91\xf1\xac\x36\xb0\xfb\x08\xbd\xcc\x9a\xe1\xb7\x6e\xee\x0a"
589 "\x69\xbf\x6d\x2b\xee\x20\x82\x61\x06\xf2\x18\xcc\x89\x11\x64\x7e"
590 "\xb2\xff\x47\xd1\x3b\x52\x73\xeb\x5a\xc0\x03\xa6\x4b\xc7\x40\x7e"
591 "\xbc\xe1\x0e\x65\x44\x3f\x40\x8b\x02\x82\x54\x04\xd9\xcc\x2c\x67"
592 "\x01\xb6\x16\x82\xd8\x33\x53\x17\xd7\xde\x8d\x5d\x02\x03\x01\x00"
593 "\x01\xa3\x81\x99\x30\x81\x96\x30\x1d\x06\x03\x55\x1d\x0e\x04\x16"
594 "\x04\x14\x6e\x48\x13\xdc\xbf\x8b\x95\x4c\x13\xf3\x1f\x97\x30\xdd"
595 "\x27\x96\x59\x9b\x0e\x68\x30\x5a\x06\x03\x55\x1d\x23\x04\x53\x30"
596 "\x51\x80\x14\x6e\x48\x13\xdc\xbf\x8b\x95\x4c\x13\xf3\x1f\x97\x30"
597 "\xdd\x27\x96\x59\x9b\x0e\x68\xa1\x2e\xa4\x2c\x30\x2a\x31\x1b\x30"
598 "\x19\x06\x03\x55\x04\x03\x0c\x12\x68\x78\x35\x30\x39\x20\x54\x65"
599 "\x73\x74\x20\x52\x6f\x6f\x74\x20\x43\x41\x31\x0b\x30\x09\x06\x03"
600 "\x55\x04\x06\x13\x02\x53\x45\x82\x09\x00\x99\x32\xde\x61\x0e\x40"
601 "\x19\x8a\x30\x0c\x06\x03\x55\x1d\x13\x04\x05\x30\x03\x01\x01\xff"
602 "\x30\x0b\x06\x03\x55\x1d\x0f\x04\x04\x03\x02\x01\xe6\x30\x0d\x06"
603 "\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x81\x81\x00"
604 "\x52\x9b\xe4\x0e\xee\xc2\x5d\xb7\xf1\xba\x47\xe3\xfe\xaf\x3d\x51"
605 "\x10\xfd\xe8\x0d\x14\x58\x05\x36\xa7\xeb\xd8\x05\xe5\x27\x6f\x51"
606 "\xb8\xec\x90\xd9\x03\xe1\xbc\x9c\x93\x38\x21\x5c\xaf\x4e\x6c\x7b"
607 "\x6c\x65\xa9\x92\xcd\x94\xef\xa8\xae\x90\x12\x14\x78\x2d\xa3\x15"
608 "\xaa\x42\xf1\xd9\x44\x64\x2c\x3c\xc0\xbd\x3a\x48\xd8\x80\x45\x8b"
609 "\xd1\x79\x82\xe0\x0f\xdf\x08\x3c\x60\x21\x6f\x31\x47\x98\xae\x2f"
610 "\xcb\xb1\xa1\xb9\xc1\xa3\x71\x5e\x4a\xc2\x67\xdf\x66\x0a\x51\xb5"
611 "\xad\x60\x05\xdb\x02\xd4\x1a\xd2\xb9\x4e\x01\x08\x2b\xc3\x57\xaf",
614 "\x30\x82\x02\x54\x30\x82\x01\xbd\xa0\x03\x02\x01\x02\x02\x01\x08"
615 "\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x30"
616 "\x2a\x31\x1b\x30\x19\x06\x03\x55\x04\x03\x0c\x12\x68\x78\x35\x30"
617 "\x39\x20\x54\x65\x73\x74\x20\x52\x6f\x6f\x74\x20\x43\x41\x31\x0b"
618 "\x30\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x30\x1e\x17\x0d\x30"
619 "\x39\x30\x34\x32\x36\x32\x30\x32\x39\x34\x30\x5a\x17\x0d\x31\x39"
620 "\x30\x34\x32\x34\x32\x30\x32\x39\x34\x30\x5a\x30\x1b\x31\x0b\x30"
621 "\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x31\x0c\x30\x0a\x06\x03"
622 "\x55\x04\x03\x0c\x03\x6b\x64\x63\x30\x81\x9f\x30\x0d\x06\x09\x2a"
623 "\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81\x8d\x00\x30\x81"
624 "\x89\x02\x81\x81\x00\xd2\x41\x7a\xf8\x4b\x55\xb2\xaf\x11\xf9\x43"
625 "\x9b\x43\x81\x09\x3b\x9a\x94\xcf\x00\xf4\x85\x75\x92\xd7\x2a\xa5"
626 "\x11\xf1\xa8\x50\x6e\xc6\x84\x74\x24\x17\xda\x84\xc8\x03\x37\xb2"
627 "\x20\xf3\xba\xb5\x59\x36\x21\x4d\xab\x70\xe2\xc3\x09\x93\x68\x14"
628 "\x12\x79\xc5\xbb\x9e\x1b\x4a\xf0\xc6\x24\x59\x25\xc3\x1c\xa8\x70"
629 "\x66\x5b\x3e\x41\x8e\xe3\x25\x71\x9a\x94\xa0\x5b\x46\x91\x6f\xdd"
630 "\x58\x14\xec\x89\xe5\x8c\x96\xc5\x38\x60\xe4\xab\xf2\x75\xee\x6e"
631 "\x62\xfc\xe1\xbd\x03\x47\xff\xc4\xbe\x0f\xca\x70\x73\xe3\x74\x58"
632 "\x3a\x2f\x04\x2d\x39\x02\x03\x01\x00\x01\xa3\x81\x98\x30\x81\x95"
633 "\x30\x09\x06\x03\x55\x1d\x13\x04\x02\x30\x00\x30\x0b\x06\x03\x55"
634 "\x1d\x0f\x04\x04\x03\x02\x05\xe0\x30\x12\x06\x03\x55\x1d\x25\x04"
635 "\x0b\x30\x09\x06\x07\x2b\x06\x01\x05\x02\x03\x05\x30\x1d\x06\x03"
636 "\x55\x1d\x0e\x04\x16\x04\x14\x3a\xd3\x73\xff\xab\xdb\x7d\x8d\xc6"
637 "\x3a\xa2\x26\x3e\xae\x78\x95\x80\xc9\xe6\x31\x30\x48\x06\x03\x55"
638 "\x1d\x11\x04\x41\x30\x3f\xa0\x3d\x06\x06\x2b\x06\x01\x05\x02\x02"
639 "\xa0\x33\x30\x31\xa0\x0d\x1b\x0b\x54\x45\x53\x54\x2e\x48\x35\x4c"
640 "\x2e\x53\x45\xa1\x20\x30\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15"
641 "\x1b\x06\x6b\x72\x62\x74\x67\x74\x1b\x0b\x54\x45\x53\x54\x2e\x48"
642 "\x35\x4c\x2e\x53\x45\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01"
643 "\x01\x05\x05\x00\x03\x81\x81\x00\x83\xf4\x14\xa7\x6e\x59\xff\x80"
644 "\x64\xe7\xfa\xcf\x13\x80\x86\xe1\xed\x02\x38\xad\x96\x72\x25\xe5"
645 "\x06\x7a\x9a\xbc\x24\x74\xa9\x75\x55\xb2\x49\x80\x69\x45\x95\x4a"
646 "\x4c\x76\xa9\xe3\x4e\x49\xd3\xc2\x69\x5a\x95\x03\xeb\xba\x72\x23"
647 "\x9c\xfd\x3d\x8b\xc6\x07\x82\x3b\xf4\xf3\xef\x6c\x2e\x9e\x0b\xac"
648 "\x9e\x6c\xbb\x37\x4a\xa1\x9e\x73\xd1\xdc\x97\x61\xba\xfc\xd3\x49"
649 "\xa6\xc2\x4c\x55\x2e\x06\x37\x76\xb5\xef\x57\xe7\x57\x58\x8a\x71"
650 "\x63\xf3\xeb\xe7\x55\x68\x0d\xf6\x46\x4c\xfb\xf9\x43\xbb\x0c\x92"
651 "\x4f\x4e\x22\x7b\x63\xe8\x4f\x9c",
664 memset(&c
, 0, sizeof(c
));
665 ret
= copy_Certificate(&c
, &c2
);
668 free_Certificate(&c2
);
670 for (i
= 0; i
< sizeof(certs
)/sizeof(certs
[0]); i
++) {
672 ret
= decode_Certificate((unsigned char *)certs
[i
].cert
,
673 certs
[i
].len
, &c
, &size
);
677 ret
= copy_Certificate(&c
, &c2
);
678 free_Certificate(&c
);
682 free_Certificate(&c2
);
693 "\x30\x80\x02\x01\x03\x31\x0b\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a"
694 "\x05\x00\x30\x80\x06\x07\x2b\x06\x01\x05\x02\x03\x03\xa0\x80\x24"
695 "\x80\x04\x50\x30\x4e\xa0\x2b\x30\x29\xa0\x03\x02\x01\x12\xa1\x22"
696 "\x04\x20\x78\xf4\x86\x31\xc6\xc2\xc9\xcb\xef\x0c\xd7\x3a\x2a\xcd"
697 "\x8c\x13\x34\x83\xb1\x5c\xa8\xbe\xbf\x2f\xea\xd2\xbb\xd8\x8c\x18"
698 "\x47\x01\xa1\x1f\x30\x1d\xa0\x03\x02\x01\x0c\xa1\x16\x04\x14\xa6"
699 "\x2c\x52\xb2\x80\x98\x30\x40\xbc\x5f\xb0\x77\x2d\x8a\xd7\xa1\xda"
700 "\x3c\xc5\x62\x00\x00\x00\x00\x00\x00\xa0\x82\x02\x09\x30\x82\x02"
701 "\x05\x30\x82\x01\x6e\xa0\x03\x02\x01\x02\x02\x04\x49\x75\x57\xbf"
702 "\x30\x0b\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x30\x3b\x31"
703 "\x1f\x30\x1d\x06\x03\x55\x04\x03\x0c\x16\x63\x6f\x6d\x2e\x61\x70"
704 "\x70\x6c\x65\x2e\x6b\x65\x72\x62\x65\x72\x6f\x73\x2e\x6b\x64\x63"
705 "\x31\x18\x30\x16\x06\x03\x55\x04\x0a\x0c\x0f\x53\x79\x73\x74\x65"
706 "\x6d\x20\x49\x64\x65\x6e\x74\x69\x74\x79\x30\x1e\x17\x0d\x30\x39"
707 "\x31\x32\x30\x34\x30\x30\x32\x30\x32\x34\x5a\x17\x0d\x32\x39\x31"
708 "\x31\x32\x39\x30\x30\x32\x30\x32\x34\x5a\x30\x3b\x31\x1f\x30\x1d"
709 "\x06\x03\x55\x04\x03\x0c\x16\x63\x6f\x6d\x2e\x61\x70\x70\x6c\x65"
710 "\x2e\x6b\x65\x72\x62\x65\x72\x6f\x73\x2e\x6b\x64\x63\x31\x18\x30"
711 "\x16\x06\x03\x55\x04\x0a\x0c\x0f\x53\x79\x73\x74\x65\x6d\x20\x49"
712 "\x64\x65\x6e\x74\x69\x74\x79\x30\x81\x9f\x30\x0d\x06\x09\x2a\x86"
713 "\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81\x8d\x00\x30\x81\x89"
714 "\x02\x81\x81\x00\xb2\xc5\x4b\x34\xe3\x93\x99\xbb\xaa\xd1\x70\x62"
715 "\x6c\x9c\xcc\xa6\xbc\x47\xc3\x23\xff\x15\xb9\x11\x27\x0a\xf8\x55"
716 "\x4c\xb2\x43\x34\x75\xad\x55\xbb\xb9\x8a\xd0\x25\x64\xa4\x8c\x82"
717 "\x74\x5d\x89\x52\xe2\x76\x75\x08\x67\xb5\x9c\x9c\x69\x86\x0c\x6d"
718 "\x79\xf7\xa0\xbe\x42\x8f\x90\x46\x0c\x18\xf4\x7a\x56\x17\xa4\x65"
719 "\x00\x3a\x5e\x3e\xbf\xbc\xf5\xe2\x2c\x26\x03\x52\xdd\xd4\x85\x3f"
720 "\x03\xd7\x0c\x45\x7f\xff\xdd\x1e\x70\x6c\x9f\xb0\x8c\xd0\x33\xad"
721 "\x92\x54\x17\x9d\x88\x89\x1a\xee\xef\xf7\x96\x3e\x68\xc3\xd1\x60"
722 "\x47\x86\x80\x5d\x02\x03\x01\x00\x01\xa3\x18\x30\x16\x30\x14\x06"
723 "\x03\x55\x1d\x25\x04\x0d\x30\x0b\x06\x09\x2a\x86\x48\x86\xf7\x63"
724 "\x64\x04\x04\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05"
725 "\x05\x00\x03\x81\x81\x00\x9b\xbb\xaa\x63\x66\xd8\x70\x84\x3e\xf6"
726 "\xa1\x3b\xf3\xe6\xd7\x3d\xfc\x4f\xc9\x45\xaa\x31\x43\x8d\xb5\x72"
727 "\xe4\x34\x95\x7b\x6e\x5f\xe5\xc8\x5e\xaf\x12\x08\x6d\xd7\x25\x76"
728 "\x40\xd5\xdc\x83\x7f\x2f\x74\xd1\x63\xc0\x7c\x26\x4d\x53\x10\xe7"
729 "\xfa\xcc\xf2\x60\x41\x63\xdf\x56\xd6\xd9\xc0\xb4\xd0\x73\x99\x54"
730 "\x40\xad\x90\x79\x2d\xd2\x5e\xcb\x13\x22\x2b\xd0\x76\xef\x8a\x48"
731 "\xfd\xb2\x6e\xca\x04\x4e\x91\x3f\xb4\x63\xad\x22\x3a\xf7\x20\x9c"
732 "\x4c\x0e\x47\x78\xe5\x2a\x85\x0e\x90\x7a\xce\x46\xe6\x15\x02\xb0"
733 "\x83\xe7\xac\xfa\x92\xf8\x31\x81\xe8\x30\x81\xe5\x02\x01\x01\x30"
734 "\x43\x30\x3b\x31\x1f\x30\x1d\x06\x03\x55\x04\x03\x0c\x16\x63\x6f"
735 "\x6d\x2e\x61\x70\x70\x6c\x65\x2e\x6b\x65\x72\x62\x65\x72\x6f\x73"
736 "\x2e\x6b\x64\x63\x31\x18\x30\x16\x06\x03\x55\x04\x0a\x0c\x0f\x53"
737 "\x79\x73\x74\x65\x6d\x20\x49\x64\x65\x6e\x74\x69\x74\x79\x02\x04"
738 "\x49\x75\x57\xbf\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x30"
739 "\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x04\x81"
740 "\x80\x50\x2c\x69\xe1\xd2\xc4\xd1\xcc\xdc\xe0\xe9\x8a\x6b\x6a\x97"
741 "\x1b\xb4\xe0\xa8\x20\xbe\x09\x6d\xe1\x55\x5f\x07\x70\x94\x2e\x14"
742 "\xed\x4e\xb1\x69\x75\x40\xbb\x99\x87\xed\x23\x50\x27\x5f\xaa\xc4"
743 "\x84\x60\x06\xfe\x45\xfd\x7e\x1b\x18\xe0\x0b\x77\x35\x2a\xb2\xf2"
744 "\xe0\x88\x31\xad\x82\x31\x4a\xbc\x6d\x71\x62\xe6\x4d\x33\xb4\x09"
745 "\x6e\x3f\x14\x12\xf2\x89\x29\x31\x84\x60\x2b\xa8\x2d\xe6\xca\x2f"
746 "\x03\x3d\xd4\x69\x89\xb3\x98\xfd\xac\x63\x14\xaf\x6a\x52\x2a\xac"
747 "\xe3\x8e\xfa\x21\x41\x8f\xcc\x04\x2d\x52\xee\x49\x54\x0d\x58\x51"
754 test_SignedData(void)
760 for (i
= 0; i
< sizeof(signeddata
) / sizeof(signeddata
[0]); i
++) {
762 ret
= decode_SignedData((unsigned char *)signeddata
[i
].sd
,
763 signeddata
[i
].len
, &sd
, &size
);
767 free_SignedData(&sd
);
775 cmp_TESTLargeTag (void *a
, void *b
)
777 TESTLargeTag
*aa
= a
;
778 TESTLargeTag
*ab
= b
;
780 COMPARE_INTEGER(aa
,ab
,foo
);
781 COMPARE_INTEGER(aa
,ab
,bar
);
786 test_large_tag (void)
788 struct test_case tests
[] = {
789 { NULL
, 15, "\x30\x0d\xbf\x7f\x03\x02\x01\x01\xbf\x81\x00\x03\x02\x01\x02", "large tag 1" }
792 int ntests
= sizeof(tests
) / sizeof(*tests
);
795 memset(<1
, 0, sizeof(lt1
));
801 return generic_test (tests
, ntests
, sizeof(TESTLargeTag
),
802 (generic_encode
)encode_TESTLargeTag
,
803 (generic_length
)length_TESTLargeTag
,
804 (generic_decode
)decode_TESTLargeTag
,
805 (generic_free
)free_TESTLargeTag
,
807 (generic_copy
)copy_TESTLargeTag
);
818 check_tag_length(void)
820 struct test_data td
[] = {
821 { 1, 3, 3, "\x02\x01\x00"},
822 { 1, 3, 3, "\x02\x01\x7f"},
823 { 1, 4, 4, "\x02\x02\x00\x80"},
824 { 1, 4, 4, "\x02\x02\x01\x00"},
825 { 1, 4, 4, "\x02\x02\x02\x00"},
826 { 0, 3, 0, "\x02\x02\x00"},
827 { 0, 3, 0, "\x02\x7f\x7f"},
828 { 0, 4, 0, "\x02\x03\x00\x80"},
829 { 0, 4, 0, "\x02\x7f\x01\x00"},
830 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
833 TESTuint32 values
[] = {0, 127, 128, 256, 512,
834 0, 127, 128, 256, 512 };
836 int i
, ret
, failed
= 0;
839 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
840 struct map_page
*page
;
842 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
844 ret
= decode_TESTuint32(buf
, td
[i
].len
, &u
, &sz
);
847 printf("failed with tag len test %d\n", i
);
852 printf("failed with success for tag len test %d\n", i
);
855 if (td
[i
].expected_len
!= sz
) {
856 printf("wrong expected size for tag test %d\n", i
);
859 if (values
[i
] != u
) {
860 printf("wrong value for tag test %d\n", i
);
864 map_free(page
, "test", "decode");
870 check_tag_length64(void)
872 struct test_data td
[] = {
873 { 1, 3, 3, "\x02\x01\x00"},
874 { 1, 7, 7, "\x02\x05\x01\xff\xff\xff\xff"},
875 { 1, 7, 7, "\x02\x05\x02\x00\x00\x00\x00"},
876 { 1, 9, 9, "\x02\x07\x7f\xff\xff\xff\xff\xff\xff"},
877 { 1, 10, 10, "\x02\x08\x00\x80\x00\x00\x00\x00\x00\x00"},
878 { 1, 10, 10, "\x02\x08\x7f\xff\xff\xff\xff\xff\xff\xff"},
879 { 1, 11, 11, "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"},
880 { 0, 3, 0, "\x02\x02\x00"},
881 { 0, 3, 0, "\x02\x7f\x7f"},
882 { 0, 4, 0, "\x02\x03\x00\x80"},
883 { 0, 4, 0, "\x02\x7f\x01\x00"},
884 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
887 TESTuint64 values
[] = {0, 8589934591LL, 8589934592LL,
888 36028797018963967LL, 36028797018963968LL,
889 9223372036854775807LL, 18446744073709551615ULL,
890 0, 127, 128, 256, 512 };
892 int i
, ret
, failed
= 0;
895 if (sizeof(TESTuint64
) != sizeof(uint64_t)) {
897 printf("sizeof(TESTuint64) %d != sizeof(uint64_t) %d\n",
898 (int)sizeof(TESTuint64
), (int)sizeof(uint64_t));
901 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
902 struct map_page
*page
;
904 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
906 ret
= decode_TESTuint64(buf
, td
[i
].len
, &u
, &sz
);
909 printf("failed with tag len test %d\n", i
);
910 printf("ret = %d\n", ret
);
915 printf("failed with success for tag len test %d\n", i
);
918 if (td
[i
].expected_len
!= sz
) {
919 printf("wrong expected size for tag test %d\n", i
);
920 printf("sz = %lu\n", (unsigned long)sz
);
923 if (values
[i
] != u
) {
924 printf("wrong value for tag test %d\n", i
);
925 printf("Expected value: %llu\nActual value: %llu\n",
926 (unsigned long long)values
[i
], (unsigned long long)u
);
930 map_free(page
, "test", "decode");
936 check_tag_length64s(void)
938 struct test_data td
[] = {
939 { 1, 3, 3, "\x02\x01\x00"},
940 { 1, 7, 7, "\x02\x05\xfe\x00\x00\x00\x01"},
941 { 1, 7, 7, "\x02\x05\xfe\x00\x00\x00\x00"},
942 { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x01"},
943 { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x00"},
944 { 1, 10, 10, "\x02\x08\x80\x00\x00\x00\x00\x00\x00\x01"},
945 { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x01"},
946 { 0, 3, 0, "\x02\x02\x00"},
947 { 0, 3, 0, "\x02\x7f\x7f"},
948 { 0, 4, 0, "\x02\x03\x00\x80"},
949 { 0, 4, 0, "\x02\x7f\x01\x00"},
950 { 0, 5, 0, "\x02\xff\x7f\x02\x00"}
953 TESTint64 values
[] = {0, -8589934591LL, -8589934592LL,
954 -36028797018963967LL, -36028797018963968LL,
955 -9223372036854775807LL, -36028797018963967LL,
956 0, 127, 128, 256, 512 };
958 int i
, ret
, failed
= 0;
961 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++) {
962 struct map_page
*page
;
964 buf
= map_alloc(OVERRUN
, td
[i
].data
, td
[i
].len
, &page
);
966 ret
= decode_TESTint64(buf
, td
[i
].len
, &u
, &sz
);
969 printf("failed with tag len test %d\n", i
);
970 printf("ret = %d\n", ret
);
975 printf("failed with success for tag len test %d\n", i
);
978 if (td
[i
].expected_len
!= sz
) {
979 printf("wrong expected size for tag test %d\n", i
);
980 printf("sz = %lu\n", (unsigned long)sz
);
983 if (values
[i
] != u
) {
984 printf("wrong value for tag test %d\n", i
);
985 printf("Expected value: %lld\nActual value: %lld\n",
986 (long long)values
[i
], (long long)u
);
990 map_free(page
, "test", "decode");
996 cmp_TESTChoice (void *a
, void *b
)
1004 struct test_case tests
[] = {
1005 { NULL
, 5, "\xa1\x03\x02\x01\x01", "large choice 1" },
1006 { NULL
, 5, "\xa2\x03\x02\x01\x02", "large choice 2" }
1009 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
1014 memset(&c1
, 0, sizeof(c1
));
1015 c1
.element
= choice_TESTChoice1_i1
;
1019 memset(&c2_1
, 0, sizeof(c2_1
));
1020 c2_1
.element
= choice_TESTChoice1_i2
;
1022 tests
[1].val
= &c2_1
;
1024 ret
+= generic_test (tests
, ntests
, sizeof(TESTChoice1
),
1025 (generic_encode
)encode_TESTChoice1
,
1026 (generic_length
)length_TESTChoice1
,
1027 (generic_decode
)decode_TESTChoice1
,
1028 (generic_free
)free_TESTChoice1
,
1030 (generic_copy
)copy_TESTChoice1
);
1032 memset(&c2_2
, 0, sizeof(c2_2
));
1033 c2_2
.element
= choice_TESTChoice2_asn1_ellipsis
;
1034 c2_2
.u
.asn1_ellipsis
.data
= "\xa2\x03\x02\x01\x02";
1035 c2_2
.u
.asn1_ellipsis
.length
= 5;
1036 tests
[1].val
= &c2_2
;
1038 ret
+= generic_test (tests
, ntests
, sizeof(TESTChoice2
),
1039 (generic_encode
)encode_TESTChoice2
,
1040 (generic_length
)length_TESTChoice2
,
1041 (generic_decode
)decode_TESTChoice2
,
1042 (generic_free
)free_TESTChoice2
,
1044 (generic_copy
)copy_TESTChoice2
);
1049 /* Test --decorate=TYPE:FIELD-TYPE:field-name[?] */
1051 test_decorated(void)
1053 TESTNotDecorated tnd
;
1054 TESTDecorated td
, td_copy
;
1059 memset(&td
, 0, sizeof(td
));
1060 memset(&tnd
, 0, sizeof(tnd
));
1062 my_copy_vers_called
= 0;
1063 my_free_vers_called
= 0;
1068 if ((td
.version2
= malloc(sizeof(*td
.version2
))) == NULL
)
1069 errx(1, "out of memory");
1071 ASN1_MALLOC_ENCODE(TESTDecorated
, ptr
, len
, &td
, &size
, ret
);
1073 warnx("could not encode a TESTDecorated struct");
1076 ret
= decode_TESTNotDecorated(ptr
, len
, &tnd
, &size
);
1078 warnx("could not decode a TESTDecorated struct as TESTNotDecorated");
1083 warnx("TESTDecorated encoded size mismatch");
1086 if (td
.version
!= tnd
.version
) {
1087 warnx("TESTDecorated did not decode as a TESTNotDecorated correctly");
1090 if (copy_TESTDecorated(&td
, &td_copy
)) {
1091 warnx("copy_TESTDecorated() failed");
1094 if (td
.version
!= td_copy
.version
) {
1095 warnx("copy_TESTDecorated() did not work correctly (1)");
1098 if (td_copy
.version2
== NULL
|| *td
.version2
!= *td_copy
.version2
) {
1099 warnx("copy_TESTDecorated() did not work correctly (2)");
1102 if (td
.version3
.v
!= td_copy
.version3
.v
||
1103 my_copy_vers_called
!= 1) {
1104 warnx("copy_TESTDecorated() did not work correctly (3)");
1107 if (td_copy
.privthing
!= 0) {
1108 warnx("copy_TESTDecorated() did not work correctly (4)");
1112 free_TESTDecorated(&td_copy
);
1113 free_TESTDecorated(&td
);
1115 warnx("free_TESTDecorated() did not work correctly (1)");
1118 if (td
.version3
.v
!= 0 || my_free_vers_called
!= 2) {
1119 warnx("free_TESTDecorated() did not work correctly (2)");
1122 if (td
.privthing
!= 0) {
1123 warnx("free_TESTDecorated() did not work correctly (3)");
1130 test_extensible_choice(void)
1132 PA_FX_FAST_REQUEST r
, r2
;
1137 memset(&r
, 0, sizeof(r
));
1139 ret
= copy_PA_FX_FAST_REQUEST(&r
, &r2
);
1142 free_PA_FX_FAST_REQUEST(&r2
);
1145 r
.u
.asn1_ellipsis
.data
= "hello";
1146 r
.u
.asn1_ellipsis
.length
= sizeof("hello") - 1;
1147 ret
= copy_PA_FX_FAST_REQUEST(&r
, &r2
);
1149 errx(1, "Out of memory");
1150 if (r2
.element
!= 0)
1151 errx(1, "Extensible CHOICE copy failure to set discriminant to 0");
1152 if (r2
.u
.asn1_ellipsis
.length
!= r
.u
.asn1_ellipsis
.length
)
1153 errx(1, "Extensible CHOICE copy failure to copy extension");
1154 if (memcmp(r
.u
.asn1_ellipsis
.data
, r2
.u
.asn1_ellipsis
.data
,
1155 r
.u
.asn1_ellipsis
.length
) != 0)
1156 errx(1, "Extensible CHOICE copy failure to copy extension (2)");
1157 free_PA_FX_FAST_REQUEST(&r2
);
1159 ASN1_MALLOC_ENCODE(PA_FX_FAST_REQUEST
, ptr
, len
, &r
, &size
, ret
);
1160 if (ret
|| len
!= size
)
1161 errx(1, "Extensible CHOICE encoding failure");
1163 ret
= decode_PA_FX_FAST_REQUEST(ptr
, len
, &r2
, &size
);
1164 if (ret
|| len
!= size
)
1165 errx(1, "Extensible CHOICE decoding failure");
1167 if (r2
.element
!= 0)
1168 errx(1, "Extensible CHOICE decode failure to set discriminant to 0");
1169 if (r2
.u
.asn1_ellipsis
.length
!= r
.u
.asn1_ellipsis
.length
)
1170 errx(1, "Extensible CHOICE decode failure to copy extension");
1171 if (memcmp(r
.u
.asn1_ellipsis
.data
, r2
.u
.asn1_ellipsis
.data
,
1172 r
.u
.asn1_ellipsis
.length
) != 0)
1173 errx(1, "Extensible CHOICE decode failure to copy extension (2)");
1175 free_PA_FX_FAST_REQUEST(&r2
);
1181 test_decorated_choice(void)
1183 TESTNotDecoratedChoice tndc
;
1184 TESTDecoratedChoice tdc
, tdc_copy
;
1189 memset(&tdc
, 0, sizeof(tdc
));
1190 memset(&tndc
, 0, sizeof(tndc
));
1192 my_copy_vers_called
= 0;
1193 my_free_vers_called
= 0;
1195 tdc
.element
= choice_TESTDecoratedChoice_version
;
1198 tdc
.privthing
= &tdc
;
1199 if ((tdc
.version2
= malloc(sizeof(*tdc
.version2
))) == NULL
)
1200 errx(1, "out of memory");
1202 ASN1_MALLOC_ENCODE(TESTDecoratedChoice
, ptr
, len
, &tdc
, &size
, ret
);
1204 warnx("could not encode a TESTDecoratedChoice struct");
1207 ret
= decode_TESTNotDecoratedChoice(ptr
, len
, &tndc
, &size
);
1209 warnx("could not decode a TESTDecoratedChoice struct as TESTNotDecoratedChoice");
1214 warnx("TESTDecoratedChoice encoded size mismatch");
1217 if ((int)tdc
.element
!= (int)tndc
.element
||
1218 tdc
.u
.version
!= tndc
.u
.version
) {
1219 warnx("TESTDecoratedChoice did not decode as a TESTNotDecoratedChoice correctly");
1222 if (copy_TESTDecoratedChoice(&tdc
, &tdc_copy
)) {
1223 warnx("copy_TESTDecoratedChoice() failed");
1226 if ((int)tdc
.element
!= (int)tdc_copy
.element
||
1227 tdc
.u
.version
!= tdc_copy
.u
.version
) {
1228 warnx("copy_TESTDecoratedChoice() did not work correctly (1)");
1231 if (tdc_copy
.version2
== NULL
|| *tdc
.version2
!= *tdc_copy
.version2
) {
1232 warnx("copy_TESTDecoratedChoice() did not work correctly (2)");
1235 if (tdc
.version3
.v
!= tdc_copy
.version3
.v
||
1236 my_copy_vers_called
!= 1) {
1237 warnx("copy_TESTDecoratedChoice() did not work correctly (3)");
1240 if (tdc_copy
.privthing
!= 0) {
1241 warnx("copy_TESTDecoratedChoice() did not work correctly (4)");
1245 free_TESTDecoratedChoice(&tdc_copy
);
1246 free_TESTDecoratedChoice(&tdc
);
1248 warnx("free_TESTDecoratedChoice() did not work correctly (1)");
1251 if (tdc
.version3
.v
!= 0 || my_free_vers_called
!= 2) {
1252 warnx("free_TESTDecoratedChoice() did not work correctly (2)");
1255 if (tdc
.privthing
!= 0) {
1256 warnx("free_TESTDecoratedChoice() did not work correctly (3)");
1264 cmp_TESTImplicit (void *a
, void *b
)
1266 TESTImplicit
*aa
= a
;
1267 TESTImplicit
*ab
= b
;
1269 COMPARE_INTEGER(aa
,ab
,ti1
);
1270 COMPARE_INTEGER(aa
,ab
,ti2
.foo
);
1271 COMPARE_INTEGER(aa
,ab
,ti3
);
1276 cmp_TESTImplicit2 (void *a
, void *b
)
1278 TESTImplicit2
*aa
= a
;
1279 TESTImplicit2
*ab
= b
;
1281 COMPARE_INTEGER(aa
,ab
,ti1
);
1282 COMPARE_INTEGER(aa
,ab
,ti3
);
1283 IF_OPT_COMPARE(aa
,ab
,ti4
) {
1284 COMPARE_INTEGER(aa
,ab
,ti4
[0]);
1290 cmp_TESTImplicit3 (void *a
, void *b
)
1292 TESTImplicit3
*aa
= a
;
1293 TESTImplicit3
*ab
= b
;
1295 COMPARE_INTEGER(aa
,ab
,element
);
1296 if (aa
->element
== choice_TESTImplicit3_ti1
) {
1297 COMPARE_INTEGER(aa
,ab
,u
.ti1
);
1299 COMPARE_INTEGER(aa
,ab
,u
.ti2
.element
);
1300 COMPARE_INTEGER(aa
,ab
,u
.ti2
.u
.i1
);
1306 cmp_TESTImplicit4 (void *a
, void *b
)
1308 TESTImplicit4
*aa
= a
;
1309 TESTImplicit4
*ab
= b
;
1311 COMPARE_INTEGER(aa
,ab
,element
);
1312 if (aa
->element
== choice_TESTImplicit4_ti1
) {
1313 COMPARE_INTEGER(aa
,ab
,u
.ti1
);
1315 COMPARE_INTEGER(aa
,ab
,u
.ti2
.element
);
1316 COMPARE_INTEGER(aa
,ab
,u
.ti2
.u
.i1
);
1322 test_implicit (void)
1326 * UNIV CONS Sequence = 14 bytes {
1327 * CONTEXT PRIM tag 0 = 1 bytes [0] IMPLICIT content
1328 * CONTEXT CONS tag 1 = 6 bytes [1]
1329 * CONTEXT CONS tag 127 = 3 bytes [127]
1330 * UNIV PRIM Integer = integer 2
1331 * CONTEXT PRIM tag 2 = 1 bytes [2] IMPLICIT content
1334 struct test_case tests
[] = {
1336 "\x30\x0e\x80\x01\x00\xa1\x06\xbf\x7f\x03\x02\x01\x02\x82\x01\x03",
1340 * UNIV CONS Sequence = 10 bytes {
1341 * CONTEXT PRIM tag 0 = 1 bytes [0] IMPLICIT content
1342 * CONTEXT PRIM tag 2 = 1 bytes [2] IMPLICIT content
1343 * CONTEXT PRIM tag 51 = 1 bytes [51] IMPLICIT content
1346 struct test_case tests2
[] = {
1348 "\x30\x0a\x80\x01\x01\x82\x01\x03\x9f\x33\x01\x04",
1352 * CONTEXT CONS tag 5 = 5 bytes [5]
1353 * CONTEXT CONS tag 1 = 3 bytes [1]
1354 * UNIV PRIM Integer = integer 5
1356 struct test_case tests3
[] = {
1358 "\xa5\x05\xa1\x03\x02\x01\x05",
1362 * Notice: same as tests3[].bytes.
1364 * CONTEXT CONS tag 5 = 5 bytes [5]
1365 * CONTEXT CONS tag 1 = 3 bytes [1]
1366 * UNIV PRIM Integer = integer 5
1368 struct test_case tests4
[] = {
1370 "\xa5\x05\xa1\x03\x02\x01\x05",
1380 memset(&c0
, 0, sizeof(c0
));
1386 memset(&c1
, 0, sizeof(c1
));
1390 tests2
[0].val
= &c1
;
1392 memset(&c2
, 0, sizeof(c2
));
1393 c2
.element
= choice_TESTImplicit3_ti2
;
1394 c2
.u
.ti2
.element
= choice_TESTImplicit3_ti2_i1
;
1396 tests3
[0].val
= &c2
;
1398 memset(&c3
, 0, sizeof(c3
));
1399 c3
.element
= choice_TESTImplicit4_ti2
;
1400 c3
.u
.ti2
.element
= choice_TESTChoice2_i1
;
1402 tests4
[0].val
= &c3
;
1404 ret
+= generic_test(tests
,
1405 sizeof(tests
) / sizeof(*tests
),
1406 sizeof(TESTImplicit
),
1407 (generic_encode
)encode_TESTImplicit
,
1408 (generic_length
)length_TESTImplicit
,
1409 (generic_decode
)decode_TESTImplicit
,
1410 (generic_free
)free_TESTImplicit
,
1412 (generic_copy
)copy_TESTImplicit
);
1414 ret
+= generic_test(tests2
,
1415 sizeof(tests2
) / sizeof(*tests2
),
1416 sizeof(TESTImplicit2
),
1417 (generic_encode
)encode_TESTImplicit2
,
1418 (generic_length
)length_TESTImplicit2
,
1419 (generic_decode
)decode_TESTImplicit2
,
1420 (generic_free
)free_TESTImplicit2
,
1424 ret
+= generic_test(tests3
,
1425 sizeof(tests3
) / sizeof(*tests3
),
1426 sizeof(TESTImplicit3
),
1427 (generic_encode
)encode_TESTImplicit3
,
1428 (generic_length
)length_TESTImplicit3
,
1429 (generic_decode
)decode_TESTImplicit3
,
1430 (generic_free
)free_TESTImplicit3
,
1434 ret
+= generic_test(tests4
,
1435 sizeof(tests4
) / sizeof(*tests4
),
1436 sizeof(TESTImplicit4
),
1437 (generic_encode
)encode_TESTImplicit4
,
1438 (generic_length
)length_TESTImplicit4
,
1439 (generic_decode
)decode_TESTImplicit4
,
1440 (generic_free
)free_TESTImplicit4
,
1448 cmp_TESTAlloc (void *a
, void *b
)
1453 IF_OPT_COMPARE(aa
,ab
,tagless
) {
1454 COMPARE_INTEGER(aa
,ab
,tagless
->ai
);
1457 COMPARE_INTEGER(aa
,ab
,three
);
1459 IF_OPT_COMPARE(aa
,ab
,tagless2
) {
1460 COMPARE_OPT_OCTET_STRING(aa
, ab
, tagless2
);
1467 UNIV CONS Sequence 12
1468 UNIV CONS Sequence 5
1470 UNIV PRIM Integer 1 01
1472 UNIV PRIM Integer 1 03
1474 UNIV CONS Sequence 5
1476 UNIV PRIM Integer 1 03
1478 UNIV CONS Sequence 8
1480 UNIV PRIM Integer 1 04
1481 UNIV PRIM Integer 1 05
1486 test_taglessalloc (void)
1488 struct test_case tests
[] = {
1490 "\x30\x0c\x30\x05\xa0\x03\x02\x01\x01\xa1\x03\x02\x01\x03",
1493 "\x30\x05\xa1\x03\x02\x01\x03",
1496 "\x30\x08\xa1\x03\x02\x01\x04\x02\x01\x05",
1500 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
1501 TESTAlloc c1
, c2
, c3
;
1504 memset(&c1
, 0, sizeof(c1
));
1505 c1
.tagless
= ecalloc(1, sizeof(*c1
.tagless
));
1510 memset(&c2
, 0, sizeof(c2
));
1515 memset(&c3
, 0, sizeof(c3
));
1518 c3
.tagless2
= &any3
;
1519 any3
.data
= "\x02\x01\x05";
1523 ret
+= generic_test (tests
, ntests
, sizeof(TESTAlloc
),
1524 (generic_encode
)encode_TESTAlloc
,
1525 (generic_length
)length_TESTAlloc
,
1526 (generic_decode
)decode_TESTAlloc
,
1527 (generic_free
)free_TESTAlloc
,
1529 (generic_copy
)copy_TESTAlloc
);
1537 cmp_TESTOptional (void *a
, void *b
)
1539 TESTOptional
*aa
= a
;
1540 TESTOptional
*ab
= b
;
1542 IF_OPT_COMPARE(aa
,ab
,zero
) {
1543 COMPARE_OPT_INTEGER(aa
,ab
,zero
);
1545 IF_OPT_COMPARE(aa
,ab
,one
) {
1546 COMPARE_OPT_INTEGER(aa
,ab
,one
);
1552 UNIV CONS Sequence 5
1554 UNIV PRIM Integer 1 00
1556 UNIV CONS Sequence 5
1558 UNIV PRIM Integer 1 03
1560 UNIV CONS Sequence 10
1562 UNIV PRIM Integer 1 00
1564 UNIV PRIM Integer 1 01
1569 test_optional (void)
1571 struct test_case tests
[] = {
1576 "\x30\x05\xa0\x03\x02\x01\x00",
1579 "\x30\x05\xa1\x03\x02\x01\x01",
1582 "\x30\x0a\xa0\x03\x02\x01\x00\xa1\x03\x02\x01\x01",
1586 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
1587 TESTOptional c0
, c1
, c2
, c3
;
1607 ret
+= generic_test (tests
, ntests
, sizeof(TESTOptional
),
1608 (generic_encode
)encode_TESTOptional
,
1609 (generic_length
)length_TESTOptional
,
1610 (generic_decode
)decode_TESTOptional
,
1611 (generic_free
)free_TESTOptional
,
1613 (generic_copy
)copy_TESTOptional
);
1619 check_fail_largetag(void)
1621 struct test_case tests
[] = {
1622 {NULL
, 14, "\x30\x0c\xbf\x87\xff\xff\xff\xff\xff\x7f\x03\x02\x01\x01",
1624 {NULL
, 0, "", "empty buffer"},
1625 {NULL
, 7, "\x30\x05\xa1\x03\x02\x02\x01",
1627 {NULL
, 7, "\x30\x04\xa1\x03\x02\x02\x01",
1629 {NULL
, 7, "\x30\x03\xa1\x03\x02\x02\x01",
1630 "three too short" },
1631 {NULL
, 7, "\x30\x02\xa1\x03\x02\x02\x01",
1633 {NULL
, 7, "\x30\x01\xa1\x03\x02\x02\x01",
1635 {NULL
, 7, "\x30\x00\xa1\x03\x02\x02\x01",
1637 {NULL
, 7, "\x30\x05\xa1\x04\x02\x02\x01",
1638 "inner one too long" },
1639 {NULL
, 7, "\x30\x00\xa1\x02\x02\x02\x01",
1640 "inner one too short" },
1641 {NULL
, 8, "\x30\x05\xbf\x7f\x03\x02\x02\x01",
1642 "inner one too short"},
1643 {NULL
, 8, "\x30\x06\xbf\x64\x03\x02\x01\x01",
1645 {NULL
, 10, "\x30\x08\xbf\x9a\x9b\x38\x03\x02\x01\x01",
1648 int ntests
= sizeof(tests
) / sizeof(*tests
);
1650 return generic_decode_fail(tests
, ntests
, sizeof(TESTLargeTag
),
1651 (generic_decode
)decode_TESTLargeTag
);
1656 check_fail_sequence(void)
1658 struct test_case tests
[] = {
1659 {NULL
, 0, "", "empty buffer"},
1661 "\x30\x16\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01"
1662 "\x02\x01\x01\xa2\x03\x02\x01\x01",
1663 "missing one byte from the end, internal length ok"},
1665 "\x30\x18\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01"
1666 "\x02\x01\x01\xa2\x03\x02\x01\x01",
1667 "inner length one byte too long"},
1669 "\x30\x17\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01"
1670 "\x01\x02\x01\x01\xa2\x03\x02\x01\x01",
1671 "correct buffer but missing one too short"}
1673 int ntests
= sizeof(tests
) / sizeof(*tests
);
1675 return generic_decode_fail(tests
, ntests
, sizeof(TESTSeq
),
1676 (generic_decode
)decode_TESTSeq
);
1680 check_fail_choice(void)
1682 struct test_case tests
[] = {
1684 "\xa1\x02\x02\x01\x01",
1685 "choice one too short"},
1687 "\xa1\x03\x02\x02\x01",
1688 "choice one too short inner"}
1690 int ntests
= sizeof(tests
) / sizeof(*tests
);
1692 return generic_decode_fail(tests
, ntests
, sizeof(TESTChoice1
),
1693 (generic_decode
)decode_TESTChoice1
);
1697 check_fail_Ticket(void)
1702 struct test_case test
;
1705 for (i
= 0; i
< sizeof(buf
); i
++) {
1706 memset(buf
, 0, sizeof(buf
));
1707 memset(&ticket
, 0, sizeof(ticket
));
1711 test
.name
= "zero life";
1712 ret
= generic_decode_fail(&test
, 1, sizeof(Ticket
),
1713 (generic_decode
)decode_Ticket
);
1730 ret
= add_TESTSeqOf(&seq
, &i
);
1731 if (ret
) { printf("failed adding\n"); goto out
; }
1732 ret
= add_TESTSeqOf(&seq
, &i
);
1733 if (ret
) { printf("failed adding\n"); goto out
; }
1734 ret
= add_TESTSeqOf(&seq
, &i
);
1735 if (ret
) { printf("failed adding\n"); goto out
; }
1736 ret
= add_TESTSeqOf(&seq
, &i
);
1737 if (ret
) { printf("failed adding\n"); goto out
; }
1739 ret
= remove_TESTSeqOf(&seq
, seq
.len
- 1);
1740 if (ret
) { printf("failed removing\n"); goto out
; }
1741 ret
= remove_TESTSeqOf(&seq
, 2);
1742 if (ret
) { printf("failed removing\n"); goto out
; }
1743 ret
= remove_TESTSeqOf(&seq
, 0);
1744 if (ret
) { printf("failed removing\n"); goto out
; }
1745 ret
= remove_TESTSeqOf(&seq
, 0);
1746 if (ret
) { printf("failed removing\n"); goto out
; }
1747 ret
= remove_TESTSeqOf(&seq
, 0);
1749 printf("can remove from empty list");
1754 printf("seq not empty!");
1757 free_TESTSeqOf(&seq
);
1765 #define test_seq_of(type, ok, ptr) \
1767 heim_octet_string os; \
1770 ASN1_MALLOC_ENCODE(type, os.data, os.length, ptr, &size, ret); \
1773 if (os.length != size) \
1775 ret = decode_##type(os.data, os.length, &decode, &size); \
1781 free_##type(&decode); \
1791 check_seq_of_size(void)
1793 #if 0 /* template */
1794 TESTInteger integers
[4] = { 1, 2, 3, 4 };
1798 TESTSeqSizeOf1 ssof1f1
= { 1, integers
};
1799 TESTSeqSizeOf1 ssof1ok1
= { 2, integers
};
1800 TESTSeqSizeOf1 ssof1f2
= { 3, integers
};
1802 test_seq_of(TESTSeqSizeOf1
, 0, &ssof1f1
);
1803 test_seq_of(TESTSeqSizeOf1
, 1, &ssof1ok1
);
1804 test_seq_of(TESTSeqSizeOf1
, 0, &ssof1f2
);
1807 TESTSeqSizeOf2 ssof2f1
= { 0, NULL
};
1808 TESTSeqSizeOf2 ssof2ok1
= { 1, integers
};
1809 TESTSeqSizeOf2 ssof2ok2
= { 2, integers
};
1810 TESTSeqSizeOf2 ssof2f2
= { 3, integers
};
1812 test_seq_of(TESTSeqSizeOf2
, 0, &ssof2f1
);
1813 test_seq_of(TESTSeqSizeOf2
, 1, &ssof2ok1
);
1814 test_seq_of(TESTSeqSizeOf2
, 1, &ssof2ok2
);
1815 test_seq_of(TESTSeqSizeOf2
, 0, &ssof2f2
);
1818 TESTSeqSizeOf3 ssof3f1
= { 0, NULL
};
1819 TESTSeqSizeOf3 ssof3ok1
= { 1, integers
};
1820 TESTSeqSizeOf3 ssof3ok2
= { 2, integers
};
1822 test_seq_of(TESTSeqSizeOf3
, 0, &ssof3f1
);
1823 test_seq_of(TESTSeqSizeOf3
, 1, &ssof3ok1
);
1824 test_seq_of(TESTSeqSizeOf3
, 1, &ssof3ok2
);
1827 TESTSeqSizeOf4 ssof4ok1
= { 0, NULL
};
1828 TESTSeqSizeOf4 ssof4ok2
= { 1, integers
};
1829 TESTSeqSizeOf4 ssof4ok3
= { 2, integers
};
1830 TESTSeqSizeOf4 ssof4f1
= { 3, integers
};
1832 test_seq_of(TESTSeqSizeOf4
, 1, &ssof4ok1
);
1833 test_seq_of(TESTSeqSizeOf4
, 1, &ssof4ok2
);
1834 test_seq_of(TESTSeqSizeOf4
, 1, &ssof4ok3
);
1835 test_seq_of(TESTSeqSizeOf4
, 0, &ssof4f1
);
1842 check_TESTMechTypeList(void)
1844 TESTMechTypeList tl
;
1845 unsigned oid1
[] = { 1, 2, 840, 48018, 1, 2, 2};
1846 unsigned oid2
[] = { 1, 2, 840, 113554, 1, 2, 2};
1847 unsigned oid3
[] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 30};
1848 unsigned oid4
[] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10};
1849 TESTMechType array
[] = {{ 7, oid1
},
1860 ASN1_MALLOC_ENCODE(TESTMechTypeList
, ptr
, len
, &tl
, &size
, ret
);
1862 errx(1, "TESTMechTypeList: %d", ret
);
1870 cmp_TESTSeqOf4(void *a
, void *b
)
1876 IF_OPT_COMPARE(aa
, ab
, b1
) {
1877 COMPARE_INTEGER(aa
->b1
, ab
->b1
, len
);
1878 for (i
= 0; i
< aa
->b1
->len
; ++i
) {
1879 COMPARE_INTEGER(aa
->b1
->val
+i
, ab
->b1
->val
+i
, u1
);
1880 COMPARE_INTEGER(aa
->b1
->val
+i
, ab
->b1
->val
+i
, u2
);
1881 COMPARE_OCTET_STRING(aa
->b1
->val
+i
, ab
->b1
->val
+i
, s1
);
1882 COMPARE_OCTET_STRING(aa
->b1
->val
+i
, ab
->b1
->val
+i
, s2
);
1885 IF_OPT_COMPARE(aa
, ab
, b2
) {
1886 COMPARE_INTEGER(aa
->b2
, ab
->b2
, len
);
1887 for (i
= 0; i
< aa
->b2
->len
; ++i
) {
1888 COMPARE_INTEGER(aa
->b2
->val
+i
, ab
->b2
->val
+i
, u1
);
1889 COMPARE_INTEGER(aa
->b2
->val
+i
, ab
->b2
->val
+i
, u2
);
1890 COMPARE_INTEGER(aa
->b2
->val
+i
, ab
->b2
->val
+i
, u3
);
1891 COMPARE_OCTET_STRING(aa
->b2
->val
+i
, ab
->b2
->val
+i
, s1
);
1892 COMPARE_OCTET_STRING(aa
->b2
->val
+i
, ab
->b2
->val
+i
, s2
);
1893 COMPARE_OCTET_STRING(aa
->b2
->val
+i
, ab
->b2
->val
+i
, s3
);
1896 IF_OPT_COMPARE(aa
, ab
, b3
) {
1897 COMPARE_INTEGER(aa
->b3
, ab
->b3
, len
);
1898 for (i
= 0; i
< aa
->b3
->len
; ++i
) {
1899 COMPARE_INTEGER(aa
->b3
->val
+i
, ab
->b3
->val
+i
, u1
);
1900 COMPARE_INTEGER(aa
->b3
->val
+i
, ab
->b3
->val
+i
, u2
);
1901 COMPARE_INTEGER(aa
->b3
->val
+i
, ab
->b3
->val
+i
, u3
);
1902 COMPARE_INTEGER(aa
->b3
->val
+i
, ab
->b3
->val
+i
, u4
);
1903 COMPARE_OCTET_STRING(aa
->b3
->val
+i
, ab
->b3
->val
+i
, s1
);
1904 COMPARE_OCTET_STRING(aa
->b3
->val
+i
, ab
->b3
->val
+i
, s2
);
1905 COMPARE_OCTET_STRING(aa
->b3
->val
+i
, ab
->b3
->val
+i
, s3
);
1906 COMPARE_OCTET_STRING(aa
->b3
->val
+i
, ab
->b3
->val
+i
, s4
);
1916 struct test_case tests
[] = {
1921 "\x30\x02" "\xa1\x00",
1924 "\x30\x06" "\xa0\x02\x30\x00" "\xa1\x00",
1926 { NULL
, 2 + (2 + 0x18) + (2 + 0x27) + (2 + 0x31),
1927 "\x30\x76" /* 2 SEQ */
1928 "\xa0\x18\x30\x16" /* 4 [0] SEQ */
1929 "\x30\x14" /* 2 SEQ */
1930 "\x04\x00" /* 2 OCTET-STRING */
1931 "\x04\x02\x01\x02" /* 4 OCTET-STRING */
1932 "\x02\x01\x01" /* 3 INT */
1933 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"
1935 "\xa1\x27" /* 2 [1] IMPL SEQ */
1936 "\x30\x25" /* 2 SEQ */
1937 "\x02\x01\x01" /* 3 INT */
1938 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"
1940 "\x02\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00"
1942 "\x04\x00" /* 2 OCTET-STRING */
1943 "\x04\x02\x01\x02" /* 4 OCTET-STRING */
1944 "\x04\x04\x00\x01\x02\x03" /* 6 OCTET-STRING */
1945 "\xa2\x31" /* 2 [2] IMPL SEQ */
1946 "\x30\x2f" /* 2 SEQ */
1947 "\x04\x00" /* 2 OCTET-STRING */
1948 "\x02\x01\x01" /* 3 INT */
1949 "\x04\x02\x01\x02" /* 4 OCTET-STRING */
1950 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"
1952 "\x04\x04\x00\x01\x02\x03" /* 6 OCTET-STRING */
1953 "\x02\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00"
1955 "\x04\x01\x00" /* 3 OCTET-STRING */
1956 "\x02\x05\x01\x00\x00\x00\x00", /* 7 INT */
1960 int ntests
= sizeof(tests
) / sizeof(*tests
);
1962 struct TESTSeqOf4_b1 b1
[4];
1963 struct TESTSeqOf4_b2 b2
[4];
1964 struct TESTSeqOf4_b3 b3
[4];
1965 struct TESTSeqOf4_b1_val b1val
[4];
1966 struct TESTSeqOf4_b2_val b2val
[4];
1967 struct TESTSeqOf4_b3_val b3val
[4];
1972 tests
[0].val
= &c
[0];
1979 tests
[1].val
= &c
[1];
1988 tests
[2].val
= &c
[2];
1990 b1val
[3].s1
.data
= "";
1991 b1val
[3].s1
.length
= 0;
1993 b1val
[3].s2
.data
= "\x01\x02";
1994 b1val
[3].s2
.length
= 2;
1997 b2val
[3].s1
.data
= "";
1998 b2val
[3].s1
.length
= 0;
2000 b2val
[3].s2
.data
= "\x01\x02";
2001 b2val
[3].s2
.length
= 2;
2003 b2val
[3].s3
.data
= "\x00\x01\x02\x03";
2004 b2val
[3].s3
.length
= 4;
2005 b2val
[3].u3
= 1LL<<63;
2007 b3val
[3].s1
.data
= "";
2008 b3val
[3].s1
.length
= 0;
2010 b3val
[3].s2
.data
= "\x01\x02";
2011 b3val
[3].s2
.length
= 2;
2013 b3val
[3].s3
.data
= "\x00\x01\x02\x03";
2014 b3val
[3].s3
.length
= 4;
2015 b3val
[3].u3
= 1LL<<63;
2016 b3val
[3].s4
.data
= "\x00";
2017 b3val
[3].s4
.length
= 1;
2018 b3val
[3].u4
= 1LL<<32;
2021 b1
[3].val
= &b1val
[3];
2023 b2
[3].val
= &b2val
[3];
2025 b3
[3].val
= &b3val
[3];
2029 tests
[3].val
= &c
[3];
2031 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOf4
),
2032 (generic_encode
)encode_TESTSeqOf4
,
2033 (generic_length
)length_TESTSeqOf4
,
2034 (generic_decode
)decode_TESTSeqOf4
,
2035 (generic_free
)free_TESTSeqOf4
,
2037 (generic_copy
)copy_TESTSeqOf4
);
2042 cmp_test_seqof5 (void *a
, void *b
)
2044 TESTSeqOf5
*aval
= a
;
2045 TESTSeqOf5
*bval
= b
;
2047 IF_OPT_COMPARE(aval
, bval
, outer
) {
2048 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u0
);
2049 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s0
);
2050 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u1
);
2051 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s1
);
2052 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u2
);
2053 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s2
);
2054 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u3
);
2055 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s3
);
2056 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u4
);
2057 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s4
);
2058 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u5
);
2059 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s5
);
2060 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u6
);
2061 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s6
);
2062 COMPARE_INTEGER(&aval
->outer
->inner
, &bval
->outer
->inner
, u7
);
2063 COMPARE_OCTET_STRING(&aval
->outer
->inner
, &bval
->outer
->inner
, s7
);
2071 struct test_case tests
[] = {
2072 { NULL
, 2, "\x30\x00", "seq5 0" },
2074 "\x30\x7c" /* SEQ */
2075 "\x30\x7a" /* SEQ */
2076 "\x30\x78" /* SEQ */
2077 "\x02\x01\x01" /* INT 1 */
2078 "\x04\x06\x01\x01\x01\x01\x01\x01" /* "\0x1"x6 */
2079 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfe" /* INT ~1 */
2080 "\x04\x06\x02\x02\x02\x02\x02\x02" /* "\x02"x6 */
2081 "\x02\x01\x02" /* INT 2 */
2082 "\x04\x06\x03\x03\x03\x03\x03\x03" /* "\x03"x6 */
2083 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfd" /* INT ~2 */
2084 "\x04\x06\x04\x04\x04\x04\x04\x04" /* ... */
2086 "\x04\x06\x05\x05\x05\x05\x05\x05"
2087 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfc"
2088 "\x04\x06\x06\x06\x06\x06\x06\x06"
2090 "\x04\x06\x07\x07\x07\x07\x07\x07"
2091 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfb"
2092 "\x04\x06\x08\x08\x08\x08\x08\x08",
2096 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
2098 struct TESTSeqOf5_outer outer
;
2099 struct TESTSeqOf5_outer_inner inner
;
2101 heim_octet_string s
[8];
2105 tests
[0].val
= &c
[0];
2107 for (i
= 0; i
< 8; ++i
) {
2108 u
[i
] = (i
&1) == 0 ? i
/2+1 : ~(i
/2+1);
2109 s
[i
].data
= memset(malloc(s
[i
].length
= 6), i
+1, 6);
2112 inner
.u0
= u
[0]; inner
.u1
= u
[1]; inner
.u2
= u
[2]; inner
.u3
= u
[3];
2113 inner
.u4
= u
[4]; inner
.u5
= u
[5]; inner
.u6
= u
[6]; inner
.u7
= u
[7];
2114 inner
.s0
= s
[0]; inner
.s1
= s
[1]; inner
.s2
= s
[2]; inner
.s3
= s
[3];
2115 inner
.s4
= s
[4]; inner
.s5
= s
[5]; inner
.s6
= s
[6]; inner
.s7
= s
[7];
2117 outer
.inner
= inner
;
2118 c
[1].outer
= &outer
;
2119 tests
[1].val
= &c
[1];
2121 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOf5
),
2122 (generic_encode
)encode_TESTSeqOf5
,
2123 (generic_length
)length_TESTSeqOf5
,
2124 (generic_decode
)decode_TESTSeqOf5
,
2125 (generic_free
)free_TESTSeqOf5
,
2129 for (i
= 0; i
< 8; ++i
)
2136 cmp_default(void *a
, void *b
)
2138 TESTDefault
*aa
= a
;
2139 TESTDefault
*ab
= b
;
2141 COMPARE_STRING(aa
,ab
,name
);
2142 COMPARE_INTEGER(aa
,ab
,version
);
2143 COMPARE_INTEGER(aa
,ab
,maxint
);
2144 COMPARE_INTEGER(aa
,ab
,works
);
2151 struct test_case tests
[] = {
2152 #ifndef DISABLE_TEST_64
2153 { NULL
, 2, "\x30\x00", NULL
},
2156 "\x30\x17\x0c\x07\x68\x65\x69\x6d\x64\x61"
2157 "\x6c\xa0\x03\x02\x01\x07\x02\x04\x7f\xff"
2158 "\xff\xff\x01\x01\x00",
2161 #ifndef DISABLE_TEST_64
2163 "\x30\x08\xa0\x03\x02\x01\x07\x01\x01\x00",
2168 "\x30\x0f\x0c\x07\x68\x65\x69\x6d\x64\x61\x6c\x02\x04"
2174 TESTDefault values
[] = {
2175 #ifndef DISABLE_TEST_64
2176 { "Heimdal", 8, 9223372036854775807LL, 1 },
2178 { "heimdal", 7, 2147483647, 0 },
2179 #ifndef DISABLE_TEST_64
2180 { "Heimdal", 7, 9223372036854775807LL, 0 },
2182 { "heimdal", 8, 2147483647, 1 },
2185 int ntests
= sizeof(tests
) / sizeof(*tests
);
2187 for (i
= 0; i
< ntests
; ++i
) {
2188 tests
[i
].val
= &values
[i
];
2189 if (asprintf (&tests
[i
].name
, "TESTDefault %d", i
) < 0)
2191 if (tests
[i
].name
== NULL
)
2195 ret
= generic_test (tests
, ntests
, sizeof(TESTDefault
),
2196 (generic_encode
)encode_TESTDefault
,
2197 (generic_length
)length_TESTDefault
,
2198 (generic_decode
)decode_TESTDefault
,
2199 (generic_free
)free_TESTDefault
,
2201 (generic_copy
)copy_TESTDefault
);
2202 for (i
= 0; i
< ntests
; ++i
)
2203 free(tests
[i
].name
);
2209 test_x690sample(void)
2212 * Taken from X.690, Appendix A, though sadly it's not specified whether
2213 * it's in BER, DER, or CER, but it is clearly BER and neither DER nor CER
2214 * because the tags of the members of the X690SamplePersonnelRecord type
2215 * are not canonically sorted in the given sample.
2217 * Our compiler does NOT canonically sort the members of SET { ... } types
2218 * so it produces the same encoding after decoding this test vector. That
2219 * is clearly a bug given that we aim to output DER.
2221 * The template compiler doesn't even decode SET { ... } values properly
2222 * when their members are not in the same order as defined (but the regular
2225 X690SamplePersonnelRecord r
;
2226 heim_octet_string os
;
2227 unsigned char encoded_sample
[] = {
2228 0x60, 0x81, 0x85, 0x61, 0x10, 0x1a, 0x04, 0x4a, 0x6f, 0x68, 0x6e, 0x1a,
2229 0x01, 0x50, 0x1a, 0x05, 0x53, 0x6d, 0x69, 0x74, 0x68, 0xa0, 0x0a, 0x1a,
2230 0x08, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x42, 0x01, 0x33,
2231 0xa1, 0x0a, 0x43, 0x08, 0x31, 0x39, 0x37, 0x31, 0x30, 0x39, 0x31, 0x37,
2232 0xa2, 0x12, 0x61, 0x10, 0x1a, 0x04, 0x4d, 0x61, 0x72, 0x79, 0x1a, 0x01,
2233 0x54, 0x1a, 0x05, 0x53, 0x6d, 0x69, 0x74, 0x68, 0xa3, 0x42, 0x31, 0x1f,
2234 0x61, 0x11, 0x1a, 0x05, 0x52, 0x61, 0x6c, 0x70, 0x68, 0x1a, 0x01, 0x54,
2235 0x1a, 0x05, 0x53, 0x6d, 0x69, 0x74, 0x68, 0xa0, 0x0a, 0x43, 0x08, 0x31,
2236 0x39, 0x35, 0x37, 0x31, 0x31, 0x31, 0x31, 0x31, 0x1f, 0x61, 0x11, 0x1a,
2237 0x05, 0x53, 0x75, 0x73, 0x61, 0x6e, 0x1a, 0x01, 0x42, 0x1a, 0x05, 0x53,
2238 0x6d, 0x69, 0x74, 0x68, 0xa0, 0x0a, 0x43, 0x08, 0x31, 0x39, 0x35, 0x39,
2239 0x30, 0x37, 0x31, 0x37
2244 memset(&r
, 0, sizeof(r
));
2245 if (decode_X690SamplePersonnelRecord(encoded_sample
, sizeof(encoded_sample
), &r
, &sz
))
2247 if (sz
!= sizeof(encoded_sample
))
2249 free_X690SamplePersonnelRecord(&r
);
2250 memset(&r
, 0, sizeof(r
));
2252 /* We re-construct the record manually to double-check the spec */
2253 r
.name
.givenName
= strdup("John");
2254 r
.name
.initial
= strdup("P");
2255 r
.name
.familyName
= strdup("Smith");
2256 r
.title
= strdup("Director");
2257 r
.dateOfHire
= strdup("19710917");
2259 r
.nameOfSpouse
.givenName
= strdup("Mary");
2260 r
.nameOfSpouse
.initial
= strdup("T");
2261 r
.nameOfSpouse
.familyName
= strdup("Smith");
2262 r
.children
.val
= calloc(2, sizeof(r
.children
.val
[0]));
2264 r
.children
.val
[0].name
.givenName
= strdup("Ralph");
2265 r
.children
.val
[0].name
.initial
= strdup("T");
2266 r
.children
.val
[0].name
.familyName
= strdup("Smith");
2267 r
.children
.val
[0].dateOfBirth
= strdup("19571111");
2268 r
.children
.val
[1].name
.givenName
= strdup("Susan");
2269 r
.children
.val
[1].name
.initial
= strdup("B");
2270 r
.children
.val
[1].name
.familyName
= strdup("Smith");
2271 r
.children
.val
[1].dateOfBirth
= strdup("19590717");
2274 ASN1_MALLOC_ENCODE(X690SamplePersonnelRecord
, os
.data
, os
.length
, &r
, &sz
,
2276 if (ret
|| sz
!= sizeof(encoded_sample
) || sz
!= os
.length
||
2277 memcmp(encoded_sample
, os
.data
, sz
) != 0)
2279 free_X690SamplePersonnelRecord(&r
);
2284 #if ASN1_IOS_SUPPORTED
2288 unsigned char encoded_sample
[] = {
2289 0x30, 0x82, 0x04, 0x8e, 0x30, 0x82, 0x03, 0x76,
2290 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x6a,
2291 0x05, 0x97, 0xba, 0x71, 0xd7, 0xe6, 0xd3, 0xac,
2292 0x0e, 0xdc, 0x9e, 0xdc, 0x95, 0xa1, 0x5b, 0x99,
2293 0x8d, 0xe4, 0x0a, 0x30, 0x0d, 0x06, 0x09, 0x2a,
2294 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
2295 0x05, 0x00, 0x30, 0x55, 0x31, 0x0b, 0x30, 0x09,
2296 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43,
2297 0x48, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55,
2298 0x04, 0x0a, 0x13, 0x15, 0x53, 0x54, 0x4d, 0x69,
2299 0x63, 0x72, 0x6f, 0x65, 0x6c, 0x65, 0x63, 0x74,
2300 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x73, 0x20, 0x4e,
2301 0x56, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55,
2302 0x04, 0x03, 0x13, 0x1d, 0x53, 0x54, 0x4d, 0x20,
2303 0x54, 0x50, 0x4d, 0x20, 0x45, 0x4b, 0x20, 0x49,
2304 0x6e, 0x74, 0x65, 0x72, 0x6d, 0x65, 0x64, 0x69,
2305 0x61, 0x74, 0x65, 0x20, 0x43, 0x41, 0x20, 0x30,
2306 0x35, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x38, 0x31,
2307 0x32, 0x31, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30,
2308 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x38, 0x31, 0x32,
2309 0x31, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
2310 0x5a, 0x30, 0x00, 0x30, 0x82, 0x01, 0x22, 0x30,
2311 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
2312 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
2313 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
2314 0x82, 0x01, 0x01, 0x00, 0xcc, 0x14, 0xeb, 0x27,
2315 0xa7, 0x8c, 0xeb, 0x0e, 0xa4, 0x86, 0xfa, 0x2d,
2316 0xf7, 0x83, 0x5f, 0x5f, 0xa8, 0xe9, 0x05, 0xb0,
2317 0x97, 0x01, 0x2b, 0x5b, 0xde, 0x50, 0x38, 0x0c,
2318 0x35, 0x5b, 0x1a, 0x2a, 0x72, 0x1b, 0xbc, 0x3d,
2319 0x08, 0xdd, 0x21, 0x79, 0x6c, 0xdb, 0x23, 0x9f,
2320 0xa9, 0x53, 0x10, 0x65, 0x1b, 0x1b, 0x56, 0xfd,
2321 0x2c, 0xfe, 0x53, 0xc8, 0x73, 0x52, 0xeb, 0xd9,
2322 0x96, 0xe3, 0x32, 0x56, 0x16, 0x04, 0x04, 0xce,
2323 0x93, 0x02, 0xa0, 0x80, 0x66, 0x80, 0x1e, 0x78,
2324 0x6a, 0x2f, 0x86, 0xe1, 0x81, 0xf9, 0x49, 0x96,
2325 0x6f, 0x49, 0x2a, 0x85, 0xb5, 0x8e, 0xaa, 0x4a,
2326 0x6a, 0x8c, 0xb3, 0x69, 0x75, 0x51, 0xbb, 0x23,
2327 0x6e, 0x87, 0xcc, 0x7b, 0xf8, 0xec, 0x13, 0x47,
2328 0x87, 0x1c, 0x91, 0xe1, 0x54, 0x37, 0xe8, 0xf2,
2329 0x66, 0xbf, 0x1e, 0xa5, 0xeb, 0x27, 0x1f, 0xdc,
2330 0xf3, 0x74, 0xd8, 0xb4, 0x7d, 0xf8, 0xbc, 0xe8,
2331 0x9e, 0x1f, 0xad, 0x61, 0xc2, 0xa0, 0x88, 0xcb,
2332 0x40, 0x36, 0xb3, 0x59, 0xcb, 0x72, 0xa2, 0x94,
2333 0x97, 0x3f, 0xed, 0xcc, 0xf0, 0xc3, 0x40, 0xaf,
2334 0xfd, 0x14, 0xb6, 0x4f, 0x04, 0x11, 0x65, 0x58,
2335 0x1a, 0xca, 0x34, 0x14, 0x7c, 0x1c, 0x75, 0x61,
2336 0x70, 0x47, 0x05, 0x8f, 0x7e, 0xd7, 0xd6, 0x03,
2337 0xe0, 0x32, 0x50, 0x80, 0x94, 0xfa, 0x73, 0xe8,
2338 0xb9, 0x15, 0x3d, 0xa3, 0xbf, 0x25, 0x5d, 0x2c,
2339 0xbb, 0xc5, 0xdf, 0x30, 0x1b, 0xa8, 0xf7, 0x4d,
2340 0x19, 0x8b, 0xeb, 0xce, 0x86, 0x04, 0x0f, 0xc1,
2341 0xd2, 0x92, 0x7c, 0x76, 0x57, 0x41, 0x44, 0x90,
2342 0xd8, 0x02, 0xf4, 0x82, 0xf3, 0xeb, 0xf2, 0xde,
2343 0x35, 0xee, 0x14, 0x9a, 0x1a, 0x6d, 0xe8, 0xd1,
2344 0x68, 0x91, 0xfb, 0xfb, 0xa0, 0x2a, 0x18, 0xaf,
2345 0xe5, 0x9f, 0x9d, 0x6f, 0x14, 0x97, 0x44, 0xe5,
2346 0xf0, 0xd5, 0x59, 0xb1, 0x02, 0x03, 0x01, 0x00,
2347 0x01, 0xa3, 0x82, 0x01, 0xa9, 0x30, 0x82, 0x01,
2348 0xa5, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23,
2349 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x1a, 0xdb,
2350 0x99, 0x4a, 0xb5, 0x8b, 0xe5, 0x7a, 0x0c, 0xc9,
2351 0xb9, 0x00, 0xe7, 0x85, 0x1e, 0x1a, 0x43, 0xc0,
2352 0x86, 0x60, 0x30, 0x42, 0x06, 0x03, 0x55, 0x1d,
2353 0x20, 0x04, 0x3b, 0x30, 0x39, 0x30, 0x37, 0x06,
2354 0x04, 0x55, 0x1d, 0x20, 0x00, 0x30, 0x2f, 0x30,
2355 0x2d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05,
2356 0x07, 0x02, 0x01, 0x16, 0x21, 0x68, 0x74, 0x74,
2357 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e,
2358 0x73, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x54,
2359 0x50, 0x4d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73,
2360 0x69, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x30, 0x59,
2361 0x06, 0x03, 0x55, 0x1d, 0x11, 0x01, 0x01, 0xff,
2362 0x04, 0x4f, 0x30, 0x4d, 0xa4, 0x4b, 0x30, 0x49,
2363 0x31, 0x16, 0x30, 0x14, 0x06, 0x05, 0x67, 0x81,
2364 0x05, 0x02, 0x01, 0x0c, 0x0b, 0x69, 0x64, 0x3a,
2365 0x35, 0x33, 0x35, 0x34, 0x34, 0x44, 0x32, 0x30,
2366 0x31, 0x17, 0x30, 0x15, 0x06, 0x05, 0x67, 0x81,
2367 0x05, 0x02, 0x02, 0x0c, 0x0c, 0x53, 0x54, 0x33,
2368 0x33, 0x48, 0x54, 0x50, 0x48, 0x41, 0x48, 0x43,
2369 0x30, 0x31, 0x16, 0x30, 0x14, 0x06, 0x05, 0x67,
2370 0x81, 0x05, 0x02, 0x03, 0x0c, 0x0b, 0x69, 0x64,
2371 0x3a, 0x30, 0x30, 0x34, 0x39, 0x30, 0x30, 0x30,
2372 0x38, 0x30, 0x67, 0x06, 0x03, 0x55, 0x1d, 0x09,
2373 0x04, 0x60, 0x30, 0x5e, 0x30, 0x17, 0x06, 0x05,
2374 0x67, 0x81, 0x05, 0x02, 0x10, 0x31, 0x0e, 0x30,
2375 0x0c, 0x0c, 0x03, 0x32, 0x2e, 0x30, 0x02, 0x01,
2376 0x00, 0x02, 0x02, 0x00, 0x8a, 0x30, 0x43, 0x06,
2377 0x05, 0x67, 0x81, 0x05, 0x02, 0x12, 0x31, 0x3a,
2378 0x30, 0x38, 0x02, 0x01, 0x00, 0x01, 0x01, 0xff,
2379 0xa0, 0x03, 0x0a, 0x01, 0x01, 0xa1, 0x03, 0x0a,
2380 0x01, 0x00, 0xa2, 0x03, 0x0a, 0x01, 0x00, 0xa3,
2381 0x10, 0x30, 0x0e, 0x16, 0x03, 0x33, 0x2e, 0x31,
2382 0x0a, 0x01, 0x04, 0x0a, 0x01, 0x02, 0x01, 0x01,
2383 0xff, 0xa4, 0x0f, 0x30, 0x0d, 0x16, 0x05, 0x31,
2384 0x34, 0x30, 0x2d, 0x32, 0x0a, 0x01, 0x02, 0x01,
2385 0x01, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d,
2386 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02,
2387 0x05, 0x20, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d,
2388 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
2389 0x30, 0x10, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04,
2390 0x09, 0x30, 0x07, 0x06, 0x05, 0x67, 0x81, 0x05,
2391 0x08, 0x01, 0x30, 0x4a, 0x06, 0x08, 0x2b, 0x06,
2392 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x3e,
2393 0x30, 0x3c, 0x30, 0x3a, 0x06, 0x08, 0x2b, 0x06,
2394 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x2e,
2395 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x73,
2396 0x65, 0x63, 0x75, 0x72, 0x65, 0x2e, 0x67, 0x6c,
2397 0x6f, 0x62, 0x61, 0x6c, 0x73, 0x69, 0x67, 0x6e,
2398 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x6d,
2399 0x74, 0x70, 0x6d, 0x65, 0x6b, 0x69, 0x6e, 0x74,
2400 0x30, 0x35, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x0d,
2401 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
2402 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01,
2403 0x01, 0x00, 0x3d, 0x4c, 0x38, 0x1e, 0x5b, 0x4f,
2404 0x1b, 0xcb, 0xe0, 0x9c, 0x63, 0xd5, 0x2f, 0x1f,
2405 0x04, 0x57, 0x0c, 0xae, 0xa1, 0x42, 0xfd, 0x9c,
2406 0xd9, 0x42, 0x04, 0x3b, 0x11, 0xf8, 0xe3, 0xbd,
2407 0xcf, 0x50, 0x00, 0x7a, 0xe1, 0x6c, 0xf8, 0x86,
2408 0x90, 0x13, 0x04, 0x1e, 0x92, 0xcd, 0xd3, 0x28,
2409 0x0b, 0xa4, 0xb5, 0x1f, 0xbb, 0xd4, 0x05, 0x82,
2410 0xed, 0x75, 0x02, 0x19, 0xe2, 0x61, 0xa6, 0x95,
2411 0x09, 0x56, 0x74, 0x85, 0x5a, 0xac, 0xeb, 0x52,
2412 0x0a, 0xda, 0xff, 0x9e, 0x7e, 0x90, 0x84, 0x80,
2413 0xa3, 0x9c, 0xdc, 0xf9, 0x00, 0x46, 0x2d, 0x91,
2414 0x71, 0x96, 0x0f, 0xfe, 0x55, 0xd3, 0xac, 0x49,
2415 0xe8, 0xc9, 0x81, 0x34, 0x1b, 0xbd, 0x2e, 0xfb,
2416 0xcc, 0x25, 0x2a, 0x4c, 0x18, 0xa4, 0xf3, 0xb7,
2417 0xc8, 0x4c, 0xce, 0x42, 0xce, 0x70, 0xa2, 0x08,
2418 0xc8, 0x4d, 0x26, 0x30, 0xa7, 0xab, 0xfb, 0xe7,
2419 0x2d, 0x62, 0x71, 0xe7, 0x5b, 0x9f, 0xf1, 0xc9,
2420 0x71, 0xd2, 0x0e, 0xb3, 0xdb, 0xd7, 0x63, 0xf1,
2421 0xe0, 0x4d, 0x83, 0x4e, 0xaa, 0x69, 0x2d, 0x2e,
2422 0x40, 0x01, 0xbb, 0xf4, 0x73, 0x0a, 0x3e, 0x3f,
2423 0xda, 0x97, 0x11, 0xae, 0x38, 0x65, 0x24, 0xd9,
2424 0x1c, 0x63, 0xbe, 0x0e, 0x51, 0x6d, 0x00, 0xd5,
2425 0xc6, 0x14, 0x1f, 0xcc, 0xf6, 0xc5, 0x39, 0xf3,
2426 0x51, 0x8e, 0x18, 0x00, 0x49, 0x86, 0x5b, 0xe1,
2427 0x6b, 0x69, 0xca, 0xe1, 0xf8, 0xcb, 0x7f, 0xdc,
2428 0x47, 0x4b, 0x38, 0xf7, 0xee, 0x56, 0xcb, 0xe7,
2429 0xd8, 0xa8, 0x9d, 0x9b, 0xa9, 0x9b, 0x65, 0xd5,
2430 0x26, 0x5a, 0xef, 0x32, 0xaa, 0x62, 0x42, 0x6b,
2431 0x10, 0xe6, 0xd7, 0x5b, 0xb8, 0x67, 0x7e, 0xc4,
2432 0x4f, 0x75, 0x5b, 0xbc, 0x28, 0x06, 0xfd, 0x2b,
2433 0x4e, 0x04, 0xbd, 0xf5, 0xd4, 0x42, 0x59, 0xdb,
2434 0xea, 0xa4, 0x2b, 0x6f, 0x56, 0x3d, 0xf7, 0xaa,
2437 char cert_json
[] = {
2438 "{\"_type\":\"Certificate\",\"tbsCertificate\":{\"_type\":\"TBSCertificate"
2439 "\",\"_save\":\"30820376A00302010202146A0597BA71D7E6D3AC0EDC9EDC95A15"
2440 "B998DE40A300D06092A864886F70D01010B05003055310B30090603550406130"
2441 "24348311E301C060355040A131553544D6963726F656C656374726F6E6963732"
2442 "04E56312630240603550403131D53544D2054504D20454B20496E7465726D656"
2443 "469617465204341203035301E170D3138313231343030303030305A170D32383"
2444 "13231343030303030305A300030820122300D06092A864886F70D01010105000"
2445 "382010F003082010A0282010100CC14EB27A78CEB0EA486FA2DF7835F5FA8E90"
2446 "5B097012B5BDE50380C355B1A2A721BBC3D08DD21796CDB239FA95310651B1B5"
2447 "6FD2CFE53C87352EBD996E33256160404CE9302A08066801E786A2F86E181F94"
2448 "9966F492A85B58EAA4A6A8CB3697551BB236E87CC7BF8EC1347871C91E15437E"
2449 "8F266BF1EA5EB271FDCF374D8B47DF8BCE89E1FAD61C2A088CB4036B359CB72A"
2450 "294973FEDCCF0C340AFFD14B64F041165581ACA34147C1C75617047058F7ED7D"
2451 "603E032508094FA73E8B9153DA3BF255D2CBBC5DF301BA8F74D198BEBCE86040"
2452 "FC1D2927C7657414490D802F482F3EBF2DE35EE149A1A6DE8D16891FBFBA02A1"
2453 "8AFE59F9D6F149744E5F0D559B10203010001A38201A9308201A5301F0603551"
2454 "D230418301680141ADB994AB58BE57A0CC9B900E7851E1A43C08660304206035"
2455 "51D20043B303930370604551D2000302F302D06082B060105050702011621687"
2456 "474703A2F2F7777772E73742E636F6D2F54504D2F7265706F7369746F72792F3"
2457 "0590603551D110101FF044F304DA44B304931163014060567810502010C0B696"
2458 "43A353335343444323031173015060567810502020C0C5354333348545048414"
2459 "8433031163014060567810502030C0B69643A303034393030303830670603551"
2460 "D090460305E301706056781050210310E300C0C03322E300201000202008A304"
2461 "306056781050212313A30380201000101FFA0030A0101A1030A0100A2030A010"
2462 "0A310300E1603332E310A01040A01020101FFA40F300D16053134302D320A010"
2463 "2010100300E0603551D0F0101FF040403020520300C0603551D130101FF04023"
2464 "00030100603551D250409300706056781050801304A06082B060105050701010"
2465 "43E303C303A06082B06010505073002862E687474703A2F2F7365637572652E6"
2466 "76C6F62616C7369676E2E636F6D2F73746D74706D656B696E7430352E637274\""
2467 ",\"version\":\"rfc3280_version_3\",\"serialNumber\":\"6A0597BA71D7E6D3A"
2468 "C0EDC9EDC95A15B998DE40A\",\"signature\":{\"_type\":\"AlgorithmIdentifi"
2469 "er\",\"algorithm\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"1.2.840.1135"
2470 "49.1.1.11\",\"components\":[1,2,840,113549,1,1,11],\"name\":\"id-pkcs1"
2471 "-sha256WithRSAEncryption\"},\"parameters\":\"0500\"},\"issuer\":{\"_choi"
2472 "ce\":\"rdnSequence\",\"value\":[[{\"_type\":\"AttributeTypeAndValue\",\"ty"
2473 "pe\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.5.4.6\",\"components\":[2"
2474 ",5,4,6],\"name\":\"id-at-countryName\"},\"value\":{\"_choice\":\"printabl"
2475 "eString\",\"value\":\"CH\"}}],[{\"_type\":\"AttributeTypeAndValue\",\"type"
2476 "\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.5.4.10\",\"components\":[2,"
2477 "5,4,10],\"name\":\"id-at-organizationName\"},\"value\":{\"_choice\":\"pri"
2478 "ntableString\",\"value\":\"STMicroelectronics NV\"}}],[{\"_type\":\"Attr"
2479 "ibuteTypeAndValue\",\"type\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2."
2480 "5.4.3\",\"components\":[2,5,4,3],\"name\":\"id-at-commonName\"},\"value\""
2481 ":{\"_choice\":\"printableString\",\"value\":\"STM TPM EK Intermediate C"
2482 "A 05\"}}]]},\"validity\":{\"_type\":\"Validity\",\"notBefore\":{\"_choice\""
2483 ":\"utcTime\",\"value\":\"2018-12-14T00:00:00Z\"},\"notAfter\":{\"_choice\""
2484 ":\"utcTime\",\"value\":\"2028-12-14T00:00:00Z\"}},\"subject\":{\"_choice\""
2485 ":\"rdnSequence\",\"value\":[]},\"subjectPublicKeyInfo\":{\"_type\":\"Subj"
2486 "ectPublicKeyInfo\",\"algorithm\":{\"_type\":\"AlgorithmIdentifier\",\"al"
2487 "gorithm\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"1.2.840.113549.1.1."
2488 "1\",\"components\":[1,2,840,113549,1,1,1],\"name\":\"id-pkcs1-rsaEncry"
2489 "ption\"},\"parameters\":\"0500\"},\"subjectPublicKey\":\"2160:3082010A02"
2490 "82010100CC14EB27A78CEB0EA486FA2DF7835F5FA8E905B097012B5BDE50380C"
2491 "355B1A2A721BBC3D08DD21796CDB239FA95310651B1B56FD2CFE53C87352EBD9"
2492 "96E33256160404CE9302A08066801E786A2F86E181F949966F492A85B58EAA4A"
2493 "6A8CB3697551BB236E87CC7BF8EC1347871C91E15437E8F266BF1EA5EB271FDC"
2494 "F374D8B47DF8BCE89E1FAD61C2A088CB4036B359CB72A294973FEDCCF0C340AF"
2495 "FD14B64F041165581ACA34147C1C75617047058F7ED7D603E032508094FA73E8"
2496 "B9153DA3BF255D2CBBC5DF301BA8F74D198BEBCE86040FC1D2927C7657414490"
2497 "D802F482F3EBF2DE35EE149A1A6DE8D16891FBFBA02A18AFE59F9D6F149744E5"
2498 "F0D559B10203010001\"},\"issuerUniqueID\":null,\"subjectUniqueID\":nul"
2499 "l,\"extensions\":[{\"_type\":\"Extension\",\"extnID\":{\"_type\":\"OBJECT I"
2500 "DENTIFIER\",\"oid\":\"2.5.29.35\",\"components\":[2,5,29,35],\"name\":\"id"
2501 "-x509-ce-authorityKeyIdentifier\"},\"critical\":false,\"extnValue\":\""
2502 "301680141ADB994AB58BE57A0CC9B900E7851E1A43C08660\",\"_extnValue_ch"
2503 "oice\":\"ext-AuthorityKeyIdentifier\",\"_extnValue\":{\"_type\":\"Author"
2504 "ityKeyIdentifier\",\"keyIdentifier\":\"1ADB994AB58BE57A0CC9B900E7851"
2505 "E1A43C08660\",\"authorityCertIssuer\":null,\"authorityCertSerialNumb"
2506 "er\":null}},{\"_type\":\"Extension\",\"extnID\":{\"_type\":\"OBJECT IDENTI"
2507 "FIER\",\"oid\":\"2.5.29.32\",\"components\":[2,5,29,32],\"name\":\"id-x509"
2508 "-ce-certificatePolicies\"},\"critical\":false,\"extnValue\":\"30393037"
2509 "0604551D2000302F302D06082B060105050702011621687474703A2F2F777777"
2510 "2E73742E636F6D2F54504D2F7265706F7369746F72792F\",\"_extnValue_choi"
2511 "ce\":\"ext-CertificatePolicies\",\"_extnValue\":[{\"_type\":\"PolicyInfo"
2512 "rmation\",\"policyIdentifier\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\""
2513 "2.5.29.32.0\",\"components\":[2,5,29,32,0],\"name\":\"id-x509-ce-certi"
2514 "ficatePolicies-anyPolicy\"},\"policyQualifiers\":[{\"_type\":\"PolicyQ"
2515 "ualifierInfo\",\"policyQualifierId\":{\"_type\":\"OBJECT IDENTIFIER\",\""
2516 "oid\":\"1.3.6.1.5.5.7.2.1\",\"components\":[1,3,6,1,5,5,7,2,1],\"name\""
2517 ":\"id-pkix-qt-cps\"},\"qualifier\":\"1621687474703A2F2F7777772E73742E"
2518 "636F6D2F54504D2F7265706F7369746F72792F\",\"_qualifier_choice\":\"pq-"
2519 "CPS\"}]}]},{\"_type\":\"Extension\",\"extnID\":{\"_type\":\"OBJECT IDENTIF"
2520 "IER\",\"oid\":\"2.5.29.17\",\"components\":[2,5,29,17],\"name\":\"id-x509-"
2521 "ce-subjectAltName\"},\"critical\":true,\"extnValue\":\"304DA44B3049311"
2522 "63014060567810502010C0B69643A35333534344432303117301506056781050"
2523 "2020C0C53543333485450484148433031163014060567810502030C0B69643A3"
2524 "030343930303038\",\"_extnValue_choice\":\"ext-SubjectAltName\",\"_extn"
2525 "Value\":[{\"_choice\":\"directoryName\",\"value\":{\"_choice\":\"rdnSequen"
2526 "ce\",\"value\":[[{\"_type\":\"AttributeTypeAndValue\",\"type\":{\"_type\":\""
2527 "OBJECT IDENTIFIER\",\"oid\":\"2.23.133.2.1\",\"components\":[2,23,133,2"
2528 ",1],\"name\":\"tcg-at-tpmManufacturer\"},\"value\":{\"_choice\":\"utf8Str"
2529 "ing\",\"value\":\"id:53544D20\"}}],[{\"_type\":\"AttributeTypeAndValue\","
2530 "\"type\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.23.133.2.2\",\"compon"
2531 "ents\":[2,23,133,2,2],\"name\":\"tcg-at-tpmModel\"},\"value\":{\"_choice"
2532 "\":\"utf8String\",\"value\":\"ST33HTPHAHC0\"}}],[{\"_type\":\"AttributeTyp"
2533 "eAndValue\",\"type\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.23.133.2"
2534 ".3\",\"components\":[2,23,133,2,3],\"name\":\"tcg-at-tpmVersion\"},\"val"
2535 "ue\":{\"_choice\":\"utf8String\",\"value\":\"id:00490008\"}}]]}}]},{\"_typ"
2536 "e\":\"Extension\",\"extnID\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.5."
2537 "29.9\",\"components\":[2,5,29,9],\"name\":\"id-x509-ce-subjectDirector"
2538 "yAttributes\"},\"critical\":false,\"extnValue\":\"305E3017060567810502"
2539 "10310E300C0C03322E300201000202008A304306056781050212313A30380201"
2540 "000101FFA0030A0101A1030A0100A2030A0100A310300E1603332E310A01040A"
2541 "01020101FFA40F300D16053134302D320A0102010100\",\"_extnValue_choice"
2542 "\":\"ext-SubjectDirectoryAttributes\",\"_extnValue\":[{\"_type\":\"Attri"
2543 "buteSet\",\"type\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.23.133.2.1"
2544 "6\",\"components\":[2,23,133,2,16],\"name\":\"tcg-at-tpmSpecification\""
2545 "},\"values\":[\"300C0C03322E300201000202008A\"],\"_values_choice\":\"at"
2546 "-TPMSpecification\",\"_values\":[{\"_type\":\"TPMSpecification\",\"famil"
2547 "y\":\"2.0\",\"level\":0,\"revision\":138}]},{\"_type\":\"AttributeSet\",\"ty"
2548 "pe\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.23.133.2.18\",\"componen"
2549 "ts\":[2,23,133,2,18],\"name\":\"tcg-at-tpmSecurityAssertions\"},\"valu"
2550 "es\":[\"30380201000101FFA0030A0101A1030A0100A2030A0100A310300E1603"
2551 "332E310A01040A01020101FFA40F300D16053134302D320A0102010100\"],\"_v"
2552 "alues_choice\":\"at-TPMSecurityAssertions\",\"_values\":[{\"_type\":\"TP"
2553 "MSecurityAssertions\",\"version\":0,\"fieldUpgradable\":true,\"ekGener"
2554 "ationType\":\"ekgt-injected\",\"ekGenerationLocation\":\"tpmManufactur"
2555 "er\",\"ekCertificateGenerationLocation\":\"tpmManufacturer\",\"ccInfo\""
2556 ":{\"_type\":\"CommonCriteriaMeasures\",\"version\":\"3.1\",\"assurancelev"
2557 "el\":\"ealevel4\",\"evaluationStatus\":\"evaluationCompleted\",\"plus\":t"
2558 "rue,\"strengthOfFunction\":null,\"profileOid\":null,\"profileUri\":nul"
2559 "l,\"targetOid\":null,\"targetUri\":null},\"fipsLevel\":{\"_type\":\"FIPSL"
2560 "evel\",\"version\":\"140-2\",\"level\":\"sllevel2\",\"plus\":false},\"iso900"
2561 "0Certified\":false,\"iso9000Uri\":null}]}]},{\"_type\":\"Extension\",\"e"
2562 "xtnID\":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"2.5.29.15\",\"component"
2563 "s\":[2,5,29,15],\"name\":\"id-x509-ce-keyUsage\"},\"critical\":true,\"ex"
2564 "tnValue\":\"03020520\",\"_extnValue_choice\":\"ext-KeyUsage\",\"_extnVal"
2565 "ue\":[\"keyEncipherment\"]},{\"_type\":\"Extension\",\"extnID\":{\"_type\":"
2566 "\"OBJECT IDENTIFIER\",\"oid\":\"2.5.29.19\",\"components\":[2,5,29,19],\""
2567 "name\":\"id-x509-ce-basicConstraints\"},\"critical\":true,\"extnValue\""
2568 ":\"3000\",\"_extnValue_choice\":\"ext-BasicConstraints\",\"_extnValue\":"
2569 "{\"_type\":\"BasicConstraints\",\"cA\":false,\"pathLenConstraint\":null}"
2570 "},{\"_type\":\"Extension\",\"extnID\":{\"_type\":\"OBJECT IDENTIFIER\",\"oi"
2571 "d\":\"2.5.29.37\",\"components\":[2,5,29,37],\"name\":\"id-x509-ce-extKe"
2572 "yUsage\"},\"critical\":false,\"extnValue\":\"300706056781050801\",\"_ext"
2573 "nValue_choice\":\"ext-ExtKeyUsage\",\"_extnValue\":[{\"_type\":\"OBJECT "
2574 "IDENTIFIER\",\"oid\":\"2.23.133.8.1\",\"components\":[2,23,133,8,1],\"na"
2575 "me\":\"tcg-kp-EKCertificate\"}]},{\"_type\":\"Extension\",\"extnID\":{\"_t"
2576 "ype\":\"OBJECT IDENTIFIER\",\"oid\":\"1.3.6.1.5.5.7.1.1\",\"components\":"
2577 "[1,3,6,1,5,5,7,1,1],\"name\":\"id-pkix-pe-authorityInfoAccess\"},\"cr"
2578 "itical\":false,\"extnValue\":\"303C303A06082B06010505073002862E68747"
2579 "4703A2F2F7365637572652E676C6F62616C7369676E2E636F6D2F73746D74706"
2580 "D656B696E7430352E637274\",\"_extnValue_choice\":\"ext-AuthorityInfoA"
2581 "ccess\",\"_extnValue\":[{\"_type\":\"AccessDescription\",\"accessMethod\""
2582 ":{\"_type\":\"OBJECT IDENTIFIER\",\"oid\":\"1.3.6.1.5.5.7.48.2\",\"compon"
2583 "ents\":[1,3,6,1,5,5,7,48,2],\"name\":\"id-pkix-ad-caIssuers\"},\"acces"
2584 "sLocation\":{\"_choice\":\"uniformResourceIdentifier\",\"value\":\"http:"
2585 "//secure.globalsign.com/stmtpmekint05.crt\"}}]}]},\"signatureAlgor"
2586 "ithm\":{\"_type\":\"AlgorithmIdentifier\",\"algorithm\":{\"_type\":\"OBJEC"
2587 "T IDENTIFIER\",\"oid\":\"1.2.840.113549.1.1.11\",\"components\":[1,2,84"
2588 "0,113549,1,1,11],\"name\":\"id-pkcs1-sha256WithRSAEncryption\"},\"par"
2589 "ameters\":\"0500\"},\"signatureValue\":\"2048:3D4C381E5B4F1BCBE09C63D5"
2590 "2F1F04570CAEA142FD9CD942043B11F8E3BDCF50007AE16CF8869013041E92CD"
2591 "D3280BA4B51FBBD40582ED750219E261A695095674855AACEB520ADAFF9E7E90"
2592 "8480A39CDCF900462D9171960FFE55D3AC49E8C981341BBD2EFBCC252A4C18A4"
2593 "F3B7C84CCE42CE70A208C84D2630A7ABFBE72D6271E75B9FF1C971D20EB3DBD7"
2594 "63F1E04D834EAA692D2E4001BBF4730A3E3FDA9711AE386524D91C63BE0E516D"
2595 "00D5C6141FCCF6C539F3518E180049865BE16B69CAE1F8CB7FDC474B38F7EE56"
2596 "CBE7D8A89D9BA99B65D5265AEF32AA62426B10E6D75BB8677EC44F755BBC2806"
2597 "FD2B4E04BDF5D44259DBEAA42B6F563DF7AA7506\""
2600 heim_octet_string os
;
2602 size_t i
, nknown
, size
;
2607 * Test automatic decoding of open types.
2609 * Decode a value that has plenty of open types with values of known
2610 * alternatives in them, then check that we got what we wanted.
2612 ret
= decode_Certificate(encoded_sample
, sizeof(encoded_sample
),
2616 if (size
!= sizeof(encoded_sample
))
2619 s
= print_Certificate(&c0
, 0);
2622 if (strcmp(s
, cert_json
) != 0)
2626 ret
= copy_Certificate(&c0
, &c1
);
2630 if (!c0
.tbsCertificate
.extensions
|| !c1
.tbsCertificate
.extensions
)
2632 if (!c0
.tbsCertificate
.extensions
->len
||
2633 c0
.tbsCertificate
.extensions
->len
!= c1
.tbsCertificate
.extensions
->len
)
2635 for (i
= nknown
= 0; i
< c0
.tbsCertificate
.extensions
->len
; i
++) {
2636 if (c0
.tbsCertificate
.extensions
->val
[i
]._ioschoice_extnValue
.element
!=
2637 c1
.tbsCertificate
.extensions
->val
[i
]._ioschoice_extnValue
.element
)
2639 if (c0
.tbsCertificate
.extensions
->val
[i
]._ioschoice_extnValue
.element
) {
2641 fprintf(stderr
, "extension %llu known %u\n",
2642 (unsigned long long)i
,
2643 c0
.tbsCertificate
.extensions
->val
[i
]._ioschoice_extnValue
._element
);
2653 * Check that this round trips. But note that this attempt to encode will
2654 * ignore the automatically decoded open type values from above because
2655 * their encodings are still present.
2657 ASN1_MALLOC_ENCODE(Certificate
, os
.data
, os
.length
, &c1
, &size
, ret
);
2660 if (os
.length
!= size
|| size
!= sizeof(encoded_sample
))
2662 if (memcmp(os
.data
, encoded_sample
, os
.length
) != 0)
2664 der_free_octet_string(&os
);
2667 * Test automatic encoding of open types by clearing the encoding of one
2668 * such open type value, forcing the encoder to encode the value from
2671 der_free_octet_string(&c0
.tbsCertificate
.extensions
->val
[0].extnValue
);
2672 der_free_oid(&c0
.tbsCertificate
.extensions
->val
[0].extnID
);
2674 ASN1_MALLOC_ENCODE(Certificate
, os
.data
, os
.length
, &c0
, &size
, ret
);
2677 if (os
.length
!= size
|| size
!= sizeof(encoded_sample
))
2679 if (memcmp(os
.data
, encoded_sample
, os
.length
) != 0)
2681 der_free_octet_string(&os
);
2684 * Repeat, but with the copy, as this will test that copying data
2685 * structures with decoded open types in them also copies those.
2687 der_free_octet_string(&c1
.tbsCertificate
.extensions
->val
[0].extnValue
);
2688 der_free_oid(&c1
.tbsCertificate
.extensions
->val
[0].extnID
);
2690 ASN1_MALLOC_ENCODE(Certificate
, os
.data
, os
.length
, &c1
, &size
, ret
);
2693 if (os
.length
!= size
|| size
!= sizeof(encoded_sample
))
2695 if (memcmp(os
.data
, encoded_sample
, os
.length
) != 0)
2697 der_free_octet_string(&os
);
2699 free_Certificate(&c0
);
2700 free_Certificate(&c1
);
2706 main(int argc
, char **argv
)
2710 #define DO_ONE(t) if (t()) { fprintf(stderr, "%s() failed!\n", #t); ret++; }
2711 DO_ONE(test_principal
);
2712 DO_ONE(test_authenticator
);
2713 DO_ONE(test_krb_error
);
2715 DO_ONE(test_bit_string
);
2716 DO_ONE(test_bit_string_rfc1510
);
2720 DO_ONE(check_tag_length
);
2721 DO_ONE(check_tag_length64
);
2722 DO_ONE(check_tag_length64s
);
2723 DO_ONE(test_large_tag
);
2724 DO_ONE(test_choice
);
2726 DO_ONE(test_implicit
);
2728 DO_ONE(test_taglessalloc
);
2729 DO_ONE(test_optional
);
2731 DO_ONE(check_fail_largetag
);
2732 DO_ONE(check_fail_sequence
);
2733 DO_ONE(check_fail_choice
);
2734 DO_ONE(check_fail_Ticket
);
2737 DO_ONE(check_seq_of_size
);
2738 DO_ONE(test_SignedData
);
2740 DO_ONE(check_TESTMechTypeList
);
2742 DO_ONE(test_seqof5
);
2744 DO_ONE(test_x690sample
);
2746 DO_ONE(test_default
);
2748 DO_ONE(test_extensible_choice
);
2750 DO_ONE(test_decorated_choice
);
2751 DO_ONE(test_decorated
);
2753 #if ASN1_IOS_SUPPORTED