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