1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* tests/asn.1/ktest.c */
4 * Copyright (C) 1994 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
31 char *sample_principal_name = "hftsai/extra@ATHENA.MIT.EDU";
34 ktest_make_sample_authenticator(krb5_authenticator *a)
36 ktest_make_sample_principal(&a->client);
37 a->checksum = ealloc(sizeof(krb5_checksum));
38 ktest_make_sample_checksum(a->checksum);
39 a->cusec = SAMPLE_USEC;
40 a->ctime = SAMPLE_TIME;
41 a->subkey = ealloc(sizeof(krb5_keyblock));
42 ktest_make_sample_keyblock(a->subkey);
43 a->seq_number = SAMPLE_SEQ_NUMBER;
44 ktest_make_sample_authorization_data(&a->authorization_data);
48 ktest_make_sample_principal(krb5_principal *p)
50 if (krb5_parse_name(test_context, sample_principal_name, p))
55 ktest_make_sample_checksum(krb5_checksum *cs)
57 cs->checksum_type = 1;
59 cs->contents = ealloc(4);
60 memcpy(cs->contents,"1234",4);
64 ktest_make_sample_keyblock(krb5_keyblock *kb)
66 kb->magic = KV5M_KEYBLOCK;
69 kb->contents = ealloc(8);
70 memcpy(kb->contents,"12345678",8);
74 ktest_make_sample_ticket(krb5_ticket *tkt)
76 ktest_make_sample_principal(&tkt->server);
77 ktest_make_sample_enc_data(&tkt->enc_part);
78 tkt->enc_part2 = NULL;
82 ktest_make_sample_enc_data(krb5_enc_data *ed)
86 krb5_data_parse(&ed->ciphertext, "krbASN.1 test message");
90 ktest_make_sample_enc_tkt_part(krb5_enc_tkt_part *etp)
92 etp->flags = SAMPLE_FLAGS;
93 etp->session = ealloc(sizeof(krb5_keyblock));
94 ktest_make_sample_keyblock(etp->session);
95 ktest_make_sample_principal(&etp->client);
96 ktest_make_sample_transited(&etp->transited);
97 ktest_make_sample_ticket_times(&etp->times);
98 ktest_make_sample_addresses(&etp->caddrs);
99 ktest_make_sample_authorization_data(&etp->authorization_data);
103 ktest_make_sample_addresses(krb5_address ***caddrs)
107 *caddrs = ealloc(3 * sizeof(krb5_address *));
108 for (i = 0; i < 2; i++) {
109 (*caddrs)[i] = ealloc(sizeof(krb5_address));
110 ktest_make_sample_address((*caddrs)[i]);
116 ktest_make_sample_authorization_data(krb5_authdata ***ad)
120 *ad = ealloc(3 * sizeof(krb5_authdata *));
121 for (i = 0; i <= 1; i++) {
122 (*ad)[i] = ealloc(sizeof(krb5_authdata));
123 ktest_make_sample_authdata((*ad)[i]);
129 ktest_make_sample_transited(krb5_transited *t)
132 krb5_data_parse(&t->tr_contents, "EDU,MIT.,ATHENA.,WASHINGTON.EDU,CS.");
136 ktest_make_sample_ticket_times(krb5_ticket_times *tt)
138 tt->authtime = SAMPLE_TIME;
139 tt->starttime = SAMPLE_TIME;
140 tt->endtime = SAMPLE_TIME;
141 tt->renew_till = SAMPLE_TIME;
145 ktest_make_sample_address(krb5_address *a)
147 a->addrtype = ADDRTYPE_INET;
149 a->contents = ealloc(4 * sizeof(krb5_octet));
151 a->contents[1] = 208;
157 ktest_make_sample_authdata(krb5_authdata *ad)
161 ad->contents = ealloc(6 * sizeof(krb5_octet));
162 memcpy(ad->contents, "foobar", 6);
166 ktest_make_sample_enc_kdc_rep_part(krb5_enc_kdc_rep_part *ekr)
168 ekr->session = ealloc(sizeof(krb5_keyblock));
169 ktest_make_sample_keyblock(ekr->session);
170 ktest_make_sample_last_req(&ekr->last_req);
171 ekr->nonce = SAMPLE_NONCE;
172 ekr->key_exp = SAMPLE_TIME;
173 ekr->flags = SAMPLE_FLAGS;
174 ekr->times.authtime = SAMPLE_TIME;
175 ekr->times.starttime = SAMPLE_TIME;
176 ekr->times.endtime = SAMPLE_TIME;
177 ekr->times.renew_till = SAMPLE_TIME;
178 ktest_make_sample_principal(&ekr->server);
179 ktest_make_sample_addresses(&ekr->caddrs);
183 ktest_make_sample_last_req(krb5_last_req_entry ***lr)
187 *lr = ealloc(3 * sizeof(krb5_last_req_entry *));
188 for (i = 0; i <= 1; i++)
189 ktest_make_sample_last_req_entry(&(*lr)[i]);
194 ktest_make_sample_last_req_entry(krb5_last_req_entry **lre)
196 *lre = ealloc(sizeof(krb5_last_req_entry));
197 (*lre)->lr_type = -5;
198 (*lre)->value = SAMPLE_TIME;
202 ktest_make_sample_kdc_rep(krb5_kdc_rep *kdcr)
204 ktest_make_sample_pa_data_array(&kdcr->padata);
205 ktest_make_sample_principal(&kdcr->client);
206 kdcr->ticket = ealloc(sizeof(krb5_ticket));
207 ktest_make_sample_ticket(kdcr->ticket);
208 ktest_make_sample_enc_data(&kdcr->enc_part);
209 kdcr->enc_part2 = NULL;
213 ktest_make_sample_pa_data_array(krb5_pa_data ***pad)
217 *pad = ealloc(3 * sizeof(krb5_pa_data *));
218 for (i = 0; i <= 1; i++) {
219 (*pad)[i] = ealloc(sizeof(krb5_pa_data));
220 ktest_make_sample_pa_data((*pad)[i]);
226 ktest_make_sample_empty_pa_data_array(krb5_pa_data ***pad)
228 *pad = ealloc(sizeof(krb5_pa_data *));
233 ktest_make_sample_pa_data(krb5_pa_data *pad)
237 pad->contents = ealloc(7);
238 memcpy(pad->contents, "pa-data", 7);
242 ktest_make_sample_ap_req(krb5_ap_req *ar)
244 ar->ap_options = SAMPLE_FLAGS;
245 ar->ticket = ealloc(sizeof(krb5_ticket));
246 ktest_make_sample_ticket(ar->ticket);
247 ktest_make_sample_enc_data(&(ar->authenticator));
251 ktest_make_sample_ap_rep(krb5_ap_rep *ar)
253 ktest_make_sample_enc_data(&ar->enc_part);
257 ktest_make_sample_ap_rep_enc_part(krb5_ap_rep_enc_part *arep)
259 arep->ctime = SAMPLE_TIME;
260 arep->cusec = SAMPLE_USEC;
261 arep->subkey = ealloc(sizeof(krb5_keyblock));
262 ktest_make_sample_keyblock(arep->subkey);
263 arep->seq_number = SAMPLE_SEQ_NUMBER;
267 ktest_make_sample_kdc_req(krb5_kdc_req *kr)
269 /* msg_type is left up to the calling procedure */
270 ktest_make_sample_pa_data_array(&kr->padata);
271 kr->kdc_options = SAMPLE_FLAGS;
272 ktest_make_sample_principal(&(kr->client));
273 ktest_make_sample_principal(&(kr->server));
274 kr->from = SAMPLE_TIME;
275 kr->till = SAMPLE_TIME;
276 kr->rtime = SAMPLE_TIME;
277 kr->nonce = SAMPLE_NONCE;
279 kr->ktype = ealloc(2 * sizeof(krb5_enctype));
282 ktest_make_sample_addresses(&kr->addresses);
283 ktest_make_sample_enc_data(&kr->authorization_data);
284 ktest_make_sample_authorization_data(&kr->unenc_authdata);
285 ktest_make_sample_sequence_of_ticket(&kr->second_ticket);
289 ktest_make_sample_kdc_req_body(krb5_kdc_req *krb)
291 krb->kdc_options = SAMPLE_FLAGS;
292 ktest_make_sample_principal(&krb->client);
293 ktest_make_sample_principal(&krb->server);
294 krb->from = SAMPLE_TIME;
295 krb->till = SAMPLE_TIME;
296 krb->rtime = SAMPLE_TIME;
297 krb->nonce = SAMPLE_NONCE;
299 krb->ktype = (krb5_enctype*)calloc(2,sizeof(krb5_enctype));
302 ktest_make_sample_addresses(&krb->addresses);
303 ktest_make_sample_enc_data(&krb->authorization_data);
304 ktest_make_sample_authorization_data(&krb->unenc_authdata);
305 ktest_make_sample_sequence_of_ticket(&krb->second_ticket);
309 ktest_make_sample_safe(krb5_safe *s)
311 ktest_make_sample_data(&s->user_data);
312 s->timestamp = SAMPLE_TIME;
313 s->usec = SAMPLE_USEC;
314 s->seq_number = SAMPLE_SEQ_NUMBER;
315 s->s_address = ealloc(sizeof(krb5_address));
316 ktest_make_sample_address(s->s_address);
317 s->r_address = ealloc(sizeof(krb5_address));
318 ktest_make_sample_address(s->r_address);
319 s->checksum = ealloc(sizeof(krb5_checksum));
320 ktest_make_sample_checksum(s->checksum);
324 ktest_make_sample_priv(krb5_priv *p)
326 ktest_make_sample_enc_data(&p->enc_part);
330 ktest_make_sample_priv_enc_part(krb5_priv_enc_part *pep)
332 ktest_make_sample_data(&(pep->user_data));
333 pep->timestamp = SAMPLE_TIME;
334 pep->usec = SAMPLE_USEC;
335 pep->seq_number = SAMPLE_SEQ_NUMBER;
336 pep->s_address = ealloc(sizeof(krb5_address));
337 ktest_make_sample_address(pep->s_address);
338 pep->r_address = ealloc(sizeof(krb5_address));
339 ktest_make_sample_address(pep->r_address);
343 ktest_make_sample_cred(krb5_cred *c)
345 ktest_make_sample_sequence_of_ticket(&c->tickets);
346 ktest_make_sample_enc_data(&c->enc_part);
350 ktest_make_sample_sequence_of_ticket(krb5_ticket ***sot)
354 *sot = ealloc(3 * sizeof(krb5_ticket *));
355 for (i = 0; i < 2; i++) {
356 (*sot)[i] = ealloc(sizeof(krb5_ticket));
357 ktest_make_sample_ticket((*sot)[i]);
363 ktest_make_sample_cred_enc_part(krb5_cred_enc_part *cep)
365 cep->nonce = SAMPLE_NONCE;
366 cep->timestamp = SAMPLE_TIME;
367 cep->usec = SAMPLE_USEC;
368 cep->s_address = ealloc(sizeof(krb5_address));
369 ktest_make_sample_address(cep->s_address);
370 cep->r_address = ealloc(sizeof(krb5_address));
371 ktest_make_sample_address(cep->r_address);
372 ktest_make_sequence_of_cred_info(&cep->ticket_info);
376 ktest_make_sequence_of_cred_info(krb5_cred_info ***soci)
380 *soci = ealloc(3 * sizeof(krb5_cred_info *));
381 for (i = 0; i < 2; i++) {
382 (*soci)[i] = ealloc(sizeof(krb5_cred_info));
383 ktest_make_sample_cred_info((*soci)[i]);
389 ktest_make_sample_cred_info(krb5_cred_info *ci)
391 ci->session = ealloc(sizeof(krb5_keyblock));
392 ktest_make_sample_keyblock(ci->session);
393 ktest_make_sample_principal(&ci->client);
394 ktest_make_sample_principal(&ci->server);
395 ci->flags = SAMPLE_FLAGS;
396 ci->times.authtime = SAMPLE_TIME;
397 ci->times.starttime = SAMPLE_TIME;
398 ci->times.endtime = SAMPLE_TIME;
399 ci->times.renew_till = SAMPLE_TIME;
400 ktest_make_sample_addresses(&ci->caddrs);
404 ktest_make_sample_error(krb5_error *kerr)
406 kerr->ctime = SAMPLE_TIME;
407 kerr->cusec = SAMPLE_USEC;
408 kerr->susec = SAMPLE_USEC;
409 kerr->stime = SAMPLE_TIME;
410 kerr->error = SAMPLE_ERROR;
411 ktest_make_sample_principal(&kerr->client);
412 ktest_make_sample_principal(&kerr->server);
413 ktest_make_sample_data(&kerr->text);
414 ktest_make_sample_data(&kerr->e_data);
418 ktest_make_sample_data(krb5_data *d)
420 krb5_data_parse(d, "krb5data");
424 ktest_make_sample_etype_info(krb5_etype_info_entry ***p)
426 krb5_etype_info_entry **info;
430 info = ealloc(4 * sizeof(krb5_etype_info_entry *));
431 for (i = 0; i < 3; i++) {
432 info[i] = ealloc(sizeof(krb5_etype_info_entry));
434 len = asprintf(&str, "Morton's #%d", i);
437 info[i]->salt = (krb5_octet *)str;
438 info[i]->length = len;
439 info[i]->s2kparams.data = NULL;
440 info[i]->s2kparams.length = 0;
441 info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
444 info[1]->length = KRB5_ETYPE_NO_SALT;
451 ktest_make_sample_etype_info2(krb5_etype_info_entry ***p)
453 krb5_etype_info_entry **info;
457 info = ealloc(4 * sizeof(krb5_etype_info_entry *));
458 for (i = 0; i < 3; i++) {
459 info[i] = ealloc(sizeof(krb5_etype_info_entry));
461 len = asprintf(&str, "Morton's #%d", i);
464 info[i]->salt = (krb5_octet *)str;
465 info[i]->length = (unsigned int)len;
466 len = asprintf(&info[i]->s2kparams.data, "s2k: %d", i);
469 info[i]->s2kparams.length = (unsigned int) len;
470 info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
473 info[1]->length = KRB5_ETYPE_NO_SALT;
480 ktest_make_sample_pa_enc_ts(krb5_pa_enc_ts *pa_enc)
482 pa_enc->patimestamp = SAMPLE_TIME;
483 pa_enc->pausec = SAMPLE_USEC;
487 ktest_make_sample_sam_challenge_2(krb5_sam_challenge_2 *p)
489 /* Need a valid DER sequence encoding here; this one contains the OCTET
490 * STRING "challenge". */
491 krb5_data_parse(&p->sam_challenge_2_body, "\x30\x0B\x04\x09" "challenge");
492 p->sam_cksum = ealloc(2 * sizeof(krb5_checksum *));
493 p->sam_cksum[0] = ealloc(sizeof(krb5_checksum));
494 ktest_make_sample_checksum(p->sam_cksum[0]);
495 p->sam_cksum[1] = NULL;
499 ktest_make_sample_sam_challenge_2_body(krb5_sam_challenge_2_body *p)
502 p->sam_flags = KRB5_SAM_USE_SAD_AS_KEY;
503 krb5_data_parse(&p->sam_type_name, "type name");
504 p->sam_track_id = empty_data();
505 krb5_data_parse(&p->sam_challenge_label, "challenge label");
506 krb5_data_parse(&p->sam_challenge, "challenge ipse");
507 krb5_data_parse(&p->sam_response_prompt, "response_prompt ipse");
508 p->sam_pk_for_sad = empty_data();
509 p->sam_nonce = 0x543210;
510 p->sam_etype = ENCTYPE_DES_CBC_CRC;
514 ktest_make_sample_sam_response_2(krb5_sam_response_2 *p)
516 p->magic = KV5M_SAM_RESPONSE;
517 p->sam_type = 43; /* information */
518 p->sam_flags = KRB5_SAM_USE_SAD_AS_KEY; /* KRB5_SAM_* values */
519 krb5_data_parse(&p->sam_track_id, "track data");
520 krb5_data_parse(&p->sam_enc_nonce_or_sad.ciphertext, "nonce or sad");
521 p->sam_enc_nonce_or_sad.enctype = ENCTYPE_DES_CBC_CRC;
522 p->sam_enc_nonce_or_sad.kvno = 3382;
523 p->sam_nonce = 0x543210;
527 ktest_make_sample_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 *p)
531 krb5_data_parse(&p->sam_sad, "enc_sam_response_enc_2");
535 ktest_make_sample_pa_for_user(krb5_pa_for_user *p)
537 ktest_make_sample_principal(&p->user);
538 ktest_make_sample_checksum(&p->cksum);
539 ktest_make_sample_data(&p->auth_package);
543 ktest_make_sample_pa_s4u_x509_user(krb5_pa_s4u_x509_user *p)
545 krb5_s4u_userid *u = &p->user_id;
548 ktest_make_sample_principal(&u->user);
549 krb5_data_parse(&u->subject_cert, "pa_s4u_x509_user");
550 u->options = 0x80000000;
551 ktest_make_sample_checksum(&p->cksum);
555 ktest_make_sample_ad_kdcissued(krb5_ad_kdcissued *p)
557 ktest_make_sample_checksum(&p->ad_checksum);
558 ktest_make_sample_principal(&p->i_principal);
559 ktest_make_sample_authorization_data(&p->elements);
563 ktest_make_sample_ad_signedpath_data(krb5_ad_signedpath_data *p)
565 ktest_make_sample_principal(&p->client);
566 p->authtime = SAMPLE_TIME;
567 p->delegated = ealloc(2 * sizeof(krb5_principal));
568 ktest_make_sample_principal(&p->delegated[0]);
569 p->delegated[1] = NULL;
570 ktest_make_sample_authorization_data(&p->authorization_data);
571 ktest_make_sample_pa_data_array(&p->method_data);
575 ktest_make_sample_ad_signedpath(krb5_ad_signedpath *p)
578 ktest_make_sample_checksum(&p->checksum);
579 p->delegated = ealloc(2 * sizeof(krb5_principal));
580 p->delegated[1] = NULL;
581 ktest_make_sample_pa_data_array(&p->method_data);
585 ktest_make_sample_iakerb_header(krb5_iakerb_header *ih)
587 ktest_make_sample_data(&(ih->target_realm));
588 ih->cookie = ealloc(sizeof(krb5_data));
589 ktest_make_sample_data(ih->cookie);
593 ktest_make_sample_iakerb_finished(krb5_iakerb_finished *ih)
595 ktest_make_sample_checksum(&ih->checksum);
599 ktest_make_sample_fast_finished(krb5_fast_finished *p)
601 p->timestamp = SAMPLE_TIME;
602 p->usec = SAMPLE_USEC;
603 ktest_make_sample_principal(&p->client);
604 ktest_make_sample_checksum(&p->ticket_checksum);
608 ktest_make_sample_fast_response(krb5_fast_response *p)
610 ktest_make_sample_pa_data_array(&p->padata);
611 p->strengthen_key = ealloc(sizeof(krb5_keyblock));
612 ktest_make_sample_keyblock(p->strengthen_key);
613 p->finished = ealloc(sizeof(krb5_fast_finished));
614 ktest_make_sample_fast_finished(p->finished);
615 p->nonce = SAMPLE_NONCE;
618 #ifndef DISABLE_PKINIT
621 ktest_make_sample_pk_authenticator(krb5_pk_authenticator *p)
623 p->cusec = SAMPLE_USEC;
624 p->ctime = SAMPLE_TIME;
625 p->nonce = SAMPLE_NONCE;
626 ktest_make_sample_checksum(&p->paChecksum);
627 /* We don't encode the checksum type, only the contents. */
628 p->paChecksum.checksum_type = 0;
632 ktest_make_sample_pk_authenticator_draft9(krb5_pk_authenticator_draft9 *p)
634 ktest_make_sample_principal(&p->kdcName);
635 p->cusec = SAMPLE_USEC;
636 p->ctime = SAMPLE_TIME;
637 p->nonce = SAMPLE_NONCE;
641 ktest_make_sample_oid(krb5_data *p)
643 krb5_data_parse(p, "\052\206\110\206\367\022\001\002\002");
647 ktest_make_sample_algorithm_identifier(krb5_algorithm_identifier *p)
649 ktest_make_sample_oid(&p->algorithm);
650 /* Need a valid DER encoding here; this is the OCTET STRING "params". */
651 krb5_data_parse(&p->parameters, "\x04\x06" "params");
655 ktest_make_sample_algorithm_identifier_no_params(krb5_algorithm_identifier *p)
657 ktest_make_sample_oid(&p->algorithm);
658 p->parameters = empty_data();
662 ktest_make_sample_subject_pk_info(krb5_subject_pk_info *p)
664 ktest_make_sample_algorithm_identifier(&p->algorithm);
665 ktest_make_sample_data(&p->subjectPublicKey);
669 ktest_make_sample_external_principal_identifier(
670 krb5_external_principal_identifier *p)
672 ktest_make_sample_data(&p->subjectName);
673 ktest_make_sample_data(&p->issuerAndSerialNumber);
674 ktest_make_sample_data(&p->subjectKeyIdentifier);
678 ktest_make_sample_trusted_ca_principalName(krb5_trusted_ca *p)
680 p->choice = choice_trusted_cas_principalName;
681 ktest_make_sample_principal(&p->u.principalName);
685 ktest_make_sample_trusted_ca_caName(krb5_trusted_ca *p)
687 p->choice = choice_trusted_cas_caName;
688 ktest_make_sample_data(&p->u.caName);
692 ktest_make_sample_trusted_ca_issuerAndSerial(krb5_trusted_ca *p)
694 p->choice = choice_trusted_cas_issuerAndSerial;
695 ktest_make_sample_data(&p->u.issuerAndSerial);
699 ktest_make_sample_pa_pk_as_req(krb5_pa_pk_as_req *p)
701 ktest_make_sample_data(&p->signedAuthPack);
702 p->trustedCertifiers =
703 ealloc(2 * sizeof(krb5_external_principal_identifier *));
704 p->trustedCertifiers[0] =
705 ealloc(sizeof(krb5_external_principal_identifier));
706 ktest_make_sample_external_principal_identifier(p->trustedCertifiers[0]);
707 p->trustedCertifiers[1] = NULL;
708 ktest_make_sample_data(&p->kdcPkId);
712 ktest_make_sample_pa_pk_as_req_draft9(krb5_pa_pk_as_req_draft9 *p)
716 ktest_make_sample_data(&p->signedAuthPack);
717 p->trustedCertifiers = ealloc(4 * sizeof(krb5_trusted_ca *));
718 for (i = 0; i < 3; i++)
719 p->trustedCertifiers[i] = ealloc(sizeof(krb5_trusted_ca));
720 ktest_make_sample_trusted_ca_principalName(p->trustedCertifiers[0]);
721 ktest_make_sample_trusted_ca_caName(p->trustedCertifiers[1]);
722 ktest_make_sample_trusted_ca_issuerAndSerial(p->trustedCertifiers[2]);
723 p->trustedCertifiers[3] = NULL;
724 ktest_make_sample_data(&p->kdcCert);
725 ktest_make_sample_data(&p->encryptionCert);
729 ktest_make_sample_dh_rep_info(krb5_dh_rep_info *p)
731 ktest_make_sample_data(&p->dhSignedData);
732 ktest_make_sample_data(&p->serverDHNonce);
733 p->kdfID = ealloc(sizeof(krb5_data));
734 ktest_make_sample_data(p->kdfID);
738 ktest_make_sample_pa_pk_as_rep_dhInfo(krb5_pa_pk_as_rep *p)
740 p->choice = choice_pa_pk_as_rep_dhInfo;
741 ktest_make_sample_dh_rep_info(&p->u.dh_Info);
745 ktest_make_sample_pa_pk_as_rep_encKeyPack(krb5_pa_pk_as_rep *p)
747 p->choice = choice_pa_pk_as_rep_encKeyPack;
748 ktest_make_sample_data(&p->u.encKeyPack);
752 ktest_make_sample_pa_pk_as_rep_draft9_dhSignedData(krb5_pa_pk_as_rep_draft9 *p)
754 p->choice = choice_pa_pk_as_rep_draft9_dhSignedData;
755 ktest_make_sample_data(&p->u.dhSignedData);
759 ktest_make_sample_pa_pk_as_rep_draft9_encKeyPack(krb5_pa_pk_as_rep_draft9 *p)
761 p->choice = choice_pa_pk_as_rep_draft9_encKeyPack;
762 ktest_make_sample_data(&p->u.encKeyPack);
766 ktest_make_sample_auth_pack(krb5_auth_pack *p)
768 ktest_make_sample_pk_authenticator(&p->pkAuthenticator);
769 p->clientPublicValue = ealloc(sizeof(krb5_subject_pk_info));
770 ktest_make_sample_subject_pk_info(p->clientPublicValue);
771 p->supportedCMSTypes = ealloc(3 * sizeof(krb5_algorithm_identifier *));
772 p->supportedCMSTypes[0] = ealloc(sizeof(krb5_algorithm_identifier));
773 ktest_make_sample_algorithm_identifier(p->supportedCMSTypes[0]);
774 p->supportedCMSTypes[1] = ealloc(sizeof(krb5_algorithm_identifier));
775 ktest_make_sample_algorithm_identifier_no_params(p->supportedCMSTypes[1]);
776 p->supportedCMSTypes[2] = NULL;
777 ktest_make_sample_data(&p->clientDHNonce);
778 p->supportedKDFs = ealloc(2 * sizeof(krb5_data ));
779 p->supportedKDFs[0] = ealloc(sizeof(krb5_data));
780 ktest_make_sample_data(p->supportedKDFs[0]);
781 p->supportedKDFs[1] = NULL;
785 ktest_make_sample_auth_pack_draft9(krb5_auth_pack_draft9 *p)
787 ktest_make_sample_pk_authenticator_draft9(&p->pkAuthenticator);
788 p->clientPublicValue = ealloc(sizeof(krb5_subject_pk_info));
789 ktest_make_sample_subject_pk_info(p->clientPublicValue);
793 ktest_make_sample_kdc_dh_key_info(krb5_kdc_dh_key_info *p)
795 ktest_make_sample_data(&p->subjectPublicKey);
796 p->nonce = SAMPLE_NONCE;
797 p->dhKeyExpiration = SAMPLE_TIME;
801 ktest_make_sample_reply_key_pack(krb5_reply_key_pack *p)
803 ktest_make_sample_keyblock(&p->replyKey);
804 ktest_make_sample_checksum(&p->asChecksum);
808 ktest_make_sample_reply_key_pack_draft9(krb5_reply_key_pack_draft9 *p)
810 ktest_make_sample_keyblock(&p->replyKey);
811 p->nonce = SAMPLE_NONCE;
815 ktest_make_sample_sp80056a_other_info(krb5_sp80056a_other_info *p)
817 ktest_make_sample_algorithm_identifier_no_params(&p->algorithm_identifier);
818 ktest_make_sample_principal(&p->party_u_info);
819 ktest_make_sample_principal(&p->party_v_info);
820 ktest_make_sample_data(&p->supp_pub_info);
824 ktest_make_sample_pkinit_supp_pub_info(krb5_pkinit_supp_pub_info *p)
826 p->enctype = ENCTYPE_DES_CBC_CRC;
827 ktest_make_sample_data(&p->as_req);
828 ktest_make_sample_data(&p->pk_as_rep);
831 #endif /* not DISABLE_PKINIT */
835 ktest_make_sample_key_data(krb5_key_data *p, int i)
841 p->key_data_kvno = 42;
842 len = asprintf(&str, "key%d", i);
845 p->key_data_type[0] = 2;
846 p->key_data_length[0] = (unsigned int) len;
847 p->key_data_contents[0] = (krb5_octet *)str;
848 len = asprintf(&str, "salt%d", i);
851 p->key_data_type[1] = i;
852 p->key_data_length[1] = (unsigned int) len;
853 p->key_data_contents[1] = (krb5_octet *)str;
857 ktest_make_sample_ldap_seqof_key_data(ldap_seqof_key_data *p)
863 p->key_data = calloc(3,sizeof(krb5_key_data));
864 for (i = 0; i < 3; i++)
865 ktest_make_sample_key_data(&p->key_data[i], i);
870 /****************************************************************/
874 ktest_destroy_data(krb5_data **d)
884 ktest_empty_data(krb5_data *d)
886 if (d->data != NULL) {
894 ktest_empty_checksum(krb5_checksum *cs)
901 ktest_destroy_checksum(krb5_checksum **cs)
904 free((*cs)->contents);
911 ktest_empty_keyblock(krb5_keyblock *kb)
922 ktest_destroy_keyblock(krb5_keyblock **kb)
925 free((*kb)->contents);
932 ktest_empty_authorization_data(krb5_authdata **ad)
937 for (i=0; ad[i] != NULL; i++)
938 ktest_destroy_authdata(&ad[i]);
943 ktest_destroy_authorization_data(krb5_authdata ***ad)
945 ktest_empty_authorization_data(*ad);
951 ktest_destroy_authdata(krb5_authdata **ad)
954 free((*ad)->contents);
961 ktest_empty_pa_data_array(krb5_pa_data **pad)
965 for (i=0; pad[i] != NULL; i++)
966 ktest_destroy_pa_data(&pad[i]);
970 ktest_destroy_pa_data_array(krb5_pa_data ***pad)
972 ktest_empty_pa_data_array(*pad);
978 ktest_destroy_pa_data(krb5_pa_data **pad)
981 free((*pad)->contents);
988 ktest_destroy_address(krb5_address **a)
991 free((*a)->contents);
998 ktest_empty_addresses(krb5_address **a)
1002 for (i=0; a[i] != NULL; i++)
1003 ktest_destroy_address(&a[i]);
1007 ktest_destroy_addresses(krb5_address ***a)
1009 ktest_empty_addresses(*a);
1015 ktest_destroy_principal(krb5_principal *p)
1019 for (i=0; i<(*p)->length; i++)
1020 ktest_empty_data(&(*p)->data[i]);
1021 ktest_empty_data(&(*p)->realm);
1028 ktest_destroy_sequence_of_integer(long **soi)
1035 ktest_destroy_sequence_of_ticket(krb5_ticket ***sot)
1039 for (i=0; (*sot)[i] != NULL; i++)
1040 ktest_destroy_ticket(&(*sot)[i]);
1046 ktest_destroy_ticket(krb5_ticket **tkt)
1048 ktest_destroy_principal(&(*tkt)->server);
1049 ktest_destroy_enc_data(&(*tkt)->enc_part);
1050 /* ktest_empty_enc_tkt_part(((*tkt)->enc_part2));*/
1056 ktest_empty_ticket(krb5_ticket *tkt)
1059 ktest_destroy_principal(&tkt->server);
1060 ktest_destroy_enc_data(&tkt->enc_part);
1062 ktest_destroy_enc_tkt_part(&tkt->enc_part2);
1066 ktest_destroy_enc_data(krb5_enc_data *ed)
1068 ktest_empty_data(&ed->ciphertext);
1073 ktest_destroy_etype_info_entry(krb5_etype_info_entry *i)
1077 ktest_empty_data(&i->s2kparams);
1082 ktest_destroy_etype_info(krb5_etype_info_entry **info)
1086 for (i = 0; info[i] != NULL; i++)
1087 ktest_destroy_etype_info_entry(info[i]);
1092 ktest_empty_kdc_req(krb5_kdc_req *kr)
1095 ktest_destroy_pa_data_array(&kr->padata);
1098 ktest_destroy_principal(&kr->client);
1101 ktest_destroy_principal(&kr->server);
1104 ktest_destroy_addresses(&kr->addresses);
1105 ktest_destroy_enc_data(&kr->authorization_data);
1106 if (kr->unenc_authdata)
1107 ktest_destroy_authorization_data(&kr->unenc_authdata);
1108 if (kr->second_ticket)
1109 ktest_destroy_sequence_of_ticket(&kr->second_ticket);
1114 ktest_empty_kdc_rep(krb5_kdc_rep *kr)
1117 ktest_destroy_pa_data_array(&kr->padata);
1120 ktest_destroy_principal(&kr->client);
1123 ktest_destroy_ticket(&kr->ticket);
1125 ktest_destroy_enc_data(&kr->enc_part);
1127 if (kr->enc_part2) {
1128 ktest_empty_enc_kdc_rep_part(kr->enc_part2);
1129 free(kr->enc_part2);
1130 kr->enc_part2 = NULL;
1135 ktest_empty_authenticator(krb5_authenticator *a)
1138 ktest_destroy_principal(&a->client);
1140 ktest_destroy_checksum(&a->checksum);
1142 ktest_destroy_keyblock(&a->subkey);
1143 if (a->authorization_data)
1144 ktest_destroy_authorization_data(&a->authorization_data);
1148 ktest_empty_enc_tkt_part(krb5_enc_tkt_part *etp)
1151 ktest_destroy_keyblock(&etp->session);
1153 ktest_destroy_principal(&etp->client);
1155 ktest_destroy_addresses(&etp->caddrs);
1156 if (etp->authorization_data)
1157 ktest_destroy_authorization_data(&etp->authorization_data);
1158 ktest_destroy_transited(&etp->transited);
1162 ktest_destroy_enc_tkt_part(krb5_enc_tkt_part **etp)
1165 ktest_empty_enc_tkt_part(*etp);
1172 ktest_empty_enc_kdc_rep_part(krb5_enc_kdc_rep_part *ekr)
1175 ktest_destroy_keyblock(&ekr->session);
1178 ktest_destroy_principal(&ekr->server);
1181 ktest_destroy_addresses(&ekr->caddrs);
1182 ktest_destroy_last_req(&ekr->last_req);
1186 ktest_destroy_transited(krb5_transited *t)
1188 if (t->tr_contents.data)
1189 ktest_empty_data(&t->tr_contents);
1193 ktest_empty_ap_rep(krb5_ap_rep *ar)
1195 ktest_destroy_enc_data(&ar->enc_part);
1199 ktest_empty_ap_req(krb5_ap_req *ar)
1202 ktest_destroy_ticket(&ar->ticket);
1203 ktest_destroy_enc_data(&ar->authenticator);
1207 ktest_empty_cred_enc_part(krb5_cred_enc_part *cep)
1210 ktest_destroy_address(&cep->s_address);
1212 ktest_destroy_address(&cep->r_address);
1213 if (cep->ticket_info)
1214 ktest_destroy_sequence_of_cred_info(&cep->ticket_info);
1218 ktest_destroy_cred_info(krb5_cred_info **ci)
1221 ktest_destroy_keyblock(&(*ci)->session);
1223 ktest_destroy_principal(&(*ci)->client);
1225 ktest_destroy_principal(&(*ci)->server);
1227 ktest_destroy_addresses(&(*ci)->caddrs);
1233 ktest_destroy_sequence_of_cred_info(krb5_cred_info ***soci)
1237 for (i = 0; (*soci)[i] != NULL; i++)
1238 ktest_destroy_cred_info(&(*soci)[i]);
1244 ktest_empty_safe(krb5_safe *s)
1246 ktest_empty_data(&s->user_data);
1247 ktest_destroy_address(&s->s_address);
1248 ktest_destroy_address(&s->r_address);
1249 ktest_destroy_checksum(&s->checksum);
1253 ktest_empty_priv_enc_part(krb5_priv_enc_part *pep)
1255 ktest_empty_data(&pep->user_data);
1256 ktest_destroy_address(&pep->s_address);
1257 ktest_destroy_address(&pep->r_address);
1261 ktest_empty_priv(krb5_priv *p)
1263 ktest_destroy_enc_data(&p->enc_part);
1267 ktest_empty_cred(krb5_cred *c)
1269 ktest_destroy_sequence_of_ticket(&c->tickets);
1270 ktest_destroy_enc_data(&c->enc_part);
1275 ktest_destroy_last_req(krb5_last_req_entry ***lr)
1280 for (i=0; (*lr)[i] != NULL; i++)
1288 ktest_empty_error(krb5_error *kerr)
1291 ktest_destroy_principal(&kerr->client);
1293 ktest_destroy_principal(&kerr->server);
1294 ktest_empty_data(&kerr->text);
1295 ktest_empty_data(&kerr->e_data);
1299 ktest_empty_ap_rep_enc_part(krb5_ap_rep_enc_part *arep)
1301 ktest_destroy_keyblock(&(arep)->subkey);
1305 ktest_empty_sam_challenge_2(krb5_sam_challenge_2 *p)
1309 ktest_empty_data(&p->sam_challenge_2_body);
1310 if (p->sam_cksum != NULL) {
1311 for (ck = p->sam_cksum; *ck != NULL; ck++)
1312 ktest_destroy_checksum(ck);
1314 p->sam_cksum = NULL;
1319 ktest_empty_sam_challenge_2_body(krb5_sam_challenge_2_body *p)
1321 ktest_empty_data(&p->sam_type_name);
1322 ktest_empty_data(&p->sam_track_id);
1323 ktest_empty_data(&p->sam_challenge_label);
1324 ktest_empty_data(&p->sam_challenge);
1325 ktest_empty_data(&p->sam_response_prompt);
1326 ktest_empty_data(&p->sam_pk_for_sad);
1330 ktest_empty_sam_response_2(krb5_sam_response_2 *p)
1332 ktest_empty_data(&p->sam_track_id);
1333 ktest_empty_data(&p->sam_enc_nonce_or_sad.ciphertext);
1337 ktest_empty_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 *p)
1339 ktest_empty_data(&p->sam_sad);
1343 ktest_empty_pa_for_user(krb5_pa_for_user *p)
1345 ktest_destroy_principal(&p->user);
1346 ktest_empty_checksum(&p->cksum);
1347 ktest_empty_data(&p->auth_package);
1351 ktest_empty_pa_s4u_x509_user(krb5_pa_s4u_x509_user *p)
1353 ktest_destroy_principal(&p->user_id.user);
1354 ktest_empty_data(&p->user_id.subject_cert);
1355 free(p->cksum.contents);
1359 ktest_empty_ad_kdcissued(krb5_ad_kdcissued *p)
1361 free(p->ad_checksum.contents);
1362 ktest_destroy_principal(&p->i_principal);
1363 ktest_destroy_authorization_data(&p->elements);
1367 ktest_empty_ad_signedpath_data(krb5_ad_signedpath_data *p)
1371 ktest_destroy_principal(&p->client);
1372 if (p->delegated != NULL) {
1373 for (i = 0; p->delegated[i] != NULL; i++) {
1374 krb5_principal princ = p->delegated[i];
1375 ktest_destroy_principal(&princ);
1379 ktest_destroy_pa_data_array(&p->method_data);
1380 ktest_destroy_authorization_data(&p->authorization_data);
1384 ktest_empty_ad_signedpath(krb5_ad_signedpath *p)
1388 free(p->checksum.contents);
1389 if (p->delegated != NULL) {
1390 for (i = 0; p->delegated[i] != NULL; i++) {
1391 krb5_principal princ = p->delegated[i];
1392 ktest_destroy_principal(&princ);
1396 ktest_destroy_pa_data_array(&p->method_data);
1400 ktest_empty_iakerb_header(krb5_iakerb_header *p)
1402 krb5_free_data_contents(NULL, &p->target_realm);
1403 krb5_free_data(NULL, p->cookie);
1407 ktest_empty_iakerb_finished(krb5_iakerb_finished *p)
1409 krb5_free_checksum_contents(NULL, &p->checksum);
1413 ktest_empty_fast_finished(krb5_fast_finished *p)
1415 ktest_destroy_principal(&p->client);
1416 ktest_empty_checksum(&p->ticket_checksum);
1420 ktest_empty_fast_response(krb5_fast_response *p)
1422 ktest_destroy_pa_data_array(&p->padata);
1423 ktest_destroy_keyblock(&p->strengthen_key);
1424 if (p->finished != NULL) {
1425 ktest_empty_fast_finished(p->finished);
1431 #ifndef DISABLE_PKINIT
1434 ktest_empty_pk_authenticator(krb5_pk_authenticator *p)
1436 ktest_empty_checksum(&p->paChecksum);
1437 p->paChecksum.contents = NULL;
1441 ktest_empty_pk_authenticator_draft9(krb5_pk_authenticator_draft9 *p)
1443 ktest_destroy_principal(&p->kdcName);
1447 ktest_empty_algorithm_identifier(krb5_algorithm_identifier *p)
1449 ktest_empty_data(&p->algorithm);
1450 ktest_empty_data(&p->parameters);
1454 ktest_empty_subject_pk_info(krb5_subject_pk_info *p)
1456 ktest_empty_algorithm_identifier(&p->algorithm);
1457 ktest_empty_data(&p->subjectPublicKey);
1461 ktest_empty_external_principal_identifier(
1462 krb5_external_principal_identifier *p)
1464 ktest_empty_data(&p->subjectName);
1465 ktest_empty_data(&p->issuerAndSerialNumber);
1466 ktest_empty_data(&p->subjectKeyIdentifier);
1470 ktest_empty_trusted_ca(krb5_trusted_ca *p)
1472 if (p->choice == choice_trusted_cas_principalName)
1473 ktest_destroy_principal(&p->u.principalName);
1474 else if (p->choice == choice_trusted_cas_caName)
1475 ktest_empty_data(&p->u.caName);
1476 else if (p->choice == choice_trusted_cas_issuerAndSerial)
1477 ktest_empty_data(&p->u.issuerAndSerial);
1478 p->choice = choice_trusted_cas_UNKNOWN;
1482 ktest_empty_pa_pk_as_req(krb5_pa_pk_as_req *p)
1484 krb5_external_principal_identifier **pi;
1486 ktest_empty_data(&p->signedAuthPack);
1487 for (pi = p->trustedCertifiers; *pi != NULL; pi++) {
1488 ktest_empty_external_principal_identifier(*pi);
1491 free(p->trustedCertifiers);
1492 p->trustedCertifiers = NULL;
1493 ktest_empty_data(&p->kdcPkId);
1497 ktest_empty_pa_pk_as_req_draft9(krb5_pa_pk_as_req_draft9 *p)
1499 krb5_trusted_ca **ca;
1501 ktest_empty_data(&p->signedAuthPack);
1502 if (p->trustedCertifiers != NULL) {
1503 for (ca = p->trustedCertifiers; *ca != NULL; ca++) {
1504 ktest_empty_trusted_ca(*ca);
1507 free(p->trustedCertifiers);
1508 p->trustedCertifiers = NULL;
1510 ktest_empty_data(&p->kdcCert);
1511 ktest_empty_data(&p->encryptionCert);
1515 ktest_empty_dh_rep_info(krb5_dh_rep_info *p)
1517 ktest_empty_data(&p->dhSignedData);
1518 ktest_empty_data(&p->serverDHNonce);
1519 ktest_destroy_data(&p->kdfID);
1523 ktest_empty_pa_pk_as_rep(krb5_pa_pk_as_rep *p)
1525 if (p->choice == choice_pa_pk_as_rep_dhInfo)
1526 ktest_empty_dh_rep_info(&p->u.dh_Info);
1527 else if (p->choice == choice_pa_pk_as_rep_encKeyPack)
1528 ktest_empty_data(&p->u.encKeyPack);
1529 p->choice = choice_pa_pk_as_rep_UNKNOWN;
1533 ktest_empty_pa_pk_as_rep_draft9(krb5_pa_pk_as_rep_draft9 *p)
1535 if (p->choice == choice_pa_pk_as_rep_draft9_dhSignedData)
1536 ktest_empty_data(&p->u.dhSignedData);
1537 else if (p->choice == choice_pa_pk_as_rep_draft9_encKeyPack)
1538 ktest_empty_data(&p->u.encKeyPack);
1539 p->choice = choice_pa_pk_as_rep_draft9_UNKNOWN;
1543 ktest_empty_auth_pack(krb5_auth_pack *p)
1545 krb5_algorithm_identifier **ai;
1548 ktest_empty_pk_authenticator(&p->pkAuthenticator);
1549 if (p->clientPublicValue != NULL) {
1550 ktest_empty_subject_pk_info(p->clientPublicValue);
1551 free(p->clientPublicValue);
1552 p->clientPublicValue = NULL;
1554 if (p->supportedCMSTypes != NULL) {
1555 for (ai = p->supportedCMSTypes; *ai != NULL; ai++) {
1556 ktest_empty_algorithm_identifier(*ai);
1559 free(p->supportedCMSTypes);
1560 p->supportedCMSTypes = NULL;
1562 ktest_empty_data(&p->clientDHNonce);
1563 if (p->supportedKDFs != NULL) {
1564 for (d = p->supportedKDFs; *d != NULL; d++) {
1565 ktest_empty_data(*d);
1568 free(p->supportedKDFs);
1569 p->supportedKDFs = NULL;
1574 ktest_empty_auth_pack_draft9(krb5_auth_pack_draft9 *p)
1576 ktest_empty_pk_authenticator_draft9(&p->pkAuthenticator);
1577 if (p->clientPublicValue != NULL) {
1578 ktest_empty_subject_pk_info(p->clientPublicValue);
1579 free(p->clientPublicValue);
1580 p->clientPublicValue = NULL;
1585 ktest_empty_kdc_dh_key_info(krb5_kdc_dh_key_info *p)
1587 ktest_empty_data(&p->subjectPublicKey);
1591 ktest_empty_reply_key_pack(krb5_reply_key_pack *p)
1593 ktest_empty_keyblock(&p->replyKey);
1594 ktest_empty_checksum(&p->asChecksum);
1598 ktest_empty_reply_key_pack_draft9(krb5_reply_key_pack_draft9 *p)
1600 ktest_empty_keyblock(&p->replyKey);
1603 void ktest_empty_sp80056a_other_info(krb5_sp80056a_other_info *p)
1605 ktest_empty_algorithm_identifier(&p->algorithm_identifier);
1606 ktest_destroy_principal(&p->party_u_info);
1607 ktest_destroy_principal(&p->party_v_info);
1608 ktest_empty_data(&p->supp_pub_info);
1611 void ktest_empty_pkinit_supp_pub_info(krb5_pkinit_supp_pub_info *p)
1613 ktest_empty_data(&p->as_req);
1614 ktest_empty_data(&p->pk_as_rep);
1617 #endif /* not DISABLE_PKINIT */
1621 ktest_empty_ldap_seqof_key_data(krb5_context ctx, ldap_seqof_key_data *p)
1625 for (i = 0; i < p->n_key_data; i++) {
1626 free(p->key_data[i].key_data_contents[0]);
1627 free(p->key_data[i].key_data_contents[1]);