2 * Routines for RFC2510 Certificate Management Protocol packet dissection
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
32 #include <epan/conversation.h>
37 #include "packet-ber.h"
38 #include "packet-cmp.h"
39 #include "packet-crmf.h"
40 #include "packet-pkix1explicit.h"
41 #include "packet-pkix1implicit.h"
42 #include "packet-tcp.h"
43 #include <epan/prefs.h>
44 #include <epan/nstime.h>
46 #define PNAME "Certificate Management Protocol"
50 #define TCP_PORT_CMP 829
52 /* desegmentation of CMP over TCP */
53 static gboolean cmp_desegment = TRUE;
55 /* Initialize the protocol and registered fields */
57 static int hf_cmp_type_oid = -1;
58 static int hf_cmp_rm = -1;
59 static int hf_cmp_type = -1;
60 static int hf_cmp_poll_ref = -1;
61 static int hf_cmp_next_poll_ref = -1;
62 static int hf_cmp_ttcb = -1;
63 #include "packet-cmp-hf.c"
65 /* Initialize the subtree pointers */
66 static gint ett_cmp = -1;
67 #include "packet-cmp-ett.c"
69 static const char *object_identifier_id;
72 #include "packet-cmp-fn.c"
75 dissect_cmp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
77 return dissect_cmp_PKIMessage(FALSE, tvb, 0, pinfo, tree, -1);
80 #define CMP_TYPE_PKIMSG 0
81 #define CMP_TYPE_POLLREP 1
82 #define CMP_TYPE_POLLREQ 2
83 #define CMP_TYPE_NEGPOLLREP 3
84 #define CMP_TYPE_PARTIALMSGREP 4
85 #define CMP_TYPE_FINALMSGREP 5
86 #define CMP_TYPE_ERRORMSGREP 6
87 static const value_string cmp_pdu_types[] = {
88 { CMP_TYPE_PKIMSG, "pkiMsg" },
89 { CMP_TYPE_POLLREP, "pollRep" },
90 { CMP_TYPE_POLLREQ, "pollReq" },
91 { CMP_TYPE_NEGPOLLREP, "negPollRep" },
92 { CMP_TYPE_PARTIALMSGREP, "partialMsgRep" },
93 { CMP_TYPE_FINALMSGREP, "finalMsgRep" },
94 { CMP_TYPE_ERRORMSGREP, "errorMsgRep" },
98 static void dissect_cmp_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
105 proto_item *item=NULL;
106 proto_tree *tree=NULL;
108 if (check_col(pinfo->cinfo, COL_PROTOCOL))
109 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMP");
111 if (check_col(pinfo->cinfo, COL_INFO)) {
112 col_clear(pinfo->cinfo, COL_INFO);
114 col_add_fstr(pinfo->cinfo, COL_INFO, "PKIXCMP");
119 item=proto_tree_add_item(parent_tree, proto_cmp, tvb, 0, -1, FALSE);
120 tree = proto_item_add_subtree(item, ett_cmp);
123 pdu_len=tvb_get_ntohl(tvb, 0);
124 pdu_type=tvb_get_guint8(tvb, 4);
126 proto_tree_add_uint(tree, hf_cmp_rm, tvb, 0, 4, pdu_len);
127 proto_tree_add_uint(tree, hf_cmp_type, tvb, 4, 1, pdu_type);
129 if (check_col (pinfo->cinfo, COL_INFO)) {
130 col_set_str (pinfo->cinfo, COL_INFO, val_to_str (pdu_type, cmp_pdu_types, "0x%x"));
134 case CMP_TYPE_PKIMSG:
135 next_tvb = tvb_new_subset(tvb, 5, tvb_length_remaining(tvb, 5), pdu_len);
136 dissect_cmp_pdu(next_tvb, pinfo, tree);
138 case CMP_TYPE_POLLREP:
139 proto_tree_add_item(tree, hf_cmp_poll_ref, tvb, 0, 4, FALSE);
141 ts.secs = tvb_get_ntohl(tvb, 4);
143 proto_tree_add_time(tree, hf_cmp_ttcb, tvb, 4, 4, &ts);
145 case CMP_TYPE_POLLREQ:
146 proto_tree_add_item(tree, hf_cmp_poll_ref, tvb, 0, 4, FALSE);
148 case CMP_TYPE_NEGPOLLREP:
150 case CMP_TYPE_PARTIALMSGREP:
151 proto_tree_add_item(tree, hf_cmp_next_poll_ref, tvb, 0, 4, FALSE);
153 ts.secs = tvb_get_ntohl(tvb, 4);
155 proto_tree_add_time(tree, hf_cmp_ttcb, tvb, 4, 4, &ts);
157 next_tvb = tvb_new_subset(tvb, 13, tvb_length_remaining(tvb, 13), pdu_len);
158 dissect_cmp_pdu(next_tvb, pinfo, tree);
160 case CMP_TYPE_FINALMSGREP:
161 next_tvb = tvb_new_subset(tvb, 5, tvb_length_remaining(tvb, 5), pdu_len);
162 dissect_cmp_pdu(next_tvb, pinfo, tree);
164 case CMP_TYPE_ERRORMSGREP:
171 static guint get_cmp_pdu_len(tvbuff_t *tvb, int offset)
176 * Get the length of the CMP-over-TCP packet.
178 plen = tvb_get_ntohl(tvb, offset);
183 /* CMP over TCP RFC2510 section 5.2 */
185 dissect_cmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
190 /* only attempt to dissect it as CMP over TCP if we have
193 if (!tvb_bytes_exist(tvb, 0, 5)) {
197 pdu_len=tvb_get_ntohl(tvb, 0);
198 pdu_type=tvb_get_guint8(tvb, 4);
200 /* arbitrary limit: assume a CMP over TCP pdu is never >10000 bytes
202 * It is definitely at least 1 byte to accomodate the flags byte
204 if((pdu_len<=0)||(pdu_len>10000)){
207 /* type is between 0 and 6 */
211 /* type 0 contains a PKI message and must therefore be >= 3 bytes
212 * long (flags + BER TAG + BER LENGTH
214 if((pdu_type==0)&&(pdu_len<3)){
218 tcp_dissect_pdus(tvb, pinfo, parent_tree, cmp_desegment, 4, get_cmp_pdu_len,
219 dissect_cmp_tcp_pdu);
221 return tvb_length(tvb);
225 dissect_cmp_http(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
227 proto_item *item=NULL;
228 proto_tree *tree=NULL;
230 if (check_col(pinfo->cinfo, COL_PROTOCOL))
231 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMP");
233 if (check_col(pinfo->cinfo, COL_INFO)) {
234 col_clear(pinfo->cinfo, COL_INFO);
236 col_add_fstr(pinfo->cinfo, COL_INFO, "PKIXCMP");
241 item=proto_tree_add_item(parent_tree, proto_cmp, tvb, 0, -1, FALSE);
242 tree = proto_item_add_subtree(item, ett_cmp);
245 dissect_cmp_pdu(tvb, pinfo, tree);
249 /*--- proto_register_cmp ----------------------------------------------*/
250 void proto_register_cmp(void) {
253 static hf_register_info hf[] = {
255 { "InfoType", "cmp.type.oid",
256 FT_STRING, BASE_NONE, NULL, 0,
257 "Type of InfoTypeAndValue", HFILL }},
259 { "Record Marker", "cmp.rm",
260 FT_UINT32, BASE_DEC, NULL, 0,
261 "Record Marker length of PDU in bytes", HFILL }},
263 { "Type", "cmp.type",
264 FT_UINT8, BASE_DEC, VALS(cmp_pdu_types), 0,
265 "PDU Type", HFILL }},
267 { "Polling Reference", "cmp.poll_ref",
268 FT_UINT32, BASE_HEX, NULL, 0,
270 { &hf_cmp_next_poll_ref,
271 { "Next Polling Reference", "cmp.next_poll_ref",
272 FT_UINT32, BASE_HEX, NULL, 0,
275 { "Time to check Back", "cmp.ttcb",
276 FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0,
278 #include "packet-cmp-hfarr.c"
281 /* List of subtrees */
282 static gint *ett[] = {
284 #include "packet-cmp-ettarr.c"
286 module_t *cmp_module;
288 /* Register protocol */
289 proto_cmp = proto_register_protocol(PNAME, PSNAME, PFNAME);
291 /* Register fields and subtrees */
292 proto_register_field_array(proto_cmp, hf, array_length(hf));
293 proto_register_subtree_array(ett, array_length(ett));
295 cmp_module = prefs_register_protocol(proto_cmp, NULL);
296 prefs_register_bool_preference(cmp_module, "desegment",
297 "Reassemble CMP-over-TCP messages spanning multiple TCP segments",
298 "Whether the CMP-over-TCP dissector should reassemble messages spanning multiple TCP segments. "
299 "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
304 /*--- proto_reg_handoff_cmp -------------------------------------------*/
305 void proto_reg_handoff_cmp(void) {
306 dissector_handle_t cmp_http_handle;
307 dissector_handle_t cmp_tcp_handle;
309 cmp_http_handle = new_create_dissector_handle(dissect_cmp_http, proto_cmp);
310 dissector_add_string("media_type", "application/pkixcmp", cmp_http_handle);
312 cmp_tcp_handle = new_create_dissector_handle(dissect_cmp_tcp, proto_cmp);
313 dissector_add("tcp.port", TCP_PORT_CMP, cmp_tcp_handle);
315 /*#include "packet-cmp-dis-tab.c"*/