2 * linux/net/sunrpc/gss_spkm3_mech.c
4 * Copyright (c) 2003 The Regents of the University of Michigan.
7 * Andy Adamson <andros@umich.edu>
8 * J. Bruce Fields <bfields@umich.edu>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <linux/err.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/types.h>
41 #include <linux/slab.h>
42 #include <linux/sunrpc/auth.h>
44 #include <linux/sunrpc/svcauth_gss.h>
45 #include <linux/sunrpc/gss_spkm3.h>
46 #include <linux/sunrpc/xdr.h>
47 #include <linux/crypto.h>
50 # define RPCDBG_FACILITY RPCDBG_AUTH
54 simple_get_bytes(const void *p, const void *end, void *res, int len)
56 const void *q = (const void *)((const char *)p + len);
57 if (unlikely(q > end || q < p))
58 return ERR_PTR(-EFAULT);
64 simple_get_netobj(const void *p, const void *end, struct xdr_netobj *res)
68 p = simple_get_bytes(p, end, &len, sizeof(len));
76 q = (const void *)((const char *)p + len);
77 if (unlikely(q > end || q < p))
78 return ERR_PTR(-EFAULT);
79 res->data = kmemdup(p, len, GFP_NOFS);
80 if (unlikely(res->data == NULL))
81 return ERR_PTR(-ENOMEM);
86 gss_import_sec_context_spkm3(const void *p, size_t len,
87 struct gss_ctx *ctx_id,
90 const void *end = (const void *)((const char *)p + len);
91 struct spkm3_ctx *ctx;
94 if (!(ctx = kzalloc(sizeof(*ctx), gfp_mask)))
97 p = simple_get_bytes(p, end, &version, sizeof(version));
99 goto out_err_free_ctx;
101 dprintk("RPC: unknown spkm3 token format: "
102 "obsolete nfs-utils?\n");
103 p = ERR_PTR(-EINVAL);
104 goto out_err_free_ctx;
107 p = simple_get_netobj(p, end, &ctx->ctx_id);
109 goto out_err_free_ctx;
111 p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
113 goto out_err_free_ctx_id;
115 p = simple_get_netobj(p, end, &ctx->mech_used);
117 goto out_err_free_ctx_id;
119 p = simple_get_bytes(p, end, &ctx->ret_flags, sizeof(ctx->ret_flags));
121 goto out_err_free_mech;
123 p = simple_get_netobj(p, end, &ctx->conf_alg);
125 goto out_err_free_mech;
127 p = simple_get_netobj(p, end, &ctx->derived_conf_key);
129 goto out_err_free_conf_alg;
131 p = simple_get_netobj(p, end, &ctx->intg_alg);
133 goto out_err_free_conf_key;
135 p = simple_get_netobj(p, end, &ctx->derived_integ_key);
137 goto out_err_free_intg_alg;
140 p = ERR_PTR(-EFAULT);
141 goto out_err_free_intg_key;
144 ctx_id->internal_ctx_id = ctx;
146 dprintk("RPC: Successfully imported new spkm context.\n");
149 out_err_free_intg_key:
150 kfree(ctx->derived_integ_key.data);
151 out_err_free_intg_alg:
152 kfree(ctx->intg_alg.data);
153 out_err_free_conf_key:
154 kfree(ctx->derived_conf_key.data);
155 out_err_free_conf_alg:
156 kfree(ctx->conf_alg.data);
158 kfree(ctx->mech_used.data);
160 kfree(ctx->ctx_id.data);
168 gss_delete_sec_context_spkm3(void *internal_ctx)
170 struct spkm3_ctx *sctx = internal_ctx;
172 kfree(sctx->derived_integ_key.data);
173 kfree(sctx->intg_alg.data);
174 kfree(sctx->derived_conf_key.data);
175 kfree(sctx->conf_alg.data);
176 kfree(sctx->mech_used.data);
177 kfree(sctx->ctx_id.data);
182 gss_verify_mic_spkm3(struct gss_ctx *ctx,
183 struct xdr_buf *signbuf,
184 struct xdr_netobj *checksum)
187 struct spkm3_ctx *sctx = ctx->internal_ctx_id;
189 maj_stat = spkm3_read_token(sctx, checksum, signbuf, SPKM_MIC_TOK);
191 dprintk("RPC: gss_verify_mic_spkm3 returning %d\n", maj_stat);
196 gss_get_mic_spkm3(struct gss_ctx *ctx,
197 struct xdr_buf *message_buffer,
198 struct xdr_netobj *message_token)
201 struct spkm3_ctx *sctx = ctx->internal_ctx_id;
203 err = spkm3_make_token(sctx, message_buffer,
204 message_token, SPKM_MIC_TOK);
205 dprintk("RPC: gss_get_mic_spkm3 returning %d\n", err);
209 static const struct gss_api_ops gss_spkm3_ops = {
210 .gss_import_sec_context = gss_import_sec_context_spkm3,
211 .gss_get_mic = gss_get_mic_spkm3,
212 .gss_verify_mic = gss_verify_mic_spkm3,
213 .gss_delete_sec_context = gss_delete_sec_context_spkm3,
216 static struct pf_desc gss_spkm3_pfs[] = {
217 {RPC_AUTH_GSS_SPKM, RPC_GSS_SVC_NONE, "spkm3"},
218 {RPC_AUTH_GSS_SPKMI, RPC_GSS_SVC_INTEGRITY, "spkm3i"},
221 static struct gss_api_mech gss_spkm3_mech = {
223 .gm_owner = THIS_MODULE,
224 .gm_oid = {7, "\053\006\001\005\005\001\003"},
225 .gm_ops = &gss_spkm3_ops,
226 .gm_pf_num = ARRAY_SIZE(gss_spkm3_pfs),
227 .gm_pfs = gss_spkm3_pfs,
230 static int __init init_spkm3_module(void)
234 status = gss_mech_register(&gss_spkm3_mech);
236 printk("Failed to register spkm3 gss mechanism!\n");
240 static void __exit cleanup_spkm3_module(void)
242 gss_mech_unregister(&gss_spkm3_mech);
245 MODULE_LICENSE("GPL");
246 module_init(init_spkm3_module);
247 module_exit(cleanup_spkm3_module);