1a9148abdSDoug Rabson /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
34de8ade9SPedro F. Giffuni *
4a9148abdSDoug Rabson * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5a9148abdSDoug Rabson * Authors: Doug Rabson <dfr@rabson.org>
6a9148abdSDoug Rabson * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
7a9148abdSDoug Rabson *
8a9148abdSDoug Rabson * Redistribution and use in source and binary forms, with or without
9a9148abdSDoug Rabson * modification, are permitted provided that the following conditions
10a9148abdSDoug Rabson * are met:
11a9148abdSDoug Rabson * 1. Redistributions of source code must retain the above copyright
12a9148abdSDoug Rabson * notice, this list of conditions and the following disclaimer.
13a9148abdSDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright
14a9148abdSDoug Rabson * notice, this list of conditions and the following disclaimer in the
15a9148abdSDoug Rabson * documentation and/or other materials provided with the distribution.
16a9148abdSDoug Rabson *
17a9148abdSDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18a9148abdSDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a9148abdSDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a9148abdSDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21a9148abdSDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a9148abdSDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a9148abdSDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a9148abdSDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a9148abdSDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a9148abdSDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a9148abdSDoug Rabson * SUCH DAMAGE.
28a9148abdSDoug Rabson */
29a9148abdSDoug Rabson
30a9148abdSDoug Rabson #include <sys/param.h>
31a9148abdSDoug Rabson #include <sys/kernel.h>
32a9148abdSDoug Rabson #include <sys/kobj.h>
33a9148abdSDoug Rabson #include <sys/malloc.h>
34a9148abdSDoug Rabson #include <sys/mbuf.h>
35a9148abdSDoug Rabson
36a9148abdSDoug Rabson #include <kgssapi/gssapi.h>
37a9148abdSDoug Rabson #include <kgssapi/gssapi_impl.h>
38a9148abdSDoug Rabson
39a9148abdSDoug Rabson #include "kgss_if.h"
40a9148abdSDoug Rabson
41a9148abdSDoug Rabson OM_uint32
gss_wrap(OM_uint32 * minor_status,const gss_ctx_id_t ctx,int conf_req_flag,gss_qop_t qop_req,const gss_buffer_t input_message_buffer,int * conf_state,gss_buffer_t output_message_buffer)42a9148abdSDoug Rabson gss_wrap(OM_uint32 *minor_status,
43a9148abdSDoug Rabson const gss_ctx_id_t ctx,
44a9148abdSDoug Rabson int conf_req_flag,
45a9148abdSDoug Rabson gss_qop_t qop_req,
46a9148abdSDoug Rabson const gss_buffer_t input_message_buffer,
47a9148abdSDoug Rabson int *conf_state,
48a9148abdSDoug Rabson gss_buffer_t output_message_buffer)
49a9148abdSDoug Rabson {
50a9148abdSDoug Rabson OM_uint32 maj_stat;
51a9148abdSDoug Rabson struct mbuf *m;
52a9148abdSDoug Rabson
53a9148abdSDoug Rabson if (!ctx) {
54a9148abdSDoug Rabson *minor_status = 0;
55a9148abdSDoug Rabson return (GSS_S_NO_CONTEXT);
56a9148abdSDoug Rabson }
57a9148abdSDoug Rabson
58a9148abdSDoug Rabson MGET(m, M_WAITOK, MT_DATA);
59a9148abdSDoug Rabson if (input_message_buffer->length > MLEN)
60a9148abdSDoug Rabson MCLGET(m, M_WAITOK);
61a9148abdSDoug Rabson m_append(m, input_message_buffer->length, input_message_buffer->value);
62a9148abdSDoug Rabson
63a9148abdSDoug Rabson maj_stat = KGSS_WRAP(ctx, minor_status, conf_req_flag, qop_req,
64a9148abdSDoug Rabson &m, conf_state);
65a9148abdSDoug Rabson
66a9148abdSDoug Rabson /*
67a9148abdSDoug Rabson * On success, m is the wrapped message, on failure, m is
68a9148abdSDoug Rabson * freed.
69a9148abdSDoug Rabson */
70a9148abdSDoug Rabson if (maj_stat == GSS_S_COMPLETE) {
71a9148abdSDoug Rabson output_message_buffer->length = m_length(m, NULL);
72a9148abdSDoug Rabson output_message_buffer->value =
73a9148abdSDoug Rabson malloc(output_message_buffer->length,
74a9148abdSDoug Rabson M_GSSAPI, M_WAITOK);
75a9148abdSDoug Rabson m_copydata(m, 0, output_message_buffer->length,
76a9148abdSDoug Rabson output_message_buffer->value);
77a9148abdSDoug Rabson m_freem(m);
78a9148abdSDoug Rabson }
79a9148abdSDoug Rabson
80a9148abdSDoug Rabson return (maj_stat);
81a9148abdSDoug Rabson }
82a9148abdSDoug Rabson
83a9148abdSDoug Rabson OM_uint32
gss_wrap_mbuf(OM_uint32 * minor_status,const gss_ctx_id_t ctx,int conf_req_flag,gss_qop_t qop_req,struct mbuf ** mp,int * conf_state)84a9148abdSDoug Rabson gss_wrap_mbuf(OM_uint32 *minor_status, const gss_ctx_id_t ctx,
85a9148abdSDoug Rabson int conf_req_flag, gss_qop_t qop_req, struct mbuf **mp, int *conf_state)
86a9148abdSDoug Rabson {
87a9148abdSDoug Rabson
88a9148abdSDoug Rabson if (!ctx) {
89a9148abdSDoug Rabson *minor_status = 0;
90a9148abdSDoug Rabson return (GSS_S_NO_CONTEXT);
91a9148abdSDoug Rabson }
92a9148abdSDoug Rabson
93a9148abdSDoug Rabson return (KGSS_WRAP(ctx, minor_status, conf_req_flag, qop_req,
94a9148abdSDoug Rabson mp, conf_state));
95a9148abdSDoug Rabson }
96