svn rev #25694: trunk/src/ lib/krb5/asn.1/ tests/asn.1/
ghudson@MIT.EDU
ghudson at MIT.EDU
Sun Feb 12 00:25:22 EST 2012
http://src.mit.edu/fisheye/changelog/krb5/?cs=25694
Commit By: ghudson
Log Message:
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.
Changed Files:
U trunk/src/lib/krb5/asn.1/asn1_k_encode.c
U trunk/src/lib/krb5/asn.1/krb5_decode.c
U trunk/src/tests/asn.1/krb5_decode_test.c
Modified: trunk/src/lib/krb5/asn.1/asn1_k_encode.c
===================================================================
--- trunk/src/lib/krb5/asn.1/asn1_k_encode.c 2012-02-11 23:25:25 UTC (rev 25693)
+++ trunk/src/lib/krb5/asn.1/asn1_k_encode.c 2012-02-12 05:25:22 UTC (rev 25694)
@@ -238,6 +238,22 @@
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_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_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
*/
Modified: trunk/src/lib/krb5/asn.1/krb5_decode.c
===================================================================
--- trunk/src/lib/krb5/asn.1/krb5_decode.c 2012-02-11 23:25:25 UTC (rev 25693)
+++ trunk/src/lib/krb5/asn.1/krb5_decode.c 2012-02-12 05:25:22 UTC (rev 25694)
@@ -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 @@
return retval;
}
#endif
-#endif
krb5_error_code KRB5_CALLCONV
krb5_decode_ticket(const krb5_data *code, krb5_ticket **repptr)
@@ -74,7 +73,6 @@
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 @@
cleanup(free);
}
-#endif
krb5_error_code KRB5_CALLCONV
krb5int_get_authdata_containee_types(krb5_context context,
@@ -841,7 +838,6 @@
assert(0); /* NOTREACHED */
}
-#if 0
#ifndef DISABLE_PKINIT
krb5_error_code
Modified: trunk/src/tests/asn.1/krb5_decode_test.c
===================================================================
--- trunk/src/tests/asn.1/krb5_decode_test.c 2012-02-11 23:25:25 UTC (rev 25693)
+++ trunk/src/tests/asn.1/krb5_decode_test.c 2012-02-12 05:25:22 UTC (rev 25694)
@@ -728,9 +728,11 @@
}
/****************************************************************/
- /* 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 @@
}
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);
}
More information about the cvs-krb5
mailing list