preauth2.c revision 505d05c73a6e56769f263d4803b22eddd168ee24
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright 1995, 2003 by the Massachusetts Institute of Technology. All
* Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*/
/*
* This file contains routines for establishing, verifying, and any other
* necessary functions, for utilizing the pre-authentication field of the
*/
#include <k5-int.h>
void *prompter_data,
void *gak_data);
typedef struct _pa_types_t {
int flags;
} pa_types_t;
#define PA_REAL 0x0001
#define PA_INFO 0x0002
/*ARGSUSED*/
static
{
return(0);
}
/*ARGSUSED*/
static
void *prompter_data,
void *gak_data)
{
#ifdef DEBUG
}
#endif
return(ret);
}
/* now get the time of day, and encrypt it accordingly */
return(ret);
return(ret);
#ifdef DEBUG
#endif
#ifdef DEBUG
#endif
if (ret) {
return(ret);
}
if (ret)
return(ret);
return(ENOMEM);
}
*out_padata = pa;
return(0);
}
static
{
char *label;
switch (sam_type) {
case PA_SAM_TYPE_ENIGMA: /* Enigma Logic */
label = "Challenge for Enigma Logic mechanism";
break;
case PA_SAM_TYPE_DIGI_PATH: /* Digital Pathways */
case PA_SAM_TYPE_DIGI_PATH_HEX: /* Digital Pathways */
label = "Challenge for Digital Pathways mechanism";
break;
case PA_SAM_TYPE_ACTIVCARD_DEC: /* Digital Pathways */
case PA_SAM_TYPE_ACTIVCARD_HEX: /* Digital Pathways */
label = "Challenge for Activcard mechanism";
break;
case PA_SAM_TYPE_SKEY_K0: /* S/key where KDC has key 0 */
break;
case PA_SAM_TYPE_SKEY: /* Traditional S/Key */
break;
case PA_SAM_TYPE_SECURID: /* Security Dynamics */
label = "Challenge for Security Dynamics mechanism";
break;
case PA_SAM_TYPE_SECURID_PREDICT: /* predictive Security Dynamics */
label = "Challenge for Security Dynamics mechanism";
break;
default:
label = "Challenge from authentication server";
break;
}
return(label);
}
/* this macro expands to the int,ptr necessary for "%.*s" in an sprintf */
/* XXX Danger! This code is not in sync with the kerberos-password-02
draft. This draft cannot be implemented as written. This code is
compatible with earlier versions of mit krb5 and cygnus kerbnet. */
/*ARGSUSED*/
static
void *prompter_data,
void *gak_data)
{
/* these two get encrypted and stuffed in to sam_response */
krb5_pa_data * pa;
return (EIO);
return(ret);
return(KRB5_SAM_UNSUPPORTED);
}
/* If we need the password from the user (USE_SAD_AS_KEY not set), */
/* then get it here. Exception for "old" KDCs with CryptoCard */
/* support which uses the USE_SAD_AS_KEY flag, but still needs pwd */
/* etype has either been set by caller or by KRB5_PADATA_ETYPE_INFO */
/* message from the KDC. If it is not set, pick an enctype that we */
/* think the KDC will have for us. */
return(ret);
}
sizeof(name) - 1));
sizeof(banner)-1));
/* sprintf(prompt, "Challenge is [%s], %s: ", challenge, prompt); */
/* PROMPTER_INVOCATION */
return(ret);
}
if (sam_challenge->sam_nonce == 0) {
&enc_sam_response_enc.sam_usec))) {
return(ret);
}
}
/* XXX What if more than one flag is set? */
/* Most of this should be taken care of before we get here. We */
/* will need the user's password and as_key to encrypt the SAD */
/* and we want to preserve ordering of user prompts (first */
/* password, then SAM data) so that user's won't be confused. */
}
/* generate a salt using the requested principal */
&defsalt))) {
return(ret);
}
} else {
}
/* generate a key using the supplied password */
if (ret) {
return(ret);
}
/* encrypt the passcode with the key from above */
/* process the key as password */
}
#if 0
&defsalt)) {
return(ret);
}
} else {
}
#else
#endif
/* XXX As of the passwords-04 draft, no enctype is specified,
the server uses ENCTYPE_DES_CBC_MD5. In the future the
server should send a PA-SAM-ETYPE-INFO containing the enctype. */
if (ret) {
return(ret);
}
} else {
/* Eventually, combine SAD with long-term key to get
encryption key. */
return KRB5_PREAUTH_BAD_TYPE;
}
/* copy things from the challenge */
/* encode the encoded part of the response */
&scratch)))
return(ret);
/*
* Solaris Kerberos:
* Using new crypto interface now so we can get rid of the
* old modules.
*/
return(ret);
}
return(ENOMEM);
}
}
if (ret)
return(ret);
/* sam_enc_key is reserved for future use */
return(ENOMEM);
return(ret);
}
*out_padata = pa;
return(0);
}
static
void *prompter_data,
void *gak_data) {
krb5_boolean valid_cksum = 0;
return KRB5_LIBOS_CANTREADPWD;
return(retval);
if (retval)
return(retval);
return(KRB5_SAM_NO_CHECKSUM);
}
return(KRB5_SAM_UNSUPPORTED);
}
return(KRB5_SAM_INVALID_ETYPE);
}
/* All of the above error checks are KDC-specific, that is, they */
/* assume a failure in the KDC reply. By returning anything other */
/* than KRB5_KDC_UNREACH, KRB5_PREAUTH_FAILED, */
/* KRB5_LIBOS_PWDINTR, or KRB5_REALM_CANT_RESOLVE, the client will */
/* most likely go on to try the AS_REQ against master KDC */
/* We will need the password to obtain the key used for */
/* the checksum, and encryption of the sam_response. */
/* Go ahead and get it now, preserving the ordering of */
/* prompts for the user. */
if (retval) {
return(retval);
}
}
sizeof(name) - 1));
sizeof(banner)-1));
return(retval);
}
/* Generate salt used by string_to_key() */
if ((retval =
return(retval);
}
} else {
}
/* Get encryption key to be used for checksum and sam_response */
/* as_key = string_to_key(password) */
}
/* generate a key using the supplied password */
if (retval) {
return(retval);
}
/* as_key = combine_key (as_key, string_to_key(SAD)) */
if (retval) {
return(retval);
}
/* This should be a call to the crypto library some day */
/* key types should already match the sam_etype */
if (retval) {
return(retval);
}
}
} else {
/* as_key = string_to_key(SAD) */
}
/* generate a key using the supplied password */
if (retval) {
return(retval);
}
}
/* Now we have a key, verify the checksum on the sam_challenge */
while (*cksum) {
/* Check this cksum */
*cksum, &valid_cksum);
if (retval) {
return(retval);
}
if (valid_cksum)
break;
cksum++;
}
if (!valid_cksum) {
/* If KRB5_SAM_SEND_ENCRYPTED_SAD is set, then password is only */
/* source for checksum key. Therefore, a bad checksum means a */
/* bad password. Don't give that direct feedback to someone */
/* trying to brute-force passwords. */
/*
* Note: We return AP_ERR_BAD_INTEGRITY so upper-level applications
* can interpret that as "password incorrect", which is probably
* the best error we can return in this situation.
*/
return(KRB5KRB_AP_ERR_BAD_INTEGRITY);
}
/* fill in enc_sam_response_enc_2 */
} else {
}
/* encode and encrypt enc_sam_response_enc_2 with as_key */
&scratch);
if (retval) {
return(retval);
}
/* Fill in sam_response_2 */
/* Now take care of sr2.sam_enc_nonce_or_sad by encrypting encoded */
/* enc_sam_response_enc_2 from above */
&ciph_len);
if (retval) {
return(retval);
}
return(ENOMEM);
}
if (retval) {
return(retval);
}
/* Encode the sam_response_2 */
if (retval) {
return (retval);
}
/* Almost there, just need to make padata ! */
if (sam_padata == NULL) {
return(ENOMEM);
}
*out_padata = sam_padata;
return(0);
}
static pa_types_t pa_types[] = {
{
},
{
},
{
},
{
},
{
},
{
-1,
NULL,
0,
},
};
{
int h, i, j, out_pa_list_size;
int seen_etype_info2 = 0;
int realdone;
*out_padata = NULL;
return(0);
}
#ifdef DEBUG
for (i = 0; in_padata[i]; i++) {
}
}
#endif
out_pa_list = NULL;
out_pa_list_size = 0;
/* first do all the informational preauths, then the first real one */
realdone = 0;
int k, l, etype_found, valid_etype_found;
/*
* This is really gross, but is necessary to prevent
* lossge when talking to a 1.0.x KDC, which returns an
* erroneous PA-PW-SALT when it returns a KRB-ERROR
* requiring additional preauth.
*/
case KRB5_PADATA_ETYPE_INFO:
case KRB5_PADATA_ETYPE_INFO2:
{
if (etype_info) {
continue;
if (pa_type == KRB5_PADATA_ETYPE_INFO2) {
etype_info = NULL;
}
}
if (pa_type == KRB5_PADATA_ETYPE_INFO2) {
}
if (ret) {
ret = 0; /*Ignore error and etype_info element*/
etype_info = NULL;
continue;
}
if (etype_info[0] == NULL) {
etype_info = NULL;
break;
}
/*
* Select first etype in our request which is also in
* etype-info (preferring client request ktype order).
*/
for (etype_found = 0, valid_etype_found = 0, k = 0;
for (l = 0; etype_info[l]; l++) {
etype_found++;
break;
}
/* check if program has support for this etype for more
* precise error reporting.
*/
}
}
if (!etype_found) {
"valid_etype_found = %d",
if (valid_etype_found) {
/* supported enctype but not requested */
goto cleanup;
}
else {
/* unsupported enctype */
goto cleanup;
}
}
else
goto cleanup;
&etype_info[l]->s2kparams,
s2kparams)) != 0)
goto cleanup;
break;
}
case KRB5_PADATA_PW_SALT:
case KRB5_PADATA_AFS3_SALT:
if (etype_info)
continue;
break;
default:
;
}
goto cleanup;
}
if (out_pa) {
if (out_pa_list == NULL) {
if ((out_pa_list =
(krb5_pa_data **)
== NULL) {
goto cleanup;
}
} else {
if ((out_pa_list =
(krb5_pa_data **)
(out_pa_list_size+2)*
sizeof(krb5_pa_data *)))
== NULL) {
/* XXX this will leak the pointers which
have already been allocated. oh well. */
goto cleanup;
}
}
}
realdone = 1;
}
}
}
}
if (out_pa_list)
if (etype_info)
return(0);
if (out_pa_list) {
}
if (etype_info)
return (ret);
}