Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / sunrpc / auth_gss / gss_spkm3_unseal.c
blob65ce81bf0bc45789d1bbda9d2d944c41ca6a95c8
1 /*
2 * linux/net/sunrpc/gss_spkm3_unseal.c
4 * Copyright (c) 2003 The Regents of the University of Michigan.
5 * All rights reserved.
7 * Andy Adamson <andros@umich.edu>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <linux/types.h>
37 #include <linux/slab.h>
38 #include <linux/jiffies.h>
39 #include <linux/sunrpc/gss_spkm3.h>
40 #include <linux/crypto.h>
42 #ifdef RPC_DEBUG
43 # define RPCDBG_FACILITY RPCDBG_AUTH
44 #endif
47 * spkm3_read_token()
49 * only SPKM_MIC_TOK with md5 intg-alg is supported
51 u32
52 spkm3_read_token(struct spkm3_ctx *ctx,
53 struct xdr_netobj *read_token, /* checksum */
54 struct xdr_buf *message_buffer, /* signbuf */
55 int *qop_state, int toktype)
57 s32 code;
58 struct xdr_netobj wire_cksum = {.len =0, .data = NULL};
59 struct xdr_netobj md5cksum = {.len = 0, .data = NULL};
60 unsigned char *ptr = (unsigned char *)read_token->data;
61 unsigned char *cksum;
62 int bodysize, md5elen;
63 int mic_hdrlen;
64 u32 ret = GSS_S_DEFECTIVE_TOKEN;
66 dprintk("RPC: spkm3_read_token read_token->len %d\n", read_token->len);
68 if (g_verify_token_header((struct xdr_netobj *) &ctx->mech_used,
69 &bodysize, &ptr, read_token->len))
70 goto out;
72 /* decode the token */
74 if (toktype == SPKM_MIC_TOK) {
76 if ((ret = spkm3_verify_mic_token(&ptr, &mic_hdrlen, &cksum)))
77 goto out;
79 if (*cksum++ != 0x03) {
80 dprintk("RPC: spkm3_read_token BAD checksum type\n");
81 goto out;
83 md5elen = *cksum++;
84 cksum++; /* move past the zbit */
86 if(!decode_asn1_bitstring(&wire_cksum, cksum, md5elen - 1, 16))
87 goto out;
89 /* HARD CODED FOR MD5 */
91 /* compute the checksum of the message.
92 * ptr + 2 = start of header piece of checksum
93 * mic_hdrlen + 2 = length of header piece of checksum
95 ret = GSS_S_DEFECTIVE_TOKEN;
96 code = make_checksum(CKSUMTYPE_RSA_MD5, ptr + 2,
97 mic_hdrlen + 2,
98 message_buffer, &md5cksum);
100 if (code)
101 goto out;
103 dprintk("RPC: spkm3_read_token: digest wire_cksum.len %d:\n",
104 wire_cksum.len);
105 dprintk(" md5cksum.data\n");
106 print_hexl((u32 *) md5cksum.data, 16, 0);
107 dprintk(" cksum.data:\n");
108 print_hexl((u32 *) wire_cksum.data, wire_cksum.len, 0);
110 ret = GSS_S_BAD_SIG;
111 code = memcmp(md5cksum.data, wire_cksum.data, wire_cksum.len);
112 if (code)
113 goto out;
115 } else {
116 dprintk("RPC: BAD or UNSUPPORTED SPKM3 token type: %d\n",toktype);
117 goto out;
120 /* XXX: need to add expiration and sequencing */
121 ret = GSS_S_COMPLETE;
122 out:
123 if (md5cksum.data)
124 kfree(md5cksum.data);
125 if (wire_cksum.data)
126 kfree(wire_cksum.data);
127 return ret;