1 /* Do not modify this file. */
2 /* It is created automatically by the ASN.1 to Wireshark dissector compiler */
4 /* ../../tools/asn2wrs.py -b -p pkcs1 -c pkcs1.cnf -s packet-pkcs1-template PKCS1.asn */
6 /* Input file: packet-pkcs1-template.c */
8 #line 1 "packet-pkcs1-template.c"
10 * Routines for PKCS#1/RFC2313 packet dissection
11 * Ronnie Sahlberg 2004
15 * Wireshark - Network traffic analyzer
16 * By Gerald Combs <gerald@wireshark.org>
17 * Copyright 1998 Gerald Combs
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 #include <epan/packet.h>
40 #include <epan/conversation.h>
41 #include <epan/asn1.h>
46 #include "packet-ber.h"
47 #include "packet-pkcs1.h"
48 #include "packet-x509af.h"
50 #define PNAME "PKCS#1"
51 #define PSNAME "PKCS-1"
52 #define PFNAME "pkcs-1"
54 /* Initialize the protocol and registered fields */
55 static int proto_pkcs1 = -1;
57 /*--- Included file: packet-pkcs1-hf.c ---*/
58 #line 1 "packet-pkcs1-hf.c"
59 static int hf_pkcs1_modulus = -1; /* INTEGER */
60 static int hf_pkcs1_publicExponent = -1; /* INTEGER */
61 static int hf_pkcs1_version = -1; /* Version */
62 static int hf_pkcs1_privateExponent = -1; /* INTEGER */
63 static int hf_pkcs1_prime1 = -1; /* INTEGER */
64 static int hf_pkcs1_prime2 = -1; /* INTEGER */
65 static int hf_pkcs1_exponent1 = -1; /* INTEGER */
66 static int hf_pkcs1_exponent2 = -1; /* INTEGER */
67 static int hf_pkcs1_coefficient = -1; /* INTEGER */
68 static int hf_pkcs1_digestAlgorithm = -1; /* DigestAlgorithmIdentifier */
69 static int hf_pkcs1_digest = -1; /* Digest */
71 /*--- End of included file: packet-pkcs1-hf.c ---*/
72 #line 49 "packet-pkcs1-template.c"
74 /* Initialize the subtree pointers */
76 /*--- Included file: packet-pkcs1-ett.c ---*/
77 #line 1 "packet-pkcs1-ett.c"
78 static gint ett_pkcs1_RSAPublicKey = -1;
79 static gint ett_pkcs1_RSAPrivateKey = -1;
80 static gint ett_pkcs1_DigestInfo = -1;
82 /*--- End of included file: packet-pkcs1-ett.c ---*/
83 #line 52 "packet-pkcs1-template.c"
86 /*--- Included file: packet-pkcs1-fn.c ---*/
87 #line 1 "packet-pkcs1-fn.c"
88 /*--- Fields for imported types ---*/
94 dissect_pkcs1_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
95 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
100 static int dissect_modulus(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
101 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_modulus);
103 static int dissect_publicExponent(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
104 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_publicExponent);
106 static int dissect_privateExponent(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
107 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_privateExponent);
109 static int dissect_prime1(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
110 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_prime1);
112 static int dissect_prime2(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
113 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_prime2);
115 static int dissect_exponent1(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
116 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_exponent1);
118 static int dissect_exponent2(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
119 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_exponent2);
121 static int dissect_coefficient(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
122 return dissect_pkcs1_INTEGER(FALSE, tvb, offset, actx, tree, hf_pkcs1_coefficient);
126 static const ber_old_sequence_t RSAPublicKey_sequence[] = {
127 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_modulus },
128 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_publicExponent },
133 dissect_pkcs1_RSAPublicKey(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
134 offset = dissect_ber_old_sequence(implicit_tag, actx, tree, tvb, offset,
135 RSAPublicKey_sequence, hf_index, ett_pkcs1_RSAPublicKey);
143 dissect_pkcs1_Version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
144 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
149 static int dissect_version(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
150 return dissect_pkcs1_Version(FALSE, tvb, offset, actx, tree, hf_pkcs1_version);
154 static const ber_old_sequence_t RSAPrivateKey_sequence[] = {
155 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_version },
156 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_modulus },
157 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_publicExponent },
158 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_privateExponent },
159 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_prime1 },
160 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_prime2 },
161 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_exponent1 },
162 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_exponent2 },
163 { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_coefficient },
168 dissect_pkcs1_RSAPrivateKey(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
169 offset = dissect_ber_old_sequence(implicit_tag, actx, tree, tvb, offset,
170 RSAPrivateKey_sequence, hf_index, ett_pkcs1_RSAPrivateKey);
178 dissect_pkcs1_DigestAlgorithmIdentifier(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
179 offset = dissect_x509af_AlgorithmIdentifier(implicit_tag, tvb, offset, actx, tree, hf_index);
183 static int dissect_digestAlgorithm(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
184 return dissect_pkcs1_DigestAlgorithmIdentifier(FALSE, tvb, offset, actx, tree, hf_pkcs1_digestAlgorithm);
190 dissect_pkcs1_Digest(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
191 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
196 static int dissect_digest(proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_) {
197 return dissect_pkcs1_Digest(FALSE, tvb, offset, actx, tree, hf_pkcs1_digest);
201 static const ber_old_sequence_t DigestInfo_sequence[] = {
202 { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_digestAlgorithm },
203 { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_digest },
208 dissect_pkcs1_DigestInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
209 offset = dissect_ber_old_sequence(implicit_tag, actx, tree, tvb, offset,
210 DigestInfo_sequence, hf_index, ett_pkcs1_DigestInfo);
216 /*--- End of included file: packet-pkcs1-fn.c ---*/
217 #line 54 "packet-pkcs1-template.c"
219 /*--- proto_register_pkcs1 ----------------------------------------------*/
220 void proto_register_pkcs1(void) {
223 static hf_register_info hf[] = {
225 /*--- Included file: packet-pkcs1-hfarr.c ---*/
226 #line 1 "packet-pkcs1-hfarr.c"
228 { "modulus", "pkcs1.modulus",
229 FT_INT32, BASE_DEC, NULL, 0,
230 "pkcs1.INTEGER", HFILL }},
231 { &hf_pkcs1_publicExponent,
232 { "publicExponent", "pkcs1.publicExponent",
233 FT_INT32, BASE_DEC, NULL, 0,
234 "pkcs1.INTEGER", HFILL }},
236 { "version", "pkcs1.version",
237 FT_INT32, BASE_DEC, VALS(x509af_Version_vals), 0,
238 "pkcs1.Version", HFILL }},
239 { &hf_pkcs1_privateExponent,
240 { "privateExponent", "pkcs1.privateExponent",
241 FT_INT32, BASE_DEC, NULL, 0,
242 "pkcs1.INTEGER", HFILL }},
244 { "prime1", "pkcs1.prime1",
245 FT_INT32, BASE_DEC, NULL, 0,
246 "pkcs1.INTEGER", HFILL }},
248 { "prime2", "pkcs1.prime2",
249 FT_INT32, BASE_DEC, NULL, 0,
250 "pkcs1.INTEGER", HFILL }},
251 { &hf_pkcs1_exponent1,
252 { "exponent1", "pkcs1.exponent1",
253 FT_INT32, BASE_DEC, NULL, 0,
254 "pkcs1.INTEGER", HFILL }},
255 { &hf_pkcs1_exponent2,
256 { "exponent2", "pkcs1.exponent2",
257 FT_INT32, BASE_DEC, NULL, 0,
258 "pkcs1.INTEGER", HFILL }},
259 { &hf_pkcs1_coefficient,
260 { "coefficient", "pkcs1.coefficient",
261 FT_INT32, BASE_DEC, NULL, 0,
262 "pkcs1.INTEGER", HFILL }},
263 { &hf_pkcs1_digestAlgorithm,
264 { "digestAlgorithm", "pkcs1.digestAlgorithm",
265 FT_NONE, BASE_NONE, NULL, 0,
266 "pkcs1.DigestAlgorithmIdentifier", HFILL }},
268 { "digest", "pkcs1.digest",
269 FT_BYTES, BASE_HEX, NULL, 0,
270 "pkcs1.Digest", HFILL }},
272 /*--- End of included file: packet-pkcs1-hfarr.c ---*/
273 #line 61 "packet-pkcs1-template.c"
276 /* List of subtrees */
277 static gint *ett[] = {
279 /*--- Included file: packet-pkcs1-ettarr.c ---*/
280 #line 1 "packet-pkcs1-ettarr.c"
281 &ett_pkcs1_RSAPublicKey,
282 &ett_pkcs1_RSAPrivateKey,
283 &ett_pkcs1_DigestInfo,
285 /*--- End of included file: packet-pkcs1-ettarr.c ---*/
286 #line 66 "packet-pkcs1-template.c"
289 /* Register protocol */
290 proto_pkcs1 = proto_register_protocol(PNAME, PSNAME, PFNAME);
292 /* Register fields and subtrees */
293 proto_register_field_array(proto_pkcs1, hf, array_length(hf));
294 proto_register_subtree_array(ett, array_length(ett));
299 /*--- proto_reg_handoff_pkcs1 -------------------------------------------*/
300 void proto_reg_handoff_pkcs1(void) {
301 register_ber_oid_dissector("1.2.840.113549.2.2", dissect_ber_oid_NULL_callback, proto_pkcs1, "md2");
302 register_ber_oid_dissector("1.2.840.113549.2.4", dissect_ber_oid_NULL_callback, proto_pkcs1, "md4");
303 register_ber_oid_dissector("1.2.840.113549.2.5", dissect_ber_oid_NULL_callback, proto_pkcs1, "md5");
305 register_ber_oid_dissector("1.2.840.113549.1.1.1", dissect_ber_oid_NULL_callback, proto_pkcs1, "rsaEncryption");
306 register_ber_oid_dissector("1.2.840.113549.1.1.2", dissect_ber_oid_NULL_callback, proto_pkcs1, "md2WithRSAEncryption");
307 register_ber_oid_dissector("1.2.840.113549.1.1.3", dissect_ber_oid_NULL_callback, proto_pkcs1, "md4WithRSAEncryption");
308 register_ber_oid_dissector("1.2.840.113549.1.1.4", dissect_ber_oid_NULL_callback, proto_pkcs1, "md5WithRSAEncryption");
311 /* these two are not from RFC2313 but pulled in from
312 http://www.alvestrand.no/objectid/1.2.840.113549.1.1.html
314 register_ber_oid_dissector("1.2.840.113549.1.1.5", dissect_ber_oid_NULL_callback, proto_pkcs1, "shaWithRSAEncryption");
315 register_ber_oid_dissector("1.2.840.113549.1.1.6", dissect_ber_oid_NULL_callback, proto_pkcs1, "rsaOAEPEncryptionSET");