Path: blob/main/crypto/krb5/src/lib/gssapi/spnego/negoex_trace.c
39563 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright (C) 2011-2018 PADL Software Pty Ltd.3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,22* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR24* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,26* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED28* OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031#include "gssapiP_spnego.h"3233static int34guid_to_string(const uint8_t guid[16], char *buffer, size_t bufsiz)35{36uint32_t data1;37uint16_t data2, data3;3839data1 = load_32_le(guid);40data2 = load_16_le(guid + 4);41data3 = load_16_le(guid + 6);4243return snprintf(buffer, bufsiz,44"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",45data1, data2, data3, guid[8], guid[9], guid[10], guid[11],46guid[12], guid[13], guid[14], guid[15]);47}4849static void50trace_auth_scheme(spnego_gss_ctx_id_t ctx, const char *prefix, int ind,51const auth_scheme scheme)52{53char trace_msg[128];54char szAuthScheme[37];5556guid_to_string(scheme, szAuthScheme, sizeof(szAuthScheme));5758snprintf(trace_msg, sizeof(trace_msg),59"NEGOEXTS: %20s[%02u] -- AuthScheme %s",60prefix, ind, szAuthScheme);61TRACE_NEGOEX_AUTH_SCHEMES(ctx->kctx, trace_msg);62}6364void65negoex_trace_auth_schemes(spnego_gss_ctx_id_t ctx, const char *prefix,66const uint8_t *schemes, uint16_t nschemes)67{68uint16_t i;6970for (i = 0; i < nschemes; i++)71trace_auth_scheme(ctx, prefix, i, schemes + i * GUID_LENGTH);72}7374void75negoex_trace_ctx_auth_schemes(spnego_gss_ctx_id_t ctx, const char *prefix)76{77negoex_auth_mech_t mech;78int ind = 0;7980K5_TAILQ_FOREACH(mech, &ctx->negoex_mechs, links)81trace_auth_scheme(ctx, prefix, ind++, mech->scheme);82}8384void85negoex_trace_message(spnego_gss_ctx_id_t ctx, int direction,86enum message_type type, const conversation_id conv_id,87unsigned int seqnum, unsigned int header_len,88unsigned int msg_len)89{90char trace_msg[128];91char conv_str[37];92char *typestr;9394if (type == INITIATOR_NEGO)95typestr = "INITIATOR_NEGO";96else if (type == ACCEPTOR_NEGO)97typestr = "ACCEPTOR_NEGO";98else if (type == INITIATOR_META_DATA)99typestr = "INITIATOR_META_DATA";100else if (type == ACCEPTOR_META_DATA)101typestr = "ACCEPTOR_META_DATA";102else if (type == CHALLENGE)103typestr = "CHALLENGE";104else if (type == AP_REQUEST)105typestr = "AP_REQUEST";106else if (type == VERIFY)107typestr = "VERIFY";108else if (type == ALERT)109typestr = "ALERT";110else111typestr = "UNKNOWN";112113guid_to_string(conv_id, conv_str, sizeof(conv_str));114snprintf(trace_msg, sizeof(trace_msg),115"NEGOEXTS%c %20s[%02u] -- ConvId %s HdrLength %u MsgLength %u",116direction ? '<' : '>', typestr, seqnum, conv_str, header_len,117msg_len);118119TRACE_NEGOEX_MESSAGE(ctx->kctx, trace_msg);120}121122123