spnego.c revision 6b432e11497f905a6b6f048df3e8a01ce8abbb1e
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Copyright (C) 2006-2016 Internet Systems Consortium, Inc. ("ISC")
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * This Source Code Form is subject to the terms of the Mozilla Public
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * License, v. 2.0. If a copy of the MPL was not distributed with this
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*! \file
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * \brief
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Portable SPNEGO implementation.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * This is part of a portable implementation of the SPNEGO protocol
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * (RFCs 2478 and 4178). This implementation uses the RFC 4178 ASN.1
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * module but is not a full implementation of the RFC 4178 protocol;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * at the moment, we only support GSS-TSIG with Kerberos
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * authentication, so we only need enough of the SPNEGO protocol to
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * support that.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * The files that make up this portable SPNEGO implementation are:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * \li spnego.c (this file)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * \li spnego.h (API SPNEGO exports to the rest of lib/dns)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam * \li spnego.asn1 (SPNEGO ASN.1 module)
cd21e7c548ae2a3b5e522244bf798f2a6b4ba02dGarrett D'Amore * \li spnego_asn1.c (routines generated from spngo.asn1)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * \li spnego_asn1.pl (perl script to generate spnego_asn1.c)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Everything but the functions exported in spnego.h is static, to
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam * avoid possible conflicts with other libraries (particularly Heimdal,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * since much of this code comes from Heimdal by way of mod_auth_kerb).
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * spnego_asn1.c is shipped as part of lib/dns because generating it
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * requires both Perl and the Heimdal ASN.1 compiler. See
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * spnego_asn1.pl for further details. We've tried to eliminate all
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * compiler warnings from the generated code, but you may see a few
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * when using a compiler version we haven't tested yet.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
ac48dfe87039078897ed719af26744eca776508cVikram Hegde * Portions of this code were derived from mod_auth_kerb and Heimdal.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * These packages are available from:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * http://modauthkerb.sourceforge.net/
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * http://www.pdc.kth.se/heimdal/
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * and were released under the following licenses:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ----------------------------------------------------------------
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Copyright (c) 2004 Masarykova universita
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * (Masaryk University, Brno, Czech Republic)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * All rights reserved.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Redistribution and use in source and binary forms, with or without
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * modification, are permitted provided that the following conditions are met:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * 1. Redistributions of source code must retain the above copyright notice,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * this list of conditions and the following disclaimer.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * 2. Redistributions in binary form must reproduce the above copyright
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * notice, this list of conditions and the following disclaimer in the
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * documentation and/or other materials provided with the distribution.
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden *
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden * 3. Neither the name of the University nor the names of its contributors may
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden * be used to endorse or promote products derived from this software
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden * without specific prior written permission.
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * POSSIBILITY OF SUCH DAMAGE.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ----------------------------------------------------------------
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Copyright (c) 1997 - 2003 Kungliga Tekniska H�gskolan
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * (Royal Institute of Technology, Stockholm, Sweden).
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * All rights reserved.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Redistribution and use in source and binary forms, with or without
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * modification, are permitted provided that the following conditions
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * are met:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * 1. Redistributions of source code must retain the above copyright
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * notice, this list of conditions and the following disclaimer.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * 2. Redistributions in binary form must reproduce the above copyright
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * notice, this list of conditions and the following disclaimer in the
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * documentation and/or other materials provided with the distribution.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * 3. Neither the name of the Institute nor the names of its contributors
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * may be used to endorse or promote products derived from this software
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * without specific prior written permission.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50200e773f0242e336d032a7b43485e1bcfc9bfeFrank Van Der Linden * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SUCH DAMAGE.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * XXXSRA We should omit this file entirely in Makefile.in via autoconf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * but this will keep it from generating errors until that's written.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#ifdef GSSAPI
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * XXXSRA Some of the following files are almost certainly unnecessary,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * but using this list (borrowed from gssapictx.c) gets rid of some
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * whacky compilation errors when building with MSVC and should be
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * harmless in any case.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <config.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <stdlib.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <errno.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/buffer.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/dir.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/entropy.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/lex.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/mem.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/once.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/random.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/safe.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/string.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/time.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <isc/util.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/fixedname.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/name.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/rdata.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/rdataclass.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/result.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/types.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/keyvalues.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dns/log.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dst/gssapi.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include <dst/result.h>
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include "dst_internal.h"
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * The API we export
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include "spnego.h"
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* asn1_err.h */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* Generated from ../../../lib/asn1/asn1_err.et */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#ifndef ERROR_TABLE_BASE_asn1
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* these may be brought in already via gssapi_krb5.h */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef enum asn1_error_number {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_BAD_TIMEFORMAT = 1859794432,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_MISSING_FIELD = 1859794433,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_MISPLACED_FIELD = 1859794434,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_TYPE_MISMATCH = 1859794435,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_OVERFLOW = 1859794436,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_OVERRUN = 1859794437,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_BAD_ID = 1859794438,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_BAD_LENGTH = 1859794439,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_BAD_FORMAT = 1859794440,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_PARSE_ERROR = 1859794441
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp} asn1_error_number;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#define ERROR_TABLE_BASE_asn1 1859794432
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#endif
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#define __asn1_common_definitions__
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef struct octet_string {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp void *data;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp} octet_string;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef char *general_string;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef char *utf8_string;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef struct oid {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned *components;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp} oid;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* der.h */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef enum {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_C_UNIV = 0, ASN1_C_APPL = 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_C_CONTEXT = 2, ASN1_C_PRIVATE = 3
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp} Der_class;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef enum {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp PRIM = 0, CONS = 1
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp} Der_type;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* Universal tags */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpenum {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_Boolean = 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_Integer = 2,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_BitString = 3,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_OctetString = 4,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_Null = 5,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_OID = 6,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_Enumerated = 10,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_Sequence = 16,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_Set = 17,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_PrintableString = 19,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_IA5String = 22,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_UTCTime = 23,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_GeneralizedTime = 24,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_VisibleString = 26,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp UT_GeneralString = 27
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#define ASN1_INDEFINITE 0xdce0deed
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_length(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t * val, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_octet_string(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp octet_string * data, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_oid(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp oid * data, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_tag(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class * class, Der_type * type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int *tag, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_match_tag(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class class, Der_type type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int tag, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_match_tag_and_length(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class class, Der_type type, int tag,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t * length_ret, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_oid(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp oid * k, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_enumerated(const unsigned char *p, size_t len, void *num, size_t *size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_octet_string(const unsigned char *, size_t, octet_string *, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_int(unsigned char *p, size_t len, int val, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length(unsigned char *p, size_t len, size_t val, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_octet_string(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const octet_string * data, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_oid(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const oid * data, size_t * size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_tag(unsigned char *p, size_t len, Der_class class, Der_type type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int tag, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length_and_tag(unsigned char *, size_t, size_t,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class, Der_type, int, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_enumerated(unsigned char *p, size_t len, const void *data, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_octet_string(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const octet_string * k, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_oid(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const oid * k, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpfree_octet_string(octet_string * k);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpfree_oid (oid * k);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic size_t
7d87efa8fdfb9453670f2832df666fdae8291a84jmcplength_len(size_t len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpfix_dce(size_t reallen, size_t * len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Include stuff generated by the ASN.1 compiler.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#include "spnego_asn1.c"
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Force the oid arrays to be isc_uint64_t aligned to silence warnings
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * about the arrays not being properly aligned for (void *).
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef union { unsigned char b[8]; isc_uint64_t _align; } aligned8;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef union { unsigned char b[16]; isc_uint64_t _align[2]; } aligned16;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic aligned16 gss_krb5_mech_oid_bytes = {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp { 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x12, 0x01, 0x02, 0x02 }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID_desc gss_krb5_mech_oid_desc = {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp 9, gss_krb5_mech_oid_bytes.b
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID GSS_KRB5_MECH = &gss_krb5_mech_oid_desc;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic aligned16 gss_mskrb5_mech_oid_bytes = {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp { 0x2a, 0x86, 0x48, 0x82, 0xf7, 0x12, 0x01, 0x02, 0x02 }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID_desc gss_mskrb5_mech_oid_desc = {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp 9, gss_mskrb5_mech_oid_bytes.b
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID GSS_MSKRB5_MECH = &gss_mskrb5_mech_oid_desc;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic aligned8 gss_spnego_mech_oid_bytes = {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID_desc gss_spnego_mech_oid_desc = {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp 6, gss_spnego_mech_oid_bytes.b
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp};
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID GSS_SPNEGO_MECH = &gss_spnego_mech_oid_desc;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* spnegokrb5_locl.h */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgssapi_spnego_encapsulate(OM_uint32 *,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgssapi_spnego_decapsulate(OM_uint32 *,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char **,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t *,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* mod_auth_kerb.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpcmp_gss_type(gss_buffer_t token, gss_OID gssoid)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (token->length == 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p = token->value;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x60)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len = *p++;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len & 0x80) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if ((len & 0x7f) > 4U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += len & 0x7f;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x06)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (((OM_uint32) *p++) != gssoid->length)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (isc_safe_memcompare(p, gssoid->elements, gssoid->length));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* accept_sec_context.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SPNEGO wrapper for Kerberos5 GSS-API kouril@ics.muni.cz, 2003 (mostly
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * based on Heimdal code)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpcode_NegTokenArg(OM_uint32 * minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const NegTokenResp * resp,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char **outbuf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t * outbuf_size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char *buf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t buf_size, buf_len = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size = 1024;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf = malloc(buf_size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (buf == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp do {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = encode_NegTokenResp(buf + buf_size - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp, &buf_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_put_length_and_tag(buf + buf_size - buf_len - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size - buf_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_C_CONTEXT,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp CONS,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &tmp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == 0)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_len += tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == ASN1_OVERFLOW) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char *tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size *= 2;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp tmp = realloc(buf, buf_size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (tmp == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(buf);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf = tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(buf);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (ret == ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *outbuf = malloc(buf_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*outbuf == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(buf);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp memmove(*outbuf, buf + buf_size - buf_len, buf_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *outbuf_size = buf_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(buf);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_COMPLETE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpsend_reject(OM_uint32 * minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t output_token)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp NegTokenResp resp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.negState = malloc(sizeof(*resp.negState));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (resp.negState == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *(resp.negState) = reject;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
ac48dfe87039078897ed719af26744eca776508cVikram Hegde resp.supportedMech = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.responseToken = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.mechListMIC = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = code_NegTokenArg(minor_status, &resp,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp (unsigned char **)&output_token->value,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &output_token->length);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_BAD_MECH);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde}
ac48dfe87039078897ed719af26744eca776508cVikram Hegde
ac48dfe87039078897ed719af26744eca776508cVikram Hegdestatic OM_uint32
ac48dfe87039078897ed719af26744eca776508cVikram Hegdesend_accept(OM_uint32 * minor_status,
ac48dfe87039078897ed719af26744eca776508cVikram Hegde gss_buffer_t output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t mech_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID pref)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp NegTokenResp resp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
ac48dfe87039078897ed719af26744eca776508cVikram Hegde memset(&resp, 0, sizeof(resp));
ac48dfe87039078897ed719af26744eca776508cVikram Hegde resp.negState = malloc(sizeof(*resp.negState));
ac48dfe87039078897ed719af26744eca776508cVikram Hegde if (resp.negState == NULL) {
ac48dfe87039078897ed719af26744eca776508cVikram Hegde *minor_status = ENOMEM;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *(resp.negState) = accept_completed;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.supportedMech = malloc(sizeof(*resp.supportedMech));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (resp.supportedMech == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_get_oid(pref->elements,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp pref->length,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.supportedMech,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp NULL);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (mech_token != NULL && mech_token->length != 0U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.responseToken = malloc(sizeof(*resp.responseToken));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (resp.responseToken == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.responseToken->length = mech_token->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.responseToken->data = mech_token->value;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = code_NegTokenArg(minor_status, &resp,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp (unsigned char **)&output_token->value,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &output_token->length);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (resp.responseToken != NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(resp.responseToken);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.responseToken = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_COMPLETE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpOM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgss_accept_sec_context_spnego(OM_uint32 *minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_ctx_id_t *context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_cred_id_t acceptor_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_buffer_t input_token_buffer,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_channel_bindings_t input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_name_t *src_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_OID *mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *time_rec,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_cred_id_t *delegated_cred_handle)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp NegTokenInit init_token;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 major_status = GSS_S_COMPLETE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 minor_status2;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_desc ibuf, obuf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t ot = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_OID pref = GSS_KRB5_MECH;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *buf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t buf_size;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t len, taglen, ni_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int found = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned i;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Before doing anything else, see whether this is a SPNEGO
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * PDU. If not, dispatch to the GSSAPI library and get out.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (cmp_gss_type(input_token_buffer, GSS_SPNEGO_MECH))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (gss_accept_sec_context(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp acceptor_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token_buffer,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp src_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp delegated_cred_handle));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * If we get here, it's SPNEGO.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp memset(&init_token, 0, sizeof(init_token));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = gssapi_spnego_decapsulate(minor_status, input_token_buffer,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &buf, &buf_size, GSS_SPNEGO_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_match_tag_and_length(buf, buf_size, ASN1_C_CONTEXT, CONS,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp 0, &len, &taglen);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = decode_NegTokenInit(buf + taglen, len, &init_token, &ni_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = EINVAL; /* XXX */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp for (i = 0; !found && i < init_token.mechTypes.len; ++i) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char mechbuf[17];
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t mech_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_put_oid(mechbuf + sizeof(mechbuf) - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp sizeof(mechbuf),
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &init_token.mechTypes.val[i],
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &mech_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenInit(&init_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (mech_len == GSS_KRB5_MECH->length &&
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp isc_safe_memequal(GSS_KRB5_MECH->elements,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mechbuf + sizeof(mechbuf) - mech_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_len))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp found = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp break;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (mech_len == GSS_MSKRB5_MECH->length &&
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp isc_safe_memequal(GSS_MSKRB5_MECH->elements,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mechbuf + sizeof(mechbuf) - mech_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_len))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp found = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (i == 0)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp pref = GSS_MSKRB5_MECH;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp break;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (!found) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenInit(&init_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (send_reject(minor_status, output_token));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (i == 0 && init_token.mechToken != NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ibuf.length = init_token.mechToken->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ibuf.value = init_token.mechToken->data;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp major_status = gss_accept_sec_context(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp acceptor_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &ibuf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp src_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &obuf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp delegated_cred_handle);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (GSS_ERROR(major_status)) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenInit(&init_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp send_reject(&minor_status2, output_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (major_status);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ot = &obuf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = send_accept(&minor_status2, output_token, ot, pref);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenInit(&init_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ot != NULL && ot->length != 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_release_buffer(&minor_status2, ot);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret != GSS_S_COMPLETE ? (OM_uint32) ret : major_status);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* decapsulate.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgssapi_verify_mech_header(u_char ** str,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t total_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t len, len_len, mech_len, foo;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char *p = *str;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (total_len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x60)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_length(p, total_len - 1, &len, &len_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e || 1 + len_len + len != total_len)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += len_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x06)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_length(p, total_len - 1 - len_len - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &mech_len, &foo);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_DEFECTIVE_TOKEN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += foo;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (mech_len != mech->length)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_BAD_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (!isc_safe_memequal(p, mech->elements, mech->length))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_BAD_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += mech_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *str = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_COMPLETE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Remove the GSS-API wrapping from `in_token' giving `buf and buf_size' Does
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * not copy data, so just free `in_token'.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgssapi_spnego_decapsulate(OM_uint32 *minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t input_token_buffer,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char **buf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t *buf_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char *p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p = input_token_buffer->value;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = gssapi_verify_mech_header(&p,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token_buffer->length,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *buf_len = input_token_buffer->length -
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp (p - (u_char *) input_token_buffer->value);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *buf = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_COMPLETE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* der_free.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpfree_octet_string(octet_string *k)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(k->data);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp k->data = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpfree_oid(oid *k)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(k->components);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp k->components = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* der_get.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * All decoding functions take a pointer `p' to first position in which to
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * read, from the left, `len' which means the maximum number of characters we
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * are able to read, `ret' were the value will be returned and `size' where
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * the number of used bytes is stored. Either 0 or an error code is returned.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_unsigned(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned *ret, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned val = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t oldlen = len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp while (len--)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val = val * 256 + *p++;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *ret = val;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = oldlen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_int(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int *ret, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int val = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t oldlen = len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len > 0U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val = (signed char)*p++;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp while (--len)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val = val * 256 + *p++;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *ret = val;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = oldlen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_length(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t *val, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t v;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len <= 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp --len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp v = *p++;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (v < 128U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *val = v;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (v == 0x80U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *val = ASN1_INDEFINITE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp v &= 0x7F;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < v)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_unsigned(p, v, &tmp, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *val = tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = l + 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_octet_string(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp octet_string *data, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->length = len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len != 0U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->data = malloc(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (data->data == NULL)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ENOMEM);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp memmove(data->data, p, len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->data = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_oid(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp oid *data, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int n;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t oldlen = len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->components = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->length = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->components = malloc(len * sizeof(*data->components));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (data->components == NULL && len != 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ENOMEM);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->components[0] = (*p) / 40;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->components[1] = (*p) % 40;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp --len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ++p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp for (n = 2; len > 0U; ++n) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned u = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp do {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp --len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u = u * 128 + (*p++ % 128);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (len > 0U && p[-1] & 0x80);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->components[n] = u;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (p[-1] & 0x80) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_oid(data);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->length = n;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = oldlen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_tag(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class *class, Der_type *type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int *tag, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *class = (Der_class) (((*p) >> 6) & 0x03);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *type = (Der_type) (((*p) >> 5) & 0x01);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *tag = (*p) & 0x1F;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_match_tag(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class class, Der_type type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int tag, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class thisclass;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_type thistype;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int thistag;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_tag(p, len, &thisclass, &thistype, &thistag, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (class != thisclass || type != thistype)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_BAD_ID);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (tag > thistag)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (ASN1_MISPLACED_FIELD);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (tag < thistag)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_MISSING_FIELD);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_match_tag_and_length(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class class, Der_type type, int tag,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t *length_ret, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l, ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, class, type, tag, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam e = der_get_length(p, len, length_ret, &l);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (e)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (e);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam /* p += l; */
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam len -= l;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam POST(len);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam ret += l;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (size)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *size = ret;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (0);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_enumerated(const unsigned char *p, size_t len, void *num, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l, reallen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_Enumerated, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam len -= l;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam ret += l;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam e = der_get_length(p, len, &reallen, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_int(p, reallen, num, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_octet_string(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp octet_string *k, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t slen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp k->data = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp k->length = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_length(p, len, &slen, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < slen)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_octet_string(p, slen, k, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_oid(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp oid *k, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t slen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_OID, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_length(p, len, &slen, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < slen)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_oid(p, slen, k, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpfix_dce(size_t reallen, size_t *len)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (reallen == ASN1_INDEFINITE)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*len < reallen)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *len = reallen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* der_length.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic size_t
7d87efa8fdfb9453670f2832df666fdae8291a84jmcplen_unsigned(unsigned val)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp do {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ++ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val /= 256;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (val);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic size_t
7d87efa8fdfb9453670f2832df666fdae8291a84jmcplength_len(size_t len)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 128U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp else
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (len_unsigned((unsigned int)len) + 1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* der_put.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * All encoding functions take a pointer `p' to first position in which to
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * write, from the right, `len' which means the maximum number of characters
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * we are able to write. The function returns the number of characters
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * written in `size' (if non-NULL). The return value is 0 or an error.
ac48dfe87039078897ed719af26744eca776508cVikram Hegde */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_unsigned(unsigned char *p, size_t len, unsigned val, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *base = p;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (val) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp while (len > 0U && val) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = val % 256;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val /= 256;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp --len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (val != 0)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = base - p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_int(unsigned char *p, size_t len, int val, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
ac48dfe87039078897ed719af26744eca776508cVikram Hegde unsigned char *base = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (val >= 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp do {
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (len < 1U)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (ASN1_OVERFLOW);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *p-- = val % 256;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam len--;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam val /= 256;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam } while (val);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (p[1] >= 128) {
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (len < 1U)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len--;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val = ~val;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp do {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = ~(val % 256);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde len--;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val /= 256;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (val);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (p[1] < 128) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = 0xff;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len--;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = base - p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
ac48dfe87039078897ed719af26744eca776508cVikram Hegde
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length(unsigned char *p, size_t len, size_t val, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (val < 128U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p = (unsigned char)val;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde *size = 1;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (0);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde } else {
ac48dfe87039078897ed719af26744eca776508cVikram Hegde size_t l;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde int e;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde
ac48dfe87039078897ed719af26744eca776508cVikram Hegde e = der_put_unsigned(p, len - 1, (unsigned int)val, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde *p = 0x80 | (unsigned char)l;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde *size = l + 1;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (0);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde }
ac48dfe87039078897ed719af26744eca776508cVikram Hegde}
ac48dfe87039078897ed719af26744eca776508cVikram Hegde
ac48dfe87039078897ed719af26744eca776508cVikram Hegdestatic int
ac48dfe87039078897ed719af26744eca776508cVikram Hegdeder_put_octet_string(unsigned char *p, size_t len,
ac48dfe87039078897ed719af26744eca776508cVikram Hegde const octet_string *data, size_t *size)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde{
ac48dfe87039078897ed719af26744eca776508cVikram Hegde if (len < data->length)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= data->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= data->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp memmove(p + 1, data->data, data->length);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = data->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_oid(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const oid *data, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *base = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t n;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp for (n = data->length; n >= 3u; --n) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned u = data->components[n - 1];
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = u % 128;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u /= 128;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp --len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp while (u > 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = 128 + u % 128;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u /= 128;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp --len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = 40 * data->components[0] + data->components[1];
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = base - p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_tag(unsigned char *p, size_t len, Der_class class, Der_type type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int tag, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p = (class << 6) | (type << 5) | tag; /* XXX */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = 1;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length_and_tag(unsigned char *p, size_t len, size_t len_val,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp Der_class class, Der_type type, int tag, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length(p, len, len_val, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_tag(p, len, class, type, tag, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_enumerated(unsigned char *p, size_t len, const void *data, size_t *size)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned num = *(const unsigned *)data;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_int(p, len, num, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_Enumerated, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_octet_string(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const octet_string *k, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_octet_string(p, len, k, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic int
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_oid(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const oid *k, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t ret = 0;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde size_t l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_oid(p, len, k, &l);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len -= l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_OID, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p -= l;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde len -= l;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde POST(p); POST(len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret += l;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *size = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* encapsulate.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgssapi_encap_length(size_t data_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t *len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t *total_len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam size_t len_len;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *len = 1 + 1 + mech->length + data_len;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam len_len = length_len(*len);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *total_len = 1 + len_len + *len;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam}
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamstatic u_char *
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamgssapi_mech_make_header(u_char *p,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam size_t len,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam const gss_OID mech)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam{
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam int e;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam size_t len_len, foo;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *p++ = 0x60;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam len_len = length_len(len);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam e = der_put_length(p + len_len - 1, len_len, len, &foo);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (e || foo != len_len)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (NULL);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam p += len_len;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *p++ = 0x06;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *p++ = mech->length;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam memmove(p, mech->elements, mech->length);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam p += mech->length;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (p);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam}
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam/*
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam * Give it a krb5_data and it will encapsulate with extra GSS-API wrappings.
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam */
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamstatic OM_uint32
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamgssapi_spnego_encapsulate(OM_uint32 * minor_status,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam unsigned char *buf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t buf_size,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t len, outer_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char *p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam gssapi_encap_length(buf_size, &len, &outer_len, mech);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam output_token->length = outer_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token->value = malloc(outer_len);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (output_token->value == NULL) {
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam *minor_status = ENOMEM;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (GSS_S_FAILURE);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p = gssapi_mech_make_header(output_token->value, len, mech);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (p == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (output_token->length != 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_release_buffer(minor_status, output_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp memmove(p, buf, buf_size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_COMPLETE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* init_sec_context.c */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SPNEGO wrapper for Kerberos5 GSS-API kouril@ics.muni.cz, 2003 (mostly
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * based on Heimdal code)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam */
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamstatic int
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamadd_mech(MechTypeList * mech_list, gss_OID mech)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam{
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam MechType *tmp;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam int ret;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam tmp = realloc(mech_list->val, (mech_list->len + 1) * sizeof(*tmp));
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (tmp == NULL)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (ENOMEM);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam mech_list->val = tmp;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam ret = der_get_oid(mech->elements, mech->length,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam &mech_list->val[mech_list->len], NULL);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam if (ret)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (ret);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam mech_list->len++;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam return (0);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam}
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam/*
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam * return the length of the mechanism in token or -1
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam * (which implies that the token was bad - GSS_S_DEFECTIVE_TOKEN
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam */
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamstatic ssize_t
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamgssapi_krb5_get_mech(const u_char *ptr,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam size_t total_len,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam const u_char **mech_ret)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam{
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam size_t len, len_len, mech_len, foo;
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam const u_char *p = ptr;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int e;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (total_len < 1U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x60)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_length (p, total_len - 1, &len, &len_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e || 1 + len_len + len != total_len)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += len_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x06)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_length (p, total_len - 1 - len_len - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &mech_len, &foo);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (e)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p += foo;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *mech_ret = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (mech_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpspnego_initial(OM_uint32 *minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_cred_id_t initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_ctx_id_t *context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_name_t target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_channel_bindings_t input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_buffer_t input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_OID *actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *time_rec)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp NegTokenInit token_init;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 major_status, minor_status2;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_desc krb5_output_token = GSS_C_EMPTY_BUFFER;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *buf = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t buf_size;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp int ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
ac48dfe87039078897ed719af26744eca776508cVikram Hegde (void)mech_type;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp memset(&token_init, 0, sizeof(token_init));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = add_mech(&token_init.mechTypes, GSS_KRB5_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = GSS_S_FAILURE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp goto end;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp major_status = gss_init_sec_context(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp GSS_KRB5_MECH,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &krb5_output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (GSS_ERROR(major_status)) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = major_status;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp goto end;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (krb5_output_token.length > 0U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp token_init.mechToken = malloc(sizeof(*token_init.mechToken));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (token_init.mechToken == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = GSS_S_FAILURE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp goto end;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp token_init.mechToken->data = krb5_output_token.value;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp token_init.mechToken->length = krb5_output_token.length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * The MS implementation of SPNEGO seems to not like the mechListMIC
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * field, so we omit it (it's optional anyway)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size = 1024;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf = malloc(buf_size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (buf == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = GSS_S_FAILURE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp goto end;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp do {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = encode_NegTokenInit(buf + buf_size - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &token_init, &len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_put_length_and_tag(buf + buf_size - len - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size - len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_C_CONTEXT,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp CONS,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp 0,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &tmp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == 0)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp len += tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == ASN1_OVERFLOW) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char *tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size *= 2;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp tmp = realloc(buf, buf_size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (tmp == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = GSS_S_FAILURE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp goto end;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf = tmp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = GSS_S_FAILURE;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp goto end;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (ret == ASN1_OVERFLOW);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = gssapi_spnego_encapsulate(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf + buf_size - len, len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token, GSS_SPNEGO_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == GSS_S_COMPLETE)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = major_status;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpend:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (token_init.mechToken != NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(token_init.mechToken);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp token_init.mechToken = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenInit(&token_init);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (krb5_output_token.length != 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_release_buffer(&minor_status2, &krb5_output_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (buf)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free(buf);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic OM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpspnego_reply(OM_uint32 *minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_cred_id_t initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_ctx_id_t *context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_name_t target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_channel_bindings_t input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_buffer_t input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_OID *actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *time_rec)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 ret;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp NegTokenResp resp;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *buf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t buf_size;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp u_char oidbuf[17];
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t oidlen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_desc sub_token;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ssize_t mech_len;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const u_char *p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp size_t len, taglen;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp (void)mech_type;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token->length = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token->value = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SPNEGO doesn't include gss wrapping on SubsequentContextToken
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * like the Kerberos 5 mech does. But lets check for it anyway.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_len = gssapi_krb5_get_mech(input_token->value,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token->length,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &p);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (mech_len < 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf = input_token->value;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp buf_size = input_token->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else if ((size_t)mech_len == GSS_KRB5_MECH->length &&
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp isc_safe_memequal(GSS_KRB5_MECH->elements, p, mech_len))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (gss_init_sec_context(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp GSS_KRB5_MECH,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp else if ((size_t)mech_len == GSS_SPNEGO_MECH->length &&
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp isc_safe_memequal(GSS_SPNEGO_MECH->elements, p, mech_len)) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = gssapi_spnego_decapsulate(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &buf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &buf_size,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp GSS_SPNEGO_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_BAD_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_match_tag_and_length(buf, buf_size,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ASN1_C_CONTEXT, CONS, 1, &len, &taglen);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if(len > buf_size - taglen)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ASN1_OVERRUN);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = decode_NegTokenResp(buf + taglen, len, &resp, NULL);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *minor_status = ENOMEM;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_FAILURE);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (resp.negState == NULL ||
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *(resp.negState) == reject ||
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.supportedMech == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (GSS_S_BAD_MECH);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_put_oid(oidbuf + sizeof(oidbuf) - 1,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp sizeof(oidbuf),
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.supportedMech,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &oidlen);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret || oidlen != GSS_KRB5_MECH->length ||
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp !isc_safe_memequal(oidbuf + sizeof(oidbuf) - oidlen,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp GSS_KRB5_MECH->elements, oidlen))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return GSS_S_BAD_MECH;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (resp.responseToken != NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp sub_token.length = resp.responseToken->length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp sub_token.value = resp.responseToken->data;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp sub_token.length = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp sub_token.value = NULL;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = gss_init_sec_context(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp GSS_KRB5_MECH,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp &sub_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /*
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * XXXSRA I don't think this limited implementation ever needs
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * to check the MIC -- our preferred mechanism (Kerberos)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * authenticates its own messages and is the only mechanism
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * we'll accept, so if the mechanism negotiation completes
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * successfully, we don't need the MIC. See RFC 4178.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp free_NegTokenResp(&resp);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpOM_uint32
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpgss_init_sec_context_spnego(OM_uint32 *minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_cred_id_t initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_ctx_id_t *context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_name_t target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_OID mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_channel_bindings_t input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp const gss_buffer_t input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_OID *actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_t output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp OM_uint32 *time_rec)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp{
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /* Dirty trick to suppress compiler warnings */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /* Figure out whether we're starting over or processing a reply */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (input_token == GSS_C_NO_BUFFER || input_token->length == 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (spnego_initial(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp else
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (spnego_reply(minor_status,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp initiator_cred_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp context_handle,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp target_name,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp req_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_req,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_chan_bindings,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp input_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp actual_mech_type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp output_token,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret_flags,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp time_rec));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp}
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#endif /* GSSAPI */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp