From: Greg Hudson Date: Sun, 12 Feb 2012 05:25:22 +0000 (+0000) Subject: Convert utility functions to new decoder X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0d975e2701abe3fbcd1bec213fdadc4e09b2b636;p=krb5.git Convert utility functions to new decoder Create a special type to plug authdata types from authdata and make krb5int_get_authdata_containee_types use it. Add a test case for it as well. Move krb5_decode_ticket (a trivial wrapper) into asn1_k_encode.c so that krb5_decode.c is empty. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25694 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/asn1_k_encode.c b/src/lib/krb5/asn.1/asn1_k_encode.c index 6be95f580..a48db98d0 100644 --- a/src/lib/krb5/asn.1/asn1_k_encode.c +++ b/src/lib/krb5/asn.1/asn1_k_encode.c @@ -238,6 +238,22 @@ DEFNONEMPTYNULLTERMSEQOFTYPE(auth_data, authdata_elt_ptr); DEFPTRTYPE(auth_data_ptr, auth_data); DEFOPTIONALEMPTYTYPE(opt_auth_data_ptr, auth_data_ptr); +/* authdata_types retrieves just the types of authdata elements in an array. */ +DEFCTAGGEDTYPE(authdata_elt_type_0, 0, int32); +static const struct atype_info *authdata_elt_type_fields[] = { + &k5_atype_authdata_elt_type_0 +}; +DEFSEQTYPE(authdata_elt_type, krb5_authdatatype, authdata_elt_type_fields); +DEFPTRTYPE(ptr_authdata_elt_type, authdata_elt_type); +DEFCOUNTEDSEQOFTYPE(cseqof_authdata_elt_type, unsigned int, + ptr_authdata_elt_type); +struct authdata_types { + krb5_authdatatype *types; + unsigned int ntypes; +}; +DEFCOUNTEDTYPE(authdata_types, struct authdata_types, types, ntypes, + cseqof_authdata_elt_type); + DEFFIELD(keyblock_0, krb5_keyblock, enctype, 0, int32); DEFCNFIELD(keyblock_1, krb5_keyblock, contents, length, 1, octetstring); static const struct atype_info *encryption_key_fields[] = { @@ -1106,6 +1122,12 @@ MAKE_CODEC(krb5_ticket, ticket); MAKE_CODEC(krb5_encryption_key, encryption_key); MAKE_CODEC(krb5_enc_tkt_part, enc_tkt_part); +krb5_error_code KRB5_CALLCONV +krb5_decode_ticket(const krb5_data *code, krb5_ticket **repptr) +{ + return decode_krb5_ticket(code, repptr); +} + /* * For backwards compatibility, we encode both EncASRepPart and EncTGSRepPart * with application tag 26. On decode, we accept either app tag and set the @@ -1251,6 +1273,27 @@ MAKE_CODEC(krb5_ad_signedpath, ad_signedpath); MAKE_CODEC(krb5_iakerb_header, iakerb_header); MAKE_CODEC(krb5_iakerb_finished, iakerb_finished); +krb5_error_code KRB5_CALLCONV +krb5int_get_authdata_containee_types(krb5_context context, + const krb5_authdata *authdata, + unsigned int *num_out, + krb5_authdatatype **types_out) +{ + asn1_error_code ret; + struct authdata_types *atypes; + void *atypes_ptr; + krb5_data d = make_data(authdata->contents, authdata->length); + + ret = k5_asn1_full_decode(&d, &k5_atype_authdata_types, &atypes_ptr); + if (ret) + return ret; + atypes = atypes_ptr; + *num_out = atypes->ntypes; + *types_out = atypes->types; + free(atypes); + return 0; +} + /* * PKINIT */ diff --git a/src/lib/krb5/asn.1/krb5_decode.c b/src/lib/krb5/asn.1/krb5_decode.c index 69d77c165..2a665f215 100644 --- a/src/lib/krb5/asn.1/krb5_decode.c +++ b/src/lib/krb5/asn.1/krb5_decode.c @@ -31,8 +31,8 @@ #include "asn1_get.h" #include "krb5_decode_macros.h" -#ifndef LEAN_CLIENT #if 0 +#ifndef LEAN_CLIENT krb5_error_code decode_krb5_authenticator(const krb5_data *code, krb5_authenticator **repptr) { @@ -66,7 +66,6 @@ error_out: return retval; } #endif -#endif krb5_error_code KRB5_CALLCONV krb5_decode_ticket(const krb5_data *code, krb5_ticket **repptr) @@ -74,7 +73,6 @@ krb5_decode_ticket(const krb5_data *code, krb5_ticket **repptr) return decode_krb5_ticket(code, repptr); } -#if 0 krb5_error_code decode_krb5_ticket(const krb5_data *code, krb5_ticket **repptr) { @@ -815,7 +813,6 @@ decode_krb5_iakerb_finished(const krb5_data *code, krb5_iakerb_finished **repptr cleanup(free); } -#endif krb5_error_code KRB5_CALLCONV krb5int_get_authdata_containee_types(krb5_context context, @@ -841,7 +838,6 @@ krb5int_get_authdata_containee_types(krb5_context context, assert(0); /* NOTREACHED */ } -#if 0 #ifndef DISABLE_PKINIT krb5_error_code diff --git a/src/tests/asn.1/krb5_decode_test.c b/src/tests/asn.1/krb5_decode_test.c index eb0fc8dbb..7e1f6feae 100644 --- a/src/tests/asn.1/krb5_decode_test.c +++ b/src/tests/asn.1/krb5_decode_test.c @@ -728,9 +728,11 @@ int main(argc, argv) } /****************************************************************/ - /* decode_krb5_authdata */ + /* decode_krb5_authdata and krb5int_get_authdata_containee_types */ { - krb5_authdata **ref, **var; + krb5_authdata **ref, **var, tmp; + unsigned int count; + krb5_authdatatype *types = NULL; ktest_make_sample_authorization_data(&ref); retval = krb5_data_hex_parse(&code,"30 22 30 0F A0 03 02 01 01 A1 08 04 06 66 6F 6F 62 61 72 30 0F A0 03 02 01 01 A1 08 04 06 66 6F 6F 62 61 72"); if (retval) { @@ -739,8 +741,16 @@ int main(argc, argv) } retval = decode_krb5_authdata(&code,&var); if (retval) com_err("decoding authorization_data",retval,""); - test(ktest_equal_authorization_data(ref,var),"authorization_data\n") - krb5_free_data_contents(test_context, &code); + test(ktest_equal_authorization_data(ref,var),"authorization_data\n"); + tmp.length = code.length; + tmp.contents = (krb5_octet *)code.data; + retval = krb5int_get_authdata_containee_types(test_context, &tmp, + &count, &types); + if (retval) com_err("reading authdata types",retval,""); + test(count == 2 && types[0] == 1 && types[1] == 1, + "authorization_data(types only)\n"); + free(types); + krb5_free_data_contents(test_context, &code); krb5_free_authdata(test_context, var); ktest_destroy_authorization_data(&ref); }