/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
*
* Copyright (c) 1994 CyberSAFE Corporation.
* Copyright 1990,1991,2007,2008 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.
* Neither M.I.T., the Open Computing Security Group, nor
* CyberSAFE Corporation make any representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
/*
*/
/*
* krb5_rd_req_decoded()
*/
#include "k5-int.h"
#include "auth_con.h"
#include "authdata.h"
#include "int-proto.h"
/* Solaris Kerberos */
#include <locale.h>
#include <syslog.h>
#include "kerberos_dtrace.h"
/*
* essentially the same as krb_rd_req, but uses a decoded AP_REQ as
* the input rather than an encoded input.
*/
/*
* Parses a KRB_AP_REQ message, returning its contents.
*
* server specifies the expected server's name for the ticket; if NULL, then
* any server will be accepted if the key can be found, and the caller should
* verify that the principal is something it trusts.
*
* rcache specifies a replay detection cache used to store authenticators and
* server names
*
* keyproc specifies a procedure to generate a decryption key for the
* ticket. If keyproc is non-NULL, keyprocarg is passed to it, and the result
* used as a decryption key. If keyproc is NULL, then fetchfrom is checked;
* if it is non-NULL, it specifies a parameter name from which to retrieve the
* decryption key. If fetchfrom is NULL, then the default key store is
* consulted.
*
* authdat is set to point at allocated storage structures; the caller
* should free them when finished.
*
* returns system errors, encryption errors, replay errors
*/
static krb5_error_code
krb5_authenticator **, int);
static krb5_error_code
const krb5_authenticator *authp,
int *desired_etypes_len);
static krb5_error_code
const krb5_enctype *desired_etypes,
int desired_etypes_len,
const krb5_enctype *permitted_etypes,
int permitted_etypes_len,
static krb5_error_code
{
#ifndef LEAN_CLIENT
/* Solaris Kerberos: for safety, I guess */
if (retval == 0) {
}
} else {
if (code != 0) {
goto map_error;
}
continue;
}
if (retval == 0) {
/*
* We overwrite ticket->server to be the principal
* that we match in the keytab. The reason for doing
* this is that GSS-API and other consumers look at
* that principal to make authorization decisions
* about whether the appropriate server is contacted.
* It might be cleaner to create a new API and store
* the server in the auth_context, but doing so would
* probably miss existing uses of the server. Instead,
* perhaps an API should be created to retrieve the
* server as it appeared in the ticket.
*/
if (retval == 0) {
} else {
}
break;
}
}
if (code != 0)
}
if (retval == KRB5KRB_AP_ERR_BAD_INTEGRITY) {
/* Solaris Kerberos: spruce-up the err msg */
if (kret == 0) {
"AP Request ticket decrypt"
" fail for principal '%s' "
"(kvno=%d, enctype=%d)"),
}
}
#endif /* LEAN_CLIENT */
#if 0 /* Solaris Kerberos */
switch (retval) {
case KRB5_KT_KVNONOTFOUND:
case KRB5_KT_NOTFOUND:
break;
default:
break;
}
#endif
return retval;
}
#if 0
#include <syslog.h>
static void
{
if (a) {
while (*a) {
(char *) (*a)->contents);
a++;
}
} else
}
#else
static void
{
}
#endif
/*
* Solaris Kerberos
* Same as krb5int_check_clockskew() plus return the skew in seconds.
*/
static krb5_error_code
{
if (retval)
return retval;
return KRB5KRB_AP_ERR_SKEW;
}
return 0;
}
/* Solaris Kerberos: added raw_req for dtrace */
static krb5_error_code
{
int desired_etypes_len = 0;
int rfc4537_etypes_len = 0;
int permitted_etypes_len = 0;
/* Solaris Kerberos */
char *realm;
princ_data = *server;
server = &princ_data;
if (retval)
return retval;
}
/* if (req->ap_options & AP_OPTS_USE_SESSION_KEY)
do we need special processing here ? */
/* decrypt the ticket */
/* Solaris Kerberos dtrace support */
goto cleanup;
}
if (check_valid_flag) {
}
} else {
/* Solaris Kerberos dtrace support */
goto cleanup;
}
}
/* XXX this is an evil hack. check_valid_flag is set iff the call
is not from inside the kdc. we can use this to determine which
key usage to use */
#ifndef LEAN_CLIENT
&((*auth_context)->authentp),
goto cleanup;
/* Solaris Kerberos dtrace support */
#endif
goto cleanup;
}
if ((*auth_context)->remote_addr &&
goto cleanup;
}
if (!server) {
}
/* Get an rcache if necessary. */
&& server) {
&(*auth_context)->rcache)))
goto cleanup;
}
/* okay, now check cross-realm policy */
#if defined(_SINGLE_HOP_ONLY)
/* Single hop cross-realm tickets only */
{
/* If the transited list is empty, then we have at most one hop */
}
#elif defined(_NO_CROSS_REALM)
/* No cross-realm tickets */
{
char * lrealm;
/*
* If the transited list is empty, then we have at most one hop
* So we also have to check that the client's realm is the local one
*/
}
}
#else
/* Hierarchical Cross-Realm */
{
/*
* If the transited list is not empty, then check that all realms
* transited are within the hierarchy between the client's realm
* and the local realm.
*/
}
}
#endif
/* only check rcache if sender has provided one---some services
may not be able to use replay caches (such as datagram servers) */
if ((*auth_context)->rcache) {
if (!retval) {
}
}
/* Solaris Kerberos */
if (retval == KRB5KRB_AP_ERR_SKEW)
goto err_skew;
if (retval)
goto cleanup;
}
if (retval == KRB5KRB_AP_ERR_TKT_NYV) {
/* Solaris Kerberos */
sizeof (timestring),
&fill);
&c_name);
"Ticket not yet valid: client '%s' AP request with ticket for '%s'. Ticket start time is %s."),
if (s_name)
if (c_name)
goto cleanup;
} else if (retval == KRB5KRB_AP_ERR_TKT_EXPIRED) {
/* Solaris Kerberos */
sizeof (timestring),
&fill);
&c_name);
"Ticket expired: client '%s' AP request with ticket for '%s'. Ticket end time is %s."),
if (s_name)
if (c_name)
goto cleanup;
}
if (retval != 0)
goto cleanup;
/* Solaris Kerberos improve error messages */
&skew))) {
&c_name);
"Clock skew too great: client '%s' AP request with ticket for '%s'. Skew is %dm (allowable %dm)."),
if (s_name)
if (c_name)
goto cleanup;
}
if (check_valid_flag) {
/* Solaris Kerberos */
if (!err) {
"Ticket has invalid flag set "
"for server '%s'"),
s_name);
}
goto cleanup;
}
&(*auth_context)->ad_context)))
goto cleanup;
(*auth_context)->ad_context,
req)))
goto cleanup;
}
/* read RFC 4537 etype list from sender */
(*auth_context)->authentp,
if (retval != 0)
goto cleanup;
if (desired_etypes == NULL)
else
(rfc4537_etypes_len + 4) *
sizeof(krb5_enctype));
if (desired_etypes == NULL) {
goto cleanup;
}
/*
* RFC 4537:
*
* If the EtypeList is present and the server prefers an enctype from
* the client's enctype list over that of the AP-REQ authenticator
* subkey (if that is present) or the service ticket session key, the
* server MUST create a subkey using that enctype. This negotiated
* subkey is sent in the subkey field of AP-REP message, and it is then
* used as the protocol key or base key [RFC3961] for subsequent
* communication.
*
* If the enctype of the ticket session key is included in the enctype
* list sent by the client, it SHOULD be the last on the list;
* otherwise, this enctype MUST NOT be negotiated if it was not included
* in the list.
*
* The second paragraph does appear to contradict the first with respect
* to whether it is legal to negotiate the ticket session key type if it
* is absent in the EtypeList. A literal reading suggests that we can use
* the AP-REQ subkey enctype. Also a client has no way of distinguishing
* a server that does not RFC 4537 from one that has chosen the same
* enctype as the ticket session key for the acceptor subkey, surely.
*/
}
} else {
if (retval != 0)
goto cleanup;
}
} else {
permitted_etypes_len = 0;
}
/* check if the various etypes are permitted */
&(*auth_context)->negotiated_etype);
if (retval != 0)
goto cleanup;
/* Solaris Kerberos */
}
&((*auth_context)->recv_subkey))))
goto cleanup;
/* Solaris Kerberos */
}
&((*auth_context)->send_subkey));
if (retval) {
goto cleanup;
}
} else {
(*auth_context)->recv_subkey = 0;
(*auth_context)->send_subkey = 0;
}
/* Solaris Kerberos */
}
&((*auth_context)->key))))
goto cleanup;
/*
* If not AP_OPTS_MUTUAL_REQUIRED then and sequence numbers are used
* then the default sequence number is the one's complement of the
* sequence number sent ot us.
*/
(*auth_context)->remote_seq_number) {
(*auth_context)->local_seq_number ^=
}
if (ticket)
goto cleanup;
if (ap_req_options) {
if (rfc4537_etypes_len != 0)
if ((*auth_context)->negotiated_etype !=
}
retval = 0;
if (desired_etypes != NULL)
if (permitted_etypes != NULL &&
if (server == &princ_data)
if (retval) {
/* only free if we're erroring out...otherwise some
applications will need the output. */
}
if (check_valid_flag)
return retval;
}
/* Solaris Kerberos */
{
1); /* check_valid_flag */
return retval;
}
{
/* Solaris Kerberos */
1); /* check_valid_flag */
return retval;
}
/* Solaris Kerberos */
{
/* Solaris Kerberos */
0); /* don't check_valid_flag */
return retval;
}
const krb5_ap_req *req,
{
/* Solaris Kerberos */
0); /* don't check_valid_flag */
return retval;
}
#ifndef LEAN_CLIENT
static krb5_error_code
{
return(ENOMEM);
return(retval);
}
/* now decode the decrypted stuff */
*authpp = local_auth;
}
return retval;
}
#endif
static krb5_error_code
const krb5_enctype *desired_etypes,
int desired_etypes_len,
const krb5_enctype *permitted_etypes,
int permitted_etypes_len,
{
int i, j;
/* mandatory segment of desired_etypes must be permitted */
for (i = mandatory_etypes_index; i < desired_etypes_len; i++) {
for (j = 0; j < permitted_etypes_len; j++) {
if (desired_etypes[i] == permitted_etypes[j]) {
break;
}
}
if (krb5_enctype_to_string(desired_etypes[i],
sizeof(enctype_name)) == 0)
"Encryption type %s not permitted"),
return KRB5_NOPERM_ETYPE;
}
}
/*
* permitted_etypes is ordered from most to least preferred;
* find first desired_etype that matches.
*/
for (j = 0; j < permitted_etypes_len; j++) {
for (i = 0; i < desired_etypes_len; i++) {
if (desired_etypes[i] == permitted_etypes[j]) {
*negotiated_etype = permitted_etypes[j];
return 0;
}
}
}
/*NOTREACHED*/
return KRB5_NOPERM_ETYPE;
}
static krb5_error_code
const krb5_authenticator *authp,
int *desired_etypes_len)
{
int i, j;
*desired_etypes = NULL;
return 0;
/*
* RFC 4537 says that ETYPE_NEGOTIATION auth data should be wrapped
* in AD_IF_RELEVANT, but we handle the case where it is mandatory.
*/
authp->authorization_data[i],
if (code != 0)
continue;
for (j = 0; ad_if_relevant[j] != NULL; j++) {
etype_adata = ad_if_relevant[j];
break;
}
}
if (etype_adata == NULL) {
}
break;
break;
default:
break;
}
if (etype_adata != NULL)
break;
}
if (etype_adata == NULL)
return 0;
if (code == 0) {
}
if (ad_if_relevant != NULL)
return code;
}