1 1.1 elric /* $NetBSD: check-gen.c,v 1.3 2023/06/19 21:41:42 christos Exp $ */ 2 1.1 elric 3 1.1 elric /* 4 1.1 elric * Copyright (c) 1999 - 2005 Kungliga Tekniska Hgskolan 5 1.1 elric * (Royal Institute of Technology, Stockholm, Sweden). 6 1.1 elric * All rights reserved. 7 1.1 elric * 8 1.1 elric * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 9 1.1 elric * 10 1.1 elric * Redistribution and use in source and binary forms, with or without 11 1.1 elric * modification, are permitted provided that the following conditions 12 1.1 elric * are met: 13 1.1 elric * 14 1.1 elric * 1. Redistributions of source code must retain the above copyright 15 1.1 elric * notice, this list of conditions and the following disclaimer. 16 1.1 elric * 17 1.1 elric * 2. Redistributions in binary form must reproduce the above copyright 18 1.1 elric * notice, this list of conditions and the following disclaimer in the 19 1.1 elric * documentation and/or other materials provided with the distribution. 20 1.1 elric * 21 1.1 elric * 3. Neither the name of the Institute nor the names of its contributors 22 1.1 elric * may be used to endorse or promote products derived from this software 23 1.1 elric * without specific prior written permission. 24 1.1 elric * 25 1.1 elric * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26 1.1 elric * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 1.1 elric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 1.1 elric * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29 1.1 elric * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 1.1 elric * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 1.1 elric * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 1.1 elric * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 1.1 elric * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 1.1 elric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 1.1 elric * SUCH DAMAGE. 36 1.1 elric */ 37 1.1 elric 38 1.1 elric #include <config.h> 39 1.1 elric #include <stdio.h> 40 1.1 elric #include <string.h> 41 1.1 elric #include <err.h> 42 1.1 elric #include <krb5/roken.h> 43 1.1 elric 44 1.1 elric #include <krb5/asn1-common.h> 45 1.1 elric #include <krb5/asn1_err.h> 46 1.1 elric #include <krb5/der.h> 47 1.1 elric #include <krb5/krb5_asn1.h> 48 1.1 elric #include <krb5/heim_asn1.h> 49 1.1 elric #include <krb5/rfc2459_asn1.h> 50 1.1 elric #include <test_asn1.h> 51 1.2 christos #include <krb5/cms_asn1.h> 52 1.1 elric 53 1.1 elric #include "check-common.h" 54 1.1 elric 55 1.1 elric static char *lha_principal[] = { "lha" }; 56 1.1 elric static char *lharoot_princ[] = { "lha", "root" }; 57 1.1 elric static char *datan_princ[] = { "host", "nutcracker.e.kth.se" }; 58 1.1 elric static char *nada_tgt_principal[] = { "krbtgt", "NADA.KTH.SE" }; 59 1.1 elric 60 1.1 elric static int 61 1.1 elric cmp_principal (void *a, void *b) 62 1.1 elric { 63 1.1 elric Principal *pa = a; 64 1.1 elric Principal *pb = b; 65 1.1 elric int i; 66 1.1 elric 67 1.1 elric COMPARE_STRING(pa,pb,realm); 68 1.1 elric COMPARE_INTEGER(pa,pb,name.name_type); 69 1.1 elric COMPARE_INTEGER(pa,pb,name.name_string.len); 70 1.1 elric 71 1.1 elric for (i = 0; i < pa->name.name_string.len; i++) 72 1.1 elric COMPARE_STRING(pa,pb,name.name_string.val[i]); 73 1.1 elric 74 1.1 elric return 0; 75 1.1 elric } 76 1.1 elric 77 1.1 elric static int 78 1.1 elric test_principal (void) 79 1.1 elric { 80 1.1 elric 81 1.1 elric struct test_case tests[] = { 82 1.1 elric { NULL, 29, 83 1.1 elric "\x30\x1b\xa0\x10\x30\x0e\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b" 84 1.2 christos "\x03\x6c\x68\x61\xa1\x07\x1b\x05\x53\x55\x2e\x53\x45", 85 1.2 christos NULL 86 1.1 elric }, 87 1.1 elric { NULL, 35, 88 1.1 elric "\x30\x21\xa0\x16\x30\x14\xa0\x03\x02\x01\x01\xa1\x0d\x30\x0b\x1b" 89 1.1 elric "\x03\x6c\x68\x61\x1b\x04\x72\x6f\x6f\x74\xa1\x07\x1b\x05\x53\x55" 90 1.2 christos "\x2e\x53\x45", 91 1.2 christos NULL 92 1.1 elric }, 93 1.1 elric { NULL, 54, 94 1.1 elric "\x30\x34\xa0\x26\x30\x24\xa0\x03\x02\x01\x03\xa1\x1d\x30\x1b\x1b" 95 1.1 elric "\x04\x68\x6f\x73\x74\x1b\x13\x6e\x75\x74\x63\x72\x61\x63\x6b\x65" 96 1.1 elric "\x72\x2e\x65\x2e\x6b\x74\x68\x2e\x73\x65\xa1\x0a\x1b\x08\x45\x2e" 97 1.2 christos "\x4b\x54\x48\x2e\x53\x45", 98 1.2 christos NULL 99 1.1 elric } 100 1.1 elric }; 101 1.1 elric 102 1.1 elric 103 1.1 elric Principal values[] = { 104 1.1 elric { { KRB5_NT_PRINCIPAL, { 1, lha_principal } }, "SU.SE" }, 105 1.1 elric { { KRB5_NT_PRINCIPAL, { 2, lharoot_princ } }, "SU.SE" }, 106 1.1 elric { { KRB5_NT_SRV_HST, { 2, datan_princ } }, "E.KTH.SE" } 107 1.1 elric }; 108 1.1 elric int i, ret; 109 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 110 1.1 elric 111 1.1 elric for (i = 0; i < ntests; ++i) { 112 1.1 elric tests[i].val = &values[i]; 113 1.1 elric if (asprintf (&tests[i].name, "Principal %d", i) < 0) 114 1.1 elric errx(1, "malloc"); 115 1.1 elric if (tests[i].name == NULL) 116 1.1 elric errx(1, "malloc"); 117 1.1 elric } 118 1.1 elric 119 1.1 elric ret = generic_test (tests, ntests, sizeof(Principal), 120 1.1 elric (generic_encode)encode_Principal, 121 1.1 elric (generic_length)length_Principal, 122 1.1 elric (generic_decode)decode_Principal, 123 1.1 elric (generic_free)free_Principal, 124 1.1 elric cmp_principal, 125 1.1 elric NULL); 126 1.1 elric for (i = 0; i < ntests; ++i) 127 1.1 elric free (tests[i].name); 128 1.1 elric 129 1.1 elric return ret; 130 1.1 elric } 131 1.1 elric 132 1.1 elric static int 133 1.1 elric cmp_authenticator (void *a, void *b) 134 1.1 elric { 135 1.1 elric Authenticator *aa = a; 136 1.1 elric Authenticator *ab = b; 137 1.1 elric int i; 138 1.1 elric 139 1.1 elric COMPARE_INTEGER(aa,ab,authenticator_vno); 140 1.1 elric COMPARE_STRING(aa,ab,crealm); 141 1.1 elric 142 1.1 elric COMPARE_INTEGER(aa,ab,cname.name_type); 143 1.1 elric COMPARE_INTEGER(aa,ab,cname.name_string.len); 144 1.1 elric 145 1.1 elric for (i = 0; i < aa->cname.name_string.len; i++) 146 1.1 elric COMPARE_STRING(aa,ab,cname.name_string.val[i]); 147 1.1 elric 148 1.1 elric return 0; 149 1.1 elric } 150 1.1 elric 151 1.1 elric static int 152 1.1 elric test_authenticator (void) 153 1.1 elric { 154 1.1 elric struct test_case tests[] = { 155 1.1 elric { NULL, 63, 156 1.1 elric "\x62\x3d\x30\x3b\xa0\x03\x02\x01\x05\xa1\x0a\x1b\x08" 157 1.1 elric "\x45\x2e\x4b\x54\x48\x2e\x53\x45\xa2\x10\x30\x0e\xa0" 158 1.1 elric "\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61" 159 1.1 elric "\xa4\x03\x02\x01\x0a\xa5\x11\x18\x0f\x31\x39\x37\x30" 160 1.2 christos "\x30\x31\x30\x31\x30\x30\x30\x31\x33\x39\x5a", 161 1.2 christos NULL 162 1.1 elric }, 163 1.1 elric { NULL, 67, 164 1.1 elric "\x62\x41\x30\x3f\xa0\x03\x02\x01\x05\xa1\x07\x1b\x05" 165 1.1 elric "\x53\x55\x2e\x53\x45\xa2\x16\x30\x14\xa0\x03\x02\x01" 166 1.1 elric "\x01\xa1\x0d\x30\x0b\x1b\x03\x6c\x68\x61\x1b\x04\x72" 167 1.1 elric "\x6f\x6f\x74\xa4\x04\x02\x02\x01\x24\xa5\x11\x18\x0f" 168 1.1 elric "\x31\x39\x37\x30\x30\x31\x30\x31\x30\x30\x31\x36\x33" 169 1.2 christos "\x39\x5a", 170 1.2 christos NULL 171 1.1 elric } 172 1.1 elric }; 173 1.1 elric 174 1.1 elric Authenticator values[] = { 175 1.1 elric { 5, "E.KTH.SE", { KRB5_NT_PRINCIPAL, { 1, lha_principal } }, 176 1.1 elric NULL, 10, 99, NULL, NULL, NULL }, 177 1.1 elric { 5, "SU.SE", { KRB5_NT_PRINCIPAL, { 2, lharoot_princ } }, 178 1.1 elric NULL, 292, 999, NULL, NULL, NULL } 179 1.1 elric }; 180 1.1 elric int i, ret; 181 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 182 1.1 elric 183 1.1 elric for (i = 0; i < ntests; ++i) { 184 1.1 elric tests[i].val = &values[i]; 185 1.1 elric if (asprintf (&tests[i].name, "Authenticator %d", i) < 0) 186 1.1 elric errx(1, "malloc"); 187 1.1 elric if (tests[i].name == NULL) 188 1.1 elric errx(1, "malloc"); 189 1.1 elric } 190 1.1 elric 191 1.1 elric ret = generic_test (tests, ntests, sizeof(Authenticator), 192 1.1 elric (generic_encode)encode_Authenticator, 193 1.1 elric (generic_length)length_Authenticator, 194 1.1 elric (generic_decode)decode_Authenticator, 195 1.1 elric (generic_free)free_Authenticator, 196 1.1 elric cmp_authenticator, 197 1.1 elric (generic_copy)copy_Authenticator); 198 1.1 elric for (i = 0; i < ntests; ++i) 199 1.1 elric free(tests[i].name); 200 1.1 elric 201 1.1 elric return ret; 202 1.1 elric } 203 1.1 elric 204 1.1 elric static int 205 1.1 elric cmp_KRB_ERROR (void *a, void *b) 206 1.1 elric { 207 1.1 elric KRB_ERROR *aa = a; 208 1.1 elric KRB_ERROR *ab = b; 209 1.1 elric int i; 210 1.1 elric 211 1.1 elric COMPARE_INTEGER(aa,ab,pvno); 212 1.1 elric COMPARE_INTEGER(aa,ab,msg_type); 213 1.1 elric 214 1.1 elric IF_OPT_COMPARE(aa,ab,ctime) { 215 1.1 elric COMPARE_INTEGER(aa,ab,ctime); 216 1.1 elric } 217 1.1 elric IF_OPT_COMPARE(aa,ab,cusec) { 218 1.1 elric COMPARE_INTEGER(aa,ab,cusec); 219 1.1 elric } 220 1.1 elric COMPARE_INTEGER(aa,ab,stime); 221 1.1 elric COMPARE_INTEGER(aa,ab,susec); 222 1.1 elric COMPARE_INTEGER(aa,ab,error_code); 223 1.1 elric 224 1.1 elric IF_OPT_COMPARE(aa,ab,crealm) { 225 1.1 elric COMPARE_OPT_STRING(aa,ab,crealm); 226 1.1 elric } 227 1.1 elric #if 0 228 1.1 elric IF_OPT_COMPARE(aa,ab,cname) { 229 1.1 elric COMPARE_OPT_STRING(aa,ab,cname); 230 1.1 elric } 231 1.1 elric #endif 232 1.1 elric COMPARE_STRING(aa,ab,realm); 233 1.1 elric 234 1.1 elric COMPARE_INTEGER(aa,ab,sname.name_string.len); 235 1.1 elric for (i = 0; i < aa->sname.name_string.len; i++) 236 1.1 elric COMPARE_STRING(aa,ab,sname.name_string.val[i]); 237 1.1 elric 238 1.1 elric IF_OPT_COMPARE(aa,ab,e_text) { 239 1.1 elric COMPARE_OPT_STRING(aa,ab,e_text); 240 1.1 elric } 241 1.1 elric IF_OPT_COMPARE(aa,ab,e_data) { 242 1.2 christos /* COMPARE_OPT_OCTET_STRING(aa,ab,e_data); */ 243 1.1 elric } 244 1.1 elric 245 1.1 elric return 0; 246 1.1 elric } 247 1.1 elric 248 1.1 elric static int 249 1.1 elric test_krb_error (void) 250 1.1 elric { 251 1.1 elric struct test_case tests[] = { 252 1.1 elric { NULL, 127, 253 1.1 elric "\x7e\x7d\x30\x7b\xa0\x03\x02\x01\x05\xa1\x03\x02\x01\x1e\xa4\x11" 254 1.1 elric "\x18\x0f\x32\x30\x30\x33\x31\x31\x32\x34\x30\x30\x31\x31\x31\x39" 255 1.1 elric "\x5a\xa5\x05\x02\x03\x04\xed\xa5\xa6\x03\x02\x01\x1f\xa7\x0d\x1b" 256 1.1 elric "\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xa8\x10\x30\x0e" 257 1.1 elric "\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61\xa9\x0d" 258 1.1 elric "\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45\xaa\x20\x30" 259 1.1 elric "\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15\x1b\x06\x6b\x72\x62\x74" 260 1.1 elric "\x67\x74\x1b\x0b\x4e\x41\x44\x41\x2e\x4b\x54\x48\x2e\x53\x45", 261 1.1 elric "KRB-ERROR Test 1" 262 1.1 elric } 263 1.1 elric }; 264 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 265 1.1 elric KRB_ERROR e1; 266 1.1 elric PrincipalName lhaprincipalname = { 1, { 1, lha_principal } }; 267 1.1 elric PrincipalName tgtprincipalname = { 1, { 2, nada_tgt_principal } }; 268 1.1 elric char *realm = "NADA.KTH.SE"; 269 1.1 elric 270 1.1 elric e1.pvno = 5; 271 1.1 elric e1.msg_type = 30; 272 1.1 elric e1.ctime = NULL; 273 1.1 elric e1.cusec = NULL; 274 1.1 elric e1.stime = 1069632679; 275 1.1 elric e1.susec = 322981; 276 1.1 elric e1.error_code = 31; 277 1.1 elric e1.crealm = &realm; 278 1.1 elric e1.cname = &lhaprincipalname; 279 1.1 elric e1.realm = "NADA.KTH.SE"; 280 1.1 elric e1.sname = tgtprincipalname; 281 1.1 elric e1.e_text = NULL; 282 1.1 elric e1.e_data = NULL; 283 1.1 elric 284 1.1 elric tests[0].val = &e1; 285 1.1 elric 286 1.1 elric return generic_test (tests, ntests, sizeof(KRB_ERROR), 287 1.1 elric (generic_encode)encode_KRB_ERROR, 288 1.1 elric (generic_length)length_KRB_ERROR, 289 1.1 elric (generic_decode)decode_KRB_ERROR, 290 1.1 elric (generic_free)free_KRB_ERROR, 291 1.1 elric cmp_KRB_ERROR, 292 1.1 elric (generic_copy)copy_KRB_ERROR); 293 1.1 elric } 294 1.1 elric 295 1.1 elric static int 296 1.1 elric cmp_Name (void *a, void *b) 297 1.1 elric { 298 1.1 elric Name *aa = a; 299 1.1 elric Name *ab = b; 300 1.1 elric 301 1.1 elric COMPARE_INTEGER(aa,ab,element); 302 1.1 elric 303 1.1 elric return 0; 304 1.1 elric } 305 1.1 elric 306 1.1 elric static int 307 1.1 elric test_Name (void) 308 1.1 elric { 309 1.1 elric struct test_case tests[] = { 310 1.1 elric { NULL, 35, 311 1.1 elric "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76" 312 1.1 elric "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48" 313 1.1 elric "\x4f\x4c\x4d", 314 1.1 elric "Name CN=Love+L=STOCKHOLM" 315 1.1 elric }, 316 1.1 elric { NULL, 35, 317 1.1 elric "\x30\x21\x31\x1f\x30\x0b\x06\x03\x55\x04\x03\x13\x04\x4c\x6f\x76" 318 1.1 elric "\x65\x30\x10\x06\x03\x55\x04\x07\x13\x09\x53\x54\x4f\x43\x4b\x48" 319 1.1 elric "\x4f\x4c\x4d", 320 1.1 elric "Name L=STOCKHOLM+CN=Love" 321 1.1 elric } 322 1.1 elric }; 323 1.1 elric 324 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 325 1.1 elric Name n1, n2; 326 1.1 elric RelativeDistinguishedName rdn1[1]; 327 1.1 elric RelativeDistinguishedName rdn2[1]; 328 1.1 elric AttributeTypeAndValue atv1[2]; 329 1.1 elric AttributeTypeAndValue atv2[2]; 330 1.1 elric unsigned cmp_CN[] = { 2, 5, 4, 3 }; 331 1.1 elric unsigned cmp_L[] = { 2, 5, 4, 7 }; 332 1.1 elric 333 1.1 elric /* n1 */ 334 1.1 elric n1.element = choice_Name_rdnSequence; 335 1.1 elric n1.u.rdnSequence.val = rdn1; 336 1.1 elric n1.u.rdnSequence.len = sizeof(rdn1)/sizeof(rdn1[0]); 337 1.1 elric rdn1[0].val = atv1; 338 1.1 elric rdn1[0].len = sizeof(atv1)/sizeof(atv1[0]); 339 1.1 elric 340 1.1 elric atv1[0].type.length = sizeof(cmp_CN)/sizeof(cmp_CN[0]); 341 1.1 elric atv1[0].type.components = cmp_CN; 342 1.1 elric atv1[0].value.element = choice_DirectoryString_printableString; 343 1.1 elric atv1[0].value.u.printableString.data = "Love"; 344 1.1 elric atv1[0].value.u.printableString.length = 4; 345 1.1 elric 346 1.1 elric atv1[1].type.length = sizeof(cmp_L)/sizeof(cmp_L[0]); 347 1.1 elric atv1[1].type.components = cmp_L; 348 1.1 elric atv1[1].value.element = choice_DirectoryString_printableString; 349 1.1 elric atv1[1].value.u.printableString.data = "STOCKHOLM"; 350 1.1 elric atv1[1].value.u.printableString.length = 9; 351 1.1 elric 352 1.1 elric /* n2 */ 353 1.1 elric n2.element = choice_Name_rdnSequence; 354 1.1 elric n2.u.rdnSequence.val = rdn2; 355 1.1 elric n2.u.rdnSequence.len = sizeof(rdn2)/sizeof(rdn2[0]); 356 1.1 elric rdn2[0].val = atv2; 357 1.1 elric rdn2[0].len = sizeof(atv2)/sizeof(atv2[0]); 358 1.1 elric 359 1.1 elric atv2[0].type.length = sizeof(cmp_L)/sizeof(cmp_L[0]); 360 1.1 elric atv2[0].type.components = cmp_L; 361 1.1 elric atv2[0].value.element = choice_DirectoryString_printableString; 362 1.1 elric atv2[0].value.u.printableString.data = "STOCKHOLM"; 363 1.1 elric atv2[0].value.u.printableString.length = 9; 364 1.1 elric 365 1.1 elric atv2[1].type.length = sizeof(cmp_CN)/sizeof(cmp_CN[0]); 366 1.1 elric atv2[1].type.components = cmp_CN; 367 1.1 elric atv2[1].value.element = choice_DirectoryString_printableString; 368 1.1 elric atv2[1].value.u.printableString.data = "Love"; 369 1.1 elric atv2[1].value.u.printableString.length = 4; 370 1.1 elric 371 1.1 elric /* */ 372 1.1 elric tests[0].val = &n1; 373 1.1 elric tests[1].val = &n2; 374 1.1 elric 375 1.1 elric return generic_test (tests, ntests, sizeof(Name), 376 1.1 elric (generic_encode)encode_Name, 377 1.1 elric (generic_length)length_Name, 378 1.1 elric (generic_decode)decode_Name, 379 1.1 elric (generic_free)free_Name, 380 1.1 elric cmp_Name, 381 1.1 elric (generic_copy)copy_Name); 382 1.1 elric } 383 1.1 elric 384 1.1 elric static int 385 1.1 elric cmp_KeyUsage (void *a, void *b) 386 1.1 elric { 387 1.1 elric KeyUsage *aa = a; 388 1.1 elric KeyUsage *ab = b; 389 1.1 elric 390 1.1 elric return KeyUsage2int(*aa) != KeyUsage2int(*ab); 391 1.1 elric } 392 1.1 elric 393 1.1 elric static int 394 1.1 elric test_bit_string (void) 395 1.1 elric { 396 1.1 elric struct test_case tests[] = { 397 1.1 elric { NULL, 4, 398 1.1 elric "\x03\x02\x07\x80", 399 1.1 elric "bitstring 1" 400 1.1 elric }, 401 1.1 elric { NULL, 4, 402 1.1 elric "\x03\x02\x05\xa0", 403 1.1 elric "bitstring 2" 404 1.1 elric }, 405 1.1 elric { NULL, 5, 406 1.1 elric "\x03\x03\x07\x00\x80", 407 1.1 elric "bitstring 3" 408 1.1 elric }, 409 1.1 elric { NULL, 3, 410 1.1 elric "\x03\x01\x00", 411 1.1 elric "bitstring 4" 412 1.1 elric } 413 1.1 elric }; 414 1.1 elric 415 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 416 1.1 elric KeyUsage ku1, ku2, ku3, ku4; 417 1.1 elric 418 1.1 elric memset(&ku1, 0, sizeof(ku1)); 419 1.1 elric ku1.digitalSignature = 1; 420 1.1 elric tests[0].val = &ku1; 421 1.1 elric 422 1.1 elric memset(&ku2, 0, sizeof(ku2)); 423 1.1 elric ku2.digitalSignature = 1; 424 1.1 elric ku2.keyEncipherment = 1; 425 1.1 elric tests[1].val = &ku2; 426 1.1 elric 427 1.1 elric memset(&ku3, 0, sizeof(ku3)); 428 1.1 elric ku3.decipherOnly = 1; 429 1.1 elric tests[2].val = &ku3; 430 1.1 elric 431 1.1 elric memset(&ku4, 0, sizeof(ku4)); 432 1.1 elric tests[3].val = &ku4; 433 1.1 elric 434 1.1 elric 435 1.1 elric return generic_test (tests, ntests, sizeof(KeyUsage), 436 1.1 elric (generic_encode)encode_KeyUsage, 437 1.1 elric (generic_length)length_KeyUsage, 438 1.1 elric (generic_decode)decode_KeyUsage, 439 1.1 elric (generic_free)free_KeyUsage, 440 1.1 elric cmp_KeyUsage, 441 1.1 elric (generic_copy)copy_KeyUsage); 442 1.1 elric } 443 1.1 elric 444 1.1 elric static int 445 1.1 elric cmp_TicketFlags (void *a, void *b) 446 1.1 elric { 447 1.1 elric TicketFlags *aa = a; 448 1.1 elric TicketFlags *ab = b; 449 1.1 elric 450 1.1 elric return TicketFlags2int(*aa) != TicketFlags2int(*ab); 451 1.1 elric } 452 1.1 elric 453 1.1 elric static int 454 1.1 elric test_bit_string_rfc1510 (void) 455 1.1 elric { 456 1.1 elric struct test_case tests[] = { 457 1.1 elric { NULL, 7, 458 1.1 elric "\x03\x05\x00\x80\x00\x00\x00", 459 1.1 elric "TF bitstring 1" 460 1.1 elric }, 461 1.1 elric { NULL, 7, 462 1.1 elric "\x03\x05\x00\x40\x20\x00\x00", 463 1.1 elric "TF bitstring 2" 464 1.1 elric }, 465 1.1 elric { NULL, 7, 466 1.1 elric "\x03\x05\x00\x00\x20\x00\x00", 467 1.1 elric "TF bitstring 3" 468 1.1 elric }, 469 1.1 elric { NULL, 7, 470 1.1 elric "\x03\x05\x00\x00\x00\x00\x00", 471 1.1 elric "TF bitstring 4" 472 1.1 elric } 473 1.1 elric }; 474 1.1 elric 475 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 476 1.1 elric TicketFlags tf1, tf2, tf3, tf4; 477 1.1 elric 478 1.1 elric memset(&tf1, 0, sizeof(tf1)); 479 1.1 elric tf1.reserved = 1; 480 1.1 elric tests[0].val = &tf1; 481 1.1 elric 482 1.1 elric memset(&tf2, 0, sizeof(tf2)); 483 1.1 elric tf2.forwardable = 1; 484 1.1 elric tf2.pre_authent = 1; 485 1.1 elric tests[1].val = &tf2; 486 1.1 elric 487 1.1 elric memset(&tf3, 0, sizeof(tf3)); 488 1.1 elric tf3.pre_authent = 1; 489 1.1 elric tests[2].val = &tf3; 490 1.1 elric 491 1.1 elric memset(&tf4, 0, sizeof(tf4)); 492 1.1 elric tests[3].val = &tf4; 493 1.1 elric 494 1.1 elric 495 1.1 elric return generic_test (tests, ntests, sizeof(TicketFlags), 496 1.1 elric (generic_encode)encode_TicketFlags, 497 1.1 elric (generic_length)length_TicketFlags, 498 1.1 elric (generic_decode)decode_TicketFlags, 499 1.1 elric (generic_free)free_TicketFlags, 500 1.1 elric cmp_TicketFlags, 501 1.1 elric (generic_copy)copy_TicketFlags); 502 1.1 elric } 503 1.1 elric 504 1.1 elric static int 505 1.1 elric cmp_KerberosTime (void *a, void *b) 506 1.1 elric { 507 1.1 elric KerberosTime *aa = a; 508 1.1 elric KerberosTime *ab = b; 509 1.1 elric 510 1.1 elric return *aa != *ab; 511 1.1 elric } 512 1.1 elric 513 1.1 elric static int 514 1.1 elric test_time (void) 515 1.1 elric { 516 1.1 elric struct test_case tests[] = { 517 1.1 elric { NULL, 17, 518 1.1 elric "\x18\x0f\x31\x39\x37\x30\x30\x31\x30\x31\x30\x31\x31\x38\x33\x31" 519 1.1 elric "\x5a", 520 1.1 elric "time 1" }, 521 1.1 elric { NULL, 17, 522 1.1 elric "\x18\x0f\x32\x30\x30\x39\x30\x35\x32\x34\x30\x32\x30\x32\x34\x30" 523 1.2 christos "\x5a", 524 1.1 elric "time 2" } 525 1.1 elric }; 526 1.1 elric 527 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 528 1.1 elric KerberosTime times[] = { 529 1.1 elric 4711, 530 1.1 elric 1243130560 531 1.1 elric }; 532 1.1 elric 533 1.1 elric tests[0].val = ×[0]; 534 1.1 elric tests[1].val = ×[1]; 535 1.1 elric 536 1.1 elric return generic_test (tests, ntests, sizeof(KerberosTime), 537 1.1 elric (generic_encode)encode_KerberosTime, 538 1.1 elric (generic_length)length_KerberosTime, 539 1.1 elric (generic_decode)decode_KerberosTime, 540 1.1 elric (generic_free)free_KerberosTime, 541 1.1 elric cmp_KerberosTime, 542 1.1 elric (generic_copy)copy_KerberosTime); 543 1.1 elric } 544 1.1 elric 545 1.1 elric struct { 546 1.1 elric const char *cert; 547 1.1 elric size_t len; 548 1.1 elric } certs[] = { 549 1.1 elric { 550 1.1 elric "\x30\x82\x02\x6c\x30\x82\x01\xd5\xa0\x03\x02\x01\x02\x02\x09\x00" 551 1.1 elric "\x99\x32\xde\x61\x0e\x40\x19\x8a\x30\x0d\x06\x09\x2a\x86\x48\x86" 552 1.1 elric "\xf7\x0d\x01\x01\x05\x05\x00\x30\x2a\x31\x1b\x30\x19\x06\x03\x55" 553 1.1 elric "\x04\x03\x0c\x12\x68\x78\x35\x30\x39\x20\x54\x65\x73\x74\x20\x52" 554 1.1 elric "\x6f\x6f\x74\x20\x43\x41\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13" 555 1.1 elric "\x02\x53\x45\x30\x1e\x17\x0d\x30\x39\x30\x34\x32\x36\x32\x30\x32" 556 1.1 elric "\x39\x34\x30\x5a\x17\x0d\x31\x39\x30\x34\x32\x34\x32\x30\x32\x39" 557 1.1 elric "\x34\x30\x5a\x30\x2a\x31\x1b\x30\x19\x06\x03\x55\x04\x03\x0c\x12" 558 1.1 elric "\x68\x78\x35\x30\x39\x20\x54\x65\x73\x74\x20\x52\x6f\x6f\x74\x20" 559 1.1 elric "\x43\x41\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x30" 560 1.1 elric "\x81\x9f\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05" 561 1.1 elric "\x00\x03\x81\x8d\x00\x30\x81\x89\x02\x81\x81\x00\xb9\xd3\x1b\x67" 562 1.1 elric "\x1c\xf7\x5e\x26\x81\x3b\x82\xff\x03\xa4\x43\xb5\xb2\x63\x0b\x89" 563 1.1 elric "\x58\x43\xfe\x3d\xe0\x38\x7d\x93\x74\xbb\xad\x21\xa4\x29\xd9\x34" 564 1.1 elric "\x79\xf3\x1c\x8c\x5a\xd6\xb0\xd7\x19\xea\xcc\xaf\xe0\xa8\x40\x02" 565 1.1 elric "\x1d\x91\xf1\xac\x36\xb0\xfb\x08\xbd\xcc\x9a\xe1\xb7\x6e\xee\x0a" 566 1.1 elric "\x69\xbf\x6d\x2b\xee\x20\x82\x61\x06\xf2\x18\xcc\x89\x11\x64\x7e" 567 1.1 elric "\xb2\xff\x47\xd1\x3b\x52\x73\xeb\x5a\xc0\x03\xa6\x4b\xc7\x40\x7e" 568 1.1 elric "\xbc\xe1\x0e\x65\x44\x3f\x40\x8b\x02\x82\x54\x04\xd9\xcc\x2c\x67" 569 1.1 elric "\x01\xb6\x16\x82\xd8\x33\x53\x17\xd7\xde\x8d\x5d\x02\x03\x01\x00" 570 1.1 elric "\x01\xa3\x81\x99\x30\x81\x96\x30\x1d\x06\x03\x55\x1d\x0e\x04\x16" 571 1.1 elric "\x04\x14\x6e\x48\x13\xdc\xbf\x8b\x95\x4c\x13\xf3\x1f\x97\x30\xdd" 572 1.1 elric "\x27\x96\x59\x9b\x0e\x68\x30\x5a\x06\x03\x55\x1d\x23\x04\x53\x30" 573 1.1 elric "\x51\x80\x14\x6e\x48\x13\xdc\xbf\x8b\x95\x4c\x13\xf3\x1f\x97\x30" 574 1.1 elric "\xdd\x27\x96\x59\x9b\x0e\x68\xa1\x2e\xa4\x2c\x30\x2a\x31\x1b\x30" 575 1.1 elric "\x19\x06\x03\x55\x04\x03\x0c\x12\x68\x78\x35\x30\x39\x20\x54\x65" 576 1.1 elric "\x73\x74\x20\x52\x6f\x6f\x74\x20\x43\x41\x31\x0b\x30\x09\x06\x03" 577 1.1 elric "\x55\x04\x06\x13\x02\x53\x45\x82\x09\x00\x99\x32\xde\x61\x0e\x40" 578 1.1 elric "\x19\x8a\x30\x0c\x06\x03\x55\x1d\x13\x04\x05\x30\x03\x01\x01\xff" 579 1.1 elric "\x30\x0b\x06\x03\x55\x1d\x0f\x04\x04\x03\x02\x01\xe6\x30\x0d\x06" 580 1.1 elric "\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x03\x81\x81\x00" 581 1.1 elric "\x52\x9b\xe4\x0e\xee\xc2\x5d\xb7\xf1\xba\x47\xe3\xfe\xaf\x3d\x51" 582 1.1 elric "\x10\xfd\xe8\x0d\x14\x58\x05\x36\xa7\xeb\xd8\x05\xe5\x27\x6f\x51" 583 1.1 elric "\xb8\xec\x90\xd9\x03\xe1\xbc\x9c\x93\x38\x21\x5c\xaf\x4e\x6c\x7b" 584 1.1 elric "\x6c\x65\xa9\x92\xcd\x94\xef\xa8\xae\x90\x12\x14\x78\x2d\xa3\x15" 585 1.1 elric "\xaa\x42\xf1\xd9\x44\x64\x2c\x3c\xc0\xbd\x3a\x48\xd8\x80\x45\x8b" 586 1.1 elric "\xd1\x79\x82\xe0\x0f\xdf\x08\x3c\x60\x21\x6f\x31\x47\x98\xae\x2f" 587 1.1 elric "\xcb\xb1\xa1\xb9\xc1\xa3\x71\x5e\x4a\xc2\x67\xdf\x66\x0a\x51\xb5" 588 1.1 elric "\xad\x60\x05\xdb\x02\xd4\x1a\xd2\xb9\x4e\x01\x08\x2b\xc3\x57\xaf", 589 1.1 elric 624 }, 590 1.1 elric { 591 1.1 elric "\x30\x82\x02\x54\x30\x82\x01\xbd\xa0\x03\x02\x01\x02\x02\x01\x08" 592 1.1 elric "\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x05\x00\x30" 593 1.1 elric "\x2a\x31\x1b\x30\x19\x06\x03\x55\x04\x03\x0c\x12\x68\x78\x35\x30" 594 1.1 elric "\x39\x20\x54\x65\x73\x74\x20\x52\x6f\x6f\x74\x20\x43\x41\x31\x0b" 595 1.1 elric "\x30\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x30\x1e\x17\x0d\x30" 596 1.1 elric "\x39\x30\x34\x32\x36\x32\x30\x32\x39\x34\x30\x5a\x17\x0d\x31\x39" 597 1.1 elric "\x30\x34\x32\x34\x32\x30\x32\x39\x34\x30\x5a\x30\x1b\x31\x0b\x30" 598 1.1 elric "\x09\x06\x03\x55\x04\x06\x13\x02\x53\x45\x31\x0c\x30\x0a\x06\x03" 599 1.1 elric "\x55\x04\x03\x0c\x03\x6b\x64\x63\x30\x81\x9f\x30\x0d\x06\x09\x2a" 600 1.1 elric "\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81\x8d\x00\x30\x81" 601 1.1 elric "\x89\x02\x81\x81\x00\xd2\x41\x7a\xf8\x4b\x55\xb2\xaf\x11\xf9\x43" 602 1.1 elric "\x9b\x43\x81\x09\x3b\x9a\x94\xcf\x00\xf4\x85\x75\x92\xd7\x2a\xa5" 603 1.1 elric "\x11\xf1\xa8\x50\x6e\xc6\x84\x74\x24\x17\xda\x84\xc8\x03\x37\xb2" 604 1.1 elric "\x20\xf3\xba\xb5\x59\x36\x21\x4d\xab\x70\xe2\xc3\x09\x93\x68\x14" 605 1.1 elric "\x12\x79\xc5\xbb\x9e\x1b\x4a\xf0\xc6\x24\x59\x25\xc3\x1c\xa8\x70" 606 1.1 elric "\x66\x5b\x3e\x41\x8e\xe3\x25\x71\x9a\x94\xa0\x5b\x46\x91\x6f\xdd" 607 1.1 elric "\x58\x14\xec\x89\xe5\x8c\x96\xc5\x38\x60\xe4\xab\xf2\x75\xee\x6e" 608 1.1 elric "\x62\xfc\xe1\xbd\x03\x47\xff\xc4\xbe\x0f\xca\x70\x73\xe3\x74\x58" 609 1.1 elric "\x3a\x2f\x04\x2d\x39\x02\x03\x01\x00\x01\xa3\x81\x98\x30\x81\x95" 610 1.1 elric "\x30\x09\x06\x03\x55\x1d\x13\x04\x02\x30\x00\x30\x0b\x06\x03\x55" 611 1.1 elric "\x1d\x0f\x04\x04\x03\x02\x05\xe0\x30\x12\x06\x03\x55\x1d\x25\x04" 612 1.1 elric "\x0b\x30\x09\x06\x07\x2b\x06\x01\x05\x02\x03\x05\x30\x1d\x06\x03" 613 1.1 elric "\x55\x1d\x0e\x04\x16\x04\x14\x3a\xd3\x73\xff\xab\xdb\x7d\x8d\xc6" 614 1.1 elric "\x3a\xa2\x26\x3e\xae\x78\x95\x80\xc9\xe6\x31\x30\x48\x06\x03\x55" 615 1.1 elric "\x1d\x11\x04\x41\x30\x3f\xa0\x3d\x06\x06\x2b\x06\x01\x05\x02\x02" 616 1.1 elric "\xa0\x33\x30\x31\xa0\x0d\x1b\x0b\x54\x45\x53\x54\x2e\x48\x35\x4c" 617 1.1 elric "\x2e\x53\x45\xa1\x20\x30\x1e\xa0\x03\x02\x01\x01\xa1\x17\x30\x15" 618 1.1 elric "\x1b\x06\x6b\x72\x62\x74\x67\x74\x1b\x0b\x54\x45\x53\x54\x2e\x48" 619 1.1 elric "\x35\x4c\x2e\x53\x45\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01" 620 1.1 elric "\x01\x05\x05\x00\x03\x81\x81\x00\x83\xf4\x14\xa7\x6e\x59\xff\x80" 621 1.1 elric "\x64\xe7\xfa\xcf\x13\x80\x86\xe1\xed\x02\x38\xad\x96\x72\x25\xe5" 622 1.1 elric "\x06\x7a\x9a\xbc\x24\x74\xa9\x75\x55\xb2\x49\x80\x69\x45\x95\x4a" 623 1.1 elric "\x4c\x76\xa9\xe3\x4e\x49\xd3\xc2\x69\x5a\x95\x03\xeb\xba\x72\x23" 624 1.1 elric "\x9c\xfd\x3d\x8b\xc6\x07\x82\x3b\xf4\xf3\xef\x6c\x2e\x9e\x0b\xac" 625 1.1 elric "\x9e\x6c\xbb\x37\x4a\xa1\x9e\x73\xd1\xdc\x97\x61\xba\xfc\xd3\x49" 626 1.1 elric "\xa6\xc2\x4c\x55\x2e\x06\x37\x76\xb5\xef\x57\xe7\x57\x58\x8a\x71" 627 1.1 elric "\x63\xf3\xeb\xe7\x55\x68\x0d\xf6\x46\x4c\xfb\xf9\x43\xbb\x0c\x92" 628 1.1 elric "\x4f\x4e\x22\x7b\x63\xe8\x4f\x9c", 629 1.1 elric 600 630 1.1 elric } 631 1.1 elric }; 632 1.1 elric 633 1.1 elric static int 634 1.1 elric test_cert(void) 635 1.1 elric { 636 1.1 elric Certificate c, c2; 637 1.1 elric size_t size; 638 1.1 elric size_t i; 639 1.1 elric int ret; 640 1.1 elric 641 1.1 elric for (i = 0; i < sizeof(certs)/sizeof(certs[0]); i++) { 642 1.1 elric 643 1.1 elric ret = decode_Certificate((unsigned char *)certs[i].cert, 644 1.1 elric certs[i].len, &c, &size); 645 1.1 elric if (ret) 646 1.1 elric return ret; 647 1.1 elric 648 1.1 elric ret = copy_Certificate(&c, &c2); 649 1.1 elric free_Certificate(&c); 650 1.1 elric if (ret) 651 1.1 elric return ret; 652 1.1 elric 653 1.1 elric free_Certificate(&c2); 654 1.1 elric } 655 1.1 elric 656 1.1 elric return 0; 657 1.1 elric } 658 1.1 elric 659 1.2 christos struct { 660 1.2 christos const char *sd; 661 1.2 christos size_t len; 662 1.2 christos } signeddata[] = { 663 1.2 christos { 664 1.2 christos "\x30\x80\x02\x01\x03\x31\x0b\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a" 665 1.2 christos "\x05\x00\x30\x80\x06\x07\x2b\x06\x01\x05\x02\x03\x03\xa0\x80\x24" 666 1.2 christos "\x80\x04\x50\x30\x4e\xa0\x2b\x30\x29\xa0\x03\x02\x01\x12\xa1\x22" 667 1.2 christos "\x04\x20\x78\xf4\x86\x31\xc6\xc2\xc9\xcb\xef\x0c\xd7\x3a\x2a\xcd" 668 1.2 christos "\x8c\x13\x34\x83\xb1\x5c\xa8\xbe\xbf\x2f\xea\xd2\xbb\xd8\x8c\x18" 669 1.2 christos "\x47\x01\xa1\x1f\x30\x1d\xa0\x03\x02\x01\x0c\xa1\x16\x04\x14\xa6" 670 1.2 christos "\x2c\x52\xb2\x80\x98\x30\x40\xbc\x5f\xb0\x77\x2d\x8a\xd7\xa1\xda" 671 1.2 christos "\x3c\xc5\x62\x00\x00\x00\x00\x00\x00\xa0\x82\x02\x09\x30\x82\x02" 672 1.2 christos "\x05\x30\x82\x01\x6e\xa0\x03\x02\x01\x02\x02\x04\x49\x75\x57\xbf" 673 1.2 christos "\x30\x0b\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05\x30\x3b\x31" 674 1.2 christos "\x1f\x30\x1d\x06\x03\x55\x04\x03\x0c\x16\x63\x6f\x6d\x2e\x61\x70" 675 1.2 christos "\x70\x6c\x65\x2e\x6b\x65\x72\x62\x65\x72\x6f\x73\x2e\x6b\x64\x63" 676 1.2 christos "\x31\x18\x30\x16\x06\x03\x55\x04\x0a\x0c\x0f\x53\x79\x73\x74\x65" 677 1.2 christos "\x6d\x20\x49\x64\x65\x6e\x74\x69\x74\x79\x30\x1e\x17\x0d\x30\x39" 678 1.2 christos "\x31\x32\x30\x34\x30\x30\x32\x30\x32\x34\x5a\x17\x0d\x32\x39\x31" 679 1.2 christos "\x31\x32\x39\x30\x30\x32\x30\x32\x34\x5a\x30\x3b\x31\x1f\x30\x1d" 680 1.2 christos "\x06\x03\x55\x04\x03\x0c\x16\x63\x6f\x6d\x2e\x61\x70\x70\x6c\x65" 681 1.2 christos "\x2e\x6b\x65\x72\x62\x65\x72\x6f\x73\x2e\x6b\x64\x63\x31\x18\x30" 682 1.2 christos "\x16\x06\x03\x55\x04\x0a\x0c\x0f\x53\x79\x73\x74\x65\x6d\x20\x49" 683 1.2 christos "\x64\x65\x6e\x74\x69\x74\x79\x30\x81\x9f\x30\x0d\x06\x09\x2a\x86" 684 1.2 christos "\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81\x8d\x00\x30\x81\x89" 685 1.2 christos "\x02\x81\x81\x00\xb2\xc5\x4b\x34\xe3\x93\x99\xbb\xaa\xd1\x70\x62" 686 1.2 christos "\x6c\x9c\xcc\xa6\xbc\x47\xc3\x23\xff\x15\xb9\x11\x27\x0a\xf8\x55" 687 1.2 christos "\x4c\xb2\x43\x34\x75\xad\x55\xbb\xb9\x8a\xd0\x25\x64\xa4\x8c\x82" 688 1.2 christos "\x74\x5d\x89\x52\xe2\x76\x75\x08\x67\xb5\x9c\x9c\x69\x86\x0c\x6d" 689 1.2 christos "\x79\xf7\xa0\xbe\x42\x8f\x90\x46\x0c\x18\xf4\x7a\x56\x17\xa4\x65" 690 1.2 christos "\x00\x3a\x5e\x3e\xbf\xbc\xf5\xe2\x2c\x26\x03\x52\xdd\xd4\x85\x3f" 691 1.2 christos "\x03\xd7\x0c\x45\x7f\xff\xdd\x1e\x70\x6c\x9f\xb0\x8c\xd0\x33\xad" 692 1.2 christos "\x92\x54\x17\x9d\x88\x89\x1a\xee\xef\xf7\x96\x3e\x68\xc3\xd1\x60" 693 1.2 christos "\x47\x86\x80\x5d\x02\x03\x01\x00\x01\xa3\x18\x30\x16\x30\x14\x06" 694 1.2 christos "\x03\x55\x1d\x25\x04\x0d\x30\x0b\x06\x09\x2a\x86\x48\x86\xf7\x63" 695 1.2 christos "\x64\x04\x04\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x05" 696 1.2 christos "\x05\x00\x03\x81\x81\x00\x9b\xbb\xaa\x63\x66\xd8\x70\x84\x3e\xf6" 697 1.2 christos "\xa1\x3b\xf3\xe6\xd7\x3d\xfc\x4f\xc9\x45\xaa\x31\x43\x8d\xb5\x72" 698 1.2 christos "\xe4\x34\x95\x7b\x6e\x5f\xe5\xc8\x5e\xaf\x12\x08\x6d\xd7\x25\x76" 699 1.2 christos "\x40\xd5\xdc\x83\x7f\x2f\x74\xd1\x63\xc0\x7c\x26\x4d\x53\x10\xe7" 700 1.2 christos "\xfa\xcc\xf2\x60\x41\x63\xdf\x56\xd6\xd9\xc0\xb4\xd0\x73\x99\x54" 701 1.2 christos "\x40\xad\x90\x79\x2d\xd2\x5e\xcb\x13\x22\x2b\xd0\x76\xef\x8a\x48" 702 1.2 christos "\xfd\xb2\x6e\xca\x04\x4e\x91\x3f\xb4\x63\xad\x22\x3a\xf7\x20\x9c" 703 1.2 christos "\x4c\x0e\x47\x78\xe5\x2a\x85\x0e\x90\x7a\xce\x46\xe6\x15\x02\xb0" 704 1.2 christos "\x83\xe7\xac\xfa\x92\xf8\x31\x81\xe8\x30\x81\xe5\x02\x01\x01\x30" 705 1.2 christos "\x43\x30\x3b\x31\x1f\x30\x1d\x06\x03\x55\x04\x03\x0c\x16\x63\x6f" 706 1.2 christos "\x6d\x2e\x61\x70\x70\x6c\x65\x2e\x6b\x65\x72\x62\x65\x72\x6f\x73" 707 1.2 christos "\x2e\x6b\x64\x63\x31\x18\x30\x16\x06\x03\x55\x04\x0a\x0c\x0f\x53" 708 1.2 christos "\x79\x73\x74\x65\x6d\x20\x49\x64\x65\x6e\x74\x69\x74\x79\x02\x04" 709 1.2 christos "\x49\x75\x57\xbf\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x30" 710 1.2 christos "\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x04\x81" 711 1.2 christos "\x80\x50\x2c\x69\xe1\xd2\xc4\xd1\xcc\xdc\xe0\xe9\x8a\x6b\x6a\x97" 712 1.2 christos "\x1b\xb4\xe0\xa8\x20\xbe\x09\x6d\xe1\x55\x5f\x07\x70\x94\x2e\x14" 713 1.2 christos "\xed\x4e\xb1\x69\x75\x40\xbb\x99\x87\xed\x23\x50\x27\x5f\xaa\xc4" 714 1.2 christos "\x84\x60\x06\xfe\x45\xfd\x7e\x1b\x18\xe0\x0b\x77\x35\x2a\xb2\xf2" 715 1.2 christos "\xe0\x88\x31\xad\x82\x31\x4a\xbc\x6d\x71\x62\xe6\x4d\x33\xb4\x09" 716 1.2 christos "\x6e\x3f\x14\x12\xf2\x89\x29\x31\x84\x60\x2b\xa8\x2d\xe6\xca\x2f" 717 1.2 christos "\x03\x3d\xd4\x69\x89\xb3\x98\xfd\xac\x63\x14\xaf\x6a\x52\x2a\xac" 718 1.2 christos "\xe3\x8e\xfa\x21\x41\x8f\xcc\x04\x2d\x52\xee\x49\x54\x0d\x58\x51" 719 1.2 christos "\x77\x00\x00", 720 1.2 christos 883 721 1.2 christos } 722 1.2 christos }; 723 1.2 christos 724 1.2 christos static int 725 1.2 christos test_SignedData(void) 726 1.2 christos { 727 1.2 christos SignedData sd; 728 1.2 christos size_t size, i; 729 1.2 christos int ret; 730 1.2 christos 731 1.2 christos for (i = 0; i < sizeof(signeddata) / sizeof(signeddata[0]); i++) { 732 1.2 christos 733 1.2 christos ret = decode_SignedData((unsigned char *)signeddata[i].sd, 734 1.2 christos signeddata[i].len, &sd, &size); 735 1.2 christos if (ret) 736 1.2 christos return ret; 737 1.2 christos 738 1.2 christos free_SignedData(&sd); 739 1.2 christos } 740 1.2 christos 741 1.2 christos return 0; 742 1.2 christos } 743 1.2 christos 744 1.1 elric 745 1.1 elric static int 746 1.1 elric cmp_TESTLargeTag (void *a, void *b) 747 1.1 elric { 748 1.1 elric TESTLargeTag *aa = a; 749 1.1 elric TESTLargeTag *ab = b; 750 1.1 elric 751 1.1 elric COMPARE_INTEGER(aa,ab,foo); 752 1.1 elric COMPARE_INTEGER(aa,ab,bar); 753 1.1 elric return 0; 754 1.1 elric } 755 1.1 elric 756 1.1 elric static int 757 1.1 elric test_large_tag (void) 758 1.1 elric { 759 1.1 elric struct test_case tests[] = { 760 1.1 elric { NULL, 15, "\x30\x0d\xbf\x7f\x03\x02\x01\x01\xbf\x81\x00\x03\x02\x01\x02", "large tag 1" } 761 1.1 elric }; 762 1.1 elric 763 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 764 1.1 elric TESTLargeTag lt1; 765 1.1 elric 766 1.1 elric memset(<1, 0, sizeof(lt1)); 767 1.1 elric lt1.foo = 1; 768 1.1 elric lt1.bar = 2; 769 1.1 elric 770 1.1 elric tests[0].val = <1; 771 1.1 elric 772 1.1 elric return generic_test (tests, ntests, sizeof(TESTLargeTag), 773 1.1 elric (generic_encode)encode_TESTLargeTag, 774 1.1 elric (generic_length)length_TESTLargeTag, 775 1.1 elric (generic_decode)decode_TESTLargeTag, 776 1.1 elric (generic_free)free_TESTLargeTag, 777 1.1 elric cmp_TESTLargeTag, 778 1.1 elric (generic_copy)copy_TESTLargeTag); 779 1.1 elric } 780 1.1 elric 781 1.1 elric struct test_data { 782 1.1 elric int ok; 783 1.1 elric size_t len; 784 1.1 elric size_t expected_len; 785 1.1 elric void *data; 786 1.1 elric }; 787 1.1 elric 788 1.1 elric static int 789 1.1 elric check_tag_length(void) 790 1.1 elric { 791 1.1 elric struct test_data td[] = { 792 1.1 elric { 1, 3, 3, "\x02\x01\x00"}, 793 1.1 elric { 1, 3, 3, "\x02\x01\x7f"}, 794 1.1 elric { 1, 4, 4, "\x02\x02\x00\x80"}, 795 1.1 elric { 1, 4, 4, "\x02\x02\x01\x00"}, 796 1.1 elric { 1, 4, 4, "\x02\x02\x02\x00"}, 797 1.1 elric { 0, 3, 0, "\x02\x02\x00"}, 798 1.1 elric { 0, 3, 0, "\x02\x7f\x7f"}, 799 1.1 elric { 0, 4, 0, "\x02\x03\x00\x80"}, 800 1.1 elric { 0, 4, 0, "\x02\x7f\x01\x00"}, 801 1.1 elric { 0, 5, 0, "\x02\xff\x7f\x02\x00"} 802 1.1 elric }; 803 1.1 elric size_t sz; 804 1.1 elric TESTuint32 values[] = {0, 127, 128, 256, 512, 805 1.1 elric 0, 127, 128, 256, 512 }; 806 1.1 elric TESTuint32 u; 807 1.1 elric int i, ret, failed = 0; 808 1.1 elric void *buf; 809 1.1 elric 810 1.1 elric for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) { 811 1.1 elric struct map_page *page; 812 1.1 elric 813 1.1 elric buf = map_alloc(OVERRUN, td[i].data, td[i].len, &page); 814 1.1 elric 815 1.1 elric ret = decode_TESTuint32(buf, td[i].len, &u, &sz); 816 1.1 elric if (ret) { 817 1.1 elric if (td[i].ok) { 818 1.1 elric printf("failed with tag len test %d\n", i); 819 1.1 elric failed = 1; 820 1.1 elric } 821 1.1 elric } else { 822 1.1 elric if (td[i].ok == 0) { 823 1.1 elric printf("failed with success for tag len test %d\n", i); 824 1.1 elric failed = 1; 825 1.1 elric } 826 1.1 elric if (td[i].expected_len != sz) { 827 1.1 elric printf("wrong expected size for tag test %d\n", i); 828 1.1 elric failed = 1; 829 1.1 elric } 830 1.1 elric if (values[i] != u) { 831 1.1 elric printf("wrong value for tag test %d\n", i); 832 1.1 elric failed = 1; 833 1.1 elric } 834 1.1 elric } 835 1.1 elric map_free(page, "test", "decode"); 836 1.1 elric } 837 1.1 elric return failed; 838 1.1 elric } 839 1.1 elric 840 1.1 elric static int 841 1.2 christos check_tag_length64(void) 842 1.2 christos { 843 1.2 christos struct test_data td[] = { 844 1.2 christos { 1, 3, 3, "\x02\x01\x00"}, 845 1.2 christos { 1, 7, 7, "\x02\x05\x01\xff\xff\xff\xff"}, 846 1.2 christos { 1, 7, 7, "\x02\x05\x02\x00\x00\x00\x00"}, 847 1.2 christos { 1, 9, 9, "\x02\x07\x7f\xff\xff\xff\xff\xff\xff"}, 848 1.2 christos { 1, 10, 10, "\x02\x08\x00\x80\x00\x00\x00\x00\x00\x00"}, 849 1.2 christos { 1, 10, 10, "\x02\x08\x7f\xff\xff\xff\xff\xff\xff\xff"}, 850 1.2 christos { 1, 11, 11, "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"}, 851 1.2 christos { 0, 3, 0, "\x02\x02\x00"}, 852 1.2 christos { 0, 3, 0, "\x02\x7f\x7f"}, 853 1.2 christos { 0, 4, 0, "\x02\x03\x00\x80"}, 854 1.2 christos { 0, 4, 0, "\x02\x7f\x01\x00"}, 855 1.2 christos { 0, 5, 0, "\x02\xff\x7f\x02\x00"} 856 1.2 christos }; 857 1.2 christos size_t sz; 858 1.2 christos TESTuint64 values[] = {0, 8589934591LL, 8589934592LL, 859 1.2 christos 36028797018963967LL, 36028797018963968LL, 860 1.2 christos 9223372036854775807LL, 18446744073709551615ULL, 861 1.2 christos 0, 127, 128, 256, 512 }; 862 1.2 christos TESTuint64 u; 863 1.2 christos int i, ret, failed = 0; 864 1.2 christos void *buf; 865 1.2 christos 866 1.2 christos if (sizeof(TESTuint64) != sizeof(uint64_t)) { 867 1.2 christos ret += 1; 868 1.2 christos printf("sizeof(TESTuint64) %d != sizeof(uint64_t) %d\n", 869 1.2 christos (int)sizeof(TESTuint64), (int)sizeof(uint64_t)); 870 1.2 christos } 871 1.2 christos 872 1.2 christos for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) { 873 1.2 christos struct map_page *page; 874 1.2 christos 875 1.2 christos buf = map_alloc(OVERRUN, td[i].data, td[i].len, &page); 876 1.2 christos 877 1.2 christos ret = decode_TESTuint64(buf, td[i].len, &u, &sz); 878 1.2 christos if (ret) { 879 1.2 christos if (td[i].ok) { 880 1.2 christos printf("failed with tag len test %d\n", i); 881 1.2 christos printf("ret = %d\n", ret); 882 1.2 christos failed = 1; 883 1.2 christos } 884 1.2 christos } else { 885 1.2 christos if (td[i].ok == 0) { 886 1.2 christos printf("failed with success for tag len test %d\n", i); 887 1.2 christos failed = 1; 888 1.2 christos } 889 1.2 christos if (td[i].expected_len != sz) { 890 1.2 christos printf("wrong expected size for tag test %d\n", i); 891 1.2 christos printf("sz = %lu\n", (unsigned long)sz); 892 1.2 christos failed = 1; 893 1.2 christos } 894 1.2 christos if (values[i] != u) { 895 1.2 christos printf("wrong value for tag test %d\n", i); 896 1.2 christos printf("Expected value: %llu\nActual value: %llu\n", 897 1.2 christos (unsigned long long)values[i], (unsigned long long)u); 898 1.2 christos failed = 1; 899 1.2 christos } 900 1.2 christos } 901 1.2 christos map_free(page, "test", "decode"); 902 1.2 christos } 903 1.2 christos return failed; 904 1.2 christos } 905 1.2 christos 906 1.2 christos static int 907 1.2 christos check_tag_length64s(void) 908 1.2 christos { 909 1.2 christos struct test_data td[] = { 910 1.2 christos { 1, 3, 3, "\x02\x01\x00"}, 911 1.2 christos { 1, 7, 7, "\x02\x05\xfe\x00\x00\x00\x01"}, 912 1.2 christos { 1, 7, 7, "\x02\x05\xfe\x00\x00\x00\x00"}, 913 1.2 christos { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x01"}, 914 1.2 christos { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x00"}, 915 1.2 christos { 1, 10, 10, "\x02\x08\x80\x00\x00\x00\x00\x00\x00\x01"}, 916 1.2 christos { 1, 9, 9, "\x02\x07\x80\x00\x00\x00\x00\x00\x01"}, 917 1.2 christos { 0, 3, 0, "\x02\x02\x00"}, 918 1.2 christos { 0, 3, 0, "\x02\x7f\x7f"}, 919 1.2 christos { 0, 4, 0, "\x02\x03\x00\x80"}, 920 1.2 christos { 0, 4, 0, "\x02\x7f\x01\x00"}, 921 1.2 christos { 0, 5, 0, "\x02\xff\x7f\x02\x00"} 922 1.2 christos }; 923 1.2 christos size_t sz; 924 1.2 christos TESTint64 values[] = {0, -8589934591LL, -8589934592LL, 925 1.2 christos -36028797018963967LL, -36028797018963968LL, 926 1.2 christos -9223372036854775807LL, -36028797018963967LL, 927 1.2 christos 0, 127, 128, 256, 512 }; 928 1.2 christos TESTint64 u; 929 1.2 christos int i, ret, failed = 0; 930 1.2 christos void *buf; 931 1.2 christos 932 1.2 christos for (i = 0; i < sizeof(td)/sizeof(td[0]); i++) { 933 1.2 christos struct map_page *page; 934 1.2 christos 935 1.2 christos buf = map_alloc(OVERRUN, td[i].data, td[i].len, &page); 936 1.2 christos 937 1.2 christos ret = decode_TESTint64(buf, td[i].len, &u, &sz); 938 1.2 christos if (ret) { 939 1.2 christos if (td[i].ok) { 940 1.2 christos printf("failed with tag len test %d\n", i); 941 1.2 christos printf("ret = %d\n", ret); 942 1.2 christos failed = 1; 943 1.2 christos } 944 1.2 christos } else { 945 1.2 christos if (td[i].ok == 0) { 946 1.2 christos printf("failed with success for tag len test %d\n", i); 947 1.2 christos failed = 1; 948 1.2 christos } 949 1.2 christos if (td[i].expected_len != sz) { 950 1.2 christos printf("wrong expected size for tag test %d\n", i); 951 1.2 christos printf("sz = %lu\n", (unsigned long)sz); 952 1.2 christos failed = 1; 953 1.2 christos } 954 1.2 christos if (values[i] != u) { 955 1.2 christos printf("wrong value for tag test %d\n", i); 956 1.2 christos printf("Expected value: %lld\nActual value: %lld\n", 957 1.2 christos (long long)values[i], (long long)u); 958 1.2 christos failed = 1; 959 1.2 christos } 960 1.2 christos } 961 1.2 christos map_free(page, "test", "decode"); 962 1.2 christos } 963 1.2 christos return failed; 964 1.2 christos } 965 1.2 christos 966 1.2 christos static int 967 1.1 elric cmp_TESTChoice (void *a, void *b) 968 1.1 elric { 969 1.1 elric return 0; 970 1.1 elric } 971 1.1 elric 972 1.1 elric static int 973 1.1 elric test_choice (void) 974 1.1 elric { 975 1.1 elric struct test_case tests[] = { 976 1.1 elric { NULL, 5, "\xa1\x03\x02\x01\x01", "large choice 1" }, 977 1.1 elric { NULL, 5, "\xa2\x03\x02\x01\x02", "large choice 2" } 978 1.1 elric }; 979 1.1 elric 980 1.1 elric int ret = 0, ntests = sizeof(tests) / sizeof(*tests); 981 1.1 elric TESTChoice1 c1; 982 1.1 elric TESTChoice1 c2_1; 983 1.1 elric TESTChoice2 c2_2; 984 1.1 elric 985 1.1 elric memset(&c1, 0, sizeof(c1)); 986 1.1 elric c1.element = choice_TESTChoice1_i1; 987 1.1 elric c1.u.i1 = 1; 988 1.1 elric tests[0].val = &c1; 989 1.1 elric 990 1.1 elric memset(&c2_1, 0, sizeof(c2_1)); 991 1.1 elric c2_1.element = choice_TESTChoice1_i2; 992 1.1 elric c2_1.u.i2 = 2; 993 1.1 elric tests[1].val = &c2_1; 994 1.1 elric 995 1.1 elric ret += generic_test (tests, ntests, sizeof(TESTChoice1), 996 1.1 elric (generic_encode)encode_TESTChoice1, 997 1.1 elric (generic_length)length_TESTChoice1, 998 1.1 elric (generic_decode)decode_TESTChoice1, 999 1.1 elric (generic_free)free_TESTChoice1, 1000 1.1 elric cmp_TESTChoice, 1001 1.1 elric (generic_copy)copy_TESTChoice1); 1002 1.1 elric 1003 1.1 elric memset(&c2_2, 0, sizeof(c2_2)); 1004 1.1 elric c2_2.element = choice_TESTChoice2_asn1_ellipsis; 1005 1.1 elric c2_2.u.asn1_ellipsis.data = "\xa2\x03\x02\x01\x02"; 1006 1.1 elric c2_2.u.asn1_ellipsis.length = 5; 1007 1.1 elric tests[1].val = &c2_2; 1008 1.1 elric 1009 1.1 elric ret += generic_test (tests, ntests, sizeof(TESTChoice2), 1010 1.1 elric (generic_encode)encode_TESTChoice2, 1011 1.1 elric (generic_length)length_TESTChoice2, 1012 1.1 elric (generic_decode)decode_TESTChoice2, 1013 1.1 elric (generic_free)free_TESTChoice2, 1014 1.1 elric cmp_TESTChoice, 1015 1.1 elric (generic_copy)copy_TESTChoice2); 1016 1.1 elric 1017 1.1 elric return ret; 1018 1.1 elric } 1019 1.1 elric 1020 1.2 christos #ifdef IMPLICIT_TAGGING_WORKS 1021 1.1 elric static int 1022 1.1 elric cmp_TESTImplicit (void *a, void *b) 1023 1.1 elric { 1024 1.1 elric TESTImplicit *aa = a; 1025 1.1 elric TESTImplicit *ab = b; 1026 1.1 elric 1027 1.1 elric COMPARE_INTEGER(aa,ab,ti1); 1028 1.1 elric COMPARE_INTEGER(aa,ab,ti2.foo); 1029 1.1 elric COMPARE_INTEGER(aa,ab,ti3); 1030 1.1 elric return 0; 1031 1.1 elric } 1032 1.2 christos #endif 1033 1.1 elric 1034 1.1 elric /* 1035 1.1 elric UNIV CONS Sequence 14 1036 1.1 elric CONTEXT PRIM 0 1 00 1037 1.1 elric CONTEXT CONS 1 6 1038 1.2 christos CONTEXT CONS 127 3 1039 1.2 christos UNIV PRIM Integer 1 02 1040 1.1 elric CONTEXT PRIM 2 1 03 1041 1.1 elric */ 1042 1.1 elric 1043 1.1 elric static int 1044 1.1 elric test_implicit (void) 1045 1.1 elric { 1046 1.2 christos int ret = 0; 1047 1.2 christos #ifdef IMPLICIT_TAGGING_WORKS 1048 1.1 elric struct test_case tests[] = { 1049 1.2 christos { NULL, 18, 1050 1.2 christos "\x30\x10\x80\x01\x00\xa1\x06\xbf" 1051 1.2 christos "\x7f\x03\x02\x01\x02\xa2\x03\x84\x01\x03", 1052 1.1 elric "implicit 1" } 1053 1.1 elric }; 1054 1.1 elric 1055 1.2 christos int ntests = sizeof(tests) / sizeof(*tests); 1056 1.1 elric TESTImplicit c0; 1057 1.1 elric 1058 1.1 elric memset(&c0, 0, sizeof(c0)); 1059 1.1 elric c0.ti1 = 0; 1060 1.1 elric c0.ti2.foo = 2; 1061 1.1 elric c0.ti3 = 3; 1062 1.1 elric tests[0].val = &c0; 1063 1.1 elric 1064 1.1 elric ret += generic_test (tests, ntests, sizeof(TESTImplicit), 1065 1.1 elric (generic_encode)encode_TESTImplicit, 1066 1.1 elric (generic_length)length_TESTImplicit, 1067 1.1 elric (generic_decode)decode_TESTImplicit, 1068 1.1 elric (generic_free)free_TESTImplicit, 1069 1.1 elric cmp_TESTImplicit, 1070 1.1 elric (generic_copy)copy_TESTImplicit); 1071 1.1 elric 1072 1.1 elric ret += generic_test (tests, ntests, sizeof(TESTImplicit2), 1073 1.1 elric (generic_encode)encode_TESTImplicit2, 1074 1.1 elric (generic_length)length_TESTImplicit2, 1075 1.1 elric (generic_decode)decode_TESTImplicit2, 1076 1.1 elric (generic_free)free_TESTImplicit2, 1077 1.1 elric cmp_TESTImplicit, 1078 1.1 elric NULL); 1079 1.1 elric 1080 1.1 elric #endif /* IMPLICIT_TAGGING_WORKS */ 1081 1.1 elric return ret; 1082 1.1 elric } 1083 1.1 elric 1084 1.1 elric static int 1085 1.1 elric cmp_TESTAlloc (void *a, void *b) 1086 1.1 elric { 1087 1.1 elric TESTAlloc *aa = a; 1088 1.1 elric TESTAlloc *ab = b; 1089 1.1 elric 1090 1.1 elric IF_OPT_COMPARE(aa,ab,tagless) { 1091 1.1 elric COMPARE_INTEGER(aa,ab,tagless->ai); 1092 1.1 elric } 1093 1.1 elric 1094 1.1 elric COMPARE_INTEGER(aa,ab,three); 1095 1.1 elric 1096 1.1 elric IF_OPT_COMPARE(aa,ab,tagless2) { 1097 1.2 christos COMPARE_OPT_OCTET_STRING(aa, ab, tagless2); 1098 1.1 elric } 1099 1.1 elric 1100 1.1 elric return 0; 1101 1.1 elric } 1102 1.1 elric 1103 1.1 elric /* 1104 1.1 elric UNIV CONS Sequence 12 1105 1.1 elric UNIV CONS Sequence 5 1106 1.1 elric CONTEXT CONS 0 3 1107 1.1 elric UNIV PRIM Integer 1 01 1108 1.1 elric CONTEXT CONS 1 3 1109 1.1 elric UNIV PRIM Integer 1 03 1110 1.1 elric 1111 1.1 elric UNIV CONS Sequence 5 1112 1.1 elric CONTEXT CONS 1 3 1113 1.1 elric UNIV PRIM Integer 1 03 1114 1.1 elric 1115 1.1 elric UNIV CONS Sequence 8 1116 1.1 elric CONTEXT CONS 1 3 1117 1.1 elric UNIV PRIM Integer 1 04 1118 1.1 elric UNIV PRIM Integer 1 05 1119 1.1 elric 1120 1.1 elric */ 1121 1.1 elric 1122 1.1 elric static int 1123 1.1 elric test_taglessalloc (void) 1124 1.1 elric { 1125 1.1 elric struct test_case tests[] = { 1126 1.1 elric { NULL, 14, 1127 1.1 elric "\x30\x0c\x30\x05\xa0\x03\x02\x01\x01\xa1\x03\x02\x01\x03", 1128 1.1 elric "alloc 1" }, 1129 1.1 elric { NULL, 7, 1130 1.1 elric "\x30\x05\xa1\x03\x02\x01\x03", 1131 1.1 elric "alloc 2" }, 1132 1.1 elric { NULL, 10, 1133 1.1 elric "\x30\x08\xa1\x03\x02\x01\x04\x02\x01\x05", 1134 1.1 elric "alloc 3" } 1135 1.1 elric }; 1136 1.1 elric 1137 1.1 elric int ret = 0, ntests = sizeof(tests) / sizeof(*tests); 1138 1.1 elric TESTAlloc c1, c2, c3; 1139 1.1 elric heim_any any3; 1140 1.1 elric 1141 1.1 elric memset(&c1, 0, sizeof(c1)); 1142 1.1 elric c1.tagless = ecalloc(1, sizeof(*c1.tagless)); 1143 1.1 elric c1.tagless->ai = 1; 1144 1.1 elric c1.three = 3; 1145 1.1 elric tests[0].val = &c1; 1146 1.1 elric 1147 1.1 elric memset(&c2, 0, sizeof(c2)); 1148 1.1 elric c2.tagless = NULL; 1149 1.1 elric c2.three = 3; 1150 1.1 elric tests[1].val = &c2; 1151 1.1 elric 1152 1.1 elric memset(&c3, 0, sizeof(c3)); 1153 1.1 elric c3.tagless = NULL; 1154 1.1 elric c3.three = 4; 1155 1.1 elric c3.tagless2 = &any3; 1156 1.1 elric any3.data = "\x02\x01\x05"; 1157 1.1 elric any3.length = 3; 1158 1.1 elric tests[2].val = &c3; 1159 1.1 elric 1160 1.1 elric ret += generic_test (tests, ntests, sizeof(TESTAlloc), 1161 1.1 elric (generic_encode)encode_TESTAlloc, 1162 1.1 elric (generic_length)length_TESTAlloc, 1163 1.1 elric (generic_decode)decode_TESTAlloc, 1164 1.1 elric (generic_free)free_TESTAlloc, 1165 1.1 elric cmp_TESTAlloc, 1166 1.1 elric (generic_copy)copy_TESTAlloc); 1167 1.1 elric 1168 1.1 elric free(c1.tagless); 1169 1.1 elric 1170 1.1 elric return ret; 1171 1.1 elric } 1172 1.1 elric 1173 1.1 elric static int 1174 1.1 elric cmp_TESTOptional (void *a, void *b) 1175 1.1 elric { 1176 1.1 elric TESTOptional *aa = a; 1177 1.1 elric TESTOptional *ab = b; 1178 1.1 elric 1179 1.1 elric IF_OPT_COMPARE(aa,ab,zero) { 1180 1.1 elric COMPARE_OPT_INTEGER(aa,ab,zero); 1181 1.1 elric } 1182 1.1 elric IF_OPT_COMPARE(aa,ab,one) { 1183 1.1 elric COMPARE_OPT_INTEGER(aa,ab,one); 1184 1.1 elric } 1185 1.1 elric return 0; 1186 1.1 elric } 1187 1.1 elric 1188 1.1 elric /* 1189 1.1 elric UNIV CONS Sequence 5 1190 1.1 elric CONTEXT CONS 0 3 1191 1.1 elric UNIV PRIM Integer 1 00 1192 1.1 elric 1193 1.1 elric UNIV CONS Sequence 5 1194 1.1 elric CONTEXT CONS 1 3 1195 1.1 elric UNIV PRIM Integer 1 03 1196 1.1 elric 1197 1.1 elric UNIV CONS Sequence 10 1198 1.1 elric CONTEXT CONS 0 3 1199 1.1 elric UNIV PRIM Integer 1 00 1200 1.1 elric CONTEXT CONS 1 3 1201 1.1 elric UNIV PRIM Integer 1 01 1202 1.1 elric 1203 1.1 elric */ 1204 1.1 elric 1205 1.1 elric static int 1206 1.1 elric test_optional (void) 1207 1.1 elric { 1208 1.1 elric struct test_case tests[] = { 1209 1.1 elric { NULL, 2, 1210 1.1 elric "\x30\x00", 1211 1.1 elric "optional 0" }, 1212 1.1 elric { NULL, 7, 1213 1.1 elric "\x30\x05\xa0\x03\x02\x01\x00", 1214 1.1 elric "optional 1" }, 1215 1.1 elric { NULL, 7, 1216 1.1 elric "\x30\x05\xa1\x03\x02\x01\x01", 1217 1.1 elric "optional 2" }, 1218 1.1 elric { NULL, 12, 1219 1.1 elric "\x30\x0a\xa0\x03\x02\x01\x00\xa1\x03\x02\x01\x01", 1220 1.1 elric "optional 3" } 1221 1.1 elric }; 1222 1.1 elric 1223 1.1 elric int ret = 0, ntests = sizeof(tests) / sizeof(*tests); 1224 1.1 elric TESTOptional c0, c1, c2, c3; 1225 1.1 elric int zero = 0; 1226 1.1 elric int one = 1; 1227 1.1 elric 1228 1.1 elric c0.zero = NULL; 1229 1.1 elric c0.one = NULL; 1230 1.1 elric tests[0].val = &c0; 1231 1.1 elric 1232 1.1 elric c1.zero = &zero; 1233 1.1 elric c1.one = NULL; 1234 1.1 elric tests[1].val = &c1; 1235 1.1 elric 1236 1.1 elric c2.zero = NULL; 1237 1.1 elric c2.one = &one; 1238 1.1 elric tests[2].val = &c2; 1239 1.1 elric 1240 1.1 elric c3.zero = &zero; 1241 1.1 elric c3.one = &one; 1242 1.1 elric tests[3].val = &c3; 1243 1.1 elric 1244 1.1 elric ret += generic_test (tests, ntests, sizeof(TESTOptional), 1245 1.1 elric (generic_encode)encode_TESTOptional, 1246 1.1 elric (generic_length)length_TESTOptional, 1247 1.1 elric (generic_decode)decode_TESTOptional, 1248 1.1 elric (generic_free)free_TESTOptional, 1249 1.1 elric cmp_TESTOptional, 1250 1.1 elric (generic_copy)copy_TESTOptional); 1251 1.1 elric 1252 1.1 elric return ret; 1253 1.1 elric } 1254 1.1 elric 1255 1.1 elric static int 1256 1.1 elric check_fail_largetag(void) 1257 1.1 elric { 1258 1.1 elric struct test_case tests[] = { 1259 1.1 elric {NULL, 14, "\x30\x0c\xbf\x87\xff\xff\xff\xff\xff\x7f\x03\x02\x01\x01", 1260 1.1 elric "tag overflow"}, 1261 1.1 elric {NULL, 0, "", "empty buffer"}, 1262 1.1 elric {NULL, 7, "\x30\x05\xa1\x03\x02\x02\x01", 1263 1.1 elric "one too short" }, 1264 1.2 christos {NULL, 7, "\x30\x04\xa1\x03\x02\x02\x01", 1265 1.1 elric "two too short" }, 1266 1.1 elric {NULL, 7, "\x30\x03\xa1\x03\x02\x02\x01", 1267 1.1 elric "three too short" }, 1268 1.1 elric {NULL, 7, "\x30\x02\xa1\x03\x02\x02\x01", 1269 1.1 elric "four too short" }, 1270 1.1 elric {NULL, 7, "\x30\x01\xa1\x03\x02\x02\x01", 1271 1.1 elric "five too short" }, 1272 1.1 elric {NULL, 7, "\x30\x00\xa1\x03\x02\x02\x01", 1273 1.1 elric "six too short" }, 1274 1.1 elric {NULL, 7, "\x30\x05\xa1\x04\x02\x02\x01", 1275 1.1 elric "inner one too long" }, 1276 1.1 elric {NULL, 7, "\x30\x00\xa1\x02\x02\x02\x01", 1277 1.1 elric "inner one too short" }, 1278 1.1 elric {NULL, 8, "\x30\x05\xbf\x7f\x03\x02\x02\x01", 1279 1.1 elric "inner one too short"}, 1280 1.1 elric {NULL, 8, "\x30\x06\xbf\x64\x03\x02\x01\x01", 1281 1.1 elric "wrong tag"}, 1282 1.1 elric {NULL, 10, "\x30\x08\xbf\x9a\x9b\x38\x03\x02\x01\x01", 1283 1.1 elric "still wrong tag"} 1284 1.1 elric }; 1285 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 1286 1.1 elric 1287 1.1 elric return generic_decode_fail(tests, ntests, sizeof(TESTLargeTag), 1288 1.1 elric (generic_decode)decode_TESTLargeTag); 1289 1.1 elric } 1290 1.1 elric 1291 1.1 elric 1292 1.1 elric static int 1293 1.1 elric check_fail_sequence(void) 1294 1.1 elric { 1295 1.1 elric struct test_case tests[] = { 1296 1.1 elric {NULL, 0, "", "empty buffer"}, 1297 1.1 elric {NULL, 24, 1298 1.1 elric "\x30\x16\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01" 1299 1.2 christos "\x02\x01\x01\xa2\x03\x02\x01\x01", 1300 1.1 elric "missing one byte from the end, internal length ok"}, 1301 1.1 elric {NULL, 25, 1302 1.1 elric "\x30\x18\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01\x01" 1303 1.1 elric "\x02\x01\x01\xa2\x03\x02\x01\x01", 1304 1.1 elric "inner length one byte too long"}, 1305 1.1 elric {NULL, 24, 1306 1.1 elric "\x30\x17\xa0\x03\x02\x01\x01\xa1\x08\x30\x06\xbf\x7f\x03\x02\x01" 1307 1.1 elric "\x01\x02\x01\x01\xa2\x03\x02\x01\x01", 1308 1.1 elric "correct buffer but missing one too short"} 1309 1.1 elric }; 1310 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 1311 1.1 elric 1312 1.1 elric return generic_decode_fail(tests, ntests, sizeof(TESTSeq), 1313 1.1 elric (generic_decode)decode_TESTSeq); 1314 1.1 elric } 1315 1.1 elric 1316 1.1 elric static int 1317 1.1 elric check_fail_choice(void) 1318 1.1 elric { 1319 1.1 elric struct test_case tests[] = { 1320 1.1 elric {NULL, 6, 1321 1.1 elric "\xa1\x02\x02\x01\x01", 1322 1.1 elric "choice one too short"}, 1323 1.1 elric {NULL, 6, 1324 1.1 elric "\xa1\x03\x02\x02\x01", 1325 1.1 elric "choice one too short inner"} 1326 1.1 elric }; 1327 1.1 elric int ntests = sizeof(tests) / sizeof(*tests); 1328 1.1 elric 1329 1.1 elric return generic_decode_fail(tests, ntests, sizeof(TESTChoice1), 1330 1.1 elric (generic_decode)decode_TESTChoice1); 1331 1.1 elric } 1332 1.1 elric 1333 1.1 elric static int 1334 1.2 christos check_fail_Ticket(void) 1335 1.2 christos { 1336 1.2 christos char buf[100]; 1337 1.2 christos size_t i; 1338 1.2 christos int ret; 1339 1.2 christos struct test_case test; 1340 1.2 christos Ticket ticket; 1341 1.2 christos 1342 1.2 christos for (i = 0; i < sizeof(buf); i++) { 1343 1.2 christos memset(buf, 0, sizeof(buf)); 1344 1.2 christos memset(&ticket, 0, sizeof(ticket)); 1345 1.2 christos test.val = &ticket; 1346 1.2 christos test.byte_len = i; 1347 1.2 christos test.bytes = buf; 1348 1.2 christos test.name = "zero life"; 1349 1.2 christos ret = generic_decode_fail(&test, 1, sizeof(Ticket), 1350 1.2 christos (generic_decode)decode_Ticket); 1351 1.2 christos if (ret) 1352 1.2 christos return ret; 1353 1.2 christos } 1354 1.2 christos return 0; 1355 1.2 christos } 1356 1.2 christos 1357 1.2 christos static int 1358 1.1 elric check_seq(void) 1359 1.1 elric { 1360 1.1 elric TESTSeqOf seq; 1361 1.3 christos TESTInteger i = 0; 1362 1.1 elric int ret; 1363 1.1 elric 1364 1.1 elric seq.val = NULL; 1365 1.1 elric seq.len = 0; 1366 1.1 elric 1367 1.1 elric ret = add_TESTSeqOf(&seq, &i); 1368 1.1 elric if (ret) { printf("failed adding\n"); goto out; } 1369 1.1 elric ret = add_TESTSeqOf(&seq, &i); 1370 1.1 elric if (ret) { printf("failed adding\n"); goto out; } 1371 1.1 elric ret = add_TESTSeqOf(&seq, &i); 1372 1.1 elric if (ret) { printf("failed adding\n"); goto out; } 1373 1.1 elric ret = add_TESTSeqOf(&seq, &i); 1374 1.1 elric if (ret) { printf("failed adding\n"); goto out; } 1375 1.1 elric 1376 1.1 elric ret = remove_TESTSeqOf(&seq, seq.len - 1); 1377 1.1 elric if (ret) { printf("failed removing\n"); goto out; } 1378 1.1 elric ret = remove_TESTSeqOf(&seq, 2); 1379 1.1 elric if (ret) { printf("failed removing\n"); goto out; } 1380 1.1 elric ret = remove_TESTSeqOf(&seq, 0); 1381 1.1 elric if (ret) { printf("failed removing\n"); goto out; } 1382 1.1 elric ret = remove_TESTSeqOf(&seq, 0); 1383 1.1 elric if (ret) { printf("failed removing\n"); goto out; } 1384 1.1 elric ret = remove_TESTSeqOf(&seq, 0); 1385 1.1 elric if (ret == 0) { 1386 1.1 elric printf("can remove from empty list"); 1387 1.1 elric return 1; 1388 1.1 elric } 1389 1.1 elric 1390 1.1 elric if (seq.len != 0) { 1391 1.1 elric printf("seq not empty!"); 1392 1.1 elric return 1; 1393 1.1 elric } 1394 1.1 elric free_TESTSeqOf(&seq); 1395 1.1 elric ret = 0; 1396 1.1 elric 1397 1.1 elric out: 1398 1.1 elric 1399 1.1 elric return ret; 1400 1.1 elric } 1401 1.1 elric 1402 1.1 elric #define test_seq_of(type, ok, ptr) \ 1403 1.1 elric { \ 1404 1.1 elric heim_octet_string os; \ 1405 1.1 elric size_t size; \ 1406 1.1 elric type decode; \ 1407 1.1 elric ASN1_MALLOC_ENCODE(type, os.data, os.length, ptr, &size, ret); \ 1408 1.1 elric if (ret) \ 1409 1.1 elric return ret; \ 1410 1.1 elric if (os.length != size) \ 1411 1.1 elric abort(); \ 1412 1.1 elric ret = decode_##type(os.data, os.length, &decode, &size); \ 1413 1.1 elric free(os.data); \ 1414 1.1 elric if (ret) { \ 1415 1.1 elric if (ok) \ 1416 1.1 elric return 1; \ 1417 1.1 elric } else { \ 1418 1.1 elric free_##type(&decode); \ 1419 1.1 elric if (!ok) \ 1420 1.1 elric return 1; \ 1421 1.1 elric if (size != 0) \ 1422 1.1 elric return 1; \ 1423 1.1 elric } \ 1424 1.1 elric return 0; \ 1425 1.1 elric } 1426 1.1 elric 1427 1.1 elric static int 1428 1.1 elric check_seq_of_size(void) 1429 1.1 elric { 1430 1.1 elric #if 0 /* template */ 1431 1.1 elric TESTInteger integers[4] = { 1, 2, 3, 4 }; 1432 1.1 elric int ret; 1433 1.1 elric 1434 1.1 elric { 1435 1.1 elric TESTSeqSizeOf1 ssof1f1 = { 1, integers }; 1436 1.1 elric TESTSeqSizeOf1 ssof1ok1 = { 2, integers }; 1437 1.1 elric TESTSeqSizeOf1 ssof1f2 = { 3, integers }; 1438 1.1 elric 1439 1.1 elric test_seq_of(TESTSeqSizeOf1, 0, &ssof1f1); 1440 1.1 elric test_seq_of(TESTSeqSizeOf1, 1, &ssof1ok1); 1441 1.1 elric test_seq_of(TESTSeqSizeOf1, 0, &ssof1f2); 1442 1.1 elric } 1443 1.1 elric { 1444 1.1 elric TESTSeqSizeOf2 ssof2f1 = { 0, NULL }; 1445 1.1 elric TESTSeqSizeOf2 ssof2ok1 = { 1, integers }; 1446 1.1 elric TESTSeqSizeOf2 ssof2ok2 = { 2, integers }; 1447 1.1 elric TESTSeqSizeOf2 ssof2f2 = { 3, integers }; 1448 1.1 elric 1449 1.1 elric test_seq_of(TESTSeqSizeOf2, 0, &ssof2f1); 1450 1.1 elric test_seq_of(TESTSeqSizeOf2, 1, &ssof2ok1); 1451 1.1 elric test_seq_of(TESTSeqSizeOf2, 1, &ssof2ok2); 1452 1.1 elric test_seq_of(TESTSeqSizeOf2, 0, &ssof2f2); 1453 1.1 elric } 1454 1.1 elric { 1455 1.1 elric TESTSeqSizeOf3 ssof3f1 = { 0, NULL }; 1456 1.1 elric TESTSeqSizeOf3 ssof3ok1 = { 1, integers }; 1457 1.1 elric TESTSeqSizeOf3 ssof3ok2 = { 2, integers }; 1458 1.1 elric 1459 1.1 elric test_seq_of(TESTSeqSizeOf3, 0, &ssof3f1); 1460 1.1 elric test_seq_of(TESTSeqSizeOf3, 1, &ssof3ok1); 1461 1.1 elric test_seq_of(TESTSeqSizeOf3, 1, &ssof3ok2); 1462 1.1 elric } 1463 1.1 elric { 1464 1.1 elric TESTSeqSizeOf4 ssof4ok1 = { 0, NULL }; 1465 1.1 elric TESTSeqSizeOf4 ssof4ok2 = { 1, integers }; 1466 1.1 elric TESTSeqSizeOf4 ssof4ok3 = { 2, integers }; 1467 1.1 elric TESTSeqSizeOf4 ssof4f1 = { 3, integers }; 1468 1.1 elric 1469 1.1 elric test_seq_of(TESTSeqSizeOf4, 1, &ssof4ok1); 1470 1.1 elric test_seq_of(TESTSeqSizeOf4, 1, &ssof4ok2); 1471 1.1 elric test_seq_of(TESTSeqSizeOf4, 1, &ssof4ok3); 1472 1.1 elric test_seq_of(TESTSeqSizeOf4, 0, &ssof4f1); 1473 1.1 elric } 1474 1.1 elric #endif 1475 1.1 elric return 0; 1476 1.1 elric } 1477 1.1 elric 1478 1.2 christos static int 1479 1.2 christos check_TESTMechTypeList(void) 1480 1.2 christos { 1481 1.2 christos TESTMechTypeList tl; 1482 1.2 christos unsigned oid1[] = { 1, 2, 840, 48018, 1, 2, 2}; 1483 1.2 christos unsigned oid2[] = { 1, 2, 840, 113554, 1, 2, 2}; 1484 1.2 christos unsigned oid3[] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 30}; 1485 1.2 christos unsigned oid4[] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10}; 1486 1.2 christos TESTMechType array[] = {{ 7, oid1 }, 1487 1.2 christos { 7, oid2 }, 1488 1.2 christos { 10, oid3 }, 1489 1.2 christos { 10, oid4 }}; 1490 1.2 christos size_t size, len; 1491 1.2 christos void *ptr; 1492 1.2 christos int ret; 1493 1.2 christos 1494 1.2 christos tl.len = 4; 1495 1.2 christos tl.val = array; 1496 1.2 christos 1497 1.2 christos ASN1_MALLOC_ENCODE(TESTMechTypeList, ptr, len, &tl, &size, ret); 1498 1.2 christos if (ret) 1499 1.2 christos errx(1, "TESTMechTypeList: %d", ret); 1500 1.2 christos if (len != size) 1501 1.2 christos abort(); 1502 1.2 christos return 0; 1503 1.2 christos } 1504 1.2 christos 1505 1.2 christos #ifdef IMPLICIT_TAGGING_WORKS 1506 1.2 christos static int 1507 1.2 christos cmp_TESTSeqOf4(void *a, void *b) 1508 1.2 christos { 1509 1.2 christos TESTSeqOf4 *aa = a; 1510 1.2 christos TESTSeqOf4 *ab = b; 1511 1.2 christos int i; 1512 1.2 christos 1513 1.2 christos IF_OPT_COMPARE(aa, ab, b1) { 1514 1.2 christos COMPARE_INTEGER(aa->b1, ab->b1, len); 1515 1.2 christos for (i = 0; i < aa->b1->len; ++i) { 1516 1.2 christos COMPARE_INTEGER(aa->b1->val+i, ab->b1->val+i, u1); 1517 1.2 christos COMPARE_INTEGER(aa->b1->val+i, ab->b1->val+i, u2); 1518 1.2 christos COMPARE_OCTET_STRING(aa->b1->val+i, ab->b1->val+i, s1); 1519 1.2 christos COMPARE_OCTET_STRING(aa->b1->val+i, ab->b1->val+i, s2); 1520 1.2 christos } 1521 1.2 christos } 1522 1.2 christos IF_OPT_COMPARE(aa, ab, b2) { 1523 1.2 christos COMPARE_INTEGER(aa->b2, ab->b2, len); 1524 1.2 christos for (i = 0; i < aa->b2->len; ++i) { 1525 1.2 christos COMPARE_INTEGER(aa->b2->val+i, ab->b2->val+i, u1); 1526 1.2 christos COMPARE_INTEGER(aa->b2->val+i, ab->b2->val+i, u2); 1527 1.2 christos COMPARE_INTEGER(aa->b2->val+i, ab->b2->val+i, u3); 1528 1.2 christos COMPARE_OCTET_STRING(aa->b2->val+i, ab->b2->val+i, s1); 1529 1.2 christos COMPARE_OCTET_STRING(aa->b2->val+i, ab->b2->val+i, s2); 1530 1.2 christos COMPARE_OCTET_STRING(aa->b2->val+i, ab->b2->val+i, s3); 1531 1.2 christos } 1532 1.2 christos } 1533 1.2 christos IF_OPT_COMPARE(aa, ab, b3) { 1534 1.2 christos COMPARE_INTEGER(aa->b3, ab->b3, len); 1535 1.2 christos for (i = 0; i < aa->b3->len; ++i) { 1536 1.2 christos COMPARE_INTEGER(aa->b3->val+i, ab->b3->val+i, u1); 1537 1.2 christos COMPARE_INTEGER(aa->b3->val+i, ab->b3->val+i, u2); 1538 1.2 christos COMPARE_INTEGER(aa->b3->val+i, ab->b3->val+i, u3); 1539 1.2 christos COMPARE_INTEGER(aa->b3->val+i, ab->b3->val+i, u4); 1540 1.2 christos COMPARE_OCTET_STRING(aa->b3->val+i, ab->b3->val+i, s1); 1541 1.2 christos COMPARE_OCTET_STRING(aa->b3->val+i, ab->b3->val+i, s2); 1542 1.2 christos COMPARE_OCTET_STRING(aa->b3->val+i, ab->b3->val+i, s3); 1543 1.2 christos COMPARE_OCTET_STRING(aa->b3->val+i, ab->b3->val+i, s4); 1544 1.2 christos } 1545 1.2 christos } 1546 1.2 christos return 0; 1547 1.2 christos } 1548 1.2 christos #endif /* IMPLICIT_TAGGING_WORKS */ 1549 1.2 christos 1550 1.2 christos static int 1551 1.2 christos test_seq4 (void) 1552 1.2 christos { 1553 1.2 christos int ret = 0; 1554 1.2 christos #ifdef IMPLICIT_TAGGING_WORKS 1555 1.2 christos struct test_case tests[] = { 1556 1.2 christos { NULL, 2, 1557 1.2 christos "\x30\x00", 1558 1.2 christos "seq4 0" }, 1559 1.2 christos { NULL, 4, 1560 1.2 christos "\x30\x02" "\xa1\x00", 1561 1.2 christos "seq4 1" }, 1562 1.2 christos { NULL, 8, 1563 1.2 christos "\x30\x06" "\xa0\x02\x30\x00" "\xa1\x00", 1564 1.2 christos "seq4 2" }, 1565 1.2 christos { NULL, 2 + (2 + 0x18) + (2 + 0x27) + (2 + 0x31), 1566 1.2 christos "\x30\x76" /* 2 SEQ */ 1567 1.2 christos "\xa0\x18\x30\x16" /* 4 [0] SEQ */ 1568 1.2 christos "\x30\x14" /* 2 SEQ */ 1569 1.2 christos "\x04\x00" /* 2 OCTET-STRING */ 1570 1.2 christos "\x04\x02\x01\x02" /* 4 OCTET-STRING */ 1571 1.2 christos "\x02\x01\x01" /* 3 INT */ 1572 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff" 1573 1.2 christos /* 11 INT */ 1574 1.2 christos "\xa1\x27" /* 2 [1] IMPL SEQ */ 1575 1.2 christos "\x30\x25" /* 2 SEQ */ 1576 1.2 christos "\x02\x01\x01" /* 3 INT */ 1577 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff" 1578 1.2 christos /* 11 INT */ 1579 1.2 christos "\x02\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00" 1580 1.2 christos /* 11 INT */ 1581 1.2 christos "\x04\x00" /* 2 OCTET-STRING */ 1582 1.2 christos "\x04\x02\x01\x02" /* 4 OCTET-STRING */ 1583 1.2 christos "\x04\x04\x00\x01\x02\x03" /* 6 OCTET-STRING */ 1584 1.2 christos "\xa2\x31" /* 2 [2] IMPL SEQ */ 1585 1.2 christos "\x30\x2f" /* 2 SEQ */ 1586 1.2 christos "\x04\x00" /* 2 OCTET-STRING */ 1587 1.2 christos "\x02\x01\x01" /* 3 INT */ 1588 1.2 christos "\x04\x02\x01\x02" /* 4 OCTET-STRING */ 1589 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff" 1590 1.2 christos /* 11 INT */ 1591 1.2 christos "\x04\x04\x00\x01\x02\x03" /* 6 OCTET-STRING */ 1592 1.2 christos "\x02\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00" 1593 1.2 christos /* 11 INT */ 1594 1.2 christos "\x04\x01\x00" /* 3 OCTET-STRING */ 1595 1.2 christos "\x02\x05\x01\x00\x00\x00\x00", /* 7 INT */ 1596 1.2 christos "seq4 3" }, 1597 1.2 christos }; 1598 1.2 christos 1599 1.2 christos int ntests = sizeof(tests) / sizeof(*tests); 1600 1.2 christos TESTSeqOf4 c[4]; 1601 1.2 christos struct TESTSeqOf4_b1 b1[4]; 1602 1.2 christos struct TESTSeqOf4_b2 b2[4]; 1603 1.2 christos struct TESTSeqOf4_b3 b3[4]; 1604 1.2 christos struct TESTSeqOf4_b1_val b1val[4]; 1605 1.2 christos struct TESTSeqOf4_b2_val b2val[4]; 1606 1.2 christos struct TESTSeqOf4_b3_val b3val[4]; 1607 1.2 christos 1608 1.2 christos c[0].b1 = NULL; 1609 1.2 christos c[0].b2 = NULL; 1610 1.2 christos c[0].b3 = NULL; 1611 1.2 christos tests[0].val = &c[0]; 1612 1.2 christos 1613 1.2 christos b2[1].len = 0; 1614 1.2 christos b2[1].val = NULL; 1615 1.2 christos c[1].b1 = NULL; 1616 1.2 christos c[1].b2 = &b2[1]; 1617 1.2 christos c[1].b3 = NULL; 1618 1.2 christos tests[1].val = &c[1]; 1619 1.2 christos 1620 1.2 christos b1[2].len = 0; 1621 1.2 christos b1[2].val = NULL; 1622 1.2 christos b2[2].len = 0; 1623 1.2 christos b2[2].val = NULL; 1624 1.2 christos c[2].b1 = &b1[2]; 1625 1.2 christos c[2].b2 = &b2[2]; 1626 1.2 christos c[2].b3 = NULL; 1627 1.2 christos tests[2].val = &c[2]; 1628 1.2 christos 1629 1.2 christos b1val[3].s1.data = ""; 1630 1.2 christos b1val[3].s1.length = 0; 1631 1.2 christos b1val[3].u1 = 1LL; 1632 1.2 christos b1val[3].s2.data = "\x01\x02"; 1633 1.2 christos b1val[3].s2.length = 2; 1634 1.2 christos b1val[3].u2 = -1LL; 1635 1.2 christos 1636 1.2 christos b2val[3].s1.data = ""; 1637 1.2 christos b2val[3].s1.length = 0; 1638 1.2 christos b2val[3].u1 = 1LL; 1639 1.2 christos b2val[3].s2.data = "\x01\x02"; 1640 1.2 christos b2val[3].s2.length = 2; 1641 1.2 christos b2val[3].u2 = -1LL; 1642 1.2 christos b2val[3].s3.data = "\x00\x01\x02\x03"; 1643 1.2 christos b2val[3].s3.length = 4; 1644 1.2 christos b2val[3].u3 = 1LL<<63; 1645 1.2 christos 1646 1.2 christos b3val[3].s1.data = ""; 1647 1.2 christos b3val[3].s1.length = 0; 1648 1.2 christos b3val[3].u1 = 1LL; 1649 1.2 christos b3val[3].s2.data = "\x01\x02"; 1650 1.2 christos b3val[3].s2.length = 2; 1651 1.2 christos b3val[3].u2 = -1LL; 1652 1.2 christos b3val[3].s3.data = "\x00\x01\x02\x03"; 1653 1.2 christos b3val[3].s3.length = 4; 1654 1.2 christos b3val[3].u3 = 1LL<<63; 1655 1.2 christos b3val[3].s4.data = "\x00"; 1656 1.2 christos b3val[3].s4.length = 1; 1657 1.2 christos b3val[3].u4 = 1LL<<32; 1658 1.2 christos 1659 1.2 christos b1[3].len = 1; 1660 1.2 christos b1[3].val = &b1val[3]; 1661 1.2 christos b2[3].len = 1; 1662 1.2 christos b2[3].val = &b2val[3]; 1663 1.2 christos b3[3].len = 1; 1664 1.2 christos b3[3].val = &b3val[3]; 1665 1.2 christos c[3].b1 = &b1[3]; 1666 1.2 christos c[3].b2 = &b2[3]; 1667 1.2 christos c[3].b3 = &b3[3]; 1668 1.2 christos tests[3].val = &c[3]; 1669 1.2 christos 1670 1.2 christos ret += generic_test (tests, ntests, sizeof(TESTSeqOf4), 1671 1.2 christos (generic_encode)encode_TESTSeqOf4, 1672 1.2 christos (generic_length)length_TESTSeqOf4, 1673 1.2 christos (generic_decode)decode_TESTSeqOf4, 1674 1.2 christos (generic_free)free_TESTSeqOf4, 1675 1.2 christos cmp_TESTSeqOf4, 1676 1.2 christos (generic_copy)copy_TESTSeqOf4); 1677 1.2 christos #endif /* IMPLICIT_TAGGING_WORKS */ 1678 1.2 christos return ret; 1679 1.2 christos } 1680 1.2 christos 1681 1.2 christos static int 1682 1.2 christos cmp_test_seqof5 (void *a, void *b) 1683 1.2 christos { 1684 1.2 christos TESTSeqOf5 *aval = a; 1685 1.2 christos TESTSeqOf5 *bval = b; 1686 1.2 christos 1687 1.2 christos IF_OPT_COMPARE(aval, bval, outer) { 1688 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u0); 1689 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s0); 1690 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u1); 1691 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s1); 1692 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u2); 1693 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s2); 1694 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u3); 1695 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s3); 1696 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u4); 1697 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s4); 1698 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u5); 1699 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s5); 1700 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u6); 1701 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s6); 1702 1.2 christos COMPARE_INTEGER(&aval->outer->inner, &bval->outer->inner, u7); 1703 1.2 christos COMPARE_OCTET_STRING(&aval->outer->inner, &bval->outer->inner, s7); 1704 1.2 christos } 1705 1.2 christos return 0; 1706 1.2 christos } 1707 1.2 christos 1708 1.2 christos static int 1709 1.2 christos test_seqof5(void) 1710 1.2 christos { 1711 1.2 christos struct test_case tests[] = { 1712 1.2 christos { NULL, 2, "\x30\x00", "seq5 0" }, 1713 1.2 christos { NULL, 126, 1714 1.2 christos "\x30\x7c" /* SEQ */ 1715 1.2 christos "\x30\x7a" /* SEQ */ 1716 1.2 christos "\x30\x78" /* SEQ */ 1717 1.2 christos "\x02\x01\x01" /* INT 1 */ 1718 1.2 christos "\x04\x06\x01\x01\x01\x01\x01\x01" /* "\0x1"x6 */ 1719 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfe" /* INT ~1 */ 1720 1.2 christos "\x04\x06\x02\x02\x02\x02\x02\x02" /* "\x02"x6 */ 1721 1.2 christos "\x02\x01\x02" /* INT 2 */ 1722 1.2 christos "\x04\x06\x03\x03\x03\x03\x03\x03" /* "\x03"x6 */ 1723 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfd" /* INT ~2 */ 1724 1.2 christos "\x04\x06\x04\x04\x04\x04\x04\x04" /* ... */ 1725 1.2 christos "\x02\x01\x03" 1726 1.2 christos "\x04\x06\x05\x05\x05\x05\x05\x05" 1727 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfc" 1728 1.2 christos "\x04\x06\x06\x06\x06\x06\x06\x06" 1729 1.2 christos "\x02\x01\x04" 1730 1.2 christos "\x04\x06\x07\x07\x07\x07\x07\x07" 1731 1.2 christos "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xfb" 1732 1.2 christos "\x04\x06\x08\x08\x08\x08\x08\x08", 1733 1.2 christos "seq5 1" }, 1734 1.2 christos }; 1735 1.2 christos 1736 1.2 christos int ret = 0, ntests = sizeof(tests) / sizeof(*tests); 1737 1.2 christos TESTSeqOf5 c[2]; 1738 1.2 christos struct TESTSeqOf5_outer outer; 1739 1.2 christos struct TESTSeqOf5_outer_inner inner; 1740 1.2 christos TESTuint64 u[8]; 1741 1.2 christos heim_octet_string s[8]; 1742 1.2 christos int i; 1743 1.2 christos 1744 1.2 christos c[0].outer = NULL; 1745 1.2 christos tests[0].val = &c[0]; 1746 1.2 christos 1747 1.2 christos for (i = 0; i < 8; ++i) { 1748 1.2 christos u[i] = (i&1) == 0 ? i/2+1 : ~(i/2+1); 1749 1.2 christos s[i].data = memset(malloc(s[i].length = 6), i+1, 6); 1750 1.2 christos } 1751 1.2 christos 1752 1.2 christos inner.u0 = u[0]; inner.u1 = u[1]; inner.u2 = u[2]; inner.u3 = u[3]; 1753 1.2 christos inner.u4 = u[4]; inner.u5 = u[5]; inner.u6 = u[6]; inner.u7 = u[7]; 1754 1.2 christos inner.s0 = s[0]; inner.s1 = s[1]; inner.s2 = s[2]; inner.s3 = s[3]; 1755 1.2 christos inner.s4 = s[4]; inner.s5 = s[5]; inner.s6 = s[6]; inner.s7 = s[7]; 1756 1.2 christos 1757 1.2 christos outer.inner = inner; 1758 1.2 christos c[1].outer = &outer; 1759 1.2 christos tests[1].val = &c[1]; 1760 1.2 christos 1761 1.2 christos ret += generic_test (tests, ntests, sizeof(TESTSeqOf5), 1762 1.2 christos (generic_encode)encode_TESTSeqOf5, 1763 1.2 christos (generic_length)length_TESTSeqOf5, 1764 1.2 christos (generic_decode)decode_TESTSeqOf5, 1765 1.2 christos (generic_free)free_TESTSeqOf5, 1766 1.2 christos cmp_test_seqof5, 1767 1.2 christos NULL); 1768 1.2 christos 1769 1.2 christos for (i = 0; i < 8; ++i) 1770 1.2 christos free(s[i].data); 1771 1.2 christos 1772 1.2 christos return ret; 1773 1.2 christos } 1774 1.2 christos 1775 1.1 elric int 1776 1.1 elric main(int argc, char **argv) 1777 1.1 elric { 1778 1.1 elric int ret = 0; 1779 1.1 elric 1780 1.1 elric ret += test_principal (); 1781 1.1 elric ret += test_authenticator(); 1782 1.1 elric ret += test_krb_error(); 1783 1.1 elric ret += test_Name(); 1784 1.1 elric ret += test_bit_string(); 1785 1.1 elric ret += test_bit_string_rfc1510(); 1786 1.1 elric ret += test_time(); 1787 1.1 elric ret += test_cert(); 1788 1.1 elric 1789 1.1 elric ret += check_tag_length(); 1790 1.2 christos ret += check_tag_length64(); 1791 1.2 christos ret += check_tag_length64s(); 1792 1.1 elric ret += test_large_tag(); 1793 1.1 elric ret += test_choice(); 1794 1.1 elric 1795 1.1 elric ret += test_implicit(); 1796 1.2 christos 1797 1.1 elric ret += test_taglessalloc(); 1798 1.1 elric ret += test_optional(); 1799 1.1 elric 1800 1.1 elric ret += check_fail_largetag(); 1801 1.1 elric ret += check_fail_sequence(); 1802 1.1 elric ret += check_fail_choice(); 1803 1.2 christos ret += check_fail_Ticket(); 1804 1.1 elric 1805 1.1 elric ret += check_seq(); 1806 1.1 elric ret += check_seq_of_size(); 1807 1.2 christos ret += test_SignedData(); 1808 1.2 christos 1809 1.2 christos ret += check_TESTMechTypeList(); 1810 1.2 christos ret += test_seq4(); 1811 1.2 christos ret += test_seqof5(); 1812 1.1 elric 1813 1.1 elric return ret; 1814 1.1 elric } 1815