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(*start
< req
->padata
->len
){
79 if(req
->padata
->val
[*start
- 1].padata_type
== 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
, const hdb_entry_ex
*princ
,
127 krb5_enctype
*etypes
, unsigned len
,
131 krb5_error_code ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
134 krb5_get_pw_salt (context
, princ
->entry
.principal
, &def_salt
);
136 for(i
= 0; ret
!= 0 && i
< len
; i
++) {
139 if (krb5_enctype_valid(context
, etypes
[i
]) != 0 &&
140 !_kdc_is_weak_exception(princ
->entry
.principal
, etypes
[i
]))
143 while (hdb_next_enctype2key(context
, &princ
->entry
, etypes
[i
], &key
) == 0) {
144 if (key
->key
.keyvalue
.length
== 0) {
145 ret
= KRB5KDC_ERR_NULL_KEY
;
150 if (is_default_salt_p(&def_salt
, key
)) {
151 krb5_free_salt (context
, def_salt
);
156 krb5_free_salt (context
, def_salt
);
161 _kdc_make_anonymous_principalname (PrincipalName
*pn
)
163 pn
->name_type
= KRB5_NT_PRINCIPAL
;
164 pn
->name_string
.len
= 1;
165 pn
->name_string
.val
= malloc(sizeof(*pn
->name_string
.val
));
166 if (pn
->name_string
.val
== NULL
)
168 pn
->name_string
.val
[0] = strdup("anonymous");
169 if (pn
->name_string
.val
[0] == NULL
) {
170 free(pn
->name_string
.val
);
171 pn
->name_string
.val
= NULL
;
178 _kdc_log_timestamp(krb5_context context
,
179 krb5_kdc_configuration
*config
,
181 KerberosTime authtime
, KerberosTime
*starttime
,
182 KerberosTime endtime
, KerberosTime
*renew_till
)
184 char authtime_str
[100], starttime_str
[100],
185 endtime_str
[100], renewtime_str
[100];
187 krb5_format_time(context
, authtime
,
188 authtime_str
, sizeof(authtime_str
), TRUE
);
190 krb5_format_time(context
, *starttime
,
191 starttime_str
, sizeof(starttime_str
), TRUE
);
193 strlcpy(starttime_str
, "unset", sizeof(starttime_str
));
194 krb5_format_time(context
, endtime
,
195 endtime_str
, sizeof(endtime_str
), TRUE
);
197 krb5_format_time(context
, *renew_till
,
198 renewtime_str
, sizeof(renewtime_str
), TRUE
);
200 strlcpy(renewtime_str
, "unset", sizeof(renewtime_str
));
202 kdc_log(context
, config
, 5,
203 "%s authtime: %s starttime: %s endtime: %s renew till: %s",
204 type
, authtime_str
, starttime_str
, endtime_str
, renewtime_str
);
208 log_patypes(krb5_context context
,
209 krb5_kdc_configuration
*config
,
212 struct rk_strpool
*p
= NULL
;
216 for (i
= 0; i
< padata
->len
; i
++) {
217 switch(padata
->val
[i
].padata_type
) {
218 case KRB5_PADATA_PK_AS_REQ
:
219 p
= rk_strpoolprintf(p
, "PK-INIT(ietf)");
221 case KRB5_PADATA_PK_AS_REQ_WIN
:
222 p
= rk_strpoolprintf(p
, "PK-INIT(win2k)");
224 case KRB5_PADATA_PA_PK_OCSP_RESPONSE
:
225 p
= rk_strpoolprintf(p
, "OCSP");
227 case KRB5_PADATA_ENC_TIMESTAMP
:
228 p
= rk_strpoolprintf(p
, "encrypted-timestamp");
231 p
= rk_strpoolprintf(p
, "%d", padata
->val
[i
].padata_type
);
234 if (p
&& i
+ 1 < padata
->len
)
235 p
= rk_strpoolprintf(p
, ", ");
237 kdc_log(context
, config
, 0, "out of memory");
242 p
= rk_strpoolprintf(p
, "none");
244 str
= rk_strpoolcollect(p
);
245 kdc_log(context
, config
, 0, "Client sent patypes: %s", str
);
255 _kdc_encode_reply(krb5_context context
,
256 krb5_kdc_configuration
*config
,
257 KDC_REP
*rep
, const EncTicketPart
*et
, EncKDCRepPart
*ek
,
259 int skvno
, const EncryptionKey
*skey
,
260 int ckvno
, const EncryptionKey
*reply_key
,
271 ASN1_MALLOC_ENCODE(EncTicketPart
, buf
, buf_size
, et
, &len
, ret
);
273 const char *msg
= krb5_get_error_message(context
, ret
);
274 kdc_log(context
, config
, 0, "Failed to encode ticket: %s", msg
);
275 krb5_free_error_message(context
, msg
);
278 if(buf_size
!= len
) {
280 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
281 *e_text
= "KDC internal error";
282 return KRB5KRB_ERR_GENERIC
;
285 ret
= krb5_crypto_init(context
, skey
, etype
, &crypto
);
289 msg
= krb5_get_error_message(context
, ret
);
290 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
291 krb5_free_error_message(context
, msg
);
295 ret
= krb5_encrypt_EncryptedData(context
,
301 &rep
->ticket
.enc_part
);
303 krb5_crypto_destroy(context
, crypto
);
305 const char *msg
= krb5_get_error_message(context
, ret
);
306 kdc_log(context
, config
, 0, "Failed to encrypt data: %s", msg
);
307 krb5_free_error_message(context
, msg
);
311 if(rep
->msg_type
== krb_as_rep
&& !config
->encode_as_rep_as_tgs_rep
)
312 ASN1_MALLOC_ENCODE(EncASRepPart
, buf
, buf_size
, ek
, &len
, ret
);
314 ASN1_MALLOC_ENCODE(EncTGSRepPart
, buf
, buf_size
, ek
, &len
, ret
);
316 const char *msg
= krb5_get_error_message(context
, ret
);
317 kdc_log(context
, config
, 0, "Failed to encode KDC-REP: %s", msg
);
318 krb5_free_error_message(context
, msg
);
321 if(buf_size
!= len
) {
323 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
324 *e_text
= "KDC internal error";
325 return KRB5KRB_ERR_GENERIC
;
327 ret
= krb5_crypto_init(context
, reply_key
, 0, &crypto
);
329 const char *msg
= krb5_get_error_message(context
, ret
);
331 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
332 krb5_free_error_message(context
, msg
);
335 if(rep
->msg_type
== krb_as_rep
) {
336 krb5_encrypt_EncryptedData(context
,
338 KRB5_KU_AS_REP_ENC_PART
,
344 ASN1_MALLOC_ENCODE(AS_REP
, buf
, buf_size
, rep
, &len
, ret
);
346 krb5_encrypt_EncryptedData(context
,
348 rk_is_subkey
? KRB5_KU_TGS_REP_ENC_PART_SUB_KEY
: KRB5_KU_TGS_REP_ENC_PART_SESSION
,
354 ASN1_MALLOC_ENCODE(TGS_REP
, buf
, buf_size
, rep
, &len
, ret
);
356 krb5_crypto_destroy(context
, crypto
);
358 const char *msg
= krb5_get_error_message(context
, ret
);
359 kdc_log(context
, config
, 0, "Failed to encode KDC-REP: %s", msg
);
360 krb5_free_error_message(context
, msg
);
363 if(buf_size
!= len
) {
365 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
366 *e_text
= "KDC internal error";
367 return KRB5KRB_ERR_GENERIC
;
370 reply
->length
= buf_size
;
375 * Return 1 if the client have only older enctypes, this is for
376 * determining if the server should send ETYPE_INFO2 or not.
380 older_enctype(krb5_enctype enctype
)
383 case ETYPE_DES_CBC_CRC
:
384 case ETYPE_DES_CBC_MD4
:
385 case ETYPE_DES_CBC_MD5
:
386 case ETYPE_DES3_CBC_SHA1
:
387 case ETYPE_ARCFOUR_HMAC_MD5
:
388 case ETYPE_ARCFOUR_HMAC_MD5_56
:
390 * The following three is "old" windows enctypes and is needed for
391 * windows 2000 hosts.
393 case ETYPE_ARCFOUR_MD4
:
394 case ETYPE_ARCFOUR_HMAC_OLD
:
395 case ETYPE_ARCFOUR_HMAC_OLD_EXP
:
406 static krb5_error_code
407 make_etype_info_entry(krb5_context context
, ETYPE_INFO_ENTRY
*ent
, Key
*key
)
409 ent
->etype
= key
->key
.keytype
;
412 ALLOC(ent
->salttype
);
414 if(key
->salt
->type
== hdb_pw_salt
)
415 *ent
->salttype
= 0; /* or 1? or NULL? */
416 else if(key
->salt
->type
== hdb_afs3_salt
)
419 kdc_log(context
, config
, 0, "unknown salt-type: %d",
421 return KRB5KRB_ERR_GENERIC
;
423 /* according to `the specs', we can't send a salt if
424 we have AFS3 salted key, but that requires that you
425 *know* what cell you are using (e.g by assuming
426 that the cell is the same as the realm in lower
429 ALLOC(ent
->salttype
);
430 *ent
->salttype
= key
->salt
->type
;
433 * We shouldn't sent salttype since it is incompatible with the
434 * specification and it breaks windows clients. The afs
435 * salting problem is solved by using KRB5-PADATA-AFS3-SALT
436 * implemented in Heimdal 0.7 and later.
438 ent
->salttype
= NULL
;
440 krb5_copy_data(context
, &key
->salt
->salt
,
443 /* we return no salt type at all, as that should indicate
444 * the default salt type and make everybody happy. some
445 * systems (like w2k) dislike being told the salt type
448 ent
->salttype
= NULL
;
454 static krb5_error_code
455 get_pa_etype_info(krb5_context context
,
456 krb5_kdc_configuration
*config
,
457 METHOD_DATA
*md
, Key
*ckey
)
459 krb5_error_code ret
= 0;
466 pa
.val
= calloc(1, sizeof(pa
.val
[0]));
470 ret
= make_etype_info_entry(context
, &pa
.val
[0], ckey
);
472 free_ETYPE_INFO(&pa
);
476 ASN1_MALLOC_ENCODE(ETYPE_INFO
, buf
, len
, &pa
, &len
, ret
);
477 free_ETYPE_INFO(&pa
);
480 ret
= realloc_method_data(md
);
485 md
->val
[md
->len
- 1].padata_type
= KRB5_PADATA_ETYPE_INFO
;
486 md
->val
[md
->len
- 1].padata_value
.length
= len
;
487 md
->val
[md
->len
- 1].padata_value
.data
= buf
;
495 extern int _krb5_AES_string_to_default_iterator
;
497 static krb5_error_code
498 make_etype_info2_entry(ETYPE_INFO2_ENTRY
*ent
, Key
*key
)
500 ent
->etype
= key
->key
.keytype
;
503 if (ent
->salt
== NULL
)
505 *ent
->salt
= malloc(key
->salt
->salt
.length
+ 1);
506 if (*ent
->salt
== NULL
) {
511 memcpy(*ent
->salt
, key
->salt
->salt
.data
, key
->salt
->salt
.length
);
512 (*ent
->salt
)[key
->salt
->salt
.length
] = '\0';
516 ent
->s2kparams
= NULL
;
518 switch (key
->key
.keytype
) {
519 case ETYPE_AES128_CTS_HMAC_SHA1_96
:
520 case ETYPE_AES256_CTS_HMAC_SHA1_96
:
521 ALLOC(ent
->s2kparams
);
522 if (ent
->s2kparams
== NULL
)
524 ent
->s2kparams
->length
= 4;
525 ent
->s2kparams
->data
= malloc(ent
->s2kparams
->length
);
526 if (ent
->s2kparams
->data
== NULL
) {
527 free(ent
->s2kparams
);
528 ent
->s2kparams
= NULL
;
531 _krb5_put_int(ent
->s2kparams
->data
,
532 _krb5_AES_string_to_default_iterator
,
533 ent
->s2kparams
->length
);
535 case ETYPE_DES_CBC_CRC
:
536 case ETYPE_DES_CBC_MD4
:
537 case ETYPE_DES_CBC_MD5
:
538 /* Check if this was a AFS3 salted key */
539 if(key
->salt
&& key
->salt
->type
== hdb_afs3_salt
){
540 ALLOC(ent
->s2kparams
);
541 if (ent
->s2kparams
== NULL
)
543 ent
->s2kparams
->length
= 1;
544 ent
->s2kparams
->data
= malloc(ent
->s2kparams
->length
);
545 if (ent
->s2kparams
->data
== NULL
) {
546 free(ent
->s2kparams
);
547 ent
->s2kparams
= NULL
;
550 _krb5_put_int(ent
->s2kparams
->data
,
552 ent
->s2kparams
->length
);
562 * Return an ETYPE-INFO2. Enctypes are storted the same way as in the
563 * database (client supported enctypes first, then the unsupported
567 static krb5_error_code
568 get_pa_etype_info2(krb5_context context
,
569 krb5_kdc_configuration
*config
,
570 METHOD_DATA
*md
, Key
*ckey
)
572 krb5_error_code ret
= 0;
578 pa
.val
= calloc(1, sizeof(pa
.val
[0]));
582 ret
= make_etype_info2_entry(&pa
.val
[0], ckey
);
584 free_ETYPE_INFO2(&pa
);
588 ASN1_MALLOC_ENCODE(ETYPE_INFO2
, buf
, len
, &pa
, &len
, ret
);
589 free_ETYPE_INFO2(&pa
);
592 ret
= realloc_method_data(md
);
597 md
->val
[md
->len
- 1].padata_type
= KRB5_PADATA_ETYPE_INFO2
;
598 md
->val
[md
->len
- 1].padata_value
.length
= len
;
599 md
->val
[md
->len
- 1].padata_value
.data
= buf
;
608 log_as_req(krb5_context context
,
609 krb5_kdc_configuration
*config
,
612 const KDC_REQ_BODY
*b
)
615 struct rk_strpool
*p
;
619 p
= rk_strpoolprintf(NULL
, "%s", "Client supported enctypes: ");
621 for (i
= 0; i
< b
->etype
.len
; i
++) {
622 ret
= krb5_enctype_to_string(context
, b
->etype
.val
[i
], &str
);
624 p
= rk_strpoolprintf(p
, "%s", str
);
627 p
= rk_strpoolprintf(p
, "%d", b
->etype
.val
[i
]);
628 if (p
&& i
+ 1 < b
->etype
.len
)
629 p
= rk_strpoolprintf(p
, ", ");
631 kdc_log(context
, config
, 0, "out of memory");
636 p
= rk_strpoolprintf(p
, "no encryption types");
642 ret
= krb5_enctype_to_string(context
, cetype
, &cet
);
644 ret
= krb5_enctype_to_string(context
, setype
, &set
);
646 p
= rk_strpoolprintf(p
, ", using %s/%s", cet
, set
);
652 p
= rk_strpoolprintf(p
, ", using enctypes %d/%d",
656 str
= rk_strpoolcollect(p
);
657 kdc_log(context
, config
, 0, "%s", str
);
662 unparse_flags(KDCOptions2int(b
->kdc_options
), asn1_KDCOptions_units(),
663 fixedstr
, sizeof(fixedstr
));
665 kdc_log(context
, config
, 0, "Requested flags: %s", fixedstr
);
670 * verify the flags on `client' and `server', returning 0
671 * if they are OK and generating an error messages and returning
672 * and error code otherwise.
676 kdc_check_flags(krb5_context context
,
677 krb5_kdc_configuration
*config
,
678 hdb_entry_ex
*client_ex
, const char *client_name
,
679 hdb_entry_ex
*server_ex
, const char *server_name
,
680 krb5_boolean is_as_req
)
682 if(client_ex
!= NULL
) {
683 hdb_entry
*client
= &client_ex
->entry
;
686 if (client
->flags
.locked_out
) {
687 kdc_log(context
, config
, 0,
688 "Client (%s) is locked out", client_name
);
689 return KRB5KDC_ERR_POLICY
;
692 if (client
->flags
.invalid
) {
693 kdc_log(context
, config
, 0,
694 "Client (%s) has invalid bit set", client_name
);
695 return KRB5KDC_ERR_POLICY
;
698 if(!client
->flags
.client
){
699 kdc_log(context
, config
, 0,
700 "Principal may not act as client -- %s", client_name
);
701 return KRB5KDC_ERR_POLICY
;
704 if (client
->valid_start
&& *client
->valid_start
> kdc_time
) {
705 char starttime_str
[100];
706 krb5_format_time(context
, *client
->valid_start
,
707 starttime_str
, sizeof(starttime_str
), TRUE
);
708 kdc_log(context
, config
, 0,
709 "Client not yet valid until %s -- %s",
710 starttime_str
, client_name
);
711 return KRB5KDC_ERR_CLIENT_NOTYET
;
714 if (client
->valid_end
&& *client
->valid_end
< kdc_time
) {
715 char endtime_str
[100];
716 krb5_format_time(context
, *client
->valid_end
,
717 endtime_str
, sizeof(endtime_str
), TRUE
);
718 kdc_log(context
, config
, 0,
719 "Client expired at %s -- %s",
720 endtime_str
, client_name
);
721 return KRB5KDC_ERR_NAME_EXP
;
724 if (client
->pw_end
&& *client
->pw_end
< kdc_time
725 && (server_ex
== NULL
|| !server_ex
->entry
.flags
.change_pw
)) {
727 krb5_format_time(context
, *client
->pw_end
,
728 pwend_str
, sizeof(pwend_str
), TRUE
);
729 kdc_log(context
, config
, 0,
730 "Client's key has expired at %s -- %s",
731 pwend_str
, client_name
);
732 return KRB5KDC_ERR_KEY_EXPIRED
;
738 if (server_ex
!= NULL
) {
739 hdb_entry
*server
= &server_ex
->entry
;
741 if (server
->flags
.locked_out
) {
742 kdc_log(context
, config
, 0,
743 "Client server locked out -- %s", server_name
);
744 return KRB5KDC_ERR_POLICY
;
746 if (server
->flags
.invalid
) {
747 kdc_log(context
, config
, 0,
748 "Server has invalid flag set -- %s", server_name
);
749 return KRB5KDC_ERR_POLICY
;
752 if(!server
->flags
.server
){
753 kdc_log(context
, config
, 0,
754 "Principal may not act as server -- %s", server_name
);
755 return KRB5KDC_ERR_POLICY
;
758 if(!is_as_req
&& server
->flags
.initial
) {
759 kdc_log(context
, config
, 0,
760 "AS-REQ is required for server -- %s", server_name
);
761 return KRB5KDC_ERR_POLICY
;
764 if (server
->valid_start
&& *server
->valid_start
> kdc_time
) {
765 char starttime_str
[100];
766 krb5_format_time(context
, *server
->valid_start
,
767 starttime_str
, sizeof(starttime_str
), TRUE
);
768 kdc_log(context
, config
, 0,
769 "Server not yet valid until %s -- %s",
770 starttime_str
, server_name
);
771 return KRB5KDC_ERR_SERVICE_NOTYET
;
774 if (server
->valid_end
&& *server
->valid_end
< kdc_time
) {
775 char endtime_str
[100];
776 krb5_format_time(context
, *server
->valid_end
,
777 endtime_str
, sizeof(endtime_str
), TRUE
);
778 kdc_log(context
, config
, 0,
779 "Server expired at %s -- %s",
780 endtime_str
, server_name
);
781 return KRB5KDC_ERR_SERVICE_EXP
;
784 if (server
->pw_end
&& *server
->pw_end
< kdc_time
) {
786 krb5_format_time(context
, *server
->pw_end
,
787 pwend_str
, sizeof(pwend_str
), TRUE
);
788 kdc_log(context
, config
, 0,
789 "Server's key has expired at -- %s",
790 pwend_str
, server_name
);
791 return KRB5KDC_ERR_KEY_EXPIRED
;
798 * Return TRUE if `from' is part of `addresses' taking into consideration
799 * the configuration variables that tells us how strict we should be about
804 _kdc_check_addresses(krb5_context context
,
805 krb5_kdc_configuration
*config
,
806 HostAddresses
*addresses
, const struct sockaddr
*from
)
811 krb5_boolean only_netbios
= TRUE
;
814 if(config
->check_ticket_addresses
== 0)
817 if(addresses
== NULL
)
818 return config
->allow_null_ticket_addresses
;
820 for (i
= 0; i
< addresses
->len
; ++i
) {
821 if (addresses
->val
[i
].addr_type
!= KRB5_ADDRESS_NETBIOS
) {
822 only_netbios
= FALSE
;
826 /* Windows sends it's netbios name, which I can only assume is
827 * used for the 'allowed workstations' check. This is painful,
828 * but we still want to check IP addresses if they happen to be
833 return config
->allow_null_ticket_addresses
;
835 ret
= krb5_sockaddr2address (context
, from
, &addr
);
839 result
= krb5_address_search(context
, &addr
, addresses
);
840 krb5_free_address (context
, &addr
);
849 send_pac_p(krb5_context context
, KDC_REQ
*req
)
852 PA_PAC_REQUEST pacreq
;
856 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PA_PAC_REQUEST
);
860 ret
= decode_PA_PAC_REQUEST(pa
->padata_value
.data
,
861 pa
->padata_value
.length
,
866 i
= pacreq
.include_pac
;
867 free_PA_PAC_REQUEST(&pacreq
);
874 _kdc_is_anonymous(krb5_context context
, krb5_principal principal
)
876 if (principal
->name
.name_type
!= KRB5_NT_WELLKNOWN
||
877 principal
->name
.name_string
.len
!= 2 ||
878 strcmp(principal
->name
.name_string
.val
[0], KRB5_WELLKNOWN_NAME
) != 0 ||
879 strcmp(principal
->name
.name_string
.val
[1], KRB5_ANON_NAME
) != 0)
889 _kdc_as_rep(krb5_context context
,
890 krb5_kdc_configuration
*config
,
892 const krb5_data
*req_buffer
,
895 struct sockaddr
*from_addr
,
898 KDC_REQ_BODY
*b
= &req
->req_body
;
900 KDCOptions f
= b
->kdc_options
;
901 hdb_entry_ex
*client
= NULL
, *server
= NULL
;
903 krb5_enctype setype
, sessionetype
;
907 krb5_principal client_princ
= NULL
, server_princ
= NULL
;
908 char *client_name
= NULL
, *server_name
= NULL
;
909 krb5_error_code ret
= 0;
910 const char *e_text
= NULL
;
913 EncryptionKey
*reply_key
= NULL
, session_key
;
916 pk_client_params
*pkp
= NULL
;
919 memset(&rep
, 0, sizeof(rep
));
920 memset(&session_key
, 0, sizeof(session_key
));
921 krb5_data_zero(&e_data
);
925 rep
.padata
->val
= NULL
;
928 flags
|= HDB_F_CANON
;
930 if(b
->sname
== NULL
){
931 ret
= KRB5KRB_ERR_GENERIC
;
932 e_text
= "No server in request";
934 ret
= _krb5_principalname2krb5_principal (context
,
939 ret
= krb5_unparse_name(context
, server_princ
, &server_name
);
942 kdc_log(context
, config
, 0,
943 "AS-REQ malformed server name from %s", from
);
946 if(b
->cname
== NULL
){
947 ret
= KRB5KRB_ERR_GENERIC
;
948 e_text
= "No client in request";
950 ret
= _krb5_principalname2krb5_principal (context
,
957 ret
= krb5_unparse_name(context
, client_princ
, &client_name
);
960 kdc_log(context
, config
, 0,
961 "AS-REQ malformed client name from %s", from
);
965 kdc_log(context
, config
, 0, "AS-REQ %s from %s for %s",
966 client_name
, from
, server_name
);
972 if (_kdc_is_anonymous(context
, client_princ
)) {
973 if (!b
->kdc_options
.request_anonymous
) {
974 kdc_log(context
, config
, 0, "Anonymous ticket w/o anonymous flag");
975 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
978 } else if (b
->kdc_options
.request_anonymous
) {
979 kdc_log(context
, config
, 0,
980 "Request for a anonymous ticket with non "
981 "anonymous client name: %s", client_name
);
982 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
990 ret
= _kdc_db_fetch(context
, config
, client_princ
,
991 HDB_F_GET_CLIENT
| flags
, NULL
,
993 if(ret
== HDB_ERR_NOT_FOUND_HERE
) {
994 kdc_log(context
, config
, 5, "client %s does not have secrets at this KDC, need to proxy", client_name
);
997 const char *msg
= krb5_get_error_message(context
, ret
);
998 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", client_name
, msg
);
999 krb5_free_error_message(context
, msg
);
1000 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
1004 ret
= _kdc_db_fetch(context
, config
, server_princ
,
1005 HDB_F_GET_SERVER
|HDB_F_GET_KRBTGT
,
1006 NULL
, NULL
, &server
);
1007 if(ret
== HDB_ERR_NOT_FOUND_HERE
) {
1008 kdc_log(context
, config
, 5, "target %s does not have secrets at this KDC, need to proxy", server_name
);
1011 const char *msg
= krb5_get_error_message(context
, ret
);
1012 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", server_name
, msg
);
1013 krb5_free_error_message(context
, msg
);
1014 ret
= KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN
;
1018 memset(&et
, 0, sizeof(et
));
1019 memset(&ek
, 0, sizeof(ek
));
1022 * Select a session enctype from the list of the crypto systems
1023 * supported enctype, is supported by the client and is one of the
1024 * enctype of the enctype of the krbtgt.
1026 * The later is used as a hint what enctype all KDC are supporting
1027 * to make sure a newer version of KDC wont generate a session
1028 * enctype that and older version of a KDC in the same realm can't
1031 * But if the KDC admin is paranoid and doesn't want to have "no
1032 * the best" enctypes on the krbtgt, lets save the best pick from
1033 * the client list and hope that that will work for any other
1037 const krb5_enctype
*p
;
1038 krb5_enctype clientbest
= ETYPE_NULL
;
1041 p
= krb5_kerberos_enctypes(context
);
1043 sessionetype
= ETYPE_NULL
;
1045 for (i
= 0; p
[i
] != ETYPE_NULL
&& sessionetype
== ETYPE_NULL
; i
++) {
1046 if (krb5_enctype_valid(context
, p
[i
]) != 0)
1049 for (j
= 0; j
< b
->etype
.len
&& sessionetype
== ETYPE_NULL
; j
++) {
1051 /* check with client */
1052 if (p
[i
] != b
->etype
.val
[j
])
1054 /* save best of union of { client, crypto system } */
1055 if (clientbest
== ETYPE_NULL
)
1057 /* check with krbtgt */
1058 ret
= hdb_enctype2key(context
, &server
->entry
, p
[i
], &dummy
);
1061 sessionetype
= p
[i
];
1064 /* if krbtgt had no shared keys with client, pick clients best */
1065 if (clientbest
!= ETYPE_NULL
&& sessionetype
== ETYPE_NULL
) {
1066 sessionetype
= clientbest
;
1067 } else if (sessionetype
== ETYPE_NULL
) {
1068 kdc_log(context
, config
, 0,
1069 "Client (%s) from %s has no common enctypes with KDC"
1070 "to use for the session key",
1077 * Pre-auth processing
1085 log_patypes(context
, config
, req
->padata
);
1088 kdc_log(context
, config
, 5,
1089 "Looking for PKINIT pa-data -- %s", client_name
);
1091 e_text
= "No PKINIT PA found";
1094 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ
);
1097 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ_WIN
);
1100 char *client_cert
= NULL
;
1102 ret
= _kdc_pk_rd_padata(context
, config
, req
, pa
, client
, &pkp
);
1104 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1105 kdc_log(context
, config
, 5,
1106 "Failed to decode PKINIT PA-DATA -- %s",
1110 if (ret
== 0 && pkp
== NULL
)
1113 ret
= _kdc_pk_check_client(context
,
1120 e_text
= "PKINIT certificate not allowed to "
1121 "impersonate principal";
1122 _kdc_pk_free_client_param(context
, pkp
);
1124 kdc_log(context
, config
, 0, "%s", e_text
);
1130 et
.flags
.pre_authent
= 1;
1131 kdc_log(context
, config
, 0,
1132 "PKINIT pre-authentication succeeded -- %s using %s",
1133 client_name
, client_cert
);
1140 kdc_log(context
, config
, 5, "Looking for ENC-TS pa-data -- %s",
1144 e_text
= "No ENC-TS found";
1145 while((pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_ENC_TIMESTAMP
))){
1149 EncryptedData enc_data
;
1155 if (b
->kdc_options
.request_anonymous
) {
1156 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1157 kdc_log(context
, config
, 0, "ENC-TS doesn't support anon");
1161 ret
= decode_EncryptedData(pa
->padata_value
.data
,
1162 pa
->padata_value
.length
,
1166 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1167 kdc_log(context
, config
, 5, "Failed to decode PA-DATA -- %s",
1172 ret
= hdb_enctype2key(context
, &client
->entry
,
1173 enc_data
.etype
, &pa_key
);
1176 e_text
= "No key matches pa-data";
1177 ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
1178 if(krb5_enctype_to_string(context
, enc_data
.etype
, &estr
))
1181 kdc_log(context
, config
, 5,
1182 "No client key matching pa-data (%d) -- %s",
1183 enc_data
.etype
, client_name
);
1185 kdc_log(context
, config
, 5,
1186 "No client key matching pa-data (%s) -- %s",
1189 free_EncryptedData(&enc_data
);
1195 ret
= krb5_crypto_init(context
, &pa_key
->key
, 0, &crypto
);
1197 const char *msg
= krb5_get_error_message(context
, ret
);
1198 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
1199 krb5_free_error_message(context
, msg
);
1200 free_EncryptedData(&enc_data
);
1204 ret
= krb5_decrypt_EncryptedData (context
,
1206 KRB5_KU_PA_ENC_TIMESTAMP
,
1209 krb5_crypto_destroy(context
, crypto
);
1211 * Since the user might have several keys with the same
1212 * enctype but with diffrent salting, we need to try all
1213 * the keys with the same enctype.
1216 krb5_error_code ret2
;
1217 const char *msg
= krb5_get_error_message(context
, ret
);
1219 ret2
= krb5_enctype_to_string(context
,
1220 pa_key
->key
.keytype
, &str
);
1223 kdc_log(context
, config
, 5,
1224 "Failed to decrypt PA-DATA -- %s "
1225 "(enctype %s) error %s",
1226 client_name
, str
? str
: "unknown enctype", msg
);
1227 krb5_free_error_message(context
, msg
);
1230 if(hdb_next_enctype2key(context
, &client
->entry
,
1231 enc_data
.etype
, &pa_key
) == 0)
1233 e_text
= "Failed to decrypt PA-DATA";
1235 free_EncryptedData(&enc_data
);
1237 if (clientdb
->hdb_auth_status
)
1238 (clientdb
->hdb_auth_status
)(context
, clientdb
, client
, HDB_AUTH_WRONG_PASSWORD
);
1240 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1243 free_EncryptedData(&enc_data
);
1244 ret
= decode_PA_ENC_TS_ENC(ts_data
.data
,
1248 krb5_data_free(&ts_data
);
1250 e_text
= "Failed to decode PA-ENC-TS-ENC";
1251 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1252 kdc_log(context
, config
,
1253 5, "Failed to decode PA-ENC-TS_ENC -- %s",
1257 free_PA_ENC_TS_ENC(&p
);
1258 if (abs(kdc_time
- p
.patimestamp
) > context
->max_skew
) {
1259 char client_time
[100];
1261 krb5_format_time(context
, p
.patimestamp
,
1262 client_time
, sizeof(client_time
), TRUE
);
1264 ret
= KRB5KRB_AP_ERR_SKEW
;
1265 kdc_log(context
, config
, 0,
1266 "Too large time skew, "
1267 "client time %s is out by %u > %u seconds -- %s",
1269 (unsigned)abs(kdc_time
- p
.patimestamp
),
1274 * The following is needed to make windows clients to
1275 * retry using the timestamp in the error message, if
1276 * there is a e_text, they become unhappy.
1281 et
.flags
.pre_authent
= 1;
1283 set_salt_padata(rep
.padata
, pa_key
->salt
);
1285 reply_key
= &pa_key
->key
;
1287 ret
= krb5_enctype_to_string(context
, pa_key
->key
.keytype
, &str
);
1291 kdc_log(context
, config
, 2,
1292 "ENC-TS Pre-authentication succeeded -- %s using %s",
1293 client_name
, str
? str
: "unknown enctype");
1300 if(found_pa
== 0 && config
->require_preauth
)
1302 /* We come here if we found a pa-enc-timestamp, but if there
1303 was some problem with it, other than too large skew */
1304 if(found_pa
&& et
.flags
.pre_authent
== 0){
1305 kdc_log(context
, config
, 0, "%s -- %s", e_text
, client_name
);
1309 }else if (config
->require_preauth
1310 || b
->kdc_options
.request_anonymous
/* hack to force anon */
1311 || client
->entry
.flags
.require_preauth
1312 || server
->entry
.flags
.require_preauth
) {
1313 METHOD_DATA method_data
;
1319 method_data
.len
= 0;
1320 method_data
.val
= NULL
;
1322 ret
= realloc_method_data(&method_data
);
1324 free_METHOD_DATA(&method_data
);
1327 pa
= &method_data
.val
[method_data
.len
-1];
1328 pa
->padata_type
= KRB5_PADATA_ENC_TIMESTAMP
;
1329 pa
->padata_value
.length
= 0;
1330 pa
->padata_value
.data
= NULL
;
1333 ret
= realloc_method_data(&method_data
);
1335 free_METHOD_DATA(&method_data
);
1338 pa
= &method_data
.val
[method_data
.len
-1];
1339 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ
;
1340 pa
->padata_value
.length
= 0;
1341 pa
->padata_value
.data
= NULL
;
1343 ret
= realloc_method_data(&method_data
);
1345 free_METHOD_DATA(&method_data
);
1348 pa
= &method_data
.val
[method_data
.len
-1];
1349 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ_WIN
;
1350 pa
->padata_value
.length
= 0;
1351 pa
->padata_value
.data
= NULL
;
1355 * If there is a client key, send ETYPE_INFO{,2}
1357 ret
= _kdc_find_etype(context
, client
, b
->etype
.val
, b
->etype
.len
,
1363 * - If the client only knows about old enctypes, then send
1364 * both info replies (we send 'info' first in the list).
1365 * - If the client is 'modern', because it knows about 'new'
1366 * enctype types, then only send the 'info2' reply.
1368 * Before we send the full list of etype-info data, we pick
1369 * the client key we would have used anyway below, just pick
1373 if (older_enctype(ckey
->key
.keytype
)) {
1374 ret
= get_pa_etype_info(context
, config
,
1375 &method_data
, ckey
);
1377 free_METHOD_DATA(&method_data
);
1381 ret
= get_pa_etype_info2(context
, config
,
1382 &method_data
, ckey
);
1384 free_METHOD_DATA(&method_data
);
1389 ASN1_MALLOC_ENCODE(METHOD_DATA
, buf
, len
, &method_data
, &len
, ret
);
1390 free_METHOD_DATA(&method_data
);
1393 e_data
.length
= len
;
1394 e_text
="Need to use PA-ENC-TIMESTAMP/PA-PK-AS-REQ",
1396 ret
= KRB5KDC_ERR_PREAUTH_REQUIRED
;
1398 kdc_log(context
, config
, 0,
1399 "No preauth found, returning PREAUTH-REQUIRED -- %s",
1404 if (clientdb
->hdb_auth_status
)
1405 (clientdb
->hdb_auth_status
)(context
, clientdb
, client
,
1409 * Verify flags after the user been required to prove its identity
1410 * with in a preauth mech.
1413 ret
= _kdc_check_access(context
, config
, client
, client_name
,
1414 server
, server_name
,
1420 * Selelct the best encryption type for the KDC with out regard to
1421 * the client since the client never needs to read that data.
1424 ret
= _kdc_get_preferred_key(context
, config
,
1425 server
, server_name
,
1430 if(f
.renew
|| f
.validate
|| f
.proxy
|| f
.forwarded
|| f
.enc_tkt_in_skey
1431 || (f
.request_anonymous
&& !config
->allow_anonymous
)) {
1432 ret
= KRB5KDC_ERR_BADOPTION
;
1433 e_text
= "Bad KDC options";
1434 kdc_log(context
, config
, 0, "Bad KDC options -- %s", client_name
);
1439 rep
.msg_type
= krb_as_rep
;
1441 ret
= copy_Realm(&client
->entry
.principal
->realm
, &rep
.crealm
);
1444 ret
= _krb5_principal2principalname(&rep
.cname
, client
->entry
.principal
);
1448 rep
.ticket
.tkt_vno
= 5;
1449 copy_Realm(&server
->entry
.principal
->realm
, &rep
.ticket
.realm
);
1450 _krb5_principal2principalname(&rep
.ticket
.sname
,
1451 server
->entry
.principal
);
1452 /* java 1.6 expects the name to be the same type, lets allow that
1453 * uncomplicated name-types. */
1454 #define CNT(sp,t) (((sp)->sname->name_type) == KRB5_NT_##t)
1455 if (CNT(b
, UNKNOWN
) || CNT(b
, PRINCIPAL
) || CNT(b
, SRV_INST
) || CNT(b
, SRV_HST
) || CNT(b
, SRV_XHST
))
1456 rep
.ticket
.sname
.name_type
= b
->sname
->name_type
;
1459 et
.flags
.initial
= 1;
1460 if(client
->entry
.flags
.forwardable
&& server
->entry
.flags
.forwardable
)
1461 et
.flags
.forwardable
= f
.forwardable
;
1462 else if (f
.forwardable
) {
1463 e_text
= "Ticket may not be forwardable";
1464 ret
= KRB5KDC_ERR_POLICY
;
1465 kdc_log(context
, config
, 0,
1466 "Ticket may not be forwardable -- %s", client_name
);
1469 if(client
->entry
.flags
.proxiable
&& server
->entry
.flags
.proxiable
)
1470 et
.flags
.proxiable
= f
.proxiable
;
1471 else if (f
.proxiable
) {
1472 e_text
= "Ticket may not be proxiable";
1473 ret
= KRB5KDC_ERR_POLICY
;
1474 kdc_log(context
, config
, 0,
1475 "Ticket may not be proxiable -- %s", client_name
);
1478 if(client
->entry
.flags
.postdate
&& server
->entry
.flags
.postdate
)
1479 et
.flags
.may_postdate
= f
.allow_postdate
;
1480 else if (f
.allow_postdate
){
1481 e_text
= "Ticket may not be postdate";
1482 ret
= KRB5KDC_ERR_POLICY
;
1483 kdc_log(context
, config
, 0,
1484 "Ticket may not be postdatable -- %s", client_name
);
1488 /* check for valid set of addresses */
1489 if(!_kdc_check_addresses(context
, config
, b
->addresses
, from_addr
)) {
1490 e_text
= "Bad address list in requested";
1491 ret
= KRB5KRB_AP_ERR_BADADDR
;
1492 kdc_log(context
, config
, 0,
1493 "Bad address list requested -- %s", client_name
);
1497 ret
= copy_PrincipalName(&rep
.cname
, &et
.cname
);
1500 ret
= copy_Realm(&rep
.crealm
, &et
.crealm
);
1508 start
= et
.authtime
= kdc_time
;
1510 if(f
.postdated
&& req
->req_body
.from
){
1511 ALLOC(et
.starttime
);
1512 start
= *et
.starttime
= *req
->req_body
.from
;
1513 et
.flags
.invalid
= 1;
1514 et
.flags
.postdated
= 1; /* XXX ??? */
1516 _kdc_fix_time(&b
->till
);
1519 /* be careful not overflowing */
1521 if(client
->entry
.max_life
)
1522 t
= start
+ min(t
- start
, *client
->entry
.max_life
);
1523 if(server
->entry
.max_life
)
1524 t
= start
+ min(t
- start
, *server
->entry
.max_life
);
1526 t
= min(t
, start
+ realm
->max_life
);
1529 if(f
.renewable_ok
&& et
.endtime
< *b
->till
){
1531 if(b
->rtime
== NULL
){
1535 if(*b
->rtime
< *b
->till
)
1536 *b
->rtime
= *b
->till
;
1538 if(f
.renewable
&& b
->rtime
){
1542 if(client
->entry
.max_renew
)
1543 t
= start
+ min(t
- start
, *client
->entry
.max_renew
);
1544 if(server
->entry
.max_renew
)
1545 t
= start
+ min(t
- start
, *server
->entry
.max_renew
);
1547 t
= min(t
, start
+ realm
->max_renew
);
1549 ALLOC(et
.renew_till
);
1551 et
.flags
.renewable
= 1;
1555 if (f
.request_anonymous
)
1556 et
.flags
.anonymous
= 1;
1560 copy_HostAddresses(b
->addresses
, et
.caddr
);
1563 et
.transited
.tr_type
= DOMAIN_X500_COMPRESS
;
1564 krb5_data_zero(&et
.transited
.contents
);
1566 /* The MIT ASN.1 library (obviously) doesn't tell lengths encoded
1567 * as 0 and as 0x80 (meaning indefinite length) apart, and is thus
1568 * incapable of correctly decoding SEQUENCE OF's of zero length.
1570 * To fix this, always send at least one no-op last_req
1572 * If there's a pw_end or valid_end we will use that,
1573 * otherwise just a dummy lr.
1575 ek
.last_req
.val
= malloc(2 * sizeof(*ek
.last_req
.val
));
1576 if (ek
.last_req
.val
== NULL
) {
1580 ek
.last_req
.len
= 0;
1581 if (client
->entry
.pw_end
1582 && (config
->kdc_warn_pwexpire
== 0
1583 || kdc_time
+ config
->kdc_warn_pwexpire
>= *client
->entry
.pw_end
)) {
1584 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_PW_EXPTIME
;
1585 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.pw_end
;
1588 if (client
->entry
.valid_end
) {
1589 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_ACCT_EXPTIME
;
1590 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.valid_end
;
1593 if (ek
.last_req
.len
== 0) {
1594 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_NONE
;
1595 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= 0;
1598 ek
.nonce
= b
->nonce
;
1599 if (client
->entry
.valid_end
|| client
->entry
.pw_end
) {
1600 ALLOC(ek
.key_expiration
);
1601 if (client
->entry
.valid_end
) {
1602 if (client
->entry
.pw_end
)
1603 *ek
.key_expiration
= min(*client
->entry
.valid_end
,
1604 *client
->entry
.pw_end
);
1606 *ek
.key_expiration
= *client
->entry
.valid_end
;
1608 *ek
.key_expiration
= *client
->entry
.pw_end
;
1610 ek
.key_expiration
= NULL
;
1611 ek
.flags
= et
.flags
;
1612 ek
.authtime
= et
.authtime
;
1614 ALLOC(ek
.starttime
);
1615 *ek
.starttime
= *et
.starttime
;
1617 ek
.endtime
= et
.endtime
;
1618 if (et
.renew_till
) {
1619 ALLOC(ek
.renew_till
);
1620 *ek
.renew_till
= *et
.renew_till
;
1622 copy_Realm(&rep
.ticket
.realm
, &ek
.srealm
);
1623 copy_PrincipalName(&rep
.ticket
.sname
, &ek
.sname
);
1626 copy_HostAddresses(et
.caddr
, ek
.caddr
);
1631 e_text
= "Failed to build PK-INIT reply";
1632 ret
= _kdc_pk_mk_pa_reply(context
, config
, pkp
, client
,
1633 sessionetype
, req
, req_buffer
,
1634 &reply_key
, &et
.key
, rep
.padata
);
1637 ret
= _kdc_add_inital_verified_cas(context
,
1647 ret
= krb5_generate_random_keyblock(context
, sessionetype
, &et
.key
);
1652 if (reply_key
== NULL
) {
1653 e_text
= "Client have no reply key";
1654 ret
= KRB5KDC_ERR_CLIENT_NOTYET
;
1658 ret
= copy_EncryptionKey(&et
.key
, &ek
.key
);
1662 /* Add signing of alias referral */
1663 if (f
.canonicalize
) {
1664 PA_ClientCanonicalized canon
;
1670 memset(&canon
, 0, sizeof(canon
));
1672 canon
.names
.requested_name
= *b
->cname
;
1673 canon
.names
.mapped_name
= client
->entry
.principal
->name
;
1675 ASN1_MALLOC_ENCODE(PA_ClientCanonicalizedNames
, data
.data
, data
.length
,
1676 &canon
.names
, &len
, ret
);
1679 if (data
.length
!= len
)
1680 krb5_abortx(context
, "internal asn.1 error");
1682 /* sign using "returned session key" */
1683 ret
= krb5_crypto_init(context
, &et
.key
, 0, &crypto
);
1689 ret
= krb5_create_checksum(context
, crypto
,
1690 KRB5_KU_CANONICALIZED_NAMES
, 0,
1691 data
.data
, data
.length
,
1692 &canon
.canon_checksum
);
1694 krb5_crypto_destroy(context
, crypto
);
1698 ASN1_MALLOC_ENCODE(PA_ClientCanonicalized
, data
.data
, data
.length
,
1700 free_Checksum(&canon
.canon_checksum
);
1703 if (data
.length
!= len
)
1704 krb5_abortx(context
, "internal asn.1 error");
1706 pa
.padata_type
= KRB5_PADATA_CLIENT_CANONICALIZED
;
1707 pa
.padata_value
= data
;
1708 ret
= add_METHOD_DATA(rep
.padata
, &pa
);
1714 if (rep
.padata
->len
== 0) {
1720 if (send_pac_p(context
, req
)) {
1724 ret
= _kdc_pac_generate(context
, client
, &p
);
1726 kdc_log(context
, config
, 0, "PAC generation failed for -- %s",
1731 ret
= _krb5_pac_sign(context
, p
, et
.authtime
,
1732 client
->entry
.principal
,
1733 &skey
->key
, /* Server key */
1734 &skey
->key
, /* FIXME: should be krbtgt key */
1736 krb5_pac_free(context
, p
);
1738 kdc_log(context
, config
, 0, "PAC signing failed for -- %s",
1743 ret
= _kdc_tkt_add_if_relevant_ad(context
, &et
,
1744 KRB5_AUTHDATA_WIN2K_PAC
,
1746 krb5_data_free(&data
);
1752 _kdc_log_timestamp(context
, config
, "AS-REQ", et
.authtime
, et
.starttime
,
1753 et
.endtime
, et
.renew_till
);
1755 /* do this as the last thing since this signs the EncTicketPart */
1756 ret
= _kdc_add_KRB5SignedPath(context
,
1760 client
->entry
.principal
,
1767 log_as_req(context
, config
, reply_key
->keytype
, setype
, b
);
1769 ret
= _kdc_encode_reply(context
, config
,
1770 &rep
, &et
, &ek
, setype
, server
->entry
.kvno
,
1771 &skey
->key
, client
->entry
.kvno
,
1772 reply_key
, 0, &e_text
, reply
);
1773 free_EncTicketPart(&et
);
1774 free_EncKDCRepPart(&ek
);
1779 if (datagram_reply
&& reply
->length
> config
->max_datagram_reply_length
) {
1780 krb5_data_free(reply
);
1781 ret
= KRB5KRB_ERR_RESPONSE_TOO_BIG
;
1782 e_text
= "Reply packet too large";
1787 if(ret
!= 0 && ret
!= HDB_ERR_NOT_FOUND_HERE
){
1788 krb5_mk_error(context
,
1791 (e_data
.data
? &e_data
: NULL
),
1801 _kdc_pk_free_client_param(context
, pkp
);
1806 krb5_free_principal(context
, client_princ
);
1809 krb5_free_principal(context
, server_princ
);
1812 _kdc_free_ent(context
, client
);
1814 _kdc_free_ent(context
, server
);
1819 * Add the AuthorizationData `data´ of `type´ to the last element in
1820 * the sequence of authorization_data in `tkt´ wrapped in an IF_RELEVANT
1824 _kdc_tkt_add_if_relevant_ad(krb5_context context
,
1827 const krb5_data
*data
)
1829 krb5_error_code ret
;
1832 if (tkt
->authorization_data
== NULL
) {
1833 tkt
->authorization_data
= calloc(1, sizeof(*tkt
->authorization_data
));
1834 if (tkt
->authorization_data
== NULL
) {
1835 krb5_set_error_message(context
, ENOMEM
, "out of memory");
1840 /* add the entry to the last element */
1842 AuthorizationData ad
= { 0, NULL
};
1843 AuthorizationDataElement ade
;
1846 ade
.ad_data
= *data
;
1848 ret
= add_AuthorizationData(&ad
, &ade
);
1850 krb5_set_error_message(context
, ret
, "add AuthorizationData failed");
1854 ade
.ad_type
= KRB5_AUTHDATA_IF_RELEVANT
;
1856 ASN1_MALLOC_ENCODE(AuthorizationData
,
1857 ade
.ad_data
.data
, ade
.ad_data
.length
,
1859 free_AuthorizationData(&ad
);
1861 krb5_set_error_message(context
, ret
, "ASN.1 encode of "
1862 "AuthorizationData failed");
1865 if (ade
.ad_data
.length
!= size
)
1866 krb5_abortx(context
, "internal asn.1 encoder error");
1868 ret
= add_AuthorizationData(tkt
->authorization_data
, &ade
);
1869 der_free_octet_string(&ade
.ad_data
);
1871 krb5_set_error_message(context
, ret
, "add AuthorizationData failed");