1 /* asn1.h 2 * Common data for ASN.1 3 * 2007 Anders Broman 4 * 5 * Wireshark - Network traffic analyzer 6 * By Gerald Combs <gerald@wireshark.org> 7 * Copyright 1998 Gerald Combs 8 * 9 * SPDX-License-Identifier: GPL-2.0-or-later 10 */ 11 12 #ifndef __ASN1_H__ 13 #define __ASN1_H__ 14 15 #include "ws_symbol_export.h" 16 17 typedef enum { 18 ASN1_ENC_BER, /* X.690 - BER, CER, DER */ 19 ASN1_ENC_PER, /* X.691 - PER */ 20 ASN1_ENC_ECN, /* X.692 - ECN */ 21 ASN1_ENC_XER, /* X.693 - XER */ 22 ASN1_ENC_OER /* X.696 - OER */ 23 } asn1_enc_e; 24 25 typedef enum { 26 CB_ASN1_ENC, 27 CB_NEW_DISSECTOR, 28 CB_DISSECTOR_HANDLE 29 } asn1_cb_variant; 30 31 typedef enum { 32 ASN1_PAR_IRR, /* irrelevant parameter */ 33 /* value */ 34 ASN1_PAR_BOOLEAN, 35 ASN1_PAR_INTEGER, 36 /* type */ 37 ASN1_PAR_TYPE 38 } asn1_par_type; 39 40 typedef struct _asn1_par_def_t { 41 const gchar *name; 42 asn1_par_type ptype; 43 } asn1_par_def_t; 44 45 typedef struct _asn1_par_t { 46 const gchar *name; 47 asn1_par_type ptype; 48 union { 49 gboolean v_boolean; 50 gint32 v_integer; 51 void *v_type; 52 } value; 53 struct _asn1_par_t *next; 54 } asn1_par_t; 55 56 typedef struct _asn1_stack_frame_t { 57 const gchar *name; 58 struct _asn1_par_t *par; 59 struct _asn1_stack_frame_t *next; 60 } asn1_stack_frame_t; 61 62 #define ASN1_CTX_SIGNATURE 0x41435458 /* "ACTX" */ 63 64 typedef struct _asn1_ctx_t { 65 guint32 signature; 66 asn1_enc_e encoding; 67 gboolean aligned; 68 packet_info *pinfo; 69 proto_item *created_item; 70 struct _asn1_stack_frame_t *stack; 71 void *value_ptr; 72 void *private_data; 73 struct { 74 int hf_index; 75 gboolean data_value_descr_present; 76 gboolean direct_ref_present; 77 gboolean indirect_ref_present; 78 tvbuff_t *data_value_descriptor; 79 const char *direct_reference; 80 gint32 indirect_reference; 81 gint encoding; 82 /* 83 0 : single-ASN1-type, 84 1 : octet-aligned, 85 2 : arbitrary 86 */ 87 tvbuff_t *single_asn1_type; 88 tvbuff_t *octet_aligned; 89 tvbuff_t *arbitrary; 90 union { 91 struct { 92 int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index ); 93 } ber; 94 struct { 95 int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int); 96 } per; 97 } u; 98 } external; 99 struct { 100 proto_tree *tree; 101 proto_tree *top_tree; 102 void* tree_ctx; 103 } subtree; 104 struct { 105 int hf_index; 106 gboolean data_value_descr_present; 107 tvbuff_t *data_value_descriptor; 108 gint identification; 109 /* 110 0 : syntaxes, 111 1 : syntax, 112 2 : presentation-context-id, 113 3 : context-negotiation, 114 4 : transfer-syntax, 115 5 : fixed 116 */ 117 gint32 presentation_context_id; 118 const char *abstract_syntax; 119 const char *transfer_syntax; 120 tvbuff_t *data_value; 121 union { 122 struct { 123 int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index ); 124 } ber; 125 struct { 126 int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int); 127 } per; 128 } u; 129 } embedded_pdv; 130 struct _rose_ctx_t *rose_ctx; 131 } asn1_ctx_t; 132 133 #define ROSE_CTX_SIGNATURE 0x524F5345 /* "ROSE" */ 134 135 typedef struct _rose_ctx_t { 136 guint32 signature; 137 dissector_table_t arg_global_dissector_table; 138 dissector_table_t arg_local_dissector_table; 139 dissector_table_t res_global_dissector_table; 140 dissector_table_t res_local_dissector_table; 141 dissector_table_t err_global_dissector_table; 142 dissector_table_t err_local_dissector_table; 143 /* filling in description into tree, info column, any buffer */ 144 int apdu_depth; 145 gboolean fillin_info; 146 gchar *fillin_ptr; 147 gsize fillin_buf_size; 148 struct { /* "dynamic" data */ 149 gint pdu; 150 /* 151 1 : invoke, 152 2 : returnResult, 153 3 : returnError, 154 4 : reject 155 */ 156 gint code; 157 /* 158 -1 : none (optional in ReturnResult) 159 0 : local, 160 1 : global 161 */ 162 gint32 code_local; 163 const char *code_global; 164 proto_item *code_item; 165 } d; 166 void *private_data; 167 } rose_ctx_t; 168 169 WS_DLL_PUBLIC void asn1_ctx_init(asn1_ctx_t *actx, asn1_enc_e encoding, gboolean aligned, packet_info *pinfo); 170 extern gboolean asn1_ctx_check_signature(asn1_ctx_t *actx); 171 extern void asn1_ctx_clean_external(asn1_ctx_t *actx); 172 extern void asn1_ctx_clean_epdv(asn1_ctx_t *actx); 173 174 extern void asn1_stack_frame_push(asn1_ctx_t *actx, const gchar *name); 175 extern void asn1_stack_frame_pop(asn1_ctx_t *actx, const gchar *name); 176 extern void asn1_stack_frame_check(asn1_ctx_t *actx, const gchar *name, const asn1_par_def_t *par_def); 177 178 extern void asn1_param_push_boolean(asn1_ctx_t *actx, gboolean value); 179 extern void asn1_param_push_integer(asn1_ctx_t *actx, gint32 value); 180 extern gboolean asn1_param_get_boolean(asn1_ctx_t *actx, const gchar *name); 181 extern gint32 asn1_param_get_integer(asn1_ctx_t *actx, const gchar *name); 182 183 WS_DLL_PUBLIC void rose_ctx_init(rose_ctx_t *rctx); 184 extern gboolean rose_ctx_check_signature(rose_ctx_t *rctx); 185 WS_DLL_PUBLIC void rose_ctx_clean_data(rose_ctx_t *rctx); 186 187 WS_DLL_PUBLIC asn1_ctx_t *get_asn1_ctx(void *ptr); 188 WS_DLL_PUBLIC rose_ctx_t *get_rose_ctx(void *ptr); 189 190 extern double asn1_get_real(const guint8 *real_ptr, gint len); 191 192 /* flags */ 193 #define ASN1_EXT_ROOT 0x01 194 #define ASN1_EXT_EXT 0x02 195 #define ASN1_OPT 0x04 196 #define ASN1_DFLT 0x08 197 198 #define ASN1_HAS_EXT(f) ((f)&(ASN1_EXT_ROOT|ASN1_EXT_EXT)) 199 200 201 #endif /* __ASN1_H__ */ 202