2 * Routines for RFC2630 Cryptographic Message Syntax 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-cms.h"
39 #include "packet-x509af.h"
40 #include "packet-x509if.h"
42 #include <epan/sha1.h>
43 #include <epan/crypt-md5.h>
45 #define PNAME "Cryptographic Message Syntax"
49 /* Initialize the protocol and registered fields */
51 static int hf_cms_ci_contentType = -1;
52 #include "packet-cms-hf.c"
54 /* Initialize the subtree pointers */
55 #include "packet-cms-ett.c"
57 static int dissect_cms_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) ; /* XXX kill a compiler warning until asn2eth stops generating these silly wrappers */
60 static const char *object_identifier_id;
61 static tvbuff_t *content_tvb = NULL;
63 static proto_tree *top_tree=NULL;
65 #define HASH_SHA1 "1.3.14.3.2.26"
66 #define SHA1_BUFFER_SIZE 20
68 #define HASH_MD5 "1.2.840.113549.2.5"
69 #define MD5_BUFFER_SIZE 16
73 #define HASH_SHA224 "2.16.840.1.101.3.4.2.4"
74 #define SHA224_BUFFER_SIZE 32 /* actually 28 */
75 #define HASH_SHA256 "2.16.840.1.101.3.4.2.1"
76 #define SHA256_BUFFER_SIZE 32
78 unsigned char digest_buf[MAX(SHA1_BUFFER_SIZE, MD5_BUFFER_SIZE)];
81 cms_verify_msg_digest(proto_item *pi, tvbuff_t *content, const char *alg, tvbuff_t *tvb, int offset)
83 sha1_context sha1_ctx;
85 int i= 0, buffer_size = 0;
87 /* we only support two algorithms at the moment - if we do add SHA2
88 we should add a registration process to use a registration process */
90 if(strcmp(alg, HASH_SHA1) == 0) {
92 sha1_starts(&sha1_ctx);
94 sha1_update(&sha1_ctx, tvb_get_ptr(content, 0, tvb_length(content)),
97 sha1_finish(&sha1_ctx, digest_buf);
99 buffer_size = SHA1_BUFFER_SIZE;
101 } else if(strcmp(alg, HASH_MD5) == 0) {
105 md5_append(&md5_ctx, tvb_get_ptr(content, 0, tvb_length(content)),
106 tvb_length(content));
108 md5_finish(&md5_ctx, digest_buf);
110 buffer_size = MD5_BUFFER_SIZE;
114 /* compare our computed hash with what we have received */
116 if(tvb_bytes_exist(tvb, offset, buffer_size) &&
117 (memcmp(tvb_get_ptr(tvb, offset, buffer_size), digest_buf, buffer_size) != 0)) {
118 proto_item_append_text(pi, " [incorrect, should be ");
119 for(i = 0; i < buffer_size; i++)
120 proto_item_append_text(pi, "%02X", digest_buf[i]);
122 proto_item_append_text(pi, "]");
125 proto_item_append_text(pi, " [correct]");
127 proto_item_append_text(pi, " [unable to verify]");
132 #include "packet-cms-fn.c"
134 /*--- proto_register_cms ----------------------------------------------*/
135 void proto_register_cms(void) {
138 static hf_register_info hf[] = {
139 { &hf_cms_ci_contentType,
140 { "contentType", "cms.contentInfo.contentType",
141 FT_OID, BASE_NONE, NULL, 0,
142 "ContentType", HFILL }},
143 #include "packet-cms-hfarr.c"
146 /* List of subtrees */
147 static gint *ett[] = {
148 #include "packet-cms-ettarr.c"
151 /* Register protocol */
152 proto_cms = proto_register_protocol(PNAME, PSNAME, PFNAME);
154 /* Register fields and subtrees */
155 proto_register_field_array(proto_cms, hf, array_length(hf));
156 proto_register_subtree_array(ett, array_length(ett));
161 /*--- proto_reg_handoff_cms -------------------------------------------*/
162 void proto_reg_handoff_cms(void) {
163 #include "packet-cms-dis-tab.c"