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_misc_type = -1;
68 static int hf_tripe_misc_payload = -1;
69 static int hf_tripe_kx_type = -1;
70 static hfge hf_tripe_kx_mychal = { -1, -1, -1, -1, -1, -1, -1, -1 };
71 static int hf_tripe_kx_mycookie = -1;
72 static int hf_tripe_kx_yourcookie = -1;
73 static hfmp hf_tripe_kx_check = { -1, -1, -1, -1 };
74 static int hf_tripe_huh = -1;
76 static int tt_tripe = -1;
77 static int tt_tripe_ct = -1;
79 G_MODULE_EXPORT const gchar version[] = VERSION;
81 /*----- Main code ---------------------------------------------------------*/
83 static void prefcb(void) { }
85 static gint gethash(proto_tree *tt, int hf, tvbuff_t *b, gint off)
87 proto_tree_add_item(tt, hf, b, off, hashsz, FALSE);
88 return (off + hashsz);
91 static gint getmp(proto_tree *tt, const hfmp *hf, tvbuff_t *b, gint off)
93 guint16 len = tvb_get_ntohs(b, off);
94 proto_item *ti = proto_tree_add_item(tt, hf->hf, b, off, len + 2, FALSE);
95 tt = proto_item_add_subtree(ti, hf->tt);
96 proto_tree_add_item(tt, hf->hf_len, b, off, 2, FALSE);
97 proto_tree_add_item(tt, hf->hf_val, b, off + 2, len, FALSE);
98 return (off + 2 + len);
101 static gint getge(proto_tree *tt, const hfge *hf, tvbuff_t *b, gint off)
103 guint16 len = tvb_get_ntohs(b, off), len2;
106 r = tvb_length_remaining(b, off);
108 (len2 = tvb_get_ntohs(b, off + 2 + len), r < 4 + len + len2)) {
109 ti = proto_tree_add_item(tt, hf->hf, b, off, len + 2, FALSE);
110 tt = proto_item_add_subtree(ti, hf->tt);
111 proto_tree_add_item(tt, hf->hf_len, b, off, 2, FALSE);
112 proto_tree_add_item(tt, hf->hf_val, b, off + 2, len, FALSE);
115 ti = proto_tree_add_item(tt, hf->hf, b, off, len + len2 + 4, FALSE);
116 tt = proto_item_add_subtree(ti, hf->tt);
117 proto_tree_add_item(tt, hf->hfx_len, b, off, 2, FALSE);
118 proto_tree_add_item(tt, hf->hfx_val, b, off + 2, len, FALSE);
119 proto_tree_add_item(tt, hf->hfy_len, b, off + 2 + len, 2, FALSE);
120 proto_tree_add_item(tt, hf->hfy_val, b, off + 4 + len, len2, FALSE);
121 r = off + len + len2 + 4;
126 static void dissect_tripe(tvbuff_t *b, packet_info *p, proto_tree *t)
134 /* --- Initialize the summary cells --- */
136 if (check_col(p->cinfo, COL_PROTOCOL))
137 col_set_str(p->cinfo, COL_PROTOCOL, "TrIPE");
138 if (check_col(p->cinfo, COL_INFO))
139 col_clear(p->cinfo, COL_INFO);
140 ty = tvb_get_guint8(b, 0);
141 if (check_col(p->cinfo, COL_INFO)) {
142 col_clear(p->cinfo, COL_INFO);
143 switch (ty & MSG_CATMASK) {
145 switch (ty & MSG_TYPEMASK) {
147 col_set_str(p->cinfo, COL_INFO, "Packet data");
150 col_add_fstr(p->cinfo, COL_INFO,
151 "Packet data, unknown type code %u",
157 switch (ty & MSG_TYPEMASK) {
159 col_set_str(p->cinfo, COL_INFO, "Key exchange, prechallenge");
162 col_set_str(p->cinfo, COL_INFO, "Key exchange, cookie");
165 col_set_str(p->cinfo, COL_INFO, "Key exchange, challenge");
168 col_set_str(p->cinfo, COL_INFO, "Key exchange, reply");
171 col_set_str(p->cinfo, COL_INFO, "Key exchange, switch request");
174 col_set_str(p->cinfo, COL_INFO, "Key exchange, switch response");
177 col_add_fstr(p->cinfo, COL_INFO,
178 "Key exchange, unknown type code %u",
184 switch (ty & MSG_TYPEMASK) {
186 col_set_str(p->cinfo, COL_INFO, "Miscellaneous, no-operation");
189 col_set_str(p->cinfo, COL_INFO, "Miscellaneous, transport ping");
192 col_set_str(p->cinfo, COL_INFO,
193 "Miscellaneous, transport ping reply");
196 col_set_str(p->cinfo, COL_INFO, "Miscellaneous, encrypted ping");
199 col_set_str(p->cinfo, COL_INFO,
200 "Miscellaneous, encrypted ping reply");
203 col_add_fstr(p->cinfo, COL_INFO,
204 "Miscellaneous, unknown type code %u",
210 col_add_fstr(p->cinfo, COL_INFO,
211 "Unknown category code %u, unknown type code %u",
212 ty & MSG_CATMASK, ty & MSG_TYPEMASK);
217 /* --- Fill in the tree --- */
220 ti = proto_tree_add_item(t, proto_tripe, b, 0, -1, FALSE);
221 tt = proto_item_add_subtree(ti, tt_tripe);
223 proto_tree_add_item(tt, hf_tripe_cat, b, 0, 1, FALSE);
226 switch (ty & MSG_CATMASK) {
228 proto_tree_add_item(tt, hf_tripe_packet_type, b, 0, 1, FALSE);
229 switch (ty & MSG_TYPEMASK) {
237 proto_tree_add_item(tt, hf_tripe_kx_type, b, 0, 1, FALSE);
238 switch (ty & MSG_TYPEMASK) {
240 off = getge(tt, &hf_tripe_kx_mychal, b, off);
243 off = getge(tt, &hf_tripe_kx_mychal, b, off);
244 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
247 off = getge(tt, &hf_tripe_kx_mychal, b, off);
248 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
249 off = getmp(tt, &hf_tripe_kx_check, b, off);
252 off = gethash(tt, hf_tripe_kx_mycookie, b, off);
253 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
254 off = getmp(tt, &hf_tripe_kx_check, b, off);
257 off = gethash(tt, hf_tripe_kx_mycookie, b, off);
258 off = gethash(tt, hf_tripe_kx_yourcookie, b, off);
267 proto_tree_add_item(tt, hf_tripe_misc_type, b, 0, 1, FALSE);
268 switch (ty & MSG_TYPEMASK) {
272 proto_tree_add_item(tt, hf_tripe_misc_payload,
286 if (tvb_offset_exists(b, off))
290 proto_tree_add_item(tt, hf_tripe_huh, b, off, -1, FALSE);
293 ti = proto_tree_add_item(tt, hf_tripe_ct, b, off, -1, FALSE);
294 seq = tvb_get_ntohl(b, off + tagsz);
295 proto_item_set_text(ti, "Encrypted ciphertext (sequence number %lu)",
297 tt = proto_item_add_subtree(ti, tt_tripe_ct);
299 proto_tree_add_item(tt, hf_tripe_ct_tag, b, off, tagsz, FALSE);
302 proto_tree_add_item(tt, hf_tripe_ct_seq, b, off, 4, FALSE);
305 proto_tree_add_item(tt, hf_tripe_ct_iv, b, off, ivsz, FALSE);
308 proto_tree_add_item(ti, hf_tripe_ct_ct, b, off, -1, FALSE);
314 void proto_register_tripe(void)
318 static value_string vs_kxtype[] = {
319 { KX_PRECHAL, "KX_PRECHAL (prechallenge)" },
320 { KX_COOKIE, "KX_COOKIE (cookie)" },
321 { KX_CHAL, "KX_CHAL (challenge)" },
322 { KX_REPLY, "KX_REPLY (reply)" },
323 { KX_SWITCH, "KX_SWITCH (switch request)" },
324 { KX_SWITCHOK, "KX_SWITCHOK (switch response)" },
328 static hf_register_info hfs[] = {
330 "Message category", "tripe.cat",
331 FT_UINT8, BASE_HEX, 0, MSG_CATMASK
333 { &hf_tripe_packet_type, {
334 "Packet message type", "tripe.packet.type",
335 FT_UINT8, BASE_HEX, 0, MSG_TYPEMASK,
336 "This is the TrIPE packet type subcode."
339 "Encrypted ciphertext", "tripe.ct",
340 FT_BYTES, BASE_NONE, 0, 0,
341 "This is an encrypted message."
343 { &hf_tripe_ct_seq, {
344 "Ciphertext sequence number", "tripe.ct.seq",
345 FT_UINT32, BASE_DEC, 0, 0,
346 "This is the unique sequence number for the ciphertext."
349 "Ciphertext initialization vector", "tripe.ct.iv",
350 FT_BYTES, BASE_NONE, 0, 0,
351 "This is the initialization vector used for the actual encryption."
354 "Actual encrypted data", "tripe.ct.ct",
355 FT_BYTES, BASE_NONE, 0, 0,
356 "This is the encrypted message. Reading it ought to be hard."
358 { &hf_tripe_ct_tag, {
359 "Message authentication code", "tripe.ct.tag",
360 FT_BYTES, BASE_NONE, 0, 0,
361 "This is the message authentication code tag for the ciphertext."
363 { &hf_tripe_misc_type, {
364 "Miscellaneous message type", "tripe.misc.type",
365 FT_UINT8, BASE_HEX, 0, MSG_TYPEMASK,
366 "This is the TrIPE miscellaneous message type subcode."
368 { &hf_tripe_misc_payload, {
369 "Miscellaneous message type", "tripe.misc.payload",
370 FT_BYTES, BASE_NONE, 0, 0,
371 "This is the miscellaneous message payload."
373 { &hf_tripe_kx_type, {
374 "Key-exchange message type", "tripe.kx.type",
375 FT_UINT8, BASE_HEX, vs_kxtype, MSG_TYPEMASK,
376 "This is the TrIPE key-exchange type subcode."
378 { &hf_tripe_kx_mychal.hf, {
379 "Sender's challenge data", "tripe.kx.mychal",
380 FT_BYTES, BASE_NONE, 0, 0,
381 "This is the sender's challenge."
383 { &hf_tripe_kx_mychal.hf_len, {
384 "Challenge length", "tripe.kx.mychal.len",
385 FT_UINT16, BASE_DEC, 0, 0,
386 "This is the length of the sender's challenge."
388 { &hf_tripe_kx_mychal.hf_val, {
389 "Challenge", "tripe.kx.mychal.val",
390 FT_BYTES, BASE_NONE, 0, 0,
391 "This is the value of the sender's challenge."
393 { &hf_tripe_kx_mychal.hfx_len, {
394 "Challenge x length", "tripe.kx.mychal.x.len",
395 FT_UINT16, BASE_DEC, 0, 0,
396 "This is the length of the sender's challenge x-coordinate."
398 { &hf_tripe_kx_mychal.hfy_val, {
399 "Challenge x value", "tripe.kx.mychal.x.val",
400 FT_BYTES, BASE_NONE, 0, 0,
401 "This is the value of the sender's challenge x-coordinate."
403 { &hf_tripe_kx_mychal.hfy_len, {
404 "Challenge y length", "tripe.kx.mychal.y.len",
405 FT_UINT16, BASE_DEC, 0, 0,
406 "This is the length of the sender's challenge x-coordinate."
408 { &hf_tripe_kx_mychal.hfx_val, {
409 "Challenge y value", "tripe.kx.mychal.y.val",
410 FT_BYTES, BASE_NONE, 0, 0,
411 "This is the value of the sender's challenge x-coordinate."
413 { &hf_tripe_kx_mycookie, {
414 "Sender's hashed cookie", "tripe.kx.mycookie",
415 FT_BYTES, BASE_NONE, 0, 0,
416 "This is the hash of the sender's challenge."
418 { &hf_tripe_kx_yourcookie, {
419 "Recipient's hashed cookie", "tripe.kx.yourcookie",
420 FT_BYTES, BASE_NONE, 0, 0,
421 "This is the hash of the recipient's challenge."
423 { &hf_tripe_kx_check.hf, {
424 "Challenge check-value", "tripe.kx.check",
425 FT_BYTES, BASE_NONE, 0, 0,
426 "This is an encrypted check-value which proves that the sender "
427 "knows the answer to the challenge, and that it is therefore honest."
429 { &hf_tripe_kx_check.hf_len, {
430 "Check-value length", "tripe.kx.check.len",
431 FT_UINT16, BASE_DEC, 0, 0,
432 "This is the length of the encrypted check-value."
434 { &hf_tripe_kx_check.hf_val, {
435 "Check-value data", "tripe.kx.check.val",
436 FT_BYTES, BASE_NONE, 0, 0,
437 "This is the actual encrypted check-value."
440 "Unknown data", "tripe.huh",
441 FT_BYTES, BASE_NONE, 0, 0,
442 "I don't know what's meant to appear here."
446 static gint *tts[] = {
449 &hf_tripe_kx_mychal.tt,
450 &hf_tripe_kx_check.tt,
453 proto_tripe = proto_register_protocol("TrIPE", "TrIPE", "tripe");
454 proto_register_field_array(proto_tripe, hfs, array_length(hfs));
455 proto_register_subtree_array(tts, array_length(tts));
457 mod = prefs_register_protocol(proto_tripe, prefcb);
458 prefs_register_uint_preference(mod, "hashsz", "Hash length",
459 "hash function output length (in octets)",
461 prefs_register_uint_preference(mod, "tagsz", "MAC tag length",
462 "MAC tag length (in octets)", 10, &tagsz);
463 prefs_register_uint_preference(mod, "ivsz", "IV length",
464 "block cipher initialization vector length"
469 void proto_reg_handoff_tripe(void)
471 dissector_handle_t dh;
473 dh = create_dissector_handle(dissect_tripe, proto_tripe);
474 dissector_add("udp.port", 22003, dh);
477 G_MODULE_EXPORT void plugin_reg_handoff(void)
479 proto_reg_handoff_tripe();
482 G_MODULE_EXPORT void plugin_register(void)
484 if (proto_tripe == -1)
485 proto_register_tripe();
488 /*----- That's all, folks -------------------------------------------------*/