spnego.c revision 6b432e11497f905a6b6f048df3e8a01ce8abbb1e
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Copyright (C) 2006-2016 Internet Systems Consortium, Inc. ("ISC")
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 * Portable SPNEGO implementation.
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 * 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 * 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 * 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.
ac48dfe87039078897ed719af26744eca776508cVikram Hegde * Portions of this code were derived from mod_auth_kerb and Heimdal.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * These packages are available from:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * and were released under the following licenses:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * ----------------------------------------------------------------
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Copyright (c) 2004 Masarykova universita
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * (Masaryk University, Brno, Czech Republic)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * All rights reserved.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Redistribution and use in source and binary forms, with or without
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * modification, are permitted provided that the following conditions are met:
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * 1. Redistributions of source code must retain the above copyright notice,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * this list of conditions and the following disclaimer.
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 * 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.
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 * Copyright (c) 1997 - 2003 Kungliga Tekniska H�gskolan
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * (Royal Institute of Technology, Stockholm, Sweden).
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * All rights reserved.
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 * 1. Redistributions of source code must retain the above copyright
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * notice, this list of conditions and the following disclaimer.
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 * 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 * 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 * 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 * 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 * The API we export
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* Generated from ../../../lib/asn1/asn1_err.et */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* these may be brought in already via gssapi_krb5.h */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef struct octet_string {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef char *general_string;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef char *utf8_string;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef struct oid {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef enum {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef enum {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp/* Universal tags */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_octet_string(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_match_tag_and_length(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_enumerated(const unsigned char *p, size_t len, void *num, size_t *size);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_octet_string(const unsigned char *, size_t, octet_string *, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_int(unsigned char *p, size_t len, int val, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length(unsigned char *p, size_t len, size_t val, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_tag(unsigned char *p, size_t len, Der_class class, Der_type type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_enumerated(unsigned char *p, size_t len, const void *data, size_t *);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Include stuff generated by the ASN.1 compiler.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Force the oid arrays to be isc_uint64_t aligned to silence warnings
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * about the arrays not being properly aligned for (void *).
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef union { unsigned char b[8]; isc_uint64_t _align; } aligned8;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcptypedef union { unsigned char b[16]; isc_uint64_t _align[2]; } aligned16;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp { 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x12, 0x01, 0x02, 0x02 }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp { 0x2a, 0x86, 0x48, 0x82, 0xf7, 0x12, 0x01, 0x02, 0x02 }
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID GSS_MSKRB5_MECH = &gss_mskrb5_mech_oid_desc;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic gss_OID GSS_SPNEGO_MECH = &gss_spnego_mech_oid_desc;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char **,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x60)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x06)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (isc_safe_memcompare(p, gssoid->elements, gssoid->length));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SPNEGO wrapper for Kerberos5 GSS-API kouril@ics.muni.cz, 2003 (mostly
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * based on Heimdal code)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char **outbuf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_put_length_and_tag(buf + buf_size - buf_len - 1,
ac48dfe87039078897ed719af26744eca776508cVikram Hegde resp.negState = malloc(sizeof(*resp.negState));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.supportedMech = malloc(sizeof(*resp.supportedMech));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp resp.responseToken = malloc(sizeof(*resp.responseToken));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *buf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned i;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * Before doing anything else, see whether this is a SPNEGO
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * PDU. If not, dispatch to the GSSAPI library and get out.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * If we get here, it's SPNEGO.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = gssapi_spnego_decapsulate(minor_status, input_token_buffer,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = der_match_tag_and_length(buf, buf_size, ASN1_C_CONTEXT, CONS,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = decode_NegTokenInit(buf + taglen, len, &init_token, &ni_len);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp for (i = 0; !found && i < init_token.mechTypes.len; ++i) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (i == 0)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = send_accept(&minor_status2, output_token, ot, pref);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (ret != GSS_S_COMPLETE ? (OM_uint32) ret : major_status);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x60)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x06)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (!isc_safe_memequal(p, mech->elements, mech->length))
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 unsigned char **buf,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
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 unsigned val = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len > 0U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp val = (signed char)*p++;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len <= 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (v < 128U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (v == 0x80U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp v &= 0x7F;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_get_octet_string(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (len != 0U) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp data->components = malloc(len * sizeof(*data->components));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned u = 0;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_get_tag(p, len, &thisclass, &thistype, &thistag, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_match_tag_and_length(const unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam /* p += l; */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpdecode_enumerated(const unsigned char *p, size_t len, void *num, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_Enumerated, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_OID, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (val);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (1);
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.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_unsigned(unsigned char *p, size_t len, unsigned val, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *base = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_int(unsigned char *p, size_t len, int val, size_t *size)
ac48dfe87039078897ed719af26744eca776508cVikram Hegde unsigned char *base = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (val >= 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } while (val);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = 0xff;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length(unsigned char *p, size_t len, size_t val, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p = (unsigned char)val;
ac48dfe87039078897ed719af26744eca776508cVikram Hegde e = der_put_unsigned(p, len - 1, (unsigned int)val, &l);
ac48dfe87039078897ed719af26744eca776508cVikram Hegde *p = 0x80 | (unsigned char)l;
ac48dfe87039078897ed719af26744eca776508cVikram Hegdeder_put_octet_string(unsigned char *p, size_t len,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *base = p;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp *p-- = u % 128;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp while (u > 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_tag(unsigned char *p, size_t len, Der_class class, Der_type type,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpder_put_length_and_tag(unsigned char *p, size_t len, size_t len_val,
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpencode_enumerated(unsigned char *p, size_t len, const void *data, size_t *size)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_Enumerated, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_OctetString, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (e);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_OID, &l);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (0);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcpstatic void
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam e = der_put_length(p + len_len - 1, len_len, len, &foo);
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam * Give it a krb5_data and it will encapsulate with extra GSS-API wrappings.
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamgssapi_spnego_encapsulate(OM_uint32 * minor_status,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam unsigned char *buf,
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam gssapi_encap_length(buf_size, &len, &outer_len, mech);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp p = gssapi_mech_make_header(output_token->value, len, mech);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (p == NULL) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SPNEGO wrapper for Kerberos5 GSS-API kouril@ics.muni.cz, 2003 (mostly
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * based on Heimdal code)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliamadd_mech(MechTypeList * mech_list, gss_OID mech)
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam tmp = realloc(mech_list->val, (mech_list->len + 1) * sizeof(*tmp));
ba758cf1b2fe06a606303351c36a766f2f9f6665Jerry Gilliam ret = der_get_oid(mech->elements, mech->length,
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
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x60)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (*p++ != 0x06)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp return (-1);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_buffer_desc krb5_output_token = GSS_C_EMPTY_BUFFER;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp token_init.mechToken = malloc(sizeof(*token_init.mechToken));
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp token_init.mechToken->length = krb5_output_token.length;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * The MS implementation of SPNEGO seems to not like the mechListMIC
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * field, so we omit it (it's optional anyway)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (ret == 0) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp gss_release_buffer(&minor_status2, &krb5_output_token);
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp unsigned char *buf;
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * SPNEGO doesn't include gss wrapping on SubsequentContextToken
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp * like the Kerberos 5 mech does. But lets check for it anyway.
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp } else if ((size_t)mech_len == GSS_KRB5_MECH->length &&
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp isc_safe_memequal(GSS_KRB5_MECH->elements, p, mech_len))
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp else if ((size_t)mech_len == GSS_SPNEGO_MECH->length &&
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp isc_safe_memequal(GSS_SPNEGO_MECH->elements, p, mech_len)) {
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp ret = decode_NegTokenResp(buf + taglen, len, &resp, NULL);
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 /* Dirty trick to suppress compiler warnings */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp /* Figure out whether we're starting over or processing a reply */
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp if (input_token == GSS_C_NO_BUFFER || input_token->length == 0U)
7d87efa8fdfb9453670f2832df666fdae8291a84jmcp#endif /* GSSAPI */