Back to index

glibc  2.9
Defines | Functions | Variables
auth_des.h File Reference
#include <sunrpc/rpc/auth_des.h>

Go to the source code of this file.

Defines

#define DECLARE_NSS_PROTOTYPES(service)

Functions

 libc_hidden_proto (getpublickey) libc_hidden_proto(rtime) extern bool_t xdr_authdes_cred(XDR *xdrs
bool_t xdr_authdes_verf (register XDR *xdrs, register struct authdes_verf *verf)
enum auth_stat _svcauth_des (register struct svc_req *rqst, register struct rpc_msg *msg)

Variables

struct authdes_credcred

Define Documentation

#define DECLARE_NSS_PROTOTYPES (   service)
Value:
extern enum nss_status _nss_ ## service ## _getpublickey              \
                       (const char *netname, char *pkey, int *errnop);       \
extern enum nss_status _nss_ ## service ## _getsecretkey              \
                       (const char *netname, char *skey, char *passwd,       \
                     int *errnop);

Definition at line 17 of file auth_des.h.


Function Documentation

enum auth_stat _svcauth_des ( register struct svc_req rqst,
register struct rpc_msg msg 
)

Definition at line 107 of file svcauth_des.c.

{
  register uint32_t *ixdr;
  des_block cryptbuf[2];
  register struct authdes_cred *cred;
  struct authdes_verf verf;
  int status;
  register struct cache_entry *entry;
  uint32_t sid = 0;
  des_block *sessionkey;
  des_block ivec;
  u_int window;
  struct rpc_timeval timestamp;
  uint32_t namelen;
  struct area
    {
      struct authdes_cred area_cred;
      char area_netname[MAXNETNAMELEN + 1];
    }
   *area;

  if (authdes_cache == NULL)
    cache_init ();
  if (authdes_cache == NULL) /* No free memory */
    return AUTH_FAILED;

  area = (struct area *) rqst->rq_clntcred;
  cred = (struct authdes_cred *) &area->area_cred;

  /*
   * Get the credential
   */
  if (msg->rm_call.cb_cred.oa_length <= 0 ||
      msg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
    return AUTH_BADCRED;

  ixdr = (uint32_t *) msg->rm_call.cb_cred.oa_base;
  cred->adc_namekind = IXDR_GET_ENUM (ixdr, enum authdes_namekind);
  switch (cred->adc_namekind)
    {
    case ADN_FULLNAME:
      namelen = IXDR_GET_U_INT32 (ixdr);
      if (namelen > MAXNETNAMELEN)
       {
         return AUTH_BADCRED;
       }
      cred->adc_fullname.name = area->area_netname;
      memcpy (cred->adc_fullname.name, (char *) ixdr, namelen);
      cred->adc_fullname.name[namelen] = 0;
      ixdr += (RNDUP (namelen) / BYTES_PER_XDR_UNIT);
      cred->adc_fullname.key.key.high = *ixdr++;
      cred->adc_fullname.key.key.low = *ixdr++;
      cred->adc_fullname.window = *ixdr++;
      break;
    case ADN_NICKNAME:
      cred->adc_nickname = *ixdr++;
      break;
    default:
      return AUTH_BADCRED;
    }

  /*
   * Get the verifier
   */
  if (msg->rm_call.cb_verf.oa_length <= 0 ||
      msg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
    return AUTH_BADCRED;

  ixdr = (uint32_t *) msg->rm_call.cb_verf.oa_base;
  verf.adv_xtimestamp.key.high = *ixdr++;
  verf.adv_xtimestamp.key.low = *ixdr++;
  verf.adv_int_u = *ixdr++;

  /*
   * Get the conversation key
   */
  if (cred->adc_namekind == ADN_FULLNAME)
    {
      netobj pkey;
      char pkey_data[1024];

      sessionkey = &cred->adc_fullname.key;
      if (!getpublickey (cred->adc_fullname.name, pkey_data))
       {
         debug("getpublickey");
         return AUTH_BADCRED;
       }
      pkey.n_bytes = pkey_data;
      pkey.n_len = strlen (pkey_data) + 1;
      if (key_decryptsession_pk (cred->adc_fullname.name, &pkey,
                             sessionkey) < 0)
       {
         debug ("decryptsessionkey");
         return AUTH_BADCRED;      /* key not found */
       }
    }
  else
    {                       /* ADN_NICKNAME */
      if (cred->adc_nickname >= AUTHDES_CACHESZ)
       {
         debug ("bad nickname");
         return AUTH_BADCRED;      /* garbled credential */
       }
      else
       sid = cred->adc_nickname;

      /* XXX This could be wrong, but else we have a
        security problem */
      if (authdes_cache[sid].rname == NULL)
       return AUTH_BADCRED;
      sessionkey = &authdes_cache[sid].key;
    }


  /*
   * Decrypt the timestamp
   */
  cryptbuf[0] = verf.adv_xtimestamp;
  if (cred->adc_namekind == ADN_FULLNAME)
    {
      cryptbuf[1].key.high = cred->adc_fullname.window;
      cryptbuf[1].key.low = verf.adv_winverf;
      ivec.key.high = ivec.key.low = 0;
      status = cbc_crypt ((char *) sessionkey, (char *) cryptbuf,
                       2 * sizeof (des_block), DES_DECRYPT | DES_HW,
                       (char *) &ivec);
    }
  else
    status = ecb_crypt ((char *) sessionkey, (char *) cryptbuf,
                     sizeof (des_block), DES_DECRYPT | DES_HW);

  if (DES_FAILED (status))
    {
      debug ("decryption failure");
      return AUTH_FAILED;   /* system error */
    }

  /*
   * XDR the decrypted timestamp
   */
  ixdr = (uint32_t *) cryptbuf;
  timestamp.tv_sec = IXDR_GET_INT32 (ixdr);
  timestamp.tv_usec = IXDR_GET_INT32 (ixdr);

  /*
   * Check for valid credentials and verifiers.
   * They could be invalid because the key was flushed
   * out of the cache, and so a new session should begin.
   * Be sure and send AUTH_REJECTED{CRED, VERF} if this is the case.
   */
  {
    struct timeval current;
    int nick;
    u_int winverf;

    if (cred->adc_namekind == ADN_FULLNAME)
      {
       short tmp_spot;

       window = IXDR_GET_U_INT32 (ixdr);
       winverf = IXDR_GET_U_INT32 (ixdr);
       if (winverf != window - 1)
         {
           debug ("window verifier mismatch");
           return AUTH_BADCRED;    /* garbled credential */
         }
       tmp_spot = cache_spot (sessionkey, cred->adc_fullname.name,
                            &timestamp);
       if (tmp_spot < 0 || tmp_spot > AUTHDES_CACHESZ)
         {
           debug ("replayed credential");
           return AUTH_REJECTEDCRED;             /* replay */
         }
       sid = tmp_spot;
       nick = 0;
      }
    else
      {                            /* ADN_NICKNAME */
       window = authdes_cache[sid].window;
       nick = 1;
      }

    if (timestamp.tv_usec >= USEC_PER_SEC)
      {
       debug ("invalid usecs");
       /* cached out (bad key), or garbled verifier */
       return nick ? AUTH_REJECTEDVERF : AUTH_BADVERF;
      }
    if (nick && BEFORE (&timestamp, &authdes_cache[sid].laststamp))
      {
       debug ("timestamp before last seen");
       return AUTH_REJECTEDVERF;   /* replay */
      }
    __gettimeofday (&current, (struct timezone *) NULL);
    current.tv_sec -= window;      /* allow for expiration */
    if (!BEFORE (&current, &timestamp))
      {
       debug ("timestamp expired");
       /* replay, or garbled credential */
       return nick ? AUTH_REJECTEDVERF : AUTH_BADCRED;
      }
  }

  /*
   * Set up the reply verifier
   */
  verf.adv_nickname = sid;

  /*
   * xdr the timestamp before encrypting
   */
  ixdr = (uint32_t *) cryptbuf;
  IXDR_PUT_INT32 (ixdr, timestamp.tv_sec - 1);
  IXDR_PUT_INT32 (ixdr, timestamp.tv_usec);

  /*
   * encrypt the timestamp
   */
  status = ecb_crypt ((char *) sessionkey, (char *) cryptbuf,
                    sizeof (des_block), DES_ENCRYPT | DES_HW);
  if (DES_FAILED (status))
    {
      debug ("encryption failure");
      return AUTH_FAILED;   /* system error */
    }
  verf.adv_xtimestamp = cryptbuf[0];

  /*
   * Serialize the reply verifier, and update rqst
   */
  ixdr = (uint32_t *) msg->rm_call.cb_verf.oa_base;
  *ixdr++ = verf.adv_xtimestamp.key.high;
  *ixdr++ = verf.adv_xtimestamp.key.low;
  *ixdr++ = verf.adv_int_u;

  rqst->rq_xprt->xp_verf.oa_flavor = AUTH_DES;
  rqst->rq_xprt->xp_verf.oa_base = msg->rm_call.cb_verf.oa_base;
  rqst->rq_xprt->xp_verf.oa_length =
    (char *) ixdr - msg->rm_call.cb_verf.oa_base;

  /*
   * We succeeded, commit the data to the cache now and
   * finish cooking the credential.
   */
  entry = &authdes_cache[sid];
  entry->laststamp = timestamp;
  cache_ref (sid);
  if (cred->adc_namekind == ADN_FULLNAME)
    {
      size_t full_len;

      cred->adc_fullname.window = window;
      cred->adc_nickname = sid;    /* save nickname */
      if (entry->rname != NULL)
       mem_free (entry->rname, strlen (entry->rname) + 1);
      full_len = strlen (cred->adc_fullname.name) + 1;
      entry->rname = mem_alloc ((u_int) full_len);
      if (entry->rname != NULL)
       memcpy (entry->rname, cred->adc_fullname.name, full_len);
      else
       {
         debug ("out of memory");
         return AUTH_FAILED; /* out of memory is bad */
       }
      entry->key = *sessionkey;
      entry->window = window;
      invalidate (entry->localcred);      /* mark any cached cred invalid */
    }
  else
    {                       /* ADN_NICKNAME */
      /*
       * nicknames are cooked into fullnames
       */
      cred->adc_namekind = ADN_FULLNAME;
      cred->adc_fullname.name = entry->rname;
      cred->adc_fullname.key = entry->key;
      cred->adc_fullname.window = entry->window;
    }
  return AUTH_OK;           /* we made it! */
}

Here is the call graph for this function:

bool_t xdr_authdes_verf ( register XDR xdrs,
register struct authdes_verf verf 
)

Definition at line 72 of file authdes_prot.c.

{
  /*
   * Unrolled xdr
   */
  ATTEMPT (INTUSE(xdr_opaque) (xdrs, (caddr_t) & verf->adv_xtimestamp,
                            sizeof (des_block)));
  ATTEMPT (INTUSE(xdr_opaque) (xdrs, (caddr_t) & verf->adv_int_u,
                            sizeof (verf->adv_int_u)));
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct authdes_cred* cred

Definition at line 8 of file auth_des.h.