From 4d61972fe3ca4d81a4ed067a11ae4253998614c2 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Mon, 28 Aug 1995 21:03:13 +0000 Subject: [PATCH] krb5_decode_test.c (main): Add tests for decode_krb5_{etype_info,alt_method} krb5_encode_test.c (main): Add tests for encode_krb5_{etype_info,alt_method} ktest_equal.c (ktest_equal_krb5_alt_method, ktest_equal_krb5_etype_info_entry, ktest_equal_krb5_etype_info) New functions to test {encode,decode}_krb5_{etype_info,alt_method}. ktest.c (ktest_make_sample_etype_info_entry, ktest_make_sample_etype_info, ktest_make_sample_alt_method, ktest_destroy_etype_info_entry, ktest_destroy_etype_info): New functions to test {encode,decode}_krb5_{etype_info,alt_method}. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6607 dc483132-0cff-0310-8789-dd5450dbe970 --- src/tests/asn.1/ChangeLog | 24 +++++++-- src/tests/asn.1/krb5_decode_test.c | 73 ++++++++++++++++++++++++++++ src/tests/asn.1/krb5_encode_test.c | 39 +++++++++++++++ src/tests/asn.1/ktest.c | 72 +++++++++++++++++++++++++++ src/tests/asn.1/ktest.h | 12 ++++- src/tests/asn.1/ktest_equal.c | 33 +++++++++++++ src/tests/asn.1/ktest_equal.h | 11 ++++- src/tests/asn.1/reference_encode.out | 5 ++ src/tests/asn.1/trval_reference.out | 47 ++++++++++++++++++ 9 files changed, 310 insertions(+), 6 deletions(-) diff --git a/src/tests/asn.1/ChangeLog b/src/tests/asn.1/ChangeLog index 4dca4c1b8..7fcf5509e 100644 --- a/src/tests/asn.1/ChangeLog +++ b/src/tests/asn.1/ChangeLog @@ -1,12 +1,28 @@ +Mon Aug 28 16:35:22 1995 + + * krb5_decode_test.c (main): Add tests for + decode_krb5_{etype_info,alt_method}. + + * krb5_encode_test.c (main): Add tests for + encode_krb5_{etype_info,alt_method}. + + * ktest_equal.c (ktest_equal_krb5_alt_method, + ktest_equal_krb5_etype_info_entry, + ktest_equal_krb5_etype_info) New functions to test + {encode,decode}_krb5_{etype_info,alt_method}. + + * ktest.c (ktest_make_sample_etype_info_entry, + ktest_make_sample_etype_info, + ktest_make_sample_alt_method, + ktest_destroy_etype_info_entry, ktest_destroy_etype_info): + New functions to test + {encode,decode}_krb5_{etype_info,alt_method}. + Sat Aug 26 12:40:57 1995 Ezra Peisach * krb5_encode_test.c (encoder_print_results): If trval2 returns non zero, indicate with error before exiting. - * trval.c (do_cons): Initialize return value to zero in case of - zero length data. (instead of random stack value). - - Fri Aug 25 21:50:37 1995 Theodore Y. Ts'o * krb5_encode_test.c (main): Add tests for diff --git a/src/tests/asn.1/krb5_decode_test.c b/src/tests/asn.1/krb5_decode_test.c index 266683bc6..3120b04b2 100644 --- a/src/tests/asn.1/krb5_decode_test.c +++ b/src/tests/asn.1/krb5_decode_test.c @@ -390,5 +390,78 @@ void main() assert(ktest_equal_sequence_of_pa_data(ref,var),"pa_data (empty)\n") } + /****************************************************************/ + /* decode_pwd_sequence */ + { + setup(krb5_alt_method,"krb5_alt_method",ktest_make_sample_alt_method); + decode_run("alt_method","","30 0F A0 03 02 01 2A A1 08 04 06 73 65 +63 72 65 74",decode_krb5_alt_method,ktest_equal_krb5_alt_method); + ref.length = 0; + decode_run("alt_method (no data)","","30 05 A0 03 02 01 2A",decode_krb5_alt_method,ktest_equal_krb5_alt_method); + + } + + /****************************************************************/ + /* decode_etype_info */ + { + krb5_etype_info ref, var; + + retval = ktest_make_sample_etype_info(&ref); + if (retval) { + com_err("krb5_decode_test", retval, + "while making sample etype info"); + exit(1); + } + retval = krb5_data_hex_parse(&code,"30 33 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 30 05 A0 03 02 01 01 30 14 A0 03 02 01 02 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 32"); + if(retval){ + com_err("krb5_decode_test", retval, "while parsing etype_info"); + exit(1); + } + retval = decode_krb5_etype_info(&code,&var); + if(retval){ + com_err("krb5_decode_test", retval, "while decoding etype_info"); + } + assert(ktest_equal_etype_info(ref,var),"etype_info\n"); + + ktest_destroy_etype_info(var); + ktest_destroy_etype_info_entry(ref[2]); ref[2] = 0; + ktest_destroy_etype_info_entry(ref[1]); ref[1] = 0; + + retval = krb5_data_hex_parse(&code,"30 16 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30"); + if(retval){ + com_err("krb5_decode_test", retval, + "while parsing etype_info (only one)"); + exit(1); + } + retval = decode_krb5_etype_info(&code,&var); + if(retval){ + com_err("krb5_decode_test", retval, + "while decoding etype_info (only one)"); + } + assert(ktest_equal_etype_info(ref,var),"etype_info (only one)\n"); + + ktest_destroy_etype_info(var); + ktest_destroy_etype_info_entry(ref[0]); ref[0] = 0; + + retval = krb5_data_hex_parse(&code,"30 00"); + if(retval){ + com_err("krb5_decode_test", retval, + "while parsing etype_info (no info)"); + exit(1); + } + retval = decode_krb5_etype_info(&code,&var); + if(retval){ + com_err("krb5_decode_test", retval, + "while decoding etype_info (no info)"); + } + assert(ktest_equal_etype_info(ref,var),"etype_info (no info)\n"); + + ktest_destroy_etype_info(var); + ktest_destroy_etype_info(ref); + } + + exit(error_count); } + + diff --git a/src/tests/asn.1/krb5_encode_test.c b/src/tests/asn.1/krb5_encode_test.c index 6adebbd82..9262a5742 100644 --- a/src/tests/asn.1/krb5_encode_test.c +++ b/src/tests/asn.1/krb5_encode_test.c @@ -459,5 +459,44 @@ void main(argc, argv) encoder_print_results(code, "padata_sequence(empty)", ""); } + /****************************************************************/ + /* encode_alt_method */ + { + krb5_alt_method am; + setup(am,krb5_alt_method,"AltMethod",ktest_make_sample_alt_method); + encode_run(am,krb5_alt_method,"alt_method","",encode_krb5_alt_method); + am.length = 0; + am.data = 0; + encode_run(am,krb5_alt_method,"alt_method (no data)","", + encode_krb5_alt_method); + } + + /****************************************************************/ + /* encode_etype_info */ + { + krb5_etype_info_entry **info; + + setup(info,krb5_etype_info_entry **,"etype_info", + ktest_make_sample_etype_info); + retval = encode_krb5_etype_info((const krb5_etype_info_entry **)info,&(code)); + if(retval) com_err("encoding etype_info",retval,""); + encoder_print_results(code, "etype_info", ""); + ktest_destroy_etype_info_entry(info[2]); info[2] = 0; + ktest_destroy_etype_info_entry(info[1]); info[1] = 0; + + retval = encode_krb5_etype_info((const krb5_etype_info_entry **)info,&(code)); + if(retval) com_err("encoding etype_info (only 1)",retval,""); + encoder_print_results(code, "etype_info (only 1)", ""); + + ktest_destroy_etype_info_entry(info[0]); info[0] = 0; + + retval = encode_krb5_etype_info((const krb5_etype_info_entry **)info,&(code)); + if(retval) com_err("encoding etype_info (no info)",retval,""); + encoder_print_results(code, "etype_info (no info)", ""); + + free(info); + } exit(error_count); } + + diff --git a/src/tests/asn.1/ktest.c b/src/tests/asn.1/ktest.c index 4951e15d3..2a01cb353 100644 --- a/src/tests/asn.1/ktest.c +++ b/src/tests/asn.1/ktest.c @@ -637,6 +637,58 @@ krb5_error_code ktest_make_sample_krb5_pwd_data(pd) return 0; } +krb5_error_code ktest_make_sample_alt_method(p) + krb5_alt_method * p; +{ + p->method = 42; + p->data = "secret"; + p->length = strlen(p->data); + return 0; +} + +krb5_error_code ktest_make_sample_etype_info_entry(p) + krb5_etype_info_entry * p; +{ + p->etype = 1; + p->salt = "Morton"; + p->length = strlen(p->salt); + return 0; +} + +krb5_error_code ktest_make_sample_etype_info(p) + krb5_etype_info_entry *** p; +{ + krb5_etype_info_entry **info; + int i; + char buf[80]; + + info = malloc(sizeof(krb5_etype_info_entry *) * 4); + if (!info) + return ENOMEM; + memset(info, 0, sizeof(krb5_etype_info_entry *) * 4); + + for (i=0; i < 3; i++) { + info[i] = malloc(sizeof(krb5_etype_info_entry)); + if (info[i] == 0) + goto memfail; + info[i]->etype = i; + sprintf(buf, "Morton's #%d", i); + info[i]->length = strlen(buf); + info[i]->salt = malloc(info[i]->length+1); + if (info[i]->salt == 0) + goto memfail; + strcpy(info[i]->salt, buf); + info[i]->magic = KV5M_ETYPE_INFO_ENTRY; + } + free(info[1]->salt); + info[1]->length = 0; + info[1]->salt = 0; + *p = info; + return 0; +memfail: + ktest_destroy_etype_info(info); + return ENOMEM; +} /****************************************************************/ /* destructors */ @@ -814,3 +866,23 @@ void ktest_destroy_enc_data(ed) ktest_empty_data(&(ed->ciphertext)); ed->kvno = 0; } + +void ktest_destroy_etype_info_entry(i) + krb5_etype_info_entry *i; +{ + if (i->salt) + free(i->salt); + free(i); +} + +void ktest_destroy_etype_info(info) + krb5_etype_info_entry **info; +{ + int i; + + for(i=0; info[i] != NULL; i++) + ktest_destroy_etype_info_entry(info[i]); + free(info); +} + + diff --git a/src/tests/asn.1/ktest.h b/src/tests/asn.1/ktest.h index 752a5f834..6d087b2d5 100644 --- a/src/tests/asn.1/ktest.h +++ b/src/tests/asn.1/ktest.h @@ -1,7 +1,7 @@ #ifndef __KTEST_H__ #define __KTEST_H__ -#include "krb5.h" +#include "k5-int.h" #define SAMPLE_USEC 123456 #define SAMPLE_TIME 771228197 /* Fri Jun 10 6:03:17 GMT 1994 */ @@ -84,6 +84,11 @@ krb5_error_code ktest_make_sample_passwd_phrase_element KRB5_PROTOTYPE((passwd_phrase_element *ppe)); krb5_error_code ktest_make_sample_krb5_pwd_data KRB5_PROTOTYPE((krb5_pwd_data *pd)); +krb5_error_code ktest_make_sample_alt_method + KRB5_PROTOTYPE((krb5_alt_method *am)); + +krb5_error_code ktest_make_sample_etype_info + KRB5_PROTOTYPE((krb5_etype_info_entry *** p)); /*----------------------------------------------------------------------*/ @@ -129,4 +134,9 @@ void ktest_destroy_sequence_of_ticket void ktest_destroy_enc_data KRB5_PROTOTYPE((krb5_enc_data *ed)); +void ktest_destroy_etype_info_entry + KRB5_PROTOTYPE((krb5_etype_info_entry *i)); +void ktest_destroy_etype_info + KRB5_PROTOTYPE((krb5_etype_info_entry **info)); + #endif diff --git a/src/tests/asn.1/ktest_equal.c b/src/tests/asn.1/ktest_equal.c index cfa6eb07d..c9cf32941 100644 --- a/src/tests/asn.1/ktest_equal.c +++ b/src/tests/asn.1/ktest_equal.c @@ -465,6 +465,32 @@ int ktest_equal_krb5_pwd_data(ref, var) return p; } +int ktest_equal_krb5_alt_method(ref, var) + krb5_alt_method *ref; + krb5_alt_method *var; +{ + if (ref->method != var->method) + return FALSE; + if (ref->length != var->length) + return FALSE; + if (memcmp(ref->data, var->data, ref->length) != 0) + return FALSE; + return TRUE; +} + +int ktest_equal_krb5_etype_info_entry(ref, var) + krb5_etype_info_entry *ref; + krb5_etype_info_entry *var; +{ + if (ref->etype != var->etype) + return FALSE; + if (ref->length != var->length) + return FALSE; + if (memcmp(ref->salt, var->salt, ref->length) != 0) + return FALSE; + return TRUE; +} + /**** arrays ****************************************************************/ int ktest_equal_array_of_data(length, ref, var) @@ -583,3 +609,10 @@ int ktest_equal_array_of_passwd_phrase_element(ref, var) { array_compare(ktest_equal_passwd_phrase_element); } + +int ktest_equal_etype_info(ref, var) + krb5_etype_info_entry ** ref; + krb5_etype_info_entry ** var; +{ + array_compare(ktest_equal_krb5_etype_info_entry); +} diff --git a/src/tests/asn.1/ktest_equal.h b/src/tests/asn.1/ktest_equal.h index a88d56555..375cc546d 100644 --- a/src/tests/asn.1/ktest_equal.h +++ b/src/tests/asn.1/ktest_equal.h @@ -1,7 +1,7 @@ #ifndef __KTEST_EQUAL_H__ #define __KTEST_EQUAL_H__ -#include "krb5.h" +#include "k5-int.h" /* int ktest_equal_structure(krb5_structure *ref, *var) */ /* effects Returns true (non-zero) if ref and var are @@ -52,6 +52,7 @@ generic(ktest_equal_encryption_key,krb5_keyblock); generic(ktest_equal_passwd_phrase_element,passwd_phrase_element); generic(ktest_equal_krb5_pwd_data,krb5_pwd_data); +generic(ktest_equal_krb5_alt_method,krb5_alt_method); int ktest_equal_last_req KRB5_PROTOTYPE((krb5_last_req_entry **ref, krb5_last_req_entry **var)); @@ -75,4 +76,12 @@ int ktest_equal_addresses int ktest_equal_array_of_char KRB5_PROTOTYPE((const int length, char *ref, char *var)); +int ktest_equal_etype_info + KRB5_PROTOTYPE((krb5_etype_info_entry ** ref, + krb5_etype_info_entry ** var)); + +int ktest_equal_etype_info_entry + KRB5_PROTOTYPE((krb5_etype_info_entry * ref, + krb5_etype_info_entry * var)); + #endif diff --git a/src/tests/asn.1/reference_encode.out b/src/tests/asn.1/reference_encode.out index 8022948fd..5778aeef1 100644 --- a/src/tests/asn.1/reference_encode.out +++ b/src/tests/asn.1/reference_encode.out @@ -39,3 +39,8 @@ encode_krb5_pwd_sequence: 30 18 A0 0A 04 08 6B 72 62 35 64 61 74 61 A1 0A 04 08 encode_krb5_pwd_data: 30 3D A0 03 02 01 02 A1 36 30 34 30 18 A0 0A 04 08 6B 72 62 35 64 61 74 61 A1 0A 04 08 6B 72 62 35 64 61 74 61 30 18 A0 0A 04 08 6B 72 62 35 64 61 74 61 A1 0A 04 08 6B 72 62 35 64 61 74 61 encode_krb5_padata_sequence: 30 24 30 10 A1 03 02 01 0D A2 09 04 07 70 61 2D 64 61 74 61 30 10 A1 03 02 01 0D A2 09 04 07 70 61 2D 64 61 74 61 encode_krb5_padata_sequence(empty): 30 00 +encode_krb5_alt_method: 30 0F A0 03 02 01 2A A1 08 04 06 73 65 63 72 65 74 +encode_krb5_alt_method (no data): 30 05 A0 03 02 01 2A +encode_krb5_etype_info: 30 33 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 30 05 A0 03 02 01 01 30 14 A0 03 02 01 02 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 32 +encode_krb5_etype_info (only 1): 30 16 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 +encode_krb5_etype_info (no info): 30 00 diff --git a/src/tests/asn.1/trval_reference.out b/src/tests/asn.1/trval_reference.out index 8fa2b7e7e..85dcd61f8 100644 --- a/src/tests/asn.1/trval_reference.out +++ b/src/tests/asn.1/trval_reference.out @@ -1837,3 +1837,50 @@ encode_krb5_padata_sequence(empty): [Sequence/Sequence Of] +encode_krb5_alt_method: + +[Sequence/Sequence Of] +. [0] [Integer] <1> + 2a * +. [1] [Octet String] <6> + 73 65 63 72 65 74 secret + +encode_krb5_alt_method (no data): + +[Sequence/Sequence Of] +. [0] [Integer] <1> + 2a * + +encode_krb5_etype_info: + +[Sequence/Sequence Of] +. [Sequence/Sequence Of] +. . [0] [Integer] <1> + 00 . +. . [1] [Octet String] <11> + 4d 6f 72 74 6f 6e 27 73 Morton's + 20 23 30 #0 +. [Sequence/Sequence Of] +. . [0] [Integer] <1> + 01 . +. [Sequence/Sequence Of] +. . [0] [Integer] <1> + 02 . +. . [1] [Octet String] <11> + 4d 6f 72 74 6f 6e 27 73 Morton's + 20 23 32 #2 + +encode_krb5_etype_info (only 1): + +[Sequence/Sequence Of] +. [Sequence/Sequence Of] +. . [0] [Integer] <1> + 00 . +. . [1] [Octet String] <11> + 4d 6f 72 74 6f 6e 27 73 Morton's + 20 23 30 #0 + +encode_krb5_etype_info (no info): + +[Sequence/Sequence Of] + -- 2.26.2