3 * $Id: packet-tripe.c,v 1.2 2004/04/03 12:35:13 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 /*----- Revision history --------------------------------------------------*
31 * $Log: packet-tripe.c,v $
32 * Revision 1.2 2004/04/03 12:35:13 mdw
33 * Support elliptic curve key exchange.
35 * Revision 1.1 2003/10/15 09:30:19 mdw
36 * Add support for Ethereal protocol analysis.
40 /*----- Header files ------------------------------------------------------*/
48 #include <netinet/in.h>
52 #include <epan/packet.h>
54 #ifdef ETHEREAL_BUGGERED
55 # define plugin_address_table_t void
56 # define plugin_address_table_init(x)
58 # include <plugins/plugin_api.h>
61 #include "tripe-protocol.h"
63 /*----- Static variables --------------------------------------------------*/
65 static int proto_tripe
= -1;
68 int hf
, hf_len
, hf_val
, tt
;
71 int hf
, hf_len
, hf_val
, hfx_len
, hfx_val
, hfy_len
, hfy_val
, tt
;
74 static int hf_tripe_cat
= -1;
75 static int hf_tripe_packet_type
= -1;
76 static int hf_tripe_ct
= -1;
77 static int hf_tripe_ct_seq
= -1;
78 static int hf_tripe_ct_iv
= -1;
79 static int hf_tripe_ct_cbc
= -1;
80 static int hf_tripe_ct_mac
= -1;
81 static int hf_tripe_kx_type
= -1;
82 static hfge hf_tripe_kx_mychal
= { -1, -1, -1, -1, -1, -1, -1, -1 };
83 static int hf_tripe_kx_mycookie
= -1;
84 static int hf_tripe_kx_yourcookie
= -1;
85 static hfmp hf_tripe_kx_check
= { -1, -1, -1, -1 };
86 static int hf_tripe_huh
= -1;
88 static int tt_tripe
= -1;
89 static int tt_tripe_ct
= -1;
91 G_MODULE_EXPORT
const gchar version
[] = VERSION
;
93 /*----- Main code ---------------------------------------------------------*/
95 static gint
gethash(proto_tree
*tt
, int hf
, tvbuff_t
*b
, gint off
)
97 proto_tree_add_item(tt
, hf
, b
, off
, 20, FALSE
);
101 static gint
getmp(proto_tree
*tt
, const hfmp
*hf
, tvbuff_t
*b
, gint off
)
103 guint16 len
= tvb_get_ntohs(b
, off
);
104 proto_item
*ti
= proto_tree_add_item(tt
, hf
->hf
, b
, off
, len
+ 2, FALSE
);
105 tt
= proto_item_add_subtree(ti
, hf
->tt
);
106 proto_tree_add_item(tt
, hf
->hf_len
, b
, off
, 2, FALSE
);
107 proto_tree_add_item(tt
, hf
->hf_val
, b
, off
+ 2, len
, FALSE
);
108 return (off
+ 2 + len
);
111 static gint
getge(proto_tree
*tt
, const hfge
*hf
, tvbuff_t
*b
, gint off
)
113 guint16 len
= tvb_get_ntohs(b
, off
), len2
;
116 r
= tvb_length_remaining(b
, off
);
118 (len2
= tvb_get_ntohs(b
, off
+ 2 + len
), r
< 4 + len
+ len2
)) {
119 ti
= proto_tree_add_item(tt
, hf
->hf
, b
, off
, len
+ 2, FALSE
);
120 tt
= proto_item_add_subtree(ti
, hf
->tt
);
121 proto_tree_add_item(tt
, hf
->hf_len
, b
, off
, 2, FALSE
);
122 proto_tree_add_item(tt
, hf
->hf_val
, b
, off
+ 2, len
, FALSE
);
125 ti
= proto_tree_add_item(tt
, hf
->hf
, b
, off
, len
+ len2
+ 4, FALSE
);
126 tt
= proto_item_add_subtree(ti
, hf
->tt
);
127 proto_tree_add_item(tt
, hf
->hfx_len
, b
, off
, 2, FALSE
);
128 proto_tree_add_item(tt
, hf
->hfx_val
, b
, off
+ 2, len
, FALSE
);
129 proto_tree_add_item(tt
, hf
->hfy_len
, b
, off
+ 2 + len
, 2, FALSE
);
130 proto_tree_add_item(tt
, hf
->hfy_val
, b
, off
+ 4 + len
, len2
, FALSE
);
131 r
= off
+ len
+ len2
+ 4;
136 static void dissect_tripe(tvbuff_t
*b
, packet_info
*p
, proto_tree
*t
)
141 gint off
= tvb_raw_offset(b
);
144 /* --- Initialize the summary cells --- */
146 if (check_col(p
->cinfo
, COL_PROTOCOL
))
147 col_set_str(p
->cinfo
, COL_PROTOCOL
, "TrIPE");
148 ty
= tvb_get_guint8(b
, 0);
149 if (check_col(p
->cinfo
, COL_INFO
)) {
150 col_clear(p
->cinfo
, COL_INFO
);
151 switch (ty
& MSG_CATMASK
) {
153 switch (ty
& MSG_TYPEMASK
) {
155 col_set_str(p
->cinfo
, COL_INFO
, "Packet data");
158 col_add_fstr(p
->cinfo
, COL_INFO
,
159 "Packet data, unknown type code %u",
165 switch (ty
& MSG_TYPEMASK
) {
167 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, prechallenge");
170 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, cookie");
173 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, challenge");
176 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, reply");
179 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, switch request");
182 col_set_str(p
->cinfo
, COL_INFO
, "Key exchange, switch response");
185 col_add_fstr(p
->cinfo
, COL_INFO
,
186 "Key exchange, unknown type code %u",
192 col_add_fstr(p
->cinfo
, COL_INFO
,
193 "Unknown category code %u, unknown type code %u",
194 ty
& MSG_CATMASK
, ty
& MSG_TYPEMASK
);
199 /* --- Fill in the tree --- */
202 ti
= proto_tree_add_item(t
, proto_tripe
, b
, 0, -1, FALSE
);
203 tt
= proto_item_add_subtree(ti
, tt_tripe
);
205 proto_tree_add_item(tt
, hf_tripe_cat
, b
, 0, 1, FALSE
);
208 switch (ty
& MSG_CATMASK
) {
210 proto_tree_add_item(tt
, hf_tripe_packet_type
, b
, 0, 1, FALSE
);
211 switch (ty
& MSG_TYPEMASK
) {
219 proto_tree_add_item(tt
, hf_tripe_kx_type
, b
, 0, 1, FALSE
);
220 switch (ty
& MSG_TYPEMASK
) {
222 off
= getge(tt
, &hf_tripe_kx_mychal
, b
, off
);
225 off
= getge(tt
, &hf_tripe_kx_mychal
, b
, off
);
226 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
229 off
= getge(tt
, &hf_tripe_kx_mychal
, b
, off
);
230 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
231 off
= getmp(tt
, &hf_tripe_kx_check
, b
, off
);
234 off
= gethash(tt
, hf_tripe_kx_mycookie
, b
, off
);
235 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
236 off
= getmp(tt
, &hf_tripe_kx_check
, b
, off
);
239 off
= gethash(tt
, hf_tripe_kx_mycookie
, b
, off
);
240 off
= gethash(tt
, hf_tripe_kx_yourcookie
, b
, off
);
252 if (tvb_offset_exists(b
, off
))
256 proto_tree_add_item(tt
, hf_tripe_huh
, b
, off
, -1, FALSE
);
259 ti
= proto_tree_add_item(tt
, hf_tripe_ct
, b
, off
, -1, FALSE
);
260 seq
= tvb_get_ntohl(b
, off
+ 10);
261 proto_item_set_text(ti
, "Encrypted ciphertext (sequence number %lu)",
263 tt
= proto_item_add_subtree(ti
, tt_tripe_ct
);
264 proto_tree_add_item(tt
, hf_tripe_ct_mac
, b
, off
, 10, FALSE
);
266 proto_tree_add_item(tt
, hf_tripe_ct_seq
, b
, off
, 4, FALSE
);
268 proto_tree_add_item(tt
, hf_tripe_ct_iv
, b
, off
, 8, FALSE
);
270 proto_tree_add_item(ti
, hf_tripe_ct_cbc
, b
, off
, -1, FALSE
);
276 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 "CBC-encrypted data", "tripe.ct.cbc",
315 FT_BYTES
, BASE_NONE
, 0, 0,
316 "This is the CBC-encrypted message. Reading it ought to be hard."
319 "Message authentication code", "tripe.ct.mac",
320 FT_BYTES
, BASE_NONE
, 0, 0,
321 "This is the message authentication code 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
));
408 void proto_reg_handoff_tripe(void)
410 dissector_handle_t dh
;
412 dh
= create_dissector_handle(dissect_tripe
, proto_tripe
);
413 dissector_add("udp.port", 22003, dh
);
416 G_MODULE_EXPORT
void plugin_reg_handoff(void)
418 proto_reg_handoff_tripe();
421 G_MODULE_EXPORT
void plugin_init(plugin_address_table_t
*pat
)
423 plugin_address_table_init(pat
);
424 if (proto_tripe
== -1)
425 proto_register_tripe();
428 /*----- That's all, folks -------------------------------------------------*/