epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-pkcs10.c
blob8f7dcf8131fe0b5fa0da3afbad03d63b741b4b3d
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 */
6 /* packet-p10.c
8 * Routines for PKCS10 packet dissection
9 * Martin Peylo <wireshark@izac.de> 2018
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "config.h"
32 #include <epan/packet.h>
33 #include <wsutil/array.h>
35 #include <epan/oids.h>
36 #include <epan/asn1.h>
37 #include "packet-ber.h"
38 #include "packet-pkcs10.h"
39 #include "packet-pkix1explicit.h"
40 #include "packet-pkix1implicit.h"
41 #include <epan/prefs.h>
43 #define PNAME "PKCS10 Certification Request"
44 #define PSNAME "PKCS10"
45 #define PFNAME "pkcs10"
47 void proto_register_pkcs10(void);
49 static dissector_handle_t csr_handle;
51 /* Initialize the protocol and registered fields */
52 static int proto_pkcs10;
53 static int hf_pkcs10_Attributes_PDU; /* Attributes */
54 static int hf_pkcs10_CertificationRequest_PDU; /* CertificationRequest */
55 static int hf_pkcs10_version; /* T_version */
56 static int hf_pkcs10_subject; /* Name */
57 static int hf_pkcs10_subjectPKInfo; /* SubjectPublicKeyInfo */
58 static int hf_pkcs10_attributes; /* Attributes */
59 static int hf_pkcs10_Attributes_item; /* Attribute */
60 static int hf_pkcs10_type; /* T_type */
61 static int hf_pkcs10_values; /* T_values */
62 static int hf_pkcs10_values_item; /* T_values_item */
63 static int hf_pkcs10_certificationRequestInfo; /* CertificationRequestInfo */
64 static int hf_pkcs10_signatureAlgorithm; /* AlgorithmIdentifier */
65 static int hf_pkcs10_signature; /* BIT_STRING */
67 /* Initialize the subtree pointers */
68 static int ett_pkcs10_CertificationRequestInfo;
69 static int ett_pkcs10_Attributes;
70 static int ett_pkcs10_Attribute;
71 static int ett_pkcs10_T_values;
72 static int ett_pkcs10_CertificationRequest;
74 static const value_string pkcs10_T_version_vals[] = {
75 { 0, "v1" },
76 { 0, NULL }
80 static int
81 dissect_pkcs10_T_version(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
82 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
83 NULL);
85 return offset;
90 static int
91 dissect_pkcs10_T_type(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
92 offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_pkcs10_type, &actx->external.direct_reference);
94 return offset;
99 static int
100 dissect_pkcs10_T_values_item(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
101 offset=call_ber_oid_callback(actx->external.direct_reference, tvb, offset, actx->pinfo, tree, NULL);
104 return offset;
108 static const ber_sequence_t T_values_set_of[1] = {
109 { &hf_pkcs10_values_item , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_values_item },
112 static int
113 dissect_pkcs10_T_values(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
114 offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
115 T_values_set_of, hf_index, ett_pkcs10_T_values);
117 return offset;
121 static const ber_sequence_t Attribute_sequence[] = {
122 { &hf_pkcs10_type , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_type },
123 { &hf_pkcs10_values , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_values },
124 { NULL, 0, 0, 0, NULL }
127 static int
128 dissect_pkcs10_Attribute(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
129 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
130 Attribute_sequence, hf_index, ett_pkcs10_Attribute);
132 return offset;
136 static const ber_sequence_t Attributes_set_of[1] = {
137 { &hf_pkcs10_Attributes_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs10_Attribute },
140 static int
141 dissect_pkcs10_Attributes(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
142 offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
143 Attributes_set_of, hf_index, ett_pkcs10_Attributes);
145 return offset;
149 static const ber_sequence_t CertificationRequestInfo_sequence[] = {
150 { &hf_pkcs10_version , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_version },
151 { &hf_pkcs10_subject , BER_CLASS_ANY, -1, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_Name },
152 { &hf_pkcs10_subjectPKInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_SubjectPublicKeyInfo },
153 { &hf_pkcs10_attributes , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_pkcs10_Attributes },
154 { NULL, 0, 0, 0, NULL }
157 static int
158 dissect_pkcs10_CertificationRequestInfo(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
159 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
160 CertificationRequestInfo_sequence, hf_index, ett_pkcs10_CertificationRequestInfo);
162 return offset;
167 static int
168 dissect_pkcs10_BIT_STRING(bool 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_bitstring(implicit_tag, actx, tree, tvb, offset,
170 NULL, 0, hf_index, -1,
171 NULL);
173 return offset;
177 static const ber_sequence_t CertificationRequest_sequence[] = {
178 { &hf_pkcs10_certificationRequestInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs10_CertificationRequestInfo },
179 { &hf_pkcs10_signatureAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_AlgorithmIdentifier },
180 { &hf_pkcs10_signature , BER_CLASS_UNI, BER_UNI_TAG_BITSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs10_BIT_STRING },
181 { NULL, 0, 0, 0, NULL }
185 dissect_pkcs10_CertificationRequest(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
186 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
187 CertificationRequest_sequence, hf_index, ett_pkcs10_CertificationRequest);
189 return offset;
192 /*--- PDUs ---*/
194 static int dissect_Attributes_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
195 int offset = 0;
196 asn1_ctx_t asn1_ctx;
197 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
198 offset = dissect_pkcs10_Attributes(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_Attributes_PDU);
199 return offset;
201 static int dissect_CertificationRequest_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
202 int offset = 0;
203 asn1_ctx_t asn1_ctx;
204 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
205 offset = dissect_pkcs10_CertificationRequest(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_CertificationRequest_PDU);
206 return offset;
210 /*--- proto_register_pkcs10 ----------------------------------------------*/
211 void proto_register_pkcs10(void) {
213 /* List of fields */
214 static hf_register_info hf[] = {
215 { &hf_pkcs10_Attributes_PDU,
216 { "Attributes", "pkcs10.Attributes",
217 FT_UINT32, BASE_DEC, NULL, 0,
218 NULL, HFILL }},
219 { &hf_pkcs10_CertificationRequest_PDU,
220 { "CertificationRequest", "pkcs10.CertificationRequest_element",
221 FT_NONE, BASE_NONE, NULL, 0,
222 NULL, HFILL }},
223 { &hf_pkcs10_version,
224 { "version", "pkcs10.version",
225 FT_UINT32, BASE_DEC, VALS(pkcs10_T_version_vals), 0,
226 NULL, HFILL }},
227 { &hf_pkcs10_subject,
228 { "subject", "pkcs10.subject",
229 FT_UINT32, BASE_DEC, NULL, 0,
230 "Name", HFILL }},
231 { &hf_pkcs10_subjectPKInfo,
232 { "subjectPKInfo", "pkcs10.subjectPKInfo_element",
233 FT_NONE, BASE_NONE, NULL, 0,
234 "SubjectPublicKeyInfo", HFILL }},
235 { &hf_pkcs10_attributes,
236 { "attributes", "pkcs10.attributes",
237 FT_UINT32, BASE_DEC, NULL, 0,
238 NULL, HFILL }},
239 { &hf_pkcs10_Attributes_item,
240 { "Attribute", "pkcs10.Attribute_element",
241 FT_NONE, BASE_NONE, NULL, 0,
242 NULL, HFILL }},
243 { &hf_pkcs10_type,
244 { "type", "pkcs10.type",
245 FT_OID, BASE_NONE, NULL, 0,
246 NULL, HFILL }},
247 { &hf_pkcs10_values,
248 { "values", "pkcs10.values",
249 FT_UINT32, BASE_DEC, NULL, 0,
250 NULL, HFILL }},
251 { &hf_pkcs10_values_item,
252 { "values item", "pkcs10.values_item_element",
253 FT_NONE, BASE_NONE, NULL, 0,
254 NULL, HFILL }},
255 { &hf_pkcs10_certificationRequestInfo,
256 { "certificationRequestInfo", "pkcs10.certificationRequestInfo_element",
257 FT_NONE, BASE_NONE, NULL, 0,
258 NULL, HFILL }},
259 { &hf_pkcs10_signatureAlgorithm,
260 { "signatureAlgorithm", "pkcs10.signatureAlgorithm_element",
261 FT_NONE, BASE_NONE, NULL, 0,
262 "AlgorithmIdentifier", HFILL }},
263 { &hf_pkcs10_signature,
264 { "signature", "pkcs10.signature",
265 FT_BYTES, BASE_NONE, NULL, 0,
266 "BIT_STRING", HFILL }},
269 /* List of subtrees */
270 static int *ett[] = {
271 &ett_pkcs10_CertificationRequestInfo,
272 &ett_pkcs10_Attributes,
273 &ett_pkcs10_Attribute,
274 &ett_pkcs10_T_values,
275 &ett_pkcs10_CertificationRequest,
277 /* Register protocol */
278 proto_pkcs10 = proto_register_protocol(PNAME, PSNAME, PFNAME);
280 /* Register fields and subtrees */
281 proto_register_field_array(proto_pkcs10, hf, array_length(hf));
282 proto_register_subtree_array(ett, array_length(ett));
284 csr_handle = register_dissector(PFNAME, dissect_CertificationRequest_PDU, proto_pkcs10);
285 register_ber_syntax_dissector("CertificationRequest", proto_pkcs10, dissect_CertificationRequest_PDU);
286 register_ber_oid_syntax(".p10", NULL, "CertificationRequest");
287 register_ber_oid_syntax(".csr", NULL, "CertificationRequest");
291 /*--- proto_reg_handoff_pkcs10 -------------------------------------------*/
292 void proto_reg_handoff_pkcs10(void) {
294 register_ber_oid_dissector("1.2.840.113549.1.9.9", dissect_Attributes_PDU, proto_pkcs10, "pkcs-9-at-extendedCertificateAttributes");
297 dissector_add_string("media_type", "application/pkcs10", csr_handle); /* RFC 5967 */
298 dissector_add_string("rfc7468.preeb_label", "CERTIFICATE REQUEST", csr_handle); /* RFC 7468 */
299 dissector_add_string("rfc7468.preeb_label", "NEW CERTIFICATE REQUEST", csr_handle); /* RFC 7468 Appendix A. Non-conforming example*/