2005-04-16 15:20:36 -07:00
/*
* linux / net / sunrpc / gss_krb5_seal . c
*
* Adapted from MIT Kerberos 5 - 1.2 .1 lib / gssapi / krb5 / k5seal . c
*
* Copyright ( c ) 2000 The Regents of the University of Michigan .
* All rights reserved .
*
* Andy Adamson < andros @ umich . edu >
* J . Bruce Fields < bfields @ umich . edu >
*/
/*
* Copyright 1993 by OpenVision Technologies , Inc .
*
* Permission to use , copy , modify , distribute , and sell this software
* and its documentation for any purpose is hereby granted without fee ,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation , and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific , written prior permission . OpenVision makes no
* representations about the suitability of this software for any
* purpose . It is provided " as is " without express or implied warranty .
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE ,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS , IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL , INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE , DATA OR PROFITS , WHETHER IN AN ACTION OF CONTRACT , NEGLIGENCE OR
* OTHER TORTIOUS ACTION , ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE .
*/
/*
* Copyright ( C ) 1998 by the FundsXpress , INC .
*
* 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 FundsXpress . not be used in advertising or publicity pertaining
* to distribution of the software without specific , written prior
* permission . FundsXpress makes no representations about the suitability of
* this software for any purpose . It is provided " as is " without express
* or implied warranty .
*
* THIS SOFTWARE IS PROVIDED ` ` AS IS ' ' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , WITHOUT LIMITATION , THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE .
*/
# include <linux/types.h>
# include <linux/slab.h>
# include <linux/jiffies.h>
# include <linux/sunrpc/gss_krb5.h>
# include <linux/random.h>
# include <linux/crypto.h>
# ifdef RPC_DEBUG
# define RPCDBG_FACILITY RPCDBG_AUTH
# endif
2006-06-27 02:53:55 -07:00
DEFINE_SPINLOCK ( krb5_seq_lock ) ;
2006-03-20 23:24:04 -05:00
2005-04-16 15:20:36 -07:00
u32
2005-10-13 16:55:23 -04:00
gss_get_mic_kerberos ( struct gss_ctx * gss_ctx , struct xdr_buf * text ,
struct xdr_netobj * token )
2005-04-16 15:20:36 -07:00
{
2005-10-13 16:55:23 -04:00
struct krb5_ctx * ctx = gss_ctx - > internal_ctx_id ;
2006-03-20 23:23:11 -05:00
char cksumdata [ 16 ] ;
struct xdr_netobj md5cksum = { . len = 0 , . data = cksumdata } ;
2005-04-16 15:20:36 -07:00
unsigned char * ptr , * krb5_hdr , * msg_start ;
s32 now ;
2006-03-20 23:24:04 -05:00
u32 seq_send ;
2005-04-16 15:20:36 -07:00
2007-01-31 12:14:05 -05:00
dprintk ( " RPC: gss_krb5_seal \n " ) ;
2007-11-09 18:42:09 -05:00
BUG_ON ( ctx = = NULL ) ;
2005-04-16 15:20:36 -07:00
now = get_seconds ( ) ;
2008-03-31 10:31:44 -04:00
token - > len = g_token_size ( & ctx - > mech_used , 24 ) ;
2005-04-16 15:20:36 -07:00
ptr = token - > data ;
2008-03-31 10:31:44 -04:00
g_make_token_header ( & ctx - > mech_used , 24 , & ptr ) ;
2005-04-16 15:20:36 -07:00
2005-10-13 16:55:08 -04:00
* ptr + + = ( unsigned char ) ( ( KG_TOK_MIC_MSG > > 8 ) & 0xff ) ;
* ptr + + = ( unsigned char ) ( KG_TOK_MIC_MSG & 0xff ) ;
2005-04-16 15:20:36 -07:00
/* ptr now at byte 2 of header described in rfc 1964, section 1.2.1: */
krb5_hdr = ptr - 2 ;
msg_start = krb5_hdr + 24 ;
2006-12-04 20:22:35 -05:00
* ( __be16 * ) ( krb5_hdr + 2 ) = htons ( SGN_ALG_DES_MAC_MD5 ) ;
2005-04-16 15:20:36 -07:00
memset ( krb5_hdr + 4 , 0xff , 4 ) ;
2006-12-04 20:22:38 -05:00
if ( make_checksum ( " md5 " , krb5_hdr , 8 , text , 0 , & md5cksum ) )
2006-12-04 20:22:39 -05:00
return GSS_S_FAILURE ;
2006-12-04 20:22:35 -05:00
if ( krb5_encrypt ( ctx - > seq , NULL , md5cksum . data ,
md5cksum . data , md5cksum . len ) )
2006-12-04 20:22:39 -05:00
return GSS_S_FAILURE ;
2006-12-04 20:22:42 -05:00
2008-02-21 13:44:27 -05:00
memcpy ( krb5_hdr + 16 , md5cksum . data + md5cksum . len - 8 , 8 ) ;
2005-04-16 15:20:36 -07:00
2006-03-20 23:24:04 -05:00
spin_lock ( & krb5_seq_lock ) ;
seq_send = ctx - > seq_send + + ;
spin_unlock ( & krb5_seq_lock ) ;
2006-12-04 20:22:42 -05:00
if ( krb5_make_seq_num ( ctx - > seq , ctx - > initiate ? 0 : 0xff ,
2008-03-31 10:31:33 -04:00
seq_send , krb5_hdr + 16 , krb5_hdr + 8 ) )
2006-12-04 20:22:39 -05:00
return GSS_S_FAILURE ;
2005-04-16 15:20:36 -07:00
2006-12-04 20:22:42 -05:00
return ( ctx - > endtime < now ) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE ;
2005-04-16 15:20:36 -07:00
}