gss_unwrap.c revision 256281
10Sstevel@tonic-gate/*-
20Sstevel@tonic-gate * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
30Sstevel@tonic-gate * Authors: Doug Rabson <dfr@rabson.org>
40Sstevel@tonic-gate * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
50Sstevel@tonic-gate *
612428SSonam.Gupta@Sun.COM * Redistribution and use in source and binary forms, with or without
712428SSonam.Gupta@Sun.COM * modification, are permitted provided that the following conditions
80Sstevel@tonic-gate * are met:
90Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
100Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
110Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
120Sstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
130Sstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
140Sstevel@tonic-gate *
150Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
160Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180Sstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2212428SSonam.Gupta@Sun.COM * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250Sstevel@tonic-gate * SUCH DAMAGE.
260Sstevel@tonic-gate */
270Sstevel@tonic-gate
280Sstevel@tonic-gate#include <sys/cdefs.h>
290Sstevel@tonic-gate__FBSDID("$FreeBSD: stable/10/sys/kgssapi/gss_unwrap.c 184588 2008-11-03 10:38:00Z dfr $");
300Sstevel@tonic-gate
3112428SSonam.Gupta@Sun.COM#include <sys/param.h>
320Sstevel@tonic-gate#include <sys/kernel.h>
330Sstevel@tonic-gate#include <sys/kobj.h>
340Sstevel@tonic-gate#include <sys/malloc.h>
350Sstevel@tonic-gate#include <sys/mbuf.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate#include <kgssapi/gssapi.h>
380Sstevel@tonic-gate#include <kgssapi/gssapi_impl.h>
3912428SSonam.Gupta@Sun.COM
400Sstevel@tonic-gate#include "kgss_if.h"
4112428SSonam.Gupta@Sun.COM
420Sstevel@tonic-gateOM_uint32
430Sstevel@tonic-gategss_unwrap(OM_uint32 *minor_status,
440Sstevel@tonic-gate    const gss_ctx_id_t ctx,
450Sstevel@tonic-gate    const gss_buffer_t input_message_buffer,
460Sstevel@tonic-gate    gss_buffer_t output_message_buffer,
470Sstevel@tonic-gate    int *conf_state,
480Sstevel@tonic-gate    gss_qop_t *qop_state)
490Sstevel@tonic-gate{
500Sstevel@tonic-gate	OM_uint32 maj_stat;
510Sstevel@tonic-gate	struct mbuf *m;
520Sstevel@tonic-gate
530Sstevel@tonic-gate	if (!ctx) {
540Sstevel@tonic-gate		*minor_status = 0;
550Sstevel@tonic-gate		return (GSS_S_NO_CONTEXT);
560Sstevel@tonic-gate	}
570Sstevel@tonic-gate
580Sstevel@tonic-gate	MGET(m, M_WAITOK, MT_DATA);
590Sstevel@tonic-gate	if (input_message_buffer->length > MLEN)
6012428SSonam.Gupta@Sun.COM		MCLGET(m, M_WAITOK);
610Sstevel@tonic-gate	m_append(m, input_message_buffer->length, input_message_buffer->value);
620Sstevel@tonic-gate
630Sstevel@tonic-gate	maj_stat = KGSS_UNWRAP(ctx, minor_status, &m, conf_state, qop_state);
640Sstevel@tonic-gate
650Sstevel@tonic-gate	/*
660Sstevel@tonic-gate	 * On success, m is the wrapped message, on failure, m is
670Sstevel@tonic-gate	 * freed.
680Sstevel@tonic-gate	 */
690Sstevel@tonic-gate	if (maj_stat == GSS_S_COMPLETE) {
700Sstevel@tonic-gate		output_message_buffer->length = m_length(m, NULL);
710Sstevel@tonic-gate		output_message_buffer->value =
720Sstevel@tonic-gate			malloc(output_message_buffer->length,
730Sstevel@tonic-gate			    M_GSSAPI, M_WAITOK);
7412428SSonam.Gupta@Sun.COM		m_copydata(m, 0, output_message_buffer->length,
750Sstevel@tonic-gate		    output_message_buffer->value);
760Sstevel@tonic-gate		m_freem(m);
770Sstevel@tonic-gate	}
780Sstevel@tonic-gate
790Sstevel@tonic-gate	return (maj_stat);
800Sstevel@tonic-gate}
810Sstevel@tonic-gate
820Sstevel@tonic-gateOM_uint32
8312428SSonam.Gupta@Sun.COMgss_unwrap_mbuf(OM_uint32 *minor_status,
840Sstevel@tonic-gate    const gss_ctx_id_t ctx,
850Sstevel@tonic-gate    struct mbuf **mp,
860Sstevel@tonic-gate    int *conf_state,
8712428SSonam.Gupta@Sun.COM    gss_qop_t *qop_state)
880Sstevel@tonic-gate{
8912428SSonam.Gupta@Sun.COM
9012428SSonam.Gupta@Sun.COM	if (!ctx) {
910Sstevel@tonic-gate		*minor_status = 0;
920Sstevel@tonic-gate		return (GSS_S_NO_CONTEXT);
930Sstevel@tonic-gate	}
940Sstevel@tonic-gate
950Sstevel@tonic-gate	return (KGSS_UNWRAP(ctx, minor_status, mp, conf_state, qop_state));
960Sstevel@tonic-gate}
970Sstevel@tonic-gate
980Sstevel@tonic-gate