2 * linux/net/sunrpc/gss_krb5_unseal.c
4 * Adapted from MIT Kerberos 5-1.2.1 lib/gssapi/krb5/k5unseal.c
6 * Copyright (c) 2000-2008 The Regents of the University of Michigan.
9 * Andy Adamson <andros@umich.edu>
13 * Copyright 1993 by OpenVision Technologies, Inc.
15 * Permission to use, copy, modify, distribute, and sell this software
16 * and its documentation for any purpose is hereby granted without fee,
17 * provided that the above copyright notice appears in all copies and
18 * that both that copyright notice and this permission notice appear in
19 * supporting documentation, and that the name of OpenVision not be used
20 * in advertising or publicity pertaining to distribution of the software
21 * without specific, written prior permission. OpenVision makes no
22 * representations about the suitability of this software for any
23 * purpose. It is provided "as is" without express or implied warranty.
25 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
26 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
27 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
28 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
29 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
30 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31 * PERFORMANCE OF THIS SOFTWARE.
35 * Copyright (C) 1998 by the FundsXpress, INC.
37 * All rights reserved.
39 * Export of this software from the United States of America may require
40 * a specific license from the United States Government. It is the
41 * responsibility of any person or organization contemplating export to
42 * obtain such a license before exporting.
44 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
45 * distribute this software and its documentation for any purpose and
46 * without fee is hereby granted, provided that the above copyright
47 * notice appear in all copies and that both that copyright notice and
48 * this permission notice appear in supporting documentation, and that
49 * the name of FundsXpress. not be used in advertising or publicity pertaining
50 * to distribution of the software without specific, written prior
51 * permission. FundsXpress makes no representations about the suitability of
52 * this software for any purpose. It is provided "as is" without express
53 * or implied warranty.
55 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
56 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
57 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60 #include <linux/types.h>
61 #include <linux/jiffies.h>
62 #include <linux/sunrpc/gss_krb5.h>
64 #include "gss_krb5_internal.h"
66 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
67 # define RPCDBG_FACILITY RPCDBG_AUTH
71 gss_krb5_verify_mic_v2(struct krb5_ctx
*ctx
, struct xdr_buf
*message_buffer
,
72 struct xdr_netobj
*read_token
)
74 struct crypto_ahash
*tfm
= ctx
->initiate
?
75 ctx
->acceptor_sign
: ctx
->initiator_sign
;
76 char cksumdata
[GSS_KRB5_MAX_CKSUM_LEN
];
77 struct xdr_netobj cksumobj
= {
78 .len
= ctx
->gk5e
->cksumlength
,
81 u8
*ptr
= read_token
->data
;
87 dprintk("RPC: %s\n", __func__
);
89 memcpy(&be16_ptr
, (char *) ptr
, 2);
90 if (be16_to_cpu(be16_ptr
) != KG2_TOK_MIC
)
91 return GSS_S_DEFECTIVE_TOKEN
;
94 if ((!ctx
->initiate
&& (flags
& KG2_TOKEN_FLAG_SENTBYACCEPTOR
)) ||
95 (ctx
->initiate
&& !(flags
& KG2_TOKEN_FLAG_SENTBYACCEPTOR
)))
98 if (flags
& KG2_TOKEN_FLAG_SEALED
) {
99 dprintk("%s: token has unexpected sealed flag\n", __func__
);
100 return GSS_S_FAILURE
;
103 for (i
= 3; i
< 8; i
++)
105 return GSS_S_DEFECTIVE_TOKEN
;
107 if (gss_krb5_checksum(tfm
, ptr
, GSS_KRB5_TOK_HDR_LEN
,
108 message_buffer
, 0, &cksumobj
))
109 return GSS_S_FAILURE
;
111 if (memcmp(cksumobj
.data
, ptr
+ GSS_KRB5_TOK_HDR_LEN
,
112 ctx
->gk5e
->cksumlength
))
113 return GSS_S_BAD_SIG
;
115 /* it got through unscathed. Make sure the context is unexpired */
116 now
= ktime_get_real_seconds();
117 if (now
> ctx
->endtime
)
118 return GSS_S_CONTEXT_EXPIRED
;
121 * NOTE: the sequence number at ptr + 8 is skipped, rpcsec_gss
122 * doesn't want it checked; see page 6 of rfc 2203.
125 return GSS_S_COMPLETE
;