Coverage Report

Created: 2026-08-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-fc00.c
Line
Count
Source
1
/* packet-fc00.c
2
 * Routines for fc00/cjdns dissection
3
 * Copyright 2015, Emery Hemingway <emery@v36.spacet>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
/*
13
 * https://github.com/cjdelisle/cjdns
14
 * https://github.com/fc00/spec
15
 */
16
17
#include <config.h>
18
19
#include <epan/expert.h>
20
#include <epan/packet.h>
21
22
/* Prototypes */
23
/* (Required to prevent [-Wmissing-prototypes] warnings */
24
void proto_reg_handoff_fc00(void);
25
void proto_register_fc00(void);
26
27
static dissector_handle_t fc00_handle;
28
29
/* Initialize the protocol and registered fields */
30
static int proto_fc00;
31
static int hf_fc00_session_state;
32
static int hf_fc00_session_nonce;
33
static int hf_fc00_auth_challenge;
34
static int hf_fc00_auth_type;
35
static int hf_fc00_auth_hash_code;
36
static int hf_fc00_auth_poly;
37
static int hf_fc00_auth_derivations;
38
static int hf_fc00_auth_additional;
39
static int hf_fc00_random_nonce;
40
static int hf_fc00_public_key;
41
static int hf_fc00_ip_address;
42
static int hf_fc00_authenticator;
43
static int hf_fc00_temp_publicy_key;
44
static int hf_fc00_payload;
45
46
/* Cjdns constants */
47
0
#define SESSION_STATE_OFF 0
48
0
#define SESSION_STATE_LEN 4
49
0
#define CHALLENGE_OFF 4
50
0
#define CHALLENGE_LEN 12
51
0
#define NONCE_OFF 16
52
0
#define NONCE_LEN 24
53
0
#define PUBLIC_KEY_OFF 40
54
0
#define PUBLIC_KEY_LEN 32
55
0
#define POLY_AUTH_OFF 72
56
0
#define POLY_AUTH_LEN 16
57
0
#define TEMP_KEY_OFF 88
58
0
#define TEMP_KEY_LEN 32
59
0
#define CRYPTO_HEADER_LEN 120
60
61
/* Initialize the subtree pointers */
62
static int ett_fc00;
63
static int ett_fc00_auth;
64
static int ett_fc00_key;
65
66
static const value_string session_states[] = {
67
    { UINT32_MAX, "Connect To Me" },
68
    { 0, "Hello" },
69
    { 1, "Hello" },
70
    { 2, "repeated Hello" },
71
    { 3, "Key" },
72
    { 4, "repeated Key" },
73
    { 0, NULL }
74
};
75
76
/* Code to actually dissect the packets */
77
static int
78
dissect_cryptoauth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
79
0
{
80
0
    uint32_t session_state;
81
0
    proto_item *ti = NULL;
82
0
    proto_tree *fc00_tree = NULL;
83
0
    unsigned payload_len = 0;
84
85
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "fc00");
86
0
    col_clear(pinfo->cinfo, COL_INFO);
87
88
0
    session_state = tvb_get_ntohl(tvb, SESSION_STATE_OFF);
89
90
0
    if ((session_state > 3) && (session_state < UINT32_MAX)) {
91
0
        ti = proto_tree_add_item(tree, proto_fc00, tvb, 0, SESSION_STATE_LEN, ENC_NA);
92
0
        fc00_tree = proto_item_add_subtree(ti, ett_fc00);
93
0
        proto_tree_add_item(fc00_tree, hf_fc00_session_nonce, tvb,
94
0
                SESSION_STATE_OFF, SESSION_STATE_LEN, ENC_BIG_ENDIAN);
95
96
0
        payload_len = tvb_reported_length(tvb)-SESSION_STATE_LEN;
97
98
0
        proto_tree_add_item(fc00_tree, hf_fc00_payload, tvb,
99
0
                SESSION_STATE_LEN, payload_len, ENC_NA);
100
101
0
        return SESSION_STATE_LEN;
102
0
    }
103
104
0
    ti = proto_tree_add_item(tree, proto_fc00, tvb, 0, 120, ENC_NA);
105
0
    fc00_tree = proto_item_add_subtree(ti, ett_fc00);
106
107
0
    proto_tree_add_item(fc00_tree, hf_fc00_session_state, tvb,
108
0
            SESSION_STATE_OFF, SESSION_STATE_LEN, ENC_BIG_ENDIAN);
109
110
0
    ti = proto_tree_add_item(fc00_tree, hf_fc00_auth_challenge, tvb,
111
0
            CHALLENGE_OFF, CHALLENGE_LEN, ENC_NA);
112
0
    {
113
0
        proto_tree *auth_tree = proto_item_add_subtree(ti, ett_fc00_auth);
114
0
        proto_tree_add_item(auth_tree, hf_fc00_auth_type, tvb, CHALLENGE_OFF, 1, ENC_NA);
115
0
        proto_tree_add_item(auth_tree, hf_fc00_auth_hash_code, tvb, CHALLENGE_OFF+1, 7, ENC_NA);
116
0
        proto_tree_add_item(auth_tree, hf_fc00_auth_poly, tvb, CHALLENGE_OFF+8, 1, ENC_NA);
117
0
        proto_tree_add_item(auth_tree, hf_fc00_auth_derivations, tvb, CHALLENGE_OFF+8, 2, ENC_BIG_ENDIAN);
118
0
        proto_tree_add_item(auth_tree, hf_fc00_auth_additional, tvb, CHALLENGE_OFF+10, 2, ENC_BIG_ENDIAN);
119
0
    }
120
121
0
    proto_tree_add_item(fc00_tree, hf_fc00_random_nonce, tvb,
122
0
            NONCE_OFF, NONCE_LEN, ENC_NA);
123
124
0
    if (fc00_tree)
125
0
    {
126
0
        GChecksum *hash  = g_checksum_new(G_CHECKSUM_SHA512);
127
0
        size_t digest_len = g_checksum_type_get_length(G_CHECKSUM_SHA512);
128
0
        proto_tree *key_tree;
129
130
0
        uint8_t *raw_key    = (uint8_t*)wmem_alloc(pinfo->pool, PUBLIC_KEY_LEN);
131
#if 0
132
        // This key is encoded according to a custom Base32 variant that
133
        // uses the alphabet "0123456789bcdfghjklmnpqrstuvwxyz" instead
134
        // of that in RFC 4648.
135
        char *encoded_key = (char*)wmem_alloc(pinfo->pool, 53);
136
#endif
137
0
        uint8_t *ip_buf    = (uint8_t*)wmem_alloc(pinfo->pool, digest_len);
138
139
0
        tvb_memcpy(tvb, raw_key, PUBLIC_KEY_OFF, PUBLIC_KEY_LEN);
140
141
0
        g_checksum_update(hash, (unsigned char*)raw_key, PUBLIC_KEY_LEN);
142
0
        g_checksum_get_digest(hash, ip_buf, &digest_len);
143
0
        g_checksum_free(hash);
144
145
0
        hash = g_checksum_new(G_CHECKSUM_SHA512);
146
0
        g_checksum_update(hash, (unsigned char*)ip_buf, digest_len);
147
0
        g_checksum_get_digest(hash, ip_buf, &digest_len);
148
0
        g_checksum_free(hash);
149
150
0
        ti = proto_tree_add_item(fc00_tree, hf_fc00_public_key, tvb, PUBLIC_KEY_OFF, PUBLIC_KEY_LEN, ENC_NA);
151
152
0
        key_tree = proto_item_add_subtree(ti, ett_fc00_key);
153
154
0
        proto_tree_add_ipv6(key_tree, hf_fc00_ip_address, tvb, PUBLIC_KEY_OFF, PUBLIC_KEY_LEN, (ws_in6_addr*)ip_buf);
155
0
    }
156
157
0
    proto_tree_add_item(fc00_tree, hf_fc00_authenticator, tvb,
158
0
            POLY_AUTH_OFF, POLY_AUTH_LEN, ENC_NA);
159
160
0
    proto_tree_add_item(fc00_tree, hf_fc00_temp_publicy_key, tvb,
161
0
            TEMP_KEY_OFF, TEMP_KEY_LEN, ENC_NA);
162
163
0
    payload_len = tvb_reported_length(tvb)-(TEMP_KEY_OFF+TEMP_KEY_LEN);
164
165
0
    proto_tree_add_item(fc00_tree, hf_fc00_payload, tvb,
166
0
            CRYPTO_HEADER_LEN, payload_len, ENC_NA);
167
168
0
    return tvb_captured_length(tvb);
169
0
}
170
171
/* Register the protocol with Wireshark.
172
 */
173
void
174
proto_register_fc00(void)
175
16
{
176
16
    static hf_register_info hf[] = {
177
16
        { &hf_fc00_session_state,
178
16
          { "Session State", "fc00.session_state",
179
16
            FT_UINT32, BASE_DEC, VALS(session_states), 0x0,
180
16
            NULL, HFILL }
181
16
        },
182
183
16
        { &hf_fc00_session_nonce,
184
16
          { "Session Nonce", "fc00.session_nonce",
185
16
            FT_UINT32, BASE_DEC, NULL, 0x0,
186
16
            NULL, HFILL }
187
16
        },
188
189
16
        { &hf_fc00_auth_challenge,
190
16
          { "Auth Challenge", "fc00.auth_challenge",
191
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
192
16
            NULL, HFILL }
193
16
        },
194
195
16
        { &hf_fc00_auth_type,
196
16
          { "Auth Type", "fc00.auth_challenge.type",
197
16
            FT_UINT8, BASE_DEC, NULL, 0x0,
198
16
            NULL, HFILL }
199
16
        },
200
201
16
        { &hf_fc00_auth_hash_code,
202
16
          { "Auth Hash Code", "fc00.auth_challenge.hash_code",
203
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
204
16
            NULL, HFILL }
205
16
        },
206
207
16
        { &hf_fc00_auth_poly,
208
16
          { "Poly1305 Authentication", "fc00.auth_challenge.poly1305",
209
16
            FT_UINT8, BASE_DEC, NULL, 0x80,
210
16
            NULL, HFILL }
211
16
        },
212
213
16
        { &hf_fc00_auth_derivations,
214
16
          { "Auth Derivations", "fc00.auth_challenge.derivations",
215
16
            FT_UINT16, BASE_DEC, NULL, 0x7F,
216
16
            NULL, HFILL }
217
16
        },
218
219
16
        { &hf_fc00_auth_additional,
220
16
          { "Auth Additional", "fc00.auth_challenge.additional",
221
16
            FT_UINT16, BASE_HEX, NULL, 0x0,
222
16
            NULL, HFILL }
223
16
        },
224
225
16
        { &hf_fc00_random_nonce,
226
16
          { "Random Nonce", "fc00.random_nonce",
227
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
228
16
            NULL, HFILL }
229
16
        },
230
231
16
        { &hf_fc00_public_key,
232
16
          { "Permanent Public Key", "fc00.public_key",
233
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
234
16
            "Base32 encoded public key", HFILL }
235
16
        },
236
237
16
        { &hf_fc00_ip_address,
238
16
          { "IPv6 Address", "fc00.ip",
239
16
            FT_IPv6, BASE_NONE, NULL, 0x0,
240
16
            "Double SHA256 hash of public key", HFILL }
241
16
        },
242
243
16
        { &hf_fc00_authenticator,
244
16
          { "Poly1305 Authenticator", "fc00.authenticator",
245
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
246
16
            NULL, HFILL }
247
16
        },
248
249
16
        { &hf_fc00_temp_publicy_key,
250
16
          { "Encrypted/Authenticated Temporary Public Key",
251
16
            "fc00.temp_key",
252
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
253
16
            NULL, HFILL }
254
16
        },
255
256
16
        { &hf_fc00_payload,
257
16
          { "Encrypted Payload", "fc00.payload",
258
16
            FT_BYTES, BASE_NONE, NULL, 0x0,
259
16
            NULL, HFILL }
260
16
        }
261
16
    };
262
263
16
    static int *ett[] = {
264
16
        &ett_fc00,
265
16
        &ett_fc00_auth,
266
16
        &ett_fc00_key
267
16
    };
268
269
    /* XXX - What is the relationship between Cjdns and Fc00? Should one
270
     * of them be an alias? */
271
16
    proto_fc00 = proto_register_protocol("Fc00 CryptoAuth", "Fc00", "fc00");
272
273
16
    proto_register_field_array(proto_fc00, hf, array_length(hf));
274
16
    proto_register_subtree_array(ett, array_length(ett));
275
276
16
    fc00_handle = register_dissector("fc00", dissect_cryptoauth, proto_fc00);
277
16
}
278
279
void
280
proto_reg_handoff_fc00(void)
281
16
{
282
16
    dissector_add_for_decode_as_with_preference("udp.port", fc00_handle);
283
16
}
284
285
/*
286
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
287
 *
288
 * Local variables:
289
 * c-basic-offset: 4
290
 * tab-width: 8
291
 * indent-tabs-mode: nil
292
 * End:
293
 *
294
 * vi: set shiftwidth=4 tabstop=8 expandtab:
295
 * :indentSize=4:tabSize=8:noTabs=true:
296
 */