Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/lib/gssapi/spnego/negoex_trace.c
39563 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/*
3
* Copyright (C) 2011-2018 PADL Software Pty Ltd.
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
*
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
*
13
* * Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in
15
* the documentation and/or other materials provided with the
16
* distribution.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29
* OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
#include "gssapiP_spnego.h"
33
34
static int
35
guid_to_string(const uint8_t guid[16], char *buffer, size_t bufsiz)
36
{
37
uint32_t data1;
38
uint16_t data2, data3;
39
40
data1 = load_32_le(guid);
41
data2 = load_16_le(guid + 4);
42
data3 = load_16_le(guid + 6);
43
44
return snprintf(buffer, bufsiz,
45
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
46
data1, data2, data3, guid[8], guid[9], guid[10], guid[11],
47
guid[12], guid[13], guid[14], guid[15]);
48
}
49
50
static void
51
trace_auth_scheme(spnego_gss_ctx_id_t ctx, const char *prefix, int ind,
52
const auth_scheme scheme)
53
{
54
char trace_msg[128];
55
char szAuthScheme[37];
56
57
guid_to_string(scheme, szAuthScheme, sizeof(szAuthScheme));
58
59
snprintf(trace_msg, sizeof(trace_msg),
60
"NEGOEXTS: %20s[%02u] -- AuthScheme %s",
61
prefix, ind, szAuthScheme);
62
TRACE_NEGOEX_AUTH_SCHEMES(ctx->kctx, trace_msg);
63
}
64
65
void
66
negoex_trace_auth_schemes(spnego_gss_ctx_id_t ctx, const char *prefix,
67
const uint8_t *schemes, uint16_t nschemes)
68
{
69
uint16_t i;
70
71
for (i = 0; i < nschemes; i++)
72
trace_auth_scheme(ctx, prefix, i, schemes + i * GUID_LENGTH);
73
}
74
75
void
76
negoex_trace_ctx_auth_schemes(spnego_gss_ctx_id_t ctx, const char *prefix)
77
{
78
negoex_auth_mech_t mech;
79
int ind = 0;
80
81
K5_TAILQ_FOREACH(mech, &ctx->negoex_mechs, links)
82
trace_auth_scheme(ctx, prefix, ind++, mech->scheme);
83
}
84
85
void
86
negoex_trace_message(spnego_gss_ctx_id_t ctx, int direction,
87
enum message_type type, const conversation_id conv_id,
88
unsigned int seqnum, unsigned int header_len,
89
unsigned int msg_len)
90
{
91
char trace_msg[128];
92
char conv_str[37];
93
char *typestr;
94
95
if (type == INITIATOR_NEGO)
96
typestr = "INITIATOR_NEGO";
97
else if (type == ACCEPTOR_NEGO)
98
typestr = "ACCEPTOR_NEGO";
99
else if (type == INITIATOR_META_DATA)
100
typestr = "INITIATOR_META_DATA";
101
else if (type == ACCEPTOR_META_DATA)
102
typestr = "ACCEPTOR_META_DATA";
103
else if (type == CHALLENGE)
104
typestr = "CHALLENGE";
105
else if (type == AP_REQUEST)
106
typestr = "AP_REQUEST";
107
else if (type == VERIFY)
108
typestr = "VERIFY";
109
else if (type == ALERT)
110
typestr = "ALERT";
111
else
112
typestr = "UNKNOWN";
113
114
guid_to_string(conv_id, conv_str, sizeof(conv_str));
115
snprintf(trace_msg, sizeof(trace_msg),
116
"NEGOEXTS%c %20s[%02u] -- ConvId %s HdrLength %u MsgLength %u",
117
direction ? '<' : '>', typestr, seqnum, conv_str, header_len,
118
msg_len);
119
120
TRACE_NEGOEX_MESSAGE(ctx->kctx, trace_msg);
121
}
122
123