xref: /freebsd/crypto/krb5/src/tests/asn.1/ktest.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert /* tests/asn.1/ktest.c */
3*7f2fe78bSCy Schubert /*
4*7f2fe78bSCy Schubert  * Copyright (C) 1994 by the Massachusetts Institute of Technology.
5*7f2fe78bSCy Schubert  * All rights reserved.
6*7f2fe78bSCy Schubert  *
7*7f2fe78bSCy Schubert  * Export of this software from the United States of America may
8*7f2fe78bSCy Schubert  *   require a specific license from the United States Government.
9*7f2fe78bSCy Schubert  *   It is the responsibility of any person or organization contemplating
10*7f2fe78bSCy Schubert  *   export to obtain such a license before exporting.
11*7f2fe78bSCy Schubert  *
12*7f2fe78bSCy Schubert  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13*7f2fe78bSCy Schubert  * distribute this software and its documentation for any purpose and
14*7f2fe78bSCy Schubert  * without fee is hereby granted, provided that the above copyright
15*7f2fe78bSCy Schubert  * notice appear in all copies and that both that copyright notice and
16*7f2fe78bSCy Schubert  * this permission notice appear in supporting documentation, and that
17*7f2fe78bSCy Schubert  * the name of M.I.T. not be used in advertising or publicity pertaining
18*7f2fe78bSCy Schubert  * to distribution of the software without specific, written prior
19*7f2fe78bSCy Schubert  * permission.  Furthermore if you modify this software you must label
20*7f2fe78bSCy Schubert  * your software as modified software and not distribute it in such a
21*7f2fe78bSCy Schubert  * fashion that it might be confused with the original M.I.T. software.
22*7f2fe78bSCy Schubert  * M.I.T. makes no representations about the suitability of
23*7f2fe78bSCy Schubert  * this software for any purpose.  It is provided "as is" without express
24*7f2fe78bSCy Schubert  * or implied warranty.
25*7f2fe78bSCy Schubert  */
26*7f2fe78bSCy Schubert 
27*7f2fe78bSCy Schubert #include "ktest.h"
28*7f2fe78bSCy Schubert #include "utility.h"
29*7f2fe78bSCy Schubert #include <stdlib.h>
30*7f2fe78bSCy Schubert 
31*7f2fe78bSCy Schubert char *sample_principal_name = "hftsai/extra@ATHENA.MIT.EDU";
32*7f2fe78bSCy Schubert 
33*7f2fe78bSCy Schubert void
ktest_make_sample_authenticator(krb5_authenticator * a)34*7f2fe78bSCy Schubert ktest_make_sample_authenticator(krb5_authenticator *a)
35*7f2fe78bSCy Schubert {
36*7f2fe78bSCy Schubert     ktest_make_sample_principal(&a->client);
37*7f2fe78bSCy Schubert     a->checksum = ealloc(sizeof(krb5_checksum));
38*7f2fe78bSCy Schubert     ktest_make_sample_checksum(a->checksum);
39*7f2fe78bSCy Schubert     a->cusec = SAMPLE_USEC;
40*7f2fe78bSCy Schubert     a->ctime = SAMPLE_TIME;
41*7f2fe78bSCy Schubert     a->subkey = ealloc(sizeof(krb5_keyblock));
42*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(a->subkey);
43*7f2fe78bSCy Schubert     a->seq_number = SAMPLE_SEQ_NUMBER;
44*7f2fe78bSCy Schubert     ktest_make_sample_authorization_data(&a->authorization_data);
45*7f2fe78bSCy Schubert }
46*7f2fe78bSCy Schubert 
47*7f2fe78bSCy Schubert void
ktest_make_sample_principal(krb5_principal * p)48*7f2fe78bSCy Schubert ktest_make_sample_principal(krb5_principal *p)
49*7f2fe78bSCy Schubert {
50*7f2fe78bSCy Schubert     if (krb5_parse_name(test_context, sample_principal_name, p))
51*7f2fe78bSCy Schubert         abort();
52*7f2fe78bSCy Schubert }
53*7f2fe78bSCy Schubert 
54*7f2fe78bSCy Schubert void
ktest_make_sample_checksum(krb5_checksum * cs)55*7f2fe78bSCy Schubert ktest_make_sample_checksum(krb5_checksum *cs)
56*7f2fe78bSCy Schubert {
57*7f2fe78bSCy Schubert     cs->checksum_type = 1;
58*7f2fe78bSCy Schubert     cs->length = 4;
59*7f2fe78bSCy Schubert     cs->contents = ealloc(4);
60*7f2fe78bSCy Schubert     memcpy(cs->contents,"1234",4);
61*7f2fe78bSCy Schubert }
62*7f2fe78bSCy Schubert 
63*7f2fe78bSCy Schubert void
ktest_make_sample_keyblock(krb5_keyblock * kb)64*7f2fe78bSCy Schubert ktest_make_sample_keyblock(krb5_keyblock *kb)
65*7f2fe78bSCy Schubert {
66*7f2fe78bSCy Schubert     kb->magic = KV5M_KEYBLOCK;
67*7f2fe78bSCy Schubert     kb->enctype = 1;
68*7f2fe78bSCy Schubert     kb->length = 8;
69*7f2fe78bSCy Schubert     kb->contents = ealloc(8);
70*7f2fe78bSCy Schubert     memcpy(kb->contents,"12345678",8);
71*7f2fe78bSCy Schubert }
72*7f2fe78bSCy Schubert 
73*7f2fe78bSCy Schubert void
ktest_make_sample_ticket(krb5_ticket * tkt)74*7f2fe78bSCy Schubert ktest_make_sample_ticket(krb5_ticket *tkt)
75*7f2fe78bSCy Schubert {
76*7f2fe78bSCy Schubert     ktest_make_sample_principal(&tkt->server);
77*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&tkt->enc_part);
78*7f2fe78bSCy Schubert     tkt->enc_part2 = NULL;
79*7f2fe78bSCy Schubert }
80*7f2fe78bSCy Schubert 
81*7f2fe78bSCy Schubert void
ktest_make_sample_enc_data(krb5_enc_data * ed)82*7f2fe78bSCy Schubert ktest_make_sample_enc_data(krb5_enc_data *ed)
83*7f2fe78bSCy Schubert {
84*7f2fe78bSCy Schubert     ed->kvno = 5;
85*7f2fe78bSCy Schubert     ed->enctype = 0;
86*7f2fe78bSCy Schubert     krb5_data_parse(&ed->ciphertext, "krbASN.1 test message");
87*7f2fe78bSCy Schubert }
88*7f2fe78bSCy Schubert 
89*7f2fe78bSCy Schubert void
ktest_make_sample_enc_tkt_part(krb5_enc_tkt_part * etp)90*7f2fe78bSCy Schubert ktest_make_sample_enc_tkt_part(krb5_enc_tkt_part *etp)
91*7f2fe78bSCy Schubert {
92*7f2fe78bSCy Schubert     etp->flags = SAMPLE_FLAGS;
93*7f2fe78bSCy Schubert     etp->session = ealloc(sizeof(krb5_keyblock));
94*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(etp->session);
95*7f2fe78bSCy Schubert     ktest_make_sample_principal(&etp->client);
96*7f2fe78bSCy Schubert     ktest_make_sample_transited(&etp->transited);
97*7f2fe78bSCy Schubert     ktest_make_sample_ticket_times(&etp->times);
98*7f2fe78bSCy Schubert     ktest_make_sample_addresses(&etp->caddrs);
99*7f2fe78bSCy Schubert     ktest_make_sample_authorization_data(&etp->authorization_data);
100*7f2fe78bSCy Schubert }
101*7f2fe78bSCy Schubert 
102*7f2fe78bSCy Schubert void
ktest_make_sample_addresses(krb5_address *** caddrs)103*7f2fe78bSCy Schubert ktest_make_sample_addresses(krb5_address ***caddrs)
104*7f2fe78bSCy Schubert {
105*7f2fe78bSCy Schubert     int i;
106*7f2fe78bSCy Schubert 
107*7f2fe78bSCy Schubert     *caddrs = ealloc(3 * sizeof(krb5_address *));
108*7f2fe78bSCy Schubert     for (i = 0; i < 2; i++) {
109*7f2fe78bSCy Schubert         (*caddrs)[i] = ealloc(sizeof(krb5_address));
110*7f2fe78bSCy Schubert         ktest_make_sample_address((*caddrs)[i]);
111*7f2fe78bSCy Schubert     }
112*7f2fe78bSCy Schubert     (*caddrs)[2] = NULL;
113*7f2fe78bSCy Schubert }
114*7f2fe78bSCy Schubert 
115*7f2fe78bSCy Schubert void
ktest_make_sample_authorization_data(krb5_authdata *** ad)116*7f2fe78bSCy Schubert ktest_make_sample_authorization_data(krb5_authdata ***ad)
117*7f2fe78bSCy Schubert {
118*7f2fe78bSCy Schubert     int i;
119*7f2fe78bSCy Schubert 
120*7f2fe78bSCy Schubert     *ad = ealloc(3 * sizeof(krb5_authdata *));
121*7f2fe78bSCy Schubert     for (i = 0; i <= 1; i++) {
122*7f2fe78bSCy Schubert         (*ad)[i] = ealloc(sizeof(krb5_authdata));
123*7f2fe78bSCy Schubert         ktest_make_sample_authdata((*ad)[i]);
124*7f2fe78bSCy Schubert     }
125*7f2fe78bSCy Schubert     (*ad)[2] = NULL;
126*7f2fe78bSCy Schubert }
127*7f2fe78bSCy Schubert 
128*7f2fe78bSCy Schubert void
ktest_make_sample_transited(krb5_transited * t)129*7f2fe78bSCy Schubert ktest_make_sample_transited(krb5_transited *t)
130*7f2fe78bSCy Schubert {
131*7f2fe78bSCy Schubert     t->tr_type = 1;
132*7f2fe78bSCy Schubert     krb5_data_parse(&t->tr_contents, "EDU,MIT.,ATHENA.,WASHINGTON.EDU,CS.");
133*7f2fe78bSCy Schubert }
134*7f2fe78bSCy Schubert 
135*7f2fe78bSCy Schubert void
ktest_make_sample_ticket_times(krb5_ticket_times * tt)136*7f2fe78bSCy Schubert ktest_make_sample_ticket_times(krb5_ticket_times *tt)
137*7f2fe78bSCy Schubert {
138*7f2fe78bSCy Schubert     tt->authtime = SAMPLE_TIME;
139*7f2fe78bSCy Schubert     tt->starttime = SAMPLE_TIME;
140*7f2fe78bSCy Schubert     tt->endtime = SAMPLE_TIME;
141*7f2fe78bSCy Schubert     tt->renew_till = SAMPLE_TIME;
142*7f2fe78bSCy Schubert }
143*7f2fe78bSCy Schubert 
144*7f2fe78bSCy Schubert void
ktest_make_sample_address(krb5_address * a)145*7f2fe78bSCy Schubert ktest_make_sample_address(krb5_address *a)
146*7f2fe78bSCy Schubert {
147*7f2fe78bSCy Schubert     a->addrtype = ADDRTYPE_INET;
148*7f2fe78bSCy Schubert     a->length = 4;
149*7f2fe78bSCy Schubert     a->contents = ealloc(4 * sizeof(krb5_octet));
150*7f2fe78bSCy Schubert     a->contents[0] = 18;
151*7f2fe78bSCy Schubert     a->contents[1] = 208;
152*7f2fe78bSCy Schubert     a->contents[2] = 0;
153*7f2fe78bSCy Schubert     a->contents[3] = 35;
154*7f2fe78bSCy Schubert }
155*7f2fe78bSCy Schubert 
156*7f2fe78bSCy Schubert void
ktest_make_sample_authdata(krb5_authdata * ad)157*7f2fe78bSCy Schubert ktest_make_sample_authdata(krb5_authdata *ad)
158*7f2fe78bSCy Schubert {
159*7f2fe78bSCy Schubert     ad->ad_type = 1;
160*7f2fe78bSCy Schubert     ad->length = 6;
161*7f2fe78bSCy Schubert     ad->contents = ealloc(6 * sizeof(krb5_octet));
162*7f2fe78bSCy Schubert     memcpy(ad->contents, "foobar", 6);
163*7f2fe78bSCy Schubert }
164*7f2fe78bSCy Schubert 
165*7f2fe78bSCy Schubert void
ktest_make_sample_enc_kdc_rep_part(krb5_enc_kdc_rep_part * ekr)166*7f2fe78bSCy Schubert ktest_make_sample_enc_kdc_rep_part(krb5_enc_kdc_rep_part *ekr)
167*7f2fe78bSCy Schubert {
168*7f2fe78bSCy Schubert     ekr->session = ealloc(sizeof(krb5_keyblock));
169*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(ekr->session);
170*7f2fe78bSCy Schubert     ktest_make_sample_last_req(&ekr->last_req);
171*7f2fe78bSCy Schubert     ekr->nonce = SAMPLE_NONCE;
172*7f2fe78bSCy Schubert     ekr->key_exp = SAMPLE_TIME;
173*7f2fe78bSCy Schubert     ekr->flags = SAMPLE_FLAGS;
174*7f2fe78bSCy Schubert     ekr->times.authtime = SAMPLE_TIME;
175*7f2fe78bSCy Schubert     ekr->times.starttime = SAMPLE_TIME;
176*7f2fe78bSCy Schubert     ekr->times.endtime = SAMPLE_TIME;
177*7f2fe78bSCy Schubert     ekr->times.renew_till = SAMPLE_TIME;
178*7f2fe78bSCy Schubert     ktest_make_sample_principal(&ekr->server);
179*7f2fe78bSCy Schubert     ktest_make_sample_addresses(&ekr->caddrs);
180*7f2fe78bSCy Schubert }
181*7f2fe78bSCy Schubert 
182*7f2fe78bSCy Schubert void
ktest_make_sample_last_req(krb5_last_req_entry *** lr)183*7f2fe78bSCy Schubert ktest_make_sample_last_req(krb5_last_req_entry ***lr)
184*7f2fe78bSCy Schubert {
185*7f2fe78bSCy Schubert     int i;
186*7f2fe78bSCy Schubert 
187*7f2fe78bSCy Schubert     *lr = ealloc(3 * sizeof(krb5_last_req_entry *));
188*7f2fe78bSCy Schubert     for (i = 0; i <= 1; i++)
189*7f2fe78bSCy Schubert         ktest_make_sample_last_req_entry(&(*lr)[i]);
190*7f2fe78bSCy Schubert     (*lr)[2] = NULL;
191*7f2fe78bSCy Schubert }
192*7f2fe78bSCy Schubert 
193*7f2fe78bSCy Schubert void
ktest_make_sample_last_req_entry(krb5_last_req_entry ** lre)194*7f2fe78bSCy Schubert ktest_make_sample_last_req_entry(krb5_last_req_entry **lre)
195*7f2fe78bSCy Schubert {
196*7f2fe78bSCy Schubert     *lre = ealloc(sizeof(krb5_last_req_entry));
197*7f2fe78bSCy Schubert     (*lre)->lr_type = -5;
198*7f2fe78bSCy Schubert     (*lre)->value = SAMPLE_TIME;
199*7f2fe78bSCy Schubert }
200*7f2fe78bSCy Schubert 
201*7f2fe78bSCy Schubert void
ktest_make_sample_kdc_rep(krb5_kdc_rep * kdcr)202*7f2fe78bSCy Schubert ktest_make_sample_kdc_rep(krb5_kdc_rep *kdcr)
203*7f2fe78bSCy Schubert {
204*7f2fe78bSCy Schubert     ktest_make_sample_pa_data_array(&kdcr->padata);
205*7f2fe78bSCy Schubert     ktest_make_sample_principal(&kdcr->client);
206*7f2fe78bSCy Schubert     kdcr->ticket = ealloc(sizeof(krb5_ticket));
207*7f2fe78bSCy Schubert     ktest_make_sample_ticket(kdcr->ticket);
208*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&kdcr->enc_part);
209*7f2fe78bSCy Schubert     kdcr->enc_part2 = NULL;
210*7f2fe78bSCy Schubert }
211*7f2fe78bSCy Schubert 
212*7f2fe78bSCy Schubert void
ktest_make_sample_pa_data_array(krb5_pa_data *** pad)213*7f2fe78bSCy Schubert ktest_make_sample_pa_data_array(krb5_pa_data ***pad)
214*7f2fe78bSCy Schubert {
215*7f2fe78bSCy Schubert     int i;
216*7f2fe78bSCy Schubert 
217*7f2fe78bSCy Schubert     *pad = ealloc(3 * sizeof(krb5_pa_data *));
218*7f2fe78bSCy Schubert     for (i = 0; i <= 1; i++) {
219*7f2fe78bSCy Schubert         (*pad)[i] = ealloc(sizeof(krb5_pa_data));
220*7f2fe78bSCy Schubert         ktest_make_sample_pa_data((*pad)[i]);
221*7f2fe78bSCy Schubert     }
222*7f2fe78bSCy Schubert     (*pad)[2] = NULL;
223*7f2fe78bSCy Schubert }
224*7f2fe78bSCy Schubert 
225*7f2fe78bSCy Schubert void
ktest_make_sample_empty_pa_data_array(krb5_pa_data *** pad)226*7f2fe78bSCy Schubert ktest_make_sample_empty_pa_data_array(krb5_pa_data ***pad)
227*7f2fe78bSCy Schubert {
228*7f2fe78bSCy Schubert     *pad = ealloc(sizeof(krb5_pa_data *));
229*7f2fe78bSCy Schubert     (*pad)[0] = NULL;
230*7f2fe78bSCy Schubert }
231*7f2fe78bSCy Schubert 
232*7f2fe78bSCy Schubert void
ktest_make_sample_pa_data(krb5_pa_data * pad)233*7f2fe78bSCy Schubert ktest_make_sample_pa_data(krb5_pa_data *pad)
234*7f2fe78bSCy Schubert {
235*7f2fe78bSCy Schubert     pad->pa_type = 13;
236*7f2fe78bSCy Schubert     pad->length = 7;
237*7f2fe78bSCy Schubert     pad->contents = ealloc(7);
238*7f2fe78bSCy Schubert     memcpy(pad->contents, "pa-data", 7);
239*7f2fe78bSCy Schubert }
240*7f2fe78bSCy Schubert 
241*7f2fe78bSCy Schubert void
ktest_make_sample_ap_req(krb5_ap_req * ar)242*7f2fe78bSCy Schubert ktest_make_sample_ap_req(krb5_ap_req *ar)
243*7f2fe78bSCy Schubert {
244*7f2fe78bSCy Schubert     ar->ap_options = SAMPLE_FLAGS;
245*7f2fe78bSCy Schubert     ar->ticket = ealloc(sizeof(krb5_ticket));
246*7f2fe78bSCy Schubert     ktest_make_sample_ticket(ar->ticket);
247*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&(ar->authenticator));
248*7f2fe78bSCy Schubert }
249*7f2fe78bSCy Schubert 
250*7f2fe78bSCy Schubert void
ktest_make_sample_ap_rep(krb5_ap_rep * ar)251*7f2fe78bSCy Schubert ktest_make_sample_ap_rep(krb5_ap_rep *ar)
252*7f2fe78bSCy Schubert {
253*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&ar->enc_part);
254*7f2fe78bSCy Schubert }
255*7f2fe78bSCy Schubert 
256*7f2fe78bSCy Schubert void
ktest_make_sample_ap_rep_enc_part(krb5_ap_rep_enc_part * arep)257*7f2fe78bSCy Schubert ktest_make_sample_ap_rep_enc_part(krb5_ap_rep_enc_part *arep)
258*7f2fe78bSCy Schubert {
259*7f2fe78bSCy Schubert     arep->ctime = SAMPLE_TIME;
260*7f2fe78bSCy Schubert     arep->cusec = SAMPLE_USEC;
261*7f2fe78bSCy Schubert     arep->subkey = ealloc(sizeof(krb5_keyblock));
262*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(arep->subkey);
263*7f2fe78bSCy Schubert     arep->seq_number = SAMPLE_SEQ_NUMBER;
264*7f2fe78bSCy Schubert }
265*7f2fe78bSCy Schubert 
266*7f2fe78bSCy Schubert void
ktest_make_sample_kdc_req(krb5_kdc_req * kr)267*7f2fe78bSCy Schubert ktest_make_sample_kdc_req(krb5_kdc_req *kr)
268*7f2fe78bSCy Schubert {
269*7f2fe78bSCy Schubert     /* msg_type is left up to the calling procedure */
270*7f2fe78bSCy Schubert     ktest_make_sample_pa_data_array(&kr->padata);
271*7f2fe78bSCy Schubert     kr->kdc_options = SAMPLE_FLAGS;
272*7f2fe78bSCy Schubert     ktest_make_sample_principal(&(kr->client));
273*7f2fe78bSCy Schubert     ktest_make_sample_principal(&(kr->server));
274*7f2fe78bSCy Schubert     kr->from = SAMPLE_TIME;
275*7f2fe78bSCy Schubert     kr->till = SAMPLE_TIME;
276*7f2fe78bSCy Schubert     kr->rtime = SAMPLE_TIME;
277*7f2fe78bSCy Schubert     kr->nonce = SAMPLE_NONCE;
278*7f2fe78bSCy Schubert     kr->nktypes = 2;
279*7f2fe78bSCy Schubert     kr->ktype = ealloc(2 * sizeof(krb5_enctype));
280*7f2fe78bSCy Schubert     kr->ktype[0] = 0;
281*7f2fe78bSCy Schubert     kr->ktype[1] = 1;
282*7f2fe78bSCy Schubert     ktest_make_sample_addresses(&kr->addresses);
283*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&kr->authorization_data);
284*7f2fe78bSCy Schubert     ktest_make_sample_authorization_data(&kr->unenc_authdata);
285*7f2fe78bSCy Schubert     ktest_make_sample_sequence_of_ticket(&kr->second_ticket);
286*7f2fe78bSCy Schubert }
287*7f2fe78bSCy Schubert 
288*7f2fe78bSCy Schubert void
ktest_make_sample_kdc_req_body(krb5_kdc_req * krb)289*7f2fe78bSCy Schubert ktest_make_sample_kdc_req_body(krb5_kdc_req *krb)
290*7f2fe78bSCy Schubert {
291*7f2fe78bSCy Schubert     krb->kdc_options = SAMPLE_FLAGS;
292*7f2fe78bSCy Schubert     ktest_make_sample_principal(&krb->client);
293*7f2fe78bSCy Schubert     ktest_make_sample_principal(&krb->server);
294*7f2fe78bSCy Schubert     krb->from = SAMPLE_TIME;
295*7f2fe78bSCy Schubert     krb->till = SAMPLE_TIME;
296*7f2fe78bSCy Schubert     krb->rtime = SAMPLE_TIME;
297*7f2fe78bSCy Schubert     krb->nonce = SAMPLE_NONCE;
298*7f2fe78bSCy Schubert     krb->nktypes = 2;
299*7f2fe78bSCy Schubert     krb->ktype = (krb5_enctype*)calloc(2,sizeof(krb5_enctype));
300*7f2fe78bSCy Schubert     krb->ktype[0] = 0;
301*7f2fe78bSCy Schubert     krb->ktype[1] = 1;
302*7f2fe78bSCy Schubert     ktest_make_sample_addresses(&krb->addresses);
303*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&krb->authorization_data);
304*7f2fe78bSCy Schubert     ktest_make_sample_authorization_data(&krb->unenc_authdata);
305*7f2fe78bSCy Schubert     ktest_make_sample_sequence_of_ticket(&krb->second_ticket);
306*7f2fe78bSCy Schubert }
307*7f2fe78bSCy Schubert 
308*7f2fe78bSCy Schubert void
ktest_make_sample_safe(krb5_safe * s)309*7f2fe78bSCy Schubert ktest_make_sample_safe(krb5_safe *s)
310*7f2fe78bSCy Schubert {
311*7f2fe78bSCy Schubert     ktest_make_sample_data(&s->user_data);
312*7f2fe78bSCy Schubert     s->timestamp = SAMPLE_TIME;
313*7f2fe78bSCy Schubert     s->usec = SAMPLE_USEC;
314*7f2fe78bSCy Schubert     s->seq_number = SAMPLE_SEQ_NUMBER;
315*7f2fe78bSCy Schubert     s->s_address = ealloc(sizeof(krb5_address));
316*7f2fe78bSCy Schubert     ktest_make_sample_address(s->s_address);
317*7f2fe78bSCy Schubert     s->r_address = ealloc(sizeof(krb5_address));
318*7f2fe78bSCy Schubert     ktest_make_sample_address(s->r_address);
319*7f2fe78bSCy Schubert     s->checksum = ealloc(sizeof(krb5_checksum));
320*7f2fe78bSCy Schubert     ktest_make_sample_checksum(s->checksum);
321*7f2fe78bSCy Schubert }
322*7f2fe78bSCy Schubert 
323*7f2fe78bSCy Schubert void
ktest_make_sample_priv(krb5_priv * p)324*7f2fe78bSCy Schubert ktest_make_sample_priv(krb5_priv *p)
325*7f2fe78bSCy Schubert {
326*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&p->enc_part);
327*7f2fe78bSCy Schubert }
328*7f2fe78bSCy Schubert 
329*7f2fe78bSCy Schubert void
ktest_make_sample_priv_enc_part(krb5_priv_enc_part * pep)330*7f2fe78bSCy Schubert ktest_make_sample_priv_enc_part(krb5_priv_enc_part *pep)
331*7f2fe78bSCy Schubert {
332*7f2fe78bSCy Schubert     ktest_make_sample_data(&(pep->user_data));
333*7f2fe78bSCy Schubert     pep->timestamp = SAMPLE_TIME;
334*7f2fe78bSCy Schubert     pep->usec = SAMPLE_USEC;
335*7f2fe78bSCy Schubert     pep->seq_number = SAMPLE_SEQ_NUMBER;
336*7f2fe78bSCy Schubert     pep->s_address = ealloc(sizeof(krb5_address));
337*7f2fe78bSCy Schubert     ktest_make_sample_address(pep->s_address);
338*7f2fe78bSCy Schubert     pep->r_address = ealloc(sizeof(krb5_address));
339*7f2fe78bSCy Schubert     ktest_make_sample_address(pep->r_address);
340*7f2fe78bSCy Schubert }
341*7f2fe78bSCy Schubert 
342*7f2fe78bSCy Schubert void
ktest_make_sample_cred(krb5_cred * c)343*7f2fe78bSCy Schubert ktest_make_sample_cred(krb5_cred *c)
344*7f2fe78bSCy Schubert {
345*7f2fe78bSCy Schubert     ktest_make_sample_sequence_of_ticket(&c->tickets);
346*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&c->enc_part);
347*7f2fe78bSCy Schubert }
348*7f2fe78bSCy Schubert 
349*7f2fe78bSCy Schubert void
ktest_make_sample_sequence_of_ticket(krb5_ticket *** sot)350*7f2fe78bSCy Schubert ktest_make_sample_sequence_of_ticket(krb5_ticket ***sot)
351*7f2fe78bSCy Schubert {
352*7f2fe78bSCy Schubert     int i;
353*7f2fe78bSCy Schubert 
354*7f2fe78bSCy Schubert     *sot = ealloc(3 * sizeof(krb5_ticket *));
355*7f2fe78bSCy Schubert     for (i = 0; i < 2; i++) {
356*7f2fe78bSCy Schubert         (*sot)[i] = ealloc(sizeof(krb5_ticket));
357*7f2fe78bSCy Schubert         ktest_make_sample_ticket((*sot)[i]);
358*7f2fe78bSCy Schubert     }
359*7f2fe78bSCy Schubert     (*sot)[2] = NULL;
360*7f2fe78bSCy Schubert }
361*7f2fe78bSCy Schubert 
362*7f2fe78bSCy Schubert void
ktest_make_sample_cred_enc_part(krb5_cred_enc_part * cep)363*7f2fe78bSCy Schubert ktest_make_sample_cred_enc_part(krb5_cred_enc_part *cep)
364*7f2fe78bSCy Schubert {
365*7f2fe78bSCy Schubert     cep->nonce = SAMPLE_NONCE;
366*7f2fe78bSCy Schubert     cep->timestamp = SAMPLE_TIME;
367*7f2fe78bSCy Schubert     cep->usec = SAMPLE_USEC;
368*7f2fe78bSCy Schubert     cep->s_address = ealloc(sizeof(krb5_address));
369*7f2fe78bSCy Schubert     ktest_make_sample_address(cep->s_address);
370*7f2fe78bSCy Schubert     cep->r_address = ealloc(sizeof(krb5_address));
371*7f2fe78bSCy Schubert     ktest_make_sample_address(cep->r_address);
372*7f2fe78bSCy Schubert     ktest_make_sequence_of_cred_info(&cep->ticket_info);
373*7f2fe78bSCy Schubert }
374*7f2fe78bSCy Schubert 
375*7f2fe78bSCy Schubert void
ktest_make_sequence_of_cred_info(krb5_cred_info *** soci)376*7f2fe78bSCy Schubert ktest_make_sequence_of_cred_info(krb5_cred_info ***soci)
377*7f2fe78bSCy Schubert {
378*7f2fe78bSCy Schubert     int i;
379*7f2fe78bSCy Schubert 
380*7f2fe78bSCy Schubert     *soci = ealloc(3 * sizeof(krb5_cred_info *));
381*7f2fe78bSCy Schubert     for (i = 0; i < 2; i++) {
382*7f2fe78bSCy Schubert         (*soci)[i] = ealloc(sizeof(krb5_cred_info));
383*7f2fe78bSCy Schubert         ktest_make_sample_cred_info((*soci)[i]);
384*7f2fe78bSCy Schubert     }
385*7f2fe78bSCy Schubert     (*soci)[2] = NULL;
386*7f2fe78bSCy Schubert }
387*7f2fe78bSCy Schubert 
388*7f2fe78bSCy Schubert void
ktest_make_sample_cred_info(krb5_cred_info * ci)389*7f2fe78bSCy Schubert ktest_make_sample_cred_info(krb5_cred_info *ci)
390*7f2fe78bSCy Schubert {
391*7f2fe78bSCy Schubert     ci->session = ealloc(sizeof(krb5_keyblock));
392*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(ci->session);
393*7f2fe78bSCy Schubert     ktest_make_sample_principal(&ci->client);
394*7f2fe78bSCy Schubert     ktest_make_sample_principal(&ci->server);
395*7f2fe78bSCy Schubert     ci->flags = SAMPLE_FLAGS;
396*7f2fe78bSCy Schubert     ci->times.authtime = SAMPLE_TIME;
397*7f2fe78bSCy Schubert     ci->times.starttime = SAMPLE_TIME;
398*7f2fe78bSCy Schubert     ci->times.endtime = SAMPLE_TIME;
399*7f2fe78bSCy Schubert     ci->times.renew_till = SAMPLE_TIME;
400*7f2fe78bSCy Schubert     ktest_make_sample_addresses(&ci->caddrs);
401*7f2fe78bSCy Schubert }
402*7f2fe78bSCy Schubert 
403*7f2fe78bSCy Schubert void
ktest_make_sample_error(krb5_error * kerr)404*7f2fe78bSCy Schubert ktest_make_sample_error(krb5_error *kerr)
405*7f2fe78bSCy Schubert {
406*7f2fe78bSCy Schubert     kerr->ctime = SAMPLE_TIME;
407*7f2fe78bSCy Schubert     kerr->cusec = SAMPLE_USEC;
408*7f2fe78bSCy Schubert     kerr->susec = SAMPLE_USEC;
409*7f2fe78bSCy Schubert     kerr->stime = SAMPLE_TIME;
410*7f2fe78bSCy Schubert     kerr->error = SAMPLE_ERROR;
411*7f2fe78bSCy Schubert     ktest_make_sample_principal(&kerr->client);
412*7f2fe78bSCy Schubert     ktest_make_sample_principal(&kerr->server);
413*7f2fe78bSCy Schubert     ktest_make_sample_data(&kerr->text);
414*7f2fe78bSCy Schubert     ktest_make_sample_data(&kerr->e_data);
415*7f2fe78bSCy Schubert }
416*7f2fe78bSCy Schubert 
417*7f2fe78bSCy Schubert void
ktest_make_sample_data(krb5_data * d)418*7f2fe78bSCy Schubert ktest_make_sample_data(krb5_data *d)
419*7f2fe78bSCy Schubert {
420*7f2fe78bSCy Schubert     krb5_data_parse(d, "krb5data");
421*7f2fe78bSCy Schubert }
422*7f2fe78bSCy Schubert 
423*7f2fe78bSCy Schubert void
ktest_make_sample_etype_info(krb5_etype_info_entry *** p)424*7f2fe78bSCy Schubert ktest_make_sample_etype_info(krb5_etype_info_entry ***p)
425*7f2fe78bSCy Schubert {
426*7f2fe78bSCy Schubert     krb5_etype_info_entry **info;
427*7f2fe78bSCy Schubert     int i, len;
428*7f2fe78bSCy Schubert     char *str;
429*7f2fe78bSCy Schubert 
430*7f2fe78bSCy Schubert     info = ealloc(4 * sizeof(krb5_etype_info_entry *));
431*7f2fe78bSCy Schubert     for (i = 0; i < 3; i++) {
432*7f2fe78bSCy Schubert         info[i] = ealloc(sizeof(krb5_etype_info_entry));
433*7f2fe78bSCy Schubert         info[i]->etype = i;
434*7f2fe78bSCy Schubert         len = asprintf(&str, "Morton's #%d", i);
435*7f2fe78bSCy Schubert         if (len < 0)
436*7f2fe78bSCy Schubert             abort();
437*7f2fe78bSCy Schubert         info[i]->salt = (krb5_octet *)str;
438*7f2fe78bSCy Schubert         info[i]->length = len;
439*7f2fe78bSCy Schubert         info[i]->s2kparams.data = NULL;
440*7f2fe78bSCy Schubert         info[i]->s2kparams.length = 0;
441*7f2fe78bSCy Schubert         info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
442*7f2fe78bSCy Schubert     }
443*7f2fe78bSCy Schubert     free(info[1]->salt);
444*7f2fe78bSCy Schubert     info[1]->length = KRB5_ETYPE_NO_SALT;
445*7f2fe78bSCy Schubert     info[1]->salt = 0;
446*7f2fe78bSCy Schubert     *p = info;
447*7f2fe78bSCy Schubert }
448*7f2fe78bSCy Schubert 
449*7f2fe78bSCy Schubert 
450*7f2fe78bSCy Schubert void
ktest_make_sample_etype_info2(krb5_etype_info_entry *** p)451*7f2fe78bSCy Schubert ktest_make_sample_etype_info2(krb5_etype_info_entry ***p)
452*7f2fe78bSCy Schubert {
453*7f2fe78bSCy Schubert     krb5_etype_info_entry **info;
454*7f2fe78bSCy Schubert     int i, len;
455*7f2fe78bSCy Schubert     char *str;
456*7f2fe78bSCy Schubert 
457*7f2fe78bSCy Schubert     info = ealloc(4 * sizeof(krb5_etype_info_entry *));
458*7f2fe78bSCy Schubert     for (i = 0; i < 3; i++) {
459*7f2fe78bSCy Schubert         info[i] = ealloc(sizeof(krb5_etype_info_entry));
460*7f2fe78bSCy Schubert         info[i]->etype = i;
461*7f2fe78bSCy Schubert         len = asprintf(&str, "Morton's #%d", i);
462*7f2fe78bSCy Schubert         if (len < 0)
463*7f2fe78bSCy Schubert             abort();
464*7f2fe78bSCy Schubert         info[i]->salt = (krb5_octet *)str;
465*7f2fe78bSCy Schubert         info[i]->length = (unsigned int)len;
466*7f2fe78bSCy Schubert         len = asprintf(&info[i]->s2kparams.data, "s2k: %d", i);
467*7f2fe78bSCy Schubert         if (len < 0)
468*7f2fe78bSCy Schubert             abort();
469*7f2fe78bSCy Schubert         info[i]->s2kparams.length = (unsigned int) len;
470*7f2fe78bSCy Schubert         info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
471*7f2fe78bSCy Schubert     }
472*7f2fe78bSCy Schubert     free(info[1]->salt);
473*7f2fe78bSCy Schubert     info[1]->length = KRB5_ETYPE_NO_SALT;
474*7f2fe78bSCy Schubert     info[1]->salt = 0;
475*7f2fe78bSCy Schubert     *p = info;
476*7f2fe78bSCy Schubert }
477*7f2fe78bSCy Schubert 
478*7f2fe78bSCy Schubert 
479*7f2fe78bSCy Schubert void
ktest_make_sample_pa_enc_ts(krb5_pa_enc_ts * pa_enc)480*7f2fe78bSCy Schubert ktest_make_sample_pa_enc_ts(krb5_pa_enc_ts *pa_enc)
481*7f2fe78bSCy Schubert {
482*7f2fe78bSCy Schubert     pa_enc->patimestamp = SAMPLE_TIME;
483*7f2fe78bSCy Schubert     pa_enc->pausec = SAMPLE_USEC;
484*7f2fe78bSCy Schubert }
485*7f2fe78bSCy Schubert 
486*7f2fe78bSCy Schubert void
ktest_make_sample_sam_challenge_2(krb5_sam_challenge_2 * p)487*7f2fe78bSCy Schubert ktest_make_sample_sam_challenge_2(krb5_sam_challenge_2 *p)
488*7f2fe78bSCy Schubert {
489*7f2fe78bSCy Schubert     /* Need a valid DER sequence encoding here; this one contains the OCTET
490*7f2fe78bSCy Schubert      * STRING "challenge". */
491*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_challenge_2_body, "\x30\x0B\x04\x09" "challenge");
492*7f2fe78bSCy Schubert     p->sam_cksum = ealloc(2 * sizeof(krb5_checksum *));
493*7f2fe78bSCy Schubert     p->sam_cksum[0] = ealloc(sizeof(krb5_checksum));
494*7f2fe78bSCy Schubert     ktest_make_sample_checksum(p->sam_cksum[0]);
495*7f2fe78bSCy Schubert     p->sam_cksum[1] = NULL;
496*7f2fe78bSCy Schubert }
497*7f2fe78bSCy Schubert 
498*7f2fe78bSCy Schubert void
ktest_make_sample_sam_challenge_2_body(krb5_sam_challenge_2_body * p)499*7f2fe78bSCy Schubert ktest_make_sample_sam_challenge_2_body(krb5_sam_challenge_2_body *p)
500*7f2fe78bSCy Schubert {
501*7f2fe78bSCy Schubert     p->sam_type = 42;
502*7f2fe78bSCy Schubert     p->sam_flags = KRB5_SAM_USE_SAD_AS_KEY;
503*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_type_name, "type name");
504*7f2fe78bSCy Schubert     p->sam_track_id = empty_data();
505*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_challenge_label, "challenge label");
506*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_challenge, "challenge ipse");
507*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_response_prompt, "response_prompt ipse");
508*7f2fe78bSCy Schubert     p->sam_pk_for_sad = empty_data();
509*7f2fe78bSCy Schubert     p->sam_nonce = 0x543210;
510*7f2fe78bSCy Schubert     p->sam_etype = ENCTYPE_AES256_CTS_HMAC_SHA384_192;
511*7f2fe78bSCy Schubert }
512*7f2fe78bSCy Schubert 
513*7f2fe78bSCy Schubert void
ktest_make_sample_sam_response_2(krb5_sam_response_2 * p)514*7f2fe78bSCy Schubert ktest_make_sample_sam_response_2(krb5_sam_response_2 *p)
515*7f2fe78bSCy Schubert {
516*7f2fe78bSCy Schubert     p->magic = KV5M_SAM_RESPONSE;
517*7f2fe78bSCy Schubert     p->sam_type = 43; /* information */
518*7f2fe78bSCy Schubert     p->sam_flags = KRB5_SAM_USE_SAD_AS_KEY; /* KRB5_SAM_* values */
519*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_track_id, "track data");
520*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_enc_nonce_or_sad.ciphertext, "nonce or sad");
521*7f2fe78bSCy Schubert     p->sam_enc_nonce_or_sad.enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192;
522*7f2fe78bSCy Schubert     p->sam_enc_nonce_or_sad.kvno = 3382;
523*7f2fe78bSCy Schubert     p->sam_nonce = 0x543210;
524*7f2fe78bSCy Schubert }
525*7f2fe78bSCy Schubert 
526*7f2fe78bSCy Schubert void
ktest_make_sample_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 * p)527*7f2fe78bSCy Schubert ktest_make_sample_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 *p)
528*7f2fe78bSCy Schubert {
529*7f2fe78bSCy Schubert     p->magic = 83;
530*7f2fe78bSCy Schubert     p->sam_nonce = 88;
531*7f2fe78bSCy Schubert     krb5_data_parse(&p->sam_sad, "enc_sam_response_enc_2");
532*7f2fe78bSCy Schubert }
533*7f2fe78bSCy Schubert 
534*7f2fe78bSCy Schubert void
ktest_make_sample_pa_for_user(krb5_pa_for_user * p)535*7f2fe78bSCy Schubert ktest_make_sample_pa_for_user(krb5_pa_for_user *p)
536*7f2fe78bSCy Schubert {
537*7f2fe78bSCy Schubert     ktest_make_sample_principal(&p->user);
538*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&p->cksum);
539*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->auth_package);
540*7f2fe78bSCy Schubert }
541*7f2fe78bSCy Schubert 
542*7f2fe78bSCy Schubert void
ktest_make_sample_pa_s4u_x509_user(krb5_pa_s4u_x509_user * p)543*7f2fe78bSCy Schubert ktest_make_sample_pa_s4u_x509_user(krb5_pa_s4u_x509_user *p)
544*7f2fe78bSCy Schubert {
545*7f2fe78bSCy Schubert     krb5_s4u_userid *u = &p->user_id;
546*7f2fe78bSCy Schubert 
547*7f2fe78bSCy Schubert     u->nonce = 13243546;
548*7f2fe78bSCy Schubert     ktest_make_sample_principal(&u->user);
549*7f2fe78bSCy Schubert     krb5_data_parse(&u->subject_cert, "pa_s4u_x509_user");
550*7f2fe78bSCy Schubert     u->options = 0x80000000;
551*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&p->cksum);
552*7f2fe78bSCy Schubert }
553*7f2fe78bSCy Schubert 
554*7f2fe78bSCy Schubert void
ktest_make_sample_ad_kdcissued(krb5_ad_kdcissued * p)555*7f2fe78bSCy Schubert ktest_make_sample_ad_kdcissued(krb5_ad_kdcissued *p)
556*7f2fe78bSCy Schubert {
557*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&p->ad_checksum);
558*7f2fe78bSCy Schubert     ktest_make_sample_principal(&p->i_principal);
559*7f2fe78bSCy Schubert     ktest_make_sample_authorization_data(&p->elements);
560*7f2fe78bSCy Schubert }
561*7f2fe78bSCy Schubert 
562*7f2fe78bSCy Schubert void
ktest_make_sample_iakerb_header(krb5_iakerb_header * ih)563*7f2fe78bSCy Schubert ktest_make_sample_iakerb_header(krb5_iakerb_header *ih)
564*7f2fe78bSCy Schubert {
565*7f2fe78bSCy Schubert     ktest_make_sample_data(&(ih->target_realm));
566*7f2fe78bSCy Schubert     ih->cookie = ealloc(sizeof(krb5_data));
567*7f2fe78bSCy Schubert     ktest_make_sample_data(ih->cookie);
568*7f2fe78bSCy Schubert }
569*7f2fe78bSCy Schubert 
570*7f2fe78bSCy Schubert void
ktest_make_sample_iakerb_finished(krb5_iakerb_finished * ih)571*7f2fe78bSCy Schubert ktest_make_sample_iakerb_finished(krb5_iakerb_finished *ih)
572*7f2fe78bSCy Schubert {
573*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&ih->checksum);
574*7f2fe78bSCy Schubert }
575*7f2fe78bSCy Schubert 
576*7f2fe78bSCy Schubert static void
ktest_make_sample_fast_finished(krb5_fast_finished * p)577*7f2fe78bSCy Schubert ktest_make_sample_fast_finished(krb5_fast_finished *p)
578*7f2fe78bSCy Schubert {
579*7f2fe78bSCy Schubert     p->timestamp = SAMPLE_TIME;
580*7f2fe78bSCy Schubert     p->usec = SAMPLE_USEC;
581*7f2fe78bSCy Schubert     ktest_make_sample_principal(&p->client);
582*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&p->ticket_checksum);
583*7f2fe78bSCy Schubert }
584*7f2fe78bSCy Schubert 
585*7f2fe78bSCy Schubert void
ktest_make_sample_fast_response(krb5_fast_response * p)586*7f2fe78bSCy Schubert ktest_make_sample_fast_response(krb5_fast_response *p)
587*7f2fe78bSCy Schubert {
588*7f2fe78bSCy Schubert     ktest_make_sample_pa_data_array(&p->padata);
589*7f2fe78bSCy Schubert     p->strengthen_key = ealloc(sizeof(krb5_keyblock));
590*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(p->strengthen_key);
591*7f2fe78bSCy Schubert     p->finished = ealloc(sizeof(krb5_fast_finished));
592*7f2fe78bSCy Schubert     ktest_make_sample_fast_finished(p->finished);
593*7f2fe78bSCy Schubert     p->nonce = SAMPLE_NONCE;
594*7f2fe78bSCy Schubert }
595*7f2fe78bSCy Schubert 
596*7f2fe78bSCy Schubert void
ktest_make_sha256_alg(krb5_algorithm_identifier * p)597*7f2fe78bSCy Schubert ktest_make_sha256_alg(krb5_algorithm_identifier *p)
598*7f2fe78bSCy Schubert {
599*7f2fe78bSCy Schubert     /* { 2 16 840 1 101 3 4 2 1 } */
600*7f2fe78bSCy Schubert     krb5_data_parse(&p->algorithm, "\x60\x86\x48\x01\x65\x03\x04\x02\x01");
601*7f2fe78bSCy Schubert     p->parameters = empty_data();
602*7f2fe78bSCy Schubert }
603*7f2fe78bSCy Schubert 
604*7f2fe78bSCy Schubert void
ktest_make_sha1_alg(krb5_algorithm_identifier * p)605*7f2fe78bSCy Schubert ktest_make_sha1_alg(krb5_algorithm_identifier *p)
606*7f2fe78bSCy Schubert {
607*7f2fe78bSCy Schubert     /* { 1 3 14 3 2 26 } */
608*7f2fe78bSCy Schubert     krb5_data_parse(&p->algorithm, "\x2b\x0e\x03\x02\x1a");
609*7f2fe78bSCy Schubert     p->parameters = empty_data();
610*7f2fe78bSCy Schubert }
611*7f2fe78bSCy Schubert 
612*7f2fe78bSCy Schubert void
ktest_make_minimal_otp_tokeninfo(krb5_otp_tokeninfo * p)613*7f2fe78bSCy Schubert ktest_make_minimal_otp_tokeninfo(krb5_otp_tokeninfo *p)
614*7f2fe78bSCy Schubert {
615*7f2fe78bSCy Schubert     memset(p, 0, sizeof(*p));
616*7f2fe78bSCy Schubert     p->length = p->format = p->iteration_count = -1;
617*7f2fe78bSCy Schubert }
618*7f2fe78bSCy Schubert 
619*7f2fe78bSCy Schubert void
ktest_make_maximal_otp_tokeninfo(krb5_otp_tokeninfo * p)620*7f2fe78bSCy Schubert ktest_make_maximal_otp_tokeninfo(krb5_otp_tokeninfo *p)
621*7f2fe78bSCy Schubert {
622*7f2fe78bSCy Schubert     p->flags = KRB5_OTP_FLAG_NEXTOTP | KRB5_OTP_FLAG_COMBINE |
623*7f2fe78bSCy Schubert         KRB5_OTP_FLAG_COLLECT_PIN | KRB5_OTP_FLAG_ENCRYPT_NONCE |
624*7f2fe78bSCy Schubert         KRB5_OTP_FLAG_SEPARATE_PIN | KRB5_OTP_FLAG_CHECK_DIGIT;
625*7f2fe78bSCy Schubert     krb5_data_parse(&p->vendor, "Examplecorp");
626*7f2fe78bSCy Schubert     krb5_data_parse(&p->challenge, "hark!");
627*7f2fe78bSCy Schubert     p->length = 10;
628*7f2fe78bSCy Schubert     p->format = 2;
629*7f2fe78bSCy Schubert     krb5_data_parse(&p->token_id, "yourtoken");
630*7f2fe78bSCy Schubert     krb5_data_parse(&p->alg_id, "urn:ietf:params:xml:ns:keyprov:pskc:hotp");
631*7f2fe78bSCy Schubert     p->supported_hash_alg = ealloc(3 * sizeof(*p->supported_hash_alg));
632*7f2fe78bSCy Schubert     p->supported_hash_alg[0] = ealloc(sizeof(*p->supported_hash_alg[0]));
633*7f2fe78bSCy Schubert     ktest_make_sha256_alg(p->supported_hash_alg[0]);
634*7f2fe78bSCy Schubert     p->supported_hash_alg[1] = ealloc(sizeof(*p->supported_hash_alg[1]));
635*7f2fe78bSCy Schubert     ktest_make_sha1_alg(p->supported_hash_alg[1]);
636*7f2fe78bSCy Schubert     p->supported_hash_alg[2] = NULL;
637*7f2fe78bSCy Schubert     p->iteration_count = 1000;
638*7f2fe78bSCy Schubert }
639*7f2fe78bSCy Schubert 
640*7f2fe78bSCy Schubert void
ktest_make_minimal_pa_otp_challenge(krb5_pa_otp_challenge * p)641*7f2fe78bSCy Schubert ktest_make_minimal_pa_otp_challenge(krb5_pa_otp_challenge *p)
642*7f2fe78bSCy Schubert {
643*7f2fe78bSCy Schubert     memset(p, 0, sizeof(*p));
644*7f2fe78bSCy Schubert     krb5_data_parse(&p->nonce, "minnonce");
645*7f2fe78bSCy Schubert     p->tokeninfo = ealloc(2 * sizeof(*p->tokeninfo));
646*7f2fe78bSCy Schubert     p->tokeninfo[0] = ealloc(sizeof(*p->tokeninfo[0]));
647*7f2fe78bSCy Schubert     ktest_make_minimal_otp_tokeninfo(p->tokeninfo[0]);
648*7f2fe78bSCy Schubert     p->tokeninfo[1] = NULL;
649*7f2fe78bSCy Schubert }
650*7f2fe78bSCy Schubert 
651*7f2fe78bSCy Schubert void
ktest_make_maximal_pa_otp_challenge(krb5_pa_otp_challenge * p)652*7f2fe78bSCy Schubert ktest_make_maximal_pa_otp_challenge(krb5_pa_otp_challenge *p)
653*7f2fe78bSCy Schubert {
654*7f2fe78bSCy Schubert     krb5_data_parse(&p->nonce, "maxnonce");
655*7f2fe78bSCy Schubert     krb5_data_parse(&p->service, "testservice");
656*7f2fe78bSCy Schubert     p->tokeninfo = ealloc(3 * sizeof(*p->tokeninfo));
657*7f2fe78bSCy Schubert     p->tokeninfo[0] = ealloc(sizeof(*p->tokeninfo[0]));
658*7f2fe78bSCy Schubert     ktest_make_minimal_otp_tokeninfo(p->tokeninfo[0]);
659*7f2fe78bSCy Schubert     p->tokeninfo[1] = ealloc(sizeof(*p->tokeninfo[1]));
660*7f2fe78bSCy Schubert     ktest_make_maximal_otp_tokeninfo(p->tokeninfo[1]);
661*7f2fe78bSCy Schubert     p->tokeninfo[2] = NULL;
662*7f2fe78bSCy Schubert     krb5_data_parse(&p->salt, "keysalt");
663*7f2fe78bSCy Schubert     krb5_data_parse(&p->s2kparams, "1234");
664*7f2fe78bSCy Schubert }
665*7f2fe78bSCy Schubert 
666*7f2fe78bSCy Schubert void
ktest_make_minimal_pa_otp_req(krb5_pa_otp_req * p)667*7f2fe78bSCy Schubert ktest_make_minimal_pa_otp_req(krb5_pa_otp_req *p)
668*7f2fe78bSCy Schubert {
669*7f2fe78bSCy Schubert     memset(p, 0, sizeof(*p));
670*7f2fe78bSCy Schubert     p->iteration_count = -1;
671*7f2fe78bSCy Schubert     p->format = -1;
672*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&p->enc_data);
673*7f2fe78bSCy Schubert }
674*7f2fe78bSCy Schubert 
675*7f2fe78bSCy Schubert void
ktest_make_maximal_pa_otp_req(krb5_pa_otp_req * p)676*7f2fe78bSCy Schubert ktest_make_maximal_pa_otp_req(krb5_pa_otp_req *p)
677*7f2fe78bSCy Schubert {
678*7f2fe78bSCy Schubert     p->flags = KRB5_OTP_FLAG_NEXTOTP | KRB5_OTP_FLAG_COMBINE;
679*7f2fe78bSCy Schubert     krb5_data_parse(&p->nonce, "nonce");
680*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&p->enc_data);
681*7f2fe78bSCy Schubert     p->hash_alg = ealloc(sizeof(*p->hash_alg));
682*7f2fe78bSCy Schubert     ktest_make_sha256_alg(p->hash_alg);
683*7f2fe78bSCy Schubert     p->iteration_count = 1000;
684*7f2fe78bSCy Schubert     krb5_data_parse(&p->otp_value, "frogs");
685*7f2fe78bSCy Schubert     krb5_data_parse(&p->pin, "myfirstpin");
686*7f2fe78bSCy Schubert     krb5_data_parse(&p->challenge, "hark!");
687*7f2fe78bSCy Schubert     p->time = SAMPLE_TIME;
688*7f2fe78bSCy Schubert     krb5_data_parse(&p->counter, "346");
689*7f2fe78bSCy Schubert     p->format = 2;
690*7f2fe78bSCy Schubert     krb5_data_parse(&p->token_id, "yourtoken");
691*7f2fe78bSCy Schubert     krb5_data_parse(&p->alg_id, "urn:ietf:params:xml:ns:keyprov:pskc:hotp");
692*7f2fe78bSCy Schubert     krb5_data_parse(&p->vendor, "Examplecorp");
693*7f2fe78bSCy Schubert }
694*7f2fe78bSCy Schubert 
695*7f2fe78bSCy Schubert #ifndef DISABLE_PKINIT
696*7f2fe78bSCy Schubert 
697*7f2fe78bSCy Schubert static void
ktest_make_sample_pk_authenticator(krb5_pk_authenticator * p)698*7f2fe78bSCy Schubert ktest_make_sample_pk_authenticator(krb5_pk_authenticator *p)
699*7f2fe78bSCy Schubert {
700*7f2fe78bSCy Schubert     p->cusec = SAMPLE_USEC;
701*7f2fe78bSCy Schubert     p->ctime = SAMPLE_TIME;
702*7f2fe78bSCy Schubert     p->nonce = SAMPLE_NONCE;
703*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&p->paChecksum);
704*7f2fe78bSCy Schubert     /* We don't encode the checksum type, only the contents. */
705*7f2fe78bSCy Schubert     p->paChecksum.checksum_type = 0;
706*7f2fe78bSCy Schubert     p->freshnessToken = ealloc(sizeof(krb5_data));
707*7f2fe78bSCy Schubert     ktest_make_sample_data(p->freshnessToken);
708*7f2fe78bSCy Schubert }
709*7f2fe78bSCy Schubert 
710*7f2fe78bSCy Schubert static void
ktest_make_sample_oid(krb5_data * p)711*7f2fe78bSCy Schubert ktest_make_sample_oid(krb5_data *p)
712*7f2fe78bSCy Schubert {
713*7f2fe78bSCy Schubert     krb5_data_parse(p, "\052\206\110\206\367\022\001\002\002");
714*7f2fe78bSCy Schubert }
715*7f2fe78bSCy Schubert 
716*7f2fe78bSCy Schubert static void
ktest_make_sample_algorithm_identifier(krb5_algorithm_identifier * p)717*7f2fe78bSCy Schubert ktest_make_sample_algorithm_identifier(krb5_algorithm_identifier *p)
718*7f2fe78bSCy Schubert {
719*7f2fe78bSCy Schubert     ktest_make_sample_oid(&p->algorithm);
720*7f2fe78bSCy Schubert     /* Need a valid DER encoding here; this is the OCTET STRING "params". */
721*7f2fe78bSCy Schubert     krb5_data_parse(&p->parameters, "\x04\x06" "params");
722*7f2fe78bSCy Schubert }
723*7f2fe78bSCy Schubert 
724*7f2fe78bSCy Schubert static void
ktest_make_sample_algorithm_identifier_no_params(krb5_algorithm_identifier * p)725*7f2fe78bSCy Schubert ktest_make_sample_algorithm_identifier_no_params(krb5_algorithm_identifier *p)
726*7f2fe78bSCy Schubert {
727*7f2fe78bSCy Schubert     ktest_make_sample_oid(&p->algorithm);
728*7f2fe78bSCy Schubert     p->parameters = empty_data();
729*7f2fe78bSCy Schubert }
730*7f2fe78bSCy Schubert 
731*7f2fe78bSCy Schubert static void
ktest_make_sample_external_principal_identifier(krb5_external_principal_identifier * p)732*7f2fe78bSCy Schubert ktest_make_sample_external_principal_identifier(
733*7f2fe78bSCy Schubert     krb5_external_principal_identifier *p)
734*7f2fe78bSCy Schubert {
735*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->subjectName);
736*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->issuerAndSerialNumber);
737*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->subjectKeyIdentifier);
738*7f2fe78bSCy Schubert }
739*7f2fe78bSCy Schubert 
740*7f2fe78bSCy Schubert void
ktest_make_sample_pa_pk_as_req(krb5_pa_pk_as_req * p)741*7f2fe78bSCy Schubert ktest_make_sample_pa_pk_as_req(krb5_pa_pk_as_req *p)
742*7f2fe78bSCy Schubert {
743*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->signedAuthPack);
744*7f2fe78bSCy Schubert     p->trustedCertifiers =
745*7f2fe78bSCy Schubert         ealloc(2 * sizeof(krb5_external_principal_identifier *));
746*7f2fe78bSCy Schubert     p->trustedCertifiers[0] =
747*7f2fe78bSCy Schubert         ealloc(sizeof(krb5_external_principal_identifier));
748*7f2fe78bSCy Schubert     ktest_make_sample_external_principal_identifier(p->trustedCertifiers[0]);
749*7f2fe78bSCy Schubert     p->trustedCertifiers[1] = NULL;
750*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->kdcPkId);
751*7f2fe78bSCy Schubert }
752*7f2fe78bSCy Schubert 
753*7f2fe78bSCy Schubert static void
ktest_make_sample_dh_rep_info(krb5_dh_rep_info * p)754*7f2fe78bSCy Schubert ktest_make_sample_dh_rep_info(krb5_dh_rep_info *p)
755*7f2fe78bSCy Schubert {
756*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->dhSignedData);
757*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->serverDHNonce);
758*7f2fe78bSCy Schubert     p->kdfID = ealloc(sizeof(krb5_data));
759*7f2fe78bSCy Schubert     ktest_make_sample_data(p->kdfID);
760*7f2fe78bSCy Schubert }
761*7f2fe78bSCy Schubert 
762*7f2fe78bSCy Schubert void
ktest_make_sample_pa_pk_as_rep_dhInfo(krb5_pa_pk_as_rep * p)763*7f2fe78bSCy Schubert ktest_make_sample_pa_pk_as_rep_dhInfo(krb5_pa_pk_as_rep *p)
764*7f2fe78bSCy Schubert {
765*7f2fe78bSCy Schubert     p->choice = choice_pa_pk_as_rep_dhInfo;
766*7f2fe78bSCy Schubert     ktest_make_sample_dh_rep_info(&p->u.dh_Info);
767*7f2fe78bSCy Schubert }
768*7f2fe78bSCy Schubert 
769*7f2fe78bSCy Schubert void
ktest_make_sample_pa_pk_as_rep_encKeyPack(krb5_pa_pk_as_rep * p)770*7f2fe78bSCy Schubert ktest_make_sample_pa_pk_as_rep_encKeyPack(krb5_pa_pk_as_rep *p)
771*7f2fe78bSCy Schubert {
772*7f2fe78bSCy Schubert     p->choice = choice_pa_pk_as_rep_encKeyPack;
773*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->u.encKeyPack);
774*7f2fe78bSCy Schubert }
775*7f2fe78bSCy Schubert 
776*7f2fe78bSCy Schubert void
ktest_make_sample_auth_pack(krb5_auth_pack * p)777*7f2fe78bSCy Schubert ktest_make_sample_auth_pack(krb5_auth_pack *p)
778*7f2fe78bSCy Schubert {
779*7f2fe78bSCy Schubert     ktest_make_sample_pk_authenticator(&p->pkAuthenticator);
780*7f2fe78bSCy Schubert     /* Need a valid DER encoding here; this is the OCTET STRING "pvalue". */
781*7f2fe78bSCy Schubert     krb5_data_parse(&p->clientPublicValue, "\x04\x06" "pvalue");
782*7f2fe78bSCy Schubert     p->supportedCMSTypes = ealloc(3 * sizeof(krb5_algorithm_identifier *));
783*7f2fe78bSCy Schubert     p->supportedCMSTypes[0] = ealloc(sizeof(krb5_algorithm_identifier));
784*7f2fe78bSCy Schubert     ktest_make_sample_algorithm_identifier(p->supportedCMSTypes[0]);
785*7f2fe78bSCy Schubert     p->supportedCMSTypes[1] = ealloc(sizeof(krb5_algorithm_identifier));
786*7f2fe78bSCy Schubert     ktest_make_sample_algorithm_identifier_no_params(p->supportedCMSTypes[1]);
787*7f2fe78bSCy Schubert     p->supportedCMSTypes[2] = NULL;
788*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->clientDHNonce);
789*7f2fe78bSCy Schubert     p->supportedKDFs = ealloc(2 * sizeof(krb5_data *));
790*7f2fe78bSCy Schubert     p->supportedKDFs[0] = ealloc(sizeof(krb5_data));
791*7f2fe78bSCy Schubert     ktest_make_sample_data(p->supportedKDFs[0]);
792*7f2fe78bSCy Schubert     p->supportedKDFs[1] = NULL;
793*7f2fe78bSCy Schubert }
794*7f2fe78bSCy Schubert 
795*7f2fe78bSCy Schubert void
ktest_make_sample_kdc_dh_key_info(krb5_kdc_dh_key_info * p)796*7f2fe78bSCy Schubert ktest_make_sample_kdc_dh_key_info(krb5_kdc_dh_key_info *p)
797*7f2fe78bSCy Schubert {
798*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->subjectPublicKey);
799*7f2fe78bSCy Schubert     p->nonce = SAMPLE_NONCE;
800*7f2fe78bSCy Schubert     p->dhKeyExpiration = SAMPLE_TIME;
801*7f2fe78bSCy Schubert }
802*7f2fe78bSCy Schubert 
803*7f2fe78bSCy Schubert void
ktest_make_sample_reply_key_pack(krb5_reply_key_pack * p)804*7f2fe78bSCy Schubert ktest_make_sample_reply_key_pack(krb5_reply_key_pack *p)
805*7f2fe78bSCy Schubert {
806*7f2fe78bSCy Schubert     ktest_make_sample_keyblock(&p->replyKey);
807*7f2fe78bSCy Schubert     ktest_make_sample_checksum(&p->asChecksum);
808*7f2fe78bSCy Schubert }
809*7f2fe78bSCy Schubert 
810*7f2fe78bSCy Schubert void
ktest_make_sample_sp80056a_other_info(krb5_sp80056a_other_info * p)811*7f2fe78bSCy Schubert ktest_make_sample_sp80056a_other_info(krb5_sp80056a_other_info *p)
812*7f2fe78bSCy Schubert {
813*7f2fe78bSCy Schubert     ktest_make_sample_algorithm_identifier_no_params(&p->algorithm_identifier);
814*7f2fe78bSCy Schubert     ktest_make_sample_principal(&p->party_u_info);
815*7f2fe78bSCy Schubert     ktest_make_sample_principal(&p->party_v_info);
816*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->supp_pub_info);
817*7f2fe78bSCy Schubert }
818*7f2fe78bSCy Schubert 
819*7f2fe78bSCy Schubert void
ktest_make_sample_pkinit_supp_pub_info(krb5_pkinit_supp_pub_info * p)820*7f2fe78bSCy Schubert ktest_make_sample_pkinit_supp_pub_info(krb5_pkinit_supp_pub_info *p)
821*7f2fe78bSCy Schubert {
822*7f2fe78bSCy Schubert     p->enctype = ENCTYPE_AES256_CTS_HMAC_SHA384_192;
823*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->as_req);
824*7f2fe78bSCy Schubert     ktest_make_sample_data(&p->pk_as_rep);
825*7f2fe78bSCy Schubert }
826*7f2fe78bSCy Schubert 
827*7f2fe78bSCy Schubert #endif /* not DISABLE_PKINIT */
828*7f2fe78bSCy Schubert 
829*7f2fe78bSCy Schubert #ifdef ENABLE_LDAP
830*7f2fe78bSCy Schubert static void
ktest_make_sample_key_data(krb5_key_data * p,int i)831*7f2fe78bSCy Schubert ktest_make_sample_key_data(krb5_key_data *p, int i)
832*7f2fe78bSCy Schubert {
833*7f2fe78bSCy Schubert     char *str;
834*7f2fe78bSCy Schubert     int len;
835*7f2fe78bSCy Schubert 
836*7f2fe78bSCy Schubert     len = asprintf(&str, "key%d", i);
837*7f2fe78bSCy Schubert     if (len < 0)
838*7f2fe78bSCy Schubert         abort();
839*7f2fe78bSCy Schubert     p->key_data_ver = 2;
840*7f2fe78bSCy Schubert     p->key_data_type[0] = 2;
841*7f2fe78bSCy Schubert     p->key_data_length[0] = (unsigned int) len;
842*7f2fe78bSCy Schubert     p->key_data_contents[0] = (krb5_octet *)str;
843*7f2fe78bSCy Schubert     len = asprintf(&str, "salt%d", i);
844*7f2fe78bSCy Schubert     if (len < 0)
845*7f2fe78bSCy Schubert         abort();
846*7f2fe78bSCy Schubert     p->key_data_type[1] = i;
847*7f2fe78bSCy Schubert     p->key_data_length[1] = (unsigned int) len;
848*7f2fe78bSCy Schubert     p->key_data_contents[1] = (krb5_octet *)str;
849*7f2fe78bSCy Schubert }
850*7f2fe78bSCy Schubert 
851*7f2fe78bSCy Schubert void
ktest_make_sample_ldap_seqof_key_data(ldap_seqof_key_data * p)852*7f2fe78bSCy Schubert ktest_make_sample_ldap_seqof_key_data(ldap_seqof_key_data *p)
853*7f2fe78bSCy Schubert {
854*7f2fe78bSCy Schubert     int i;
855*7f2fe78bSCy Schubert 
856*7f2fe78bSCy Schubert     p->mkvno = 14;
857*7f2fe78bSCy Schubert     p->n_key_data = 3;
858*7f2fe78bSCy Schubert     p->key_data = calloc(3,sizeof(krb5_key_data));
859*7f2fe78bSCy Schubert     p->kvno = 42;
860*7f2fe78bSCy Schubert     for (i = 0; i < 3; i++)
861*7f2fe78bSCy Schubert         ktest_make_sample_key_data(&p->key_data[i], i);
862*7f2fe78bSCy Schubert }
863*7f2fe78bSCy Schubert #endif
864*7f2fe78bSCy Schubert 
865*7f2fe78bSCy Schubert void
ktest_make_sample_kkdcp_message(krb5_kkdcp_message * p)866*7f2fe78bSCy Schubert ktest_make_sample_kkdcp_message(krb5_kkdcp_message *p)
867*7f2fe78bSCy Schubert {
868*7f2fe78bSCy Schubert     krb5_kdc_req req;
869*7f2fe78bSCy Schubert     krb5_data *message;
870*7f2fe78bSCy Schubert 
871*7f2fe78bSCy Schubert     ktest_make_sample_kdc_req(&req);
872*7f2fe78bSCy Schubert     req.msg_type = KRB5_AS_REQ;
873*7f2fe78bSCy Schubert     encode_krb5_as_req(&req, &message);
874*7f2fe78bSCy Schubert     p->kerb_message = *message;
875*7f2fe78bSCy Schubert     free(message);
876*7f2fe78bSCy Schubert     ktest_empty_kdc_req(&req);
877*7f2fe78bSCy Schubert     ktest_make_sample_data(&(p->target_domain));
878*7f2fe78bSCy Schubert     p->dclocator_hint = 0;
879*7f2fe78bSCy Schubert }
880*7f2fe78bSCy Schubert 
881*7f2fe78bSCy Schubert static krb5_authdata *
make_ad_element(krb5_authdatatype ad_type,const char * str)882*7f2fe78bSCy Schubert make_ad_element(krb5_authdatatype ad_type, const char *str)
883*7f2fe78bSCy Schubert {
884*7f2fe78bSCy Schubert     krb5_authdata *ad;
885*7f2fe78bSCy Schubert 
886*7f2fe78bSCy Schubert     ad = ealloc(sizeof(*ad));
887*7f2fe78bSCy Schubert     ad->ad_type = ad_type;
888*7f2fe78bSCy Schubert     ad->length = strlen(str);
889*7f2fe78bSCy Schubert     ad->contents = ealloc(ad->length);
890*7f2fe78bSCy Schubert     memcpy(ad->contents, str, ad->length);
891*7f2fe78bSCy Schubert     return ad;
892*7f2fe78bSCy Schubert }
893*7f2fe78bSCy Schubert 
894*7f2fe78bSCy Schubert static krb5_verifier_mac *
make_vmac(krb5_boolean include_princ,krb5_kvno kvno,krb5_enctype enctype,const char * cksumstr)895*7f2fe78bSCy Schubert make_vmac(krb5_boolean include_princ, krb5_kvno kvno, krb5_enctype enctype,
896*7f2fe78bSCy Schubert           const char *cksumstr)
897*7f2fe78bSCy Schubert {
898*7f2fe78bSCy Schubert     krb5_verifier_mac *vmac;
899*7f2fe78bSCy Schubert 
900*7f2fe78bSCy Schubert     vmac = ealloc(sizeof(*vmac));
901*7f2fe78bSCy Schubert     if (include_princ) {
902*7f2fe78bSCy Schubert         ktest_make_sample_principal(&vmac->princ);
903*7f2fe78bSCy Schubert         (void)krb5_set_principal_realm(NULL, vmac->princ, "");
904*7f2fe78bSCy Schubert     } else {
905*7f2fe78bSCy Schubert         vmac->princ = NULL;
906*7f2fe78bSCy Schubert     }
907*7f2fe78bSCy Schubert     vmac->kvno = kvno;
908*7f2fe78bSCy Schubert     vmac->enctype = enctype;
909*7f2fe78bSCy Schubert     vmac->checksum.checksum_type = 1;
910*7f2fe78bSCy Schubert     vmac->checksum.length = strlen(cksumstr);
911*7f2fe78bSCy Schubert     vmac->checksum.contents = ealloc(vmac->checksum.length);
912*7f2fe78bSCy Schubert     memcpy(vmac->checksum.contents, cksumstr, vmac->checksum.length);
913*7f2fe78bSCy Schubert     return vmac;
914*7f2fe78bSCy Schubert }
915*7f2fe78bSCy Schubert 
916*7f2fe78bSCy Schubert void
ktest_make_minimal_cammac(krb5_cammac * p)917*7f2fe78bSCy Schubert ktest_make_minimal_cammac(krb5_cammac *p)
918*7f2fe78bSCy Schubert {
919*7f2fe78bSCy Schubert     memset(p, 0, sizeof(*p));
920*7f2fe78bSCy Schubert     p->elements = ealloc(2 * sizeof(*p->elements));
921*7f2fe78bSCy Schubert     p->elements[0] = make_ad_element(1, "ad1");
922*7f2fe78bSCy Schubert     p->elements[1] = NULL;
923*7f2fe78bSCy Schubert }
924*7f2fe78bSCy Schubert 
925*7f2fe78bSCy Schubert void
ktest_make_maximal_cammac(krb5_cammac * p)926*7f2fe78bSCy Schubert ktest_make_maximal_cammac(krb5_cammac *p)
927*7f2fe78bSCy Schubert {
928*7f2fe78bSCy Schubert     p->elements = ealloc(3 * sizeof(*p->elements));
929*7f2fe78bSCy Schubert     p->elements[0] = make_ad_element(1, "ad1");
930*7f2fe78bSCy Schubert     p->elements[1] = make_ad_element(2, "ad2");
931*7f2fe78bSCy Schubert     p->elements[2] = NULL;
932*7f2fe78bSCy Schubert     p->kdc_verifier = make_vmac(TRUE, 5, 16, "cksumkdc");
933*7f2fe78bSCy Schubert     p->svc_verifier = make_vmac(TRUE, 5, 16, "cksumsvc");
934*7f2fe78bSCy Schubert     p->other_verifiers = ealloc(3 * sizeof(*p->other_verifiers));
935*7f2fe78bSCy Schubert     p->other_verifiers[0] = make_vmac(FALSE, 0, 0, "cksum1");
936*7f2fe78bSCy Schubert     p->other_verifiers[1] = make_vmac(TRUE, 5, 16, "cksum2");
937*7f2fe78bSCy Schubert     p->other_verifiers[2] = NULL;
938*7f2fe78bSCy Schubert }
939*7f2fe78bSCy Schubert 
940*7f2fe78bSCy Schubert void
ktest_make_sample_secure_cookie(krb5_secure_cookie * p)941*7f2fe78bSCy Schubert ktest_make_sample_secure_cookie(krb5_secure_cookie *p)
942*7f2fe78bSCy Schubert {
943*7f2fe78bSCy Schubert     ktest_make_sample_pa_data_array(&p->data);
944*7f2fe78bSCy Schubert     p->time = SAMPLE_TIME;
945*7f2fe78bSCy Schubert }
946*7f2fe78bSCy Schubert 
947*7f2fe78bSCy Schubert void
ktest_make_minimal_spake_factor(krb5_spake_factor * p)948*7f2fe78bSCy Schubert ktest_make_minimal_spake_factor(krb5_spake_factor *p)
949*7f2fe78bSCy Schubert {
950*7f2fe78bSCy Schubert     p->type = 1;
951*7f2fe78bSCy Schubert     p->data = NULL;
952*7f2fe78bSCy Schubert }
953*7f2fe78bSCy Schubert 
954*7f2fe78bSCy Schubert void
ktest_make_maximal_spake_factor(krb5_spake_factor * p)955*7f2fe78bSCy Schubert ktest_make_maximal_spake_factor(krb5_spake_factor *p)
956*7f2fe78bSCy Schubert {
957*7f2fe78bSCy Schubert     p->type = 2;
958*7f2fe78bSCy Schubert     p->data = ealloc(sizeof(*p->data));
959*7f2fe78bSCy Schubert     krb5_data_parse(p->data, "fdata");
960*7f2fe78bSCy Schubert }
961*7f2fe78bSCy Schubert 
962*7f2fe78bSCy Schubert void
ktest_make_support_pa_spake(krb5_pa_spake * p)963*7f2fe78bSCy Schubert ktest_make_support_pa_spake(krb5_pa_spake *p)
964*7f2fe78bSCy Schubert {
965*7f2fe78bSCy Schubert     krb5_spake_support *s = &p->u.support;
966*7f2fe78bSCy Schubert 
967*7f2fe78bSCy Schubert     s->ngroups = 2;
968*7f2fe78bSCy Schubert     s->groups = ealloc(s->ngroups * sizeof(*s->groups));
969*7f2fe78bSCy Schubert     s->groups[0] = 1;
970*7f2fe78bSCy Schubert     s->groups[1] = 2;
971*7f2fe78bSCy Schubert     p->choice = SPAKE_MSGTYPE_SUPPORT;
972*7f2fe78bSCy Schubert }
973*7f2fe78bSCy Schubert 
974*7f2fe78bSCy Schubert void
ktest_make_challenge_pa_spake(krb5_pa_spake * p)975*7f2fe78bSCy Schubert ktest_make_challenge_pa_spake(krb5_pa_spake *p)
976*7f2fe78bSCy Schubert {
977*7f2fe78bSCy Schubert     krb5_spake_challenge *c = &p->u.challenge;
978*7f2fe78bSCy Schubert 
979*7f2fe78bSCy Schubert     c->group = 1;
980*7f2fe78bSCy Schubert     krb5_data_parse(&c->pubkey, "T value");
981*7f2fe78bSCy Schubert     c->factors = ealloc(3 * sizeof(*c->factors));
982*7f2fe78bSCy Schubert     c->factors[0] = ealloc(sizeof(*c->factors[0]));
983*7f2fe78bSCy Schubert     ktest_make_minimal_spake_factor(c->factors[0]);
984*7f2fe78bSCy Schubert     c->factors[1] = ealloc(sizeof(*c->factors[1]));
985*7f2fe78bSCy Schubert     ktest_make_maximal_spake_factor(c->factors[1]);
986*7f2fe78bSCy Schubert     c->factors[2] = NULL;
987*7f2fe78bSCy Schubert     p->choice = SPAKE_MSGTYPE_CHALLENGE;
988*7f2fe78bSCy Schubert }
989*7f2fe78bSCy Schubert 
990*7f2fe78bSCy Schubert void
ktest_make_response_pa_spake(krb5_pa_spake * p)991*7f2fe78bSCy Schubert ktest_make_response_pa_spake(krb5_pa_spake *p)
992*7f2fe78bSCy Schubert {
993*7f2fe78bSCy Schubert     krb5_spake_response *r = &p->u.response;
994*7f2fe78bSCy Schubert 
995*7f2fe78bSCy Schubert     krb5_data_parse(&r->pubkey, "S value");
996*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&r->factor);
997*7f2fe78bSCy Schubert     p->choice = SPAKE_MSGTYPE_RESPONSE;
998*7f2fe78bSCy Schubert }
999*7f2fe78bSCy Schubert 
1000*7f2fe78bSCy Schubert void
ktest_make_encdata_pa_spake(krb5_pa_spake * p)1001*7f2fe78bSCy Schubert ktest_make_encdata_pa_spake(krb5_pa_spake *p)
1002*7f2fe78bSCy Schubert {
1003*7f2fe78bSCy Schubert     ktest_make_sample_enc_data(&p->u.encdata);
1004*7f2fe78bSCy Schubert     p->choice = SPAKE_MSGTYPE_ENCDATA;
1005*7f2fe78bSCy Schubert }
1006*7f2fe78bSCy Schubert 
1007*7f2fe78bSCy Schubert /****************************************************************/
1008*7f2fe78bSCy Schubert /* destructors */
1009*7f2fe78bSCy Schubert 
1010*7f2fe78bSCy Schubert void
ktest_destroy_data(krb5_data ** d)1011*7f2fe78bSCy Schubert ktest_destroy_data(krb5_data **d)
1012*7f2fe78bSCy Schubert {
1013*7f2fe78bSCy Schubert     if (*d != NULL) {
1014*7f2fe78bSCy Schubert         free((*d)->data);
1015*7f2fe78bSCy Schubert         free(*d);
1016*7f2fe78bSCy Schubert         *d = NULL;
1017*7f2fe78bSCy Schubert     }
1018*7f2fe78bSCy Schubert }
1019*7f2fe78bSCy Schubert 
1020*7f2fe78bSCy Schubert void
ktest_empty_data(krb5_data * d)1021*7f2fe78bSCy Schubert ktest_empty_data(krb5_data *d)
1022*7f2fe78bSCy Schubert {
1023*7f2fe78bSCy Schubert     if (d->data != NULL) {
1024*7f2fe78bSCy Schubert         free(d->data);
1025*7f2fe78bSCy Schubert         d->data = NULL;
1026*7f2fe78bSCy Schubert         d->length = 0;
1027*7f2fe78bSCy Schubert     }
1028*7f2fe78bSCy Schubert }
1029*7f2fe78bSCy Schubert 
1030*7f2fe78bSCy Schubert static void
ktest_empty_checksum(krb5_checksum * cs)1031*7f2fe78bSCy Schubert ktest_empty_checksum(krb5_checksum *cs)
1032*7f2fe78bSCy Schubert {
1033*7f2fe78bSCy Schubert     free(cs->contents);
1034*7f2fe78bSCy Schubert     cs->contents = NULL;
1035*7f2fe78bSCy Schubert }
1036*7f2fe78bSCy Schubert 
1037*7f2fe78bSCy Schubert void
ktest_destroy_checksum(krb5_checksum ** cs)1038*7f2fe78bSCy Schubert ktest_destroy_checksum(krb5_checksum **cs)
1039*7f2fe78bSCy Schubert {
1040*7f2fe78bSCy Schubert     if (*cs != NULL) {
1041*7f2fe78bSCy Schubert         free((*cs)->contents);
1042*7f2fe78bSCy Schubert         free(*cs);
1043*7f2fe78bSCy Schubert         *cs = NULL;
1044*7f2fe78bSCy Schubert     }
1045*7f2fe78bSCy Schubert }
1046*7f2fe78bSCy Schubert 
1047*7f2fe78bSCy Schubert void
ktest_empty_keyblock(krb5_keyblock * kb)1048*7f2fe78bSCy Schubert ktest_empty_keyblock(krb5_keyblock *kb)
1049*7f2fe78bSCy Schubert {
1050*7f2fe78bSCy Schubert     if (kb != NULL) {
1051*7f2fe78bSCy Schubert         if (kb->contents) {
1052*7f2fe78bSCy Schubert             free(kb->contents);
1053*7f2fe78bSCy Schubert             kb->contents = NULL;
1054*7f2fe78bSCy Schubert         }
1055*7f2fe78bSCy Schubert     }
1056*7f2fe78bSCy Schubert }
1057*7f2fe78bSCy Schubert 
1058*7f2fe78bSCy Schubert void
ktest_destroy_keyblock(krb5_keyblock ** kb)1059*7f2fe78bSCy Schubert ktest_destroy_keyblock(krb5_keyblock **kb)
1060*7f2fe78bSCy Schubert {
1061*7f2fe78bSCy Schubert     if (*kb != NULL) {
1062*7f2fe78bSCy Schubert         free((*kb)->contents);
1063*7f2fe78bSCy Schubert         free(*kb);
1064*7f2fe78bSCy Schubert         *kb = NULL;
1065*7f2fe78bSCy Schubert     }
1066*7f2fe78bSCy Schubert }
1067*7f2fe78bSCy Schubert 
1068*7f2fe78bSCy Schubert void
ktest_empty_authorization_data(krb5_authdata ** ad)1069*7f2fe78bSCy Schubert ktest_empty_authorization_data(krb5_authdata **ad)
1070*7f2fe78bSCy Schubert {
1071*7f2fe78bSCy Schubert     int i;
1072*7f2fe78bSCy Schubert 
1073*7f2fe78bSCy Schubert     if (*ad != NULL) {
1074*7f2fe78bSCy Schubert         for (i=0; ad[i] != NULL; i++)
1075*7f2fe78bSCy Schubert             ktest_destroy_authdata(&ad[i]);
1076*7f2fe78bSCy Schubert     }
1077*7f2fe78bSCy Schubert }
1078*7f2fe78bSCy Schubert 
1079*7f2fe78bSCy Schubert void
ktest_destroy_authorization_data(krb5_authdata *** ad)1080*7f2fe78bSCy Schubert ktest_destroy_authorization_data(krb5_authdata ***ad)
1081*7f2fe78bSCy Schubert {
1082*7f2fe78bSCy Schubert     ktest_empty_authorization_data(*ad);
1083*7f2fe78bSCy Schubert     free(*ad);
1084*7f2fe78bSCy Schubert     *ad = NULL;
1085*7f2fe78bSCy Schubert }
1086*7f2fe78bSCy Schubert 
1087*7f2fe78bSCy Schubert void
ktest_destroy_authdata(krb5_authdata ** ad)1088*7f2fe78bSCy Schubert ktest_destroy_authdata(krb5_authdata **ad)
1089*7f2fe78bSCy Schubert {
1090*7f2fe78bSCy Schubert     if (*ad != NULL) {
1091*7f2fe78bSCy Schubert         free((*ad)->contents);
1092*7f2fe78bSCy Schubert         free(*ad);
1093*7f2fe78bSCy Schubert         *ad = NULL;
1094*7f2fe78bSCy Schubert     }
1095*7f2fe78bSCy Schubert }
1096*7f2fe78bSCy Schubert 
1097*7f2fe78bSCy Schubert void
ktest_empty_pa_data_array(krb5_pa_data ** pad)1098*7f2fe78bSCy Schubert ktest_empty_pa_data_array(krb5_pa_data **pad)
1099*7f2fe78bSCy Schubert {
1100*7f2fe78bSCy Schubert     int i;
1101*7f2fe78bSCy Schubert 
1102*7f2fe78bSCy Schubert     for (i=0; pad[i] != NULL; i++)
1103*7f2fe78bSCy Schubert         ktest_destroy_pa_data(&pad[i]);
1104*7f2fe78bSCy Schubert }
1105*7f2fe78bSCy Schubert 
1106*7f2fe78bSCy Schubert void
ktest_destroy_pa_data_array(krb5_pa_data *** pad)1107*7f2fe78bSCy Schubert ktest_destroy_pa_data_array(krb5_pa_data ***pad)
1108*7f2fe78bSCy Schubert {
1109*7f2fe78bSCy Schubert     ktest_empty_pa_data_array(*pad);
1110*7f2fe78bSCy Schubert     free(*pad);
1111*7f2fe78bSCy Schubert     *pad = NULL;
1112*7f2fe78bSCy Schubert }
1113*7f2fe78bSCy Schubert 
1114*7f2fe78bSCy Schubert void
ktest_destroy_pa_data(krb5_pa_data ** pad)1115*7f2fe78bSCy Schubert ktest_destroy_pa_data(krb5_pa_data **pad)
1116*7f2fe78bSCy Schubert {
1117*7f2fe78bSCy Schubert     if (*pad != NULL) {
1118*7f2fe78bSCy Schubert         free((*pad)->contents);
1119*7f2fe78bSCy Schubert         free(*pad);
1120*7f2fe78bSCy Schubert         *pad = NULL;
1121*7f2fe78bSCy Schubert     }
1122*7f2fe78bSCy Schubert }
1123*7f2fe78bSCy Schubert 
1124*7f2fe78bSCy Schubert void
ktest_destroy_address(krb5_address ** a)1125*7f2fe78bSCy Schubert ktest_destroy_address(krb5_address **a)
1126*7f2fe78bSCy Schubert {
1127*7f2fe78bSCy Schubert     if (*a != NULL) {
1128*7f2fe78bSCy Schubert         free((*a)->contents);
1129*7f2fe78bSCy Schubert         free(*a);
1130*7f2fe78bSCy Schubert         *a = NULL;
1131*7f2fe78bSCy Schubert     }
1132*7f2fe78bSCy Schubert }
1133*7f2fe78bSCy Schubert 
1134*7f2fe78bSCy Schubert void
ktest_empty_addresses(krb5_address ** a)1135*7f2fe78bSCy Schubert ktest_empty_addresses(krb5_address **a)
1136*7f2fe78bSCy Schubert {
1137*7f2fe78bSCy Schubert     int i;
1138*7f2fe78bSCy Schubert 
1139*7f2fe78bSCy Schubert     for (i=0; a[i] != NULL; i++)
1140*7f2fe78bSCy Schubert         ktest_destroy_address(&a[i]);
1141*7f2fe78bSCy Schubert }
1142*7f2fe78bSCy Schubert 
1143*7f2fe78bSCy Schubert void
ktest_destroy_addresses(krb5_address *** a)1144*7f2fe78bSCy Schubert ktest_destroy_addresses(krb5_address ***a)
1145*7f2fe78bSCy Schubert {
1146*7f2fe78bSCy Schubert     ktest_empty_addresses(*a);
1147*7f2fe78bSCy Schubert     free(*a);
1148*7f2fe78bSCy Schubert     *a = NULL;
1149*7f2fe78bSCy Schubert }
1150*7f2fe78bSCy Schubert 
1151*7f2fe78bSCy Schubert void
ktest_destroy_principal(krb5_principal * p)1152*7f2fe78bSCy Schubert ktest_destroy_principal(krb5_principal *p)
1153*7f2fe78bSCy Schubert {
1154*7f2fe78bSCy Schubert     int i;
1155*7f2fe78bSCy Schubert 
1156*7f2fe78bSCy Schubert     if (*p == NULL)
1157*7f2fe78bSCy Schubert         return;
1158*7f2fe78bSCy Schubert     for (i=0; i<(*p)->length; i++)
1159*7f2fe78bSCy Schubert         ktest_empty_data(&(*p)->data[i]);
1160*7f2fe78bSCy Schubert     ktest_empty_data(&(*p)->realm);
1161*7f2fe78bSCy Schubert     free((*p)->data);
1162*7f2fe78bSCy Schubert     free(*p);
1163*7f2fe78bSCy Schubert     *p = NULL;
1164*7f2fe78bSCy Schubert }
1165*7f2fe78bSCy Schubert 
1166*7f2fe78bSCy Schubert void
ktest_destroy_sequence_of_integer(long ** soi)1167*7f2fe78bSCy Schubert ktest_destroy_sequence_of_integer(long **soi)
1168*7f2fe78bSCy Schubert {
1169*7f2fe78bSCy Schubert     free(*soi);
1170*7f2fe78bSCy Schubert     *soi = NULL;
1171*7f2fe78bSCy Schubert }
1172*7f2fe78bSCy Schubert 
1173*7f2fe78bSCy Schubert void
ktest_destroy_sequence_of_ticket(krb5_ticket *** sot)1174*7f2fe78bSCy Schubert ktest_destroy_sequence_of_ticket(krb5_ticket ***sot)
1175*7f2fe78bSCy Schubert {
1176*7f2fe78bSCy Schubert     int i;
1177*7f2fe78bSCy Schubert 
1178*7f2fe78bSCy Schubert     for (i=0; (*sot)[i] != NULL; i++)
1179*7f2fe78bSCy Schubert         ktest_destroy_ticket(&(*sot)[i]);
1180*7f2fe78bSCy Schubert     free(*sot);
1181*7f2fe78bSCy Schubert     *sot = NULL;
1182*7f2fe78bSCy Schubert }
1183*7f2fe78bSCy Schubert 
1184*7f2fe78bSCy Schubert void
ktest_destroy_ticket(krb5_ticket ** tkt)1185*7f2fe78bSCy Schubert ktest_destroy_ticket(krb5_ticket **tkt)
1186*7f2fe78bSCy Schubert {
1187*7f2fe78bSCy Schubert     ktest_destroy_principal(&(*tkt)->server);
1188*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&(*tkt)->enc_part);
1189*7f2fe78bSCy Schubert     /*  ktest_empty_enc_tkt_part(((*tkt)->enc_part2));*/
1190*7f2fe78bSCy Schubert     free(*tkt);
1191*7f2fe78bSCy Schubert     *tkt = NULL;
1192*7f2fe78bSCy Schubert }
1193*7f2fe78bSCy Schubert 
1194*7f2fe78bSCy Schubert void
ktest_empty_ticket(krb5_ticket * tkt)1195*7f2fe78bSCy Schubert ktest_empty_ticket(krb5_ticket *tkt)
1196*7f2fe78bSCy Schubert {
1197*7f2fe78bSCy Schubert     if (tkt->server)
1198*7f2fe78bSCy Schubert         ktest_destroy_principal(&tkt->server);
1199*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&tkt->enc_part);
1200*7f2fe78bSCy Schubert     if (tkt->enc_part2)
1201*7f2fe78bSCy Schubert         ktest_destroy_enc_tkt_part(&tkt->enc_part2);
1202*7f2fe78bSCy Schubert }
1203*7f2fe78bSCy Schubert 
1204*7f2fe78bSCy Schubert void
ktest_destroy_enc_data(krb5_enc_data * ed)1205*7f2fe78bSCy Schubert ktest_destroy_enc_data(krb5_enc_data *ed)
1206*7f2fe78bSCy Schubert {
1207*7f2fe78bSCy Schubert     ktest_empty_data(&ed->ciphertext);
1208*7f2fe78bSCy Schubert     ed->kvno = 0;
1209*7f2fe78bSCy Schubert }
1210*7f2fe78bSCy Schubert 
1211*7f2fe78bSCy Schubert void
ktest_destroy_etype_info_entry(krb5_etype_info_entry * i)1212*7f2fe78bSCy Schubert ktest_destroy_etype_info_entry(krb5_etype_info_entry *i)
1213*7f2fe78bSCy Schubert {
1214*7f2fe78bSCy Schubert     if (i->salt)
1215*7f2fe78bSCy Schubert         free(i->salt);
1216*7f2fe78bSCy Schubert     ktest_empty_data(&i->s2kparams);
1217*7f2fe78bSCy Schubert     free(i);
1218*7f2fe78bSCy Schubert }
1219*7f2fe78bSCy Schubert 
1220*7f2fe78bSCy Schubert void
ktest_destroy_etype_info(krb5_etype_info_entry ** info)1221*7f2fe78bSCy Schubert ktest_destroy_etype_info(krb5_etype_info_entry **info)
1222*7f2fe78bSCy Schubert {
1223*7f2fe78bSCy Schubert     int i;
1224*7f2fe78bSCy Schubert 
1225*7f2fe78bSCy Schubert     for (i = 0; info[i] != NULL; i++)
1226*7f2fe78bSCy Schubert         ktest_destroy_etype_info_entry(info[i]);
1227*7f2fe78bSCy Schubert     free(info);
1228*7f2fe78bSCy Schubert }
1229*7f2fe78bSCy Schubert 
1230*7f2fe78bSCy Schubert void
ktest_empty_kdc_req(krb5_kdc_req * kr)1231*7f2fe78bSCy Schubert ktest_empty_kdc_req(krb5_kdc_req *kr)
1232*7f2fe78bSCy Schubert {
1233*7f2fe78bSCy Schubert     if (kr->padata)
1234*7f2fe78bSCy Schubert         ktest_destroy_pa_data_array(&kr->padata);
1235*7f2fe78bSCy Schubert 
1236*7f2fe78bSCy Schubert     if (kr->client)
1237*7f2fe78bSCy Schubert         ktest_destroy_principal(&kr->client);
1238*7f2fe78bSCy Schubert 
1239*7f2fe78bSCy Schubert     if (kr->server)
1240*7f2fe78bSCy Schubert         ktest_destroy_principal(&kr->server);
1241*7f2fe78bSCy Schubert     free(kr->ktype);
1242*7f2fe78bSCy Schubert     if (kr->addresses)
1243*7f2fe78bSCy Schubert         ktest_destroy_addresses(&kr->addresses);
1244*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&kr->authorization_data);
1245*7f2fe78bSCy Schubert     if (kr->unenc_authdata)
1246*7f2fe78bSCy Schubert         ktest_destroy_authorization_data(&kr->unenc_authdata);
1247*7f2fe78bSCy Schubert     if (kr->second_ticket)
1248*7f2fe78bSCy Schubert         ktest_destroy_sequence_of_ticket(&kr->second_ticket);
1249*7f2fe78bSCy Schubert 
1250*7f2fe78bSCy Schubert }
1251*7f2fe78bSCy Schubert 
1252*7f2fe78bSCy Schubert void
ktest_empty_kdc_rep(krb5_kdc_rep * kr)1253*7f2fe78bSCy Schubert ktest_empty_kdc_rep(krb5_kdc_rep *kr)
1254*7f2fe78bSCy Schubert {
1255*7f2fe78bSCy Schubert     if (kr->padata)
1256*7f2fe78bSCy Schubert         ktest_destroy_pa_data_array(&kr->padata);
1257*7f2fe78bSCy Schubert 
1258*7f2fe78bSCy Schubert     if (kr->client)
1259*7f2fe78bSCy Schubert         ktest_destroy_principal(&kr->client);
1260*7f2fe78bSCy Schubert 
1261*7f2fe78bSCy Schubert     if (kr->ticket)
1262*7f2fe78bSCy Schubert         ktest_destroy_ticket(&kr->ticket);
1263*7f2fe78bSCy Schubert 
1264*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&kr->enc_part);
1265*7f2fe78bSCy Schubert 
1266*7f2fe78bSCy Schubert     if (kr->enc_part2) {
1267*7f2fe78bSCy Schubert         ktest_empty_enc_kdc_rep_part(kr->enc_part2);
1268*7f2fe78bSCy Schubert         free(kr->enc_part2);
1269*7f2fe78bSCy Schubert         kr->enc_part2 = NULL;
1270*7f2fe78bSCy Schubert     }
1271*7f2fe78bSCy Schubert }
1272*7f2fe78bSCy Schubert 
1273*7f2fe78bSCy Schubert void
ktest_empty_authenticator(krb5_authenticator * a)1274*7f2fe78bSCy Schubert ktest_empty_authenticator(krb5_authenticator *a)
1275*7f2fe78bSCy Schubert {
1276*7f2fe78bSCy Schubert     if (a->client)
1277*7f2fe78bSCy Schubert         ktest_destroy_principal(&a->client);
1278*7f2fe78bSCy Schubert     if (a->checksum)
1279*7f2fe78bSCy Schubert         ktest_destroy_checksum(&a->checksum);
1280*7f2fe78bSCy Schubert     if (a->subkey)
1281*7f2fe78bSCy Schubert         ktest_destroy_keyblock(&a->subkey);
1282*7f2fe78bSCy Schubert     if (a->authorization_data)
1283*7f2fe78bSCy Schubert         ktest_destroy_authorization_data(&a->authorization_data);
1284*7f2fe78bSCy Schubert }
1285*7f2fe78bSCy Schubert 
1286*7f2fe78bSCy Schubert void
ktest_empty_enc_tkt_part(krb5_enc_tkt_part * etp)1287*7f2fe78bSCy Schubert ktest_empty_enc_tkt_part(krb5_enc_tkt_part *etp)
1288*7f2fe78bSCy Schubert {
1289*7f2fe78bSCy Schubert     if (etp->session)
1290*7f2fe78bSCy Schubert         ktest_destroy_keyblock(&etp->session);
1291*7f2fe78bSCy Schubert     if (etp->client)
1292*7f2fe78bSCy Schubert         ktest_destroy_principal(&etp->client);
1293*7f2fe78bSCy Schubert     if (etp->caddrs)
1294*7f2fe78bSCy Schubert         ktest_destroy_addresses(&etp->caddrs);
1295*7f2fe78bSCy Schubert     if (etp->authorization_data)
1296*7f2fe78bSCy Schubert         ktest_destroy_authorization_data(&etp->authorization_data);
1297*7f2fe78bSCy Schubert     ktest_destroy_transited(&etp->transited);
1298*7f2fe78bSCy Schubert }
1299*7f2fe78bSCy Schubert 
1300*7f2fe78bSCy Schubert void
ktest_destroy_enc_tkt_part(krb5_enc_tkt_part ** etp)1301*7f2fe78bSCy Schubert ktest_destroy_enc_tkt_part(krb5_enc_tkt_part **etp)
1302*7f2fe78bSCy Schubert {
1303*7f2fe78bSCy Schubert     if (*etp) {
1304*7f2fe78bSCy Schubert         ktest_empty_enc_tkt_part(*etp);
1305*7f2fe78bSCy Schubert         free(*etp);
1306*7f2fe78bSCy Schubert         *etp = NULL;
1307*7f2fe78bSCy Schubert     }
1308*7f2fe78bSCy Schubert }
1309*7f2fe78bSCy Schubert 
1310*7f2fe78bSCy Schubert void
ktest_empty_enc_kdc_rep_part(krb5_enc_kdc_rep_part * ekr)1311*7f2fe78bSCy Schubert ktest_empty_enc_kdc_rep_part(krb5_enc_kdc_rep_part *ekr)
1312*7f2fe78bSCy Schubert {
1313*7f2fe78bSCy Schubert     if (ekr->session)
1314*7f2fe78bSCy Schubert         ktest_destroy_keyblock(&ekr->session);
1315*7f2fe78bSCy Schubert 
1316*7f2fe78bSCy Schubert     if (ekr->server)
1317*7f2fe78bSCy Schubert         ktest_destroy_principal(&ekr->server);
1318*7f2fe78bSCy Schubert 
1319*7f2fe78bSCy Schubert     if (ekr->caddrs)
1320*7f2fe78bSCy Schubert         ktest_destroy_addresses(&ekr->caddrs);
1321*7f2fe78bSCy Schubert     ktest_destroy_last_req(&ekr->last_req);
1322*7f2fe78bSCy Schubert }
1323*7f2fe78bSCy Schubert 
1324*7f2fe78bSCy Schubert void
ktest_destroy_transited(krb5_transited * t)1325*7f2fe78bSCy Schubert ktest_destroy_transited(krb5_transited *t)
1326*7f2fe78bSCy Schubert {
1327*7f2fe78bSCy Schubert     if (t->tr_contents.data)
1328*7f2fe78bSCy Schubert         ktest_empty_data(&t->tr_contents);
1329*7f2fe78bSCy Schubert }
1330*7f2fe78bSCy Schubert 
1331*7f2fe78bSCy Schubert void
ktest_empty_ap_rep(krb5_ap_rep * ar)1332*7f2fe78bSCy Schubert ktest_empty_ap_rep(krb5_ap_rep *ar)
1333*7f2fe78bSCy Schubert {
1334*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&ar->enc_part);
1335*7f2fe78bSCy Schubert }
1336*7f2fe78bSCy Schubert 
1337*7f2fe78bSCy Schubert void
ktest_empty_ap_req(krb5_ap_req * ar)1338*7f2fe78bSCy Schubert ktest_empty_ap_req(krb5_ap_req *ar)
1339*7f2fe78bSCy Schubert {
1340*7f2fe78bSCy Schubert     if (ar->ticket)
1341*7f2fe78bSCy Schubert         ktest_destroy_ticket(&ar->ticket);
1342*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&ar->authenticator);
1343*7f2fe78bSCy Schubert }
1344*7f2fe78bSCy Schubert 
1345*7f2fe78bSCy Schubert void
ktest_empty_cred_enc_part(krb5_cred_enc_part * cep)1346*7f2fe78bSCy Schubert ktest_empty_cred_enc_part(krb5_cred_enc_part *cep)
1347*7f2fe78bSCy Schubert {
1348*7f2fe78bSCy Schubert     if (cep->s_address)
1349*7f2fe78bSCy Schubert         ktest_destroy_address(&cep->s_address);
1350*7f2fe78bSCy Schubert     if (cep->r_address)
1351*7f2fe78bSCy Schubert         ktest_destroy_address(&cep->r_address);
1352*7f2fe78bSCy Schubert     if (cep->ticket_info)
1353*7f2fe78bSCy Schubert         ktest_destroy_sequence_of_cred_info(&cep->ticket_info);
1354*7f2fe78bSCy Schubert }
1355*7f2fe78bSCy Schubert 
1356*7f2fe78bSCy Schubert void
ktest_destroy_cred_info(krb5_cred_info ** ci)1357*7f2fe78bSCy Schubert ktest_destroy_cred_info(krb5_cred_info **ci)
1358*7f2fe78bSCy Schubert {
1359*7f2fe78bSCy Schubert     if ((*ci)->session)
1360*7f2fe78bSCy Schubert         ktest_destroy_keyblock(&(*ci)->session);
1361*7f2fe78bSCy Schubert     if ((*ci)->client)
1362*7f2fe78bSCy Schubert         ktest_destroy_principal(&(*ci)->client);
1363*7f2fe78bSCy Schubert     if ((*ci)->server)
1364*7f2fe78bSCy Schubert         ktest_destroy_principal(&(*ci)->server);
1365*7f2fe78bSCy Schubert     if ((*ci)->caddrs)
1366*7f2fe78bSCy Schubert         ktest_destroy_addresses(&(*ci)->caddrs);
1367*7f2fe78bSCy Schubert     free(*ci);
1368*7f2fe78bSCy Schubert     *ci = NULL;
1369*7f2fe78bSCy Schubert }
1370*7f2fe78bSCy Schubert 
1371*7f2fe78bSCy Schubert void
ktest_destroy_sequence_of_cred_info(krb5_cred_info *** soci)1372*7f2fe78bSCy Schubert ktest_destroy_sequence_of_cred_info(krb5_cred_info ***soci)
1373*7f2fe78bSCy Schubert {
1374*7f2fe78bSCy Schubert     int i;
1375*7f2fe78bSCy Schubert 
1376*7f2fe78bSCy Schubert     for (i = 0; (*soci)[i] != NULL; i++)
1377*7f2fe78bSCy Schubert         ktest_destroy_cred_info(&(*soci)[i]);
1378*7f2fe78bSCy Schubert     free(*soci);
1379*7f2fe78bSCy Schubert     *soci = NULL;
1380*7f2fe78bSCy Schubert }
1381*7f2fe78bSCy Schubert 
1382*7f2fe78bSCy Schubert void
ktest_empty_safe(krb5_safe * s)1383*7f2fe78bSCy Schubert ktest_empty_safe(krb5_safe *s)
1384*7f2fe78bSCy Schubert {
1385*7f2fe78bSCy Schubert     ktest_empty_data(&s->user_data);
1386*7f2fe78bSCy Schubert     ktest_destroy_address(&s->s_address);
1387*7f2fe78bSCy Schubert     ktest_destroy_address(&s->r_address);
1388*7f2fe78bSCy Schubert     ktest_destroy_checksum(&s->checksum);
1389*7f2fe78bSCy Schubert }
1390*7f2fe78bSCy Schubert 
1391*7f2fe78bSCy Schubert void
ktest_empty_priv_enc_part(krb5_priv_enc_part * pep)1392*7f2fe78bSCy Schubert ktest_empty_priv_enc_part(krb5_priv_enc_part *pep)
1393*7f2fe78bSCy Schubert {
1394*7f2fe78bSCy Schubert     ktest_empty_data(&pep->user_data);
1395*7f2fe78bSCy Schubert     ktest_destroy_address(&pep->s_address);
1396*7f2fe78bSCy Schubert     ktest_destroy_address(&pep->r_address);
1397*7f2fe78bSCy Schubert }
1398*7f2fe78bSCy Schubert 
1399*7f2fe78bSCy Schubert void
ktest_empty_priv(krb5_priv * p)1400*7f2fe78bSCy Schubert ktest_empty_priv(krb5_priv *p)
1401*7f2fe78bSCy Schubert {
1402*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&p->enc_part);
1403*7f2fe78bSCy Schubert }
1404*7f2fe78bSCy Schubert 
1405*7f2fe78bSCy Schubert void
ktest_empty_cred(krb5_cred * c)1406*7f2fe78bSCy Schubert ktest_empty_cred(krb5_cred *c)
1407*7f2fe78bSCy Schubert {
1408*7f2fe78bSCy Schubert     ktest_destroy_sequence_of_ticket(&c->tickets);
1409*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&c->enc_part);
1410*7f2fe78bSCy Schubert     /* enc_part2 */
1411*7f2fe78bSCy Schubert }
1412*7f2fe78bSCy Schubert 
1413*7f2fe78bSCy Schubert void
ktest_destroy_last_req(krb5_last_req_entry *** lr)1414*7f2fe78bSCy Schubert ktest_destroy_last_req(krb5_last_req_entry ***lr)
1415*7f2fe78bSCy Schubert {
1416*7f2fe78bSCy Schubert     int i;
1417*7f2fe78bSCy Schubert 
1418*7f2fe78bSCy Schubert     if (*lr) {
1419*7f2fe78bSCy Schubert         for (i=0; (*lr)[i] != NULL; i++)
1420*7f2fe78bSCy Schubert             free((*lr)[i]);
1421*7f2fe78bSCy Schubert 
1422*7f2fe78bSCy Schubert         free(*lr);
1423*7f2fe78bSCy Schubert     }
1424*7f2fe78bSCy Schubert }
1425*7f2fe78bSCy Schubert 
1426*7f2fe78bSCy Schubert void
ktest_empty_error(krb5_error * kerr)1427*7f2fe78bSCy Schubert ktest_empty_error(krb5_error *kerr)
1428*7f2fe78bSCy Schubert {
1429*7f2fe78bSCy Schubert     if (kerr->client)
1430*7f2fe78bSCy Schubert         ktest_destroy_principal(&kerr->client);
1431*7f2fe78bSCy Schubert     if (kerr->server)
1432*7f2fe78bSCy Schubert         ktest_destroy_principal(&kerr->server);
1433*7f2fe78bSCy Schubert     ktest_empty_data(&kerr->text);
1434*7f2fe78bSCy Schubert     ktest_empty_data(&kerr->e_data);
1435*7f2fe78bSCy Schubert }
1436*7f2fe78bSCy Schubert 
1437*7f2fe78bSCy Schubert void
ktest_empty_ap_rep_enc_part(krb5_ap_rep_enc_part * arep)1438*7f2fe78bSCy Schubert ktest_empty_ap_rep_enc_part(krb5_ap_rep_enc_part *arep)
1439*7f2fe78bSCy Schubert {
1440*7f2fe78bSCy Schubert     ktest_destroy_keyblock(&(arep)->subkey);
1441*7f2fe78bSCy Schubert }
1442*7f2fe78bSCy Schubert 
1443*7f2fe78bSCy Schubert void
ktest_empty_sam_challenge_2(krb5_sam_challenge_2 * p)1444*7f2fe78bSCy Schubert ktest_empty_sam_challenge_2(krb5_sam_challenge_2 *p)
1445*7f2fe78bSCy Schubert {
1446*7f2fe78bSCy Schubert     krb5_checksum **ck;
1447*7f2fe78bSCy Schubert 
1448*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_challenge_2_body);
1449*7f2fe78bSCy Schubert     if (p->sam_cksum != NULL) {
1450*7f2fe78bSCy Schubert         for (ck = p->sam_cksum; *ck != NULL; ck++)
1451*7f2fe78bSCy Schubert             ktest_destroy_checksum(ck);
1452*7f2fe78bSCy Schubert         free(p->sam_cksum);
1453*7f2fe78bSCy Schubert         p->sam_cksum = NULL;
1454*7f2fe78bSCy Schubert     }
1455*7f2fe78bSCy Schubert }
1456*7f2fe78bSCy Schubert 
1457*7f2fe78bSCy Schubert void
ktest_empty_sam_challenge_2_body(krb5_sam_challenge_2_body * p)1458*7f2fe78bSCy Schubert ktest_empty_sam_challenge_2_body(krb5_sam_challenge_2_body *p)
1459*7f2fe78bSCy Schubert {
1460*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_type_name);
1461*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_track_id);
1462*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_challenge_label);
1463*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_challenge);
1464*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_response_prompt);
1465*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_pk_for_sad);
1466*7f2fe78bSCy Schubert }
1467*7f2fe78bSCy Schubert 
1468*7f2fe78bSCy Schubert void
ktest_empty_sam_response_2(krb5_sam_response_2 * p)1469*7f2fe78bSCy Schubert ktest_empty_sam_response_2(krb5_sam_response_2 *p)
1470*7f2fe78bSCy Schubert {
1471*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_track_id);
1472*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_enc_nonce_or_sad.ciphertext);
1473*7f2fe78bSCy Schubert }
1474*7f2fe78bSCy Schubert 
1475*7f2fe78bSCy Schubert void
ktest_empty_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 * p)1476*7f2fe78bSCy Schubert ktest_empty_enc_sam_response_enc_2(krb5_enc_sam_response_enc_2 *p)
1477*7f2fe78bSCy Schubert {
1478*7f2fe78bSCy Schubert     ktest_empty_data(&p->sam_sad);
1479*7f2fe78bSCy Schubert }
1480*7f2fe78bSCy Schubert 
1481*7f2fe78bSCy Schubert void
ktest_empty_pa_for_user(krb5_pa_for_user * p)1482*7f2fe78bSCy Schubert ktest_empty_pa_for_user(krb5_pa_for_user *p)
1483*7f2fe78bSCy Schubert {
1484*7f2fe78bSCy Schubert     ktest_destroy_principal(&p->user);
1485*7f2fe78bSCy Schubert     ktest_empty_checksum(&p->cksum);
1486*7f2fe78bSCy Schubert     ktest_empty_data(&p->auth_package);
1487*7f2fe78bSCy Schubert }
1488*7f2fe78bSCy Schubert 
1489*7f2fe78bSCy Schubert void
ktest_empty_pa_s4u_x509_user(krb5_pa_s4u_x509_user * p)1490*7f2fe78bSCy Schubert ktest_empty_pa_s4u_x509_user(krb5_pa_s4u_x509_user *p)
1491*7f2fe78bSCy Schubert {
1492*7f2fe78bSCy Schubert     ktest_destroy_principal(&p->user_id.user);
1493*7f2fe78bSCy Schubert     ktest_empty_data(&p->user_id.subject_cert);
1494*7f2fe78bSCy Schubert     free(p->cksum.contents);
1495*7f2fe78bSCy Schubert }
1496*7f2fe78bSCy Schubert 
1497*7f2fe78bSCy Schubert void
ktest_empty_ad_kdcissued(krb5_ad_kdcissued * p)1498*7f2fe78bSCy Schubert ktest_empty_ad_kdcissued(krb5_ad_kdcissued *p)
1499*7f2fe78bSCy Schubert {
1500*7f2fe78bSCy Schubert     free(p->ad_checksum.contents);
1501*7f2fe78bSCy Schubert     ktest_destroy_principal(&p->i_principal);
1502*7f2fe78bSCy Schubert     ktest_destroy_authorization_data(&p->elements);
1503*7f2fe78bSCy Schubert }
1504*7f2fe78bSCy Schubert 
1505*7f2fe78bSCy Schubert void
ktest_empty_iakerb_header(krb5_iakerb_header * p)1506*7f2fe78bSCy Schubert ktest_empty_iakerb_header(krb5_iakerb_header *p)
1507*7f2fe78bSCy Schubert {
1508*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->target_realm);
1509*7f2fe78bSCy Schubert     krb5_free_data(NULL, p->cookie);
1510*7f2fe78bSCy Schubert }
1511*7f2fe78bSCy Schubert 
1512*7f2fe78bSCy Schubert void
ktest_empty_iakerb_finished(krb5_iakerb_finished * p)1513*7f2fe78bSCy Schubert ktest_empty_iakerb_finished(krb5_iakerb_finished *p)
1514*7f2fe78bSCy Schubert {
1515*7f2fe78bSCy Schubert     krb5_free_checksum_contents(NULL, &p->checksum);
1516*7f2fe78bSCy Schubert }
1517*7f2fe78bSCy Schubert 
1518*7f2fe78bSCy Schubert static void
ktest_empty_fast_finished(krb5_fast_finished * p)1519*7f2fe78bSCy Schubert ktest_empty_fast_finished(krb5_fast_finished *p)
1520*7f2fe78bSCy Schubert {
1521*7f2fe78bSCy Schubert     ktest_destroy_principal(&p->client);
1522*7f2fe78bSCy Schubert     ktest_empty_checksum(&p->ticket_checksum);
1523*7f2fe78bSCy Schubert }
1524*7f2fe78bSCy Schubert 
1525*7f2fe78bSCy Schubert void
ktest_empty_fast_response(krb5_fast_response * p)1526*7f2fe78bSCy Schubert ktest_empty_fast_response(krb5_fast_response *p)
1527*7f2fe78bSCy Schubert {
1528*7f2fe78bSCy Schubert     ktest_destroy_pa_data_array(&p->padata);
1529*7f2fe78bSCy Schubert     ktest_destroy_keyblock(&p->strengthen_key);
1530*7f2fe78bSCy Schubert     if (p->finished != NULL) {
1531*7f2fe78bSCy Schubert         ktest_empty_fast_finished(p->finished);
1532*7f2fe78bSCy Schubert         free(p->finished);
1533*7f2fe78bSCy Schubert         p->finished = NULL;
1534*7f2fe78bSCy Schubert     }
1535*7f2fe78bSCy Schubert }
1536*7f2fe78bSCy Schubert 
1537*7f2fe78bSCy Schubert static void
ktest_empty_algorithm_identifier(krb5_algorithm_identifier * p)1538*7f2fe78bSCy Schubert ktest_empty_algorithm_identifier(krb5_algorithm_identifier *p)
1539*7f2fe78bSCy Schubert {
1540*7f2fe78bSCy Schubert     ktest_empty_data(&p->algorithm);
1541*7f2fe78bSCy Schubert     ktest_empty_data(&p->parameters);
1542*7f2fe78bSCy Schubert }
1543*7f2fe78bSCy Schubert 
1544*7f2fe78bSCy Schubert void
ktest_empty_otp_tokeninfo(krb5_otp_tokeninfo * p)1545*7f2fe78bSCy Schubert ktest_empty_otp_tokeninfo(krb5_otp_tokeninfo *p)
1546*7f2fe78bSCy Schubert {
1547*7f2fe78bSCy Schubert     krb5_algorithm_identifier **alg;
1548*7f2fe78bSCy Schubert 
1549*7f2fe78bSCy Schubert     p->flags = 0;
1550*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->vendor);
1551*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->challenge);
1552*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->token_id);
1553*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->alg_id);
1554*7f2fe78bSCy Schubert     for (alg = p->supported_hash_alg; alg != NULL && *alg != NULL; alg++) {
1555*7f2fe78bSCy Schubert         ktest_empty_algorithm_identifier(*alg);
1556*7f2fe78bSCy Schubert         free(*alg);
1557*7f2fe78bSCy Schubert     }
1558*7f2fe78bSCy Schubert     free(p->supported_hash_alg);
1559*7f2fe78bSCy Schubert     p->supported_hash_alg = NULL;
1560*7f2fe78bSCy Schubert     p->length = p->format = p->iteration_count = -1;
1561*7f2fe78bSCy Schubert }
1562*7f2fe78bSCy Schubert 
1563*7f2fe78bSCy Schubert void
ktest_empty_pa_otp_challenge(krb5_pa_otp_challenge * p)1564*7f2fe78bSCy Schubert ktest_empty_pa_otp_challenge(krb5_pa_otp_challenge *p)
1565*7f2fe78bSCy Schubert {
1566*7f2fe78bSCy Schubert     krb5_otp_tokeninfo **ti;
1567*7f2fe78bSCy Schubert 
1568*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->nonce);
1569*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->service);
1570*7f2fe78bSCy Schubert     for (ti = p->tokeninfo; *ti != NULL; ti++) {
1571*7f2fe78bSCy Schubert         ktest_empty_otp_tokeninfo(*ti);
1572*7f2fe78bSCy Schubert         free(*ti);
1573*7f2fe78bSCy Schubert     }
1574*7f2fe78bSCy Schubert     free(p->tokeninfo);
1575*7f2fe78bSCy Schubert     p->tokeninfo = NULL;
1576*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->salt);
1577*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->s2kparams);
1578*7f2fe78bSCy Schubert }
1579*7f2fe78bSCy Schubert 
1580*7f2fe78bSCy Schubert void
ktest_empty_pa_otp_req(krb5_pa_otp_req * p)1581*7f2fe78bSCy Schubert ktest_empty_pa_otp_req(krb5_pa_otp_req *p)
1582*7f2fe78bSCy Schubert {
1583*7f2fe78bSCy Schubert     p->flags = 0;
1584*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->nonce);
1585*7f2fe78bSCy Schubert     ktest_destroy_enc_data(&p->enc_data);
1586*7f2fe78bSCy Schubert     if (p->hash_alg != NULL)
1587*7f2fe78bSCy Schubert         ktest_empty_algorithm_identifier(p->hash_alg);
1588*7f2fe78bSCy Schubert     free(p->hash_alg);
1589*7f2fe78bSCy Schubert     p->hash_alg = NULL;
1590*7f2fe78bSCy Schubert     p->iteration_count = -1;
1591*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->otp_value);
1592*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->pin);
1593*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->challenge);
1594*7f2fe78bSCy Schubert     p->time = 0;
1595*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->counter);
1596*7f2fe78bSCy Schubert     p->format = -1;
1597*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->token_id);
1598*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->alg_id);
1599*7f2fe78bSCy Schubert     krb5_free_data_contents(NULL, &p->vendor);
1600*7f2fe78bSCy Schubert }
1601*7f2fe78bSCy Schubert 
1602*7f2fe78bSCy Schubert #ifndef DISABLE_PKINIT
1603*7f2fe78bSCy Schubert 
1604*7f2fe78bSCy Schubert static void
ktest_empty_pk_authenticator(krb5_pk_authenticator * p)1605*7f2fe78bSCy Schubert ktest_empty_pk_authenticator(krb5_pk_authenticator *p)
1606*7f2fe78bSCy Schubert {
1607*7f2fe78bSCy Schubert     ktest_empty_checksum(&p->paChecksum);
1608*7f2fe78bSCy Schubert     p->paChecksum.contents = NULL;
1609*7f2fe78bSCy Schubert     krb5_free_data(NULL, p->freshnessToken);
1610*7f2fe78bSCy Schubert     p->freshnessToken = NULL;
1611*7f2fe78bSCy Schubert }
1612*7f2fe78bSCy Schubert 
1613*7f2fe78bSCy Schubert static void
ktest_empty_external_principal_identifier(krb5_external_principal_identifier * p)1614*7f2fe78bSCy Schubert ktest_empty_external_principal_identifier(
1615*7f2fe78bSCy Schubert     krb5_external_principal_identifier *p)
1616*7f2fe78bSCy Schubert {
1617*7f2fe78bSCy Schubert     ktest_empty_data(&p->subjectName);
1618*7f2fe78bSCy Schubert     ktest_empty_data(&p->issuerAndSerialNumber);
1619*7f2fe78bSCy Schubert     ktest_empty_data(&p->subjectKeyIdentifier);
1620*7f2fe78bSCy Schubert }
1621*7f2fe78bSCy Schubert 
1622*7f2fe78bSCy Schubert void
ktest_empty_pa_pk_as_req(krb5_pa_pk_as_req * p)1623*7f2fe78bSCy Schubert ktest_empty_pa_pk_as_req(krb5_pa_pk_as_req *p)
1624*7f2fe78bSCy Schubert {
1625*7f2fe78bSCy Schubert     krb5_external_principal_identifier **pi;
1626*7f2fe78bSCy Schubert 
1627*7f2fe78bSCy Schubert     ktest_empty_data(&p->signedAuthPack);
1628*7f2fe78bSCy Schubert     for (pi = p->trustedCertifiers; *pi != NULL; pi++) {
1629*7f2fe78bSCy Schubert         ktest_empty_external_principal_identifier(*pi);
1630*7f2fe78bSCy Schubert         free(*pi);
1631*7f2fe78bSCy Schubert     }
1632*7f2fe78bSCy Schubert     free(p->trustedCertifiers);
1633*7f2fe78bSCy Schubert     p->trustedCertifiers = NULL;
1634*7f2fe78bSCy Schubert     ktest_empty_data(&p->kdcPkId);
1635*7f2fe78bSCy Schubert }
1636*7f2fe78bSCy Schubert 
1637*7f2fe78bSCy Schubert static void
ktest_empty_dh_rep_info(krb5_dh_rep_info * p)1638*7f2fe78bSCy Schubert ktest_empty_dh_rep_info(krb5_dh_rep_info *p)
1639*7f2fe78bSCy Schubert {
1640*7f2fe78bSCy Schubert     ktest_empty_data(&p->dhSignedData);
1641*7f2fe78bSCy Schubert     ktest_empty_data(&p->serverDHNonce);
1642*7f2fe78bSCy Schubert     ktest_destroy_data(&p->kdfID);
1643*7f2fe78bSCy Schubert }
1644*7f2fe78bSCy Schubert 
1645*7f2fe78bSCy Schubert void
ktest_empty_pa_pk_as_rep(krb5_pa_pk_as_rep * p)1646*7f2fe78bSCy Schubert ktest_empty_pa_pk_as_rep(krb5_pa_pk_as_rep *p)
1647*7f2fe78bSCy Schubert {
1648*7f2fe78bSCy Schubert     if (p->choice == choice_pa_pk_as_rep_dhInfo)
1649*7f2fe78bSCy Schubert         ktest_empty_dh_rep_info(&p->u.dh_Info);
1650*7f2fe78bSCy Schubert     else if (p->choice == choice_pa_pk_as_rep_encKeyPack)
1651*7f2fe78bSCy Schubert         ktest_empty_data(&p->u.encKeyPack);
1652*7f2fe78bSCy Schubert     p->choice = choice_pa_pk_as_rep_UNKNOWN;
1653*7f2fe78bSCy Schubert }
1654*7f2fe78bSCy Schubert 
1655*7f2fe78bSCy Schubert void
ktest_empty_auth_pack(krb5_auth_pack * p)1656*7f2fe78bSCy Schubert ktest_empty_auth_pack(krb5_auth_pack *p)
1657*7f2fe78bSCy Schubert {
1658*7f2fe78bSCy Schubert     krb5_algorithm_identifier **ai;
1659*7f2fe78bSCy Schubert     krb5_data **d;
1660*7f2fe78bSCy Schubert 
1661*7f2fe78bSCy Schubert     ktest_empty_pk_authenticator(&p->pkAuthenticator);
1662*7f2fe78bSCy Schubert     ktest_empty_data(&p->clientPublicValue);
1663*7f2fe78bSCy Schubert     if (p->supportedCMSTypes != NULL) {
1664*7f2fe78bSCy Schubert         for (ai = p->supportedCMSTypes; *ai != NULL; ai++) {
1665*7f2fe78bSCy Schubert             ktest_empty_algorithm_identifier(*ai);
1666*7f2fe78bSCy Schubert             free(*ai);
1667*7f2fe78bSCy Schubert         }
1668*7f2fe78bSCy Schubert         free(p->supportedCMSTypes);
1669*7f2fe78bSCy Schubert         p->supportedCMSTypes = NULL;
1670*7f2fe78bSCy Schubert     }
1671*7f2fe78bSCy Schubert     ktest_empty_data(&p->clientDHNonce);
1672*7f2fe78bSCy Schubert     if (p->supportedKDFs != NULL) {
1673*7f2fe78bSCy Schubert         for (d = p->supportedKDFs; *d != NULL; d++) {
1674*7f2fe78bSCy Schubert             ktest_empty_data(*d);
1675*7f2fe78bSCy Schubert             free(*d);
1676*7f2fe78bSCy Schubert         }
1677*7f2fe78bSCy Schubert         free(p->supportedKDFs);
1678*7f2fe78bSCy Schubert         p->supportedKDFs = NULL;
1679*7f2fe78bSCy Schubert     }
1680*7f2fe78bSCy Schubert }
1681*7f2fe78bSCy Schubert 
1682*7f2fe78bSCy Schubert void
ktest_empty_kdc_dh_key_info(krb5_kdc_dh_key_info * p)1683*7f2fe78bSCy Schubert ktest_empty_kdc_dh_key_info(krb5_kdc_dh_key_info *p)
1684*7f2fe78bSCy Schubert {
1685*7f2fe78bSCy Schubert     ktest_empty_data(&p->subjectPublicKey);
1686*7f2fe78bSCy Schubert }
1687*7f2fe78bSCy Schubert 
1688*7f2fe78bSCy Schubert void
ktest_empty_reply_key_pack(krb5_reply_key_pack * p)1689*7f2fe78bSCy Schubert ktest_empty_reply_key_pack(krb5_reply_key_pack *p)
1690*7f2fe78bSCy Schubert {
1691*7f2fe78bSCy Schubert     ktest_empty_keyblock(&p->replyKey);
1692*7f2fe78bSCy Schubert     ktest_empty_checksum(&p->asChecksum);
1693*7f2fe78bSCy Schubert }
1694*7f2fe78bSCy Schubert 
ktest_empty_sp80056a_other_info(krb5_sp80056a_other_info * p)1695*7f2fe78bSCy Schubert void ktest_empty_sp80056a_other_info(krb5_sp80056a_other_info *p)
1696*7f2fe78bSCy Schubert {
1697*7f2fe78bSCy Schubert     ktest_empty_algorithm_identifier(&p->algorithm_identifier);
1698*7f2fe78bSCy Schubert     ktest_destroy_principal(&p->party_u_info);
1699*7f2fe78bSCy Schubert     ktest_destroy_principal(&p->party_v_info);
1700*7f2fe78bSCy Schubert     ktest_empty_data(&p->supp_pub_info);
1701*7f2fe78bSCy Schubert }
1702*7f2fe78bSCy Schubert 
ktest_empty_pkinit_supp_pub_info(krb5_pkinit_supp_pub_info * p)1703*7f2fe78bSCy Schubert void ktest_empty_pkinit_supp_pub_info(krb5_pkinit_supp_pub_info *p)
1704*7f2fe78bSCy Schubert {
1705*7f2fe78bSCy Schubert     ktest_empty_data(&p->as_req);
1706*7f2fe78bSCy Schubert     ktest_empty_data(&p->pk_as_rep);
1707*7f2fe78bSCy Schubert }
1708*7f2fe78bSCy Schubert 
1709*7f2fe78bSCy Schubert #endif /* not DISABLE_PKINIT */
1710*7f2fe78bSCy Schubert 
1711*7f2fe78bSCy Schubert #ifdef ENABLE_LDAP
1712*7f2fe78bSCy Schubert void
ktest_empty_ldap_seqof_key_data(krb5_context ctx,ldap_seqof_key_data * p)1713*7f2fe78bSCy Schubert ktest_empty_ldap_seqof_key_data(krb5_context ctx, ldap_seqof_key_data *p)
1714*7f2fe78bSCy Schubert {
1715*7f2fe78bSCy Schubert     int i;
1716*7f2fe78bSCy Schubert 
1717*7f2fe78bSCy Schubert     for (i = 0; i < p->n_key_data; i++) {
1718*7f2fe78bSCy Schubert         free(p->key_data[i].key_data_contents[0]);
1719*7f2fe78bSCy Schubert         free(p->key_data[i].key_data_contents[1]);
1720*7f2fe78bSCy Schubert     }
1721*7f2fe78bSCy Schubert     free(p->key_data);
1722*7f2fe78bSCy Schubert }
1723*7f2fe78bSCy Schubert #endif
1724*7f2fe78bSCy Schubert 
1725*7f2fe78bSCy Schubert void
ktest_empty_kkdcp_message(krb5_kkdcp_message * p)1726*7f2fe78bSCy Schubert ktest_empty_kkdcp_message(krb5_kkdcp_message *p)
1727*7f2fe78bSCy Schubert {
1728*7f2fe78bSCy Schubert     ktest_empty_data(&p->kerb_message);
1729*7f2fe78bSCy Schubert     ktest_empty_data(&p->target_domain);
1730*7f2fe78bSCy Schubert     p->dclocator_hint = -1;
1731*7f2fe78bSCy Schubert }
1732*7f2fe78bSCy Schubert 
1733*7f2fe78bSCy Schubert static void
destroy_verifier_mac(krb5_verifier_mac ** vmac)1734*7f2fe78bSCy Schubert destroy_verifier_mac(krb5_verifier_mac **vmac)
1735*7f2fe78bSCy Schubert {
1736*7f2fe78bSCy Schubert     if (*vmac == NULL)
1737*7f2fe78bSCy Schubert         return;
1738*7f2fe78bSCy Schubert     ktest_destroy_principal(&(*vmac)->princ);
1739*7f2fe78bSCy Schubert     ktest_empty_checksum(&(*vmac)->checksum);
1740*7f2fe78bSCy Schubert     free(*vmac);
1741*7f2fe78bSCy Schubert     *vmac = NULL;
1742*7f2fe78bSCy Schubert }
1743*7f2fe78bSCy Schubert 
1744*7f2fe78bSCy Schubert void
ktest_empty_cammac(krb5_cammac * p)1745*7f2fe78bSCy Schubert ktest_empty_cammac(krb5_cammac *p)
1746*7f2fe78bSCy Schubert {
1747*7f2fe78bSCy Schubert     krb5_verifier_mac **vmacp;
1748*7f2fe78bSCy Schubert 
1749*7f2fe78bSCy Schubert     ktest_destroy_authorization_data(&p->elements);
1750*7f2fe78bSCy Schubert     destroy_verifier_mac(&p->kdc_verifier);
1751*7f2fe78bSCy Schubert     destroy_verifier_mac(&p->svc_verifier);
1752*7f2fe78bSCy Schubert     for (vmacp = p->other_verifiers; vmacp != NULL && *vmacp != NULL; vmacp++)
1753*7f2fe78bSCy Schubert         destroy_verifier_mac(vmacp);
1754*7f2fe78bSCy Schubert     free(p->other_verifiers);
1755*7f2fe78bSCy Schubert     p->other_verifiers = NULL;
1756*7f2fe78bSCy Schubert }
1757*7f2fe78bSCy Schubert 
1758*7f2fe78bSCy Schubert void
ktest_empty_secure_cookie(krb5_secure_cookie * p)1759*7f2fe78bSCy Schubert ktest_empty_secure_cookie(krb5_secure_cookie *p)
1760*7f2fe78bSCy Schubert {
1761*7f2fe78bSCy Schubert     ktest_empty_pa_data_array(p->data);
1762*7f2fe78bSCy Schubert }
1763*7f2fe78bSCy Schubert 
1764*7f2fe78bSCy Schubert void
ktest_empty_spake_factor(krb5_spake_factor * p)1765*7f2fe78bSCy Schubert ktest_empty_spake_factor(krb5_spake_factor *p)
1766*7f2fe78bSCy Schubert {
1767*7f2fe78bSCy Schubert     krb5_free_data(NULL, p->data);
1768*7f2fe78bSCy Schubert     p->data = NULL;
1769*7f2fe78bSCy Schubert }
1770*7f2fe78bSCy Schubert 
1771*7f2fe78bSCy Schubert void
ktest_empty_pa_spake(krb5_pa_spake * p)1772*7f2fe78bSCy Schubert ktest_empty_pa_spake(krb5_pa_spake *p)
1773*7f2fe78bSCy Schubert {
1774*7f2fe78bSCy Schubert     krb5_spake_factor **f;
1775*7f2fe78bSCy Schubert 
1776*7f2fe78bSCy Schubert     switch (p->choice) {
1777*7f2fe78bSCy Schubert     case SPAKE_MSGTYPE_SUPPORT:
1778*7f2fe78bSCy Schubert         free(p->u.support.groups);
1779*7f2fe78bSCy Schubert         break;
1780*7f2fe78bSCy Schubert     case SPAKE_MSGTYPE_CHALLENGE:
1781*7f2fe78bSCy Schubert         ktest_empty_data(&p->u.challenge.pubkey);
1782*7f2fe78bSCy Schubert         for (f = p->u.challenge.factors; *f != NULL; f++) {
1783*7f2fe78bSCy Schubert             ktest_empty_spake_factor(*f);
1784*7f2fe78bSCy Schubert             free(*f);
1785*7f2fe78bSCy Schubert         }
1786*7f2fe78bSCy Schubert         free(p->u.challenge.factors);
1787*7f2fe78bSCy Schubert         break;
1788*7f2fe78bSCy Schubert     case SPAKE_MSGTYPE_RESPONSE:
1789*7f2fe78bSCy Schubert         ktest_empty_data(&p->u.response.pubkey);
1790*7f2fe78bSCy Schubert         ktest_destroy_enc_data(&p->u.response.factor);
1791*7f2fe78bSCy Schubert         break;
1792*7f2fe78bSCy Schubert     case SPAKE_MSGTYPE_ENCDATA:
1793*7f2fe78bSCy Schubert         ktest_destroy_enc_data(&p->u.encdata);
1794*7f2fe78bSCy Schubert         break;
1795*7f2fe78bSCy Schubert     default:
1796*7f2fe78bSCy Schubert         break;
1797*7f2fe78bSCy Schubert     }
1798*7f2fe78bSCy Schubert     p->choice = SPAKE_MSGTYPE_UNKNOWN;
1799*7f2fe78bSCy Schubert }
1800