3 * $Id: packet-tripe.c,v 1.4 2004/04/18 18:08:11 mdw Exp $
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 <epan/packet.h>
44 #ifdef ETHEREAL_BUGGERED
45 # define plugin_address_table_t void
46 # define plugin_address_table_init(x)
48 # include <plugins/plugin_api.h>
51 #include "tripe-protocol.h"
53 /*----- Static variables --------------------------------------------------*/
55 static int proto_tripe
= -1;
57 static guint hashsz
= 20, tagsz
= 10, ivsz
= 8;
60 int hf
, hf_len
, hf_val
, tt
;
63 int hf
, hf_len
, hf_val
, hfx_len
, hfx_val
, hfy_len
, hfy_val
, tt
;
66 static int hf_tripe_cat
= -1;
67 static int hf_tripe_packet_type
= -1;
68 static int hf_tripe_ct
= -1;
69 static int hf_tripe_ct_seq
= -1;
70 static int hf_tripe_ct_iv
= -1;
71 static int hf_tripe_ct_ct
= -1;
72 static int hf_tripe_ct_tag
= -1;
73 static int hf_tripe_kx_type
= -1;
74 static hfge hf_tripe_kx_mychal
= { -1, -1, -1, -1, -1, -1, -1, -1 };
75 static int hf_tripe_kx_mycookie
= -1;
76 static int hf_tripe_kx_yourcookie
= -1;
77 static hfmp hf_tripe_kx_check
= { -1, -1, -1, -1 };
78 static int hf_tripe_huh
= -1;
80 static int tt_tripe
= -1;
81 static int tt_tripe_ct
= -1;
83 G_MODULE_EXPORT
const gchar version
[] = VERSION
;
85 /*----- Main code ---------------------------------------------------------*/
87 static void prefcb(void) { }
89 static gint
gethash(proto_tree
*tt
, int hf
, tvbuff_t
*b
, gint off
)
91 proto_tree_add_item(tt
, hf
, b
, off
, hashsz
, FALSE
);
92 return (off
+ hashsz
);
95 static gint
getmp(proto_tree
*tt
, const hfmp
*hf
, tvbuff_t
*b
, gint off
)
97 guint16 len
= tvb_get_ntohs(b
, off
);
98 proto_item
*ti
= proto_tree_add_item(tt
, hf
->hf
, b
, off
, len
+ 2, FALSE
);
99 tt
= proto_item_add_subtree(ti
, hf
->tt
);
100 proto_tree_add_item(tt
, hf
->hf_len
, b
, off
, 2, FALSE
);
101 proto_tree_add_item(tt
, hf
->hf_val
, b
, off
+ 2, len
, FALSE
);
102 return (off
+ 2 + len
);
105 static gint
getge(proto_tree
*tt
, const hfge
*hf
, tvbuff_t
*b
, gint off
)
107 guint16 len
= tvb_get_ntohs(b
, off
), len2
;
110 r
= tvb_length_remaining(b
, off
);
112 (len2
= tvb_get_ntohs(b
, off
+ 2 + len
), r
< 4 + len
+ len2
)) {
113 ti
= proto_tree_add_item(tt
, hf
->hf
, b
, off
, len
+ 2, FALSE
);
114 tt
= proto_item_add_subtree(ti
, hf
->tt
);
115 proto_tree_add_item(tt
, hf
->hf_len
, b
, off
, 2, FALSE
);
116 proto_tree_add_item(tt
, hf
->hf_val
, b
, off
+ 2, len
, FALSE
);
119 ti
= proto_tree_add_item(tt
, hf
->hf
, b
, off
, len
+ len2
+ 4, FALSE
);
120 tt
= proto_item_add_subtree(ti
, hf
->tt
);
121 proto_tree_add_item(tt
, hf
->hfx_len
, b
, off
, 2, FALSE
);
122 proto_tree_add_item(tt
, hf
->hfx_val
, b
, off
+ 2, len
, FALSE
);
123 proto_tree_add_item(tt
, hf
->hfy_len
, b
, off
+ 2 + len
, 2, FALSE
);
124 proto_tree_add_item(tt
, hf
->hfy_val
, b
, off
+ 4 + len
, len2
, FALSE
);
125 r
= off
+ len
+ len2
+ 4;
130 static void dissect_tripe(tvbuff_t
*b
, packet_info
*p
, proto_tree
*t
)
135 gint off
= tvb_raw_offset(b
);
138 /* --- Initialize the summary cells --- */
140 if (check_col(p
->cinfo
, COL_PROTOCOL
))
141 col_set_str(p
->cinfo
, COL_PROTOCOL
, "TrIPE");
142 ty
= tvb_get_guint8(b
, 0);
143 if (check_col(p
->cinfo
, COL_INFO
)) {
144 col_clear(p
->cinfo
, COL_INFO
);
145 switch (ty
& MSG_CATMASK
) {
147 switch (ty
& MSG_TYPEMASK
) {
149 col_set_str(p
->cinfo
, COL_INFO
, "Packet data");
152 col_add_fstr(p
->cinfo
, COL_INFO
,
153 "Packet data, unknown type code %u",
159 switch (ty
& MSG_TYPEMASK
) {
161 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, prechallenge");
164 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, cookie");
167 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, challenge");
170 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, reply");
173 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, switch request");
176 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, switch response");
179 col_add_fstr(p
->cinfo
, COL_INFO
,
180 "Key exchange, unknown type code %u",
186 col_add_fstr(p
->cinfo
, COL_INFO
,
187 "Unknown category code %u, unknown type code %u",
188 ty
& MSG_CATMASK
, ty
& MSG_TYPEMASK
);
193 /* --- Fill in the tree --- */
196 ti
= proto_tree_add_item(t
, proto_tripe
, b
, 0, -1, FALSE
);
197 tt
= proto_item_add_subtree(ti
, tt_tripe
);
199 proto_tree_add_item(tt
, hf_tripe_cat
, b
, 0, 1, FALSE
);
202 switch (ty
& MSG_CATMASK
) {
204 proto_tree_add_item(tt
, hf_tripe_packet_type
, b
, 0, 1, FALSE
);
205 switch (ty
& MSG_TYPEMASK
) {
213 proto_tree_add_item(tt
, hf_tripe_kx_type
, b
, 0, 1, FALSE
);
214 switch (ty
& MSG_TYPEMASK
) {
216 off
= getge(tt
, &hf_tripe_kx_mychal
, b
, off
);
219 off
= getge(tt
, &hf_tripe_kx_mychal
, b
, off
);
220 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
223 off
= getge(tt
, &hf_tripe_kx_mychal
, b
, off
);
224 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
225 off
= getmp(tt
, &hf_tripe_kx_check
, b
, off
);
228 off
= gethash(tt
, hf_tripe_kx_mycookie
, b
, off
);
229 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
230 off
= getmp(tt
, &hf_tripe_kx_check
, b
, off
);
233 off
= gethash(tt
, hf_tripe_kx_mycookie
, b
, off
);
234 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
246 if (tvb_offset_exists(b
, off
))
250 proto_tree_add_item(tt
, hf_tripe_huh
, b
, off
, -1, FALSE
);
253 ti
= proto_tree_add_item(tt
, hf_tripe_ct
, b
, off
, -1, FALSE
);
254 seq
= tvb_get_ntohl(b
, off
+ tagsz
);
255 proto_item_set_text(ti
, "Encrypted ciphertext (sequence number %lu)",
257 tt
= proto_item_add_subtree(ti
, tt_tripe_ct
);
259 proto_tree_add_item(tt
, hf_tripe_ct_tag
, b
, off
, tagsz
, FALSE
);
262 proto_tree_add_item(tt
, hf_tripe_ct_seq
, b
, off
, 4, FALSE
);
265 proto_tree_add_item(tt
, hf_tripe_ct_iv
, b
, off
, ivsz
, FALSE
);
268 proto_tree_add_item(ti
, hf_tripe_ct_ct
, b
, off
, -1, FALSE
);
274 void proto_register_tripe(void)
278 static value_string vs_kxtype
[] = {
279 { KX_PRECHAL
, "KX_PRECHAL (prechallenge)" },
280 { KX_COOKIE
, "KX_COOKIE (cookie)" },
281 { KX_CHAL
, "KX_CHAL (challenge)" },
282 { KX_REPLY
, "KX_REPLY (reply)" },
283 { KX_SWITCH
, "KX_SWITCH (switch request)" },
284 { KX_SWITCHOK
, "KX_SWITCHOK (switch response)" },
288 static hf_register_info hfs
[] = {
290 "Message category", "tripe.cat",
291 FT_UINT8
, BASE_HEX
, 0, MSG_CATMASK
293 &hf_tripe_packet_type
, {
294 "Packet message type", "tripe.packet.type",
295 FT_UINT8
, BASE_HEX
, 0, MSG_TYPEMASK
,
296 "This is the TrIPE packet type subcode."
299 "Encrypted ciphertext", "tripe.ct",
300 FT_BYTES
, BASE_NONE
, 0, 0,
301 "This is an encrypted message."
304 "Ciphertext sequence number", "tripe.ct.seq",
305 FT_UINT32
, BASE_DEC
, 0, 0,
306 "This is the unique sequence number for the ciphertext."
309 "Ciphertext initialization vector", "tripe.ct.iv",
310 FT_BYTES
, BASE_NONE
, 0, 0,
311 "This is the initialization vector used for the actual encryption."
314 "Actual encrypted data", "tripe.ct.ct",
315 FT_BYTES
, BASE_NONE
, 0, 0,
316 "This is the encrypted message. Reading it ought to be hard."
319 "Message authentication code", "tripe.ct.tag",
320 FT_BYTES
, BASE_NONE
, 0, 0,
321 "This is the message authentication code tag for the ciphertext."
324 "Key-exchange message type", "tripe.kx.type",
325 FT_UINT8
, BASE_HEX
, vs_kxtype
, MSG_TYPEMASK
,
326 "This is the TrIPE key-exchange type subcode."
328 &hf_tripe_kx_mychal
.hf
, {
329 "Sender's challenge data", "tripe.kx.mychal",
330 FT_BYTES
, BASE_NONE
, 0, 0,
331 "This is the sender's challenge."
333 &hf_tripe_kx_mychal
.hf_len
, {
334 "Challenge length", "tripe.kx.mychal.len",
335 FT_UINT16
, BASE_DEC
, 0, 0,
336 "This is the length of the sender's challenge."
338 &hf_tripe_kx_mychal
.hf_val
, {
339 "Challenge", "tripe.kx.mychal.val",
340 FT_BYTES
, BASE_NONE
, 0, 0,
341 "This is the value of the sender's challenge."
343 &hf_tripe_kx_mychal
.hfx_len
, {
344 "Challenge x length", "tripe.kx.mychal.x.len",
345 FT_UINT16
, BASE_DEC
, 0, 0,
346 "This is the length of the sender's challenge x-coordinate."
348 &hf_tripe_kx_mychal
.hfy_val
, {
349 "Challenge x value", "tripe.kx.mychal.x.val",
350 FT_BYTES
, BASE_NONE
, 0, 0,
351 "This is the value of the sender's challenge x-coordinate."
353 &hf_tripe_kx_mychal
.hfy_len
, {
354 "Challenge y length", "tripe.kx.mychal.y.len",
355 FT_UINT16
, BASE_DEC
, 0, 0,
356 "This is the length of the sender's challenge x-coordinate."
358 &hf_tripe_kx_mychal
.hfx_val
, {
359 "Challenge y value", "tripe.kx.mychal.y.val",
360 FT_BYTES
, BASE_NONE
, 0, 0,
361 "This is the value of the sender's challenge x-coordinate."
363 &hf_tripe_kx_mycookie
, {
364 "Sender's hashed cookie", "tripe.kx.mycookie",
365 FT_BYTES
, BASE_NONE
, 0, 0,
366 "This is the hash of the sender's challenge."
368 &hf_tripe_kx_yourcookie
, {
369 "Recipient's hashed cookie", "tripe.kx.yourcookie",
370 FT_BYTES
, BASE_NONE
, 0, 0,
371 "This is the hash of the recipient's challenge."
373 &hf_tripe_kx_check
.hf
, {
374 "Challenge check-value", "tripe.kx.check",
375 FT_BYTES
, BASE_NONE
, 0, 0,
376 "This is an encrypted check-value which proves that the sender "
377 "knows the answer to the challenge, and that it is therefore honest."
379 &hf_tripe_kx_check
.hf_len
, {
380 "Check-value length", "tripe.kx.check.len",
381 FT_UINT16
, BASE_DEC
, 0, 0,
382 "This is the length of the encrypted check-value."
384 &hf_tripe_kx_check
.hf_val
, {
385 "Check-value data", "tripe.kx.check.val",
386 FT_BYTES
, BASE_NONE
, 0, 0,
387 "This is the actual encrypted check-value."
390 "Unknown data", "tripe.huh",
391 FT_BYTES
, BASE_NONE
, 0, 0,
392 "I don't know what's meant to appear here."
396 static gint
*tts
[] = {
399 &hf_tripe_kx_mychal
.tt
,
400 &hf_tripe_kx_check
.tt
,
403 proto_tripe
= proto_register_protocol("TrIPE", "TrIPE", "tripe");
404 proto_register_field_array(proto_tripe
, hfs
, array_length(hfs
));
405 proto_register_subtree_array(tts
, array_length(tts
));
407 mod
= prefs_register_protocol(proto_tripe
, prefcb
);
408 prefs_register_uint_preference(mod
, "hashsz", "Hash length",
409 "hash function output length (in octets)",
411 prefs_register_uint_preference(mod
, "tagsz", "MAC tag length",
412 "MAC tag length (in octets)", 10, &tagsz
);
413 prefs_register_uint_preference(mod
, "ivsz", "IV length",
414 "block cipher initialization vector length"
419 void proto_reg_handoff_tripe(void)
421 dissector_handle_t dh
;
423 dh
= create_dissector_handle(dissect_tripe
, proto_tripe
);
424 dissector_add("udp.port", 22003, dh
);
427 G_MODULE_EXPORT
void plugin_reg_handoff(void)
429 proto_reg_handoff_tripe();
432 G_MODULE_EXPORT
void plugin_init(plugin_address_table_t
*pat
)
434 plugin_address_table_init(pat
);
435 if (proto_tripe
== -1)
436 proto_register_tripe();
439 /*----- That's all, folks -------------------------------------------------*/