1 /* Do not modify this file. Changes will be overwritten. */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler */
4 /* asn2wrs.py -b -q -L -p pkcs10 -c ./pkcs10.cnf -s ./packet-pkcs10-template -D . -O ../.. PKCS10.asn */
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.
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
[] = {
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
,
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
);
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
);
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
},
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
);
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
}
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
);
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
},
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
);
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
}
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
);
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,
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
);
194 static int dissect_Attributes_PDU(tvbuff_t
*tvb _U_
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
, void *data _U_
) {
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
);
201 static int dissect_CertificationRequest_PDU(tvbuff_t
*tvb _U_
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
, void *data _U_
) {
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
);
210 /*--- proto_register_pkcs10 ----------------------------------------------*/
211 void proto_register_pkcs10(void) {
214 static hf_register_info hf
[] = {
215 { &hf_pkcs10_Attributes_PDU
,
216 { "Attributes", "pkcs10.Attributes",
217 FT_UINT32
, BASE_DEC
, NULL
, 0,
219 { &hf_pkcs10_CertificationRequest_PDU
,
220 { "CertificationRequest", "pkcs10.CertificationRequest_element",
221 FT_NONE
, BASE_NONE
, NULL
, 0,
223 { &hf_pkcs10_version
,
224 { "version", "pkcs10.version",
225 FT_UINT32
, BASE_DEC
, VALS(pkcs10_T_version_vals
), 0,
227 { &hf_pkcs10_subject
,
228 { "subject", "pkcs10.subject",
229 FT_UINT32
, BASE_DEC
, NULL
, 0,
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,
239 { &hf_pkcs10_Attributes_item
,
240 { "Attribute", "pkcs10.Attribute_element",
241 FT_NONE
, BASE_NONE
, NULL
, 0,
244 { "type", "pkcs10.type",
245 FT_OID
, BASE_NONE
, NULL
, 0,
248 { "values", "pkcs10.values",
249 FT_UINT32
, BASE_DEC
, NULL
, 0,
251 { &hf_pkcs10_values_item
,
252 { "values item", "pkcs10.values_item_element",
253 FT_NONE
, BASE_NONE
, NULL
, 0,
255 { &hf_pkcs10_certificationRequestInfo
,
256 { "certificationRequestInfo", "pkcs10.certificationRequestInfo_element",
257 FT_NONE
, BASE_NONE
, NULL
, 0,
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*/