 0f49388ac2
			
		
	
	0f49388ac2
	
	
	
		
			
			elements, don't use just the size of the last element. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@13313 ec53bebd-3082-4978-b11e-865c3cabbd6b
		
			
				
	
	
		
			299 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			299 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 1999 - 2004 Kungliga Tekniska Högskolan
 | |
|  * (Royal Institute of Technology, Stockholm, Sweden). 
 | |
|  * All rights reserved. 
 | |
|  *
 | |
|  * Redistribution and use in source and binary forms, with or without 
 | |
|  * modification, are permitted provided that the following conditions 
 | |
|  * are met: 
 | |
|  *
 | |
|  * 1. Redistributions of source code must retain the above copyright 
 | |
|  *    notice, this list of conditions and the following disclaimer. 
 | |
|  *
 | |
|  * 2. Redistributions in binary form must reproduce the above copyright 
 | |
|  *    notice, this list of conditions and the following disclaimer in the 
 | |
|  *    documentation and/or other materials provided with the distribution. 
 | |
|  *
 | |
|  * 3. Neither the name of the Institute nor the names of its contributors 
 | |
|  *    may be used to endorse or promote products derived from this software 
 | |
|  *    without specific prior written permission. 
 | |
|  *
 | |
|  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
 | |
|  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 | |
|  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 | |
|  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
 | |
|  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 | |
|  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
 | |
|  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 | |
|  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 | |
|  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 | |
|  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 | |
|  * SUCH DAMAGE. 
 | |
|  */
 | |
| 
 | |
| #ifdef HAVE_CONFIG_H
 | |
| #include <config.h>
 | |
| #endif
 | |
| #include <stdio.h>
 | |
| #include <string.h>
 | |
| #include <err.h>
 | |
| #include <roken.h>
 | |
| 
 | |
| #include <asn1-common.h>
 | |
| #include <asn1_err.h>
 | |
| #include <der.h>
 | |
| #include <krb5_asn1.h>
 | |
| 
 | |
| #include "check-common.h"
 | |
| 
 | |
| RCSID("$Id$");
 | |
| 
 | |
| static char *lha_princ[] = { "lha" };
 | |
| static char *lharoot_princ[] = { "lha", "root" };
 | |
| static char *datan_princ[] = { "host", "nutcracker.e.kth.se" };
 | |
| 
 | |
| 
 | |
| #define COMPARE_STRING(ac,bc,e) \
 | |
| 	do { if (strcmp((ac)->e, (bc)->e) != 0) return 1; } while(0)
 | |
| #define COMPARE_INTEGER(ac,bc,e) \
 | |
| 	do { if ((ac)->e != (bc)->e) return 1; } while(0)
 | |
| #define COMPARE_MEM(ac,bc,e,len) \
 | |
| 	do { if (memcmp((ac)->e, (bc)->e,len) != 0) return 1; } while(0)
 | |
| 
 | |
| static int
 | |
| cmp_principal (void *a, void *b)
 | |
| {
 | |
|     Principal *pa = a;
 | |
|     Principal *pb = b;
 | |
|     int i;
 | |
| 
 | |
|     COMPARE_STRING(pa,pb,realm);
 | |
|     COMPARE_INTEGER(pa,pb,name.name_type);
 | |
|     COMPARE_INTEGER(pa,pb,name.name_string.len);
 | |
| 
 | |
|     for (i = 0; i < pa->name.name_string.len; i++)
 | |
| 	COMPARE_STRING(pa,pb,name.name_string.val[i]);
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| static int
 | |
| test_principal (void)
 | |
| {
 | |
| 
 | |
|     struct test_case tests[] = {
 | |
| 	{ NULL, 29, 
 | |
| 	  (unsigned char*)"\x30\x1b\xa0\x10\x30\x0e\xa0\x03\x02\x01\x01\xa1\x07\x30\x05\x1b"
 | |
| 	  "\x03\x6c\x68\x61\xa1\x07\x1b\x05\x53\x55\x2e\x53\x45"
 | |
| 	},
 | |
| 	{ NULL, 35,
 | |
| 	  (unsigned char*)"\x30\x21\xa0\x16\x30\x14\xa0\x03\x02\x01\x01\xa1\x0d\x30\x0b\x1b"
 | |
| 	  "\x03\x6c\x68\x61\x1b\x04\x72\x6f\x6f\x74\xa1\x07\x1b\x05\x53\x55"
 | |
| 	  "\x2e\x53\x45"
 | |
| 	},
 | |
| 	{ NULL, 54, 
 | |
| 	  (unsigned char*)"\x30\x34\xa0\x26\x30\x24\xa0\x03\x02\x01\x03\xa1\x1d\x30\x1b\x1b"
 | |
| 	  "\x04\x68\x6f\x73\x74\x1b\x13\x6e\x75\x74\x63\x72\x61\x63\x6b\x65"
 | |
| 	  "\x72\x2e\x65\x2e\x6b\x74\x68\x2e\x73\x65\xa1\x0a\x1b\x08\x45\x2e"
 | |
| 	  "\x4b\x54\x48\x2e\x53\x45"
 | |
| 	}
 | |
|     };
 | |
| 
 | |
| 
 | |
|     Principal values[] = { 
 | |
| 	{ { KRB5_NT_PRINCIPAL, { 1, lha_princ } },  "SU.SE" },
 | |
| 	{ { KRB5_NT_PRINCIPAL, { 2, lharoot_princ } },  "SU.SE" },
 | |
| 	{ { KRB5_NT_SRV_HST, { 2, datan_princ } },  "E.KTH.SE" }
 | |
|     };
 | |
|     int i;
 | |
|     int ntests = sizeof(tests) / sizeof(*tests);
 | |
| 
 | |
|     for (i = 0; i < ntests; ++i) {
 | |
| 	tests[i].val = &values[i];
 | |
| 	asprintf (&tests[i].name, "Principal %d", i);
 | |
|     }
 | |
| 
 | |
|     return generic_test (tests, ntests, sizeof(Principal),
 | |
| 			 (generic_encode)encode_Principal,
 | |
| 			 (generic_length)length_Principal,
 | |
| 			 (generic_decode)decode_Principal,
 | |
| 			 cmp_principal);
 | |
| }
 | |
| 
 | |
| static int
 | |
| cmp_authenticator (void *a, void *b)
 | |
| {
 | |
|     Authenticator *aa = a;
 | |
|     Authenticator *ab = b;
 | |
|     int i;
 | |
| 
 | |
|     COMPARE_INTEGER(aa,ab,authenticator_vno);
 | |
|     COMPARE_STRING(aa,ab,crealm);
 | |
| 
 | |
|     COMPARE_INTEGER(aa,ab,cname.name_type);
 | |
|     COMPARE_INTEGER(aa,ab,cname.name_string.len);
 | |
| 
 | |
|     for (i = 0; i < aa->cname.name_string.len; i++)
 | |
| 	COMPARE_STRING(aa,ab,cname.name_string.val[i]);
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| static int
 | |
| test_authenticator (void)
 | |
| {
 | |
|     struct test_case tests[] = {
 | |
| 	{ NULL, 63, 
 | |
| 	  (unsigned char*)"\x62\x3d\x30\x3b\xa0\x03\x02\x01\x05\xa1\x0a\x1b\x08"
 | |
| 	  "\x45\x2e\x4b\x54\x48\x2e\x53\x45\xa2\x10\x30\x0e\xa0"
 | |
| 	  "\x03\x02\x01\x01\xa1\x07\x30\x05\x1b\x03\x6c\x68\x61"
 | |
| 	  "\xa4\x03\x02\x01\x0a\xa5\x11\x18\x0f\x31\x39\x37\x30"
 | |
| 	  "\x30\x31\x30\x31\x30\x30\x30\x31\x33\x39\x5a"
 | |
| 	},
 | |
| 	{ NULL, 67, 
 | |
| 	  (unsigned char*)"\x62\x41\x30\x3f\xa0\x03\x02\x01\x05\xa1\x07\x1b\x05"
 | |
| 	  "\x53\x55\x2e\x53\x45\xa2\x16\x30\x14\xa0\x03\x02\x01"
 | |
| 	  "\x01\xa1\x0d\x30\x0b\x1b\x03\x6c\x68\x61\x1b\x04\x72"
 | |
| 	  "\x6f\x6f\x74\xa4\x04\x02\x02\x01\x24\xa5\x11\x18\x0f"
 | |
| 	  "\x31\x39\x37\x30\x30\x31\x30\x31\x30\x30\x31\x36\x33"
 | |
| 	  "\x39\x5a"
 | |
| 	}
 | |
|     };
 | |
| 
 | |
|     Authenticator values[] = {
 | |
| 	{ 5, "E.KTH.SE", { KRB5_NT_PRINCIPAL, { 1, lha_princ } },
 | |
| 	  NULL, 10, 99, NULL, NULL, NULL },
 | |
| 	{ 5, "SU.SE", { KRB5_NT_PRINCIPAL, { 2, lharoot_princ } },
 | |
| 	  NULL, 292, 999, NULL, NULL, NULL }
 | |
|     };
 | |
|     int i;
 | |
|     int ntests = sizeof(tests) / sizeof(*tests);
 | |
| 
 | |
|     for (i = 0; i < ntests; ++i) {
 | |
| 	tests[i].val = &values[i];
 | |
| 	asprintf (&tests[i].name, "Authenticator %d", i);
 | |
|     }
 | |
| 
 | |
|     return generic_test (tests, ntests, sizeof(Authenticator),
 | |
| 			 (generic_encode)encode_Authenticator,
 | |
| 			 (generic_length)length_Authenticator,
 | |
| 			 (generic_decode)decode_Authenticator,
 | |
| 			 cmp_authenticator);
 | |
| }
 | |
| 
 | |
| static int
 | |
| cmp_AuthorizationData (void *a, void *b)
 | |
| {
 | |
|     AuthorizationData *aa = a;
 | |
|     AuthorizationData *ab = b;
 | |
| 
 | |
|     COMPARE_INTEGER(aa,ab,len);
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| static char static_buf512[512];
 | |
| 
 | |
| static int
 | |
| test_AuthorizationData (void)
 | |
| {
 | |
|     struct test_case tests[] = {
 | |
| 	{ NULL, 14, 
 | |
| 	  (unsigned char*)
 | |
| 	  "\x30\x0c\x30\x0a\xa0\x03\x02\x01\x01\xa1\x03\x04\x01\x00"
 | |
| 	},
 | |
| 	{ NULL, 142, 
 | |
| 	  (unsigned char*)
 | |
| 	  "\x30\x81\x8b\x30\x81\x88\xa0\x03\x02\x01\x01\xa1\x81\x80\x04\x7e"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	},
 | |
| 	{ NULL, 132, 
 | |
| 	  (unsigned char*)
 | |
| 	  "\x30\x81\x81\x30\x73\xa0\x03\x02\x01\x01\xa1\x6c\x04\x6a\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x30\x0a\xa0\x03\x02\x01\x01\xa1"
 | |
| 	  "\x03\x04\x01\x00"
 | |
| 	},
 | |
| 	{ NULL, 134, 
 | |
| 	  (unsigned char*)
 | |
| 	  "\x30\x81\x83\x30\x74\xa0\x03\x02\x01\x01\xa1\x6d\x04\x6b\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
 | |
| 	  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x30\x0b\xa0\x03\x02\x01\x01"
 | |
| 	  "\xa1\x04\x04\x02\x00\x00"
 | |
| 	}
 | |
|     };
 | |
| 
 | |
|     AuthorizationData values[] = {
 | |
| 	{ 1, NULL },
 | |
| 	{ 1, NULL },
 | |
| 	{ 2, NULL },
 | |
| 	{ 2, NULL }
 | |
|     };
 | |
|     int i;
 | |
|     int ntests = sizeof(tests) / sizeof(*tests);
 | |
| 
 | |
|     for (i = 0; i < ntests; ++i) {
 | |
| 	tests[i].val = &values[i];
 | |
| 	asprintf (&tests[i].name, "AuthorizationData %d", i);
 | |
| 	values[i].val = emalloc(values[i].len * sizeof(values[i].val[0]));
 | |
|     }
 | |
|     values[0].val[0].ad_type = 1;
 | |
|     values[0].val[0].ad_data.length = 1;
 | |
|     values[0].val[0].ad_data.data = static_buf512;
 | |
| 
 | |
|     values[1].val[0].ad_type = 1;
 | |
|     values[1].val[0].ad_data.length = 126;
 | |
|     values[1].val[0].ad_data.data = static_buf512;
 | |
| 
 | |
|     values[2].val[0].ad_type = 1;
 | |
|     values[2].val[0].ad_data.length = 106;
 | |
|     values[2].val[0].ad_data.data = static_buf512;
 | |
| 
 | |
|     values[2].val[1].ad_type = 1;
 | |
|     values[2].val[1].ad_data.length = 1;
 | |
|     values[2].val[1].ad_data.data = static_buf512;
 | |
| 
 | |
|     values[3].val[0].ad_type = 1;
 | |
|     values[3].val[0].ad_data.length = 107;
 | |
|     values[3].val[0].ad_data.data = static_buf512;
 | |
| 
 | |
|     values[3].val[1].ad_type = 1;
 | |
|     values[3].val[1].ad_data.length = 2;
 | |
|     values[3].val[1].ad_data.data = static_buf512;
 | |
| 
 | |
|     return generic_test (tests, ntests, sizeof(AuthorizationData),
 | |
| 			 (generic_encode)encode_AuthorizationData,
 | |
| 			 (generic_length)length_AuthorizationData,
 | |
| 			 (generic_decode)decode_AuthorizationData,
 | |
| 			 cmp_AuthorizationData);
 | |
| }
 | |
| 
 | |
| int
 | |
| main(int argc, char **argv)
 | |
| {
 | |
|     int ret = 0;
 | |
| 
 | |
|     ret += test_principal ();
 | |
|     ret += test_authenticator();
 | |
|     ret += test_AuthorizationData();
 | |
| 
 | |
|     return ret;
 | |
| }
 |