/src/wireshark/epan/dissectors/packet-pkcs10.c
Line | Count | Source |
1 | | /* Do not modify this file. Changes will be overwritten. */ |
2 | | /* Generated automatically by the ASN.1 to Wireshark dissector compiler */ |
3 | | /* packet-pkcs10.c */ |
4 | | /* asn2wrs.py -b -q -L -p pkcs10 -c ./pkcs10.cnf -s ./packet-pkcs10-template -D . -O ../.. PKCS10.asn */ |
5 | | |
6 | | /* packet-pkcs10.c |
7 | | * |
8 | | * Routines for PKCS10 packet dissection |
9 | | * Martin Peylo <wireshark@izac.de> 2018 |
10 | | * |
11 | | * Wireshark - Network traffic analyzer |
12 | | * By Gerald Combs <gerald@wireshark.org> |
13 | | * Copyright 1998 Gerald Combs |
14 | | * |
15 | | * SPDX-License-Identifier: GPL-2.0-or-later |
16 | | */ |
17 | | |
18 | | #include "config.h" |
19 | | |
20 | | #include <epan/packet.h> |
21 | | #include <wsutil/array.h> |
22 | | |
23 | | #include <epan/oids.h> |
24 | | #include <epan/asn1.h> |
25 | | #include "packet-ber.h" |
26 | | #include "packet-pkcs10.h" |
27 | | #include "packet-pkix1explicit.h" |
28 | | #include "packet-pkix1implicit.h" |
29 | | #include <epan/prefs.h> |
30 | | |
31 | | void proto_reg_handoff_pkcs10(void); |
32 | | void proto_register_pkcs10(void); |
33 | | |
34 | | static dissector_handle_t csr_handle; |
35 | | static dissector_handle_t cri_handle; |
36 | | |
37 | | /* Initialize the protocol and registered fields */ |
38 | | static int proto_pkcs10; |
39 | | static int hf_pkcs10_CertificationRequestInfo_PDU; /* CertificationRequestInfo */ |
40 | | static int hf_pkcs10_Attributes_PDU; /* Attributes */ |
41 | | static int hf_pkcs10_CertificationRequest_PDU; /* CertificationRequest */ |
42 | | static int hf_pkcs10_version; /* T_version */ |
43 | | static int hf_pkcs10_subject; /* Name */ |
44 | | static int hf_pkcs10_subjectPKInfo; /* SubjectPublicKeyInfo */ |
45 | | static int hf_pkcs10_attributes; /* Attributes */ |
46 | | static int hf_pkcs10_Attributes_item; /* Attribute */ |
47 | | static int hf_pkcs10_type; /* T_type */ |
48 | | static int hf_pkcs10_values; /* T_values */ |
49 | | static int hf_pkcs10_values_item; /* T_values_item */ |
50 | | static int hf_pkcs10_certificationRequestInfo; /* CertificationRequestInfo */ |
51 | | static int hf_pkcs10_signatureAlgorithm; /* AlgorithmIdentifier */ |
52 | | static int hf_pkcs10_signature; /* BIT_STRING */ |
53 | | |
54 | | /* Initialize the subtree pointers */ |
55 | | static int ett_pkcs10_CertificationRequestInfo; |
56 | | static int ett_pkcs10_Attributes; |
57 | | static int ett_pkcs10_Attribute; |
58 | | static int ett_pkcs10_T_values; |
59 | | static int ett_pkcs10_CertificationRequest; |
60 | | |
61 | | static const value_string pkcs10_T_version_vals[] = { |
62 | | { 0, "v1" }, |
63 | | { 0, NULL } |
64 | | }; |
65 | | |
66 | | |
67 | | static unsigned |
68 | 0 | dissect_pkcs10_T_version(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
69 | 0 | offset = dissect_ber_constrained_integer(implicit_tag, actx, tree, tvb, offset, |
70 | 0 | 0U, 0U, hf_index, NULL); |
71 | |
|
72 | 0 | return offset; |
73 | 0 | } |
74 | | |
75 | | |
76 | | |
77 | | static unsigned |
78 | 0 | dissect_pkcs10_T_type(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
79 | 0 | offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_pkcs10_type, &actx->external.direct_reference); |
80 | |
|
81 | 0 | return offset; |
82 | 0 | } |
83 | | |
84 | | |
85 | | |
86 | | static unsigned |
87 | 0 | dissect_pkcs10_T_values_item(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
88 | 0 | offset=call_ber_oid_callback(actx->external.direct_reference, tvb, offset, actx->pinfo, tree, NULL); |
89 | | |
90 | |
|
91 | 0 | return offset; |
92 | 0 | } |
93 | | |
94 | | |
95 | | static const ber_sequence_t T_values_set_of[1] = { |
96 | | { &hf_pkcs10_values_item , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_values_item }, |
97 | | }; |
98 | | |
99 | | static unsigned |
100 | 0 | dissect_pkcs10_T_values(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
101 | 0 | offset = dissect_ber_constrained_set_of(implicit_tag, actx, tree, tvb, offset, |
102 | 0 | 1, NO_BOUND, T_values_set_of, hf_index, ett_pkcs10_T_values); |
103 | |
|
104 | 0 | return offset; |
105 | 0 | } |
106 | | |
107 | | |
108 | | static const ber_sequence_t Attribute_sequence[] = { |
109 | | { &hf_pkcs10_type , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_type }, |
110 | | { &hf_pkcs10_values , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_values }, |
111 | | { NULL, 0, 0, 0, NULL } |
112 | | }; |
113 | | |
114 | | static unsigned |
115 | 0 | dissect_pkcs10_Attribute(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
116 | 0 | offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset, |
117 | 0 | Attribute_sequence, hf_index, ett_pkcs10_Attribute); |
118 | |
|
119 | 0 | return offset; |
120 | 0 | } |
121 | | |
122 | | |
123 | | static const ber_sequence_t Attributes_set_of[1] = { |
124 | | { &hf_pkcs10_Attributes_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs10_Attribute }, |
125 | | }; |
126 | | |
127 | | static unsigned |
128 | 0 | dissect_pkcs10_Attributes(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
129 | 0 | offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset, |
130 | 0 | Attributes_set_of, hf_index, ett_pkcs10_Attributes); |
131 | |
|
132 | 0 | return offset; |
133 | 0 | } |
134 | | |
135 | | |
136 | | static const ber_sequence_t CertificationRequestInfo_sequence[] = { |
137 | | { &hf_pkcs10_version , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_version }, |
138 | | { &hf_pkcs10_subject , BER_CLASS_ANY, -1, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_Name }, |
139 | | { &hf_pkcs10_subjectPKInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_SubjectPublicKeyInfo }, |
140 | | { &hf_pkcs10_attributes , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_pkcs10_Attributes }, |
141 | | { NULL, 0, 0, 0, NULL } |
142 | | }; |
143 | | |
144 | | unsigned |
145 | 0 | dissect_pkcs10_CertificationRequestInfo(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
146 | 0 | offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset, |
147 | 0 | CertificationRequestInfo_sequence, hf_index, ett_pkcs10_CertificationRequestInfo); |
148 | |
|
149 | 0 | return offset; |
150 | 0 | } |
151 | | |
152 | | |
153 | | |
154 | | static unsigned |
155 | 0 | dissect_pkcs10_BIT_STRING(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
156 | 0 | offset = dissect_ber_bitstring(implicit_tag, actx, tree, tvb, offset, |
157 | 0 | NULL, 0, hf_index, -1, |
158 | 0 | NULL); |
159 | |
|
160 | 0 | return offset; |
161 | 0 | } |
162 | | |
163 | | |
164 | | static const ber_sequence_t CertificationRequest_sequence[] = { |
165 | | { &hf_pkcs10_certificationRequestInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs10_CertificationRequestInfo }, |
166 | | { &hf_pkcs10_signatureAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_AlgorithmIdentifier }, |
167 | | { &hf_pkcs10_signature , BER_CLASS_UNI, BER_UNI_TAG_BITSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs10_BIT_STRING }, |
168 | | { NULL, 0, 0, 0, NULL } |
169 | | }; |
170 | | |
171 | | unsigned |
172 | 0 | dissect_pkcs10_CertificationRequest(bool implicit_tag _U_, tvbuff_t *tvb _U_, unsigned offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { |
173 | 0 | offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset, |
174 | 0 | CertificationRequest_sequence, hf_index, ett_pkcs10_CertificationRequest); |
175 | |
|
176 | 0 | return offset; |
177 | 0 | } |
178 | | |
179 | | /*--- PDUs ---*/ |
180 | | |
181 | 0 | static int dissect_CertificationRequestInfo_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) { |
182 | 0 | unsigned offset = 0; |
183 | 0 | asn1_ctx_t asn1_ctx; |
184 | 0 | asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo); |
185 | 0 | offset = dissect_pkcs10_CertificationRequestInfo(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_CertificationRequestInfo_PDU); |
186 | 0 | return offset; |
187 | 0 | } |
188 | 0 | static int dissect_Attributes_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) { |
189 | 0 | unsigned offset = 0; |
190 | 0 | asn1_ctx_t asn1_ctx; |
191 | 0 | asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo); |
192 | 0 | offset = dissect_pkcs10_Attributes(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_Attributes_PDU); |
193 | 0 | return offset; |
194 | 0 | } |
195 | 0 | static int dissect_CertificationRequest_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) { |
196 | 0 | unsigned offset = 0; |
197 | 0 | asn1_ctx_t asn1_ctx; |
198 | 0 | asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo); |
199 | 0 | offset = dissect_pkcs10_CertificationRequest(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_CertificationRequest_PDU); |
200 | 0 | return offset; |
201 | 0 | } |
202 | | |
203 | | |
204 | | /*--- proto_register_pkcs10 ----------------------------------------------*/ |
205 | 16 | void proto_register_pkcs10(void) { |
206 | | |
207 | | /* List of fields */ |
208 | 16 | static hf_register_info hf[] = { |
209 | 16 | { &hf_pkcs10_CertificationRequestInfo_PDU, |
210 | 16 | { "CertificationRequestInfo", "pkcs10.CertificationRequestInfo_element", |
211 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
212 | 16 | NULL, HFILL }}, |
213 | 16 | { &hf_pkcs10_Attributes_PDU, |
214 | 16 | { "Attributes", "pkcs10.Attributes", |
215 | 16 | FT_UINT32, BASE_DEC, NULL, 0, |
216 | 16 | NULL, HFILL }}, |
217 | 16 | { &hf_pkcs10_CertificationRequest_PDU, |
218 | 16 | { "CertificationRequest", "pkcs10.CertificationRequest_element", |
219 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
220 | 16 | NULL, HFILL }}, |
221 | 16 | { &hf_pkcs10_version, |
222 | 16 | { "version", "pkcs10.version", |
223 | 16 | FT_UINT32, BASE_DEC, VALS(pkcs10_T_version_vals), 0, |
224 | 16 | NULL, HFILL }}, |
225 | 16 | { &hf_pkcs10_subject, |
226 | 16 | { "subject", "pkcs10.subject", |
227 | 16 | FT_UINT32, BASE_DEC, NULL, 0, |
228 | 16 | "Name", HFILL }}, |
229 | 16 | { &hf_pkcs10_subjectPKInfo, |
230 | 16 | { "subjectPKInfo", "pkcs10.subjectPKInfo_element", |
231 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
232 | 16 | "SubjectPublicKeyInfo", HFILL }}, |
233 | 16 | { &hf_pkcs10_attributes, |
234 | 16 | { "attributes", "pkcs10.attributes", |
235 | 16 | FT_UINT32, BASE_DEC, NULL, 0, |
236 | 16 | NULL, HFILL }}, |
237 | 16 | { &hf_pkcs10_Attributes_item, |
238 | 16 | { "Attribute", "pkcs10.Attribute_element", |
239 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
240 | 16 | NULL, HFILL }}, |
241 | 16 | { &hf_pkcs10_type, |
242 | 16 | { "type", "pkcs10.type", |
243 | 16 | FT_OID, BASE_NONE, NULL, 0, |
244 | 16 | NULL, HFILL }}, |
245 | 16 | { &hf_pkcs10_values, |
246 | 16 | { "values", "pkcs10.values", |
247 | 16 | FT_UINT32, BASE_DEC, NULL, 0, |
248 | 16 | NULL, HFILL }}, |
249 | 16 | { &hf_pkcs10_values_item, |
250 | 16 | { "values item", "pkcs10.values_item_element", |
251 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
252 | 16 | NULL, HFILL }}, |
253 | 16 | { &hf_pkcs10_certificationRequestInfo, |
254 | 16 | { "certificationRequestInfo", "pkcs10.certificationRequestInfo_element", |
255 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
256 | 16 | NULL, HFILL }}, |
257 | 16 | { &hf_pkcs10_signatureAlgorithm, |
258 | 16 | { "signatureAlgorithm", "pkcs10.signatureAlgorithm_element", |
259 | 16 | FT_NONE, BASE_NONE, NULL, 0, |
260 | 16 | "AlgorithmIdentifier", HFILL }}, |
261 | 16 | { &hf_pkcs10_signature, |
262 | 16 | { "signature", "pkcs10.signature", |
263 | 16 | FT_BYTES, BASE_NONE, NULL, 0, |
264 | 16 | "BIT_STRING", HFILL }}, |
265 | 16 | }; |
266 | | |
267 | | /* List of subtrees */ |
268 | 16 | static int *ett[] = { |
269 | 16 | &ett_pkcs10_CertificationRequestInfo, |
270 | 16 | &ett_pkcs10_Attributes, |
271 | 16 | &ett_pkcs10_Attribute, |
272 | 16 | &ett_pkcs10_T_values, |
273 | 16 | &ett_pkcs10_CertificationRequest, |
274 | 16 | }; |
275 | | /* Register protocol */ |
276 | 16 | proto_pkcs10 = proto_register_protocol("PKCS10 Certification Request", "PKCS10", "pkcs10"); |
277 | | |
278 | | /* Register fields and subtrees */ |
279 | 16 | proto_register_field_array(proto_pkcs10, hf, array_length(hf)); |
280 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
281 | | |
282 | 16 | csr_handle = register_dissector("pkcs10", dissect_CertificationRequest_PDU, proto_pkcs10); |
283 | 16 | cri_handle = register_dissector("pkcs10.cri", dissect_CertificationRequestInfo_PDU, proto_pkcs10); |
284 | 16 | register_ber_syntax_dissector("CertificationRequest", proto_pkcs10, dissect_CertificationRequest_PDU); |
285 | 16 | register_ber_syntax_dissector("CertificationRequestInfo", proto_pkcs10, dissect_CertificationRequestInfo_PDU); |
286 | 16 | register_ber_oid_syntax(".p10", NULL, "CertificationRequest"); |
287 | 16 | register_ber_oid_syntax(".csr", NULL, "CertificationRequest"); |
288 | 16 | } |
289 | | |
290 | | |
291 | | /*--- proto_reg_handoff_pkcs10 -------------------------------------------*/ |
292 | 16 | void proto_reg_handoff_pkcs10(void) { |
293 | | |
294 | 16 | register_ber_oid_dissector("1.2.840.113549.1.9.9", dissect_Attributes_PDU, proto_pkcs10, "pkcs-9-at-extendedCertificateAttributes"); |
295 | | |
296 | | |
297 | 16 | dissector_add_string("media_type", "application/pkcs10", csr_handle); /* RFC 5967 */ |
298 | 16 | dissector_add_string("rfc7468.preeb_label", "CERTIFICATE REQUEST", csr_handle); /* RFC 7468 */ |
299 | 16 | dissector_add_string("rfc7468.preeb_label", "NEW CERTIFICATE REQUEST", csr_handle); /* RFC 7468 Appendix A. Non-conforming example*/ |
300 | 16 | } |