2 * Copyright (c) 1997 - 2008 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
34 #include "krb5_locl.h"
38 krb5_error_code KRB5_LIB_FUNCTION
39 krb5_init_etype (krb5_context context
,
42 const krb5_enctype
*etypes
)
46 krb5_enctype
*tmp
= NULL
;
50 ret
= krb5_get_default_in_tkt_etypes(context
,
57 for (i
= 0; etypes
[i
]; ++i
)
60 *val
= malloc(i
* sizeof(**val
));
61 if (i
!= 0 && *val
== NULL
) {
63 krb5_set_error_string(context
, "malloc: out of memory");
75 static krb5_error_code
76 check_server_referral(krb5_context context
,
79 krb5_const_principal requested
,
80 krb5_const_principal returned
,
81 const krb5_keyblock
const * key
)
84 PA_ServerReferralData ref
;
92 if (rep
->kdc_rep
.padata
== NULL
)
95 pa
= krb5_find_padata(rep
->kdc_rep
.padata
->val
,
96 rep
->kdc_rep
.padata
->len
,
97 KRB5_PADATA_SERVER_REFERRAL
, &i
);
101 memset(&ed
, 0, sizeof(ed
));
102 memset(&ref
, 0, sizeof(ref
));
104 ret
= decode_EncryptedData(pa
->padata_value
.data
,
105 pa
->padata_value
.length
,
109 if (len
!= pa
->padata_value
.length
) {
110 free_EncryptedData(&ed
);
111 krb5_set_error_string(context
, "Referral EncryptedData wrong");
112 return KRB5KRB_AP_ERR_MODIFIED
;
115 ret
= krb5_crypto_init(context
, key
, 0, &session
);
117 free_EncryptedData(&ed
);
121 ret
= krb5_decrypt_EncryptedData(context
, session
,
122 KRB5_KU_PA_SERVER_REFERRAL
,
124 free_EncryptedData(&ed
);
125 krb5_crypto_destroy(context
, session
);
129 ret
= decode_PA_ServerReferralData(data
.data
, data
.length
, &ref
, &len
);
131 krb5_data_free(&data
);
134 krb5_data_free(&data
);
136 if (strcmp(requested
->realm
, returned
->realm
) != 0) {
137 free_PA_ServerReferralData(&ref
);
138 krb5_set_error_string(context
, "server ref realm mismatch");
139 return KRB5KRB_AP_ERR_MODIFIED
;
142 if (returned
->name
.name_string
.len
== 2 &&
143 strcmp(returned
->name
.name_string
.val
[0], KRB5_TGS_NAME
) == 0)
145 const char *realm
= returned
->name
.name_string
.val
[1];
147 if (ref
.referred_realm
== NULL
148 || strcmp(*ref
.referred_realm
, realm
) != 0)
150 free_PA_ServerReferralData(&ref
);
151 krb5_set_error_string(context
, "tgt returned with wrong ref");
152 return KRB5KRB_AP_ERR_MODIFIED
;
154 } else if (krb5_principal_compare(context
, returned
, requested
) == 0) {
155 free_PA_ServerReferralData(&ref
);
156 krb5_set_error_string(context
, "req princ no same as returned");
157 return KRB5KRB_AP_ERR_MODIFIED
;
160 if (ref
.requested_principal_name
) {
161 cmp
= _krb5_principal_compare_PrincipalName(context
,
163 ref
.requested_principal_name
);
165 free_PA_ServerReferralData(&ref
);
166 krb5_set_error_string(context
, "compare requested failed");
167 return KRB5KRB_AP_ERR_MODIFIED
;
169 } else if (flags
& EXTRACT_TICKET_AS_REQ
) {
170 free_PA_ServerReferralData(&ref
);
171 krb5_set_error_string(context
, "Requested principal missing on AS-REQ");
172 return KRB5KRB_AP_ERR_MODIFIED
;
175 free_PA_ServerReferralData(&ref
);
179 if (krb5_principal_compare(context
, requested
, returned
) == FALSE
) {
180 krb5_set_error_string(context
, "Not same server principal returned "
182 return KRB5KRB_AP_ERR_MODIFIED
;
189 * Verify referral data
193 static krb5_error_code
194 check_client_referral(krb5_context context
,
196 krb5_const_principal requested
,
197 krb5_const_principal mapped
,
198 krb5_keyblock
const * key
)
201 PA_ClientCanonicalized canon
;
208 if (rep
->kdc_rep
.padata
== NULL
)
211 pa
= krb5_find_padata(rep
->kdc_rep
.padata
->val
,
212 rep
->kdc_rep
.padata
->len
,
213 KRB5_PADATA_CLIENT_CANONICALIZED
, &i
);
217 ret
= decode_PA_ClientCanonicalized(pa
->padata_value
.data
,
218 pa
->padata_value
.length
,
221 krb5_set_error_string(context
, "Failed to decode "
222 "PA_ClientCanonicalized");
226 ASN1_MALLOC_ENCODE(PA_ClientCanonicalizedNames
, data
.data
, data
.length
,
227 &canon
.names
, &len
, ret
);
229 free_PA_ClientCanonicalized(&canon
);
232 if (data
.length
!= len
)
233 krb5_abortx(context
, "internal asn.1 error");
235 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
238 free_PA_ClientCanonicalized(&canon
);
242 ret
= krb5_verify_checksum(context
, crypto
, KRB5_KU_CANONICALIZED_NAMES
,
243 data
.data
, data
.length
,
244 &canon
.canon_checksum
);
245 krb5_crypto_destroy(context
, crypto
);
248 krb5_set_error_string(context
, "Failed to verify "
249 "client canonicalized data");
250 free_PA_ClientCanonicalized(&canon
);
254 if (!_krb5_principal_compare_PrincipalName(context
,
256 &canon
.names
.requested_name
))
258 free_PA_ClientCanonicalized(&canon
);
259 krb5_set_error_string(context
, "Requested name doesn't match"
260 " in client referral");
261 return KRB5_PRINC_NOMATCH
;
263 if (!_krb5_principal_compare_PrincipalName(context
,
265 &canon
.names
.mapped_name
))
267 free_PA_ClientCanonicalized(&canon
);
268 krb5_set_error_string(context
, "Mapped name doesn't match"
269 " in client referral");
270 return KRB5_PRINC_NOMATCH
;
276 if (krb5_principal_compare(context
, requested
, mapped
) == FALSE
) {
277 krb5_set_error_string(context
, "Not same client principal returned "
279 return KRB5KRB_AP_ERR_MODIFIED
;
286 static krb5_error_code
287 decrypt_tkt (krb5_context context
,
289 krb5_key_usage usage
,
290 krb5_const_pointer decrypt_arg
,
291 krb5_kdc_rep
*dec_rep
)
298 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
302 ret
= krb5_decrypt_EncryptedData (context
,
305 &dec_rep
->kdc_rep
.enc_part
,
307 krb5_crypto_destroy(context
, crypto
);
312 ret
= krb5_decode_EncASRepPart(context
,
318 ret
= krb5_decode_EncTGSRepPart(context
,
323 krb5_data_free (&data
);
330 _krb5_extract_ticket(krb5_context context
,
334 krb5_const_pointer keyseed
,
335 krb5_key_usage key_usage
,
336 krb5_addresses
*addrs
,
339 krb5_decrypt_proc decrypt_proc
,
340 krb5_const_pointer decryptarg
)
343 krb5_principal tmp_principal
;
346 krb5_timestamp sec_now
;
350 if (decrypt_proc
== NULL
)
351 decrypt_proc
= decrypt_tkt
;
353 ret
= (*decrypt_proc
)(context
, key
, key_usage
, decryptarg
, rep
);
357 /* save session key */
359 creds
->session
.keyvalue
.length
= 0;
360 creds
->session
.keyvalue
.data
= NULL
;
361 creds
->session
.keytype
= rep
->enc_part
.key
.keytype
;
362 ret
= krb5_data_copy (&creds
->session
.keyvalue
,
363 rep
->enc_part
.key
.keyvalue
.data
,
364 rep
->enc_part
.key
.keyvalue
.length
);
366 krb5_clear_error_string(context
);
370 /* compare client and save */
371 ret
= _krb5_principalname2krb5_principal (context
,
374 rep
->kdc_rep
.crealm
);
378 /* check client referral and save principal */
379 /* anonymous here ? */
380 if((flags
& EXTRACT_TICKET_ALLOW_CNAME_MISMATCH
) == 0) {
381 ret
= check_client_referral(context
, rep
,
386 krb5_free_principal (context
, tmp_principal
);
390 krb5_free_principal (context
, creds
->client
);
391 creds
->client
= tmp_principal
;
393 /* check server referral and save principal */
394 ret
= _krb5_principalname2krb5_principal (context
,
396 rep
->kdc_rep
.ticket
.sname
,
397 rep
->kdc_rep
.ticket
.realm
);
400 if((flags
& EXTRACT_TICKET_ALLOW_SERVER_MISMATCH
) == 0){
401 ret
= check_server_referral(context
,
408 krb5_free_principal (context
, tmp_principal
);
412 krb5_free_principal(context
, creds
->server
);
413 creds
->server
= tmp_principal
;
416 if(flags
& EXTRACT_TICKET_MATCH_REALM
){
417 const char *srealm
= krb5_principal_get_realm(context
, creds
->server
);
418 const char *crealm
= krb5_principal_get_realm(context
, creds
->client
);
420 if (strcmp(rep
->enc_part
.srealm
, srealm
) != 0 ||
421 strcmp(rep
->enc_part
.srealm
, crealm
) != 0)
423 ret
= KRB5KRB_AP_ERR_MODIFIED
;
424 krb5_clear_error_string(context
);
431 if (nonce
!= rep
->enc_part
.nonce
) {
432 ret
= KRB5KRB_AP_ERR_MODIFIED
;
433 krb5_set_error_string(context
, "malloc: out of memory");
439 krb5_timeofday (context
, &sec_now
);
440 if (rep
->enc_part
.flags
.initial
441 && context
->kdc_sec_offset
== 0
442 && krb5_config_get_bool (context
, NULL
,
446 context
->kdc_sec_offset
= rep
->enc_part
.authtime
- sec_now
;
447 krb5_timeofday (context
, &sec_now
);
450 /* check all times */
452 if (rep
->enc_part
.starttime
) {
453 tmp_time
= *rep
->enc_part
.starttime
;
455 tmp_time
= rep
->enc_part
.authtime
;
457 if (creds
->times
.starttime
== 0
458 && abs(tmp_time
- sec_now
) > context
->max_skew
) {
459 ret
= KRB5KRB_AP_ERR_SKEW
;
460 krb5_set_error_string (context
,
461 "time skew (%d) larger than max (%d)",
462 abs(tmp_time
- sec_now
),
463 (int)context
->max_skew
);
467 if (creds
->times
.starttime
!= 0
468 && tmp_time
!= creds
->times
.starttime
) {
469 krb5_clear_error_string (context
);
470 ret
= KRB5KRB_AP_ERR_MODIFIED
;
474 creds
->times
.starttime
= tmp_time
;
476 if (rep
->enc_part
.renew_till
) {
477 tmp_time
= *rep
->enc_part
.renew_till
;
481 if (creds
->times
.renew_till
!= 0
482 && tmp_time
> creds
->times
.renew_till
) {
483 krb5_clear_error_string (context
);
484 ret
= KRB5KRB_AP_ERR_MODIFIED
;
488 creds
->times
.renew_till
= tmp_time
;
490 creds
->times
.authtime
= rep
->enc_part
.authtime
;
492 if (creds
->times
.endtime
!= 0
493 && rep
->enc_part
.endtime
> creds
->times
.endtime
) {
494 krb5_clear_error_string (context
);
495 ret
= KRB5KRB_AP_ERR_MODIFIED
;
499 creds
->times
.endtime
= rep
->enc_part
.endtime
;
501 if(rep
->enc_part
.caddr
)
502 krb5_copy_addresses (context
, rep
->enc_part
.caddr
, &creds
->addresses
);
504 krb5_copy_addresses (context
, addrs
, &creds
->addresses
);
506 creds
->addresses
.len
= 0;
507 creds
->addresses
.val
= NULL
;
509 creds
->flags
.b
= rep
->enc_part
.flags
;
511 creds
->authdata
.len
= 0;
512 creds
->authdata
.val
= NULL
;
515 ASN1_MALLOC_ENCODE(Ticket
, creds
->ticket
.data
, creds
->ticket
.length
,
516 &rep
->kdc_rep
.ticket
, &len
, ret
);
519 if (creds
->ticket
.length
!= len
)
520 krb5_abortx(context
, "internal error in ASN.1 encoder");
521 creds
->second_ticket
.length
= 0;
522 creds
->second_ticket
.data
= NULL
;
526 memset (rep
->enc_part
.key
.keyvalue
.data
, 0,
527 rep
->enc_part
.key
.keyvalue
.length
);
532 static krb5_error_code
533 make_pa_enc_timestamp(krb5_context context
, PA_DATA
*pa
,
534 krb5_enctype etype
, krb5_keyblock
*key
)
540 EncryptedData encdata
;
546 krb5_us_timeofday (context
, &p
.patimestamp
, &usec
);
550 ASN1_MALLOC_ENCODE(PA_ENC_TS_ENC
, buf
, buf_size
, &p
, &len
, ret
);
554 krb5_abortx(context
, "internal error in ASN.1 encoder");
555 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
560 ret
= krb5_encrypt_EncryptedData(context
,
562 KRB5_KU_PA_ENC_TIMESTAMP
,
568 krb5_crypto_destroy(context
, crypto
);
572 ASN1_MALLOC_ENCODE(EncryptedData
, buf
, buf_size
, &encdata
, &len
, ret
);
573 free_EncryptedData(&encdata
);
577 krb5_abortx(context
, "internal error in ASN.1 encoder");
578 pa
->padata_type
= KRB5_PADATA_ENC_TIMESTAMP
;
579 pa
->padata_value
.length
= len
;
580 pa
->padata_value
.data
= buf
;
584 static krb5_error_code
585 add_padata(krb5_context context
,
587 krb5_principal client
,
588 krb5_key_proc key_proc
,
589 krb5_const_pointer keyseed
,
590 krb5_enctype
*enctypes
,
601 /* default to standard salt */
602 ret
= krb5_get_pw_salt (context
, client
, &salt2
);
606 enctypes
= context
->etypes
;
608 for (ep
= enctypes
; *ep
!= ETYPE_NULL
; ep
++)
611 pa2
= realloc (md
->val
, (md
->len
+ netypes
) * sizeof(*md
->val
));
613 krb5_set_error_string(context
, "malloc: out of memory");
618 for (i
= 0; i
< netypes
; ++i
) {
621 ret
= (*key_proc
)(context
, enctypes
[i
], *salt
, keyseed
, &key
);
624 ret
= make_pa_enc_timestamp (context
, &md
->val
[md
->len
],
626 krb5_free_keyblock (context
, key
);
632 krb5_free_salt(context
, salt2
);
636 static krb5_error_code
637 init_as_req (krb5_context context
,
640 const krb5_addresses
*addrs
,
641 const krb5_enctype
*etypes
,
642 const krb5_preauthtype
*ptypes
,
643 const krb5_preauthdata
*preauth
,
644 krb5_key_proc key_proc
,
645 krb5_const_pointer keyseed
,
652 memset(a
, 0, sizeof(*a
));
655 a
->msg_type
= krb_as_req
;
656 a
->req_body
.kdc_options
= opts
;
657 a
->req_body
.cname
= malloc(sizeof(*a
->req_body
.cname
));
658 if (a
->req_body
.cname
== NULL
) {
660 krb5_set_error_string(context
, "malloc: out of memory");
663 a
->req_body
.sname
= malloc(sizeof(*a
->req_body
.sname
));
664 if (a
->req_body
.sname
== NULL
) {
666 krb5_set_error_string(context
, "malloc: out of memory");
669 ret
= _krb5_principal2principalname (a
->req_body
.cname
, creds
->client
);
672 ret
= _krb5_principal2principalname (a
->req_body
.sname
, creds
->server
);
675 ret
= copy_Realm(&creds
->client
->realm
, &a
->req_body
.realm
);
679 if(creds
->times
.starttime
) {
680 a
->req_body
.from
= malloc(sizeof(*a
->req_body
.from
));
681 if (a
->req_body
.from
== NULL
) {
683 krb5_set_error_string(context
, "malloc: out of memory");
686 *a
->req_body
.from
= creds
->times
.starttime
;
688 if(creds
->times
.endtime
){
689 ALLOC(a
->req_body
.till
, 1);
690 *a
->req_body
.till
= creds
->times
.endtime
;
692 if(creds
->times
.renew_till
){
693 a
->req_body
.rtime
= malloc(sizeof(*a
->req_body
.rtime
));
694 if (a
->req_body
.rtime
== NULL
) {
696 krb5_set_error_string(context
, "malloc: out of memory");
699 *a
->req_body
.rtime
= creds
->times
.renew_till
;
701 a
->req_body
.nonce
= nonce
;
702 ret
= krb5_init_etype (context
,
703 &a
->req_body
.etype
.len
,
704 &a
->req_body
.etype
.val
,
710 * This means no addresses
713 if (addrs
&& addrs
->len
== 0) {
714 a
->req_body
.addresses
= NULL
;
716 a
->req_body
.addresses
= malloc(sizeof(*a
->req_body
.addresses
));
717 if (a
->req_body
.addresses
== NULL
) {
719 krb5_set_error_string(context
, "malloc: out of memory");
724 ret
= krb5_copy_addresses(context
, addrs
, a
->req_body
.addresses
);
726 ret
= krb5_get_all_client_addrs (context
, a
->req_body
.addresses
);
727 if(ret
== 0 && a
->req_body
.addresses
->len
== 0) {
728 free(a
->req_body
.addresses
);
729 a
->req_body
.addresses
= NULL
;
736 a
->req_body
.enc_authorization_data
= NULL
;
737 a
->req_body
.additional_tickets
= NULL
;
739 if(preauth
!= NULL
) {
742 if(a
->padata
== NULL
) {
744 krb5_set_error_string(context
, "malloc: out of memory");
747 a
->padata
->val
= NULL
;
749 for(i
= 0; i
< preauth
->len
; i
++) {
750 if(preauth
->val
[i
].type
== KRB5_PADATA_ENC_TIMESTAMP
){
753 for(j
= 0; j
< preauth
->val
[i
].info
.len
; j
++) {
754 krb5_salt
*sp
= &salt
;
755 if(preauth
->val
[i
].info
.val
[j
].salttype
)
756 salt
.salttype
= *preauth
->val
[i
].info
.val
[j
].salttype
;
758 salt
.salttype
= KRB5_PW_SALT
;
759 if(preauth
->val
[i
].info
.val
[j
].salt
)
760 salt
.saltvalue
= *preauth
->val
[i
].info
.val
[j
].salt
;
762 if(salt
.salttype
== KRB5_PW_SALT
)
765 krb5_data_zero(&salt
.saltvalue
);
766 ret
= add_padata(context
, a
->padata
, creds
->client
,
768 &preauth
->val
[i
].info
.val
[j
].etype
, 1,
776 /* not sure this is the way to use `ptypes' */
777 if (ptypes
== NULL
|| *ptypes
== KRB5_PADATA_NONE
)
779 else if (*ptypes
== KRB5_PADATA_ENC_TIMESTAMP
) {
781 if (a
->padata
== NULL
) {
783 krb5_set_error_string(context
, "malloc: out of memory");
787 a
->padata
->val
= NULL
;
789 /* make a v5 salted pa-data */
790 add_padata(context
, a
->padata
, creds
->client
,
791 key_proc
, keyseed
, a
->req_body
.etype
.val
,
792 a
->req_body
.etype
.len
, NULL
);
794 /* make a v4 salted pa-data */
795 salt
.salttype
= KRB5_PW_SALT
;
796 krb5_data_zero(&salt
.saltvalue
);
797 add_padata(context
, a
->padata
, creds
->client
,
798 key_proc
, keyseed
, a
->req_body
.etype
.val
,
799 a
->req_body
.etype
.len
, &salt
);
801 krb5_set_error_string (context
, "pre-auth type %d not supported",
803 ret
= KRB5_PREAUTH_BAD_TYPE
;
813 set_ptypes(krb5_context context
,
815 const krb5_preauthtype
**ptypes
,
816 krb5_preauthdata
**preauth
)
818 static krb5_preauthdata preauth2
;
819 static krb5_preauthtype ptypes2
[] = { KRB5_PADATA_ENC_TIMESTAMP
, KRB5_PADATA_NONE
};
824 decode_METHOD_DATA(error
->e_data
->data
,
825 error
->e_data
->length
,
828 for(i
= 0; i
< md
.len
; i
++){
829 switch(md
.val
[i
].padata_type
){
830 case KRB5_PADATA_ENC_TIMESTAMP
:
833 case KRB5_PADATA_ETYPE_INFO
:
834 *preauth
= &preauth2
;
835 ALLOC_SEQ(*preauth
, 1);
836 (*preauth
)->val
[0].type
= KRB5_PADATA_ENC_TIMESTAMP
;
837 krb5_decode_ETYPE_INFO(context
,
838 md
.val
[i
].padata_value
.data
,
839 md
.val
[i
].padata_value
.length
,
840 &(*preauth
)->val
[0].info
,
847 free_METHOD_DATA(&md
);
854 krb5_error_code KRB5_LIB_FUNCTION
855 krb5_get_in_cred(krb5_context context
,
857 const krb5_addresses
*addrs
,
858 const krb5_enctype
*etypes
,
859 const krb5_preauthtype
*ptypes
,
860 const krb5_preauthdata
*preauth
,
861 krb5_key_proc key_proc
,
862 krb5_const_pointer keyseed
,
863 krb5_decrypt_proc decrypt_proc
,
864 krb5_const_pointer decryptarg
,
866 krb5_kdc_rep
*ret_as_reply
)
879 krb5_preauthdata
*my_preauth
= NULL
;
883 opts
= int2KDCOptions(options
);
885 krb5_generate_random_block (&nonce
, sizeof(nonce
));
890 ret
= init_as_req (context
,
902 free_ETYPE_INFO(&my_preauth
->val
[0].info
);
903 free (my_preauth
->val
);
909 ASN1_MALLOC_ENCODE(AS_REQ
, req
.data
, req
.length
, &a
, &len
, ret
);
913 if(len
!= req
.length
)
914 krb5_abortx(context
, "internal error in ASN.1 encoder");
916 ret
= krb5_sendto_kdc (context
, &req
, &creds
->client
->realm
, &resp
);
917 krb5_data_free(&req
);
921 memset (&rep
, 0, sizeof(rep
));
922 ret
= decode_AS_REP(resp
.data
, resp
.length
, &rep
.kdc_rep
, &size
);
924 /* let's try to parse it as a KRB-ERROR */
928 ret2
= krb5_rd_error(context
, &resp
, &error
);
929 if(ret2
&& resp
.data
&& ((char*)resp
.data
)[0] == 4)
930 ret
= KRB5KRB_AP_ERR_V4_REPLY
;
931 krb5_data_free(&resp
);
933 ret
= krb5_error_from_rd_error(context
, &error
, creds
);
934 /* if no preauth was set and KDC requires it, give it
936 if (!ptypes
&& !preauth
937 && ret
== KRB5KDC_ERR_PREAUTH_REQUIRED
939 || ret
== KRB5KDC_ERR_BADOPTION
941 && set_ptypes(context
, &error
, &ptypes
, &my_preauth
)) {
943 preauth
= my_preauth
;
944 krb5_free_error_contents(context
, &error
);
945 krb5_clear_error_string(context
);
949 ret_as_reply
->error
= error
;
951 free_KRB_ERROR (&error
);
956 krb5_data_free(&resp
);
960 etype
= rep
.kdc_rep
.enc_part
.etype
;
961 if(rep
.kdc_rep
.padata
){
963 pa
= krb5_find_padata(rep
.kdc_rep
.padata
->val
, rep
.kdc_rep
.padata
->len
,
964 KRB5_PADATA_PW_SALT
, &i
);
967 pa
= krb5_find_padata(rep
.kdc_rep
.padata
->val
,
968 rep
.kdc_rep
.padata
->len
,
969 KRB5_PADATA_AFS3_SALT
, &i
);
973 salt
.salttype
= pa
->padata_type
;
974 salt
.saltvalue
= pa
->padata_value
;
976 ret
= (*key_proc
)(context
, etype
, salt
, keyseed
, &key
);
978 /* make a v5 salted pa-data */
979 ret
= krb5_get_pw_salt (context
, creds
->client
, &salt
);
983 ret
= (*key_proc
)(context
, etype
, salt
, keyseed
, &key
);
984 krb5_free_salt(context
, salt
);
991 if (opts
.request_anonymous
)
992 flags
|= EXTRACT_TICKET_ALLOW_SERVER_MISMATCH
;
994 ret
= _krb5_extract_ticket(context
,
999 KRB5_KU_AS_REP_ENC_PART
,
1006 memset (key
->keyvalue
.data
, 0, key
->keyvalue
.length
);
1007 krb5_free_keyblock_contents (context
, key
);
1011 if (ret
== 0 && ret_as_reply
)
1012 *ret_as_reply
= rep
;
1014 krb5_free_kdc_rep (context
, &rep
);
1018 krb5_error_code KRB5_LIB_FUNCTION
1019 krb5_get_in_tkt(krb5_context context
,
1021 const krb5_addresses
*addrs
,
1022 const krb5_enctype
*etypes
,
1023 const krb5_preauthtype
*ptypes
,
1024 krb5_key_proc key_proc
,
1025 krb5_const_pointer keyseed
,
1026 krb5_decrypt_proc decrypt_proc
,
1027 krb5_const_pointer decryptarg
,
1030 krb5_kdc_rep
*ret_as_reply
)
1032 krb5_error_code ret
;
1034 ret
= krb5_get_in_cred (context
,
1049 ret
= krb5_cc_store_cred (context
, ccache
, creds
);