2 * Routines for RFC2630 Cryptographic Message Syntax packet dissection
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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>
33 #include <epan/oids.h>
34 #include <epan/asn1.h>
39 #include "packet-ber.h"
40 #include "packet-cms.h"
41 #include "packet-x509af.h"
42 #include "packet-x509if.h"
43 #include "packet-pkcs12.h"
45 #include <epan/crypt/crypt-sha1.h>
46 #include <epan/crypt/crypt-md5.h>
48 #define PNAME "Cryptographic Message Syntax"
52 /* Initialize the protocol and registered fields */
54 static int hf_cms_ci_contentType = -1;
55 #include "packet-cms-hf.c"
57 /* Initialize the subtree pointers */
58 #include "packet-cms-ett.c"
60 static int dissect_cms_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_) ; /* XXX kill a compiler warning until asn2wrs stops generating these silly wrappers */
63 static const char *object_identifier_id;
64 static tvbuff_t *content_tvb = NULL;
66 static proto_tree *top_tree=NULL;
67 static proto_tree *cap_tree=NULL;
69 #define HASH_SHA1 "1.3.14.3.2.26"
70 #define SHA1_BUFFER_SIZE 20
72 #define HASH_MD5 "1.2.840.113549.2.5"
73 #define MD5_BUFFER_SIZE 16
77 #define HASH_SHA224 "2.16.840.1.101.3.4.2.4"
78 #define SHA224_BUFFER_SIZE 32 /* actually 28 */
79 #define HASH_SHA256 "2.16.840.1.101.3.4.2.1"
80 #define SHA256_BUFFER_SIZE 32
82 unsigned char digest_buf[MAX(SHA1_BUFFER_SIZE, MD5_BUFFER_SIZE)];
85 cms_verify_msg_digest(proto_item *pi, tvbuff_t *content, const char *alg, tvbuff_t *tvb, int offset)
87 sha1_context sha1_ctx;
89 int i= 0, buffer_size = 0;
91 /* we only support two algorithms at the moment - if we do add SHA2
92 we should add a registration process to use a registration process */
94 if(strcmp(alg, HASH_SHA1) == 0) {
96 sha1_starts(&sha1_ctx);
98 sha1_update(&sha1_ctx, tvb_get_ptr(content, 0, tvb_length(content)),
101 sha1_finish(&sha1_ctx, digest_buf);
103 buffer_size = SHA1_BUFFER_SIZE;
105 } else if(strcmp(alg, HASH_MD5) == 0) {
109 md5_append(&md5_ctx, tvb_get_ptr(content, 0, tvb_length(content)),
110 tvb_length(content));
112 md5_finish(&md5_ctx, digest_buf);
114 buffer_size = MD5_BUFFER_SIZE;
118 /* compare our computed hash with what we have received */
120 if(tvb_bytes_exist(tvb, offset, buffer_size) &&
121 (memcmp(tvb_get_ptr(tvb, offset, buffer_size), digest_buf, buffer_size) != 0)) {
122 proto_item_append_text(pi, " [incorrect, should be ");
123 for(i = 0; i < buffer_size; i++)
124 proto_item_append_text(pi, "%02X", digest_buf[i]);
126 proto_item_append_text(pi, "]");
129 proto_item_append_text(pi, " [correct]");
131 proto_item_append_text(pi, " [unable to verify]");
136 #include "packet-cms-fn.c"
138 /*--- proto_register_cms ----------------------------------------------*/
139 void proto_register_cms(void) {
142 static hf_register_info hf[] = {
143 { &hf_cms_ci_contentType,
144 { "contentType", "cms.contentInfo.contentType",
145 FT_OID, BASE_NONE, NULL, 0,
146 "ContentType", HFILL }},
147 #include "packet-cms-hfarr.c"
150 /* List of subtrees */
151 static gint *ett[] = {
152 #include "packet-cms-ettarr.c"
155 /* Register protocol */
156 proto_cms = proto_register_protocol(PNAME, PSNAME, PFNAME);
158 /* Register fields and subtrees */
159 proto_register_field_array(proto_cms, hf, array_length(hf));
160 proto_register_subtree_array(ett, array_length(ett));
162 register_ber_syntax_dissector("ContentInfo", proto_cms, dissect_ContentInfo_PDU);
163 register_ber_oid_syntax(".p7s", NULL, "ContentInfo");
164 register_ber_oid_syntax(".p7m", NULL, "ContentInfo");
165 register_ber_oid_syntax(".p7c", NULL, "ContentInfo");
171 /*--- proto_reg_handoff_cms -------------------------------------------*/
172 void proto_reg_handoff_cms(void) {
173 #include "packet-cms-dis-tab.c"
175 add_oid_str_name("1.2.840.113549.1.7.1", "id-data");
176 add_oid_str_name("1.2.840.113549.3.7", "id-alg-des-ede3-cbc");
177 add_oid_str_name("1.3.14.3.2.7", "id-alg-des-cbc");