2 * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "krb5_locl.h"
41 typedef struct krb5_get_init_creds_ctx
{
44 krb5_addresses
*addrs
;
46 krb5_preauthtype
*pre_auth_types
;
55 /* password and keytab_data is freed on completion */
57 krb5_keytab_key_proc_args
*keytab_data
;
59 krb5_pointer
*keyseed
;
60 krb5_s2k_proc keyproc
;
62 krb5_get_init_creds_tristate req_pac
;
64 krb5_pk_init_ctx pk_init_ctx
;
69 #define USED_PKINIT_W2K 2
70 #define USED_ENC_TS_GUESS 4
71 #define USED_ENC_TS_INFO 8
76 EncKDCRepPart enc_part
;
78 krb5_prompter_fct prompter
;
81 struct pa_info_data
*ppaid
;
83 enum PA_FX_FAST_REQUEST_enum type
;
85 #define KRB5_FAST_REPLY_KEY_USE_TO_ENCRYPT_THE_REPLY 1
86 #define KRB5_FAST_REPLY_KEY_USE_IN_TRANSACTION 2
87 #define KRB5_FAST_KDC_REPLY_KEY_REPLACED 4
88 #define KRB5_FAST_REPLY_REPLY_VERIFED 8
89 #define KRB5_FAST_STRONG 16
90 #define KRB5_FAST_EXPECTED 32 /* in exchange with KDC, fast was discovered */
91 #define KRB5_FAST_REQUIRED 64 /* fast required by action of caller */
92 #define KRB5_FAST_DISABLED 128
93 #define KRB5_FAST_AP_ARMOR_SERVICE 256
94 krb5_keyblock
*reply_key
;
95 krb5_ccache armor_ccache
;
96 krb5_principal armor_service
;
97 krb5_crypto armor_crypto
;
98 krb5_keyblock armor_key
;
99 krb5_keyblock
*strengthen_key
;
101 } krb5_get_init_creds_ctx
;
104 struct pa_info_data
{
107 krb5_data
*s2kparams
;
111 free_paid(krb5_context context
, struct pa_info_data
*ppaid
)
113 krb5_free_salt(context
, ppaid
->salt
);
114 if (ppaid
->s2kparams
)
115 krb5_free_data(context
, ppaid
->s2kparams
);
118 static krb5_error_code KRB5_CALLCONV
119 default_s2k_func(krb5_context context
, krb5_enctype type
,
120 krb5_const_pointer keyseed
,
121 krb5_salt salt
, krb5_data
*s2kparms
,
128 _krb5_debug(context
, 5, "krb5_get_init_creds: using default_s2k_func");
130 password
.data
= rk_UNCONST(keyseed
);
131 password
.length
= strlen(keyseed
);
135 krb5_data_zero(&opaque
);
137 *key
= malloc(sizeof(**key
));
140 ret
= krb5_string_to_key_data_salt_opaque(context
, type
, password
,
150 free_init_creds_ctx(krb5_context context
, krb5_init_creds_context ctx
)
154 if (ctx
->pre_auth_types
)
155 free (ctx
->pre_auth_types
);
156 if (ctx
->in_tkt_service
)
157 free(ctx
->in_tkt_service
);
158 if (ctx
->keytab_data
)
159 free(ctx
->keytab_data
);
161 memset(ctx
->password
, 0, strlen(ctx
->password
));
165 * FAST state (we don't close the armor_ccache because we might have
166 * to destroy it, and how would we know? also, the caller should
167 * take care of cleaning up the armor_ccache).
169 if (ctx
->fast_state
.armor_service
)
170 krb5_free_principal(context
, ctx
->fast_state
.armor_service
);
171 if (ctx
->fast_state
.armor_crypto
)
172 krb5_crypto_destroy(context
, ctx
->fast_state
.armor_crypto
);
173 if (ctx
->fast_state
.strengthen_key
)
174 krb5_free_keyblock(context
, ctx
->fast_state
.strengthen_key
);
175 krb5_free_keyblock_contents(context
, &ctx
->fast_state
.armor_key
);
177 krb5_data_free(&ctx
->req_buffer
);
178 krb5_free_cred_contents(context
, &ctx
->cred
);
179 free_METHOD_DATA(&ctx
->md
);
180 free_AS_REP(&ctx
->as_rep
);
181 free_EncKDCRepPart(&ctx
->enc_part
);
182 free_KRB_ERROR(&ctx
->error
);
183 free_AS_REQ(&ctx
->as_req
);
185 free_paid(context
, ctx
->ppaid
);
188 memset(ctx
, 0, sizeof(*ctx
));
192 get_config_time (krb5_context context
,
199 ret
= krb5_config_get_time (context
, NULL
,
206 ret
= krb5_config_get_time (context
, NULL
,
215 static krb5_error_code
216 init_cred (krb5_context context
,
218 krb5_principal client
,
219 krb5_deltat start_time
,
220 krb5_get_init_creds_opt
*options
)
226 krb5_timeofday (context
, &now
);
228 memset (cred
, 0, sizeof(*cred
));
231 krb5_copy_principal(context
, client
, &cred
->client
);
233 ret
= krb5_get_default_principal (context
,
240 cred
->times
.starttime
= now
+ start_time
;
242 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_TKT_LIFE
)
243 tmp
= options
->tkt_life
;
246 cred
->times
.endtime
= now
+ tmp
;
248 if ((options
->flags
& KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE
) &&
249 options
->renew_life
> 0) {
250 cred
->times
.renew_till
= now
+ options
->renew_life
;
256 krb5_free_cred_contents (context
, cred
);
261 * Print a message (str) to the user about the expiration in `lr'
265 report_expiration (krb5_context context
,
266 krb5_prompter_fct prompter
,
273 if (asprintf(&p
, "%s%s", str
, ctime(&now
)) < 0 || p
== NULL
)
275 (*prompter
)(context
, data
, NULL
, p
, 0, NULL
);
280 * Check the context, and in the case there is a expiration warning,
281 * use the prompter to print the warning.
283 * @param context A Kerberos 5 context.
284 * @param options An GIC options structure
285 * @param ctx The krb5_init_creds_context check for expiration.
289 krb5_process_last_request(krb5_context context
,
290 krb5_get_init_creds_opt
*options
,
291 krb5_init_creds_context ctx
)
293 krb5_const_realm realm
;
295 krb5_boolean reported
= FALSE
;
301 * First check if there is a API consumer.
304 realm
= krb5_principal_get_realm (context
, ctx
->cred
.client
);
305 lr
= &ctx
->enc_part
.last_req
;
307 if (options
&& options
->opt_private
&& options
->opt_private
->lr
.func
) {
308 krb5_last_req_entry
**lre
;
310 lre
= calloc(lr
->len
+ 1, sizeof(**lre
));
312 return krb5_enomem(context
);
313 for (i
= 0; i
< lr
->len
; i
++) {
314 lre
[i
] = calloc(1, sizeof(*lre
[i
]));
317 lre
[i
]->lr_type
= lr
->val
[i
].lr_type
;
318 lre
[i
]->value
= lr
->val
[i
].lr_value
;
321 (*options
->opt_private
->lr
.func
)(context
, lre
,
322 options
->opt_private
->lr
.ctx
);
324 for (i
= 0; i
< lr
->len
; i
++)
330 * Now check if we should prompt the user
333 if (ctx
->prompter
== NULL
)
336 krb5_timeofday (context
, &sec
);
338 t
= sec
+ get_config_time (context
,
343 for (i
= 0; i
< lr
->len
; ++i
) {
344 if (lr
->val
[i
].lr_value
<= t
) {
345 switch (abs(lr
->val
[i
].lr_type
)) {
347 report_expiration(context
, ctx
->prompter
,
349 "Your password will expire at ",
350 lr
->val
[i
].lr_value
);
353 case LR_ACCT_EXPTIME
:
354 report_expiration(context
, ctx
->prompter
,
356 "Your account will expire at ",
357 lr
->val
[i
].lr_value
);
365 && ctx
->enc_part
.key_expiration
366 && *ctx
->enc_part
.key_expiration
<= t
) {
367 report_expiration(context
, ctx
->prompter
,
369 "Your password/account will expire at ",
370 *ctx
->enc_part
.key_expiration
);
375 static krb5_addresses no_addrs
= { 0, NULL
};
377 static krb5_error_code
378 get_init_creds_common(krb5_context context
,
379 krb5_principal client
,
380 krb5_deltat start_time
,
381 krb5_get_init_creds_opt
*options
,
382 krb5_init_creds_context ctx
)
384 krb5_get_init_creds_opt
*default_opt
= NULL
;
386 krb5_enctype
*etypes
;
387 krb5_preauthtype
*pre_auth_types
;
389 memset(ctx
, 0, sizeof(*ctx
));
391 if (options
== NULL
) {
392 const char *realm
= krb5_principal_get_realm(context
, client
);
394 krb5_get_init_creds_opt_alloc (context
, &default_opt
);
395 options
= default_opt
;
396 krb5_get_init_creds_opt_set_default_flags(context
, NULL
, realm
, options
);
399 if (options
->opt_private
) {
400 if (options
->opt_private
->password
) {
401 ret
= krb5_init_creds_set_password(context
, ctx
,
402 options
->opt_private
->password
);
407 ctx
->keyproc
= options
->opt_private
->key_proc
;
408 ctx
->req_pac
= options
->opt_private
->req_pac
;
409 ctx
->pk_init_ctx
= options
->opt_private
->pk_init_ctx
;
410 ctx
->ic_flags
= options
->opt_private
->flags
;
412 ctx
->req_pac
= KRB5_INIT_CREDS_TRISTATE_UNSET
;
414 if (ctx
->keyproc
== NULL
)
415 ctx
->keyproc
= default_s2k_func
;
417 /* Enterprise name implicitly turns on canonicalize */
418 if ((ctx
->ic_flags
& KRB5_INIT_CREDS_CANONICALIZE
) ||
419 krb5_principal_get_type(context
, client
) == KRB5_NT_ENTERPRISE_PRINCIPAL
)
420 ctx
->flags
.canonicalize
= 1;
422 ctx
->pre_auth_types
= NULL
;
425 ctx
->pre_auth_types
= NULL
;
427 ret
= init_cred(context
, &ctx
->cred
, client
, start_time
, options
);
430 krb5_get_init_creds_opt_free(context
, default_opt
);
434 ret
= krb5_init_creds_set_service(context
, ctx
, NULL
);
438 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_FORWARDABLE
)
439 ctx
->flags
.forwardable
= options
->forwardable
;
441 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_PROXIABLE
)
442 ctx
->flags
.proxiable
= options
->proxiable
;
445 ctx
->flags
.postdated
= 1;
446 if (ctx
->cred
.times
.renew_till
)
447 ctx
->flags
.renewable
= 1;
448 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST
) {
449 ctx
->addrs
= options
->address_list
;
450 } else if (options
->opt_private
) {
451 switch (options
->opt_private
->addressless
) {
452 case KRB5_INIT_CREDS_TRISTATE_UNSET
:
453 #if KRB5_ADDRESSLESS_DEFAULT == TRUE
454 ctx
->addrs
= &no_addrs
;
459 case KRB5_INIT_CREDS_TRISTATE_FALSE
:
462 case KRB5_INIT_CREDS_TRISTATE_TRUE
:
463 ctx
->addrs
= &no_addrs
;
467 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST
) {
471 etypes
= malloc((options
->etype_list_length
+ 1)
472 * sizeof(krb5_enctype
));
473 if (etypes
== NULL
) {
474 ret
= krb5_enomem(context
);
477 memcpy (etypes
, options
->etype_list
,
478 options
->etype_list_length
* sizeof(krb5_enctype
));
479 etypes
[options
->etype_list_length
] = ETYPE_NULL
;
480 ctx
->etypes
= etypes
;
482 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST
) {
483 pre_auth_types
= malloc((options
->preauth_list_length
+ 1)
484 * sizeof(krb5_preauthtype
));
485 if (pre_auth_types
== NULL
) {
486 ret
= krb5_enomem(context
);
489 memcpy (pre_auth_types
, options
->preauth_list
,
490 options
->preauth_list_length
* sizeof(krb5_preauthtype
));
491 pre_auth_types
[options
->preauth_list_length
] = KRB5_PADATA_NONE
;
492 ctx
->pre_auth_types
= pre_auth_types
;
494 if (options
->flags
& KRB5_GET_INIT_CREDS_OPT_ANONYMOUS
)
495 ctx
->flags
.request_anonymous
= options
->anonymous
;
497 krb5_get_init_creds_opt_free(context
, default_opt
);
501 krb5_get_init_creds_opt_free(context
, default_opt
);
505 static krb5_error_code
506 change_password (krb5_context context
,
507 krb5_principal client
,
508 const char *password
,
511 krb5_prompter_fct prompter
,
513 krb5_get_init_creds_opt
*old_options
)
515 krb5_prompt prompts
[2];
518 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
519 krb5_data password_data
[2];
521 krb5_data result_code_string
;
522 krb5_data result_string
;
524 krb5_get_init_creds_opt
*options
;
526 memset (&cpw_cred
, 0, sizeof(cpw_cred
));
528 ret
= krb5_get_init_creds_opt_alloc(context
, &options
);
531 krb5_get_init_creds_opt_set_tkt_life (options
, 60);
532 krb5_get_init_creds_opt_set_forwardable (options
, FALSE
);
533 krb5_get_init_creds_opt_set_proxiable (options
, FALSE
);
534 if (old_options
&& old_options
->flags
& KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST
)
535 krb5_get_init_creds_opt_set_preauth_list (options
,
536 old_options
->preauth_list
,
537 old_options
->preauth_list_length
);
539 krb5_data_zero (&result_code_string
);
540 krb5_data_zero (&result_string
);
542 ret
= krb5_get_init_creds_password (context
,
551 krb5_get_init_creds_opt_free(context
, options
);
556 password_data
[0].data
= buf1
;
557 password_data
[0].length
= sizeof(buf1
);
559 prompts
[0].hidden
= 1;
560 prompts
[0].prompt
= "New password: ";
561 prompts
[0].reply
= &password_data
[0];
562 prompts
[0].type
= KRB5_PROMPT_TYPE_NEW_PASSWORD
;
564 password_data
[1].data
= buf2
;
565 password_data
[1].length
= sizeof(buf2
);
567 prompts
[1].hidden
= 1;
568 prompts
[1].prompt
= "Repeat new password: ";
569 prompts
[1].reply
= &password_data
[1];
570 prompts
[1].type
= KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN
;
572 ret
= (*prompter
) (context
, data
, NULL
, "Changing password",
575 memset (buf1
, 0, sizeof(buf1
));
576 memset (buf2
, 0, sizeof(buf2
));
580 if (strcmp (buf1
, buf2
) == 0)
582 memset (buf1
, 0, sizeof(buf1
));
583 memset (buf2
, 0, sizeof(buf2
));
586 ret
= krb5_set_password (context
,
595 if (asprintf(&p
, "%s: %.*s\n",
596 result_code
? "Error" : "Success",
597 (int)result_string
.length
,
598 result_string
.length
> 0 ? (char*)result_string
.data
: "") < 0)
604 /* return the result */
605 (*prompter
) (context
, data
, NULL
, p
, 0, NULL
);
608 if (result_code
== 0) {
609 strlcpy (newpw
, buf1
, newpw_sz
);
613 krb5_set_error_message(context
, ret
,
614 N_("failed changing password", ""));
618 memset (buf1
, 0, sizeof(buf1
));
619 memset (buf2
, 0, sizeof(buf2
));
620 krb5_data_free (&result_string
);
621 krb5_data_free (&result_code_string
);
622 krb5_free_cred_contents (context
, &cpw_cred
);
627 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
628 krb5_keyblock_key_proc (krb5_context context
,
631 krb5_const_pointer keyseed
,
634 return krb5_copy_keyblock (context
, keyseed
, key
);
641 static krb5_error_code
642 init_as_req (krb5_context context
,
644 const krb5_creds
*creds
,
645 const krb5_addresses
*addrs
,
646 const krb5_enctype
*etypes
,
651 memset(a
, 0, sizeof(*a
));
654 a
->msg_type
= krb_as_req
;
655 a
->req_body
.kdc_options
= opts
;
656 a
->req_body
.cname
= malloc(sizeof(*a
->req_body
.cname
));
657 if (a
->req_body
.cname
== NULL
) {
658 ret
= krb5_enomem(context
);
661 a
->req_body
.sname
= malloc(sizeof(*a
->req_body
.sname
));
662 if (a
->req_body
.sname
== NULL
) {
663 ret
= krb5_enomem(context
);
667 ret
= _krb5_principal2principalname (a
->req_body
.cname
, creds
->client
);
670 ret
= copy_Realm(&creds
->client
->realm
, &a
->req_body
.realm
);
674 ret
= _krb5_principal2principalname (a
->req_body
.sname
, creds
->server
);
678 if(creds
->times
.starttime
) {
679 a
->req_body
.from
= malloc(sizeof(*a
->req_body
.from
));
680 if (a
->req_body
.from
== NULL
) {
681 ret
= krb5_enomem(context
);
684 *a
->req_body
.from
= creds
->times
.starttime
;
686 if(creds
->times
.endtime
){
687 ALLOC(a
->req_body
.till
, 1);
688 *a
->req_body
.till
= creds
->times
.endtime
;
690 if(creds
->times
.renew_till
){
691 a
->req_body
.rtime
= malloc(sizeof(*a
->req_body
.rtime
));
692 if (a
->req_body
.rtime
== NULL
) {
693 ret
= krb5_enomem(context
);
696 *a
->req_body
.rtime
= creds
->times
.renew_till
;
698 a
->req_body
.nonce
= 0;
699 ret
= _krb5_init_etype(context
,
701 &a
->req_body
.etype
.len
,
702 &a
->req_body
.etype
.val
,
708 * This means no addresses
711 if (addrs
&& addrs
->len
== 0) {
712 a
->req_body
.addresses
= NULL
;
714 a
->req_body
.addresses
= malloc(sizeof(*a
->req_body
.addresses
));
715 if (a
->req_body
.addresses
== NULL
) {
716 ret
= krb5_enomem(context
);
721 ret
= krb5_copy_addresses(context
, addrs
, a
->req_body
.addresses
);
723 ret
= krb5_get_all_client_addrs (context
, a
->req_body
.addresses
);
724 if(ret
== 0 && a
->req_body
.addresses
->len
== 0) {
725 free(a
->req_body
.addresses
);
726 a
->req_body
.addresses
= NULL
;
733 a
->req_body
.enc_authorization_data
= NULL
;
734 a
->req_body
.additional_tickets
= NULL
;
741 memset(a
, 0, sizeof(*a
));
746 static krb5_error_code
747 set_paid(struct pa_info_data
*paid
, krb5_context context
,
749 krb5_salttype salttype
, void *salt_string
, size_t salt_len
,
750 krb5_data
*s2kparams
)
753 paid
->salt
.salttype
= salttype
;
754 paid
->salt
.saltvalue
.data
= malloc(salt_len
+ 1);
755 if (paid
->salt
.saltvalue
.data
== NULL
) {
756 krb5_clear_error_message(context
);
759 memcpy(paid
->salt
.saltvalue
.data
, salt_string
, salt_len
);
760 ((char *)paid
->salt
.saltvalue
.data
)[salt_len
] = '\0';
761 paid
->salt
.saltvalue
.length
= salt_len
;
765 ret
= krb5_copy_data(context
, s2kparams
, &paid
->s2kparams
);
767 krb5_clear_error_message(context
);
768 krb5_free_salt(context
, paid
->salt
);
772 paid
->s2kparams
= NULL
;
777 static struct pa_info_data
*
778 pa_etype_info2(krb5_context context
,
779 const krb5_principal client
,
781 struct pa_info_data
*paid
,
782 heim_octet_string
*data
)
789 memset(&e
, 0, sizeof(e
));
790 ret
= decode_ETYPE_INFO2(data
->data
, data
->length
, &e
, &sz
);
795 for (j
= 0; j
< asreq
->req_body
.etype
.len
; j
++) {
796 for (i
= 0; i
< e
.len
; i
++) {
797 if (asreq
->req_body
.etype
.val
[j
] == e
.val
[i
].etype
) {
799 if (e
.val
[i
].salt
== NULL
)
800 ret
= krb5_get_pw_salt(context
, client
, &salt
);
802 salt
.saltvalue
.data
= *e
.val
[i
].salt
;
803 salt
.saltvalue
.length
= strlen(*e
.val
[i
].salt
);
807 ret
= set_paid(paid
, context
, e
.val
[i
].etype
,
810 salt
.saltvalue
.length
,
812 if (e
.val
[i
].salt
== NULL
)
813 krb5_free_salt(context
, salt
);
815 free_ETYPE_INFO2(&e
);
822 free_ETYPE_INFO2(&e
);
826 static struct pa_info_data
*
827 pa_etype_info(krb5_context context
,
828 const krb5_principal client
,
830 struct pa_info_data
*paid
,
831 heim_octet_string
*data
)
838 memset(&e
, 0, sizeof(e
));
839 ret
= decode_ETYPE_INFO(data
->data
, data
->length
, &e
, &sz
);
844 for (j
= 0; j
< asreq
->req_body
.etype
.len
; j
++) {
845 for (i
= 0; i
< e
.len
; i
++) {
846 if (asreq
->req_body
.etype
.val
[j
] == e
.val
[i
].etype
) {
848 salt
.salttype
= KRB5_PW_SALT
;
849 if (e
.val
[i
].salt
== NULL
)
850 ret
= krb5_get_pw_salt(context
, client
, &salt
);
852 salt
.saltvalue
= *e
.val
[i
].salt
;
855 if (e
.val
[i
].salttype
)
856 salt
.salttype
= *e
.val
[i
].salttype
;
858 ret
= set_paid(paid
, context
, e
.val
[i
].etype
,
861 salt
.saltvalue
.length
,
863 if (e
.val
[i
].salt
== NULL
)
864 krb5_free_salt(context
, salt
);
878 static struct pa_info_data
*
879 pa_pw_or_afs3_salt(krb5_context context
,
880 const krb5_principal client
,
882 struct pa_info_data
*paid
,
883 heim_octet_string
*data
)
886 if (paid
->etype
== KRB5_ENCTYPE_NULL
)
888 ret
= set_paid(paid
, context
,
901 krb5_preauthtype type
;
902 struct pa_info_data
*(*salt_info
)(krb5_context
,
903 const krb5_principal
,
905 struct pa_info_data
*,
906 heim_octet_string
*);
909 static struct pa_info pa_prefs
[] = {
910 { KRB5_PADATA_ETYPE_INFO2
, pa_etype_info2
},
911 { KRB5_PADATA_ETYPE_INFO
, pa_etype_info
},
912 { KRB5_PADATA_PW_SALT
, pa_pw_or_afs3_salt
},
913 { KRB5_PADATA_AFS3_SALT
, pa_pw_or_afs3_salt
}
917 find_pa_data(const METHOD_DATA
*md
, unsigned type
)
922 for (i
= 0; i
< md
->len
; i
++)
923 if (md
->val
[i
].padata_type
== type
)
928 static struct pa_info_data
*
929 process_pa_info(krb5_context context
,
930 const krb5_principal client
,
932 struct pa_info_data
*paid
,
935 struct pa_info_data
*p
= NULL
;
938 for (i
= 0; p
== NULL
&& i
< sizeof(pa_prefs
)/sizeof(pa_prefs
[0]); i
++) {
939 PA_DATA
*pa
= find_pa_data(md
, pa_prefs
[i
].type
);
942 paid
->salt
.salttype
= (krb5_salttype
)pa_prefs
[i
].type
;
943 p
= (*pa_prefs
[i
].salt_info
)(context
, client
, asreq
,
944 paid
, &pa
->padata_value
);
949 static krb5_error_code
950 make_pa_enc_timestamp(krb5_context context
, METHOD_DATA
*md
,
951 krb5_enctype etype
, krb5_keyblock
*key
)
957 EncryptedData encdata
;
963 krb5_us_timeofday (context
, &p
.patimestamp
, &usec
);
967 ASN1_MALLOC_ENCODE(PA_ENC_TS_ENC
, buf
, buf_size
, &p
, &len
, ret
);
971 krb5_abortx(context
, "internal error in ASN.1 encoder");
973 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
978 ret
= krb5_encrypt_EncryptedData(context
,
980 KRB5_KU_PA_ENC_TIMESTAMP
,
986 krb5_crypto_destroy(context
, crypto
);
990 ASN1_MALLOC_ENCODE(EncryptedData
, buf
, buf_size
, &encdata
, &len
, ret
);
991 free_EncryptedData(&encdata
);
995 krb5_abortx(context
, "internal error in ASN.1 encoder");
997 ret
= krb5_padata_add(context
, md
, KRB5_PADATA_ENC_TIMESTAMP
, buf
, len
);
1003 static krb5_error_code
1004 add_enc_ts_padata(krb5_context context
,
1006 krb5_principal client
,
1007 krb5_s2k_proc keyproc
,
1008 krb5_const_pointer keyseed
,
1009 krb5_enctype
*enctypes
,
1012 krb5_data
*s2kparams
)
1014 krb5_error_code ret
;
1020 /* default to standard salt */
1021 ret
= krb5_get_pw_salt (context
, client
, &salt2
);
1027 enctypes
= context
->etypes
;
1029 for (ep
= enctypes
; *ep
!= (krb5_enctype
)ETYPE_NULL
; ep
++)
1033 for (i
= 0; i
< netypes
; ++i
) {
1036 _krb5_debug(context
, 5, "krb5_get_init_creds: using ENC-TS with enctype %d", enctypes
[i
]);
1038 ret
= (*keyproc
)(context
, enctypes
[i
], keyseed
,
1039 *salt
, s2kparams
, &key
);
1042 ret
= make_pa_enc_timestamp (context
, md
, enctypes
[i
], key
);
1043 krb5_free_keyblock (context
, key
);
1048 krb5_free_salt(context
, salt2
);
1052 static krb5_error_code
1053 pa_data_to_md_ts_enc(krb5_context context
,
1055 const krb5_principal client
,
1056 krb5_get_init_creds_ctx
*ctx
,
1057 struct pa_info_data
*ppaid
,
1060 if (ctx
->keyproc
== NULL
|| ctx
->keyseed
== NULL
)
1064 add_enc_ts_padata(context
, md
, client
,
1065 ctx
->keyproc
, ctx
->keyseed
,
1067 &ppaid
->salt
, ppaid
->s2kparams
);
1071 _krb5_debug(context
, 5, "krb5_get_init_creds: pa-info not found, guessing salt");
1073 /* make a v5 salted pa-data */
1074 add_enc_ts_padata(context
, md
, client
,
1075 ctx
->keyproc
, ctx
->keyseed
,
1076 a
->req_body
.etype
.val
, a
->req_body
.etype
.len
,
1079 /* make a v4 salted pa-data */
1080 salt
.salttype
= KRB5_PW_SALT
;
1081 krb5_data_zero(&salt
.saltvalue
);
1082 add_enc_ts_padata(context
, md
, client
,
1083 ctx
->keyproc
, ctx
->keyseed
,
1084 a
->req_body
.etype
.val
, a
->req_body
.etype
.len
,
1090 static krb5_error_code
1091 pa_data_to_key_plain(krb5_context context
,
1092 const krb5_principal client
,
1093 krb5_get_init_creds_ctx
*ctx
,
1095 krb5_data
*s2kparams
,
1097 krb5_keyblock
**key
)
1099 krb5_error_code ret
;
1101 ret
= (*ctx
->keyproc
)(context
, etype
, ctx
->keyseed
,
1102 salt
, s2kparams
, key
);
1107 static krb5_error_code
1108 pa_data_to_md_pkinit(krb5_context context
,
1110 const krb5_principal client
,
1112 krb5_get_init_creds_ctx
*ctx
,
1115 if (ctx
->pk_init_ctx
== NULL
)
1118 return _krb5_pk_mk_padata(context
,
1126 krb5_set_error_message(context
, EINVAL
,
1127 N_("no support for PKINIT compiled in", ""));
1132 static krb5_error_code
1133 pa_data_add_pac_request(krb5_context context
,
1134 krb5_get_init_creds_ctx
*ctx
,
1137 size_t len
= 0, length
;
1138 krb5_error_code ret
;
1142 switch (ctx
->req_pac
) {
1143 case KRB5_INIT_CREDS_TRISTATE_UNSET
:
1144 return 0; /* don't bother */
1145 case KRB5_INIT_CREDS_TRISTATE_TRUE
:
1146 req
.include_pac
= 1;
1148 case KRB5_INIT_CREDS_TRISTATE_FALSE
:
1149 req
.include_pac
= 0;
1152 ASN1_MALLOC_ENCODE(PA_PAC_REQUEST
, buf
, length
,
1157 krb5_abortx(context
, "internal error in ASN.1 encoder");
1159 ret
= krb5_padata_add(context
, md
, KRB5_PADATA_PA_PAC_REQUEST
, buf
, len
);
1167 * Assumes caller always will free `out_md', even on error.
1170 static krb5_error_code
1171 process_pa_data_to_md(krb5_context context
,
1172 const krb5_creds
*creds
,
1174 krb5_get_init_creds_ctx
*ctx
,
1176 METHOD_DATA
**out_md
,
1177 krb5_prompter_fct prompter
,
1178 void *prompter_data
)
1180 krb5_error_code ret
;
1183 if (*out_md
== NULL
)
1184 return krb5_enomem(context
);
1187 (*out_md
)->val
= NULL
;
1189 if (_krb5_have_debug(context
, 5)) {
1191 _krb5_debug(context
, 5, "KDC send %d patypes", in_md
->len
);
1192 for (i
= 0; i
< in_md
->len
; i
++)
1193 _krb5_debug(context
, 5, "KDC send PA-DATA type: %d", in_md
->val
[i
].padata_type
);
1197 * Make sure we don't sent both ENC-TS and PK-INIT pa data, no
1198 * need to expose our password protecting our PKCS12 key.
1201 if (ctx
->pk_init_ctx
) {
1203 _krb5_debug(context
, 5, "krb5_get_init_creds: "
1204 "prepareing PKINIT padata (%s)",
1205 (ctx
->used_pa_types
& USED_PKINIT_W2K
) ? "win2k" : "ietf");
1207 if (ctx
->used_pa_types
& USED_PKINIT_W2K
) {
1208 krb5_set_error_message(context
, KRB5_GET_IN_TKT_LOOP
,
1209 "Already tried pkinit, looping");
1210 return KRB5_GET_IN_TKT_LOOP
;
1213 ret
= pa_data_to_md_pkinit(context
, a
, creds
->client
,
1214 (ctx
->used_pa_types
& USED_PKINIT
),
1219 if (ctx
->used_pa_types
& USED_PKINIT
)
1220 ctx
->used_pa_types
|= USED_PKINIT_W2K
;
1222 ctx
->used_pa_types
|= USED_PKINIT
;
1224 } else if (in_md
->len
!= 0) {
1225 struct pa_info_data
*paid
, *ppaid
;
1228 paid
= calloc(1, sizeof(*paid
));
1230 paid
->etype
= KRB5_ENCTYPE_NULL
;
1231 ppaid
= process_pa_info(context
, creds
->client
, a
, paid
, in_md
);
1234 flag
= USED_ENC_TS_INFO
;
1236 flag
= USED_ENC_TS_GUESS
;
1238 if (ctx
->used_pa_types
& flag
) {
1240 free_paid(context
, ppaid
);
1241 krb5_set_error_message(context
, KRB5_GET_IN_TKT_LOOP
,
1242 "Already tried ENC-TS-%s, looping",
1243 flag
== USED_ENC_TS_INFO
? "info" : "guess");
1244 return KRB5_GET_IN_TKT_LOOP
;
1247 pa_data_to_md_ts_enc(context
, a
, creds
->client
, ctx
, ppaid
, *out_md
);
1249 ctx
->used_pa_types
|= flag
;
1253 free_paid(context
, ctx
->ppaid
);
1261 pa_data_add_pac_request(context
, ctx
, *out_md
);
1263 if ((ctx
->fast_state
.flags
& KRB5_FAST_DISABLED
) == 0) {
1264 ret
= krb5_padata_add(context
, *out_md
, KRB5_PADATA_REQ_ENC_PA_REP
, NULL
, 0);
1269 if ((*out_md
)->len
== 0) {
1277 static krb5_error_code
1278 process_pa_data_to_key(krb5_context context
,
1279 krb5_get_init_creds_ctx
*ctx
,
1283 const krb5_krbhst_info
*hi
,
1284 krb5_keyblock
**key
)
1286 struct pa_info_data paid
, *ppaid
= NULL
;
1287 krb5_error_code ret
;
1291 memset(&paid
, 0, sizeof(paid
));
1293 etype
= rep
->enc_part
.etype
;
1297 ppaid
= process_pa_info(context
, creds
->client
, a
, &paid
,
1302 if (ppaid
== NULL
) {
1303 ret
= krb5_get_pw_salt (context
, creds
->client
, &paid
.salt
);
1307 paid
.s2kparams
= NULL
;
1314 pa
= krb5_find_padata(rep
->padata
->val
,
1316 KRB5_PADATA_PK_AS_REP
,
1320 pa
= krb5_find_padata(rep
->padata
->val
,
1322 KRB5_PADATA_PK_AS_REP_19
,
1326 if (pa
&& ctx
->pk_init_ctx
) {
1328 _krb5_debug(context
, 5, "krb5_get_init_creds: using PKINIT");
1330 ret
= _krb5_pk_rd_pa_reply(context
,
1341 krb5_set_error_message(context
, ret
, N_("no support for PKINIT compiled in", ""));
1343 } else if (ctx
->keyseed
) {
1344 _krb5_debug(context
, 5, "krb5_get_init_creds: using keyproc");
1345 ret
= pa_data_to_key_plain(context
, creds
->client
, ctx
,
1346 ppaid
->salt
, ppaid
->s2kparams
, etype
, key
);
1349 krb5_set_error_message(context
, ret
, N_("No usable pa data type", ""));
1352 free_paid(context
, &paid
);
1357 * Start a new context to get a new initial credential.
1359 * @param context A Kerberos 5 context.
1360 * @param client The Kerberos principal to get the credential for, if
1361 * NULL is given, the default principal is used as determined by
1362 * krb5_get_default_principal().
1364 * @param prompter_data
1365 * @param start_time the time the ticket should start to be valid or 0 for now.
1366 * @param options a options structure, can be NULL for default options.
1367 * @param rctx A new allocated free with krb5_init_creds_free().
1369 * @return 0 for success or an Kerberos 5 error code, see krb5_get_error_message().
1371 * @ingroup krb5_credential
1374 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1375 krb5_init_creds_init(krb5_context context
,
1376 krb5_principal client
,
1377 krb5_prompter_fct prompter
,
1378 void *prompter_data
,
1379 krb5_deltat start_time
,
1380 krb5_get_init_creds_opt
*options
,
1381 krb5_init_creds_context
*rctx
)
1383 krb5_init_creds_context ctx
;
1384 krb5_error_code ret
;
1388 ctx
= calloc(1, sizeof(*ctx
));
1390 return krb5_enomem(context
);
1392 ret
= get_init_creds_common(context
, client
, start_time
, options
, ctx
);
1398 /* Set a new nonce. */
1399 krb5_generate_random_block (&ctx
->nonce
, sizeof(ctx
->nonce
));
1400 ctx
->nonce
&= 0x7fffffff;
1401 /* XXX these just needs to be the same when using Windows PK-INIT */
1402 ctx
->pk_nonce
= ctx
->nonce
;
1404 ctx
->prompter
= prompter
;
1405 ctx
->prompter_data
= prompter_data
;
1413 * Sets the service that the is requested. This call is only neede for
1414 * special initial tickets, by default the a krbtgt is fetched in the default realm.
1416 * @param context a Kerberos 5 context.
1417 * @param ctx a krb5_init_creds_context context.
1418 * @param service the service given as a string, for example
1419 * "kadmind/admin". If NULL, the default krbtgt in the clients
1422 * @return 0 for success, or an Kerberos 5 error code, see krb5_get_error_message().
1423 * @ingroup krb5_credential
1426 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1427 krb5_init_creds_set_service(krb5_context context
,
1428 krb5_init_creds_context ctx
,
1429 const char *service
)
1431 krb5_const_realm client_realm
;
1432 krb5_principal principal
;
1433 krb5_error_code ret
;
1435 client_realm
= krb5_principal_get_realm (context
, ctx
->cred
.client
);
1438 ret
= krb5_parse_name (context
, service
, &principal
);
1441 krb5_principal_set_realm (context
, principal
, client_realm
);
1443 ret
= krb5_make_principal(context
, &principal
,
1444 client_realm
, KRB5_TGS_NAME
, client_realm
,
1451 * This is for Windows RODC that are picky about what name type
1452 * the server principal have, and the really strange part is that
1453 * they are picky about the AS-REQ name type and not the TGS-REQ
1457 if (krb5_principal_is_krbtgt(context
, principal
))
1458 krb5_principal_set_type(context
, principal
, KRB5_NT_SRV_INST
);
1460 krb5_free_principal(context
, ctx
->cred
.server
);
1461 ctx
->cred
.server
= principal
;
1467 * Sets the password that will use for the request.
1469 * @param context a Kerberos 5 context.
1470 * @param ctx ctx krb5_init_creds_context context.
1471 * @param password the password to use.
1473 * @return 0 for success, or an Kerberos 5 error code, see krb5_get_error_message().
1474 * @ingroup krb5_credential
1477 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1478 krb5_init_creds_set_password(krb5_context context
,
1479 krb5_init_creds_context ctx
,
1480 const char *password
)
1482 if (ctx
->password
) {
1483 memset(ctx
->password
, 0, strlen(ctx
->password
));
1484 free(ctx
->password
);
1487 ctx
->password
= strdup(password
);
1488 if (ctx
->password
== NULL
)
1489 return krb5_enomem(context
);
1490 ctx
->keyseed
= (void *) ctx
->password
;
1492 ctx
->keyseed
= NULL
;
1493 ctx
->password
= NULL
;
1499 static krb5_error_code KRB5_CALLCONV
1500 keytab_key_proc(krb5_context context
, krb5_enctype enctype
,
1501 krb5_const_pointer keyseed
,
1502 krb5_salt salt
, krb5_data
*s2kparms
,
1503 krb5_keyblock
**key
)
1505 krb5_keytab_key_proc_args
*args
= rk_UNCONST(keyseed
);
1506 krb5_keytab keytab
= args
->keytab
;
1507 krb5_principal principal
= args
->principal
;
1508 krb5_error_code ret
;
1509 krb5_keytab real_keytab
;
1510 krb5_keytab_entry entry
;
1513 krb5_kt_default(context
, &real_keytab
);
1515 real_keytab
= keytab
;
1517 ret
= krb5_kt_get_entry (context
, real_keytab
, principal
,
1518 0, enctype
, &entry
);
1521 krb5_kt_close (context
, real_keytab
);
1526 ret
= krb5_copy_keyblock (context
, &entry
.keyblock
, key
);
1527 krb5_kt_free_entry(context
, &entry
);
1533 * Set the keytab to use for authentication.
1535 * @param context a Kerberos 5 context.
1536 * @param ctx ctx krb5_init_creds_context context.
1537 * @param keytab the keytab to read the key from.
1539 * @return 0 for success, or an Kerberos 5 error code, see krb5_get_error_message().
1540 * @ingroup krb5_credential
1543 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1544 krb5_init_creds_set_keytab(krb5_context context
,
1545 krb5_init_creds_context ctx
,
1548 krb5_keytab_key_proc_args
*a
;
1549 krb5_keytab_entry entry
;
1550 krb5_kt_cursor cursor
;
1551 krb5_enctype
*etypes
= NULL
;
1552 krb5_error_code ret
;
1554 int kvno
= 0, found
= 0;
1556 a
= malloc(sizeof(*a
));
1558 return krb5_enomem(context
);
1560 a
->principal
= ctx
->cred
.client
;
1563 ctx
->keytab_data
= a
;
1564 ctx
->keyseed
= (void *)a
;
1565 ctx
->keyproc
= keytab_key_proc
;
1568 * We need to the KDC what enctypes we support for this keytab,
1569 * esp if the keytab is really a password based entry, then the
1570 * KDC might have more enctypes in the database then what we have
1574 ret
= krb5_kt_start_seq_get(context
, keytab
, &cursor
);
1578 while(krb5_kt_next_entry(context
, keytab
, &entry
, &cursor
) == 0){
1581 if (!krb5_principal_compare(context
, entry
.principal
, ctx
->cred
.client
))
1586 /* check if we ahve this kvno already */
1587 if (entry
.vno
> kvno
) {
1588 /* remove old list of etype */
1594 } else if (entry
.vno
!= kvno
)
1597 /* check if enctype is supported */
1598 if (krb5_enctype_valid(context
, entry
.keyblock
.keytype
) != 0)
1601 /* add enctype to supported list */
1602 ptr
= realloc(etypes
, sizeof(etypes
[0]) * (netypes
+ 2));
1605 ret
= krb5_enomem(context
);
1610 etypes
[netypes
] = entry
.keyblock
.keytype
;
1611 etypes
[netypes
+ 1] = ETYPE_NULL
;
1614 krb5_kt_free_entry(context
, &entry
);
1616 krb5_kt_end_seq_get(context
, keytab
, &cursor
);
1621 ctx
->etypes
= etypes
;
1627 ret
= KRB5_KT_NOTFOUND
;
1628 _krb5_kt_principal_not_found(context
, ret
, keytab
, ctx
->cred
.client
, 0, 0);
1634 static krb5_error_code KRB5_CALLCONV
1635 keyblock_key_proc(krb5_context context
, krb5_enctype enctype
,
1636 krb5_const_pointer keyseed
,
1637 krb5_salt salt
, krb5_data
*s2kparms
,
1638 krb5_keyblock
**key
)
1640 return krb5_copy_keyblock (context
, keyseed
, key
);
1643 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1644 krb5_init_creds_set_keyblock(krb5_context context
,
1645 krb5_init_creds_context ctx
,
1646 krb5_keyblock
*keyblock
)
1648 ctx
->keyseed
= (void *)keyblock
;
1649 ctx
->keyproc
= keyblock_key_proc
;
1654 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1655 krb5_init_creds_set_fast_ccache(krb5_context context
,
1656 krb5_init_creds_context ctx
,
1657 krb5_ccache fast_ccache
)
1659 ctx
->fast_state
.armor_ccache
= fast_ccache
;
1660 ctx
->fast_state
.flags
|= KRB5_FAST_REQUIRED
;
1664 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1665 krb5_init_creds_set_fast_ap_armor_service(krb5_context context
,
1666 krb5_init_creds_context ctx
,
1667 krb5_const_principal armor_service
)
1669 krb5_error_code ret
;
1671 if (ctx
->fast_state
.armor_service
)
1672 krb5_free_principal(context
, ctx
->fast_state
.armor_service
);
1673 if (armor_service
) {
1674 ret
= krb5_copy_principal(context
, armor_service
, &ctx
->fast_state
.armor_service
);
1678 ctx
->fast_state
.armor_service
= NULL
;
1680 ctx
->fast_state
.flags
|= KRB5_FAST_REQUIRED
| KRB5_FAST_AP_ARMOR_SERVICE
;
1688 static krb5_error_code
1689 check_fast(krb5_context context
, struct fast_state
*state
)
1691 if (state
->flags
& KRB5_FAST_EXPECTED
) {
1692 krb5_set_error_message(context
, KRB5KRB_AP_ERR_MODIFIED
,
1693 "Expected FAST, but no FAST "
1694 "was in the response from the KDC");
1695 return KRB5KRB_AP_ERR_MODIFIED
;
1701 static krb5_error_code
1702 fast_unwrap_as_rep(krb5_context context
, int32_t nonce
,
1703 krb5_data
*chksumdata
,
1704 struct fast_state
*state
, AS_REP
*rep
)
1706 PA_FX_FAST_REPLY fxfastrep
;
1707 KrbFastResponse fastrep
;
1708 krb5_error_code ret
;
1712 if (state
->armor_crypto
== NULL
|| rep
->padata
== NULL
)
1713 return check_fast(context
, state
);
1715 /* find PA_FX_FAST_REPLY */
1717 pa
= krb5_find_padata(rep
->padata
->val
, rep
->padata
->len
,
1718 KRB5_PADATA_FX_FAST
, &idx
);
1720 return check_fast(context
, state
);
1722 memset(&fxfastrep
, 0, sizeof(fxfastrep
));
1723 memset(&fastrep
, 0, sizeof(fastrep
));
1725 ret
= decode_PA_FX_FAST_REPLY(pa
->padata_value
.data
, pa
->padata_value
.length
, &fxfastrep
, NULL
);
1729 if (fxfastrep
.element
== choice_PA_FX_FAST_REPLY_armored_data
) {
1731 ret
= krb5_decrypt_EncryptedData(context
,
1732 state
->armor_crypto
,
1734 &fxfastrep
.u
.armored_data
.enc_fast_rep
,
1739 ret
= decode_KrbFastResponse(data
.data
, data
.length
, &fastrep
, NULL
);
1740 krb5_data_free(&data
);
1745 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1749 free_METHOD_DATA(rep
->padata
);
1750 ret
= copy_METHOD_DATA(&fastrep
.padata
, rep
->padata
);
1754 if (fastrep
.strengthen_key
) {
1755 if (state
->strengthen_key
)
1756 krb5_free_keyblock(context
, state
->strengthen_key
);
1758 ret
= krb5_copy_keyblock(context
, fastrep
.strengthen_key
, &state
->strengthen_key
);
1763 if (nonce
!= fastrep
.nonce
) {
1764 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1767 if (fastrep
.finished
) {
1768 PrincipalName cname
;
1769 krb5_realm crealm
= NULL
;
1771 if (chksumdata
== NULL
) {
1772 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1776 ret
= krb5_verify_checksum(context
, state
->armor_crypto
,
1777 KRB5_KU_FAST_FINISHED
,
1778 chksumdata
->data
, chksumdata
->length
,
1779 &fastrep
.finished
->ticket_checksum
);
1784 ret
= copy_Realm(&fastrep
.finished
->crealm
, &crealm
);
1787 free_Realm(&rep
->crealm
);
1788 rep
->crealm
= crealm
;
1790 ret
= copy_PrincipalName(&fastrep
.finished
->cname
, &cname
);
1793 free_PrincipalName(&rep
->cname
);
1796 #if 0 /* store authenticated checksum as kdc-offset */
1797 fastrep
->finished
.timestamp
;
1798 fastrep
->finished
.usec
= 0;
1801 } else if (chksumdata
) {
1802 /* expected fastrep.finish but didn't get it */
1803 ret
= KRB5KDC_ERR_PREAUTH_FAILED
;
1807 free_PA_FX_FAST_REPLY(&fxfastrep
);
1812 static krb5_error_code
1813 fast_unwrap_error(krb5_context context
, struct fast_state
*state
, KRB_ERROR
*error
)
1815 if (state
->armor_crypto
== NULL
)
1816 return check_fast(context
, state
);
1822 _krb5_make_fast_ap_fxarmor(krb5_context context
,
1823 krb5_ccache armor_ccache
,
1824 krb5_data
*armor_value
,
1825 krb5_keyblock
*armor_key
,
1826 krb5_crypto
*armor_crypto
)
1828 krb5_auth_context auth_context
= NULL
;
1829 krb5_creds cred
, *credp
= NULL
;
1830 krb5_error_code ret
;
1833 krb5_data_zero(&empty
);
1835 memset(&cred
, 0, sizeof(cred
));
1837 ret
= krb5_auth_con_init (context
, &auth_context
);
1841 ret
= krb5_cc_get_principal(context
, armor_ccache
, &cred
.client
);
1845 ret
= krb5_make_principal(context
, &cred
.server
,
1851 krb5_free_principal(context
, cred
.client
);
1855 ret
= krb5_get_credentials(context
, 0, armor_ccache
, &cred
, &credp
);
1856 krb5_free_principal(context
, cred
.server
);
1857 krb5_free_principal(context
, cred
.client
);
1861 ret
= krb5_auth_con_add_AuthorizationData(context
, auth_context
, KRB5_PADATA_FX_FAST_ARMOR
, &empty
);
1865 ret
= krb5_mk_req_extended(context
,
1871 krb5_free_creds(context
, credp
);
1875 ret
= _krb5_fast_armor_key(context
,
1876 auth_context
->local_subkey
,
1877 auth_context
->keyblock
,
1888 static heim_base_once_t armor_service_once
= HEIM_BASE_ONCE_INIT
;
1889 static heim_ipc armor_service
= NULL
;
1892 fast_armor_init_ipc(void *ctx
)
1894 heim_ipc
*ipc
= ctx
;
1895 heim_ipc_init_context("ANY:org.h5l.armor-service", ipc
);
1900 static krb5_error_code
1901 make_fast_ap_fxarmor(krb5_context context
,
1902 struct fast_state
*state
,
1904 KrbFastArmor
**armor
)
1906 KrbFastArmor
*fxarmor
= NULL
;
1907 krb5_error_code ret
;
1909 if (state
->armor_crypto
)
1910 krb5_crypto_destroy(context
, state
->armor_crypto
);
1911 krb5_free_keyblock_contents(context
, &state
->armor_key
);
1915 if (fxarmor
== NULL
) {
1920 if (state
->flags
& KRB5_FAST_AP_ARMOR_SERVICE
) {
1922 krb5_set_error_message(context
, ENOTSUP
, "Fast armor IPC service not supportted yet on Windows");
1925 KERB_ARMOR_SERVICE_REPLY msg
;
1926 krb5_data request
, reply
;
1928 heim_base_once_f(&armor_service_once
, &armor_service
, fast_armor_init_ipc
);
1929 if (armor_service
== NULL
) {
1930 krb5_set_error_message(context
, ENOENT
, "Failed to open fast armor service");
1934 krb5_data_zero(&reply
);
1936 request
.data
= rk_UNCONST(realm
);
1937 request
.length
= strlen(realm
);
1939 ret
= heim_ipc_call(armor_service
, &request
, &reply
, NULL
);
1942 krb5_set_error_message(context
, ret
, "Failed to get armor service credential");
1946 ret
= decode_KERB_ARMOR_SERVICE_REPLY(reply
.data
, reply
.length
, &msg
, NULL
);
1947 krb5_data_free(&reply
);
1951 ret
= copy_KrbFastArmor(fxarmor
, &msg
.armor
);
1953 free_KERB_ARMOR_SERVICE_REPLY(&msg
);
1957 ret
= krb5_copy_keyblock_contents(context
, &msg
.armor_key
, &state
->armor_key
);
1958 free_KERB_ARMOR_SERVICE_REPLY(&msg
);
1962 ret
= krb5_crypto_init(context
, &state
->armor_key
, 0, &state
->armor_crypto
);
1968 fxarmor
->armor_type
= 1;
1970 ret
= _krb5_make_fast_ap_fxarmor(context
,
1971 state
->armor_ccache
,
1972 &fxarmor
->armor_value
,
1974 &state
->armor_crypto
);
1984 free_KrbFastArmor(fxarmor
);
1990 static krb5_error_code
1991 fast_wrap_req(krb5_context context
, struct fast_state
*state
, KDC_REQ
*req
)
1993 KrbFastArmor
*fxarmor
= NULL
;
1994 PA_FX_FAST_REQUEST fxreq
;
1995 krb5_error_code ret
;
2000 if (state
->flags
& KRB5_FAST_DISABLED
) {
2001 _krb5_debug(context
, 10, "fast disabled, not doing any fast wrapping");
2005 memset(&fxreq
, 0, sizeof(fxreq
));
2006 memset(&fastreq
, 0, sizeof(fastreq
));
2007 krb5_data_zero(&data
);
2009 if (state
->armor_crypto
== NULL
) {
2010 if (state
->armor_ccache
) {
2012 * Instead of keeping state in FX_COOKIE in the KDC, we
2013 * rebuild a new armor key for every request, because this
2014 * is what the MIT KDC expect and RFC6113 is vage about
2015 * what the behavior should be.
2017 state
->type
= choice_PA_FX_FAST_REQUEST_armored_data
;
2019 return check_fast(context
, state
);
2023 state
->flags
|= KRB5_FAST_EXPECTED
;
2025 fastreq
.fast_options
.hide_client_names
= 1;
2027 ret
= copy_KDC_REQ_BODY(&req
->req_body
, &fastreq
.req_body
);
2028 free_KDC_REQ_BODY(&req
->req_body
);
2030 req
->req_body
.realm
= strdup(KRB5_ANON_REALM
);
2031 ALLOC(req
->req_body
.cname
, 1);
2032 req
->req_body
.cname
->name_type
= KRB5_NT_PRINCIPAL
;
2033 ALLOC(req
->req_body
.cname
->name_string
.val
, 2);
2034 req
->req_body
.cname
->name_string
.len
= 2;
2035 req
->req_body
.cname
->name_string
.val
[0] = strdup(KRB5_WELLKNOWN_NAME
);
2036 req
->req_body
.cname
->name_string
.val
[1] = strdup(KRB5_ANON_NAME
);
2037 ALLOC(req
->req_body
.till
, 1);
2038 *req
->req_body
.till
= 0;
2041 ret
= copy_METHOD_DATA(req
->padata
, &fastreq
.padata
);
2042 free_METHOD_DATA(req
->padata
);
2044 ALLOC(req
->padata
, 1);
2048 ASN1_MALLOC_ENCODE(KrbFastReq
, data
.data
, data
.length
, &fastreq
, &size
, ret
);
2051 heim_assert(data
.length
== size
, "ASN.1 internal error");
2053 fxreq
.element
= state
->type
;
2055 if (state
->type
== choice_PA_FX_FAST_REQUEST_armored_data
) {
2059 ret
= make_fast_ap_fxarmor(context
, state
, fastreq
.req_body
.realm
, &fxreq
.u
.armored_data
.armor
);
2063 heim_assert(state
->armor_crypto
!= NULL
, "FAST armor key missing when FAST started");
2065 ASN1_MALLOC_ENCODE(KDC_REQ_BODY
, buf
, len
, &req
->req_body
, &size
, ret
);
2068 heim_assert(len
== size
, "ASN.1 internal error");
2070 ret
= krb5_create_checksum(context
, state
->armor_crypto
,
2071 KRB5_KU_FAST_REQ_CHKSUM
, 0,
2073 &fxreq
.u
.armored_data
.req_checksum
);
2078 ret
= krb5_encrypt_EncryptedData(context
, state
->armor_crypto
,
2083 &fxreq
.u
.armored_data
.enc_fast_req
);
2084 krb5_data_free(&data
);
2087 krb5_data_free(&data
);
2088 heim_assert(false, "unknown FAST type, internal error");
2091 ASN1_MALLOC_ENCODE(PA_FX_FAST_REQUEST
, data
.data
, data
.length
, &fxreq
, &size
, ret
);
2094 heim_assert(data
.length
== size
, "ASN.1 internal error");
2097 ret
= krb5_padata_add(context
, req
->padata
, KRB5_PADATA_FX_FAST
, data
.data
, data
.length
);
2100 krb5_data_zero(&data
);
2103 free_PA_FX_FAST_REQUEST(&fxreq
);
2105 free_KrbFastArmor(fxarmor
);
2108 krb5_data_free(&data
);
2115 * The core loop if krb5_get_init_creds() function family. Create the
2116 * packets and have the caller send them off to the KDC.
2118 * If the caller want all work been done for them, use
2119 * krb5_init_creds_get() instead.
2121 * @param context a Kerberos 5 context.
2122 * @param ctx ctx krb5_init_creds_context context.
2123 * @param in input data from KDC, first round it should be reset by krb5_data_zer().
2124 * @param out reply to KDC.
2125 * @param hostinfo KDC address info, first round it can be NULL.
2126 * @param flags status of the round, if
2127 * KRB5_INIT_CREDS_STEP_FLAG_CONTINUE is set, continue one more round.
2129 * @return 0 for success, or an Kerberos 5 error code, see
2130 * krb5_get_error_message().
2132 * @ingroup krb5_credential
2135 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2136 krb5_init_creds_step(krb5_context context
,
2137 krb5_init_creds_context ctx
,
2140 krb5_krbhst_info
*hostinfo
,
2141 unsigned int *flags
)
2143 krb5_error_code ret
;
2148 krb5_data_zero(out
);
2150 if (ctx
->as_req
.req_body
.cname
== NULL
) {
2151 ret
= init_as_req(context
, ctx
->flags
, &ctx
->cred
,
2152 ctx
->addrs
, ctx
->etypes
, &ctx
->as_req
);
2154 free_init_creds_ctx(context
, ctx
);
2159 #define MAX_PA_COUNTER 10
2160 if (ctx
->pa_counter
> MAX_PA_COUNTER
) {
2161 krb5_set_error_message(context
, KRB5_GET_IN_TKT_LOOP
,
2162 N_("Looping %d times while getting "
2163 "initial credentials", ""),
2165 return KRB5_GET_IN_TKT_LOOP
;
2169 _krb5_debug(context
, 5, "krb5_get_init_creds: loop %d", ctx
->pa_counter
);
2171 /* Lets process the input packet */
2172 if (in
&& in
->length
) {
2175 memset(&rep
, 0, sizeof(rep
));
2177 _krb5_debug(context
, 5, "krb5_get_init_creds: processing input");
2179 ret
= decode_AS_REP(in
->data
, in
->length
, &rep
.kdc_rep
, &size
);
2181 unsigned eflags
= EXTRACT_TICKET_AS_REQ
| EXTRACT_TICKET_TIMESYNC
;
2187 ASN1_MALLOC_ENCODE(Ticket
, data
.data
, data
.length
,
2188 &rep
.kdc_rep
.ticket
, &size
, ret
);
2191 heim_assert(data
.length
== size
, "ASN.1 internal error");
2193 ret
= fast_unwrap_as_rep(context
, ctx
->nonce
, &data
,
2194 &ctx
->fast_state
, &rep
.kdc_rep
);
2195 krb5_data_free(&data
);
2200 * Now check and extract the ticket
2203 if (ctx
->flags
.canonicalize
) {
2204 eflags
|= EXTRACT_TICKET_ALLOW_SERVER_MISMATCH
;
2205 eflags
|= EXTRACT_TICKET_MATCH_REALM
;
2207 if (ctx
->ic_flags
& KRB5_INIT_CREDS_NO_C_CANON_CHECK
)
2208 eflags
|= EXTRACT_TICKET_ALLOW_CNAME_MISMATCH
;
2210 ret
= process_pa_data_to_key(context
, ctx
, &ctx
->cred
,
2211 &ctx
->as_req
, &rep
.kdc_rep
,
2212 hostinfo
, &ctx
->fast_state
.reply_key
);
2214 free_AS_REP(&rep
.kdc_rep
);
2218 _krb5_debug(context
, 5, "krb5_get_init_creds: extracting ticket");
2220 ret
= _krb5_extract_ticket(context
,
2223 ctx
->fast_state
.reply_key
,
2225 KRB5_KU_AS_REP_ENC_PART
,
2233 ret
= copy_EncKDCRepPart(&rep
.enc_part
, &ctx
->enc_part
);
2235 krb5_free_keyblock(context
, ctx
->fast_state
.reply_key
);
2236 ctx
->fast_state
.reply_key
= NULL
;
2239 free_AS_REP(&rep
.kdc_rep
);
2240 free_EncASRepPart(&rep
.enc_part
);
2245 /* let's try to parse it as a KRB-ERROR */
2247 _krb5_debug(context
, 5, "krb5_get_init_creds: got an error");
2249 free_KRB_ERROR(&ctx
->error
);
2251 ret
= krb5_rd_error(context
, in
, &ctx
->error
);
2252 if(ret
&& in
->length
&& ((char*)in
->data
)[0] == 4)
2253 ret
= KRB5KRB_AP_ERR_V4_REPLY
;
2255 _krb5_debug(context
, 5, "krb5_get_init_creds: failed to read error");
2262 ret
= fast_unwrap_error(context
, &ctx
->fast_state
, &ctx
->error
);
2270 ret
= krb5_error_from_rd_error(context
, &ctx
->error
, &ctx
->cred
);
2272 _krb5_debug(context
, 5, "krb5_get_init_creds: KRB-ERROR %d", ret
);
2275 * If no preauth was set and KDC requires it, give it one
2279 if (ret
== KRB5KDC_ERR_PREAUTH_REQUIRED
) {
2281 free_METHOD_DATA(&ctx
->md
);
2282 memset(&ctx
->md
, 0, sizeof(ctx
->md
));
2284 if (ctx
->error
.e_data
) {
2285 ret
= decode_METHOD_DATA(ctx
->error
.e_data
->data
,
2286 ctx
->error
.e_data
->length
,
2290 krb5_set_error_message(context
, ret
,
2291 N_("Failed to decode METHOD-DATA", ""));
2293 krb5_set_error_message(context
, ret
,
2294 N_("Preauth required but no preauth "
2295 "options send by KDC", ""));
2297 } else if (ret
== KRB5KRB_AP_ERR_SKEW
&& context
->kdc_sec_offset
== 0) {
2299 * Try adapt to timeskrew when we are using pre-auth, and
2300 * if there was a time skew, try again.
2302 krb5_set_real_time(context
, ctx
->error
.stime
, -1);
2303 if (context
->kdc_sec_offset
)
2306 _krb5_debug(context
, 10, "init_creds: err skew updateing kdc offset to %d",
2307 context
->kdc_sec_offset
);
2309 ctx
->used_pa_types
= 0;
2311 } else if (ret
== KRB5_KDC_ERR_WRONG_REALM
&& ctx
->flags
.canonicalize
) {
2312 /* client referal to a new realm */
2314 if (ctx
->error
.crealm
== NULL
) {
2315 krb5_set_error_message(context
, ret
,
2316 N_("Got a client referral, not but no realm", ""));
2319 _krb5_debug(context
, 5,
2320 "krb5_get_init_creds: got referal to realm %s",
2321 *ctx
->error
.crealm
);
2323 ret
= krb5_principal_set_realm(context
,
2325 *ctx
->error
.crealm
);
2327 ctx
->used_pa_types
= 0;
2328 } else if (ret
== KRB5KDC_ERR_PREAUTH_FAILED
) {
2330 if (ctx
->fast_state
.flags
& KRB5_FAST_DISABLED
)
2332 if (ctx
->fast_state
.flags
& (KRB5_FAST_REQUIRED
| KRB5_FAST_EXPECTED
))
2335 _krb5_debug(context
, 10, "preauth failed with FAST, "
2336 "and told by KD or user, trying w/o FAST");
2338 ctx
->fast_state
.flags
|= KRB5_FAST_DISABLED
;
2339 ctx
->used_pa_types
= 0;
2347 if (ctx
->as_req
.padata
) {
2348 free_METHOD_DATA(ctx
->as_req
.padata
);
2349 free(ctx
->as_req
.padata
);
2350 ctx
->as_req
.padata
= NULL
;
2353 /* Set a new nonce. */
2354 ctx
->as_req
.req_body
.nonce
= ctx
->nonce
;
2356 /* fill_in_md_data */
2357 ret
= process_pa_data_to_md(context
, &ctx
->cred
, &ctx
->as_req
, ctx
,
2358 &ctx
->md
, &ctx
->as_req
.padata
,
2359 ctx
->prompter
, ctx
->prompter_data
);
2366 copy_AS_REQ(&ctx
->as_req
, &req2
);
2368 ret
= fast_wrap_req(context
, &ctx
->fast_state
, &req2
);
2374 krb5_data_free(&ctx
->req_buffer
);
2376 ASN1_MALLOC_ENCODE(AS_REQ
,
2377 ctx
->req_buffer
.data
, ctx
->req_buffer
.length
,
2382 if(len
!= ctx
->req_buffer
.length
)
2383 krb5_abortx(context
, "internal error in ASN.1 encoder");
2385 out
->data
= ctx
->req_buffer
.data
;
2386 out
->length
= ctx
->req_buffer
.length
;
2388 *flags
= KRB5_INIT_CREDS_STEP_FLAG_CONTINUE
;
2396 * Extract the newly acquired credentials from krb5_init_creds_context
2399 * @param context A Kerberos 5 context.
2401 * @param cred credentials, free with krb5_free_cred_contents().
2403 * @return 0 for sucess or An Kerberos error code, see krb5_get_error_message().
2406 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2407 krb5_init_creds_get_creds(krb5_context context
,
2408 krb5_init_creds_context ctx
,
2411 return krb5_copy_creds_contents(context
, &ctx
->cred
, cred
);
2415 * Get the last error from the transaction.
2417 * @return Returns 0 or an error code
2419 * @ingroup krb5_credential
2422 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2423 krb5_init_creds_get_error(krb5_context context
,
2424 krb5_init_creds_context ctx
,
2427 krb5_error_code ret
;
2429 ret
= copy_KRB_ERROR(&ctx
->error
, error
);
2431 krb5_enomem(context
);
2438 * @ingroup krb5_credential
2442 krb5_init_creds_store(krb5_context context
,
2443 krb5_init_creds_context ctx
,
2446 krb5_error_code ret
;
2448 if (ctx
->cred
.client
== NULL
) {
2449 ret
= KRB5KDC_ERR_PREAUTH_REQUIRED
;
2450 krb5_set_error_message(context
, ret
, "init creds not completed yet");
2454 ret
= krb5_cc_initialize(context
, id
, ctx
->cred
.client
);
2458 ret
= krb5_cc_store_cred(context
, id
, &ctx
->cred
);
2462 if (ctx
->cred
.flags
.b
.enc_pa_rep
) {
2463 krb5_data data
= { 3, rk_UNCONST("yes") };
2464 ret
= krb5_cc_set_config(context
, id
, ctx
->cred
.server
,
2465 "fast_avail", &data
);
2474 * Free the krb5_init_creds_context allocated by krb5_init_creds_init().
2476 * @param context A Kerberos 5 context.
2477 * @param ctx The krb5_init_creds_context to free.
2479 * @ingroup krb5_credential
2482 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
2483 krb5_init_creds_free(krb5_context context
,
2484 krb5_init_creds_context ctx
)
2486 free_init_creds_ctx(context
, ctx
);
2491 * Get new credentials as setup by the krb5_init_creds_context.
2493 * @param context A Kerberos 5 context.
2494 * @param ctx The krb5_init_creds_context to process.
2496 * @ingroup krb5_credential
2499 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2500 krb5_init_creds_get(krb5_context context
, krb5_init_creds_context ctx
)
2502 krb5_sendto_ctx stctx
= NULL
;
2503 krb5_krbhst_info
*hostinfo
= NULL
;
2504 krb5_error_code ret
;
2506 unsigned int flags
= 0;
2508 krb5_data_zero(&in
);
2509 krb5_data_zero(&out
);
2511 ret
= krb5_sendto_ctx_alloc(context
, &stctx
);
2514 krb5_sendto_ctx_set_func(stctx
, _krb5_kdc_retry
, NULL
);
2518 ret
= krb5_init_creds_step(context
, ctx
, &in
, &out
, hostinfo
, &flags
);
2519 krb5_data_free(&in
);
2523 if ((flags
& 1) == 0)
2526 ret
= krb5_sendto_context (context
, stctx
, &out
,
2527 ctx
->cred
.client
->realm
, &in
);
2535 krb5_sendto_ctx_free(context
, stctx
);
2541 * Get new credentials using password.
2543 * @ingroup krb5_credential
2547 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2548 krb5_get_init_creds_password(krb5_context context
,
2550 krb5_principal client
,
2551 const char *password
,
2552 krb5_prompter_fct prompter
,
2554 krb5_deltat start_time
,
2555 const char *in_tkt_service
,
2556 krb5_get_init_creds_opt
*options
)
2558 krb5_init_creds_context ctx
;
2559 char buf
[BUFSIZ
], buf2
[BUFSIZ
];
2560 krb5_error_code ret
;
2564 ret
= krb5_init_creds_init(context
, client
, prompter
, data
, start_time
, options
, &ctx
);
2568 ret
= krb5_init_creds_set_service(context
, ctx
, in_tkt_service
);
2572 if (prompter
!= NULL
&& ctx
->password
== NULL
&& password
== NULL
) {
2574 krb5_data password_data
;
2578 ret
= krb5_unparse_name(context
, client
, &p
);
2582 aret
= asprintf(&q
, "%s's Password: ", p
);
2584 if (aret
== -1 || q
== NULL
) {
2585 ret
= krb5_enomem(context
);
2589 password_data
.data
= buf
;
2590 password_data
.length
= sizeof(buf
);
2592 prompt
.reply
= &password_data
;
2593 prompt
.type
= KRB5_PROMPT_TYPE_PASSWORD
;
2595 ret
= (*prompter
) (context
, data
, NULL
, NULL
, 1, &prompt
);
2598 memset (buf
, 0, sizeof(buf
));
2599 ret
= KRB5_LIBOS_PWDINTR
;
2600 krb5_clear_error_message (context
);
2603 password
= password_data
.data
;
2607 ret
= krb5_init_creds_set_password(context
, ctx
, password
);
2612 ret
= krb5_init_creds_get(context
, ctx
);
2615 krb5_process_last_request(context
, options
, ctx
);
2618 if (ret
== KRB5KDC_ERR_KEY_EXPIRED
&& chpw
== 0) {
2619 /* try to avoid recursion */
2620 if (in_tkt_service
!= NULL
&& strcmp(in_tkt_service
, "kadmin/changepw") == 0)
2623 /* don't try to change password where then where none */
2624 if (prompter
== NULL
)
2627 ret
= change_password (context
,
2639 krb5_init_creds_free(context
, ctx
);
2645 krb5_init_creds_get_creds(context
, ctx
, creds
);
2648 krb5_init_creds_free(context
, ctx
);
2650 memset(buf
, 0, sizeof(buf
));
2651 memset(buf2
, 0, sizeof(buf2
));
2656 * Get new credentials using keyblock.
2658 * @ingroup krb5_credential
2661 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2662 krb5_get_init_creds_keyblock(krb5_context context
,
2664 krb5_principal client
,
2665 krb5_keyblock
*keyblock
,
2666 krb5_deltat start_time
,
2667 const char *in_tkt_service
,
2668 krb5_get_init_creds_opt
*options
)
2670 krb5_init_creds_context ctx
;
2671 krb5_error_code ret
;
2673 memset(creds
, 0, sizeof(*creds
));
2675 ret
= krb5_init_creds_init(context
, client
, NULL
, NULL
, start_time
, options
, &ctx
);
2679 ret
= krb5_init_creds_set_service(context
, ctx
, in_tkt_service
);
2683 ret
= krb5_init_creds_set_keyblock(context
, ctx
, keyblock
);
2687 ret
= krb5_init_creds_get(context
, ctx
);
2690 krb5_process_last_request(context
, options
, ctx
);
2694 krb5_init_creds_get_creds(context
, ctx
, creds
);
2697 krb5_init_creds_free(context
, ctx
);
2703 * Get new credentials using keytab.
2705 * @ingroup krb5_credential
2708 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2709 krb5_get_init_creds_keytab(krb5_context context
,
2711 krb5_principal client
,
2713 krb5_deltat start_time
,
2714 const char *in_tkt_service
,
2715 krb5_get_init_creds_opt
*options
)
2717 krb5_init_creds_context ctx
;
2718 krb5_error_code ret
;
2720 memset(creds
, 0, sizeof(*creds
));
2722 ret
= krb5_init_creds_init(context
, client
, NULL
, NULL
, start_time
, options
, &ctx
);
2726 ret
= krb5_init_creds_set_service(context
, ctx
, in_tkt_service
);
2730 ret
= krb5_init_creds_set_keytab(context
, ctx
, keytab
);
2734 ret
= krb5_init_creds_get(context
, ctx
);
2736 krb5_process_last_request(context
, options
, ctx
);
2740 krb5_init_creds_get_creds(context
, ctx
, creds
);
2743 krb5_init_creds_free(context
, ctx
);