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 __RCSID("$Heimdal: kerberos5.c 22071 2007-11-14 20:04:50Z lha $"
39 #define MAX_TIME ((time_t)((1U << 31) - 1))
42 _kdc_fix_time(time_t **t
)
48 if(**t
== 0) **t
= MAX_TIME
; /* fix for old clients */
52 realloc_method_data(METHOD_DATA
*md
)
55 pa
= realloc(md
->val
, (md
->len
+ 1) * sizeof(*md
->val
));
64 set_salt_padata (METHOD_DATA
*md
, Salt
*salt
)
67 realloc_method_data(md
);
68 md
->val
[md
->len
- 1].padata_type
= salt
->type
;
69 der_copy_octet_string(&salt
->salt
,
70 &md
->val
[md
->len
- 1].padata_value
);
75 _kdc_find_padata(const KDC_REQ
*req
, int *start
, int type
)
77 if (req
->padata
== NULL
)
80 while(*start
< req
->padata
->len
){
82 if(req
->padata
->val
[*start
- 1].padata_type
== type
)
83 return &req
->padata
->val
[*start
- 1];
89 * Detect if `key' is the using the the precomputed `default_salt'.
93 is_default_salt_p(const krb5_salt
*default_salt
, const Key
*key
)
95 if (key
->salt
== NULL
)
97 if (default_salt
->salttype
!= key
->salt
->type
)
99 if (krb5_data_cmp(&default_salt
->saltvalue
, &key
->salt
->salt
))
105 * return the first appropriate key of `princ' in `ret_key'. Look for
106 * all the etypes in (`etypes', `len'), stopping as soon as we find
107 * one, but preferring one that has default salt
111 _kdc_find_etype(krb5_context context
, const hdb_entry_ex
*princ
,
112 krb5_enctype
*etypes
, unsigned len
,
113 Key
**ret_key
, krb5_enctype
*ret_etype
)
116 krb5_error_code ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
119 krb5_get_pw_salt (context
, princ
->entry
.principal
, &def_salt
);
121 for(i
= 0; ret
!= 0 && i
< len
; i
++) {
124 if (krb5_enctype_valid(context
, etypes
[i
]) != 0)
127 while (hdb_next_enctype2key(context
, &princ
->entry
, etypes
[i
], &key
) == 0) {
128 if (key
->key
.keyvalue
.length
== 0) {
129 ret
= KRB5KDC_ERR_NULL_KEY
;
133 *ret_etype
= etypes
[i
];
135 if (is_default_salt_p(&def_salt
, key
)) {
136 krb5_free_salt (context
, def_salt
);
141 krb5_free_salt (context
, def_salt
);
146 _kdc_make_anonymous_principalname (PrincipalName
*pn
)
148 pn
->name_type
= KRB5_NT_PRINCIPAL
;
149 pn
->name_string
.len
= 1;
150 pn
->name_string
.val
= malloc(sizeof(*pn
->name_string
.val
));
151 if (pn
->name_string
.val
== NULL
)
153 pn
->name_string
.val
[0] = strdup("anonymous");
154 if (pn
->name_string
.val
[0] == NULL
) {
155 free(pn
->name_string
.val
);
156 pn
->name_string
.val
= NULL
;
163 _kdc_log_timestamp(krb5_context context
,
164 krb5_kdc_configuration
*config
,
166 KerberosTime authtime
, KerberosTime
*starttime
,
167 KerberosTime endtime
, KerberosTime
*renew_till
)
169 char authtime_str
[100], starttime_str
[100],
170 endtime_str
[100], renewtime_str
[100];
172 krb5_format_time(context
, authtime
,
173 authtime_str
, sizeof(authtime_str
), TRUE
);
175 krb5_format_time(context
, *starttime
,
176 starttime_str
, sizeof(starttime_str
), TRUE
);
178 strlcpy(starttime_str
, "unset", sizeof(starttime_str
));
179 krb5_format_time(context
, endtime
,
180 endtime_str
, sizeof(endtime_str
), TRUE
);
182 krb5_format_time(context
, *renew_till
,
183 renewtime_str
, sizeof(renewtime_str
), TRUE
);
185 strlcpy(renewtime_str
, "unset", sizeof(renewtime_str
));
187 kdc_log(context
, config
, 5,
188 "%s authtime: %s starttime: %s endtime: %s renew till: %s",
189 type
, authtime_str
, starttime_str
, endtime_str
, renewtime_str
);
193 log_patypes(krb5_context context
,
194 krb5_kdc_configuration
*config
,
197 struct rk_strpool
*p
= NULL
;
201 for (i
= 0; i
< padata
->len
; i
++) {
202 switch(padata
->val
[i
].padata_type
) {
203 case KRB5_PADATA_PK_AS_REQ
:
204 p
= rk_strpoolprintf(p
, "PK-INIT(ietf)");
206 case KRB5_PADATA_PK_AS_REQ_WIN
:
207 p
= rk_strpoolprintf(p
, "PK-INIT(win2k)");
209 case KRB5_PADATA_PA_PK_OCSP_RESPONSE
:
210 p
= rk_strpoolprintf(p
, "OCSP");
212 case KRB5_PADATA_ENC_TIMESTAMP
:
213 p
= rk_strpoolprintf(p
, "encrypted-timestamp");
216 p
= rk_strpoolprintf(p
, "%d", padata
->val
[i
].padata_type
);
219 if (p
&& i
+ 1 < padata
->len
)
220 p
= rk_strpoolprintf(p
, ", ");
222 kdc_log(context
, config
, 0, "out of memory");
227 p
= rk_strpoolprintf(p
, "none");
229 str
= rk_strpoolcollect(p
);
230 kdc_log(context
, config
, 0, "Client sent patypes: %s", str
);
240 _kdc_encode_reply(krb5_context context
,
241 krb5_kdc_configuration
*config
,
242 KDC_REP
*rep
, const EncTicketPart
*et
, EncKDCRepPart
*ek
,
244 int skvno
, const EncryptionKey
*skey
,
245 int ckvno
, const EncryptionKey
*ckey
,
255 ASN1_MALLOC_ENCODE(EncTicketPart
, buf
, buf_size
, et
, &len
, ret
);
257 kdc_log(context
, config
, 0, "Failed to encode ticket: %s",
258 krb5_get_err_text(context
, ret
));
261 if(buf_size
!= len
) {
263 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
264 *e_text
= "KDC internal error";
265 return KRB5KRB_ERR_GENERIC
;
268 ret
= krb5_crypto_init(context
, skey
, etype
, &crypto
);
271 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s",
272 krb5_get_err_text(context
, ret
));
276 ret
= krb5_encrypt_EncryptedData(context
,
282 &rep
->ticket
.enc_part
);
284 krb5_crypto_destroy(context
, crypto
);
286 kdc_log(context
, config
, 0, "Failed to encrypt data: %s",
287 krb5_get_err_text(context
, ret
));
291 if(rep
->msg_type
== krb_as_rep
&& !config
->encode_as_rep_as_tgs_rep
)
292 ASN1_MALLOC_ENCODE(EncASRepPart
, buf
, buf_size
, ek
, &len
, ret
);
294 ASN1_MALLOC_ENCODE(EncTGSRepPart
, buf
, buf_size
, ek
, &len
, ret
);
296 kdc_log(context
, config
, 0, "Failed to encode KDC-REP: %s",
297 krb5_get_err_text(context
, ret
));
300 if(buf_size
!= len
) {
302 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
303 *e_text
= "KDC internal error";
304 return KRB5KRB_ERR_GENERIC
;
306 ret
= krb5_crypto_init(context
, ckey
, 0, &crypto
);
309 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s",
310 krb5_get_err_text(context
, ret
));
313 if(rep
->msg_type
== krb_as_rep
) {
314 krb5_encrypt_EncryptedData(context
,
316 KRB5_KU_AS_REP_ENC_PART
,
322 ASN1_MALLOC_ENCODE(AS_REP
, buf
, buf_size
, rep
, &len
, ret
);
324 krb5_encrypt_EncryptedData(context
,
326 KRB5_KU_TGS_REP_ENC_PART_SESSION
,
332 ASN1_MALLOC_ENCODE(TGS_REP
, buf
, buf_size
, rep
, &len
, ret
);
334 krb5_crypto_destroy(context
, crypto
);
336 kdc_log(context
, config
, 0, "Failed to encode KDC-REP: %s",
337 krb5_get_err_text(context
, ret
));
340 if(buf_size
!= len
) {
342 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
343 *e_text
= "KDC internal error";
344 return KRB5KRB_ERR_GENERIC
;
347 reply
->length
= buf_size
;
352 * Return 1 if the client have only older enctypes, this is for
353 * determining if the server should send ETYPE_INFO2 or not.
357 older_enctype(krb5_enctype enctype
)
360 case ETYPE_DES_CBC_CRC
:
361 case ETYPE_DES_CBC_MD4
:
362 case ETYPE_DES_CBC_MD5
:
363 case ETYPE_DES3_CBC_SHA1
:
364 case ETYPE_ARCFOUR_HMAC_MD5
:
365 case ETYPE_ARCFOUR_HMAC_MD5_56
:
367 * The following three is "old" windows enctypes and is needed for
368 * windows 2000 hosts.
370 case ETYPE_ARCFOUR_MD4
:
371 case ETYPE_ARCFOUR_HMAC_OLD
:
372 case ETYPE_ARCFOUR_HMAC_OLD_EXP
:
380 only_older_enctype_p(const KDC_REQ
*req
)
384 for(i
= 0; i
< req
->req_body
.etype
.len
; i
++) {
385 if (!older_enctype(req
->req_body
.etype
.val
[i
]))
395 static krb5_error_code
396 make_etype_info_entry(krb5_context context
, ETYPE_INFO_ENTRY
*ent
, Key
*key
)
398 ent
->etype
= key
->key
.keytype
;
401 ALLOC(ent
->salttype
);
403 if(key
->salt
->type
== hdb_pw_salt
)
404 *ent
->salttype
= 0; /* or 1? or NULL? */
405 else if(key
->salt
->type
== hdb_afs3_salt
)
408 kdc_log(context
, config
, 0, "unknown salt-type: %d",
410 return KRB5KRB_ERR_GENERIC
;
412 /* according to `the specs', we can't send a salt if
413 we have AFS3 salted key, but that requires that you
414 *know* what cell you are using (e.g by assuming
415 that the cell is the same as the realm in lower
418 ALLOC(ent
->salttype
);
419 *ent
->salttype
= key
->salt
->type
;
422 * We shouldn't sent salttype since it is incompatible with the
423 * specification and it breaks windows clients. The afs
424 * salting problem is solved by using KRB5-PADATA-AFS3-SALT
425 * implemented in Heimdal 0.7 and later.
427 ent
->salttype
= NULL
;
429 krb5_copy_data(context
, &key
->salt
->salt
,
432 /* we return no salt type at all, as that should indicate
433 * the default salt type and make everybody happy. some
434 * systems (like w2k) dislike being told the salt type
437 ent
->salttype
= NULL
;
443 static krb5_error_code
444 get_pa_etype_info(krb5_context context
,
445 krb5_kdc_configuration
*config
,
446 METHOD_DATA
*md
, hdb_entry
*client
,
447 ENCTYPE
*etypes
, unsigned int etypes_len
)
449 krb5_error_code ret
= 0;
457 pa
.len
= client
->keys
.len
;
458 if(pa
.len
> UINT_MAX
/sizeof(*pa
.val
))
460 pa
.val
= malloc(pa
.len
* sizeof(*pa
.val
));
463 memset(pa
.val
, 0, pa
.len
* sizeof(*pa
.val
));
465 for(i
= 0; i
< client
->keys
.len
; i
++) {
466 for (j
= 0; j
< n
; j
++)
467 if (pa
.val
[j
].etype
== client
->keys
.val
[i
].key
.keytype
)
469 for(j
= 0; j
< etypes_len
; j
++) {
470 if(client
->keys
.val
[i
].key
.keytype
== etypes
[j
]) {
471 if (krb5_enctype_valid(context
, etypes
[j
]) != 0)
473 if (!older_enctype(etypes
[j
]))
476 krb5_abortx(context
, "internal error: n >= p.len");
477 if((ret
= make_etype_info_entry(context
,
479 &client
->keys
.val
[i
])) != 0) {
480 free_ETYPE_INFO(&pa
);
488 for(i
= 0; i
< client
->keys
.len
; i
++) {
490 for(j
= 0; j
< etypes_len
; j
++) {
491 if(client
->keys
.val
[i
].key
.keytype
== etypes
[j
])
494 if (krb5_enctype_valid(context
, client
->keys
.val
[i
].key
.keytype
) != 0)
496 if (!older_enctype(etypes
[j
]))
499 krb5_abortx(context
, "internal error: n >= p.len");
500 if((ret
= make_etype_info_entry(context
,
502 &client
->keys
.val
[i
])) != 0) {
503 free_ETYPE_INFO(&pa
);
510 /* stripped out dups, newer enctypes, and not valid enctypes */
514 ASN1_MALLOC_ENCODE(ETYPE_INFO
, buf
, len
, &pa
, &len
, ret
);
515 free_ETYPE_INFO(&pa
);
518 ret
= realloc_method_data(md
);
523 md
->val
[md
->len
- 1].padata_type
= KRB5_PADATA_ETYPE_INFO
;
524 md
->val
[md
->len
- 1].padata_value
.length
= len
;
525 md
->val
[md
->len
- 1].padata_value
.data
= buf
;
533 extern int _krb5_AES_string_to_default_iterator
;
535 static krb5_error_code
536 make_etype_info2_entry(ETYPE_INFO2_ENTRY
*ent
, Key
*key
)
538 ent
->etype
= key
->key
.keytype
;
541 if (ent
->salt
== NULL
)
543 *ent
->salt
= malloc(key
->salt
->salt
.length
+ 1);
544 if (*ent
->salt
== NULL
) {
549 memcpy(*ent
->salt
, key
->salt
->salt
.data
, key
->salt
->salt
.length
);
550 (*ent
->salt
)[key
->salt
->salt
.length
] = '\0';
554 ent
->s2kparams
= NULL
;
556 switch (key
->key
.keytype
) {
557 case ETYPE_AES128_CTS_HMAC_SHA1_96
:
558 case ETYPE_AES256_CTS_HMAC_SHA1_96
:
559 ALLOC(ent
->s2kparams
);
560 if (ent
->s2kparams
== NULL
)
562 ent
->s2kparams
->length
= 4;
563 ent
->s2kparams
->data
= malloc(ent
->s2kparams
->length
);
564 if (ent
->s2kparams
->data
== NULL
) {
565 free(ent
->s2kparams
);
566 ent
->s2kparams
= NULL
;
569 _krb5_put_int(ent
->s2kparams
->data
,
570 _krb5_AES_string_to_default_iterator
,
571 ent
->s2kparams
->length
);
573 case ETYPE_DES_CBC_CRC
:
574 case ETYPE_DES_CBC_MD4
:
575 case ETYPE_DES_CBC_MD5
:
576 /* Check if this was a AFS3 salted key */
577 if(key
->salt
&& key
->salt
->type
== hdb_afs3_salt
){
578 ALLOC(ent
->s2kparams
);
579 if (ent
->s2kparams
== NULL
)
581 ent
->s2kparams
->length
= 1;
582 ent
->s2kparams
->data
= malloc(ent
->s2kparams
->length
);
583 if (ent
->s2kparams
->data
== NULL
) {
584 free(ent
->s2kparams
);
585 ent
->s2kparams
= NULL
;
588 _krb5_put_int(ent
->s2kparams
->data
,
590 ent
->s2kparams
->length
);
600 * Return an ETYPE-INFO2. Enctypes are storted the same way as in the
601 * database (client supported enctypes first, then the unsupported
605 static krb5_error_code
606 get_pa_etype_info2(krb5_context context
,
607 krb5_kdc_configuration
*config
,
608 METHOD_DATA
*md
, hdb_entry
*client
,
609 ENCTYPE
*etypes
, unsigned int etypes_len
)
611 krb5_error_code ret
= 0;
618 pa
.len
= client
->keys
.len
;
619 if(pa
.len
> UINT_MAX
/sizeof(*pa
.val
))
621 pa
.val
= malloc(pa
.len
* sizeof(*pa
.val
));
624 memset(pa
.val
, 0, pa
.len
* sizeof(*pa
.val
));
626 for(i
= 0; i
< client
->keys
.len
; i
++) {
627 for (j
= 0; j
< n
; j
++)
628 if (pa
.val
[j
].etype
== client
->keys
.val
[i
].key
.keytype
)
630 for(j
= 0; j
< etypes_len
; j
++) {
631 if(client
->keys
.val
[i
].key
.keytype
== etypes
[j
]) {
632 if (krb5_enctype_valid(context
, etypes
[j
]) != 0)
635 krb5_abortx(context
, "internal error: n >= p.len");
636 if((ret
= make_etype_info2_entry(&pa
.val
[n
++],
637 &client
->keys
.val
[i
])) != 0) {
638 free_ETYPE_INFO2(&pa
);
646 /* send enctypes that the client doesn't know about too */
647 for(i
= 0; i
< client
->keys
.len
; i
++) {
649 for(j
= 0; j
< etypes_len
; j
++) {
650 if(client
->keys
.val
[i
].key
.keytype
== etypes
[j
])
653 if (krb5_enctype_valid(context
, client
->keys
.val
[i
].key
.keytype
) != 0)
656 krb5_abortx(context
, "internal error: n >= p.len");
657 if((ret
= make_etype_info2_entry(&pa
.val
[n
++],
658 &client
->keys
.val
[i
])) != 0) {
659 free_ETYPE_INFO2(&pa
);
666 /* stripped out dups, and not valid enctypes */
670 ASN1_MALLOC_ENCODE(ETYPE_INFO2
, buf
, len
, &pa
, &len
, ret
);
671 free_ETYPE_INFO2(&pa
);
674 ret
= realloc_method_data(md
);
679 md
->val
[md
->len
- 1].padata_type
= KRB5_PADATA_ETYPE_INFO2
;
680 md
->val
[md
->len
- 1].padata_value
.length
= len
;
681 md
->val
[md
->len
- 1].padata_value
.data
= buf
;
690 log_as_req(krb5_context context
,
691 krb5_kdc_configuration
*config
,
694 const KDC_REQ_BODY
*b
)
697 struct rk_strpool
*p
= NULL
;
701 for (i
= 0; i
< b
->etype
.len
; i
++) {
702 ret
= krb5_enctype_to_string(context
, b
->etype
.val
[i
], &str
);
704 p
= rk_strpoolprintf(p
, "%s", str
);
707 p
= rk_strpoolprintf(p
, "%d", b
->etype
.val
[i
]);
708 if (p
&& i
+ 1 < b
->etype
.len
)
709 p
= rk_strpoolprintf(p
, ", ");
711 kdc_log(context
, config
, 0, "out of memory");
716 p
= rk_strpoolprintf(p
, "no encryption types");
718 str
= rk_strpoolcollect(p
);
719 kdc_log(context
, config
, 0, "Client supported enctypes: %s", str
);
726 ret
= krb5_enctype_to_string(context
, cetype
, &cet
);
728 ret
= krb5_enctype_to_string(context
, setype
, &set
);
730 kdc_log(context
, config
, 5, "Using %s/%s", cet
, set
);
736 kdc_log(context
, config
, 5, "Using e-types %d/%d", cetype
, setype
);
741 unparse_flags(KDCOptions2int(b
->kdc_options
), asn1_KDCOptions_units(),
742 fixedstr
, sizeof(fixedstr
));
744 kdc_log(context
, config
, 2, "Requested flags: %s", fixedstr
);
749 * verify the flags on `client' and `server', returning 0
750 * if they are OK and generating an error messages and returning
751 * and error code otherwise.
755 _kdc_check_flags(krb5_context context
,
756 krb5_kdc_configuration
*config
,
757 hdb_entry_ex
*client_ex
, const char *client_name
,
758 hdb_entry_ex
*server_ex
, const char *server_name
,
759 krb5_boolean is_as_req
)
761 if(client_ex
!= NULL
) {
762 hdb_entry
*client
= &client_ex
->entry
;
765 if (client
->flags
.invalid
) {
766 kdc_log(context
, config
, 0,
767 "Client (%s) has invalid bit set", client_name
);
768 return KRB5KDC_ERR_POLICY
;
771 if(!client
->flags
.client
){
772 kdc_log(context
, config
, 0,
773 "Principal may not act as client -- %s", client_name
);
774 return KRB5KDC_ERR_POLICY
;
777 if (client
->valid_start
&& *client
->valid_start
> kdc_time
) {
778 char starttime_str
[100];
779 krb5_format_time(context
, *client
->valid_start
,
780 starttime_str
, sizeof(starttime_str
), TRUE
);
781 kdc_log(context
, config
, 0,
782 "Client not yet valid until %s -- %s",
783 starttime_str
, client_name
);
784 return KRB5KDC_ERR_CLIENT_NOTYET
;
787 if (client
->valid_end
&& *client
->valid_end
< kdc_time
) {
788 char endtime_str
[100];
789 krb5_format_time(context
, *client
->valid_end
,
790 endtime_str
, sizeof(endtime_str
), TRUE
);
791 kdc_log(context
, config
, 0,
792 "Client expired at %s -- %s",
793 endtime_str
, client_name
);
794 return KRB5KDC_ERR_NAME_EXP
;
797 if (client
->pw_end
&& *client
->pw_end
< kdc_time
798 && (server_ex
== NULL
|| !server_ex
->entry
.flags
.change_pw
)) {
800 krb5_format_time(context
, *client
->pw_end
,
801 pwend_str
, sizeof(pwend_str
), TRUE
);
802 kdc_log(context
, config
, 0,
803 "Client's key has expired at %s -- %s",
804 pwend_str
, client_name
);
805 return KRB5KDC_ERR_KEY_EXPIRED
;
811 if (server_ex
!= NULL
) {
812 hdb_entry
*server
= &server_ex
->entry
;
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
)
920 PA_PAC_REQUEST pacreq
;
924 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PA_PAC_REQUEST
);
928 ret
= decode_PA_PAC_REQUEST(pa
->padata_value
.data
,
929 pa
->padata_value
.length
,
934 i
= pacreq
.include_pac
;
935 free_PA_PAC_REQUEST(&pacreq
);
946 _kdc_as_rep(krb5_context context
,
947 krb5_kdc_configuration
*config
,
949 const krb5_data
*req_buffer
,
952 struct sockaddr
*from_addr
,
955 KDC_REQ_BODY
*b
= &req
->req_body
;
957 KDCOptions f
= b
->kdc_options
;
958 hdb_entry_ex
*client
= NULL
, *server
= NULL
;
959 krb5_enctype cetype
, setype
, sessionetype
;
963 krb5_principal client_princ
= NULL
, server_princ
= NULL
;
964 char *client_name
= NULL
, *server_name
= NULL
;
965 krb5_error_code ret
= 0;
966 const char *e_text
= NULL
;
969 EncryptionKey
*reply_key
;
972 pk_client_params
*pkp
= NULL
;
975 memset(&rep
, 0, sizeof(rep
));
976 krb5_data_zero(&e_data
);
979 flags
|= HDB_F_CANON
;
981 if(b
->sname
== NULL
){
982 ret
= KRB5KRB_ERR_GENERIC
;
983 e_text
= "No server in request";
985 ret
= _krb5_principalname2krb5_principal (context
,
990 ret
= krb5_unparse_name(context
, server_princ
, &server_name
);
993 kdc_log(context
, config
, 0,
994 "AS-REQ malformed server name from %s", from
);
998 if(b
->cname
== NULL
){
999 ret
= KRB5KRB_ERR_GENERIC
;
1000 e_text
= "No client in request";
1003 if (b
->cname
->name_type
== KRB5_NT_ENTERPRISE_PRINCIPAL
) {
1004 if (b
->cname
->name_string
.len
!= 1) {
1005 kdc_log(context
, config
, 0,
1006 "AS-REQ malformed canon request from %s, "
1007 "enterprise name with %d name components",
1008 from
, b
->cname
->name_string
.len
);
1009 ret
= KRB5_PARSE_MALFORMED
;
1012 ret
= krb5_parse_name(context
, b
->cname
->name_string
.val
[0],
1017 ret
= _krb5_principalname2krb5_principal (context
,
1024 ret
= krb5_unparse_name(context
, client_princ
, &client_name
);
1027 kdc_log(context
, config
, 0,
1028 "AS-REQ malformed client name from %s", from
);
1032 kdc_log(context
, config
, 0, "AS-REQ %s from %s for %s",
1033 client_name
, from
, server_name
);
1035 ret
= _kdc_db_fetch(context
, config
, client_princ
,
1036 HDB_F_GET_CLIENT
| flags
, NULL
, &client
);
1038 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", client_name
,
1039 krb5_get_err_text(context
, ret
));
1040 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
1044 ret
= _kdc_db_fetch(context
, config
, server_princ
,
1045 HDB_F_GET_SERVER
|HDB_F_GET_KRBTGT
,
1048 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", server_name
,
1049 krb5_get_err_text(context
, ret
));
1050 ret
= KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN
;
1054 ret
= _kdc_windc_client_access(context
, client
, req
);
1058 ret
= _kdc_check_flags(context
, config
,
1059 client
, client_name
,
1060 server
, server_name
,
1065 memset(&et
, 0, sizeof(et
));
1066 memset(&ek
, 0, sizeof(ek
));
1073 log_patypes(context
, config
, req
->padata
);
1076 kdc_log(context
, config
, 5,
1077 "Looking for PKINIT pa-data -- %s", client_name
);
1079 e_text
= "No PKINIT PA found";
1082 if ((pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ
)))
1086 if((pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ_WIN
)))
1090 char *client_cert
= NULL
;
1092 ret
= _kdc_pk_rd_padata(context
, config
, req
, pa
, &pkp
);
1094 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1095 kdc_log(context
, config
, 5,
1096 "Failed to decode PKINIT PA-DATA -- %s",
1100 if (ret
== 0 && pkp
== NULL
)
1103 ret
= _kdc_pk_check_client(context
,
1109 e_text
= "PKINIT certificate not allowed to "
1110 "impersonate principal";
1111 _kdc_pk_free_client_param(context
, pkp
);
1113 kdc_log(context
, config
, 0, "%s", e_text
);
1118 et
.flags
.pre_authent
= 1;
1119 kdc_log(context
, config
, 0,
1120 "PKINIT pre-authentication succeeded -- %s using %s",
1121 client_name
, client_cert
);
1128 kdc_log(context
, config
, 5, "Looking for ENC-TS pa-data -- %s",
1132 e_text
= "No ENC-TS found";
1133 while((pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_ENC_TIMESTAMP
))){
1137 EncryptedData enc_data
;
1143 ret
= decode_EncryptedData(pa
->padata_value
.data
,
1144 pa
->padata_value
.length
,
1148 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1149 kdc_log(context
, config
, 5, "Failed to decode PA-DATA -- %s",
1154 ret
= hdb_enctype2key(context
, &client
->entry
,
1155 enc_data
.etype
, &pa_key
);
1158 e_text
= "No key matches pa-data";
1159 ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
1160 if(krb5_enctype_to_string(context
, enc_data
.etype
, &estr
))
1163 kdc_log(context
, config
, 5,
1164 "No client key matching pa-data (%d) -- %s",
1165 enc_data
.etype
, client_name
);
1167 kdc_log(context
, config
, 5,
1168 "No client key matching pa-data (%s) -- %s",
1172 free_EncryptedData(&enc_data
);
1177 ret
= krb5_crypto_init(context
, &pa_key
->key
, 0, &crypto
);
1179 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s",
1180 krb5_get_err_text(context
, ret
));
1181 free_EncryptedData(&enc_data
);
1185 ret
= krb5_decrypt_EncryptedData (context
,
1187 KRB5_KU_PA_ENC_TIMESTAMP
,
1190 krb5_crypto_destroy(context
, crypto
);
1192 krb5_error_code ret2
;
1193 ret2
= krb5_enctype_to_string(context
,
1194 pa_key
->key
.keytype
, &str
);
1197 kdc_log(context
, config
, 5,
1198 "Failed to decrypt PA-DATA -- %s "
1199 "(enctype %s) error %s",
1201 str
? str
: "unknown enctype",
1202 krb5_get_err_text(context
, ret
));
1205 if(hdb_next_enctype2key(context
, &client
->entry
,
1206 enc_data
.etype
, &pa_key
) == 0)
1208 e_text
= "Failed to decrypt PA-DATA";
1210 free_EncryptedData(&enc_data
);
1211 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1214 free_EncryptedData(&enc_data
);
1215 ret
= decode_PA_ENC_TS_ENC(ts_data
.data
,
1219 krb5_data_free(&ts_data
);
1221 e_text
= "Failed to decode PA-ENC-TS-ENC";
1222 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1223 kdc_log(context
, config
,
1224 5, "Failed to decode PA-ENC-TS_ENC -- %s",
1228 free_PA_ENC_TS_ENC(&p
);
1229 if (abs(kdc_time
- p
.patimestamp
) > context
->max_skew
) {
1230 char client_time
[100];
1232 krb5_format_time(context
, p
.patimestamp
,
1233 client_time
, sizeof(client_time
), TRUE
);
1235 ret
= KRB5KRB_AP_ERR_SKEW
;
1236 kdc_log(context
, config
, 0,
1237 "Too large time skew, "
1238 "client time %s is out by %u > %u seconds -- %s",
1240 (unsigned)abs(kdc_time
- p
.patimestamp
),
1244 /* This code is from samba, needs testing */
1246 * the following is needed to make windows clients
1247 * to retry using the timestamp in the error message
1249 * this is maybe a bug in windows to not trying when e_text
1254 e_text
= "Too large time skew";
1258 et
.flags
.pre_authent
= 1;
1260 ret
= krb5_enctype_to_string(context
,pa_key
->key
.keytype
, &str
);
1264 kdc_log(context
, config
, 2,
1265 "ENC-TS Pre-authentication succeeded -- %s using %s",
1266 client_name
, str
? str
: "unknown enctype");
1273 if(found_pa
== 0 && config
->require_preauth
)
1275 /* We come here if we found a pa-enc-timestamp, but if there
1276 was some problem with it, other than too large skew */
1277 if(found_pa
&& et
.flags
.pre_authent
== 0){
1278 kdc_log(context
, config
, 0, "%s -- %s", e_text
, client_name
);
1282 }else if (config
->require_preauth
1283 || client
->entry
.flags
.require_preauth
1284 || server
->entry
.flags
.require_preauth
) {
1285 METHOD_DATA method_data
;
1291 method_data
.len
= 0;
1292 method_data
.val
= NULL
;
1294 ret
= realloc_method_data(&method_data
);
1295 pa
= &method_data
.val
[method_data
.len
-1];
1296 pa
->padata_type
= KRB5_PADATA_ENC_TIMESTAMP
;
1297 pa
->padata_value
.length
= 0;
1298 pa
->padata_value
.data
= NULL
;
1301 ret
= realloc_method_data(&method_data
);
1302 pa
= &method_data
.val
[method_data
.len
-1];
1303 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ
;
1304 pa
->padata_value
.length
= 0;
1305 pa
->padata_value
.data
= NULL
;
1307 ret
= realloc_method_data(&method_data
);
1308 pa
= &method_data
.val
[method_data
.len
-1];
1309 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ_WIN
;
1310 pa
->padata_value
.length
= 0;
1311 pa
->padata_value
.data
= NULL
;
1316 * - If the client only knows about old enctypes, then send
1317 * both info replies (we send 'info' first in the list).
1318 * - If the client is 'modern', because it knows about 'new'
1319 * enctype types, then only send the 'info2' reply.
1323 if (only_older_enctype_p(req
))
1324 ret
= get_pa_etype_info(context
, config
,
1325 &method_data
, &client
->entry
,
1326 b
->etype
.val
, b
->etype
.len
);
1328 ret
= get_pa_etype_info2(context
, config
, &method_data
,
1329 &client
->entry
, b
->etype
.val
, b
->etype
.len
);
1332 ASN1_MALLOC_ENCODE(METHOD_DATA
, buf
, len
, &method_data
, &len
, ret
);
1333 free_METHOD_DATA(&method_data
);
1336 e_data
.length
= len
;
1337 e_text
="Need to use PA-ENC-TIMESTAMP/PA-PK-AS-REQ",
1339 ret
= KRB5KDC_ERR_PREAUTH_REQUIRED
;
1341 kdc_log(context
, config
, 0,
1342 "No preauth found, returning PREAUTH-REQUIRED -- %s",
1348 * Find the client key (for preauth ENC-TS verification and reply
1349 * encryption). Then the best encryption type for the KDC and
1350 * last the best session key that shared between the client and
1351 * KDC runtime enctypes.
1354 ret
= _kdc_find_etype(context
, client
, b
->etype
.val
, b
->etype
.len
,
1357 kdc_log(context
, config
, 0,
1358 "Client (%s) has no support for etypes", client_name
);
1362 ret
= _kdc_get_preferred_key(context
, config
,
1363 server
, server_name
,
1369 * Select a session enctype from the list of the crypto systems
1370 * supported enctype, is supported by the client and is one of the
1371 * enctype of the enctype of the krbtgt.
1373 * The later is used as a hint what enctype all KDC are supporting
1374 * to make sure a newer version of KDC wont generate a session
1375 * enctype that and older version of a KDC in the same realm can't
1378 * But if the KDC admin is paranoid and doesn't want to have "no
1379 * the best" enctypes on the krbtgt, lets save the best pick from
1380 * the client list and hope that that will work for any other
1384 const krb5_enctype
*p
;
1385 krb5_enctype clientbest
= ETYPE_NULL
;
1388 p
= krb5_kerberos_enctypes(context
);
1390 sessionetype
= ETYPE_NULL
;
1392 for (i
= 0; p
[i
] != ETYPE_NULL
&& sessionetype
== ETYPE_NULL
; i
++) {
1393 if (krb5_enctype_valid(context
, p
[i
]) != 0)
1396 for (j
= 0; j
< b
->etype
.len
&& sessionetype
== ETYPE_NULL
; j
++) {
1398 /* check with client */
1399 if (p
[i
] != b
->etype
.val
[j
])
1401 /* save best of union of { client, crypto system } */
1402 if (clientbest
== ETYPE_NULL
)
1404 /* check with krbtgt */
1405 ret
= hdb_enctype2key(context
, &server
->entry
, p
[i
], &dummy
);
1408 sessionetype
= p
[i
];
1411 /* if krbtgt had no shared keys with client, pick clients best */
1412 if (clientbest
!= ETYPE_NULL
&& sessionetype
== ETYPE_NULL
) {
1413 sessionetype
= clientbest
;
1414 } else if (sessionetype
== ETYPE_NULL
) {
1415 kdc_log(context
, config
, 0,
1416 "Client (%s) from %s has no common enctypes with KDC"
1417 "to use for the session key",
1423 log_as_req(context
, config
, cetype
, setype
, b
);
1425 if(f
.renew
|| f
.validate
|| f
.proxy
|| f
.forwarded
|| f
.enc_tkt_in_skey
1426 || (f
.request_anonymous
&& !config
->allow_anonymous
)) {
1427 ret
= KRB5KDC_ERR_BADOPTION
;
1428 kdc_log(context
, config
, 0, "Bad KDC options -- %s", client_name
);
1433 rep
.msg_type
= krb_as_rep
;
1434 copy_Realm(&client
->entry
.principal
->realm
, &rep
.crealm
);
1435 if (f
.request_anonymous
)
1436 _kdc_make_anonymous_principalname (&rep
.cname
);
1438 _krb5_principal2principalname(&rep
.cname
,
1439 client
->entry
.principal
);
1440 rep
.ticket
.tkt_vno
= 5;
1441 copy_Realm(&server
->entry
.principal
->realm
, &rep
.ticket
.realm
);
1442 _krb5_principal2principalname(&rep
.ticket
.sname
,
1443 server
->entry
.principal
);
1444 /* java 1.6 expects the name to be the same type, lets allow that
1445 * uncomplicated name-types. */
1446 #define CNT(sp,t) (((sp)->sname->name_type) == KRB5_NT_##t)
1447 if (CNT(b
, UNKNOWN
) || CNT(b
, PRINCIPAL
) || CNT(b
, SRV_INST
) || CNT(b
, SRV_HST
) || CNT(b
, SRV_XHST
))
1448 rep
.ticket
.sname
.name_type
= b
->sname
->name_type
;
1451 et
.flags
.initial
= 1;
1452 if(client
->entry
.flags
.forwardable
&& server
->entry
.flags
.forwardable
)
1453 et
.flags
.forwardable
= f
.forwardable
;
1454 else if (f
.forwardable
) {
1455 ret
= KRB5KDC_ERR_POLICY
;
1456 kdc_log(context
, config
, 0,
1457 "Ticket may not be forwardable -- %s", client_name
);
1460 if(client
->entry
.flags
.proxiable
&& server
->entry
.flags
.proxiable
)
1461 et
.flags
.proxiable
= f
.proxiable
;
1462 else if (f
.proxiable
) {
1463 ret
= KRB5KDC_ERR_POLICY
;
1464 kdc_log(context
, config
, 0,
1465 "Ticket may not be proxiable -- %s", client_name
);
1468 if(client
->entry
.flags
.postdate
&& server
->entry
.flags
.postdate
)
1469 et
.flags
.may_postdate
= f
.allow_postdate
;
1470 else if (f
.allow_postdate
){
1471 ret
= KRB5KDC_ERR_POLICY
;
1472 kdc_log(context
, config
, 0,
1473 "Ticket may not be postdatable -- %s", client_name
);
1477 /* check for valid set of addresses */
1478 if(!_kdc_check_addresses(context
, config
, b
->addresses
, from_addr
)) {
1479 ret
= KRB5KRB_AP_ERR_BADADDR
;
1480 kdc_log(context
, config
, 0,
1481 "Bad address list requested -- %s", client_name
);
1485 ret
= krb5_generate_random_keyblock(context
, sessionetype
, &et
.key
);
1488 copy_PrincipalName(&rep
.cname
, &et
.cname
);
1489 copy_Realm(&rep
.crealm
, &et
.crealm
);
1495 start
= et
.authtime
= kdc_time
;
1497 if(f
.postdated
&& req
->req_body
.from
){
1498 ALLOC(et
.starttime
);
1499 start
= *et
.starttime
= *req
->req_body
.from
;
1500 et
.flags
.invalid
= 1;
1501 et
.flags
.postdated
= 1; /* XXX ??? */
1503 _kdc_fix_time(&b
->till
);
1506 /* be careful not overflowing */
1508 if(client
->entry
.max_life
)
1509 t
= start
+ min(t
- start
, *client
->entry
.max_life
);
1510 if(server
->entry
.max_life
)
1511 t
= start
+ min(t
- start
, *server
->entry
.max_life
);
1513 t
= min(t
, start
+ realm
->max_life
);
1516 if(f
.renewable_ok
&& et
.endtime
< *b
->till
){
1518 if(b
->rtime
== NULL
){
1522 if(*b
->rtime
< *b
->till
)
1523 *b
->rtime
= *b
->till
;
1525 if(f
.renewable
&& b
->rtime
){
1529 if(client
->entry
.max_renew
)
1530 t
= start
+ min(t
- start
, *client
->entry
.max_renew
);
1531 if(server
->entry
.max_renew
)
1532 t
= start
+ min(t
- start
, *server
->entry
.max_renew
);
1534 t
= min(t
, start
+ realm
->max_renew
);
1536 ALLOC(et
.renew_till
);
1538 et
.flags
.renewable
= 1;
1542 if (f
.request_anonymous
)
1543 et
.flags
.anonymous
= 1;
1547 copy_HostAddresses(b
->addresses
, et
.caddr
);
1550 et
.transited
.tr_type
= DOMAIN_X500_COMPRESS
;
1551 krb5_data_zero(&et
.transited
.contents
);
1553 copy_EncryptionKey(&et
.key
, &ek
.key
);
1555 /* The MIT ASN.1 library (obviously) doesn't tell lengths encoded
1556 * as 0 and as 0x80 (meaning indefinite length) apart, and is thus
1557 * incapable of correctly decoding SEQUENCE OF's of zero length.
1559 * To fix this, always send at least one no-op last_req
1561 * If there's a pw_end or valid_end we will use that,
1562 * otherwise just a dummy lr.
1564 ek
.last_req
.val
= malloc(2 * sizeof(*ek
.last_req
.val
));
1565 if (ek
.last_req
.val
== NULL
) {
1569 ek
.last_req
.len
= 0;
1570 if (client
->entry
.pw_end
1571 && (config
->kdc_warn_pwexpire
== 0
1572 || kdc_time
+ config
->kdc_warn_pwexpire
>= *client
->entry
.pw_end
)) {
1573 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_PW_EXPTIME
;
1574 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.pw_end
;
1577 if (client
->entry
.valid_end
) {
1578 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_ACCT_EXPTIME
;
1579 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.valid_end
;
1582 if (ek
.last_req
.len
== 0) {
1583 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_NONE
;
1584 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= 0;
1587 ek
.nonce
= b
->nonce
;
1588 if (client
->entry
.valid_end
|| client
->entry
.pw_end
) {
1589 ALLOC(ek
.key_expiration
);
1590 if (client
->entry
.valid_end
) {
1591 if (client
->entry
.pw_end
)
1592 *ek
.key_expiration
= min(*client
->entry
.valid_end
,
1593 *client
->entry
.pw_end
);
1595 *ek
.key_expiration
= *client
->entry
.valid_end
;
1597 *ek
.key_expiration
= *client
->entry
.pw_end
;
1599 ek
.key_expiration
= NULL
;
1600 ek
.flags
= et
.flags
;
1601 ek
.authtime
= et
.authtime
;
1603 ALLOC(ek
.starttime
);
1604 *ek
.starttime
= *et
.starttime
;
1606 ek
.endtime
= et
.endtime
;
1607 if (et
.renew_till
) {
1608 ALLOC(ek
.renew_till
);
1609 *ek
.renew_till
= *et
.renew_till
;
1611 copy_Realm(&rep
.ticket
.realm
, &ek
.srealm
);
1612 copy_PrincipalName(&rep
.ticket
.sname
, &ek
.sname
);
1615 copy_HostAddresses(et
.caddr
, ek
.caddr
);
1619 rep
.padata
->len
= 0;
1620 rep
.padata
->val
= NULL
;
1622 reply_key
= &ckey
->key
;
1625 ret
= _kdc_pk_mk_pa_reply(context
, config
, pkp
, client
,
1627 &reply_key
, rep
.padata
);
1630 ret
= _kdc_add_inital_verified_cas(context
,
1639 set_salt_padata (rep
.padata
, ckey
->salt
);
1641 /* Add signing of alias referral */
1642 if (f
.canonicalize
) {
1643 PA_ClientCanonicalized canon
;
1649 memset(&canon
, 0, sizeof(canon
));
1651 canon
.names
.requested_name
= *b
->cname
;
1652 canon
.names
.real_name
= client
->entry
.principal
->name
;
1654 ASN1_MALLOC_ENCODE(PA_ClientCanonicalizedNames
, data
.data
, data
.length
,
1655 &canon
.names
, &len
, ret
);
1658 if (data
.length
!= len
)
1659 krb5_abortx(context
, "internal asn.1 error");
1661 /* sign using "returned session key" */
1662 ret
= krb5_crypto_init(context
, &et
.key
, 0, &crypto
);
1668 ret
= krb5_create_checksum(context
, crypto
,
1669 KRB5_KU_CANONICALIZED_NAMES
, 0,
1670 data
.data
, data
.length
,
1671 &canon
.canon_checksum
);
1673 krb5_crypto_destroy(context
, crypto
);
1677 ASN1_MALLOC_ENCODE(PA_ClientCanonicalized
, data
.data
, data
.length
,
1679 free_Checksum(&canon
.canon_checksum
);
1682 if (data
.length
!= len
)
1683 krb5_abortx(context
, "internal asn.1 error");
1685 pa
.padata_type
= KRB5_PADATA_CLIENT_CANONICALIZED
;
1686 pa
.padata_value
= data
;
1687 ret
= add_METHOD_DATA(rep
.padata
, &pa
);
1693 if (rep
.padata
->len
== 0) {
1699 if (send_pac_p(context
, req
)) {
1703 ret
= _kdc_pac_generate(context
, client
, &p
);
1705 kdc_log(context
, config
, 0, "PAC generation failed for -- %s",
1710 ret
= _krb5_pac_sign(context
, p
, et
.authtime
,
1711 client
->entry
.principal
,
1712 &skey
->key
, /* Server key */
1713 &skey
->key
, /* FIXME: should be krbtgt key */
1715 krb5_pac_free(context
, p
);
1717 kdc_log(context
, config
, 0, "PAC signing failed for -- %s",
1722 ret
= _kdc_tkt_add_if_relevant_ad(context
, &et
,
1723 KRB5_AUTHDATA_WIN2K_PAC
,
1725 krb5_data_free(&data
);
1731 _kdc_log_timestamp(context
, config
, "AS-REQ", et
.authtime
, et
.starttime
,
1732 et
.endtime
, et
.renew_till
);
1734 /* do this as the last thing since this signs the EncTicketPart */
1735 ret
= _kdc_add_KRB5SignedPath(context
,
1745 ret
= _kdc_encode_reply(context
, config
,
1746 &rep
, &et
, &ek
, setype
, server
->entry
.kvno
,
1747 &skey
->key
, client
->entry
.kvno
,
1748 reply_key
, &e_text
, reply
);
1749 free_EncTicketPart(&et
);
1750 free_EncKDCRepPart(&ek
);
1755 if (datagram_reply
&& reply
->length
> config
->max_datagram_reply_length
) {
1756 krb5_data_free(reply
);
1757 ret
= KRB5KRB_ERR_RESPONSE_TOO_BIG
;
1758 e_text
= "Reply packet too large";
1764 krb5_mk_error(context
,
1767 (e_data
.data
? &e_data
: NULL
),
1777 _kdc_pk_free_client_param(context
, pkp
);
1782 krb5_free_principal(context
, client_princ
);
1785 krb5_free_principal(context
, server_princ
);
1788 _kdc_free_ent(context
, client
);
1790 _kdc_free_ent(context
, server
);
1795 * Add the AuthorizationData `data´ of `type´ to the last element in
1796 * the sequence of authorization_data in `tkt´ wrapped in an IF_RELEVANT
1800 _kdc_tkt_add_if_relevant_ad(krb5_context context
,
1803 const krb5_data
*data
)
1805 krb5_error_code ret
;
1808 if (tkt
->authorization_data
== NULL
) {
1809 tkt
->authorization_data
= calloc(1, sizeof(*tkt
->authorization_data
));
1810 if (tkt
->authorization_data
== NULL
) {
1811 krb5_set_error_string(context
, "out of memory");
1816 /* add the entry to the last element */
1818 AuthorizationData ad
= { 0, NULL
};
1819 AuthorizationDataElement ade
;
1822 ade
.ad_data
= *data
;
1824 ret
= add_AuthorizationData(&ad
, &ade
);
1826 krb5_set_error_string(context
, "add AuthorizationData failed");
1830 ade
.ad_type
= KRB5_AUTHDATA_IF_RELEVANT
;
1832 ASN1_MALLOC_ENCODE(AuthorizationData
,
1833 ade
.ad_data
.data
, ade
.ad_data
.length
,
1835 free_AuthorizationData(&ad
);
1837 krb5_set_error_string(context
, "ASN.1 encode of "
1838 "AuthorizationData failed");
1841 if (ade
.ad_data
.length
!= size
)
1842 krb5_abortx(context
, "internal asn.1 encoder error");
1844 ret
= add_AuthorizationData(tkt
->authorization_data
, &ade
);
1845 der_free_octet_string(&ade
.ad_data
);
1847 krb5_set_error_string(context
, "add AuthorizationData failed");