kssl.c revision 9dc0df1bac950d6e491f9a7c7e4888f2b301cb15
/* Written by Vern Staats <staatsvr@asc.hpc.mil> for the OpenSSL project 2000.
*/
/* ====================================================================
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
**
** 19990701 VRS Started.
** 200011?? Jeffrey Altman, Richard Levitte
** Generalized for Heimdal, Newer MIT, & Win32.
** Integrated into main OpenSSL 0.9.7 snapshots.
** 20010413 Simon Wilkinson, VRS
** Real RFC2712 KerberosWrapper replaces AP_REQ.
*/
#include <openssl/opensslconf.h>
#include <time.h>
#if 0 /* experimental */
#endif
#include <string.h>
#define KRB5_PRIVATE 1
#include <openssl/krb5_asn.h>
#ifndef OPENSSL_NO_KRB5
#ifndef ENOMEM
#define ENOMEM KRB5KRB_ERR_GENERIC
#endif
/*
* When OpenSSL is built on Windows, we do not want to require that
* the Kerberos DLLs be available in order for the OpenSSL DLLs to
* work. Therefore, all Kerberos routines are loaded at run time
* and we do not link to a .LIB file.
*/
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
/*
* The purpose of the following pre-processor statements is to provide
* compatibility with different releases of MIT Kerberos for Windows.
* All versions up to 1.2 used macros. But macros do not allow for
* a binary compatible interface for DLLs. Therefore, all macros are
* being replaced by function calls. The following code will allow
* an OpenSSL DLL built on Windows to work whether or not the macro
* or function form of the routines are utilized.
*/
#ifdef krb5_cc_get_principal
#define NO_DEF_KRB5_CCACHE
#endif
#define krb5_cc_default kssl_krb5_cc_default
#define krb5_rd_req kssl_krb5_rd_req
#define krb5_kt_default kssl_krb5_kt_default
#define krb5_kt_resolve kssl_krb5_kt_resolve
/* macros in mit 1.2.2 and earlier; functions in mit 1.2.3 and greater */
#ifndef krb5_kt_close
#define krb5_kt_close kssl_krb5_kt_close
#endif /* krb5_kt_close */
#ifndef krb5_kt_get_entry
#endif /* krb5_kt_get_entry */
#define krb5_timeofday kssl_krb5_timeofday
#define krb5_rc_default kssl_krb5_rc_default
#ifdef krb5_rc_initialize
#endif
#ifdef krb5_rc_get_lifespan
#endif
#ifdef krb5_rc_destroy
#endif
#define krb5_rc_destroy kssl_krb5_rc_destroy
#define valid_cksumtype kssl_valid_cksumtype
/* Prototypes for built in stubs */
krb5_const char *,
krb5_keytab *);
krb5_keytab *);
krb5_flags *,krb5_ticket **);
krb5_data *,
krb5_creds *,
krb5_data * );
krb5_const char *,
krb5_const char *,
krb5_principal *);
krb5_creds *,
krb5_creds * *);
krb5_rcache *);
krb5_rcache *);
/* Function pointers (almost all Kerberos functions are _stdcall) */
=NULL;
=NULL;
krb5_keytab *)=NULL;
krb5_ticket *)=NULL;
krb5_ticket **)=NULL;
krb5_ccache *)=NULL;
krb5_ticket *)=NULL;
krb5_rcache *)=NULL;
krb5_rcache *)=NULL;
static int krb5_loaded = 0; /* only attempt to initialize func ptrs once */
/* Function to Load the Kerberos 5 DLL and initialize function pointers */
void
load_krb5_dll(void)
{
krb5_loaded++;
if (!hKRB5_32)
return;
(FARPROC) p_krb5_rd_req =
}
/* Stubs for each function to be dynamicly loaded */
void
{
if (!krb5_loaded)
if ( p_krb5_free_data_contents )
}
krb5_creds * pC,
{
if (!krb5_loaded)
if ( p_krb5_mk_req_extended )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_auth_con_init )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_auth_con_free )
else
return KRB5KRB_ERR_GENERIC;
}
krb5_creds * pCR,
krb5_creds ** ppCR)
{
if (!krb5_loaded)
if ( p_krb5_get_credentials )
else
return KRB5KRB_ERR_GENERIC;
}
krb5_const char * pC1,
krb5_const char * pC2,
krb5_int32 I,
{
if (!krb5_loaded)
if ( p_krb5_sname_to_principal )
else
return KRB5KRB_ERR_GENERIC;
}
krb5_ccache * pCC)
{
if (!krb5_loaded)
if ( p_krb5_cc_default )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_init_context )
return(p_krb5_init_context(pCO));
else
return KRB5KRB_ERR_GENERIC;
}
void
{
if (!krb5_loaded)
if ( p_krb5_free_context )
}
void
{
if (!krb5_loaded)
if ( p_krb5_free_principal )
p_krb5_free_principal(c,p);
}
krb5_const char * sz,
krb5_keytab * kt)
{
if (!krb5_loaded)
if ( p_krb5_kt_resolve )
else
return KRB5KRB_ERR_GENERIC;
}
krb5_keytab * kt)
{
if (!krb5_loaded)
if ( p_krb5_kt_default )
else
return KRB5KRB_ERR_GENERIC;
}
krb5_ticket * kt)
{
if (!krb5_loaded)
if ( p_krb5_free_ticket )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_rd_req )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_principal_compare )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_decrypt_tkt_part )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_timeofday )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_rc_default )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_rc_initialize )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_rc_get_lifespan )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_rc_destroy )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_checksum_size )
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_valid_cksumtype )
return(p_valid_cksumtype(ctype));
else
return KRB5KRB_ERR_GENERIC;
}
{
if (!krb5_loaded)
if ( p_krb5_kt_free_entry )
else
return KRB5KRB_ERR_GENERIC;
}
/* Structure definitions */
#ifndef NO_DEF_KRB5_CCACHE
#ifndef krb5_x
#endif
typedef struct _krb5_ccache
{
} *krb5_ccache;
typedef struct _krb5_cc_ops
{
char *prefix;
char * (KRB5_CALLCONV *get_name)
(krb5_context, krb5_ccache *, const char *);
(krb5_context, krb5_ccache *);
krb5_cc_cursor *, krb5_creds *);
krb5_flags, krb5_creds *);
} krb5_cc_ops;
#endif /* NO_DEF_KRB5_CCACHE */
{
if ( p_krb5_cc_get_principal )
else
return(krb5_x
}
{
if ( p_krb5_auth_con_setrcache )
else
return KRB5KRB_ERR_GENERIC;
}
{
if ( p_krb5_get_server_rcache )
else
return KRB5KRB_ERR_GENERIC;
}
{
if ( p_krb5_auth_con_getrcache )
else
return KRB5KRB_ERR_GENERIC;
}
{
if ( p_krb5_kt_close )
else
return KRB5KRB_ERR_GENERIC;
}
{
if ( p_krb5_kt_get_entry )
else
return KRB5KRB_ERR_GENERIC;
}
#endif /* OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32 */
char
{
static char *null = "[NULL]";
}
/* Given KRB5 enctype (basically DES or 3DES),
** return closest match openssl EVP_ encryption algorithm.
** Return NULL for unknown or problematic (krb5_dk_encrypt) enctypes.
** Assume ENCTYPE_*_RAW (krb5_raw_encrypt) are OK.
*/
const EVP_CIPHER *
{
switch (enctype)
{
case ENCTYPE_DES_HMAC_SHA1: /* EVP_des_cbc(); */
case ENCTYPE_DES_CBC_CRC:
case ENCTYPE_DES_CBC_MD4:
case ENCTYPE_DES_CBC_MD5:
case ENCTYPE_DES_CBC_RAW:
return EVP_des_cbc();
break;
case ENCTYPE_DES3_CBC_SHA1: /* EVP_des_ede3_cbc(); */
case ENCTYPE_DES3_CBC_SHA:
case ENCTYPE_DES3_CBC_RAW:
return EVP_des_ede3_cbc();
break;
default: return NULL;
break;
}
}
/* Return true:1 if p "looks like" the start of the real authenticator
** described in kssl_skip_confound() below. The ASN.1 pattern is
** "62 xx 30 yy" (APPLICATION-2, SEQUENCE), where xx-yy =~ 2, and
** xx and yy are possibly multi-byte length fields.
*/
int kssl_test_confound(unsigned char *p)
{
int len = 2;
if (*p++ != 0x62) return 0;
if (*p > 0x82) return 0;
switch(*p) {
case 0x81: p++; xx = *p++; break;
case 0x80: return 0;
default: xx = *p++; break;
}
if (*p++ != 0x30) return 0;
if (*p > 0x82) return 0;
switch(*p) {
case 0x80: return 0;
default: yy = *p++; break;
}
}
/* Allocate, fill, and return cksumlens array of checksum lengths.
** This array holds just the unique elements from the krb5_cksumarray[].
** array[n] == 0 signals end of data.
**
** The krb5_cksumarray[] was an internal variable that has since been
** replaced by a more general method for storing the data. It should
** not be used. Instead we use real API calls and make a guess for
** what the highest assigned CKSUMTYPE_ constant is. As of 1.2.2
** it is 0x000c (CKSUMTYPE_HMAC_SHA1_DES3). So we will use 0x0010.
*/
size_t *populate_cksumlens(void)
{
int i, j, n;
#ifdef KRB5_MIT_OLD11
n = krb5_max_cksum;
#else
n = 0x0010;
#endif /* KRB5_MIT_OLD11 */
#ifdef KRB5CHECKAUTH
for (i=0; i < n; i++) {
if (!valid_cksumtype(i)) continue; /* array has holes */
for (j=0; j < n; j++) {
if (cklens[j] == 0) {
break; /* krb5 elem was new: add */
}
break; /* ignore duplicate elements */
}
}
}
#endif /* KRB5CHECKAUTH */
return cklens;
}
/* Return pointer to start of real authenticator within authenticator, or
** return NULL on error.
** Decrypted authenticator looks like this:
** [0 or 8 byte confounder] [4-24 byte checksum] [real authent'r]
** This hackery wouldn't be necessary if MIT KRB5 1.0.6 had the
** krb5_auth_con_getcksumtype() function advertised in its krb5.h.
*/
{
int i, conlen;
unsigned char *test_auth;
{
}
return NULL;
}
/* Set kssl_err error info when reason text is a simple string
** kssl_err = struct { int reason; char text[KSSL_ERR_MAX+1]; }
*/
void
{
return;
}
/* Display contents of krb5_data struct, for debugging
*/
void
{
int i;
{
else
}
printf("\n");
}
/* Display contents of krb5_authdata struct, for debugging
*/
void
{
{
return;
}
#if 0
{
int i;
{
}
printf("\n");
}
#endif
}
/* Display contents of krb5_keyblock struct, for debugging
*/
void
{
int i;
{
return;
}
#ifdef KRB5_HEIMDAL
{
}
printf("\n");
#else
{
}
printf("\n");
#endif
}
/* Display contents of krb5_principal_data struct, for debugging
** (krb5_principal is typedef'd == krb5_principal_data *)
*/
void
{
{
}
printf("\n");
}
return;
}
/* Given krb5 service (typically "kssl") and hostname in kssl_ctx,
** Return encrypted Kerberos ticket for service @ hostname.
** If authenp is non-NULL, also return encrypted authenticator,
** whose data should be freed by caller.
** (Originally was: Create Kerberos AP_REQ message for SSL Client.)
**
** 19990628 VRS Started; Returns Kerberos AP_REQ message.
** 20010409 VRS Modified for RFC2712; Returns enc tkt.
** 20010606 VRS May also return optional authenticator.
*/
{
if (!kssl_ctx)
{
"No kssl_ctx defined.\n");
goto err;
}
else if (!kssl_ctx->service_host)
{
"kssl_ctx service_host undefined.\n");
goto err;
}
{
"krb5_init_context() fails: %d\n", krb5rc);
goto err;
}
{
"krb5_sname_to_principal() fails for %s/%s\n",
KRB5SVC);
goto err;
}
{
"krb5_cc_default fails.\n");
goto err;
}
{
"krb5_cc_get_principal() fails.\n");
goto err;
}
&krb5creds, &krb5credsp)) != 0)
{
"krb5_get_credentials() fails.\n");
goto err;
}
#ifdef KRB5_HEIMDAL
#else
#endif
/* caller should free data of krb5_app_req */
/* 20010406 VRS deleted for real KerberosWrapper
** 20010605 VRS reinstated to offer Authenticator to KerberosWrapper
*/
krb5_app_req.length = 0;
if (authenp)
{
const unsigned char *p;
long arlen;
krb5in_data.length = 0;
&krb5_app_req)) != 0)
{
"krb5_mk_req_extended() fails.\n");
goto err;
}
p = (unsigned char *)krb5_app_req.data;
if (ap_req)
{
{
}
}
if (krb5_app_req.length)
}
#ifdef KRB5_HEIMDAL
{
"kssl_ctx_setkey() fails.\n");
}
#else
{
"kssl_ctx_setkey() fails.\n");
}
#endif
else krb5rc = 0;
err:
#ifdef KSSL_DEBUG
#endif /* KSSL_DEBUG */
return (krb5rc);
}
/* Given d2i_-decoded asn1ticket, allocate and return a new krb5_ticket.
** Return Kerberos error code and kssl_err struct on error.
** Allocates krb5_ticket and krb5_principal; caller should free these.
**
** 20010410 VRS Implemented krb5_decode_ticket() as
** old_krb5_decode_ticket(). Missing from MIT1.0.6.
** Re-used some of the old krb5_decode_ticket()
** like the real thing.
*/
{
*krb5ticket = NULL;
{
"Null field in asn1ticket.\n");
return KRB5KRB_ERR_GENERIC;
}
{
"Unable to allocate new krb5_ticket.\n");
return ENOMEM; /* or KRB5KRB_ERR_GENERIC; */
}
&new5ticket->server,
{
"Error building ticket server principal.\n");
return krb5rc; /* or KRB5KRB_ERR_GENERIC; */
}
{
"Error allocating cipher in krb5ticket.\n");
return KRB5KRB_ERR_GENERIC;
}
else
{
}
*krb5ticket = new5ticket;
return 0;
}
/* Given krb5 service name in KSSL_CTX *kssl_ctx (typically "kssl"),
** and krb5 AP_REQ message & message length,
** Return Kerberos session key and client principle
** to SSL Server in KSSL_CTX *kssl_ctx.
**
** 19990702 VRS Started.
*/
{
const unsigned char *p;
if (!kssl_ctx)
{
"No kssl_ctx defined.\n");
goto err;
}
#ifdef KSSL_DEBUG
#endif /* KSSL_DEBUG */
{
"krb5_init_context() fails.\n");
goto err;
}
if (krb5auth_context &&
{
"krb5_auth_con_free() fails.\n");
goto err;
}
else krb5auth_context = NULL;
if (!krb5auth_context &&
{
"krb5_auth_con_init() fails.\n");
goto err;
}
&rcache)))
{
"krb5_auth_con_getrcache() fails.\n");
goto err;
}
KRB5_NT_SRV_HST, &krb5server)) != 0)
{
"krb5_sname_to_principal() fails.\n");
goto err;
}
{
&rcache)))
{
"krb5_get_server_rcache() fails.\n");
goto err;
}
}
{
"krb5_auth_con_setrcache() fails.\n");
goto err;
}
/* kssl_ctx->keytab_file == NULL ==> use Kerberos default
*/
if (kssl_ctx->keytab_file)
{
&krb5keytab);
if (krb5rc)
{
"krb5_kt_resolve() fails.\n");
goto err;
}
}
else
{
if (krb5rc)
{
"krb5_kt_default() fails.\n");
goto err;
}
}
/* Actual Kerberos5 krb5_recvauth() has initial conversation here
** o check KRB5_SENDAUTH_BADAUTHVERS
** unless KRB5_RECVAUTH_SKIP_VERSION
** o check KRB5_SENDAUTH_BADAPPLVERS
** o send "0" msg if all OK
*/
/* 20010411 was using AP_REQ instead of true KerberosWrapper
**
** if ((krb5rc = krb5_rd_req(krb5context, &krb5auth_context,
** &krb5in_data, krb5server, krb5keytab,
** &ap_option, &krb5ticket)) != 0) { Error }
*/
{
"d2i_KRB5_TICKET() ASN.1 decode failure.\n");
goto err;
}
/* Was: krb5rc = krb5_decode_ticket(krb5in_data,&krb5ticket)) != 0) */
kssl_err)) != 0)
{
"Error converting ASN.1 ticket to krb5_ticket.\n");
goto err;
}
krb5ticket->server)) {
"server principal != ticket principal\n");
goto err;
}
"krb5_kt_get_entry() fails with %x.\n", krb5rc);
goto err;
}
krb5ticket)) != 0) {
"krb5_decrypt_tkt_part() failed.\n");
goto err;
}
else {
#ifdef KSSL_DEBUG
{
printf("Decrypted ticket fields:\n");
printf("\tflags: %X, transit-type: %X",
print_krb5_data("\ttransit-data: ",
printf("\tcaddrs: %p, authdata: %p\n",
if (paddr)
{
printf("\tcaddrs:\n");
{
krb5_data d;
print_krb5_data("\t\tIP: ", &d);
}
}
}
#endif /* KSSL_DEBUG */
}
{
"bad ticket from krb5_rd_req.\n");
}
{
"kssl_ctx_setprinc() fails.\n");
}
{
"kssl_ctx_setkey() fails.\n");
}
{
"invalid ticket from krb5_rd_req.\n");
}
else krb5rc = 0;
err:
#ifdef KSSL_DEBUG
#endif /* KSSL_DEBUG */
return (krb5rc);
}
/* Allocate & return a new kssl_ctx struct.
*/
KSSL_CTX *
kssl_ctx_new(void)
{
}
/* Frees a kssl_ctx struct and any allocated memory it holds.
** Returns NULL.
*/
KSSL_CTX *
{
}
/* Given an array of (krb5_data *) entity (and optional realm),
** set the plain (char *) client_princ or service_host member
** of the kssl_ctx struct.
*/
{
char **princ;
int length;
int i;
switch (which)
{
default: return KSSL_CTX_ERR; break;
}
/* Add up all the entity->lengths */
length = 0;
for (i=0; i < nentities; i++)
{
}
/* Add in space for the '/' character(s) (if any) */
/* Space for the ('@'+realm+NULL | NULL) */
return KSSL_CTX_ERR;
else
{
for (i = 0; i < nentities; i++)
{
if (i < nentities-1)
{
}
}
if (realm)
{
}
}
return KSSL_CTX_OK;
}
/* Set one of the plain (char *) string members of the kssl_ctx struct.
** Default values should be:
** which == KSSL_SERVICE => "khost" (KRB5SVC)
** which == KSSL_KEYTAB => "/etc/krb5.keytab" (KRB5KEYTAB)
*/
{
char **string;
if (!kssl_ctx) return KSSL_CTX_ERR;
switch (which)
{
default: return KSSL_CTX_ERR; break;
}
if (!text)
{
*string = '\0';
return KSSL_CTX_OK;
}
return KSSL_CTX_ERR;
else
return KSSL_CTX_OK;
}
/* Copy the Kerberos session key from a (krb5_keyblock *) to a kssl_ctx
** struct. Clear kssl_ctx->key if Kerberos session key is NULL.
*/
{
int length;
if (!kssl_ctx) return KSSL_CTX_ERR;
{
}
if (session)
{
#ifdef KRB5_HEIMDAL
#else
#endif
}
else
{
return KSSL_CTX_OK;
}
{
return KSSL_CTX_ERR;
}
else
return KSSL_CTX_OK;
}
/* Display contents of kssl_ctx struct
*/
void
{
int i;
printf("kssl_ctx: ");
{
printf("NULL\n");
return;
}
else
printf("\tservice:\t%s\n",
printf("\tclient:\t%s\n",
printf("\tserver:\t%s\n",
printf("\tkeytab:\t%s\n",
printf("\tkey [%d:%d]:\t",
{
}
printf("\n");
return;
}
int
{
int rc = 0;
return(0);
/* kssl_ctx->keytab_file == NULL ==> use Kerberos default
*/
if (kssl_ctx->keytab_file)
{
&krb5keytab);
if (krb5rc)
goto exit;
}
else
{
if (krb5rc)
goto exit;
}
/* the host key we are looking for */
KRB5_NT_SRV_HST, &princ);
0 /* IGNORE_VNO */,
0 /* IGNORE_ENCTYPE */,
&entry);
if ( krb5rc == KRB5_KT_NOTFOUND ) {
rc = 1;
goto exit;
} else if ( krb5rc )
goto exit;
rc = 1;
exit:
return(rc);
}
int
{
int rc = 0;
if (!kssl_ctx)
return(0);
if (!kssl_ctx->service_host)
return(0);
goto err;
goto err;
goto err;
goto err;
&krb5creds, &krb5credsp)) != 0)
goto err;
rc = 1;
err:
#ifdef KSSL_DEBUG
#endif /* KSSL_DEBUG */
return(rc);
}
#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_WIN32)
{
#ifdef KRB5_HEIMDAL
#elif defined(KRB5_MIT_OLD11)
}
#else
#endif
}
#endif /* !OPENSSL_SYS_WINDOWS && !OPENSSL_SYS_WIN32 */
/* Given pointers to KerberosTime and struct tm structs, convert the
** KerberosTime string to struct tm. Note that KerberosTime is a
** ASN1_GENERALIZEDTIME value, constrained to GMT with no fractional
** seconds as defined in RFC 1510.
** Return pointer to the (partially) filled in struct tm on success,
** return NULL on failure.
*/
{
char c, *p;
return k_tm;
}
/* Helper function for kssl_validate_times().
** We need context->clockskew, but krb5_context is an opaque struct.
** So we try to sneek the clockskew out through the replay cache.
** If that fails just return a likely default (300 seconds).
*/
{
}
return clockskew;
}
/* kssl_validate_times() combines (and more importantly exposes)
** the MIT KRB5 internal function krb5_validate_times() and the
** in_clock_skew() macro. The authenticator client time is checked
** to be within clockskew secs of the current time and the current
** time is checked to be within the ticket start and expire times.
** Either check may be omitted by supplying a NULL value.
** Returns 0 for valid times, SSL_R_KRB5* error codes otherwise.
** See Also: (Kerberos source)/krb5/lib/krb5/krb/valid_times.c
** 20010420 VRS
*/
{
if (! ttimes) return 0;
#ifdef KSSL_DEBUG
printf("kssl_validate_times: %d |<- | %d - %d | < %d ->| %d\n",
#endif /* KSSL_DEBUG */
return 0;
}
/* Decode and decrypt given DER-encoded authenticator, then pass
** authenticator ctime back in *atimep (or 0 if time unavailable).
** Returns krb5_error_code and kssl_err on error. A NULL
** authenticator (authentp->length == 0) is not considered an error.
** Note that kssl_check_authent() makes use of the KRB5 session key;
** you must call kssl_sget_tkt() to get the key before calling this routine.
*/
{
krb5_error_code krb5rc = 0;
unsigned char iv[EVP_MAX_IV_LENGTH];
const unsigned char *p;
unsigned char *unenc_authent;
int outl, unencbufsize;
*atimep = 0;
#ifndef KRB5CHECKAUTH
#else
#if KRB5CHECKAUTH == 0
#endif
#endif /* KRB5CHECKAUTH */
#ifdef KSSL_DEBUG
{
unsigned int ui;
printf("\n");
}
#endif /* KSSL_DEBUG */
{
"Unable to allocate authenticator buffer.\n");
goto err;
}
{
"Error decoding authenticator.\n");
goto err;
}
#if !defined(KRB5_MIT_OLD11)
switch ( enctype ) {
case ENCTYPE_DES3_CBC_SHA1: /* EVP_des_ede3_cbc(); */
case ENCTYPE_DES3_CBC_SHA:
case ENCTYPE_DES3_CBC_RAW:
krb5rc = 0; /* Skip, can't handle derived keys */
goto err;
}
#endif
{
/* Disable kssl_check_authent for ENCTYPE_DES3_CBC_SHA1.
** This enctype indicates the authenticator was encrypted
** using key-usage derived keys which openssl cannot decrypt.
*/
goto err;
}
{
"EVP_CipherInit error decrypting authenticator.\n");
goto err;
}
{
"EVP_Cipher error decrypting authenticator.\n");
goto err;
}
#ifdef KSSL_DEBUG
printf("\n");
#endif /* KSSL_DEBUG */
{
"confounded by authenticator.\n");
goto err;
}
outl -= p - unenc_authent;
{
"Error decoding authenticator body.\n");
goto err;
}
{
}
#ifdef KSSL_DEBUG
else printf("NULL\n");
#endif /* KSSL_DEBUG */
err:
return krb5rc;
}
/* Replaces krb5_build_principal_ext(), with varargs length == 2 (svc, host),
** because I dont't know how to stub varargs.
** Returns krb5_error_code == ENOMEM on alloc error, otherwise
** passes back newly constructed principal, which should be freed by caller.
*/
{
return 0;
err:
return ENOMEM;
}
#else /* !OPENSSL_NO_KRB5 */
#if defined(PEDANTIC) || defined(OPENSSL_SYS_VMS)
#endif
#endif /* !OPENSSL_NO_KRB5 */