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