2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #define MAX_TIME ((time_t)((1U << 31) - 1))
39 _kdc_fix_time(time_t **t)
45 if(**t == 0) **t = MAX_TIME; /* fix for old clients */
49 realloc_method_data(METHOD_DATA *md)
52 pa = realloc(md->val, (md->len + 1) * sizeof(*md->val));
61 set_salt_padata(METHOD_DATA *md, Salt *salt)
64 realloc_method_data(md);
65 md->val[md->len - 1].padata_type = salt->type;
66 der_copy_octet_string(&salt->salt,
67 &md->val[md->len - 1].padata_value);
72 _kdc_find_padata(const KDC_REQ *req, int *start, int type)
74 if (req->padata == NULL)
77 while((size_t)*start < req->padata->len){
79 if(req->padata->val[*start - 1].padata_type == (unsigned)type)
80 return &req->padata->val[*start - 1];
86 * This is a hack to allow predefined weak services, like afs to
87 * still use weak types
91 _kdc_is_weak_exception(krb5_principal principal, krb5_enctype etype)
93 if (principal->name.name_string.len > 0 &&
94 strcmp(principal->name.name_string.val[0], "afs") == 0 &&
95 (etype == ETYPE_DES_CBC_CRC
96 || etype == ETYPE_DES_CBC_MD4
97 || etype == ETYPE_DES_CBC_MD5))
104 * Detect if `key' is the using the the precomputed `default_salt'.
108 is_default_salt_p(const krb5_salt *default_salt, const Key *key)
110 if (key->salt == NULL)
112 if (default_salt->salttype != key->salt->type)
114 if (krb5_data_cmp(&default_salt->saltvalue, &key->salt->salt))
120 * return the first appropriate key of `princ' in `ret_key'. Look for
121 * all the etypes in (`etypes', `len'), stopping as soon as we find
122 * one, but preferring one that has default salt
126 _kdc_find_etype(krb5_context context, krb5_boolean use_strongest_session_key,
127 krb5_boolean is_preauth, hdb_entry_ex *princ,
128 krb5_enctype *etypes, unsigned len,
129 krb5_enctype *ret_enctype, Key **ret_key)
133 krb5_enctype enctype = ETYPE_NULL;
137 /* We'll want to avoid keys with v4 salted keys in the pre-auth case... */
138 ret = krb5_get_pw_salt(context, princ->entry.principal, &def_salt);
142 ret = KRB5KDC_ERR_ETYPE_NOSUPP;
144 if (use_strongest_session_key) {
145 const krb5_enctype *p;
146 krb5_enctype clientbest = ETYPE_NULL;
150 * Pick the strongest key that the KDC, target service, and
151 * client all support, using the local cryptosystem enctype
152 * list in strongest-to-weakest order to drive the search.
154 * This is not what RFC4120 says to do, but it encourages
155 * adoption of stronger enctypes. This doesn't play well with
156 * clients that have multiple Kerberos client implementations
157 * available with different supported enctype lists.
160 /* drive the search with local supported enctypes list */
161 p = krb5_kerberos_enctypes(context);
162 for (i = 0; p[i] != ETYPE_NULL && enctype == ETYPE_NULL; i++) {
163 if (krb5_enctype_valid(context, p[i]) != 0)
166 /* check that the client supports it too */
167 for (j = 0; j < len && enctype == ETYPE_NULL; j++) {
168 if (p[i] != etypes[j])
170 /* save best of union of { client, crypto system } */
171 if (clientbest == ETYPE_NULL)
173 /* check target princ support */
174 ret = hdb_enctype2key(context, &princ->entry, p[i], &key);
177 if (is_preauth && enctype == (krb5_enctype)ETYPE_DES_CBC_CRC
178 && !is_default_salt_p(&def_salt, key))
183 if (clientbest != ETYPE_NULL && enctype == ETYPE_NULL)
184 enctype = clientbest;
185 else if (enctype == ETYPE_NULL)
186 ret = KRB5KDC_ERR_ETYPE_NOSUPP;
187 if (ret == 0 && ret_enctype != NULL)
188 *ret_enctype = enctype;
189 if (ret == 0 && ret_key != NULL)
193 * Pick the first key from the client's enctype list that is
194 * supported by the cryptosystem and by the given principal.
196 * RFC4120 says we SHOULD pick the first _strong_ key from the
197 * client's list... not the first key... If the admin disallows
198 * weak enctypes in krb5.conf and selects this key selection
199 * algorithm, then we get exactly what RFC4120 says.
201 for(key = NULL, i = 0; ret != 0 && i < len; i++, key = NULL) {
203 if (krb5_enctype_valid(context, etypes[i]) != 0 &&
204 !_kdc_is_weak_exception(princ->entry.principal, etypes[i]))
207 while (hdb_next_enctype2key(context, &princ->entry, etypes[i], &key) == 0) {
208 if (key->key.keyvalue.length == 0) {
209 ret = KRB5KDC_ERR_NULL_KEY;
214 if (ret_enctype != NULL)
215 *ret_enctype = etypes[i];
217 if (is_preauth && is_default_salt_p(&def_salt, key))
224 krb5_free_salt (context, def_salt);
229 _kdc_make_anonymous_principalname (PrincipalName *pn)
231 pn->name_type = KRB5_NT_PRINCIPAL;
232 pn->name_string.len = 1;
233 pn->name_string.val = malloc(sizeof(*pn->name_string.val));
234 if (pn->name_string.val == NULL)
236 pn->name_string.val[0] = strdup("anonymous");
237 if (pn->name_string.val[0] == NULL) {
238 free(pn->name_string.val);
239 pn->name_string.val = NULL;
246 _kdc_log_timestamp(krb5_context context,
247 krb5_kdc_configuration *config,
249 KerberosTime authtime, KerberosTime *starttime,
250 KerberosTime endtime, KerberosTime *renew_till)
252 char authtime_str[100], starttime_str[100],
253 endtime_str[100], renewtime_str[100];
255 krb5_format_time(context, authtime,
256 authtime_str, sizeof(authtime_str), TRUE);
258 krb5_format_time(context, *starttime,
259 starttime_str, sizeof(starttime_str), TRUE);
261 strlcpy(starttime_str, "unset", sizeof(starttime_str));
262 krb5_format_time(context, endtime,
263 endtime_str, sizeof(endtime_str), TRUE);
265 krb5_format_time(context, *renew_till,
266 renewtime_str, sizeof(renewtime_str), TRUE);
268 strlcpy(renewtime_str, "unset", sizeof(renewtime_str));
270 kdc_log(context, config, 5,
271 "%s authtime: %s starttime: %s endtime: %s renew till: %s",
272 type, authtime_str, starttime_str, endtime_str, renewtime_str);
276 log_patypes(krb5_context context,
277 krb5_kdc_configuration *config,
280 struct rk_strpool *p = NULL;
284 for (i = 0; i < padata->len; i++) {
285 switch(padata->val[i].padata_type) {
286 case KRB5_PADATA_PK_AS_REQ:
287 p = rk_strpoolprintf(p, "PK-INIT(ietf)");
289 case KRB5_PADATA_PK_AS_REQ_WIN:
290 p = rk_strpoolprintf(p, "PK-INIT(win2k)");
292 case KRB5_PADATA_PA_PK_OCSP_RESPONSE:
293 p = rk_strpoolprintf(p, "OCSP");
295 case KRB5_PADATA_ENC_TIMESTAMP:
296 p = rk_strpoolprintf(p, "encrypted-timestamp");
299 p = rk_strpoolprintf(p, "%d", padata->val[i].padata_type);
302 if (p && i + 1 < padata->len)
303 p = rk_strpoolprintf(p, ", ");
305 kdc_log(context, config, 0, "out of memory");
310 p = rk_strpoolprintf(p, "none");
312 str = rk_strpoolcollect(p);
313 kdc_log(context, config, 0, "Client sent patypes: %s", str);
323 _kdc_encode_reply(krb5_context context,
324 krb5_kdc_configuration *config,
325 KDC_REP *rep, const EncTicketPart *et, EncKDCRepPart *ek,
327 int skvno, const EncryptionKey *skey,
328 int ckvno, const EncryptionKey *reply_key,
339 ASN1_MALLOC_ENCODE(EncTicketPart, buf, buf_size, et, &len, ret);
341 const char *msg = krb5_get_error_message(context, ret);
342 kdc_log(context, config, 0, "Failed to encode ticket: %s", msg);
343 krb5_free_error_message(context, msg);
346 if(buf_size != len) {
348 kdc_log(context, config, 0, "Internal error in ASN.1 encoder");
349 *e_text = "KDC internal error";
350 return KRB5KRB_ERR_GENERIC;
353 ret = krb5_crypto_init(context, skey, etype, &crypto);
357 msg = krb5_get_error_message(context, ret);
358 kdc_log(context, config, 0, "krb5_crypto_init failed: %s", msg);
359 krb5_free_error_message(context, msg);
363 ret = krb5_encrypt_EncryptedData(context,
369 &rep->ticket.enc_part);
371 krb5_crypto_destroy(context, crypto);
373 const char *msg = krb5_get_error_message(context, ret);
374 kdc_log(context, config, 0, "Failed to encrypt data: %s", msg);
375 krb5_free_error_message(context, msg);
379 if(rep->msg_type == krb_as_rep && !config->encode_as_rep_as_tgs_rep)
380 ASN1_MALLOC_ENCODE(EncASRepPart, buf, buf_size, ek, &len, ret);
382 ASN1_MALLOC_ENCODE(EncTGSRepPart, buf, buf_size, ek, &len, ret);
384 const char *msg = krb5_get_error_message(context, ret);
385 kdc_log(context, config, 0, "Failed to encode KDC-REP: %s", msg);
386 krb5_free_error_message(context, msg);
389 if(buf_size != len) {
391 kdc_log(context, config, 0, "Internal error in ASN.1 encoder");
392 *e_text = "KDC internal error";
393 return KRB5KRB_ERR_GENERIC;
395 ret = krb5_crypto_init(context, reply_key, 0, &crypto);
397 const char *msg = krb5_get_error_message(context, ret);
399 kdc_log(context, config, 0, "krb5_crypto_init failed: %s", msg);
400 krb5_free_error_message(context, msg);
403 if(rep->msg_type == krb_as_rep) {
404 krb5_encrypt_EncryptedData(context,
406 KRB5_KU_AS_REP_ENC_PART,
412 ASN1_MALLOC_ENCODE(AS_REP, buf, buf_size, rep, &len, ret);
414 krb5_encrypt_EncryptedData(context,
416 rk_is_subkey ? KRB5_KU_TGS_REP_ENC_PART_SUB_KEY : KRB5_KU_TGS_REP_ENC_PART_SESSION,
422 ASN1_MALLOC_ENCODE(TGS_REP, buf, buf_size, rep, &len, ret);
424 krb5_crypto_destroy(context, crypto);
426 const char *msg = krb5_get_error_message(context, ret);
427 kdc_log(context, config, 0, "Failed to encode KDC-REP: %s", msg);
428 krb5_free_error_message(context, msg);
431 if(buf_size != len) {
433 kdc_log(context, config, 0, "Internal error in ASN.1 encoder");
434 *e_text = "KDC internal error";
435 return KRB5KRB_ERR_GENERIC;
438 reply->length = buf_size;
443 * Return 1 if the client have only older enctypes, this is for
444 * determining if the server should send ETYPE_INFO2 or not.
448 older_enctype(krb5_enctype enctype)
451 case ETYPE_DES_CBC_CRC:
452 case ETYPE_DES_CBC_MD4:
453 case ETYPE_DES_CBC_MD5:
454 case ETYPE_DES3_CBC_SHA1:
455 case ETYPE_ARCFOUR_HMAC_MD5:
456 case ETYPE_ARCFOUR_HMAC_MD5_56:
458 * The following three is "old" windows enctypes and is needed for
459 * windows 2000 hosts.
461 case ETYPE_ARCFOUR_MD4:
462 case ETYPE_ARCFOUR_HMAC_OLD:
463 case ETYPE_ARCFOUR_HMAC_OLD_EXP:
474 static krb5_error_code
475 make_etype_info_entry(krb5_context context, ETYPE_INFO_ENTRY *ent, Key *key)
477 ent->etype = key->key.keytype;
480 ALLOC(ent->salttype);
482 if(key->salt->type == hdb_pw_salt)
483 *ent->salttype = 0; /* or 1? or NULL? */
484 else if(key->salt->type == hdb_afs3_salt)
487 kdc_log(context, config, 0, "unknown salt-type: %d",
489 return KRB5KRB_ERR_GENERIC;
491 /* according to `the specs', we can't send a salt if
492 we have AFS3 salted key, but that requires that you
493 *know* what cell you are using (e.g by assuming
494 that the cell is the same as the realm in lower
497 ALLOC(ent->salttype);
498 *ent->salttype = key->salt->type;
501 * We shouldn't sent salttype since it is incompatible with the
502 * specification and it breaks windows clients. The afs
503 * salting problem is solved by using KRB5-PADATA-AFS3-SALT
504 * implemented in Heimdal 0.7 and later.
506 ent->salttype = NULL;
508 krb5_copy_data(context, &key->salt->salt,
511 /* we return no salt type at all, as that should indicate
512 * the default salt type and make everybody happy. some
513 * systems (like w2k) dislike being told the salt type
516 ent->salttype = NULL;
522 static krb5_error_code
523 get_pa_etype_info(krb5_context context,
524 krb5_kdc_configuration *config,
525 METHOD_DATA *md, Key *ckey)
527 krb5_error_code ret = 0;
534 pa.val = calloc(1, sizeof(pa.val[0]));
538 ret = make_etype_info_entry(context, &pa.val[0], ckey);
540 free_ETYPE_INFO(&pa);
544 ASN1_MALLOC_ENCODE(ETYPE_INFO, buf, len, &pa, &len, ret);
545 free_ETYPE_INFO(&pa);
548 ret = realloc_method_data(md);
553 md->val[md->len - 1].padata_type = KRB5_PADATA_ETYPE_INFO;
554 md->val[md->len - 1].padata_value.length = len;
555 md->val[md->len - 1].padata_value.data = buf;
563 extern int _krb5_AES_string_to_default_iterator;
565 static krb5_error_code
566 make_etype_info2_entry(ETYPE_INFO2_ENTRY *ent, Key *key)
568 ent->etype = key->key.keytype;
571 if (ent->salt == NULL)
573 *ent->salt = malloc(key->salt->salt.length + 1);
574 if (*ent->salt == NULL) {
579 memcpy(*ent->salt, key->salt->salt.data, key->salt->salt.length);
580 (*ent->salt)[key->salt->salt.length] = '\0';
584 ent->s2kparams = NULL;
586 switch (key->key.keytype) {
587 case ETYPE_AES128_CTS_HMAC_SHA1_96:
588 case ETYPE_AES256_CTS_HMAC_SHA1_96:
589 ALLOC(ent->s2kparams);
590 if (ent->s2kparams == NULL)
592 ent->s2kparams->length = 4;
593 ent->s2kparams->data = malloc(ent->s2kparams->length);
594 if (ent->s2kparams->data == NULL) {
595 free(ent->s2kparams);
596 ent->s2kparams = NULL;
599 _krb5_put_int(ent->s2kparams->data,
600 _krb5_AES_string_to_default_iterator,
601 ent->s2kparams->length);
603 case ETYPE_DES_CBC_CRC:
604 case ETYPE_DES_CBC_MD4:
605 case ETYPE_DES_CBC_MD5:
606 /* Check if this was a AFS3 salted key */
607 if(key->salt && key->salt->type == hdb_afs3_salt){
608 ALLOC(ent->s2kparams);
609 if (ent->s2kparams == NULL)
611 ent->s2kparams->length = 1;
612 ent->s2kparams->data = malloc(ent->s2kparams->length);
613 if (ent->s2kparams->data == NULL) {
614 free(ent->s2kparams);
615 ent->s2kparams = NULL;
618 _krb5_put_int(ent->s2kparams->data,
620 ent->s2kparams->length);
630 * Return an ETYPE-INFO2. Enctypes are storted the same way as in the
631 * database (client supported enctypes first, then the unsupported
635 static krb5_error_code
636 get_pa_etype_info2(krb5_context context,
637 krb5_kdc_configuration *config,
638 METHOD_DATA *md, Key *ckey)
640 krb5_error_code ret = 0;
646 pa.val = calloc(1, sizeof(pa.val[0]));
650 ret = make_etype_info2_entry(&pa.val[0], ckey);
652 free_ETYPE_INFO2(&pa);
656 ASN1_MALLOC_ENCODE(ETYPE_INFO2, buf, len, &pa, &len, ret);
657 free_ETYPE_INFO2(&pa);
660 ret = realloc_method_data(md);
665 md->val[md->len - 1].padata_type = KRB5_PADATA_ETYPE_INFO2;
666 md->val[md->len - 1].padata_value.length = len;
667 md->val[md->len - 1].padata_value.data = buf;
676 log_as_req(krb5_context context,
677 krb5_kdc_configuration *config,
680 const KDC_REQ_BODY *b)
683 struct rk_strpool *p;
687 p = rk_strpoolprintf(NULL, "%s", "Client supported enctypes: ");
689 for (i = 0; i < b->etype.len; i++) {
690 ret = krb5_enctype_to_string(context, b->etype.val[i], &str);
692 p = rk_strpoolprintf(p, "%s", str);
695 p = rk_strpoolprintf(p, "%d", b->etype.val[i]);
696 if (p && i + 1 < b->etype.len)
697 p = rk_strpoolprintf(p, ", ");
699 kdc_log(context, config, 0, "out of memory");
704 p = rk_strpoolprintf(p, "no encryption types");
710 ret = krb5_enctype_to_string(context, cetype, &cet);
712 ret = krb5_enctype_to_string(context, setype, &set);
714 p = rk_strpoolprintf(p, ", using %s/%s", cet, set);
720 p = rk_strpoolprintf(p, ", using enctypes %d/%d",
724 str = rk_strpoolcollect(p);
725 kdc_log(context, config, 0, "%s", str);
730 unparse_flags(KDCOptions2int(b->kdc_options), asn1_KDCOptions_units(),
731 fixedstr, sizeof(fixedstr));
733 kdc_log(context, config, 0, "Requested flags: %s", fixedstr);
738 * verify the flags on `client' and `server', returning 0
739 * if they are OK and generating an error messages and returning
740 * and error code otherwise.
744 kdc_check_flags(krb5_context context,
745 krb5_kdc_configuration *config,
746 hdb_entry_ex *client_ex, const char *client_name,
747 hdb_entry_ex *server_ex, const char *server_name,
748 krb5_boolean is_as_req)
750 if(client_ex != NULL) {
751 hdb_entry *client = &client_ex->entry;
754 if (client->flags.locked_out) {
755 kdc_log(context, config, 0,
756 "Client (%s) is locked out", client_name);
757 return KRB5KDC_ERR_CLIENT_REVOKED;
760 if (client->flags.invalid) {
761 kdc_log(context, config, 0,
762 "Client (%s) has invalid bit set", client_name);
763 return KRB5KDC_ERR_POLICY;
766 if(!client->flags.client){
767 kdc_log(context, config, 0,
768 "Principal may not act as client -- %s", client_name);
769 return KRB5KDC_ERR_POLICY;
772 if (client->valid_start && *client->valid_start > kdc_time) {
773 char starttime_str[100];
774 krb5_format_time(context, *client->valid_start,
775 starttime_str, sizeof(starttime_str), TRUE);
776 kdc_log(context, config, 0,
777 "Client not yet valid until %s -- %s",
778 starttime_str, client_name);
779 return KRB5KDC_ERR_CLIENT_NOTYET;
782 if (client->valid_end && *client->valid_end < kdc_time) {
783 char endtime_str[100];
784 krb5_format_time(context, *client->valid_end,
785 endtime_str, sizeof(endtime_str), TRUE);
786 kdc_log(context, config, 0,
787 "Client expired at %s -- %s",
788 endtime_str, client_name);
789 return KRB5KDC_ERR_NAME_EXP;
792 if (client->pw_end && *client->pw_end < kdc_time
793 && (server_ex == NULL || !server_ex->entry.flags.change_pw)) {
795 krb5_format_time(context, *client->pw_end,
796 pwend_str, sizeof(pwend_str), TRUE);
797 kdc_log(context, config, 0,
798 "Client's key has expired at %s -- %s",
799 pwend_str, client_name);
800 return KRB5KDC_ERR_KEY_EXPIRED;
806 if (server_ex != NULL) {
807 hdb_entry *server = &server_ex->entry;
809 if (server->flags.locked_out) {
810 kdc_log(context, config, 0,
811 "Client server locked out -- %s", server_name);
812 return KRB5KDC_ERR_POLICY;
814 if (server->flags.invalid) {
815 kdc_log(context, config, 0,
816 "Server has invalid flag set -- %s", server_name);
817 return KRB5KDC_ERR_POLICY;
820 if(!server->flags.server){
821 kdc_log(context, config, 0,
822 "Principal may not act as server -- %s", server_name);
823 return KRB5KDC_ERR_POLICY;
826 if(!is_as_req && server->flags.initial) {
827 kdc_log(context, config, 0,
828 "AS-REQ is required for server -- %s", server_name);
829 return KRB5KDC_ERR_POLICY;
832 if (server->valid_start && *server->valid_start > kdc_time) {
833 char starttime_str[100];
834 krb5_format_time(context, *server->valid_start,
835 starttime_str, sizeof(starttime_str), TRUE);
836 kdc_log(context, config, 0,
837 "Server not yet valid until %s -- %s",
838 starttime_str, server_name);
839 return KRB5KDC_ERR_SERVICE_NOTYET;
842 if (server->valid_end && *server->valid_end < kdc_time) {
843 char endtime_str[100];
844 krb5_format_time(context, *server->valid_end,
845 endtime_str, sizeof(endtime_str), TRUE);
846 kdc_log(context, config, 0,
847 "Server expired at %s -- %s",
848 endtime_str, server_name);
849 return KRB5KDC_ERR_SERVICE_EXP;
852 if (server->pw_end && *server->pw_end < kdc_time) {
854 krb5_format_time(context, *server->pw_end,
855 pwend_str, sizeof(pwend_str), TRUE);
856 kdc_log(context, config, 0,
857 "Server's key has expired at -- %s",
858 pwend_str, server_name);
859 return KRB5KDC_ERR_KEY_EXPIRED;
866 * Return TRUE if `from' is part of `addresses' taking into consideration
867 * the configuration variables that tells us how strict we should be about
872 _kdc_check_addresses(krb5_context context,
873 krb5_kdc_configuration *config,
874 HostAddresses *addresses, const struct sockaddr *from)
879 krb5_boolean only_netbios = TRUE;
882 if(config->check_ticket_addresses == 0)
885 if(addresses == NULL)
886 return config->allow_null_ticket_addresses;
888 for (i = 0; i < addresses->len; ++i) {
889 if (addresses->val[i].addr_type != KRB5_ADDRESS_NETBIOS) {
890 only_netbios = FALSE;
894 /* Windows sends it's netbios name, which I can only assume is
895 * used for the 'allowed workstations' check. This is painful,
896 * but we still want to check IP addresses if they happen to be
901 return config->allow_null_ticket_addresses;
903 ret = krb5_sockaddr2address (context, from, &addr);
907 result = krb5_address_search(context, &addr, addresses);
908 krb5_free_address (context, &addr);
917 send_pac_p(krb5_context context, KDC_REQ *req, krb5_boolean *pac_request)
920 PA_PAC_REQUEST pacreq;
926 pa = _kdc_find_padata(req, &i, KRB5_PADATA_PA_PAC_REQUEST);
930 ret = decode_PA_PAC_REQUEST(pa->padata_value.data,
931 pa->padata_value.length,
936 i = pacreq.include_pac;
937 free_PA_PAC_REQUEST(&pacreq);
939 *pac_request = FALSE;
945 _kdc_is_anonymous(krb5_context context, krb5_principal principal)
947 if (principal->name.name_type != KRB5_NT_WELLKNOWN ||
948 principal->name.name_string.len != 2 ||
949 strcmp(principal->name.name_string.val[0], KRB5_WELLKNOWN_NAME) != 0 ||
950 strcmp(principal->name.name_string.val[1], KRB5_ANON_NAME) != 0)
955 static krb5_error_code
956 get_local_tgs(krb5_context context,
957 krb5_kdc_configuration *config,
958 krb5_const_realm realm,
959 hdb_entry_ex **krbtgt)
962 krb5_principal tgs_name;
966 ret = krb5_make_principal(context,
975 ret = _kdc_db_fetch(context, config, tgs_name,
976 HDB_F_GET_KRBTGT, NULL, NULL, krbtgt);
977 krb5_free_principal(context, tgs_name);
987 _kdc_as_rep(krb5_context context,
988 krb5_kdc_configuration *config,
990 const krb5_data *req_buffer,
993 struct sockaddr *from_addr,
996 KDC_REQ_BODY *b = &req->req_body;
998 KDCOptions f = b->kdc_options;
999 hdb_entry_ex *client = NULL, *server = NULL;
1000 HDB *clientdb = NULL;
1001 krb5_enctype setype, sessionetype;
1005 krb5_principal client_princ = NULL, server_princ = NULL;
1006 char *client_name = NULL, *server_name = NULL;
1007 krb5_error_code ret = 0;
1008 const char *e_text = NULL;
1011 EncryptionKey *reply_key = NULL, session_key;
1012 int flags = HDB_F_FOR_AS_REQ;
1014 pk_client_params *pkp = NULL;
1016 const EncryptionKey *pk_reply_key = NULL;
1017 krb5_boolean is_tgs;
1018 hdb_entry_ex *krbtgt = NULL;
1019 Key *krbtgt_key = NULL;
1021 memset(&rep, 0, sizeof(rep));
1022 memset(&session_key, 0, sizeof(session_key));
1023 krb5_data_zero(&e_data);
1026 rep.padata->len = 0;
1027 rep.padata->val = NULL;
1030 flags |= HDB_F_CANON;
1032 if(b->sname == NULL){
1033 ret = KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN;
1034 e_text = "No server in request";
1036 ret = _krb5_principalname2krb5_principal (context,
1041 ret = krb5_unparse_name(context, server_princ, &server_name);
1044 kdc_log(context, config, 0,
1045 "AS-REQ malformed server name from %s", from);
1048 if(b->cname == NULL){
1049 ret = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN;
1050 e_text = "No client in request";
1052 ret = _krb5_principalname2krb5_principal (context,
1059 ret = krb5_unparse_name(context, client_princ, &client_name);
1062 kdc_log(context, config, 0,
1063 "AS-REQ malformed client name from %s", from);
1067 kdc_log(context, config, 0, "AS-REQ %s from %s for %s",
1068 client_name, from, server_name);
1070 is_tgs = krb5_principal_is_krbtgt(context, server_princ);
1076 if (_kdc_is_anonymous(context, client_princ)) {
1077 if (!b->kdc_options.request_anonymous) {
1078 kdc_log(context, config, 0, "Anonymous ticket w/o anonymous flag");
1079 ret = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN;
1082 } else if (b->kdc_options.request_anonymous) {
1083 kdc_log(context, config, 0,
1084 "Request for a anonymous ticket with non "
1085 "anonymous client name: %s", client_name);
1086 ret = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN;
1094 ret = _kdc_db_fetch(context, config, client_princ,
1095 HDB_F_GET_CLIENT | flags, NULL,
1096 &clientdb, &client);
1097 if(ret == HDB_ERR_NOT_FOUND_HERE) {
1098 kdc_log(context, config, 5, "client %s does not have secrets at this KDC, need to proxy", client_name);
1100 } else if (ret == HDB_ERR_WRONG_REALM) {
1101 char *fixed_client_name = NULL;
1103 ret = krb5_unparse_name(context, client->entry.principal,
1104 &fixed_client_name);
1109 kdc_log(context, config, 0, "WRONG_REALM - %s -> %s",
1110 client_name, fixed_client_name);
1111 free(fixed_client_name);
1113 ret = krb5_mk_error_ext(context,
1114 KRB5_KDC_ERR_WRONG_REALM,
1118 NULL, /* client_name */
1119 &client->entry.principal->realm,
1120 NULL, /* client_time */
1121 NULL, /* client_usec */
1125 const char *msg = krb5_get_error_message(context, ret);
1126 kdc_log(context, config, 0, "UNKNOWN -- %s: %s", client_name, msg);
1127 krb5_free_error_message(context, msg);
1128 ret = KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN;
1130 if (config->db[0] && config->db[0]->hdb_auth_status)
1131 (config->db[0]->hdb_auth_status)(context, config->db[0], NULL,
1136 HDB_AUTH_CLIENT_UNKNOWN);
1139 ret = _kdc_db_fetch(context, config, server_princ,
1140 HDB_F_GET_SERVER | flags | (is_tgs ? HDB_F_GET_KRBTGT : 0),
1141 NULL, NULL, &server);
1142 if(ret == HDB_ERR_NOT_FOUND_HERE) {
1143 kdc_log(context, config, 5, "target %s does not have secrets at this KDC, need to proxy", server_name);
1146 const char *msg = krb5_get_error_message(context, ret);
1147 kdc_log(context, config, 0, "UNKNOWN -- %s: %s", server_name, msg);
1148 krb5_free_error_message(context, msg);
1149 ret = KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN;
1153 memset(&et, 0, sizeof(et));
1154 memset(&ek, 0, sizeof(ek));
1157 * Select a session enctype from the list of the crypto system
1158 * supported enctypes that is supported by the client and is one of
1159 * the enctype of the enctype of the service (likely krbtgt).
1161 * The latter is used as a hint of what enctypes all KDC support,
1162 * to make sure a newer version of KDC won't generate a session
1163 * enctype that an older version of a KDC in the same realm can't
1166 ret = _kdc_find_etype(context, config->as_use_strongest_session_key, FALSE,
1167 client, b->etype.val, b->etype.len, &sessionetype,
1170 kdc_log(context, config, 0,
1171 "Client (%s) from %s has no common enctypes with KDC "
1172 "to use for the session key",
1177 * But if the KDC admin is paranoid and doesn't want to have "not
1178 * the best" enctypes on the krbtgt, lets save the best pick from
1179 * the client list and hope that that will work for any other
1184 * Pre-auth processing
1192 log_patypes(context, config, req->padata);
1195 kdc_log(context, config, 5,
1196 "Looking for PKINIT pa-data -- %s", client_name);
1198 e_text = "No PKINIT PA found";
1201 pa = _kdc_find_padata(req, &i, KRB5_PADATA_PK_AS_REQ);
1204 pa = _kdc_find_padata(req, &i, KRB5_PADATA_PK_AS_REQ_WIN);
1207 char *client_cert = NULL;
1209 ret = _kdc_pk_rd_padata(context, config, req, pa, client, &pkp);
1211 ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1212 kdc_log(context, config, 5,
1213 "Failed to decode PKINIT PA-DATA -- %s",
1217 if (ret == 0 && pkp == NULL)
1220 ret = _kdc_pk_check_client(context,
1227 e_text = "PKINIT certificate not allowed to "
1228 "impersonate principal";
1229 _kdc_pk_free_client_param(context, pkp);
1231 kdc_log(context, config, 0, "%s", e_text);
1237 et.flags.pre_authent = 1;
1238 kdc_log(context, config, 0,
1239 "PKINIT pre-authentication succeeded -- %s using %s",
1240 client_name, client_cert);
1241 if (clientdb->hdb_auth_status)
1242 (clientdb->hdb_auth_status)(context, clientdb, client,
1247 HDB_AUTH_PKINIT_SUCCESS);
1255 if (client->entry.flags.locked_out) {
1256 ret = KRB5KDC_ERR_CLIENT_REVOKED;
1257 kdc_log(context, config, 0,
1258 "Client (%s) is locked out", client_name);
1262 kdc_log(context, config, 5, "Looking for ENC-TS pa-data -- %s",
1266 e_text = "No ENC-TS found";
1267 while((pa = _kdc_find_padata(req, &i, KRB5_PADATA_ENC_TIMESTAMP))){
1271 EncryptedData enc_data;
1277 if (b->kdc_options.request_anonymous) {
1278 ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1279 kdc_log(context, config, 0, "ENC-TS doesn't support anon");
1283 ret = decode_EncryptedData(pa->padata_value.data,
1284 pa->padata_value.length,
1288 ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
1289 kdc_log(context, config, 5, "Failed to decode PA-DATA -- %s",
1294 ret = hdb_enctype2key(context, &client->entry,
1295 enc_data.etype, &pa_key);
1298 e_text = "No key matches pa-data";
1299 ret = KRB5KDC_ERR_ETYPE_NOSUPP;
1300 if(krb5_enctype_to_string(context, enc_data.etype, &estr))
1303 kdc_log(context, config, 5,
1304 "No client key matching pa-data (%d) -- %s",
1305 enc_data.etype, client_name);
1307 kdc_log(context, config, 5,
1308 "No client key matching pa-data (%s) -- %s",
1311 free_EncryptedData(&enc_data);
1317 ret = krb5_crypto_init(context, &pa_key->key, 0, &crypto);
1319 const char *msg = krb5_get_error_message(context, ret);
1320 kdc_log(context, config, 0, "krb5_crypto_init failed: %s", msg);
1321 krb5_free_error_message(context, msg);
1322 free_EncryptedData(&enc_data);
1326 ret = krb5_decrypt_EncryptedData (context,
1328 KRB5_KU_PA_ENC_TIMESTAMP,
1331 krb5_crypto_destroy(context, crypto);
1333 * Since the user might have several keys with the same
1334 * enctype but with diffrent salting, we need to try all
1335 * the keys with the same enctype.
1338 krb5_error_code ret2;
1339 const char *msg = krb5_get_error_message(context, ret);
1341 ret2 = krb5_enctype_to_string(context,
1342 pa_key->key.keytype, &str);
1346 kdc_log(context, config, 5,
1347 "Failed to decrypt PA-DATA -- %s "
1348 "(enctype %s) error %s",
1349 client_name, str ? str : "unknown enctype", msg);
1350 krb5_free_error_message(context, msg);
1352 if(hdb_next_enctype2key(context, &client->entry,
1353 enc_data.etype, &pa_key) == 0) {
1357 e_text = "Failed to decrypt PA-DATA";
1359 free_EncryptedData(&enc_data);
1361 if (clientdb->hdb_auth_status) {
1362 ret = (clientdb->hdb_auth_status)(context, clientdb, client,
1366 str ? str : "unknown enctype",
1367 HDB_AUTH_WRONG_PASSWORD);
1368 if (ret == HDB_ERR_NOT_FOUND_HERE) {
1369 kdc_log(context, config, 5, "client %s HDB_AUTH_WRONG_PASSWORD at this KDC, forward to proxy", client_name);
1377 ret = KRB5KDC_ERR_PREAUTH_FAILED;
1380 free_EncryptedData(&enc_data);
1381 ret = decode_PA_ENC_TS_ENC(ts_data.data,
1385 krb5_data_free(&ts_data);
1387 e_text = "Failed to decode PA-ENC-TS-ENC";
1388 ret = KRB5KDC_ERR_PREAUTH_FAILED;
1389 kdc_log(context, config,
1390 5, "Failed to decode PA-ENC-TS_ENC -- %s",
1394 if (abs(kdc_time - p.patimestamp) > context->max_skew) {
1395 char client_time[100];
1397 krb5_format_time(context, p.patimestamp,
1398 client_time, sizeof(client_time), TRUE);
1400 ret = KRB5KRB_AP_ERR_SKEW;
1401 kdc_log(context, config, 0,
1402 "Too large time skew, "
1403 "client time %s is out by %u > %u seconds -- %s",
1405 (unsigned)abs(kdc_time - p.patimestamp),
1410 * The following is needed to make windows clients to
1411 * retry using the timestamp in the error message, if
1412 * there is a e_text, they become unhappy.
1415 free_PA_ENC_TS_ENC(&p);
1418 free_PA_ENC_TS_ENC(&p);
1419 et.flags.pre_authent = 1;
1421 set_salt_padata(rep.padata, pa_key->salt);
1423 reply_key = &pa_key->key;
1425 ret = krb5_enctype_to_string(context, pa_key->key.keytype, &str);
1429 kdc_log(context, config, 2,
1430 "ENC-TS Pre-authentication succeeded -- %s using %s",
1431 client_name, str ? str : "unknown enctype");
1432 if (clientdb->hdb_auth_status)
1433 (clientdb->hdb_auth_status)(context, clientdb, client,
1437 str ? str : "unknown enctype",
1438 HDB_AUTH_CORRECT_PASSWORD);
1446 if(found_pa == 0 && config->require_preauth)
1448 /* We come here if we found a pa-enc-timestamp, but if there
1449 was some problem with it, other than too large skew */
1450 if(found_pa && et.flags.pre_authent == 0){
1451 kdc_log(context, config, 0, "%s -- %s", e_text, client_name);
1452 if (!prepare_enc_data(context, config, &e_data, b, client)) {
1458 }else if (config->require_preauth
1459 || b->kdc_options.request_anonymous /* hack to force anon */
1460 || client->entry.flags.require_preauth
1461 || server->entry.flags.require_preauth) {
1463 if (!prepare_enc_data(context, config, &e_data, b, client)) {
1467 e_text ="Need to use PA-ENC-TIMESTAMP/PA-PK-AS-REQ",
1469 ret = KRB5KDC_ERR_PREAUTH_REQUIRED;
1471 kdc_log(context, config, 0,
1472 "No preauth found, returning PREAUTH-REQUIRED -- %s",
1480 * Verify flags after the user been required to prove its identity
1481 * with in a preauth mech.
1484 ret = _kdc_check_access(context, config, client, client_name,
1485 server, server_name,
1490 if (clientdb->hdb_auth_status)
1491 (clientdb->hdb_auth_status)(context, clientdb, client,
1499 * Selelct the best encryption type for the KDC with out regard to
1500 * the client since the client never needs to read that data.
1503 ret = _kdc_get_preferred_key(context, config,
1504 server, server_name,
1509 /* If server is not krbtgt, fetch local krbtgt key for signing authdata */
1513 ret = get_local_tgs(context, config, server_princ->realm,
1518 ret = _kdc_get_preferred_key(context, config, krbtgt,
1519 server_princ->realm,
1525 if(f.renew || f.validate || f.proxy || f.forwarded || f.enc_tkt_in_skey
1526 || (f.request_anonymous && !config->allow_anonymous)) {
1527 ret = KRB5KDC_ERR_BADOPTION;
1528 e_text = "Bad KDC options";
1529 kdc_log(context, config, 0, "Bad KDC options -- %s", client_name);
1534 rep.msg_type = krb_as_rep;
1536 ret = copy_Realm(&client->entry.principal->realm, &rep.crealm);
1539 ret = _krb5_principal2principalname(&rep.cname, client->entry.principal);
1543 rep.ticket.tkt_vno = 5;
1544 copy_Realm(&server->entry.principal->realm, &rep.ticket.realm);
1545 _krb5_principal2principalname(&rep.ticket.sname,
1546 server->entry.principal);
1547 /* java 1.6 expects the name to be the same type, lets allow that
1548 * uncomplicated name-types, when f.canonicalize is not set (to
1549 * match Windows Server 1709). */
1550 #define CNT(sp,t) (((sp)->sname->name_type) == KRB5_NT_##t)
1552 && (CNT(b, UNKNOWN) || CNT(b, PRINCIPAL) || CNT(b, SRV_INST) || CNT(b, SRV_HST) || CNT(b, SRV_XHST))) {
1553 rep.ticket.sname.name_type = b->sname->name_type;
1557 et.flags.initial = 1;
1558 if(client->entry.flags.forwardable && server->entry.flags.forwardable)
1559 et.flags.forwardable = f.forwardable;
1560 else if (f.forwardable) {
1561 e_text = "Ticket may not be forwardable";
1562 ret = KRB5KDC_ERR_POLICY;
1563 kdc_log(context, config, 0,
1564 "Ticket may not be forwardable -- %s", client_name);
1567 if(client->entry.flags.proxiable && server->entry.flags.proxiable)
1568 et.flags.proxiable = f.proxiable;
1569 else if (f.proxiable) {
1570 e_text = "Ticket may not be proxiable";
1571 ret = KRB5KDC_ERR_POLICY;
1572 kdc_log(context, config, 0,
1573 "Ticket may not be proxiable -- %s", client_name);
1576 if(client->entry.flags.postdate && server->entry.flags.postdate)
1577 et.flags.may_postdate = f.allow_postdate;
1578 else if (f.allow_postdate){
1579 e_text = "Ticket may not be postdate";
1580 ret = KRB5KDC_ERR_POLICY;
1581 kdc_log(context, config, 0,
1582 "Ticket may not be postdatable -- %s", client_name);
1586 /* check for valid set of addresses */
1587 if(!_kdc_check_addresses(context, config, b->addresses, from_addr)) {
1588 e_text = "Bad address list in requested";
1589 ret = KRB5KRB_AP_ERR_BADADDR;
1590 kdc_log(context, config, 0,
1591 "Bad address list requested -- %s", client_name);
1595 ret = copy_PrincipalName(&rep.cname, &et.cname);
1598 ret = copy_Realm(&rep.crealm, &et.crealm);
1606 start = et.authtime = kdc_time;
1608 if(f.postdated && req->req_body.from){
1609 ALLOC(et.starttime);
1610 start = *et.starttime = *req->req_body.from;
1611 et.flags.invalid = 1;
1612 et.flags.postdated = 1; /* XXX ??? */
1614 _kdc_fix_time(&b->till);
1617 /* be careful not overflowing */
1619 if(client->entry.max_life)
1620 t = start + min(t - start, *client->entry.max_life);
1621 if(server->entry.max_life)
1622 t = start + min(t - start, *server->entry.max_life);
1624 t = min(t, start + realm->max_life);
1627 if(f.renewable_ok && et.endtime < *b->till){
1629 if(b->rtime == NULL){
1633 if(*b->rtime < *b->till)
1634 *b->rtime = *b->till;
1636 if(f.renewable && b->rtime){
1640 if(client->entry.max_renew)
1641 t = start + min(t - start, *client->entry.max_renew);
1642 if(server->entry.max_renew)
1643 t = start + min(t - start, *server->entry.max_renew);
1645 t = min(t, start + realm->max_renew);
1647 ALLOC(et.renew_till);
1649 et.flags.renewable = 1;
1653 if (f.request_anonymous)
1654 et.flags.anonymous = 1;
1658 copy_HostAddresses(b->addresses, et.caddr);
1661 et.transited.tr_type = DOMAIN_X500_COMPRESS;
1662 krb5_data_zero(&et.transited.contents);
1664 /* The MIT ASN.1 library (obviously) doesn't tell lengths encoded
1665 * as 0 and as 0x80 (meaning indefinite length) apart, and is thus
1666 * incapable of correctly decoding SEQUENCE OF's of zero length.
1668 * To fix this, always send at least one no-op last_req
1670 * If there's a pw_end or valid_end we will use that,
1671 * otherwise just a dummy lr.
1673 ek.last_req.val = malloc(2 * sizeof(*ek.last_req.val));
1674 if (ek.last_req.val == NULL) {
1678 ek.last_req.len = 0;
1679 if (client->entry.pw_end
1680 && (config->kdc_warn_pwexpire == 0
1681 || kdc_time + config->kdc_warn_pwexpire >= *client->entry.pw_end)) {
1682 ek.last_req.val[ek.last_req.len].lr_type = LR_PW_EXPTIME;
1683 ek.last_req.val[ek.last_req.len].lr_value = *client->entry.pw_end;
1686 if (client->entry.valid_end) {
1687 ek.last_req.val[ek.last_req.len].lr_type = LR_ACCT_EXPTIME;
1688 ek.last_req.val[ek.last_req.len].lr_value = *client->entry.valid_end;
1691 if (ek.last_req.len == 0) {
1692 ek.last_req.val[ek.last_req.len].lr_type = LR_NONE;
1693 ek.last_req.val[ek.last_req.len].lr_value = 0;
1696 ek.nonce = b->nonce;
1697 if (client->entry.valid_end || client->entry.pw_end) {
1698 ALLOC(ek.key_expiration);
1699 if (client->entry.valid_end) {
1700 if (client->entry.pw_end)
1701 *ek.key_expiration = min(*client->entry.valid_end,
1702 *client->entry.pw_end);
1704 *ek.key_expiration = *client->entry.valid_end;
1706 *ek.key_expiration = *client->entry.pw_end;
1708 ek.key_expiration = NULL;
1709 ek.flags = et.flags;
1710 ek.authtime = et.authtime;
1712 ALLOC(ek.starttime);
1713 *ek.starttime = *et.starttime;
1715 ek.endtime = et.endtime;
1716 if (et.renew_till) {
1717 ALLOC(ek.renew_till);
1718 *ek.renew_till = *et.renew_till;
1720 copy_Realm(&rep.ticket.realm, &ek.srealm);
1721 copy_PrincipalName(&rep.ticket.sname, &ek.sname);
1724 copy_HostAddresses(et.caddr, ek.caddr);
1729 e_text = "Failed to build PK-INIT reply";
1730 ret = _kdc_pk_mk_pa_reply(context, config, pkp, client,
1731 sessionetype, req, req_buffer,
1732 &reply_key, &et.key, rep.padata);
1735 ret = _kdc_add_inital_verified_cas(context,
1743 * Send reply key as constant value to pac generate which allows
1744 * parts of the buffer to be encrypted (i.e., PAC_CREDENTIAL_DATA).
1746 pk_reply_key = reply_key;
1750 ret = krb5_generate_random_keyblock(context, sessionetype, &et.key);
1755 if (reply_key == NULL) {
1756 e_text = "Client have no reply key";
1757 ret = KRB5KDC_ERR_CLIENT_NOTYET;
1761 ret = copy_EncryptionKey(&et.key, &ek.key);
1765 if (rep.padata->len == 0) {
1775 krb5_principal client_pac;
1776 krb5_boolean sent_pac_request;
1777 krb5_boolean pac_request;
1779 sent_pac_request = send_pac_p(context, req, &pac_request);
1781 ret = _kdc_pac_generate(context, client, server, pk_reply_key,
1782 sent_pac_request ? &pac_request : NULL,
1785 kdc_log(context, config, 0, "PAC generation failed for -- %s",
1790 rodc_id = server->entry.kvno >> 16;
1792 /* libkrb5 expects ticket and PAC client names to match */
1793 ret = _krb5_principalname2krb5_principal(context, &client_pac,
1794 et.cname, et.crealm);
1796 krb5_pac_free(context, p);
1800 ret = _krb5_pac_sign(context, p, et.authtime,
1802 &skey->key, /* Server key */
1803 &krbtgt_key->key, /* TGS key */
1806 krb5_free_principal(context, client_pac);
1807 krb5_pac_free(context, p);
1809 kdc_log(context, config, 0, "PAC signing failed for -- %s",
1814 ret = _kdc_tkt_insert_pac(context, &et, &data);
1815 krb5_data_free(&data);
1821 _kdc_log_timestamp(context, config, "AS-REQ", et.authtime, et.starttime,
1822 et.endtime, et.renew_till);
1824 log_as_req(context, config, reply_key->keytype, setype, b);
1826 ret = _kdc_encode_reply(context, config,
1827 &rep, &et, &ek, setype, server->entry.kvno,
1828 &skey->key, client->entry.kvno,
1829 reply_key, 0, &e_text, reply);
1830 free_EncTicketPart(&et);
1831 free_EncKDCRepPart(&ek);
1836 if (datagram_reply && reply->length > config->max_datagram_reply_length) {
1837 krb5_data_free(reply);
1838 ret = KRB5KRB_ERR_RESPONSE_TOO_BIG;
1839 e_text = "Reply packet too large";
1844 if(ret != 0 && ret != HDB_ERR_NOT_FOUND_HERE && reply->length == 0) {
1845 krb5_mk_error(context,
1848 (e_data.data ? &e_data : NULL),
1858 _kdc_pk_free_client_param(context, pkp);
1863 krb5_free_principal(context, client_princ);
1866 krb5_free_principal(context, server_princ);
1869 _kdc_free_ent(context, client);
1871 _kdc_free_ent(context, server);
1873 _kdc_free_ent(context, krbtgt);
1878 prepare_enc_data(krb5_context context,
1879 krb5_kdc_configuration *config,
1882 hdb_entry_ex *client)
1884 METHOD_DATA method_data;
1889 krb5_error_code ret;
1891 method_data.len = 0;
1892 method_data.val = NULL;
1894 ret = realloc_method_data(&method_data);
1896 free_METHOD_DATA(&method_data);
1899 pa = &method_data.val[method_data.len-1];
1900 pa->padata_type = KRB5_PADATA_ENC_TIMESTAMP;
1901 pa->padata_value.length = 0;
1902 pa->padata_value.data = NULL;
1905 ret = realloc_method_data(&method_data);
1907 free_METHOD_DATA(&method_data);
1910 pa = &method_data.val[method_data.len-1];
1911 pa->padata_type = KRB5_PADATA_PK_AS_REQ;
1912 pa->padata_value.length = 0;
1913 pa->padata_value.data = NULL;
1915 ret = realloc_method_data(&method_data);
1917 free_METHOD_DATA(&method_data);
1920 pa = &method_data.val[method_data.len-1];
1921 pa->padata_type = KRB5_PADATA_PK_AS_REQ_WIN;
1922 pa->padata_value.length = 0;
1923 pa->padata_value.data = NULL;
1927 * If there is a client key, send ETYPE_INFO{,2}
1929 ret = _kdc_find_etype(context,
1930 config->preauth_use_strongest_session_key, TRUE,
1931 client, b->etype.val, b->etype.len, NULL, &ckey);
1936 * - If the client only knows about old enctypes, then send
1937 * both info replies (we send 'info' first in the list).
1938 * - If the client is 'modern', because it knows about 'new'
1939 * enctype types, then only send the 'info2' reply.
1941 * Before we send the full list of etype-info data, we pick
1942 * the client key we would have used anyway below, just pick
1946 if (older_enctype(ckey->key.keytype)) {
1947 ret = get_pa_etype_info(context, config,
1948 &method_data, ckey);
1950 free_METHOD_DATA(&method_data);
1954 ret = get_pa_etype_info2(context, config,
1955 &method_data, ckey);
1957 free_METHOD_DATA(&method_data);
1962 ASN1_MALLOC_ENCODE(METHOD_DATA, buf, len, &method_data, &len, ret);
1963 free_METHOD_DATA(&method_data);
1966 e_data->length = len;