Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / asn1 / ess / packet-ess-template.c
blob55d95accd9994eb39d38930de9aa80f1cd12c410
1 /* packet-ess.c
2 * Routines for RFC 2634 and RFC 5035 Extended Security Services packet
3 * dissection
4 * Ronnie Sahlberg 2004
5 * Stig Bjorlykke 2010
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/asn1.h>
18 #include <epan/prefs.h>
19 #include <epan/uat.h>
20 #include <wsutil/array.h>
22 #include "packet-ber.h"
23 #include "packet-ess.h"
24 #include "packet-cms.h"
25 #include "packet-x509ce.h"
26 #include "packet-x509af.h"
28 #define PNAME "Extended Security Services"
29 #define PSNAME "ESS"
30 #define PFNAME "ess"
32 void proto_register_ess(void);
33 void proto_reg_handoff_ess(void);
35 typedef struct _ess_category_attributes_t {
36 char *oid;
37 unsigned lacv;
38 char *name;
39 } ess_category_attributes_t;
41 static ess_category_attributes_t *ess_category_attributes;
42 static unsigned num_ess_category_attributes;
44 /* Initialize the protocol and registered fields */
45 static int proto_ess;
46 static int hf_ess_SecurityCategory_type_OID;
47 static int hf_ess_Category_attribute;
49 static int ett_Category_attributes;
51 #include "packet-ess-hf.c"
53 #include "packet-ess-val.h"
55 /* Initialize the subtree pointers */
56 #include "packet-ess-ett.c"
58 static const char *object_identifier_id;
60 UAT_CSTRING_CB_DEF(ess_category_attributes, oid, ess_category_attributes_t)
61 UAT_DEC_CB_DEF(ess_category_attributes, lacv, ess_category_attributes_t)
62 UAT_CSTRING_CB_DEF(ess_category_attributes, name, ess_category_attributes_t)
64 static void *
65 ess_copy_cb(void *dest, const void *orig, size_t len _U_)
67 ess_category_attributes_t *u = (ess_category_attributes_t *)dest;
68 const ess_category_attributes_t *o = (const ess_category_attributes_t *)orig;
70 u->oid = g_strdup(o->oid);
71 u->lacv = o->lacv;
72 u->name = g_strdup(o->name);
74 return dest;
77 static void
78 ess_free_cb(void *r)
80 ess_category_attributes_t *u = (ess_category_attributes_t *)r;
82 g_free(u->oid);
83 g_free(u->name);
86 static void
87 ess_dissect_attribute (uint32_t value, asn1_ctx_t *actx)
89 unsigned i;
91 for (i = 0; i < num_ess_category_attributes; i++) {
92 ess_category_attributes_t *u = &(ess_category_attributes[i]);
94 if ((strcmp (u->oid, object_identifier_id) == 0) &&
95 (u->lacv == value))
97 proto_item_append_text (actx->created_item, " (%s)", u->name);
98 break;
103 static void
104 ess_dissect_attribute_flags (tvbuff_t *tvb, asn1_ctx_t *actx)
106 proto_tree *tree;
107 uint8_t *value;
108 unsigned i;
110 tree = proto_item_add_subtree (actx->created_item, ett_Category_attributes);
111 value = (uint8_t *)tvb_memdup (actx->pinfo->pool, tvb, 0, tvb_captured_length (tvb));
113 for (i = 0; i < num_ess_category_attributes; i++) {
114 ess_category_attributes_t *u = &(ess_category_attributes[i]);
116 if ((strcmp (u->oid, object_identifier_id) == 0) &&
117 ((u->lacv / 8) < tvb_captured_length (tvb)) &&
118 (value[u->lacv / 8] & (1U << (7 - (u->lacv % 8)))))
120 proto_tree_add_string_format (tree, hf_ess_Category_attribute, tvb,
121 u->lacv / 8, 1, u->name,
122 "%s (%d)", u->name, u->lacv);
127 #include "packet-ess-fn.c"
129 /*--- proto_register_ess ----------------------------------------------*/
130 void proto_register_ess(void) {
132 /* List of fields */
133 static hf_register_info hf[] = {
134 { &hf_ess_SecurityCategory_type_OID,
135 { "type", "ess.type_OID", FT_STRING, BASE_NONE, NULL, 0,
136 "Type of Security Category", HFILL }},
137 { &hf_ess_Category_attribute,
138 { "Attribute", "ess.attribute", FT_STRING, BASE_NONE, NULL, 0,
139 NULL, HFILL }},
140 #include "packet-ess-hfarr.c"
143 /* List of subtrees */
144 static int *ett[] = {
145 &ett_Category_attributes,
146 #include "packet-ess-ettarr.c"
149 static uat_field_t attributes_flds[] = {
150 UAT_FLD_CSTRING(ess_category_attributes,oid, "Tag Set", "Category Tag Set (Object Identifier)"),
151 UAT_FLD_DEC(ess_category_attributes,lacv, "Value", "Label And Cert Value"),
152 UAT_FLD_CSTRING(ess_category_attributes,name, "Name", "Category Name"),
153 UAT_END_FIELDS
156 uat_t *attributes_uat = uat_new("ESS Category Attributes",
157 sizeof(ess_category_attributes_t),
158 "ess_category_attributes",
159 true,
160 &ess_category_attributes,
161 &num_ess_category_attributes,
162 UAT_AFFECTS_DISSECTION, /* affects dissection of packets, but not set of named fields */
163 "ChEssCategoryAttributes",
164 ess_copy_cb,
165 NULL,
166 ess_free_cb,
167 NULL,
168 NULL,
169 attributes_flds);
171 static module_t *ess_module;
173 /* Register protocol */
174 proto_ess = proto_register_protocol(PNAME, PSNAME, PFNAME);
176 /* Register fields and subtrees */
177 proto_register_field_array(proto_ess, hf, array_length(hf));
178 proto_register_subtree_array(ett, array_length(ett));
180 ess_module = prefs_register_protocol(proto_ess, NULL);
182 prefs_register_uat_preference(ess_module, "attributes_table",
183 "ESS Category Attributes",
184 "ESS category attributes translation table",
185 attributes_uat);
190 /*--- proto_reg_handoff_ess -------------------------------------------*/
191 void proto_reg_handoff_ess(void) {
192 #include "packet-ess-dis-tab.c"