5 * TrIPE protocol dissector for Ethereal
7 * (c) 2003 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Trivial IP Encryption (TrIPE).
14 * TrIPE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * TrIPE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with TrIPE; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
37 #include <netinet/in.h>
41 #include <ethereal/config.h>
42 #include <ethereal/epan/packet.h>
43 #include <ethereal/epan/prefs.h>
45 #include "tripe-protocol.h"
47 /*----- Static variables --------------------------------------------------*/
49 static int proto_tripe = -1;
51 static guint hashsz = 20, tagsz = 10, ivsz = 8;
54 int hf, hf_len, hf_val, tt;
57 int hf, hf_len, hf_val, hfx_len, hfx_val, hfy_len, hfy_val, tt;
60 static int hf_tripe_cat = -1;
61 static int hf_tripe_packet_type = -1;
62 static int hf_tripe_ct = -1;
63 static int hf_tripe_ct_seq = -1;
64 static int hf_tripe_ct_iv = -1;
65 static int hf_tripe_ct_ct = -1;
66 static int hf_tripe_ct_tag = -1;
67 static int hf_tripe_kx_type = -1;
68 static hfge hf_tripe_kx_mychal = { -1, -1, -1, -1, -1, -1, -1, -1 };
69 static int hf_tripe_kx_mycookie = -1;
70 static int hf_tripe_kx_yourcookie = -1;
71 static hfmp hf_tripe_kx_check = { -1, -1, -1, -1 };
72 static int hf_tripe_huh = -1;
74 static int tt_tripe = -1;
75 static int tt_tripe_ct = -1;
77 G_MODULE_EXPORT const gchar version[] = VERSION;
79 /*----- Main code ---------------------------------------------------------*/
81 static void prefcb(void) { }
83 static gint gethash(proto_tree *tt, int hf, tvbuff_t *b, gint off)
85 proto_tree_add_item(tt, hf, b, off, hashsz, FALSE);
86 return (off + hashsz);
89 static gint getmp(proto_tree *tt, const hfmp *hf, tvbuff_t *b, gint off)
91 guint16 len = tvb_get_ntohs(b, off);
92 proto_item *ti = proto_tree_add_item(tt, hf->hf, b, off, len + 2, FALSE);
93 tt = proto_item_add_subtree(ti, hf->tt);
94 proto_tree_add_item(tt, hf->hf_len, b, off, 2, FALSE);
95 proto_tree_add_item(tt, hf->hf_val, b, off + 2, len, FALSE);
96 return (off + 2 + len);
99 static gint getge(proto_tree *tt, const hfge *hf, tvbuff_t *b, gint off)
101 guint16 len = tvb_get_ntohs(b, off), len2;
104 r = tvb_length_remaining(b, off);
106 (len2 = tvb_get_ntohs(b, off + 2 + len), r < 4 + len + len2)) {
107 ti = proto_tree_add_item(tt, hf->hf, b, off, len + 2, FALSE);
108 tt = proto_item_add_subtree(ti, hf->tt);
109 proto_tree_add_item(tt, hf->hf_len, b, off, 2, FALSE);
110 proto_tree_add_item(tt, hf->hf_val, b, off + 2, len, FALSE);
113 ti = proto_tree_add_item(tt, hf->hf, b, off, len + len2 + 4, FALSE);
114 tt = proto_item_add_subtree(ti, hf->tt);
115 proto_tree_add_item(tt, hf->hfx_len, b, off, 2, FALSE);
116 proto_tree_add_item(tt, hf->hfx_val, b, off + 2, len, FALSE);
117 proto_tree_add_item(tt, hf->hfy_len, b, off + 2 + len, 2, FALSE);
118 proto_tree_add_item(tt, hf->hfy_val, b, off + 4 + len, len2, FALSE);
119 r = off + len + len2 + 4;
124 static void dissect_tripe(tvbuff_t *b, packet_info *p, proto_tree *t)
132 /* --- Initialize the summary cells --- */
134 if (check_col(p->cinfo, COL_PROTOCOL))
135 col_set_str(p->cinfo, COL_PROTOCOL, "TrIPE");
136 if (check_col(p->cinfo, COL_INFO))
137 col_clear(p->cinfo, COL_INFO);
138 ty = tvb_get_guint8(b, 0);
139 if (check_col(p->cinfo, COL_INFO)) {
140 col_clear(p->cinfo, COL_INFO);
141 switch (ty & MSG_CATMASK) {
143 switch (ty & MSG_TYPEMASK) {
145 col_set_str(p->cinfo, COL_INFO, "Packet data");
148 col_add_fstr(p->cinfo, COL_INFO,
149 "Packet data, unknown type code %u",
155 switch (ty & MSG_TYPEMASK) {
157 col_set_str(p->cinfo, COL_INFO, "Key exchange, prechallenge");
160 col_set_str(p->cinfo, COL_INFO, "Key exchange, cookie");
163 col_set_str(p->cinfo, COL_INFO, "Key exchange, challenge");
166 col_set_str(p->cinfo, COL_INFO, "Key exchange, reply");
169 col_set_str(p->cinfo, COL_INFO, "Key exchange, switch request");
172 col_set_str(p->cinfo, COL_INFO, "Key exchange, switch response");
175 col_add_fstr(p->cinfo, COL_INFO,
176 "Key exchange, unknown type code %u",
182 col_add_fstr(p->cinfo, COL_INFO,
183 "Unknown category code %u, unknown type code %u",
184 ty & MSG_CATMASK, ty & MSG_TYPEMASK);
189 /* --- Fill in the tree --- */
192 ti = proto_tree_add_item(t, proto_tripe, b, 0, -1, FALSE);
193 tt = proto_item_add_subtree(ti, tt_tripe);
195 proto_tree_add_item(tt, hf_tripe_cat, b, 0, 1, FALSE);
198 switch (ty & MSG_CATMASK) {
200 proto_tree_add_item(tt, hf_tripe_packet_type, b, 0, 1, FALSE);
201 switch (ty & MSG_TYPEMASK) {
209 proto_tree_add_item(tt, hf_tripe_kx_type, b, 0, 1, FALSE);
210 switch (ty & MSG_TYPEMASK) {
212 off = getge(tt, &hf_tripe_kx_mychal, b, off);
215 off = getge(tt, &hf_tripe_kx_mychal, b, off);
216 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
219 off = getge(tt, &hf_tripe_kx_mychal, b, off);
220 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
221 off = getmp(tt, &hf_tripe_kx_check, b, off);
224 off = gethash(tt, hf_tripe_kx_mycookie, b, off);
225 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
226 off = getmp(tt, &hf_tripe_kx_check, b, off);
229 off = gethash(tt, hf_tripe_kx_mycookie, b, off);
230 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
242 if (tvb_offset_exists(b, off))
246 proto_tree_add_item(tt, hf_tripe_huh, b, off, -1, FALSE);
249 ti = proto_tree_add_item(tt, hf_tripe_ct, b, off, -1, FALSE);
250 seq = tvb_get_ntohl(b, off + tagsz);
251 proto_item_set_text(ti, "Encrypted ciphertext (sequence number %lu)",
253 tt = proto_item_add_subtree(ti, tt_tripe_ct);
255 proto_tree_add_item(tt, hf_tripe_ct_tag, b, off, tagsz, FALSE);
258 proto_tree_add_item(tt, hf_tripe_ct_seq, b, off, 4, FALSE);
261 proto_tree_add_item(tt, hf_tripe_ct_iv, b, off, ivsz, FALSE);
264 proto_tree_add_item(ti, hf_tripe_ct_ct, b, off, -1, FALSE);
270 void proto_register_tripe(void)
274 static value_string vs_kxtype[] = {
275 { KX_PRECHAL, "KX_PRECHAL (prechallenge)" },
276 { KX_COOKIE, "KX_COOKIE (cookie)" },
277 { KX_CHAL, "KX_CHAL (challenge)" },
278 { KX_REPLY, "KX_REPLY (reply)" },
279 { KX_SWITCH, "KX_SWITCH (switch request)" },
280 { KX_SWITCHOK, "KX_SWITCHOK (switch response)" },
284 static hf_register_info hfs[] = {
286 "Message category", "tripe.cat",
287 FT_UINT8, BASE_HEX, 0, MSG_CATMASK
289 { &hf_tripe_packet_type, {
290 "Packet message type", "tripe.packet.type",
291 FT_UINT8, BASE_HEX, 0, MSG_TYPEMASK,
292 "This is the TrIPE packet type subcode."
295 "Encrypted ciphertext", "tripe.ct",
296 FT_BYTES, BASE_NONE, 0, 0,
297 "This is an encrypted message."
299 { &hf_tripe_ct_seq, {
300 "Ciphertext sequence number", "tripe.ct.seq",
301 FT_UINT32, BASE_DEC, 0, 0,
302 "This is the unique sequence number for the ciphertext."
305 "Ciphertext initialization vector", "tripe.ct.iv",
306 FT_BYTES, BASE_NONE, 0, 0,
307 "This is the initialization vector used for the actual encryption."
310 "Actual encrypted data", "tripe.ct.ct",
311 FT_BYTES, BASE_NONE, 0, 0,
312 "This is the encrypted message. Reading it ought to be hard."
314 { &hf_tripe_ct_tag, {
315 "Message authentication code", "tripe.ct.tag",
316 FT_BYTES, BASE_NONE, 0, 0,
317 "This is the message authentication code tag for the ciphertext."
319 { &hf_tripe_kx_type, {
320 "Key-exchange message type", "tripe.kx.type",
321 FT_UINT8, BASE_HEX, vs_kxtype, MSG_TYPEMASK,
322 "This is the TrIPE key-exchange type subcode."
324 { &hf_tripe_kx_mychal.hf, {
325 "Sender's challenge data", "tripe.kx.mychal",
326 FT_BYTES, BASE_NONE, 0, 0,
327 "This is the sender's challenge."
329 { &hf_tripe_kx_mychal.hf_len, {
330 "Challenge length", "tripe.kx.mychal.len",
331 FT_UINT16, BASE_DEC, 0, 0,
332 "This is the length of the sender's challenge."
334 { &hf_tripe_kx_mychal.hf_val, {
335 "Challenge", "tripe.kx.mychal.val",
336 FT_BYTES, BASE_NONE, 0, 0,
337 "This is the value of the sender's challenge."
339 { &hf_tripe_kx_mychal.hfx_len, {
340 "Challenge x length", "tripe.kx.mychal.x.len",
341 FT_UINT16, BASE_DEC, 0, 0,
342 "This is the length of the sender's challenge x-coordinate."
344 { &hf_tripe_kx_mychal.hfy_val, {
345 "Challenge x value", "tripe.kx.mychal.x.val",
346 FT_BYTES, BASE_NONE, 0, 0,
347 "This is the value of the sender's challenge x-coordinate."
349 { &hf_tripe_kx_mychal.hfy_len, {
350 "Challenge y length", "tripe.kx.mychal.y.len",
351 FT_UINT16, BASE_DEC, 0, 0,
352 "This is the length of the sender's challenge x-coordinate."
354 { &hf_tripe_kx_mychal.hfx_val, {
355 "Challenge y value", "tripe.kx.mychal.y.val",
356 FT_BYTES, BASE_NONE, 0, 0,
357 "This is the value of the sender's challenge x-coordinate."
359 { &hf_tripe_kx_mycookie, {
360 "Sender's hashed cookie", "tripe.kx.mycookie",
361 FT_BYTES, BASE_NONE, 0, 0,
362 "This is the hash of the sender's challenge."
364 { &hf_tripe_kx_yourcookie, {
365 "Recipient's hashed cookie", "tripe.kx.yourcookie",
366 FT_BYTES, BASE_NONE, 0, 0,
367 "This is the hash of the recipient's challenge."
369 { &hf_tripe_kx_check.hf, {
370 "Challenge check-value", "tripe.kx.check",
371 FT_BYTES, BASE_NONE, 0, 0,
372 "This is an encrypted check-value which proves that the sender "
373 "knows the answer to the challenge, and that it is therefore honest."
375 { &hf_tripe_kx_check.hf_len, {
376 "Check-value length", "tripe.kx.check.len",
377 FT_UINT16, BASE_DEC, 0, 0,
378 "This is the length of the encrypted check-value."
380 { &hf_tripe_kx_check.hf_val, {
381 "Check-value data", "tripe.kx.check.val",
382 FT_BYTES, BASE_NONE, 0, 0,
383 "This is the actual encrypted check-value."
386 "Unknown data", "tripe.huh",
387 FT_BYTES, BASE_NONE, 0, 0,
388 "I don't know what's meant to appear here."
392 static gint *tts[] = {
395 &hf_tripe_kx_mychal.tt,
396 &hf_tripe_kx_check.tt,
399 proto_tripe = proto_register_protocol("TrIPE", "TrIPE", "tripe");
400 proto_register_field_array(proto_tripe, hfs, array_length(hfs));
401 proto_register_subtree_array(tts, array_length(tts));
403 mod = prefs_register_protocol(proto_tripe, prefcb);
404 prefs_register_uint_preference(mod, "hashsz", "Hash length",
405 "hash function output length (in octets)",
407 prefs_register_uint_preference(mod, "tagsz", "MAC tag length",
408 "MAC tag length (in octets)", 10, &tagsz);
409 prefs_register_uint_preference(mod, "ivsz", "IV length",
410 "block cipher initialization vector length"
415 void proto_reg_handoff_tripe(void)
417 dissector_handle_t dh;
419 dh = create_dissector_handle(dissect_tripe, proto_tripe);
420 dissector_add("udp.port", 22003, dh);
423 G_MODULE_EXPORT void plugin_reg_handoff(void)
425 proto_reg_handoff_tripe();
428 G_MODULE_EXPORT void plugin_register(void)
430 if (proto_tripe == -1)
431 proto_register_tripe();
434 /*----- That's all, folks -------------------------------------------------*/