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
38 #define MAX_TIME ((time_t)((1U << 31) - 1))
41 _kdc_fix_time(time_t **t
)
47 if(**t
== 0) **t
= MAX_TIME
; /* fix for old clients */
51 realloc_method_data(METHOD_DATA
*md
)
54 pa
= realloc(md
->val
, (md
->len
+ 1) * sizeof(*md
->val
));
63 set_salt_padata (METHOD_DATA
*md
, Salt
*salt
)
66 realloc_method_data(md
);
67 md
->val
[md
->len
- 1].padata_type
= salt
->type
;
68 der_copy_octet_string(&salt
->salt
,
69 &md
->val
[md
->len
- 1].padata_value
);
74 _kdc_find_padata(const KDC_REQ
*req
, int *start
, int type
)
76 if (req
->padata
== NULL
)
79 while(*start
< req
->padata
->len
){
81 if(req
->padata
->val
[*start
- 1].padata_type
== type
)
82 return &req
->padata
->val
[*start
- 1];
88 * This is a hack to allow predefined weak services, like afs to
89 * still use weak types
93 _kdc_is_weak_exception(krb5_principal principal
, krb5_enctype etype
)
95 if (principal
->name
.name_string
.len
> 0 &&
96 strcmp(principal
->name
.name_string
.val
[0], "afs") == 0 &&
97 (etype
== ETYPE_DES_CBC_CRC
98 || etype
== ETYPE_DES_CBC_MD4
99 || etype
== ETYPE_DES_CBC_MD5
))
106 * Detect if `key' is the using the the precomputed `default_salt'.
110 is_default_salt_p(const krb5_salt
*default_salt
, const Key
*key
)
112 if (key
->salt
== NULL
)
114 if (default_salt
->salttype
!= key
->salt
->type
)
116 if (krb5_data_cmp(&default_salt
->saltvalue
, &key
->salt
->salt
))
122 * return the first appropriate key of `princ' in `ret_key'. Look for
123 * all the etypes in (`etypes', `len'), stopping as soon as we find
124 * one, but preferring one that has default salt
128 _kdc_find_etype(krb5_context context
, const hdb_entry_ex
*princ
,
129 krb5_enctype
*etypes
, unsigned len
,
130 Key
**ret_key
, krb5_enctype
*ret_etype
)
133 krb5_error_code ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
136 krb5_get_pw_salt (context
, princ
->entry
.principal
, &def_salt
);
138 for(i
= 0; ret
!= 0 && i
< len
; i
++) {
141 if (krb5_enctype_valid(context
, etypes
[i
]) != 0 &&
142 !_kdc_is_weak_exception(princ
->entry
.principal
, etypes
[i
]))
145 while (hdb_next_enctype2key(context
, &princ
->entry
, etypes
[i
], &key
) == 0) {
146 if (key
->key
.keyvalue
.length
== 0) {
147 ret
= KRB5KDC_ERR_NULL_KEY
;
151 *ret_etype
= etypes
[i
];
153 if (is_default_salt_p(&def_salt
, key
)) {
154 krb5_free_salt (context
, def_salt
);
159 krb5_free_salt (context
, def_salt
);
164 _kdc_make_anonymous_principalname (PrincipalName
*pn
)
166 pn
->name_type
= KRB5_NT_PRINCIPAL
;
167 pn
->name_string
.len
= 1;
168 pn
->name_string
.val
= malloc(sizeof(*pn
->name_string
.val
));
169 if (pn
->name_string
.val
== NULL
)
171 pn
->name_string
.val
[0] = strdup("anonymous");
172 if (pn
->name_string
.val
[0] == NULL
) {
173 free(pn
->name_string
.val
);
174 pn
->name_string
.val
= NULL
;
181 _kdc_log_timestamp(krb5_context context
,
182 krb5_kdc_configuration
*config
,
184 KerberosTime authtime
, KerberosTime
*starttime
,
185 KerberosTime endtime
, KerberosTime
*renew_till
)
187 char authtime_str
[100], starttime_str
[100],
188 endtime_str
[100], renewtime_str
[100];
190 krb5_format_time(context
, authtime
,
191 authtime_str
, sizeof(authtime_str
), TRUE
);
193 krb5_format_time(context
, *starttime
,
194 starttime_str
, sizeof(starttime_str
), TRUE
);
196 strlcpy(starttime_str
, "unset", sizeof(starttime_str
));
197 krb5_format_time(context
, endtime
,
198 endtime_str
, sizeof(endtime_str
), TRUE
);
200 krb5_format_time(context
, *renew_till
,
201 renewtime_str
, sizeof(renewtime_str
), TRUE
);
203 strlcpy(renewtime_str
, "unset", sizeof(renewtime_str
));
205 kdc_log(context
, config
, 5,
206 "%s authtime: %s starttime: %s endtime: %s renew till: %s",
207 type
, authtime_str
, starttime_str
, endtime_str
, renewtime_str
);
211 log_patypes(krb5_context context
,
212 krb5_kdc_configuration
*config
,
215 struct rk_strpool
*p
= NULL
;
219 for (i
= 0; i
< padata
->len
; i
++) {
220 switch(padata
->val
[i
].padata_type
) {
221 case KRB5_PADATA_PK_AS_REQ
:
222 p
= rk_strpoolprintf(p
, "PK-INIT(ietf)");
224 case KRB5_PADATA_PK_AS_REQ_WIN
:
225 p
= rk_strpoolprintf(p
, "PK-INIT(win2k)");
227 case KRB5_PADATA_PA_PK_OCSP_RESPONSE
:
228 p
= rk_strpoolprintf(p
, "OCSP");
230 case KRB5_PADATA_ENC_TIMESTAMP
:
231 p
= rk_strpoolprintf(p
, "encrypted-timestamp");
234 p
= rk_strpoolprintf(p
, "%d", padata
->val
[i
].padata_type
);
237 if (p
&& i
+ 1 < padata
->len
)
238 p
= rk_strpoolprintf(p
, ", ");
240 kdc_log(context
, config
, 0, "out of memory");
245 p
= rk_strpoolprintf(p
, "none");
247 str
= rk_strpoolcollect(p
);
248 kdc_log(context
, config
, 0, "Client sent patypes: %s", str
);
258 _kdc_encode_reply(krb5_context context
,
259 krb5_kdc_configuration
*config
,
260 KDC_REP
*rep
, const EncTicketPart
*et
, EncKDCRepPart
*ek
,
262 int skvno
, const EncryptionKey
*skey
,
263 int ckvno
, const EncryptionKey
*reply_key
,
274 ASN1_MALLOC_ENCODE(EncTicketPart
, buf
, buf_size
, et
, &len
, ret
);
276 const char *msg
= krb5_get_error_message(context
, ret
);
277 kdc_log(context
, config
, 0, "Failed to encode ticket: %s", msg
);
278 krb5_free_error_message(context
, msg
);
281 if(buf_size
!= len
) {
283 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
284 *e_text
= "KDC internal error";
285 return KRB5KRB_ERR_GENERIC
;
288 ret
= krb5_crypto_init(context
, skey
, etype
, &crypto
);
291 const char *msg
= krb5_get_error_message(context
, ret
);
292 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
293 krb5_free_error_message(context
, msg
);
297 ret
= krb5_encrypt_EncryptedData(context
,
303 &rep
->ticket
.enc_part
);
305 krb5_crypto_destroy(context
, crypto
);
307 const char *msg
= krb5_get_error_message(context
, ret
);
308 kdc_log(context
, config
, 0, "Failed to encrypt data: %s", msg
);
309 krb5_free_error_message(context
, msg
);
313 if(rep
->msg_type
== krb_as_rep
&& !config
->encode_as_rep_as_tgs_rep
)
314 ASN1_MALLOC_ENCODE(EncASRepPart
, buf
, buf_size
, ek
, &len
, ret
);
316 ASN1_MALLOC_ENCODE(EncTGSRepPart
, buf
, buf_size
, ek
, &len
, ret
);
318 const char *msg
= krb5_get_error_message(context
, ret
);
319 kdc_log(context
, config
, 0, "Failed to encode KDC-REP: %s", msg
);
320 krb5_free_error_message(context
, msg
);
323 if(buf_size
!= len
) {
325 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
326 *e_text
= "KDC internal error";
327 return KRB5KRB_ERR_GENERIC
;
329 ret
= krb5_crypto_init(context
, reply_key
, 0, &crypto
);
331 const char *msg
= krb5_get_error_message(context
, ret
);
333 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
334 krb5_free_error_message(context
, msg
);
337 if(rep
->msg_type
== krb_as_rep
) {
338 krb5_encrypt_EncryptedData(context
,
340 KRB5_KU_AS_REP_ENC_PART
,
346 ASN1_MALLOC_ENCODE(AS_REP
, buf
, buf_size
, rep
, &len
, ret
);
348 krb5_encrypt_EncryptedData(context
,
350 rk_is_subkey
? KRB5_KU_TGS_REP_ENC_PART_SUB_KEY
: KRB5_KU_TGS_REP_ENC_PART_SESSION
,
356 ASN1_MALLOC_ENCODE(TGS_REP
, buf
, buf_size
, rep
, &len
, ret
);
358 krb5_crypto_destroy(context
, crypto
);
360 const char *msg
= krb5_get_error_message(context
, ret
);
361 kdc_log(context
, config
, 0, "Failed to encode KDC-REP: %s", msg
);
362 krb5_free_error_message(context
, msg
);
365 if(buf_size
!= len
) {
367 kdc_log(context
, config
, 0, "Internal error in ASN.1 encoder");
368 *e_text
= "KDC internal error";
369 return KRB5KRB_ERR_GENERIC
;
372 reply
->length
= buf_size
;
377 * Return 1 if the client have only older enctypes, this is for
378 * determining if the server should send ETYPE_INFO2 or not.
382 older_enctype(krb5_enctype enctype
)
385 case ETYPE_DES_CBC_CRC
:
386 case ETYPE_DES_CBC_MD4
:
387 case ETYPE_DES_CBC_MD5
:
388 case ETYPE_DES3_CBC_SHA1
:
389 case ETYPE_ARCFOUR_HMAC_MD5
:
390 case ETYPE_ARCFOUR_HMAC_MD5_56
:
392 * The following three is "old" windows enctypes and is needed for
393 * windows 2000 hosts.
395 case ETYPE_ARCFOUR_MD4
:
396 case ETYPE_ARCFOUR_HMAC_OLD
:
397 case ETYPE_ARCFOUR_HMAC_OLD_EXP
:
408 static krb5_error_code
409 make_etype_info_entry(krb5_context context
, ETYPE_INFO_ENTRY
*ent
, Key
*key
)
411 ent
->etype
= key
->key
.keytype
;
414 ALLOC(ent
->salttype
);
416 if(key
->salt
->type
== hdb_pw_salt
)
417 *ent
->salttype
= 0; /* or 1? or NULL? */
418 else if(key
->salt
->type
== hdb_afs3_salt
)
421 kdc_log(context
, config
, 0, "unknown salt-type: %d",
423 return KRB5KRB_ERR_GENERIC
;
425 /* according to `the specs', we can't send a salt if
426 we have AFS3 salted key, but that requires that you
427 *know* what cell you are using (e.g by assuming
428 that the cell is the same as the realm in lower
431 ALLOC(ent
->salttype
);
432 *ent
->salttype
= key
->salt
->type
;
435 * We shouldn't sent salttype since it is incompatible with the
436 * specification and it breaks windows clients. The afs
437 * salting problem is solved by using KRB5-PADATA-AFS3-SALT
438 * implemented in Heimdal 0.7 and later.
440 ent
->salttype
= NULL
;
442 krb5_copy_data(context
, &key
->salt
->salt
,
445 /* we return no salt type at all, as that should indicate
446 * the default salt type and make everybody happy. some
447 * systems (like w2k) dislike being told the salt type
450 ent
->salttype
= NULL
;
456 static krb5_error_code
457 get_pa_etype_info(krb5_context context
,
458 krb5_kdc_configuration
*config
,
459 METHOD_DATA
*md
, Key
*ckey
)
461 krb5_error_code ret
= 0;
468 pa
.val
= calloc(1, sizeof(pa
.val
[0]));
472 ret
= make_etype_info_entry(context
, &pa
.val
[0], ckey
);
474 free_ETYPE_INFO(&pa
);
478 ASN1_MALLOC_ENCODE(ETYPE_INFO
, buf
, len
, &pa
, &len
, ret
);
479 free_ETYPE_INFO(&pa
);
482 ret
= realloc_method_data(md
);
487 md
->val
[md
->len
- 1].padata_type
= KRB5_PADATA_ETYPE_INFO
;
488 md
->val
[md
->len
- 1].padata_value
.length
= len
;
489 md
->val
[md
->len
- 1].padata_value
.data
= buf
;
497 extern int _krb5_AES_string_to_default_iterator
;
499 static krb5_error_code
500 make_etype_info2_entry(ETYPE_INFO2_ENTRY
*ent
, Key
*key
)
502 ent
->etype
= key
->key
.keytype
;
505 if (ent
->salt
== NULL
)
507 *ent
->salt
= malloc(key
->salt
->salt
.length
+ 1);
508 if (*ent
->salt
== NULL
) {
513 memcpy(*ent
->salt
, key
->salt
->salt
.data
, key
->salt
->salt
.length
);
514 (*ent
->salt
)[key
->salt
->salt
.length
] = '\0';
518 ent
->s2kparams
= NULL
;
520 switch (key
->key
.keytype
) {
521 case ETYPE_AES128_CTS_HMAC_SHA1_96
:
522 case ETYPE_AES256_CTS_HMAC_SHA1_96
:
523 ALLOC(ent
->s2kparams
);
524 if (ent
->s2kparams
== NULL
)
526 ent
->s2kparams
->length
= 4;
527 ent
->s2kparams
->data
= malloc(ent
->s2kparams
->length
);
528 if (ent
->s2kparams
->data
== NULL
) {
529 free(ent
->s2kparams
);
530 ent
->s2kparams
= NULL
;
533 _krb5_put_int(ent
->s2kparams
->data
,
534 _krb5_AES_string_to_default_iterator
,
535 ent
->s2kparams
->length
);
537 case ETYPE_DES_CBC_CRC
:
538 case ETYPE_DES_CBC_MD4
:
539 case ETYPE_DES_CBC_MD5
:
540 /* Check if this was a AFS3 salted key */
541 if(key
->salt
&& key
->salt
->type
== hdb_afs3_salt
){
542 ALLOC(ent
->s2kparams
);
543 if (ent
->s2kparams
== NULL
)
545 ent
->s2kparams
->length
= 1;
546 ent
->s2kparams
->data
= malloc(ent
->s2kparams
->length
);
547 if (ent
->s2kparams
->data
== NULL
) {
548 free(ent
->s2kparams
);
549 ent
->s2kparams
= NULL
;
552 _krb5_put_int(ent
->s2kparams
->data
,
554 ent
->s2kparams
->length
);
564 * Return an ETYPE-INFO2. Enctypes are storted the same way as in the
565 * database (client supported enctypes first, then the unsupported
569 static krb5_error_code
570 get_pa_etype_info2(krb5_context context
,
571 krb5_kdc_configuration
*config
,
572 METHOD_DATA
*md
, Key
*ckey
)
574 krb5_error_code ret
= 0;
580 pa
.val
= calloc(1, sizeof(pa
.val
[0]));
584 ret
= make_etype_info2_entry(&pa
.val
[0], ckey
);
586 free_ETYPE_INFO2(&pa
);
590 ASN1_MALLOC_ENCODE(ETYPE_INFO2
, buf
, len
, &pa
, &len
, ret
);
591 free_ETYPE_INFO2(&pa
);
594 ret
= realloc_method_data(md
);
599 md
->val
[md
->len
- 1].padata_type
= KRB5_PADATA_ETYPE_INFO2
;
600 md
->val
[md
->len
- 1].padata_value
.length
= len
;
601 md
->val
[md
->len
- 1].padata_value
.data
= buf
;
610 log_as_req(krb5_context context
,
611 krb5_kdc_configuration
*config
,
614 const KDC_REQ_BODY
*b
)
617 struct rk_strpool
*p
;
621 p
= rk_strpoolprintf(NULL
, "%s", "Client supported enctypes: ");
623 for (i
= 0; i
< b
->etype
.len
; i
++) {
624 ret
= krb5_enctype_to_string(context
, b
->etype
.val
[i
], &str
);
626 p
= rk_strpoolprintf(p
, "%s", str
);
629 p
= rk_strpoolprintf(p
, "%d", b
->etype
.val
[i
]);
630 if (p
&& i
+ 1 < b
->etype
.len
)
631 p
= rk_strpoolprintf(p
, ", ");
633 kdc_log(context
, config
, 0, "out of memory");
638 p
= rk_strpoolprintf(p
, "no encryption types");
644 ret
= krb5_enctype_to_string(context
, cetype
, &cet
);
646 ret
= krb5_enctype_to_string(context
, setype
, &set
);
648 p
= rk_strpoolprintf(p
, ", using %s/%s", cet
, set
);
654 p
= rk_strpoolprintf(p
, ", using enctypes %d/%d",
658 str
= rk_strpoolcollect(p
);
659 kdc_log(context
, config
, 0, "%s", str
);
664 unparse_flags(KDCOptions2int(b
->kdc_options
), asn1_KDCOptions_units(),
665 fixedstr
, sizeof(fixedstr
));
667 kdc_log(context
, config
, 0, "Requested flags: %s", fixedstr
);
672 * verify the flags on `client' and `server', returning 0
673 * if they are OK and generating an error messages and returning
674 * and error code otherwise.
678 kdc_check_flags(krb5_context context
,
679 krb5_kdc_configuration
*config
,
680 hdb_entry_ex
*client_ex
, const char *client_name
,
681 hdb_entry_ex
*server_ex
, const char *server_name
,
682 krb5_boolean is_as_req
)
684 if(client_ex
!= NULL
) {
685 hdb_entry
*client
= &client_ex
->entry
;
688 if (client
->flags
.locked_out
) {
689 kdc_log(context
, config
, 0,
690 "Client (%s) is locked out", client_name
);
691 return KRB5KDC_ERR_POLICY
;
694 if (client
->flags
.invalid
) {
695 kdc_log(context
, config
, 0,
696 "Client (%s) has invalid bit set", client_name
);
697 return KRB5KDC_ERR_POLICY
;
700 if(!client
->flags
.client
){
701 kdc_log(context
, config
, 0,
702 "Principal may not act as client -- %s", client_name
);
703 return KRB5KDC_ERR_POLICY
;
706 if (client
->valid_start
&& *client
->valid_start
> kdc_time
) {
707 char starttime_str
[100];
708 krb5_format_time(context
, *client
->valid_start
,
709 starttime_str
, sizeof(starttime_str
), TRUE
);
710 kdc_log(context
, config
, 0,
711 "Client not yet valid until %s -- %s",
712 starttime_str
, client_name
);
713 return KRB5KDC_ERR_CLIENT_NOTYET
;
716 if (client
->valid_end
&& *client
->valid_end
< kdc_time
) {
717 char endtime_str
[100];
718 krb5_format_time(context
, *client
->valid_end
,
719 endtime_str
, sizeof(endtime_str
), TRUE
);
720 kdc_log(context
, config
, 0,
721 "Client expired at %s -- %s",
722 endtime_str
, client_name
);
723 return KRB5KDC_ERR_NAME_EXP
;
726 if (client
->pw_end
&& *client
->pw_end
< kdc_time
727 && (server_ex
== NULL
|| !server_ex
->entry
.flags
.change_pw
)) {
729 krb5_format_time(context
, *client
->pw_end
,
730 pwend_str
, sizeof(pwend_str
), TRUE
);
731 kdc_log(context
, config
, 0,
732 "Client's key has expired at %s -- %s",
733 pwend_str
, client_name
);
734 return KRB5KDC_ERR_KEY_EXPIRED
;
740 if (server_ex
!= NULL
) {
741 hdb_entry
*server
= &server_ex
->entry
;
743 if (server
->flags
.locked_out
) {
744 kdc_log(context
, config
, 0,
745 "Client server locked out -- %s", server_name
);
746 return KRB5KDC_ERR_POLICY
;
748 if (server
->flags
.invalid
) {
749 kdc_log(context
, config
, 0,
750 "Server has invalid flag set -- %s", server_name
);
751 return KRB5KDC_ERR_POLICY
;
754 if(!server
->flags
.server
){
755 kdc_log(context
, config
, 0,
756 "Principal may not act as server -- %s", server_name
);
757 return KRB5KDC_ERR_POLICY
;
760 if(!is_as_req
&& server
->flags
.initial
) {
761 kdc_log(context
, config
, 0,
762 "AS-REQ is required for server -- %s", server_name
);
763 return KRB5KDC_ERR_POLICY
;
766 if (server
->valid_start
&& *server
->valid_start
> kdc_time
) {
767 char starttime_str
[100];
768 krb5_format_time(context
, *server
->valid_start
,
769 starttime_str
, sizeof(starttime_str
), TRUE
);
770 kdc_log(context
, config
, 0,
771 "Server not yet valid until %s -- %s",
772 starttime_str
, server_name
);
773 return KRB5KDC_ERR_SERVICE_NOTYET
;
776 if (server
->valid_end
&& *server
->valid_end
< kdc_time
) {
777 char endtime_str
[100];
778 krb5_format_time(context
, *server
->valid_end
,
779 endtime_str
, sizeof(endtime_str
), TRUE
);
780 kdc_log(context
, config
, 0,
781 "Server expired at %s -- %s",
782 endtime_str
, server_name
);
783 return KRB5KDC_ERR_SERVICE_EXP
;
786 if (server
->pw_end
&& *server
->pw_end
< kdc_time
) {
788 krb5_format_time(context
, *server
->pw_end
,
789 pwend_str
, sizeof(pwend_str
), TRUE
);
790 kdc_log(context
, config
, 0,
791 "Server's key has expired at -- %s",
792 pwend_str
, server_name
);
793 return KRB5KDC_ERR_KEY_EXPIRED
;
800 * Return TRUE if `from' is part of `addresses' taking into consideration
801 * the configuration variables that tells us how strict we should be about
806 _kdc_check_addresses(krb5_context context
,
807 krb5_kdc_configuration
*config
,
808 HostAddresses
*addresses
, const struct sockaddr
*from
)
813 krb5_boolean only_netbios
= TRUE
;
816 if(config
->check_ticket_addresses
== 0)
819 if(addresses
== NULL
)
820 return config
->allow_null_ticket_addresses
;
822 for (i
= 0; i
< addresses
->len
; ++i
) {
823 if (addresses
->val
[i
].addr_type
!= KRB5_ADDRESS_NETBIOS
) {
824 only_netbios
= FALSE
;
828 /* Windows sends it's netbios name, which I can only assume is
829 * used for the 'allowed workstations' check. This is painful,
830 * but we still want to check IP addresses if they happen to be
835 return config
->allow_null_ticket_addresses
;
837 ret
= krb5_sockaddr2address (context
, from
, &addr
);
841 result
= krb5_address_search(context
, &addr
, addresses
);
842 krb5_free_address (context
, &addr
);
851 send_pac_p(krb5_context context
, KDC_REQ
*req
)
854 PA_PAC_REQUEST pacreq
;
858 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PA_PAC_REQUEST
);
862 ret
= decode_PA_PAC_REQUEST(pa
->padata_value
.data
,
863 pa
->padata_value
.length
,
868 i
= pacreq
.include_pac
;
869 free_PA_PAC_REQUEST(&pacreq
);
876 _kdc_is_anonymous(krb5_context context
, krb5_principal principal
)
878 if (principal
->name
.name_type
!= KRB5_NT_WELLKNOWN
||
879 principal
->name
.name_string
.len
!= 2 ||
880 strcmp(principal
->name
.name_string
.val
[0], KRB5_WELLKNOWN_NAME
) != 0 ||
881 strcmp(principal
->name
.name_string
.val
[1], KRB5_ANON_NAME
) != 0)
891 _kdc_as_rep(krb5_context context
,
892 krb5_kdc_configuration
*config
,
894 const krb5_data
*req_buffer
,
897 struct sockaddr
*from_addr
,
900 KDC_REQ_BODY
*b
= &req
->req_body
;
902 KDCOptions f
= b
->kdc_options
;
903 hdb_entry_ex
*client
= NULL
, *server
= NULL
;
905 krb5_enctype cetype
, setype
, sessionetype
;
909 krb5_principal client_princ
= NULL
, server_princ
= NULL
;
910 char *client_name
= NULL
, *server_name
= NULL
;
911 krb5_error_code ret
= 0;
912 const char *e_text
= NULL
;
915 EncryptionKey
*reply_key
;
918 pk_client_params
*pkp
= NULL
;
921 memset(&rep
, 0, sizeof(rep
));
922 krb5_data_zero(&e_data
);
925 flags
|= HDB_F_CANON
;
927 if(b
->sname
== NULL
){
928 ret
= KRB5KRB_ERR_GENERIC
;
929 e_text
= "No server in request";
931 ret
= _krb5_principalname2krb5_principal (context
,
936 ret
= krb5_unparse_name(context
, server_princ
, &server_name
);
939 kdc_log(context
, config
, 0,
940 "AS-REQ malformed server name from %s", from
);
943 if(b
->cname
== NULL
){
944 ret
= KRB5KRB_ERR_GENERIC
;
945 e_text
= "No client in request";
947 ret
= _krb5_principalname2krb5_principal (context
,
954 ret
= krb5_unparse_name(context
, client_princ
, &client_name
);
957 kdc_log(context
, config
, 0,
958 "AS-REQ malformed client name from %s", from
);
962 kdc_log(context
, config
, 0, "AS-REQ %s from %s for %s",
963 client_name
, from
, server_name
);
969 if (_kdc_is_anonymous(context
, client_princ
)) {
970 if (!b
->kdc_options
.request_anonymous
) {
971 kdc_log(context
, config
, 0, "Anonymous ticket w/o anonymous flag");
972 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
975 } else if (b
->kdc_options
.request_anonymous
) {
976 kdc_log(context
, config
, 0,
977 "Request for a anonymous ticket with non "
978 "anonymous client name: %s", client_name
);
979 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
987 ret
= _kdc_db_fetch(context
, config
, client_princ
,
988 HDB_F_GET_CLIENT
| flags
, &clientdb
, &client
);
990 const char *msg
= krb5_get_error_message(context
, ret
);
991 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", client_name
, msg
);
992 krb5_free_error_message(context
, msg
);
993 ret
= KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN
;
997 ret
= _kdc_db_fetch(context
, config
, server_princ
,
998 HDB_F_GET_SERVER
|HDB_F_GET_KRBTGT
,
1001 const char *msg
= krb5_get_error_message(context
, ret
);
1002 kdc_log(context
, config
, 0, "UNKNOWN -- %s: %s", server_name
, msg
);
1003 krb5_free_error_message(context
, msg
);
1004 ret
= KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN
;
1008 memset(&et
, 0, sizeof(et
));
1009 memset(&ek
, 0, sizeof(ek
));
1012 * Find the client key for reply encryption and pa-type salt, Pick
1013 * the client key upfront before the other keys because that is
1014 * going to affect what enctypes we are going to use in
1018 ret
= _kdc_find_etype(context
, client
, b
->etype
.val
, b
->etype
.len
,
1021 kdc_log(context
, config
, 0,
1022 "Client (%s) has no support for etypes", client_name
);
1027 * Pre-auth processing
1035 log_patypes(context
, config
, req
->padata
);
1038 kdc_log(context
, config
, 5,
1039 "Looking for PKINIT pa-data -- %s", client_name
);
1041 e_text
= "No PKINIT PA found";
1044 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ
);
1047 pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_PK_AS_REQ_WIN
);
1050 char *client_cert
= NULL
;
1052 ret
= _kdc_pk_rd_padata(context
, config
, req
, pa
, client
, &pkp
);
1054 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1055 kdc_log(context
, config
, 5,
1056 "Failed to decode PKINIT PA-DATA -- %s",
1060 if (ret
== 0 && pkp
== NULL
)
1063 ret
= _kdc_pk_check_client(context
,
1070 e_text
= "PKINIT certificate not allowed to "
1071 "impersonate principal";
1072 _kdc_pk_free_client_param(context
, pkp
);
1074 kdc_log(context
, config
, 0, "%s", e_text
);
1080 et
.flags
.pre_authent
= 1;
1081 kdc_log(context
, config
, 0,
1082 "PKINIT pre-authentication succeeded -- %s using %s",
1083 client_name
, client_cert
);
1090 kdc_log(context
, config
, 5, "Looking for ENC-TS pa-data -- %s",
1094 e_text
= "No ENC-TS found";
1095 while((pa
= _kdc_find_padata(req
, &i
, KRB5_PADATA_ENC_TIMESTAMP
))){
1099 EncryptedData enc_data
;
1105 if (b
->kdc_options
.request_anonymous
) {
1106 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1107 kdc_log(context
, config
, 0, "ENC-TS doesn't support anon");
1111 ret
= decode_EncryptedData(pa
->padata_value
.data
,
1112 pa
->padata_value
.length
,
1116 ret
= KRB5KRB_AP_ERR_BAD_INTEGRITY
;
1117 kdc_log(context
, config
, 5, "Failed to decode PA-DATA -- %s",
1122 ret
= hdb_enctype2key(context
, &client
->entry
,
1123 enc_data
.etype
, &pa_key
);
1126 e_text
= "No key matches pa-data";
1127 ret
= KRB5KDC_ERR_ETYPE_NOSUPP
;
1128 if(krb5_enctype_to_string(context
, enc_data
.etype
, &estr
))
1131 kdc_log(context
, config
, 5,
1132 "No client key matching pa-data (%d) -- %s",
1133 enc_data
.etype
, client_name
);
1135 kdc_log(context
, config
, 5,
1136 "No client key matching pa-data (%s) -- %s",
1139 free_EncryptedData(&enc_data
);
1145 ret
= krb5_crypto_init(context
, &pa_key
->key
, 0, &crypto
);
1147 const char *msg
= krb5_get_error_message(context
, ret
);
1148 kdc_log(context
, config
, 0, "krb5_crypto_init failed: %s", msg
);
1149 krb5_free_error_message(context
, msg
);
1150 free_EncryptedData(&enc_data
);
1154 ret
= krb5_decrypt_EncryptedData (context
,
1156 KRB5_KU_PA_ENC_TIMESTAMP
,
1159 krb5_crypto_destroy(context
, crypto
);
1161 * Since the user might have several keys with the same
1162 * enctype but with diffrent salting, we need to try all
1163 * the keys with the same enctype.
1166 krb5_error_code ret2
;
1167 const char *msg
= krb5_get_error_message(context
, ret
);
1169 ret2
= krb5_enctype_to_string(context
,
1170 pa_key
->key
.keytype
, &str
);
1173 kdc_log(context
, config
, 5,
1174 "Failed to decrypt PA-DATA -- %s "
1175 "(enctype %s) error %s",
1176 client_name
, str
? str
: "unknown enctype", msg
);
1177 krb5_free_error_message(context
, msg
);
1180 if(hdb_next_enctype2key(context
, &client
->entry
,
1181 enc_data
.etype
, &pa_key
) == 0)
1183 e_text
= "Failed to decrypt PA-DATA";
1185 free_EncryptedData(&enc_data
);
1187 if (clientdb
->hdb_auth_status
)
1188 (clientdb
->hdb_auth_status
)(context
, clientdb
, client
, HDB_AUTH_WRONG_PASSWORD
);
1190 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1193 free_EncryptedData(&enc_data
);
1194 ret
= decode_PA_ENC_TS_ENC(ts_data
.data
,
1198 krb5_data_free(&ts_data
);
1200 e_text
= "Failed to decode PA-ENC-TS-ENC";
1201 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1202 kdc_log(context
, config
,
1203 5, "Failed to decode PA-ENC-TS_ENC -- %s",
1207 free_PA_ENC_TS_ENC(&p
);
1208 if (abs(kdc_time
- p
.patimestamp
) > context
->max_skew
) {
1209 char client_time
[100];
1211 krb5_format_time(context
, p
.patimestamp
,
1212 client_time
, sizeof(client_time
), TRUE
);
1214 ret
= KRB5KRB_AP_ERR_SKEW
;
1215 kdc_log(context
, config
, 0,
1216 "Too large time skew, "
1217 "client time %s is out by %u > %u seconds -- %s",
1219 (unsigned)abs(kdc_time
- p
.patimestamp
),
1224 * The following is needed to make windows clients to
1225 * retry using the timestamp in the error message, if
1226 * there is a e_text, they become unhappy.
1231 et
.flags
.pre_authent
= 1;
1233 ret
= krb5_enctype_to_string(context
,pa_key
->key
.keytype
, &str
);
1237 kdc_log(context
, config
, 2,
1238 "ENC-TS Pre-authentication succeeded -- %s using %s",
1239 client_name
, str
? str
: "unknown enctype");
1246 if(found_pa
== 0 && config
->require_preauth
)
1248 /* We come here if we found a pa-enc-timestamp, but if there
1249 was some problem with it, other than too large skew */
1250 if(found_pa
&& et
.flags
.pre_authent
== 0){
1251 kdc_log(context
, config
, 0, "%s -- %s", e_text
, client_name
);
1255 }else if (config
->require_preauth
1256 || b
->kdc_options
.request_anonymous
/* hack to force anon */
1257 || client
->entry
.flags
.require_preauth
1258 || server
->entry
.flags
.require_preauth
) {
1259 METHOD_DATA method_data
;
1265 method_data
.len
= 0;
1266 method_data
.val
= NULL
;
1268 ret
= realloc_method_data(&method_data
);
1270 free_METHOD_DATA(&method_data
);
1273 pa
= &method_data
.val
[method_data
.len
-1];
1274 pa
->padata_type
= KRB5_PADATA_ENC_TIMESTAMP
;
1275 pa
->padata_value
.length
= 0;
1276 pa
->padata_value
.data
= NULL
;
1279 ret
= realloc_method_data(&method_data
);
1281 free_METHOD_DATA(&method_data
);
1284 pa
= &method_data
.val
[method_data
.len
-1];
1285 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ
;
1286 pa
->padata_value
.length
= 0;
1287 pa
->padata_value
.data
= NULL
;
1289 ret
= realloc_method_data(&method_data
);
1291 free_METHOD_DATA(&method_data
);
1294 pa
= &method_data
.val
[method_data
.len
-1];
1295 pa
->padata_type
= KRB5_PADATA_PK_AS_REQ_WIN
;
1296 pa
->padata_value
.length
= 0;
1297 pa
->padata_value
.data
= NULL
;
1301 * If there is a client key, send ETYPE_INFO{,2}
1307 * - If the client only knows about old enctypes, then send
1308 * both info replies (we send 'info' first in the list).
1309 * - If the client is 'modern', because it knows about 'new'
1310 * enctype types, then only send the 'info2' reply.
1312 * Before we send the full list of etype-info data, we pick
1313 * the client key we would have used anyway below, just pick
1317 if (older_enctype(ckey
->key
.keytype
)) {
1318 ret
= get_pa_etype_info(context
, config
,
1319 &method_data
, ckey
);
1321 free_METHOD_DATA(&method_data
);
1325 ret
= get_pa_etype_info2(context
, config
,
1326 &method_data
, ckey
);
1328 free_METHOD_DATA(&method_data
);
1333 ASN1_MALLOC_ENCODE(METHOD_DATA
, buf
, len
, &method_data
, &len
, ret
);
1334 free_METHOD_DATA(&method_data
);
1337 e_data
.length
= len
;
1338 e_text
="Need to use PA-ENC-TIMESTAMP/PA-PK-AS-REQ",
1340 ret
= KRB5KDC_ERR_PREAUTH_REQUIRED
;
1342 kdc_log(context
, config
, 0,
1343 "No preauth found, returning PREAUTH-REQUIRED -- %s",
1348 if (clientdb
->hdb_auth_status
)
1349 (clientdb
->hdb_auth_status
)(context
, clientdb
, client
,
1353 * Verify flags after the user been required to prove its identity
1354 * with in a preauth mech.
1357 ret
= _kdc_check_access(context
, config
, client
, client_name
,
1358 server
, server_name
,
1364 * Selelct the best encryption type for the KDC with out regard to
1365 * the client since the client never needs to read that data.
1368 ret
= _kdc_get_preferred_key(context
, config
,
1369 server
, server_name
,
1375 * Select a session enctype from the list of the crypto systems
1376 * supported enctype, is supported by the client and is one of the
1377 * enctype of the enctype of the krbtgt.
1379 * The later is used as a hint what enctype all KDC are supporting
1380 * to make sure a newer version of KDC wont generate a session
1381 * enctype that and older version of a KDC in the same realm can't
1384 * But if the KDC admin is paranoid and doesn't want to have "no
1385 * the best" enctypes on the krbtgt, lets save the best pick from
1386 * the client list and hope that that will work for any other
1390 const krb5_enctype
*p
;
1391 krb5_enctype clientbest
= ETYPE_NULL
;
1394 p
= krb5_kerberos_enctypes(context
);
1396 sessionetype
= ETYPE_NULL
;
1398 for (i
= 0; p
[i
] != ETYPE_NULL
&& sessionetype
== ETYPE_NULL
; i
++) {
1399 if (krb5_enctype_valid(context
, p
[i
]) != 0)
1402 for (j
= 0; j
< b
->etype
.len
&& sessionetype
== ETYPE_NULL
; j
++) {
1404 /* check with client */
1405 if (p
[i
] != b
->etype
.val
[j
])
1407 /* save best of union of { client, crypto system } */
1408 if (clientbest
== ETYPE_NULL
)
1410 /* check with krbtgt */
1411 ret
= hdb_enctype2key(context
, &server
->entry
, p
[i
], &dummy
);
1414 sessionetype
= p
[i
];
1417 /* if krbtgt had no shared keys with client, pick clients best */
1418 if (clientbest
!= ETYPE_NULL
&& sessionetype
== ETYPE_NULL
) {
1419 sessionetype
= clientbest
;
1420 } else if (sessionetype
== ETYPE_NULL
) {
1421 kdc_log(context
, config
, 0,
1422 "Client (%s) from %s has no common enctypes with KDC"
1423 "to use for the session key",
1429 log_as_req(context
, config
, cetype
, setype
, b
);
1431 if(f
.renew
|| f
.validate
|| f
.proxy
|| f
.forwarded
|| f
.enc_tkt_in_skey
1432 || (f
.request_anonymous
&& !config
->allow_anonymous
)) {
1433 ret
= KRB5KDC_ERR_BADOPTION
;
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 ret
= KRB5KDC_ERR_POLICY
;
1464 kdc_log(context
, config
, 0,
1465 "Ticket may not be forwardable -- %s", client_name
);
1468 if(client
->entry
.flags
.proxiable
&& server
->entry
.flags
.proxiable
)
1469 et
.flags
.proxiable
= f
.proxiable
;
1470 else if (f
.proxiable
) {
1471 ret
= KRB5KDC_ERR_POLICY
;
1472 kdc_log(context
, config
, 0,
1473 "Ticket may not be proxiable -- %s", client_name
);
1476 if(client
->entry
.flags
.postdate
&& server
->entry
.flags
.postdate
)
1477 et
.flags
.may_postdate
= f
.allow_postdate
;
1478 else if (f
.allow_postdate
){
1479 ret
= KRB5KDC_ERR_POLICY
;
1480 kdc_log(context
, config
, 0,
1481 "Ticket may not be postdatable -- %s", client_name
);
1485 /* check for valid set of addresses */
1486 if(!_kdc_check_addresses(context
, config
, b
->addresses
, from_addr
)) {
1487 ret
= KRB5KRB_AP_ERR_BADADDR
;
1488 kdc_log(context
, config
, 0,
1489 "Bad address list requested -- %s", client_name
);
1493 ret
= copy_PrincipalName(&rep
.cname
, &et
.cname
);
1496 ret
= copy_Realm(&rep
.crealm
, &et
.crealm
);
1504 start
= et
.authtime
= kdc_time
;
1506 if(f
.postdated
&& req
->req_body
.from
){
1507 ALLOC(et
.starttime
);
1508 start
= *et
.starttime
= *req
->req_body
.from
;
1509 et
.flags
.invalid
= 1;
1510 et
.flags
.postdated
= 1; /* XXX ??? */
1512 _kdc_fix_time(&b
->till
);
1515 /* be careful not overflowing */
1517 if(client
->entry
.max_life
)
1518 t
= start
+ min(t
- start
, *client
->entry
.max_life
);
1519 if(server
->entry
.max_life
)
1520 t
= start
+ min(t
- start
, *server
->entry
.max_life
);
1522 t
= min(t
, start
+ realm
->max_life
);
1525 if(f
.renewable_ok
&& et
.endtime
< *b
->till
){
1527 if(b
->rtime
== NULL
){
1531 if(*b
->rtime
< *b
->till
)
1532 *b
->rtime
= *b
->till
;
1534 if(f
.renewable
&& b
->rtime
){
1538 if(client
->entry
.max_renew
)
1539 t
= start
+ min(t
- start
, *client
->entry
.max_renew
);
1540 if(server
->entry
.max_renew
)
1541 t
= start
+ min(t
- start
, *server
->entry
.max_renew
);
1543 t
= min(t
, start
+ realm
->max_renew
);
1545 ALLOC(et
.renew_till
);
1547 et
.flags
.renewable
= 1;
1551 if (f
.request_anonymous
)
1552 et
.flags
.anonymous
= 1;
1556 copy_HostAddresses(b
->addresses
, et
.caddr
);
1559 et
.transited
.tr_type
= DOMAIN_X500_COMPRESS
;
1560 krb5_data_zero(&et
.transited
.contents
);
1562 /* The MIT ASN.1 library (obviously) doesn't tell lengths encoded
1563 * as 0 and as 0x80 (meaning indefinite length) apart, and is thus
1564 * incapable of correctly decoding SEQUENCE OF's of zero length.
1566 * To fix this, always send at least one no-op last_req
1568 * If there's a pw_end or valid_end we will use that,
1569 * otherwise just a dummy lr.
1571 ek
.last_req
.val
= malloc(2 * sizeof(*ek
.last_req
.val
));
1572 if (ek
.last_req
.val
== NULL
) {
1576 ek
.last_req
.len
= 0;
1577 if (client
->entry
.pw_end
1578 && (config
->kdc_warn_pwexpire
== 0
1579 || kdc_time
+ config
->kdc_warn_pwexpire
>= *client
->entry
.pw_end
)) {
1580 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_PW_EXPTIME
;
1581 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.pw_end
;
1584 if (client
->entry
.valid_end
) {
1585 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_ACCT_EXPTIME
;
1586 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= *client
->entry
.valid_end
;
1589 if (ek
.last_req
.len
== 0) {
1590 ek
.last_req
.val
[ek
.last_req
.len
].lr_type
= LR_NONE
;
1591 ek
.last_req
.val
[ek
.last_req
.len
].lr_value
= 0;
1594 ek
.nonce
= b
->nonce
;
1595 if (client
->entry
.valid_end
|| client
->entry
.pw_end
) {
1596 ALLOC(ek
.key_expiration
);
1597 if (client
->entry
.valid_end
) {
1598 if (client
->entry
.pw_end
)
1599 *ek
.key_expiration
= min(*client
->entry
.valid_end
,
1600 *client
->entry
.pw_end
);
1602 *ek
.key_expiration
= *client
->entry
.valid_end
;
1604 *ek
.key_expiration
= *client
->entry
.pw_end
;
1606 ek
.key_expiration
= NULL
;
1607 ek
.flags
= et
.flags
;
1608 ek
.authtime
= et
.authtime
;
1610 ALLOC(ek
.starttime
);
1611 *ek
.starttime
= *et
.starttime
;
1613 ek
.endtime
= et
.endtime
;
1614 if (et
.renew_till
) {
1615 ALLOC(ek
.renew_till
);
1616 *ek
.renew_till
= *et
.renew_till
;
1618 copy_Realm(&rep
.ticket
.realm
, &ek
.srealm
);
1619 copy_PrincipalName(&rep
.ticket
.sname
, &ek
.sname
);
1622 copy_HostAddresses(et
.caddr
, ek
.caddr
);
1626 rep
.padata
->len
= 0;
1627 rep
.padata
->val
= NULL
;
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
,
1646 reply_key
= &ckey
->key
;
1647 ret
= krb5_generate_random_keyblock(context
, sessionetype
, &et
.key
);
1651 e_text
= "Client have no reply key";
1652 ret
= KRB5KDC_ERR_CLIENT_NOTYET
;
1656 ret
= copy_EncryptionKey(&et
.key
, &ek
.key
);
1661 set_salt_padata (rep
.padata
, ckey
->salt
);
1663 /* Add signing of alias referral */
1664 if (f
.canonicalize
) {
1665 PA_ClientCanonicalized canon
;
1671 memset(&canon
, 0, sizeof(canon
));
1673 canon
.names
.requested_name
= *b
->cname
;
1674 canon
.names
.mapped_name
= client
->entry
.principal
->name
;
1676 ASN1_MALLOC_ENCODE(PA_ClientCanonicalizedNames
, data
.data
, data
.length
,
1677 &canon
.names
, &len
, ret
);
1680 if (data
.length
!= len
)
1681 krb5_abortx(context
, "internal asn.1 error");
1683 /* sign using "returned session key" */
1684 ret
= krb5_crypto_init(context
, &et
.key
, 0, &crypto
);
1690 ret
= krb5_create_checksum(context
, crypto
,
1691 KRB5_KU_CANONICALIZED_NAMES
, 0,
1692 data
.data
, data
.length
,
1693 &canon
.canon_checksum
);
1695 krb5_crypto_destroy(context
, crypto
);
1699 ASN1_MALLOC_ENCODE(PA_ClientCanonicalized
, data
.data
, data
.length
,
1701 free_Checksum(&canon
.canon_checksum
);
1704 if (data
.length
!= len
)
1705 krb5_abortx(context
, "internal asn.1 error");
1707 pa
.padata_type
= KRB5_PADATA_CLIENT_CANONICALIZED
;
1708 pa
.padata_value
= data
;
1709 ret
= add_METHOD_DATA(rep
.padata
, &pa
);
1715 if (rep
.padata
->len
== 0) {
1721 if (send_pac_p(context
, req
)) {
1725 ret
= _kdc_pac_generate(context
, client
, &p
);
1727 kdc_log(context
, config
, 0, "PAC generation failed for -- %s",
1732 ret
= _krb5_pac_sign(context
, p
, et
.authtime
,
1733 client
->entry
.principal
,
1734 &skey
->key
, /* Server key */
1735 &skey
->key
, /* FIXME: should be krbtgt key */
1737 krb5_pac_free(context
, p
);
1739 kdc_log(context
, config
, 0, "PAC signing failed for -- %s",
1744 ret
= _kdc_tkt_add_if_relevant_ad(context
, &et
,
1745 KRB5_AUTHDATA_WIN2K_PAC
,
1747 krb5_data_free(&data
);
1753 _kdc_log_timestamp(context
, config
, "AS-REQ", et
.authtime
, et
.starttime
,
1754 et
.endtime
, et
.renew_till
);
1756 /* do this as the last thing since this signs the EncTicketPart */
1757 ret
= _kdc_add_KRB5SignedPath(context
,
1761 client
->entry
.principal
,
1768 ret
= _kdc_encode_reply(context
, config
,
1769 &rep
, &et
, &ek
, setype
, server
->entry
.kvno
,
1770 &skey
->key
, client
->entry
.kvno
,
1771 reply_key
, 0, &e_text
, reply
);
1772 free_EncTicketPart(&et
);
1773 free_EncKDCRepPart(&ek
);
1778 if (datagram_reply
&& reply
->length
> config
->max_datagram_reply_length
) {
1779 krb5_data_free(reply
);
1780 ret
= KRB5KRB_ERR_RESPONSE_TOO_BIG
;
1781 e_text
= "Reply packet too large";
1787 krb5_mk_error(context
,
1790 (e_data
.data
? &e_data
: NULL
),
1800 _kdc_pk_free_client_param(context
, pkp
);
1805 krb5_free_principal(context
, client_princ
);
1808 krb5_free_principal(context
, server_princ
);
1811 _kdc_free_ent(context
, client
);
1813 _kdc_free_ent(context
, server
);
1818 * Add the AuthorizationData `data´ of `type´ to the last element in
1819 * the sequence of authorization_data in `tkt´ wrapped in an IF_RELEVANT
1823 _kdc_tkt_add_if_relevant_ad(krb5_context context
,
1826 const krb5_data
*data
)
1828 krb5_error_code ret
;
1831 if (tkt
->authorization_data
== NULL
) {
1832 tkt
->authorization_data
= calloc(1, sizeof(*tkt
->authorization_data
));
1833 if (tkt
->authorization_data
== NULL
) {
1834 krb5_set_error_message(context
, ENOMEM
, "out of memory");
1839 /* add the entry to the last element */
1841 AuthorizationData ad
= { 0, NULL
};
1842 AuthorizationDataElement ade
;
1845 ade
.ad_data
= *data
;
1847 ret
= add_AuthorizationData(&ad
, &ade
);
1849 krb5_set_error_message(context
, ret
, "add AuthorizationData failed");
1853 ade
.ad_type
= KRB5_AUTHDATA_IF_RELEVANT
;
1855 ASN1_MALLOC_ENCODE(AuthorizationData
,
1856 ade
.ad_data
.data
, ade
.ad_data
.length
,
1858 free_AuthorizationData(&ad
);
1860 krb5_set_error_message(context
, ret
, "ASN.1 encode of "
1861 "AuthorizationData failed");
1864 if (ade
.ad_data
.length
!= size
)
1865 krb5_abortx(context
, "internal asn.1 encoder error");
1867 ret
= add_AuthorizationData(tkt
->authorization_data
, &ade
);
1868 der_free_octet_string(&ade
.ad_data
);
1870 krb5_set_error_message(context
, ret
, "add AuthorizationData failed");