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
, &clientdb
, &client
);
993 const char *msg
= krb5_get_error_message(context
, ret
);
994 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", client_name
, msg
);
995 krb5_free_error_message(context
, msg
);
996 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
1000 ret
= _kdc_db_fetch(context
, config
, server_princ
,
1001 HDB_F_GET_SERVER
|HDB_F_GET_KRBTGT
,
1004 const char *msg
= krb5_get_error_message(context
, ret
);
1005 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", server_name
, msg
);
1006 krb5_free_error_message(context
, msg
);
1007 ret
= KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN
;
1011 memset(&et
, 0, sizeof(et
));
1012 memset(&ek
, 0, sizeof(ek
));
1015 * Select a session enctype from the list of the crypto systems
1016 * supported enctype, is supported by the client and is one of the
1017 * enctype of the enctype of the krbtgt.
1019 * The later is used as a hint what enctype all KDC are supporting
1020 * to make sure a newer version of KDC wont generate a session
1021 * enctype that and older version of a KDC in the same realm can't
1024 * But if the KDC admin is paranoid and doesn't want to have "no
1025 * the best" enctypes on the krbtgt, lets save the best pick from
1026 * the client list and hope that that will work for any other
1030 const krb5_enctype
*p
;
1031 krb5_enctype clientbest
= ETYPE_NULL
;
1034 p
= krb5_kerberos_enctypes(context
);
1036 sessionetype
= ETYPE_NULL
;
1038 for (i
= 0; p
[i
] != ETYPE_NULL
&& sessionetype
== ETYPE_NULL
; i
++) {
1039 if (krb5_enctype_valid(context
, p
[i
]) != 0)
1042 for (j
= 0; j
< b
->etype
.len
&& sessionetype
== ETYPE_NULL
; j
++) {
1044 /* check with client */
1045 if (p
[i
] != b
->etype
.val
[j
])
1047 /* save best of union of { client, crypto system } */
1048 if (clientbest
== ETYPE_NULL
)
1050 /* check with krbtgt */
1051 ret
= hdb_enctype2key(context
, &server
->entry
, p
[i
], &dummy
);
1054 sessionetype
= p
[i
];
1057 /* if krbtgt had no shared keys with client, pick clients best */
1058 if (clientbest
!= ETYPE_NULL
&& sessionetype
== ETYPE_NULL
) {
1059 sessionetype
= clientbest
;
1060 } else if (sessionetype
== ETYPE_NULL
) {
1061 kdc_log(context
, config
, 0,
1062 "Client (%s) from %s has no common enctypes with KDC"
1063 "to use for the session key",
1070 * Pre-auth processing
1078 log_patypes(context
, config
, req
->padata
);
1081 kdc_log(context
, config
, 5,
1082 "Looking for PKINIT pa-data -- %s", client_name
);
1084 e_text
= "No PKINIT PA found";
1087 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ
);
1090 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ_WIN
);
1093 char *client_cert
= NULL
;
1095 ret
= _kdc_pk_rd_padata(context
, config
, req
, pa
, client
, &pkp
);
1097 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1098 kdc_log(context
, config
, 5,
1099 "Failed to decode PKINIT PA-DATA -- %s",
1103 if (ret
== 0 && pkp
== NULL
)
1106 ret
= _kdc_pk_check_client(context
,
1113 e_text
= "PKINIT certificate not allowed to "
1114 "impersonate principal";
1115 _kdc_pk_free_client_param(context
, pkp
);
1117 kdc_log(context
, config
, 0, "%s", e_text
);
1123 et
.flags
.pre_authent
= 1;
1124 kdc_log(context
, config
, 0,
1125 "PKINIT pre-authentication succeeded -- %s using %s",
1126 client_name
, client_cert
);
1133 kdc_log(context
, config
, 5, "Looking for ENC-TS pa-data -- %s",
1137 e_text
= "No ENC-TS found";
1138 while((pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_ENC_TIMESTAMP
))){
1142 EncryptedData enc_data
;
1148 if (b
->kdc_options
.request_anonymous
) {
1149 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1150 kdc_log(context
, config
, 0, "ENC-TS doesn't support anon");
1154 ret
= decode_EncryptedData(pa
->padata_value
.data
,
1155 pa
->padata_value
.length
,
1159 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1160 kdc_log(context
, config
, 5, "Failed to decode PA-DATA -- %s",
1165 ret
= hdb_enctype2key(context
, &client
->entry
,
1166 enc_data
.etype
, &pa_key
);
1169 e_text
= "No key matches pa-data";
1170 ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
1171 if(krb5_enctype_to_string(context
, enc_data
.etype
, &estr
))
1174 kdc_log(context
, config
, 5,
1175 "No client key matching pa-data (%d) -- %s",
1176 enc_data
.etype
, client_name
);
1178 kdc_log(context
, config
, 5,
1179 "No client key matching pa-data (%s) -- %s",
1182 free_EncryptedData(&enc_data
);
1188 ret
= krb5_crypto_init(context
, &pa_key
->key
, 0, &crypto
);
1190 const char *msg
= krb5_get_error_message(context
, ret
);
1191 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
1192 krb5_free_error_message(context
, msg
);
1193 free_EncryptedData(&enc_data
);
1197 ret
= krb5_decrypt_EncryptedData (context
,
1199 KRB5_KU_PA_ENC_TIMESTAMP
,
1202 krb5_crypto_destroy(context
, crypto
);
1204 * Since the user might have several keys with the same
1205 * enctype but with diffrent salting, we need to try all
1206 * the keys with the same enctype.
1209 krb5_error_code ret2
;
1210 const char *msg
= krb5_get_error_message(context
, ret
);
1212 ret2
= krb5_enctype_to_string(context
,
1213 pa_key
->key
.keytype
, &str
);
1216 kdc_log(context
, config
, 5,
1217 "Failed to decrypt PA-DATA -- %s "
1218 "(enctype %s) error %s",
1219 client_name
, str
? str
: "unknown enctype", msg
);
1220 krb5_free_error_message(context
, msg
);
1223 if(hdb_next_enctype2key(context
, &client
->entry
,
1224 enc_data
.etype
, &pa_key
) == 0)
1226 e_text
= "Failed to decrypt PA-DATA";
1228 free_EncryptedData(&enc_data
);
1230 if (clientdb
->hdb_auth_status
)
1231 (clientdb
->hdb_auth_status
)(context
, clientdb
, client
, HDB_AUTH_WRONG_PASSWORD
);
1233 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1236 free_EncryptedData(&enc_data
);
1237 ret
= decode_PA_ENC_TS_ENC(ts_data
.data
,
1241 krb5_data_free(&ts_data
);
1243 e_text
= "Failed to decode PA-ENC-TS-ENC";
1244 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1245 kdc_log(context
, config
,
1246 5, "Failed to decode PA-ENC-TS_ENC -- %s",
1250 free_PA_ENC_TS_ENC(&p
);
1251 if (abs(kdc_time
- p
.patimestamp
) > context
->max_skew
) {
1252 char client_time
[100];
1254 krb5_format_time(context
, p
.patimestamp
,
1255 client_time
, sizeof(client_time
), TRUE
);
1257 ret
= KRB5KRB_AP_ERR_SKEW
;
1258 kdc_log(context
, config
, 0,
1259 "Too large time skew, "
1260 "client time %s is out by %u > %u seconds -- %s",
1262 (unsigned)abs(kdc_time
- p
.patimestamp
),
1267 * The following is needed to make windows clients to
1268 * retry using the timestamp in the error message, if
1269 * there is a e_text, they become unhappy.
1274 et
.flags
.pre_authent
= 1;
1276 set_salt_padata(rep
.padata
, pa_key
->salt
);
1278 reply_key
= &pa_key
->key
;
1280 ret
= krb5_enctype_to_string(context
, pa_key
->key
.keytype
, &str
);
1284 kdc_log(context
, config
, 2,
1285 "ENC-TS Pre-authentication succeeded -- %s using %s",
1286 client_name
, str
? str
: "unknown enctype");
1293 if(found_pa
== 0 && config
->require_preauth
)
1295 /* We come here if we found a pa-enc-timestamp, but if there
1296 was some problem with it, other than too large skew */
1297 if(found_pa
&& et
.flags
.pre_authent
== 0){
1298 kdc_log(context
, config
, 0, "%s -- %s", e_text
, client_name
);
1302 }else if (config
->require_preauth
1303 || b
->kdc_options
.request_anonymous
/* hack to force anon */
1304 || client
->entry
.flags
.require_preauth
1305 || server
->entry
.flags
.require_preauth
) {
1306 METHOD_DATA method_data
;
1312 method_data
.len
= 0;
1313 method_data
.val
= NULL
;
1315 ret
= realloc_method_data(&method_data
);
1317 free_METHOD_DATA(&method_data
);
1320 pa
= &method_data
.val
[method_data
.len
-1];
1321 pa
->padata_type
= KRB5_PADATA_ENC_TIMESTAMP
;
1322 pa
->padata_value
.length
= 0;
1323 pa
->padata_value
.data
= NULL
;
1326 ret
= realloc_method_data(&method_data
);
1328 free_METHOD_DATA(&method_data
);
1331 pa
= &method_data
.val
[method_data
.len
-1];
1332 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ
;
1333 pa
->padata_value
.length
= 0;
1334 pa
->padata_value
.data
= NULL
;
1336 ret
= realloc_method_data(&method_data
);
1338 free_METHOD_DATA(&method_data
);
1341 pa
= &method_data
.val
[method_data
.len
-1];
1342 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ_WIN
;
1343 pa
->padata_value
.length
= 0;
1344 pa
->padata_value
.data
= NULL
;
1348 * If there is a client key, send ETYPE_INFO{,2}
1350 ret
= _kdc_find_etype(context
, client
, b
->etype
.val
, b
->etype
.len
,
1356 * - If the client only knows about old enctypes, then send
1357 * both info replies (we send 'info' first in the list).
1358 * - If the client is 'modern', because it knows about 'new'
1359 * enctype types, then only send the 'info2' reply.
1361 * Before we send the full list of etype-info data, we pick
1362 * the client key we would have used anyway below, just pick
1366 if (older_enctype(ckey
->key
.keytype
)) {
1367 ret
= get_pa_etype_info(context
, config
,
1368 &method_data
, ckey
);
1370 free_METHOD_DATA(&method_data
);
1374 ret
= get_pa_etype_info2(context
, config
,
1375 &method_data
, ckey
);
1377 free_METHOD_DATA(&method_data
);
1382 ASN1_MALLOC_ENCODE(METHOD_DATA
, buf
, len
, &method_data
, &len
, ret
);
1383 free_METHOD_DATA(&method_data
);
1386 e_data
.length
= len
;
1387 e_text
="Need to use PA-ENC-TIMESTAMP/PA-PK-AS-REQ",
1389 ret
= KRB5KDC_ERR_PREAUTH_REQUIRED
;
1391 kdc_log(context
, config
, 0,
1392 "No preauth found, returning PREAUTH-REQUIRED -- %s",
1397 if (clientdb
->hdb_auth_status
)
1398 (clientdb
->hdb_auth_status
)(context
, clientdb
, client
,
1402 * Verify flags after the user been required to prove its identity
1403 * with in a preauth mech.
1406 ret
= _kdc_check_access(context
, config
, client
, client_name
,
1407 server
, server_name
,
1413 * Selelct the best encryption type for the KDC with out regard to
1414 * the client since the client never needs to read that data.
1417 ret
= _kdc_get_preferred_key(context
, config
,
1418 server
, server_name
,
1423 if(f
.renew
|| f
.validate
|| f
.proxy
|| f
.forwarded
|| f
.enc_tkt_in_skey
1424 || (f
.request_anonymous
&& !config
->allow_anonymous
)) {
1425 ret
= KRB5KDC_ERR_BADOPTION
;
1426 e_text
= "Bad KDC options";
1427 kdc_log(context
, config
, 0, "Bad KDC options -- %s", client_name
);
1432 rep
.msg_type
= krb_as_rep
;
1434 ret
= copy_Realm(&client
->entry
.principal
->realm
, &rep
.crealm
);
1437 ret
= _krb5_principal2principalname(&rep
.cname
, client
->entry
.principal
);
1441 rep
.ticket
.tkt_vno
= 5;
1442 copy_Realm(&server
->entry
.principal
->realm
, &rep
.ticket
.realm
);
1443 _krb5_principal2principalname(&rep
.ticket
.sname
,
1444 server
->entry
.principal
);
1445 /* java 1.6 expects the name to be the same type, lets allow that
1446 * uncomplicated name-types. */
1447 #define CNT(sp,t) (((sp)->sname->name_type) == KRB5_NT_##t)
1448 if (CNT(b
, UNKNOWN
) || CNT(b
, PRINCIPAL
) || CNT(b
, SRV_INST
) || CNT(b
, SRV_HST
) || CNT(b
, SRV_XHST
))
1449 rep
.ticket
.sname
.name_type
= b
->sname
->name_type
;
1452 et
.flags
.initial
= 1;
1453 if(client
->entry
.flags
.forwardable
&& server
->entry
.flags
.forwardable
)
1454 et
.flags
.forwardable
= f
.forwardable
;
1455 else if (f
.forwardable
) {
1456 e_text
= "Ticket may not be forwardable";
1457 ret
= KRB5KDC_ERR_POLICY
;
1458 kdc_log(context
, config
, 0,
1459 "Ticket may not be forwardable -- %s", client_name
);
1462 if(client
->entry
.flags
.proxiable
&& server
->entry
.flags
.proxiable
)
1463 et
.flags
.proxiable
= f
.proxiable
;
1464 else if (f
.proxiable
) {
1465 e_text
= "Ticket may not be proxiable";
1466 ret
= KRB5KDC_ERR_POLICY
;
1467 kdc_log(context
, config
, 0,
1468 "Ticket may not be proxiable -- %s", client_name
);
1471 if(client
->entry
.flags
.postdate
&& server
->entry
.flags
.postdate
)
1472 et
.flags
.may_postdate
= f
.allow_postdate
;
1473 else if (f
.allow_postdate
){
1474 e_text
= "Ticket may not be postdate";
1475 ret
= KRB5KDC_ERR_POLICY
;
1476 kdc_log(context
, config
, 0,
1477 "Ticket may not be postdatable -- %s", client_name
);
1481 /* check for valid set of addresses */
1482 if(!_kdc_check_addresses(context
, config
, b
->addresses
, from_addr
)) {
1483 e_text
= "Bad address list in requested";
1484 ret
= KRB5KRB_AP_ERR_BADADDR
;
1485 kdc_log(context
, config
, 0,
1486 "Bad address list requested -- %s", client_name
);
1490 ret
= copy_PrincipalName(&rep
.cname
, &et
.cname
);
1493 ret
= copy_Realm(&rep
.crealm
, &et
.crealm
);
1501 start
= et
.authtime
= kdc_time
;
1503 if(f
.postdated
&& req
->req_body
.from
){
1504 ALLOC(et
.starttime
);
1505 start
= *et
.starttime
= *req
->req_body
.from
;
1506 et
.flags
.invalid
= 1;
1507 et
.flags
.postdated
= 1; /* XXX ??? */
1509 _kdc_fix_time(&b
->till
);
1512 /* be careful not overflowing */
1514 if(client
->entry
.max_life
)
1515 t
= start
+ min(t
- start
, *client
->entry
.max_life
);
1516 if(server
->entry
.max_life
)
1517 t
= start
+ min(t
- start
, *server
->entry
.max_life
);
1519 t
= min(t
, start
+ realm
->max_life
);
1522 if(f
.renewable_ok
&& et
.endtime
< *b
->till
){
1524 if(b
->rtime
== NULL
){
1528 if(*b
->rtime
< *b
->till
)
1529 *b
->rtime
= *b
->till
;
1531 if(f
.renewable
&& b
->rtime
){
1535 if(client
->entry
.max_renew
)
1536 t
= start
+ min(t
- start
, *client
->entry
.max_renew
);
1537 if(server
->entry
.max_renew
)
1538 t
= start
+ min(t
- start
, *server
->entry
.max_renew
);
1540 t
= min(t
, start
+ realm
->max_renew
);
1542 ALLOC(et
.renew_till
);
1544 et
.flags
.renewable
= 1;
1548 if (f
.request_anonymous
)
1549 et
.flags
.anonymous
= 1;
1553 copy_HostAddresses(b
->addresses
, et
.caddr
);
1556 et
.transited
.tr_type
= DOMAIN_X500_COMPRESS
;
1557 krb5_data_zero(&et
.transited
.contents
);
1559 /* The MIT ASN.1 library (obviously) doesn't tell lengths encoded
1560 * as 0 and as 0x80 (meaning indefinite length) apart, and is thus
1561 * incapable of correctly decoding SEQUENCE OF's of zero length.
1563 * To fix this, always send at least one no-op last_req
1565 * If there's a pw_end or valid_end we will use that,
1566 * otherwise just a dummy lr.
1568 ek
.last_req
.val
= malloc(2 * sizeof(*ek
.last_req
.val
));
1569 if (ek
.last_req
.val
== NULL
) {
1573 ek
.last_req
.len
= 0;
1574 if (client
->entry
.pw_end
1575 && (config
->kdc_warn_pwexpire
== 0
1576 || kdc_time
+ config
->kdc_warn_pwexpire
>= *client
->entry
.pw_end
)) {
1577 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_PW_EXPTIME
;
1578 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.pw_end
;
1581 if (client
->entry
.valid_end
) {
1582 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_ACCT_EXPTIME
;
1583 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.valid_end
;
1586 if (ek
.last_req
.len
== 0) {
1587 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_NONE
;
1588 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= 0;
1591 ek
.nonce
= b
->nonce
;
1592 if (client
->entry
.valid_end
|| client
->entry
.pw_end
) {
1593 ALLOC(ek
.key_expiration
);
1594 if (client
->entry
.valid_end
) {
1595 if (client
->entry
.pw_end
)
1596 *ek
.key_expiration
= min(*client
->entry
.valid_end
,
1597 *client
->entry
.pw_end
);
1599 *ek
.key_expiration
= *client
->entry
.valid_end
;
1601 *ek
.key_expiration
= *client
->entry
.pw_end
;
1603 ek
.key_expiration
= NULL
;
1604 ek
.flags
= et
.flags
;
1605 ek
.authtime
= et
.authtime
;
1607 ALLOC(ek
.starttime
);
1608 *ek
.starttime
= *et
.starttime
;
1610 ek
.endtime
= et
.endtime
;
1611 if (et
.renew_till
) {
1612 ALLOC(ek
.renew_till
);
1613 *ek
.renew_till
= *et
.renew_till
;
1615 copy_Realm(&rep
.ticket
.realm
, &ek
.srealm
);
1616 copy_PrincipalName(&rep
.ticket
.sname
, &ek
.sname
);
1619 copy_HostAddresses(et
.caddr
, ek
.caddr
);
1624 e_text
= "Failed to build PK-INIT reply";
1625 ret
= _kdc_pk_mk_pa_reply(context
, config
, pkp
, client
,
1626 sessionetype
, req
, req_buffer
,
1627 &reply_key
, &et
.key
, rep
.padata
);
1630 ret
= _kdc_add_inital_verified_cas(context
,
1640 ret
= krb5_generate_random_keyblock(context
, sessionetype
, &et
.key
);
1645 if (reply_key
== NULL
) {
1646 e_text
= "Client have no reply key";
1647 ret
= KRB5KDC_ERR_CLIENT_NOTYET
;
1651 ret
= copy_EncryptionKey(&et
.key
, &ek
.key
);
1655 /* Add signing of alias referral */
1656 if (f
.canonicalize
) {
1657 PA_ClientCanonicalized canon
;
1663 memset(&canon
, 0, sizeof(canon
));
1665 canon
.names
.requested_name
= *b
->cname
;
1666 canon
.names
.mapped_name
= client
->entry
.principal
->name
;
1668 ASN1_MALLOC_ENCODE(PA_ClientCanonicalizedNames
, data
.data
, data
.length
,
1669 &canon
.names
, &len
, ret
);
1672 if (data
.length
!= len
)
1673 krb5_abortx(context
, "internal asn.1 error");
1675 /* sign using "returned session key" */
1676 ret
= krb5_crypto_init(context
, &et
.key
, 0, &crypto
);
1682 ret
= krb5_create_checksum(context
, crypto
,
1683 KRB5_KU_CANONICALIZED_NAMES
, 0,
1684 data
.data
, data
.length
,
1685 &canon
.canon_checksum
);
1687 krb5_crypto_destroy(context
, crypto
);
1691 ASN1_MALLOC_ENCODE(PA_ClientCanonicalized
, data
.data
, data
.length
,
1693 free_Checksum(&canon
.canon_checksum
);
1696 if (data
.length
!= len
)
1697 krb5_abortx(context
, "internal asn.1 error");
1699 pa
.padata_type
= KRB5_PADATA_CLIENT_CANONICALIZED
;
1700 pa
.padata_value
= data
;
1701 ret
= add_METHOD_DATA(rep
.padata
, &pa
);
1707 if (rep
.padata
->len
== 0) {
1713 if (send_pac_p(context
, req
)) {
1717 ret
= _kdc_pac_generate(context
, client
, &p
);
1719 kdc_log(context
, config
, 0, "PAC generation failed for -- %s",
1724 ret
= _krb5_pac_sign(context
, p
, et
.authtime
,
1725 client
->entry
.principal
,
1726 &skey
->key
, /* Server key */
1727 &skey
->key
, /* FIXME: should be krbtgt key */
1729 krb5_pac_free(context
, p
);
1731 kdc_log(context
, config
, 0, "PAC signing failed for -- %s",
1736 ret
= _kdc_tkt_add_if_relevant_ad(context
, &et
,
1737 KRB5_AUTHDATA_WIN2K_PAC
,
1739 krb5_data_free(&data
);
1745 _kdc_log_timestamp(context
, config
, "AS-REQ", et
.authtime
, et
.starttime
,
1746 et
.endtime
, et
.renew_till
);
1748 /* do this as the last thing since this signs the EncTicketPart */
1749 ret
= _kdc_add_KRB5SignedPath(context
,
1753 client
->entry
.principal
,
1760 log_as_req(context
, config
, reply_key
->keytype
, setype
, b
);
1762 ret
= _kdc_encode_reply(context
, config
,
1763 &rep
, &et
, &ek
, setype
, server
->entry
.kvno
,
1764 &skey
->key
, client
->entry
.kvno
,
1765 reply_key
, 0, &e_text
, reply
);
1766 free_EncTicketPart(&et
);
1767 free_EncKDCRepPart(&ek
);
1772 if (datagram_reply
&& reply
->length
> config
->max_datagram_reply_length
) {
1773 krb5_data_free(reply
);
1774 ret
= KRB5KRB_ERR_RESPONSE_TOO_BIG
;
1775 e_text
= "Reply packet too large";
1781 krb5_mk_error(context
,
1784 (e_data
.data
? &e_data
: NULL
),
1794 _kdc_pk_free_client_param(context
, pkp
);
1799 krb5_free_principal(context
, client_princ
);
1802 krb5_free_principal(context
, server_princ
);
1805 _kdc_free_ent(context
, client
);
1807 _kdc_free_ent(context
, server
);
1812 * Add the AuthorizationData `data´ of `type´ to the last element in
1813 * the sequence of authorization_data in `tkt´ wrapped in an IF_RELEVANT
1817 _kdc_tkt_add_if_relevant_ad(krb5_context context
,
1820 const krb5_data
*data
)
1822 krb5_error_code ret
;
1825 if (tkt
->authorization_data
== NULL
) {
1826 tkt
->authorization_data
= calloc(1, sizeof(*tkt
->authorization_data
));
1827 if (tkt
->authorization_data
== NULL
) {
1828 krb5_set_error_message(context
, ENOMEM
, "out of memory");
1833 /* add the entry to the last element */
1835 AuthorizationData ad
= { 0, NULL
};
1836 AuthorizationDataElement ade
;
1839 ade
.ad_data
= *data
;
1841 ret
= add_AuthorizationData(&ad
, &ade
);
1843 krb5_set_error_message(context
, ret
, "add AuthorizationData failed");
1847 ade
.ad_type
= KRB5_AUTHDATA_IF_RELEVANT
;
1849 ASN1_MALLOC_ENCODE(AuthorizationData
,
1850 ade
.ad_data
.data
, ade
.ad_data
.length
,
1852 free_AuthorizationData(&ad
);
1854 krb5_set_error_message(context
, ret
, "ASN.1 encode of "
1855 "AuthorizationData failed");
1858 if (ade
.ad_data
.length
!= size
)
1859 krb5_abortx(context
, "internal asn.1 encoder error");
1861 ret
= add_AuthorizationData(tkt
->authorization_data
, &ade
);
1862 der_free_octet_string(&ade
.ad_data
);
1864 krb5_set_error_message(context
, ret
, "add AuthorizationData failed");