1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* lib/krb5/asn.1/asn1_k_decode_kdc.c */
/*
* Copyright 1994, 2007, 2008, 2010 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
#include "asn1_k_decode_macros.h"
asn1_error_code
asn1_decode_kdc_req(asn1buf *buf, krb5_kdc_req *val)
{
setup();
val->padata = NULL;
{ begin_structure();
{ krb5_kvno kvno;
get_field(kvno,1,asn1_decode_kvno);
if (kvno != KVNO) clean_return(KRB5KDC_ERR_BAD_PVNO); }
get_field(val->msg_type,2,asn1_decode_msgtype);
opt_field(val->padata,3,asn1_decode_sequence_of_pa_data,NULL);
get_field(*val,4,asn1_decode_kdc_req_body);
end_structure();
val->magic = KV5M_KDC_REQ;
}
return 0;
error_out:
krb5_free_pa_data(NULL, val->padata);
val->padata = NULL;
return retval;
}
asn1_error_code
asn1_decode_kdc_req_body(asn1buf *buf, krb5_kdc_req *val)
{
setup();
val->client = NULL;
val->server = NULL;
val->ktype = NULL;
val->addresses = NULL;
val->authorization_data.ciphertext.data = NULL;
val->unenc_authdata = NULL;
val->second_ticket = NULL;
{
krb5_principal psave;
begin_structure();
get_field(val->kdc_options,0,asn1_decode_kdc_options);
if (tagnum == 1) { alloc_principal(val->client); }
opt_field(val->client,1,asn1_decode_principal_name,NULL);
alloc_principal(val->server);
get_field(val->server,2,asn1_decode_realm);
if (val->client != NULL) {
retval = asn1_krb5_realm_copy(val->client,val->server);
if (retval) clean_return(retval); }
/* If opt_field server is missing, memory reference to server is
* lost and results in memory leak
*/
psave = val->server;
opt_field(val->server,3,asn1_decode_principal_name,NULL);
if (val->server == NULL) {
if (psave->realm.data) {
free(psave->realm.data);
psave->realm.data = NULL;
psave->realm.length=0;
}
free(psave);
}
opt_field(val->from,4,asn1_decode_kerberos_time,0);
get_field(val->till,5,asn1_decode_kerberos_time);
opt_field(val->rtime,6,asn1_decode_kerberos_time,0);
get_field(val->nonce,7,asn1_decode_int32);
get_lenfield(val->nktypes,val->ktype,8,asn1_decode_sequence_of_enctype);
opt_field(val->addresses,9,asn1_decode_host_addresses,0);
if (tagnum == 10) {
get_field(val->authorization_data,10,asn1_decode_encrypted_data); }
else {
val->authorization_data.magic = KV5M_ENC_DATA;
val->authorization_data.enctype = 0;
val->authorization_data.kvno = 0;
val->authorization_data.ciphertext.data = NULL;
val->authorization_data.ciphertext.length = 0;
}
opt_field(val->second_ticket,11,asn1_decode_sequence_of_ticket,NULL);
end_structure();
val->magic = KV5M_KDC_REQ;
}
return 0;
error_out:
krb5_free_principal(NULL, val->client);
krb5_free_principal(NULL, val->server);
free(val->ktype);
krb5_free_addresses(NULL, val->addresses);
krb5_free_data_contents(NULL, &val->authorization_data.ciphertext);
krb5_free_tickets(NULL, val->second_ticket);
val->client = NULL;
val->server = NULL;
val->ktype = NULL;
val->addresses = NULL;
val->unenc_authdata = NULL;
val->second_ticket = NULL;
return retval;
}
#ifndef DISABLE_PKINIT
/* PKINIT */
asn1_error_code
asn1_decode_pa_pk_as_req(asn1buf *buf, krb5_pa_pk_as_req *val)
{
setup();
val->signedAuthPack.data = NULL;
val->trustedCertifiers = NULL;
val->kdcPkId.data = NULL;
{
begin_structure();
get_implicit_octet_string(val->signedAuthPack.length, val->signedAuthPack.data, 0);
opt_field(val->trustedCertifiers, 1, asn1_decode_sequence_of_external_principal_identifier, NULL);
opt_implicit_octet_string(val->kdcPkId.length, val->kdcPkId.data, 2);
end_structure();
}
return 0;
error_out:
free(val->signedAuthPack.data);
free(val->trustedCertifiers);
free(val->kdcPkId.data);
val->signedAuthPack.data = NULL;
val->trustedCertifiers = NULL;
val->kdcPkId.data = NULL;
return retval;
}
static void
free_trusted_ca(void *dummy, krb5_trusted_ca *val)
{
if (val->choice == choice_trusted_cas_caName)
free(val->u.caName.data);
else if (val->choice == choice_trusted_cas_issuerAndSerial)
free(val->u.issuerAndSerial.data);
free(val);
}
asn1_error_code
asn1_decode_pa_pk_as_req_draft9(asn1buf *buf, krb5_pa_pk_as_req_draft9 *val)
{
int i;
setup();
val->signedAuthPack.data = NULL;
val->kdcCert.data = NULL;
val->encryptionCert.data = NULL;
val->trustedCertifiers = NULL;
{ begin_structure();
get_implicit_octet_string(val->signedAuthPack.length, val->signedAuthPack.data, 0);
opt_field(val->trustedCertifiers, 1, asn1_decode_sequence_of_trusted_ca, NULL);
opt_lenfield(val->kdcCert.length, val->kdcCert.data, 2, asn1_decode_octetstring);
opt_lenfield(val->encryptionCert.length, val->encryptionCert.data, 2, asn1_decode_octetstring);
end_structure();
}
return 0;
error_out:
free(val->signedAuthPack.data);
free(val->kdcCert.data);
free(val->encryptionCert.data);
if (val->trustedCertifiers) {
for (i = 0; val->trustedCertifiers[i]; i++)
free_trusted_ca(NULL, val->trustedCertifiers[i]);
free(val->trustedCertifiers);
}
val->signedAuthPack.data = NULL;
val->kdcCert.data = NULL;
val->encryptionCert.data = NULL;
val->trustedCertifiers = NULL;
return retval;
}
static void
free_algorithm_identifier(krb5_algorithm_identifier *val)
{
free(val->algorithm.data);
free(val->parameters.data);
free(val);
}
asn1_error_code
asn1_decode_auth_pack(asn1buf *buf, krb5_auth_pack *val)
{
int i;
setup();
val->clientPublicValue = NULL;
val->pkAuthenticator.paChecksum.contents = NULL;
val->supportedCMSTypes = NULL;
val->clientDHNonce.data = NULL;
val->supportedKDFs = NULL;
{ begin_structure();
get_field(val->pkAuthenticator, 0, asn1_decode_pk_authenticator);
if (tagnum == 1) {
alloc_field(val->clientPublicValue);
val->clientPublicValue->algorithm.algorithm.data = NULL;
val->clientPublicValue->algorithm.parameters.data = NULL;
val->clientPublicValue->subjectPublicKey.data = NULL;
}
/* can't call opt_field because it does decoder(&subbuf, &(val)); */
if (asn1buf_remains(&subbuf, seqindef)) {
if ((asn1class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)
&& (tagnum || taglen || asn1class != UNIVERSAL))
clean_return(ASN1_BAD_ID);
if (tagnum == 1) {
retval = asn1_decode_subject_pk_info(&subbuf,
val->clientPublicValue);
if (retval) clean_return(retval);
if (!taglen && indef) { get_eoc(); }
next_tag();
} else val->clientPublicValue = NULL;
}
/* can't call opt_field because it does decoder(&subbuf, &(val)); */
if (asn1buf_remains(&subbuf, seqindef)) {
if (tagnum == 2) {
retval = asn1_decode_sequence_of_algorithm_identifier(&subbuf, &val->supportedCMSTypes);
if (retval) clean_return(retval);
if (!taglen && indef) { get_eoc(); }
next_tag();
} else val->supportedCMSTypes = NULL;
}
opt_lenfield(val->clientDHNonce.length, val->clientDHNonce.data, 3, asn1_decode_octetstring);
opt_field(val->supportedKDFs, 4, asn1_decode_sequence_of_kdf_alg_id, NULL);
end_structure();
}
return 0;
error_out:
if (val->clientPublicValue) {
free(val->clientPublicValue->algorithm.algorithm.data);
free(val->clientPublicValue->algorithm.parameters.data);
free(val->clientPublicValue->subjectPublicKey.data);
free(val->clientPublicValue);
}
free(val->pkAuthenticator.paChecksum.contents);
if (val->supportedCMSTypes) {
for (i = 0; val->supportedCMSTypes[i]; i++)
free_algorithm_identifier(val->supportedCMSTypes[i]);
free(val->supportedCMSTypes);
}
free(val->clientDHNonce.data);
if (val->supportedKDFs) {
for (i = 0; val->supportedKDFs[i]; i++)
krb5_free_octet_data(NULL, val->supportedKDFs[i]);
free(val->supportedKDFs);
val->supportedKDFs = NULL;
}
val->clientPublicValue = NULL;
val->pkAuthenticator.paChecksum.contents = NULL;
val->supportedCMSTypes = NULL;
val->clientDHNonce.data = NULL;
return retval;
}
asn1_error_code
asn1_decode_auth_pack_draft9(asn1buf *buf, krb5_auth_pack_draft9 *val)
{
setup();
val->pkAuthenticator.kdcName = NULL;
val->clientPublicValue = NULL;
{ begin_structure();
get_field(val->pkAuthenticator, 0, asn1_decode_pk_authenticator_draft9);
if (tagnum == 1) {
alloc_field(val->clientPublicValue);
val->clientPublicValue->algorithm.algorithm.data = NULL;
val->clientPublicValue->algorithm.parameters.data = NULL;
val->clientPublicValue->subjectPublicKey.data = NULL;
/* can't call opt_field because it does decoder(&subbuf, &(val)); */
if (asn1buf_remains(&subbuf, seqindef)) {
if ((asn1class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)
&& (tagnum || taglen || asn1class != UNIVERSAL))
clean_return(ASN1_BAD_ID);
if (tagnum == 1) {
retval = asn1_decode_subject_pk_info(&subbuf,
val->clientPublicValue);
if (retval) clean_return(retval);
if (!taglen && indef) { get_eoc(); }
next_tag();
} else val->clientPublicValue = NULL;
}
}
end_structure();
}
return 0;
error_out:
free(val->pkAuthenticator.kdcName);
if (val->clientPublicValue) {
free(val->clientPublicValue->algorithm.algorithm.data);
free(val->clientPublicValue->algorithm.parameters.data);
free(val->clientPublicValue->subjectPublicKey.data);
free(val->clientPublicValue);
}
val->pkAuthenticator.kdcName = NULL;
val->clientPublicValue = NULL;
return retval;
}
#endif /* DISABLE_PKINIT */
|