Coverage Report

Created: 2026-06-30 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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-p10.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
36
/* Initialize the protocol and registered fields */
37
static int proto_pkcs10;
38
static int hf_pkcs10_Attributes_PDU;              /* Attributes */
39
static int hf_pkcs10_CertificationRequest_PDU;    /* CertificationRequest */
40
static int hf_pkcs10_version;                     /* T_version */
41
static int hf_pkcs10_subject;                     /* Name */
42
static int hf_pkcs10_subjectPKInfo;               /* SubjectPublicKeyInfo */
43
static int hf_pkcs10_attributes;                  /* Attributes */
44
static int hf_pkcs10_Attributes_item;             /* Attribute */
45
static int hf_pkcs10_type;                        /* T_type */
46
static int hf_pkcs10_values;                      /* T_values */
47
static int hf_pkcs10_values_item;                 /* T_values_item */
48
static int hf_pkcs10_certificationRequestInfo;    /* CertificationRequestInfo */
49
static int hf_pkcs10_signatureAlgorithm;          /* AlgorithmIdentifier */
50
static int hf_pkcs10_signature;                   /* BIT_STRING */
51
52
/* Initialize the subtree pointers */
53
static int ett_pkcs10_CertificationRequestInfo;
54
static int ett_pkcs10_Attributes;
55
static int ett_pkcs10_Attribute;
56
static int ett_pkcs10_T_values;
57
static int ett_pkcs10_CertificationRequest;
58
59
static const value_string pkcs10_T_version_vals[] = {
60
  {   0, "v1" },
61
  { 0, NULL }
62
};
63
64
65
static unsigned
66
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_) {
67
0
  offset = dissect_ber_constrained_integer(implicit_tag, actx, tree, tvb, offset,
68
0
                                                            0U, 0U, hf_index, NULL);
69
70
0
  return offset;
71
0
}
72
73
74
75
static unsigned
76
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_) {
77
0
  offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_pkcs10_type, &actx->external.direct_reference);
78
79
0
  return offset;
80
0
}
81
82
83
84
static unsigned
85
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_) {
86
0
    offset=call_ber_oid_callback(actx->external.direct_reference, tvb, offset, actx->pinfo, tree, NULL);
87
88
89
0
  return offset;
90
0
}
91
92
93
static const ber_sequence_t T_values_set_of[1] = {
94
  { &hf_pkcs10_values_item  , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_values_item },
95
};
96
97
static unsigned
98
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_) {
99
0
  offset = dissect_ber_constrained_set_of(implicit_tag, actx, tree, tvb, offset,
100
0
                                             1, NO_BOUND, T_values_set_of, hf_index, ett_pkcs10_T_values);
101
102
0
  return offset;
103
0
}
104
105
106
static const ber_sequence_t Attribute_sequence[] = {
107
  { &hf_pkcs10_type         , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_type },
108
  { &hf_pkcs10_values       , BER_CLASS_UNI, BER_UNI_TAG_SET, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_values },
109
  { NULL, 0, 0, 0, NULL }
110
};
111
112
static unsigned
113
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_) {
114
0
  offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
115
0
                                   Attribute_sequence, hf_index, ett_pkcs10_Attribute);
116
117
0
  return offset;
118
0
}
119
120
121
static const ber_sequence_t Attributes_set_of[1] = {
122
  { &hf_pkcs10_Attributes_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs10_Attribute },
123
};
124
125
static unsigned
126
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_) {
127
0
  offset = dissect_ber_set_of(implicit_tag, actx, tree, tvb, offset,
128
0
                                 Attributes_set_of, hf_index, ett_pkcs10_Attributes);
129
130
0
  return offset;
131
0
}
132
133
134
static const ber_sequence_t CertificationRequestInfo_sequence[] = {
135
  { &hf_pkcs10_version      , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_pkcs10_T_version },
136
  { &hf_pkcs10_subject      , BER_CLASS_ANY, -1, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_Name },
137
  { &hf_pkcs10_subjectPKInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_SubjectPublicKeyInfo },
138
  { &hf_pkcs10_attributes   , BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_pkcs10_Attributes },
139
  { NULL, 0, 0, 0, NULL }
140
};
141
142
static unsigned
143
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_) {
144
0
  offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
145
0
                                   CertificationRequestInfo_sequence, hf_index, ett_pkcs10_CertificationRequestInfo);
146
147
0
  return offset;
148
0
}
149
150
151
152
static unsigned
153
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_) {
154
0
  offset = dissect_ber_bitstring(implicit_tag, actx, tree, tvb, offset,
155
0
                                    NULL, 0, hf_index, -1,
156
0
                                    NULL);
157
158
0
  return offset;
159
0
}
160
161
162
static const ber_sequence_t CertificationRequest_sequence[] = {
163
  { &hf_pkcs10_certificationRequestInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkcs10_CertificationRequestInfo },
164
  { &hf_pkcs10_signatureAlgorithm, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_pkix1explicit_AlgorithmIdentifier },
165
  { &hf_pkcs10_signature    , BER_CLASS_UNI, BER_UNI_TAG_BITSTRING, BER_FLAGS_NOOWNTAG, dissect_pkcs10_BIT_STRING },
166
  { NULL, 0, 0, 0, NULL }
167
};
168
169
unsigned
170
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_) {
171
0
  offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
172
0
                                   CertificationRequest_sequence, hf_index, ett_pkcs10_CertificationRequest);
173
174
0
  return offset;
175
0
}
176
177
/*--- PDUs ---*/
178
179
0
static int dissect_Attributes_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
180
0
  unsigned offset = 0;
181
0
  asn1_ctx_t asn1_ctx;
182
0
  asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
183
0
  offset = dissect_pkcs10_Attributes(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_Attributes_PDU);
184
0
  return offset;
185
0
}
186
0
static int dissect_CertificationRequest_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
187
0
  unsigned offset = 0;
188
0
  asn1_ctx_t asn1_ctx;
189
0
  asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
190
0
  offset = dissect_pkcs10_CertificationRequest(false, tvb, offset, &asn1_ctx, tree, hf_pkcs10_CertificationRequest_PDU);
191
0
  return offset;
192
0
}
193
194
195
/*--- proto_register_pkcs10 ----------------------------------------------*/
196
14
void proto_register_pkcs10(void) {
197
198
  /* List of fields */
199
14
  static hf_register_info hf[] = {
200
14
    { &hf_pkcs10_Attributes_PDU,
201
14
      { "Attributes", "pkcs10.Attributes",
202
14
        FT_UINT32, BASE_DEC, NULL, 0,
203
14
        NULL, HFILL }},
204
14
    { &hf_pkcs10_CertificationRequest_PDU,
205
14
      { "CertificationRequest", "pkcs10.CertificationRequest_element",
206
14
        FT_NONE, BASE_NONE, NULL, 0,
207
14
        NULL, HFILL }},
208
14
    { &hf_pkcs10_version,
209
14
      { "version", "pkcs10.version",
210
14
        FT_UINT32, BASE_DEC, VALS(pkcs10_T_version_vals), 0,
211
14
        NULL, HFILL }},
212
14
    { &hf_pkcs10_subject,
213
14
      { "subject", "pkcs10.subject",
214
14
        FT_UINT32, BASE_DEC, NULL, 0,
215
14
        "Name", HFILL }},
216
14
    { &hf_pkcs10_subjectPKInfo,
217
14
      { "subjectPKInfo", "pkcs10.subjectPKInfo_element",
218
14
        FT_NONE, BASE_NONE, NULL, 0,
219
14
        "SubjectPublicKeyInfo", HFILL }},
220
14
    { &hf_pkcs10_attributes,
221
14
      { "attributes", "pkcs10.attributes",
222
14
        FT_UINT32, BASE_DEC, NULL, 0,
223
14
        NULL, HFILL }},
224
14
    { &hf_pkcs10_Attributes_item,
225
14
      { "Attribute", "pkcs10.Attribute_element",
226
14
        FT_NONE, BASE_NONE, NULL, 0,
227
14
        NULL, HFILL }},
228
14
    { &hf_pkcs10_type,
229
14
      { "type", "pkcs10.type",
230
14
        FT_OID, BASE_NONE, NULL, 0,
231
14
        NULL, HFILL }},
232
14
    { &hf_pkcs10_values,
233
14
      { "values", "pkcs10.values",
234
14
        FT_UINT32, BASE_DEC, NULL, 0,
235
14
        NULL, HFILL }},
236
14
    { &hf_pkcs10_values_item,
237
14
      { "values item", "pkcs10.values_item_element",
238
14
        FT_NONE, BASE_NONE, NULL, 0,
239
14
        NULL, HFILL }},
240
14
    { &hf_pkcs10_certificationRequestInfo,
241
14
      { "certificationRequestInfo", "pkcs10.certificationRequestInfo_element",
242
14
        FT_NONE, BASE_NONE, NULL, 0,
243
14
        NULL, HFILL }},
244
14
    { &hf_pkcs10_signatureAlgorithm,
245
14
      { "signatureAlgorithm", "pkcs10.signatureAlgorithm_element",
246
14
        FT_NONE, BASE_NONE, NULL, 0,
247
14
        "AlgorithmIdentifier", HFILL }},
248
14
    { &hf_pkcs10_signature,
249
14
      { "signature", "pkcs10.signature",
250
14
        FT_BYTES, BASE_NONE, NULL, 0,
251
14
        "BIT_STRING", HFILL }},
252
14
  };
253
254
  /* List of subtrees */
255
14
  static int *ett[] = {
256
14
    &ett_pkcs10_CertificationRequestInfo,
257
14
    &ett_pkcs10_Attributes,
258
14
    &ett_pkcs10_Attribute,
259
14
    &ett_pkcs10_T_values,
260
14
    &ett_pkcs10_CertificationRequest,
261
14
  };
262
  /* Register protocol */
263
14
  proto_pkcs10 = proto_register_protocol("PKCS10 Certification Request", "PKCS10", "pkcs10");
264
265
  /* Register fields and subtrees */
266
14
  proto_register_field_array(proto_pkcs10, hf, array_length(hf));
267
14
  proto_register_subtree_array(ett, array_length(ett));
268
269
14
  csr_handle = register_dissector("pkcs10", dissect_CertificationRequest_PDU, proto_pkcs10);
270
14
  register_ber_syntax_dissector("CertificationRequest", proto_pkcs10, dissect_CertificationRequest_PDU);
271
14
  register_ber_oid_syntax(".p10", NULL, "CertificationRequest");
272
14
  register_ber_oid_syntax(".csr", NULL, "CertificationRequest");
273
14
}
274
275
276
/*--- proto_reg_handoff_pkcs10 -------------------------------------------*/
277
14
void proto_reg_handoff_pkcs10(void) {
278
279
14
  register_ber_oid_dissector("1.2.840.113549.1.9.9", dissect_Attributes_PDU, proto_pkcs10, "pkcs-9-at-extendedCertificateAttributes");
280
281
282
14
  dissector_add_string("media_type", "application/pkcs10", csr_handle); /* RFC 5967 */
283
14
  dissector_add_string("rfc7468.preeb_label", "CERTIFICATE REQUEST", csr_handle); /* RFC 7468 */
284
14
  dissector_add_string("rfc7468.preeb_label", "NEW CERTIFICATE REQUEST", csr_handle); /* RFC 7468 Appendix A. Non-conforming example*/
285
14
}