blob: 86fbf7c3e39ca0e96fd7b31f17bceb9f068b1ce8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/net/sunrpc/gss_spkm3_seal.c
3 *
4 * Copyright (c) 2003 The Regents of the University of Michigan.
5 * All rights reserved.
6 *
7 * Andy Adamson <andros@umich.edu>
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
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.
21 *
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.
33 *
34 */
35
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/random.h>
41#include <linux/crypto.h>
42
43#ifdef RPC_DEBUG
44# define RPCDBG_FACILITY RPCDBG_AUTH
45#endif
46
47/*
48 * spkm3_make_token()
49 *
50 * Only SPKM_MIC_TOK with md5 intg-alg is supported
51 */
52
53u32
J. Bruce Fields00fd6e12005-10-13 16:55:18 -040054spkm3_make_token(struct spkm3_ctx *ctx,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 struct xdr_buf * text, struct xdr_netobj * token,
56 int toktype)
57{
58 s32 checksum_type;
59 char tokhdrbuf[25];
60 struct xdr_netobj md5cksum = {.len = 0, .data = NULL};
61 struct xdr_netobj mic_hdr = {.len = 0, .data = tokhdrbuf};
J. Bruce Fields9eed1292006-01-03 09:56:00 +010062 int tokenlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned char *ptr;
64 s32 now;
65 int ctxelen = 0, ctxzbit = 0;
66 int md5elen = 0, md5zbit = 0;
67
68 dprintk("RPC: spkm3_make_token\n");
69
70 now = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 if (ctx->ctx_id.len != 16) {
73 dprintk("RPC: spkm3_make_token BAD ctx_id.len %d\n",
74 ctx->ctx_id.len);
75 goto out_err;
76 }
77
78 switch (ctx->intg_alg) {
79 case NID_md5:
80 checksum_type = CKSUMTYPE_RSA_MD5;
81 break;
82 default:
83 dprintk("RPC: gss_spkm3_seal: ctx->signalg %d not"
84 " supported\n", ctx->intg_alg);
85 goto out_err;
86 }
87 /* XXX since we don't support WRAP, perhaps we don't care... */
88 if (ctx->conf_alg != NID_cast5_cbc) {
89 dprintk("RPC: gss_spkm3_seal: ctx->sealalg %d not supported\n",
90 ctx->conf_alg);
91 goto out_err;
92 }
93
94 if (toktype == SPKM_MIC_TOK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 /* Calculate checksum over the mic-header */
96 asn1_bitstring_len(&ctx->ctx_id, &ctxelen, &ctxzbit);
97 spkm3_mic_header(&mic_hdr.data, &mic_hdr.len, ctx->ctx_id.data,
98 ctxelen, ctxzbit);
99
100 if (make_checksum(checksum_type, mic_hdr.data, mic_hdr.len,
J. Bruce Fields9eed1292006-01-03 09:56:00 +0100101 text, 0, &md5cksum))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 goto out_err;
103
104 asn1_bitstring_len(&md5cksum, &md5elen, &md5zbit);
J. Bruce Fields9eed1292006-01-03 09:56:00 +0100105 tokenlen = 10 + ctxelen + 1 + md5elen + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 /* Create token header using generic routines */
J. Bruce Fields9eed1292006-01-03 09:56:00 +0100108 token->len = g_token_size(&ctx->mech_used, tokenlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 ptr = token->data;
J. Bruce Fields9eed1292006-01-03 09:56:00 +0100111 g_make_token_header(&ctx->mech_used, tokenlen, &ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 spkm3_make_mic_token(&ptr, tokenlen, &mic_hdr, &md5cksum, md5elen, md5zbit);
114 } else if (toktype == SPKM_WRAP_TOK) { /* Not Supported */
115 dprintk("RPC: gss_spkm3_seal: SPKM_WRAP_TOK not supported\n");
116 goto out_err;
117 }
118 kfree(md5cksum.data);
119
120 /* XXX need to implement sequence numbers, and ctx->expired */
121
122 return GSS_S_COMPLETE;
123out_err:
Jesper Juhla51482b2005-11-08 09:41:34 -0800124 kfree(md5cksum.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 token->data = NULL;
126 token->len = 0;
127 return GSS_S_FAILURE;
128}