[PATCH] x86_64: Fix 64bit FXSAVE encoding
[linux-2.6/libata-dev.git] / net / sunrpc / auth_gss / gss_krb5_unseal.c
blobdb055fd7d7789c22ef62e4e8faab7ebac7cafebd
1 /*
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 The Regents of the University of Michigan.
7 * All rights reserved.
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/slab.h>
62 #include <linux/jiffies.h>
63 #include <linux/sunrpc/gss_krb5.h>
64 #include <linux/crypto.h>
66 #ifdef RPC_DEBUG
67 # define RPCDBG_FACILITY RPCDBG_AUTH
68 #endif
71 /* read_token is a mic token, and message_buffer is the data that the mic was
72 * supposedly taken over. */
74 u32
75 gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
76 struct xdr_buf *message_buffer, struct xdr_netobj *read_token)
78 struct krb5_ctx *ctx = gss_ctx->internal_ctx_id;
79 int signalg;
80 int sealalg;
81 s32 checksum_type;
82 struct xdr_netobj md5cksum = {.len = 0, .data = NULL};
83 s32 now;
84 int direction;
85 s32 seqnum;
86 unsigned char *ptr = (unsigned char *)read_token->data;
87 int bodysize;
88 u32 ret = GSS_S_DEFECTIVE_TOKEN;
90 dprintk("RPC: krb5_read_token\n");
92 if (g_verify_token_header(&ctx->mech_used, &bodysize, &ptr,
93 read_token->len))
94 goto out;
96 if ((*ptr++ != ((KG_TOK_MIC_MSG>>8)&0xff)) ||
97 (*ptr++ != ( KG_TOK_MIC_MSG &0xff)) )
98 goto out;
100 /* XXX sanity-check bodysize?? */
102 /* get the sign and seal algorithms */
104 signalg = ptr[0] + (ptr[1] << 8);
105 sealalg = ptr[2] + (ptr[3] << 8);
107 /* Sanity checks */
109 if ((ptr[4] != 0xff) || (ptr[5] != 0xff))
110 goto out;
112 if (sealalg != 0xffff)
113 goto out;
115 /* there are several mappings of seal algorithms to sign algorithms,
116 but few enough that we can try them all. */
118 if ((ctx->sealalg == SEAL_ALG_NONE && signalg > 1) ||
119 (ctx->sealalg == SEAL_ALG_1 && signalg != SGN_ALG_3) ||
120 (ctx->sealalg == SEAL_ALG_DES3KD &&
121 signalg != SGN_ALG_HMAC_SHA1_DES3_KD))
122 goto out;
124 /* compute the checksum of the message */
126 /* initialize the the cksum */
127 switch (signalg) {
128 case SGN_ALG_DES_MAC_MD5:
129 checksum_type = CKSUMTYPE_RSA_MD5;
130 break;
131 default:
132 ret = GSS_S_DEFECTIVE_TOKEN;
133 goto out;
136 switch (signalg) {
137 case SGN_ALG_DES_MAC_MD5:
138 ret = make_checksum(checksum_type, ptr - 2, 8,
139 message_buffer, 0, &md5cksum);
140 if (ret)
141 goto out;
143 ret = krb5_encrypt(ctx->seq, NULL, md5cksum.data,
144 md5cksum.data, 16);
145 if (ret)
146 goto out;
148 if (memcmp(md5cksum.data + 8, ptr + 14, 8)) {
149 ret = GSS_S_BAD_SIG;
150 goto out;
152 break;
153 default:
154 ret = GSS_S_DEFECTIVE_TOKEN;
155 goto out;
158 /* it got through unscathed. Make sure the context is unexpired */
160 now = get_seconds();
162 ret = GSS_S_CONTEXT_EXPIRED;
163 if (now > ctx->endtime)
164 goto out;
166 /* do sequencing checks */
168 ret = GSS_S_BAD_SIG;
169 if ((ret = krb5_get_seq_num(ctx->seq, ptr + 14, ptr + 6, &direction,
170 &seqnum)))
171 goto out;
173 if ((ctx->initiate && direction != 0xff) ||
174 (!ctx->initiate && direction != 0))
175 goto out;
177 ret = GSS_S_COMPLETE;
178 out:
179 kfree(md5cksum.data);
180 return ret;