From 887c33561e4731da0238c14420a277f0609680c9 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sat, 25 Oct 2008 05:58:13 +0000 Subject: [PATCH] More regression tests for ASN.1 encoders Export encode_krb5_sam_response_2 and encode_krb5_enc_sam_response_enc_2 via accessor. Add encode tests for encode_krb5_sam_key, _enc_sam_response_enc, _predicted_sam_response, _sam_response_2, _enc_sam_response_enc_2. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20922 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/k5-int.h | 5 ++ src/lib/krb5/os/accessor.c | 3 + src/tests/asn.1/krb5_encode_test.c | 24 +++++++- src/tests/asn.1/ktest.c | 84 ++++++++++++++++++++++++++++ src/tests/asn.1/ktest.h | 13 +++++ src/tests/asn.1/reference_encode.out | 5 ++ src/tests/asn.1/trval_reference.out | 50 +++++++++++++++++ 7 files changed, 182 insertions(+), 2 deletions(-) diff --git a/src/include/k5-int.h b/src/include/k5-int.h index cbc810e77..bd038db50 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -1941,6 +1941,11 @@ typedef struct _krb5int_access { krb5_error_code (*encode_krb5_authdata_elt) (const krb5_authdata *rep, krb5_data **code); + /* Exported for testing only! */ + krb5_error_code (*encode_krb5_sam_response_2) + (const krb5_sam_response_2 *rep, krb5_data **code); + krb5_error_code (*encode_krb5_enc_sam_response_enc_2) + (const krb5_enc_sam_response_enc_2 *rep, krb5_data **code); } krb5int_access; #define KRB5INT_ACCESS_VERSION \ diff --git a/src/lib/krb5/os/accessor.c b/src/lib/krb5/os/accessor.c index 1593468cd..5a4e9557a 100644 --- a/src/lib/krb5/os/accessor.c +++ b/src/lib/krb5/os/accessor.c @@ -134,6 +134,9 @@ krb5int_accessor(krb5int_access *internals, krb5_int32 version) SC (encode_krb5_authdata_elt, encode_krb5_authdata_elt), #undef SC + S (encode_krb5_sam_response_2, encode_krb5_sam_response_2), + S (encode_krb5_enc_sam_response_enc_2, encode_krb5_enc_sam_response_enc_2), + #if DESIGNATED_INITIALIZERS }; #else diff --git a/src/tests/asn.1/krb5_encode_test.c b/src/tests/asn.1/krb5_encode_test.c index 3f8e34492..c6dab46c2 100644 --- a/src/tests/asn.1/krb5_encode_test.c +++ b/src/tests/asn.1/krb5_encode_test.c @@ -644,7 +644,6 @@ main(argc, argv) encode_krb5_sam_response); ktest_empty_sam_response(&sam_ch); } -#if 0 /****************************************************************/ /* encode_krb5_sam_key */ { @@ -653,6 +652,7 @@ main(argc, argv) ktest_make_sample_sam_key); encode_run(sam_ch,krb5_sam_key,"sam_key","", encode_krb5_sam_key); + ktest_empty_sam_key(&sam_ch); } /****************************************************************/ /* encode_krb5_enc_sam_response_enc */ @@ -672,7 +672,27 @@ main(argc, argv) encode_run(sam_ch,krb5_predicted_sam_response,"predicted_sam_response","", encode_krb5_predicted_sam_response); } -#endif + /****************************************************************/ + /* encode_krb5_sam_response_2 */ + { + krb5_sam_response_2 sam_ch2; + setup(sam_ch2,krb5_sam_response_2,"sam_response_2", + ktest_make_sample_sam_response_2); + encode_run(sam_ch2,krb5_sam_response_2,"sam_response_2","", + acc.encode_krb5_sam_response_2); + ktest_empty_sam_response_2(&sam_ch2); + } + /****************************************************************/ + /* encode_krb5_sam_response_enc_2 */ + { + krb5_enc_sam_response_enc_2 sam_ch2; + setup(sam_ch2,krb5_enc_sam_response_enc_2,"enc_sam_response_enc_2", + ktest_make_sample_enc_sam_response_enc_2); + encode_run(sam_ch2,krb5_enc_sam_response_enc_2, + "enc_sam_response_enc_2","", + acc.encode_krb5_enc_sam_response_enc_2); + ktest_empty_enc_sam_response_enc_2(&sam_ch2); + } #ifdef ENABLE_LDAP { ldap_seqof_key_data skd; diff --git a/src/tests/asn.1/ktest.c b/src/tests/asn.1/ktest.c index d1ba257fc..76120744a 100644 --- a/src/tests/asn.1/ktest.c +++ b/src/tests/asn.1/ktest.c @@ -776,6 +776,56 @@ krb5_error_code ktest_make_sample_sam_response(p) return 0; } +krb5_error_code ktest_make_sample_sam_response_2(p) + krb5_sam_response_2 * p; +{ + p->magic = KV5M_SAM_RESPONSE; + p->sam_type = 43; /* information */ + p->sam_flags = KRB5_SAM_USE_SAD_AS_KEY; /* KRB5_SAM_* values */ + p->sam_track_id.data = strdup("track data"); + if (p->sam_track_id.data == NULL) return ENOMEM; + p->sam_track_id.length = strlen(p->sam_track_id.data); + p->sam_enc_nonce_or_sad.ciphertext.data = strdup("nonce or sad"); + if (p->sam_enc_nonce_or_sad.ciphertext.data == NULL) return ENOMEM; + p->sam_enc_nonce_or_sad.ciphertext.length = + strlen(p->sam_enc_nonce_or_sad.ciphertext.data); + p->sam_enc_nonce_or_sad.enctype = ENCTYPE_DES_CBC_CRC; + p->sam_enc_nonce_or_sad.kvno = 3382; + p->sam_nonce = 0x543210; + + return 0; +} + +krb5_error_code ktest_make_sample_sam_key(p) + krb5_sam_key *p; +{ + p->magic = 99; + return ktest_make_sample_keyblock(&p->sam_key); +} + +krb5_error_code ktest_make_sample_enc_sam_response_enc(p) + krb5_enc_sam_response_enc *p; +{ + p->magic = 78; + p->sam_nonce = 78634; + p->sam_timestamp = 99999; + p->sam_usec = 399; + p->sam_sad.data = strdup("enc_sam_response_enc"); + if (p->sam_sad.data == NULL) return ENOMEM; + p->sam_sad.length = strlen(p->sam_sad.data); + return 0; +} + +krb5_error_code ktest_make_sample_enc_sam_response_enc_2(p) + krb5_enc_sam_response_enc_2 *p; +{ + p->magic = 83; + p->sam_nonce = 88; + p->sam_sad.data = strdup("enc_sam_response_enc_2"); + if (p->sam_sad.data == NULL) return ENOMEM; + p->sam_sad.length = strlen(p->sam_sad.data); + return 0; +} #ifdef ENABLE_LDAP static krb5_error_code ktest_make_sample_key_data(krb5_key_data *p, int i) @@ -812,6 +862,24 @@ krb5_error_code ktest_make_sample_ldap_seqof_key_data(p) } #endif +krb5_error_code ktest_make_sample_predicted_sam_response(p) + krb5_predicted_sam_response *p; +{ + krb5_error_code retval; + + p->magic = 79; + retval = ktest_make_sample_keyblock(&p->sam_key); + if (retval) return retval; + p->sam_flags = 9; + p->stime = 17; + p->susec = 18; + retval = ktest_make_sample_principal(&p->client); + if (retval) return retval; + retval = krb5_data_parse(&p->msd, "hello"); + if (retval) return retval; + return 0; +} + /****************************************************************/ /* destructors */ @@ -1320,6 +1388,22 @@ void ktest_empty_sam_response(p) ktest_empty_data(&(p->sam_enc_nonce_or_ts.ciphertext)); } +void ktest_empty_sam_key(p) + krb5_sam_key *p; +{ + if (p->sam_key.contents) + free(p->sam_key.contents); +} + +void ktest_empty_sam_response_2(p) + krb5_sam_response_2 *p; +{ +} +void ktest_empty_enc_sam_response_enc_2(p) + krb5_enc_sam_response_enc_2 *p; +{ +} + #ifdef ENABLE_LDAP void ktest_empty_ldap_seqof_key_data(ctx, p) krb5_context ctx; diff --git a/src/tests/asn.1/ktest.h b/src/tests/asn.1/ktest.h index 5173260bd..b69481fc5 100644 --- a/src/tests/asn.1/ktest.h +++ b/src/tests/asn.1/ktest.h @@ -98,6 +98,15 @@ krb5_error_code ktest_make_sample_sam_challenge (krb5_sam_challenge * p); krb5_error_code ktest_make_sample_sam_response (krb5_sam_response * p); +krb5_error_code ktest_make_sample_sam_response_2 + (krb5_sam_response_2 * p); +krb5_error_code ktest_make_sample_sam_key(krb5_sam_key *p); +krb5_error_code ktest_make_sample_enc_sam_response_enc + (krb5_enc_sam_response_enc *p); +krb5_error_code ktest_make_sample_predicted_sam_response(krb5_predicted_sam_response *p); +krb5_error_code ktest_make_sample_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 *p); + + #ifdef ENABLE_LDAP krb5_error_code ktest_make_sample_ldap_seqof_key_data(ldap_seqof_key_data * p); #endif @@ -200,6 +209,10 @@ void ktest_empty_sam_challenge (krb5_sam_challenge * p); void ktest_empty_sam_response (krb5_sam_response * p); +void ktest_empty_sam_key(krb5_sam_key *p); +void ktest_empty_sam_response_2(krb5_sam_response_2 *p); +void ktest_empty_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 *p); + #ifdef ENABLE_LDAP void ktest_empty_ldap_seqof_key_data(krb5_context, ldap_seqof_key_data *p); #endif diff --git a/src/tests/asn.1/reference_encode.out b/src/tests/asn.1/reference_encode.out index a118c050d..b6ac7fb2d 100644 --- a/src/tests/asn.1/reference_encode.out +++ b/src/tests/asn.1/reference_encode.out @@ -51,3 +51,8 @@ encode_krb5_pa_enc_ts (no usec): 30 13 A0 11 18 0F 31 39 39 34 30 36 31 30 30 36 encode_krb5_enc_data: 30 23 A0 03 02 01 00 A1 03 02 01 05 A2 17 04 15 6B 72 62 41 53 4E 2E 31 20 74 65 73 74 20 6D 65 73 73 61 67 65 encode_krb5_sam_challenge: 30 70 A0 03 02 01 2A A1 07 03 05 00 80 00 00 00 A2 0B 04 09 74 79 70 65 20 6E 61 6D 65 A4 11 04 0F 63 68 61 6C 6C 65 6E 67 65 20 6C 61 62 65 6C A5 10 04 0E 63 68 61 6C 6C 65 6E 67 65 20 69 70 73 65 A6 16 04 14 72 65 73 70 6F 6E 73 65 5F 70 72 6F 6D 70 74 20 69 70 73 65 A8 05 02 03 54 32 10 A9 0F 30 0D A0 03 02 01 01 A1 06 04 04 31 32 33 34 encode_krb5_sam_response: 30 6A A0 03 02 01 2A A1 07 03 05 00 80 00 00 00 A2 0C 04 0A 74 72 61 63 6B 20 64 61 74 61 A3 14 30 12 A0 03 02 01 01 A1 04 02 02 07 96 A2 05 04 03 6B 65 79 A4 1C 30 1A A0 03 02 01 01 A1 04 02 02 0D 36 A2 0D 04 0B 6E 6F 6E 63 65 20 6F 72 20 74 73 A5 05 02 03 54 32 10 A6 11 18 0F 31 39 39 34 30 36 31 30 30 36 30 33 31 37 5A +encode_krb5_sam_key: 30 15 A0 13 30 11 A0 03 02 01 01 A1 0A 04 08 31 32 33 34 35 36 37 38 +encode_krb5_enc_sam_response_enc: 30 38 A0 05 02 03 01 33 2A A1 11 18 0F 31 39 37 30 30 31 30 32 30 33 34 36 33 39 5A A2 04 02 02 01 8F A3 16 04 14 65 6E 63 5F 73 61 6D 5F 72 65 73 70 6F 6E 73 65 5F 65 6E 63 +encode_krb5_predicted_sam_response: 30 6D A0 13 30 11 A0 03 02 01 01 A1 0A 04 08 31 32 33 34 35 36 37 38 A1 07 03 05 00 00 00 00 09 A2 11 18 0F 31 39 37 30 30 31 30 31 30 30 30 30 31 37 5A A3 03 02 01 12 A4 10 1B 0E 41 54 48 45 4E 41 2E 4D 49 54 2E 45 44 55 A5 1A 30 18 A0 03 02 01 01 A1 11 30 0F 1B 06 68 66 74 73 61 69 1B 05 65 78 74 72 61 A6 07 04 05 68 65 6C 6C 6F +encode_krb5_sam_response_2: 30 42 A0 03 02 01 2B A1 07 03 05 00 80 00 00 00 A2 0C 04 0A 74 72 61 63 6B 20 64 61 74 61 A3 1D 30 1B A0 03 02 01 01 A1 04 02 02 0D 36 A2 0E 04 0C 6E 6F 6E 63 65 20 6F 72 20 73 61 64 A4 05 02 03 54 32 10 +encode_krb5_enc_sam_response_enc_2: 30 1F A0 03 02 01 58 A1 18 04 16 65 6E 63 5F 73 61 6D 5F 72 65 73 70 6F 6E 73 65 5F 65 6E 63 5F 32 diff --git a/src/tests/asn.1/trval_reference.out b/src/tests/asn.1/trval_reference.out index 95311d3fe..9c5f8cc1e 100644 --- a/src/tests/asn.1/trval_reference.out +++ b/src/tests/asn.1/trval_reference.out @@ -1196,3 +1196,53 @@ encode_krb5_sam_response: . [5] [Integer] 5517840 . [6] [Generalized Time] "19940610060317Z" +encode_krb5_sam_key: + +[Sequence/Sequence Of] +. [0] [Sequence/Sequence Of] +. . [0] [Integer] 1 +. . [1] [Octet String] "12345678" + +encode_krb5_enc_sam_response_enc: + +[Sequence/Sequence Of] +. [0] [Integer] 78634 +. [1] [Generalized Time] "19700102034639Z" +. [2] [Integer] 399 +. [3] [Octet String] "enc_sam_response_enc" + +encode_krb5_predicted_sam_response: + +[Sequence/Sequence Of] +. [0] [Sequence/Sequence Of] +. . [0] [Integer] 1 +. . [1] [Octet String] "12345678" +. [1] [Bit String] 0x9 +. [2] [Generalized Time] "19700101000017Z" +. [3] [Integer] 18 +. [4] [General string] "ATHENA.MIT.EDU" +. [5] [Sequence/Sequence Of] +. . [0] [Integer] 1 +. . [1] [Sequence/Sequence Of] +. . . [General string] "hftsai" +. . . [General string] "extra" +. [6] [Octet String] "hello" + +encode_krb5_sam_response_2: + +[Sequence/Sequence Of] +. [0] [Integer] 43 +. [1] [Bit String] 0x80000000 +. [2] [Octet String] "track data" +. [3] [Sequence/Sequence Of] +. . [0] [Integer] 1 +. . [1] [Integer] 3382 +. . [2] [Octet String] "nonce or sad" +. [4] [Integer] 5517840 + +encode_krb5_enc_sam_response_enc_2: + +[Sequence/Sequence Of] +. [0] [Integer] 88 +. [1] [Octet String] "enc_sam_response_enc_2" + -- 2.26.2