tor  master
parsecommon.h
Go to the documentation of this file.
1 /* Copyright (c) 2016-2017, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
9 #ifndef TOR_PARSECOMMON_H
10 #define TOR_PARSECOMMON_H
11 
12 #include "container.h"
13 #include "crypto.h"
14 #include "memarea.h"
15 
21 typedef enum {
22  K_ACCEPT = 0,
23  K_ACCEPT6,
24  K_DIRECTORY_SIGNATURE,
25  K_RECOMMENDED_SOFTWARE,
26  K_REJECT,
27  K_REJECT6,
28  K_ROUTER,
29  K_SIGNED_DIRECTORY,
30  K_SIGNING_KEY,
31  K_ONION_KEY,
32  K_ONION_KEY_NTOR,
33  K_ROUTER_SIGNATURE,
34  K_PUBLISHED,
35  K_RUNNING_ROUTERS,
36  K_ROUTER_STATUS,
37  K_PLATFORM,
38  K_PROTO,
39  K_OPT,
40  K_BANDWIDTH,
41  K_CONTACT,
42  K_NETWORK_STATUS,
43  K_UPTIME,
44  K_DIR_SIGNING_KEY,
45  K_FAMILY,
46  K_FINGERPRINT,
47  K_HIBERNATING,
48  K_READ_HISTORY,
49  K_WRITE_HISTORY,
50  K_NETWORK_STATUS_VERSION,
51  K_DIR_SOURCE,
52  K_DIR_OPTIONS,
53  K_CLIENT_VERSIONS,
54  K_SERVER_VERSIONS,
55  K_RECOMMENDED_CLIENT_PROTOCOLS,
56  K_RECOMMENDED_RELAY_PROTOCOLS,
57  K_REQUIRED_CLIENT_PROTOCOLS,
58  K_REQUIRED_RELAY_PROTOCOLS,
59  K_OR_ADDRESS,
60  K_ID,
61  K_P,
62  K_P6,
63  K_R,
64  K_A,
65  K_S,
66  K_V,
67  K_W,
68  K_M,
69  K_EXTRA_INFO,
70  K_EXTRA_INFO_DIGEST,
71  K_CACHES_EXTRA_INFO,
72  K_HIDDEN_SERVICE_DIR,
73  K_ALLOW_SINGLE_HOP_EXITS,
74  K_IPV6_POLICY,
75  K_ROUTER_SIG_ED25519,
76  K_IDENTITY_ED25519,
77  K_MASTER_KEY_ED25519,
78  K_ONION_KEY_CROSSCERT,
79  K_NTOR_ONION_KEY_CROSSCERT,
80 
81  K_DIRREQ_END,
82  K_DIRREQ_V2_IPS,
83  K_DIRREQ_V3_IPS,
84  K_DIRREQ_V2_REQS,
85  K_DIRREQ_V3_REQS,
86  K_DIRREQ_V2_SHARE,
87  K_DIRREQ_V3_SHARE,
88  K_DIRREQ_V2_RESP,
89  K_DIRREQ_V3_RESP,
90  K_DIRREQ_V2_DIR,
91  K_DIRREQ_V3_DIR,
92  K_DIRREQ_V2_TUN,
93  K_DIRREQ_V3_TUN,
94  K_ENTRY_END,
95  K_ENTRY_IPS,
96  K_CELL_END,
97  K_CELL_PROCESSED,
98  K_CELL_QUEUED,
99  K_CELL_TIME,
100  K_CELL_CIRCS,
101  K_EXIT_END,
102  K_EXIT_WRITTEN,
103  K_EXIT_READ,
104  K_EXIT_OPENED,
105 
106  K_DIR_KEY_CERTIFICATE_VERSION,
107  K_DIR_IDENTITY_KEY,
108  K_DIR_KEY_PUBLISHED,
109  K_DIR_KEY_EXPIRES,
110  K_DIR_KEY_CERTIFICATION,
111  K_DIR_KEY_CROSSCERT,
112  K_DIR_ADDRESS,
113  K_DIR_TUNNELLED,
114 
115  K_VOTE_STATUS,
116  K_VALID_AFTER,
117  K_FRESH_UNTIL,
118  K_VALID_UNTIL,
119  K_VOTING_DELAY,
120 
121  K_KNOWN_FLAGS,
122  K_PARAMS,
123  K_BW_WEIGHTS,
124  K_VOTE_DIGEST,
125  K_CONSENSUS_DIGEST,
126  K_ADDITIONAL_DIGEST,
127  K_ADDITIONAL_SIGNATURE,
128  K_CONSENSUS_METHODS,
129  K_CONSENSUS_METHOD,
130  K_LEGACY_DIR_KEY,
131  K_DIRECTORY_FOOTER,
132  K_SIGNING_CERT_ED,
133  K_SR_FLAG,
134  K_COMMIT,
135  K_PREVIOUS_SRV,
136  K_CURRENT_SRV,
137  K_PACKAGE,
138 
139  A_PURPOSE,
140  A_LAST_LISTED,
141  A_UNKNOWN_,
142 
143  R_RENDEZVOUS_SERVICE_DESCRIPTOR,
144  R_VERSION,
145  R_PERMANENT_KEY,
146  R_SECRET_ID_PART,
147  R_PUBLICATION_TIME,
148  R_PROTOCOL_VERSIONS,
149  R_INTRODUCTION_POINTS,
150  R_SIGNATURE,
151 
152  R_HS_DESCRIPTOR, /* From version 3, this MUST be generic to all future
153  descriptor versions thus making it R_. */
154  R3_DESC_LIFETIME,
155  R3_DESC_SIGNING_CERT,
156  R3_REVISION_COUNTER,
157  R3_SUPERENCRYPTED,
158  R3_SIGNATURE,
159  R3_CREATE2_FORMATS,
160  R3_INTRO_AUTH_REQUIRED,
161  R3_SINGLE_ONION_SERVICE,
162  R3_INTRODUCTION_POINT,
163  R3_INTRO_ONION_KEY,
164  R3_INTRO_AUTH_KEY,
165  R3_INTRO_ENC_KEY,
166  R3_INTRO_ENC_KEY_CERT,
167  R3_INTRO_LEGACY_KEY,
168  R3_INTRO_LEGACY_KEY_CERT,
169  R3_DESC_AUTH_TYPE,
170  R3_DESC_AUTH_KEY,
171  R3_DESC_AUTH_CLIENT,
172  R3_ENCRYPTED,
173 
174  R_IPO_IDENTIFIER,
175  R_IPO_IP_ADDRESS,
176  R_IPO_ONION_PORT,
177  R_IPO_ONION_KEY,
178  R_IPO_SERVICE_KEY,
179 
180  C_CLIENT_NAME,
181  C_DESCRIPTOR_COOKIE,
182  C_CLIENT_KEY,
183 
184  ERR_,
185  EOF_,
186  NIL_
188 
199 typedef struct directory_token_t {
201  int n_args:30;
202  char **args;
204  char *object_type;
205  size_t object_size;
206  char *object_body;
210  char *error;
212 
216 typedef enum {
223 } obj_syntax;
224 
225 #define AT_START 1
226 #define AT_END 2
227 
228 #define TS_ANNOTATIONS_OK 1
229 #define TS_NOCHECK 2
230 #define TS_NO_NEW_ANNOTATIONS 4
231 
242 #define END_OF_TABLE { NULL, NIL_, 0,0,0, NO_OBJ, 0, INT_MAX, 0, 0 }
243 
244 #define T(s,t,a,o) { s, t, a, o, 0, INT_MAX, 0, 0 }
245 
246 #define T0N(s,t,a,o) { s, t, a, o, 0, INT_MAX, 0, 0 }
247 
248 #define T1(s,t,a,o) { s, t, a, o, 1, 1, 0, 0 }
249 
250 #define T1_START(s,t,a,o) { s, t, a, o, 1, 1, AT_START, 0 }
251 
252 #define T1_END(s,t,a,o) { s, t, a, o, 1, 1, AT_END, 0 }
253 
254 #define T1N(s,t,a,o) { s, t, a, o, 1, INT_MAX, 0, 0 }
255 
256 #define T01(s,t,a,o) { s, t, a, o, 0, 1, 0, 0 }
257 
258 #define A01(s,t,a,o) { s, t, a, o, 0, 1, 0, 1 }
259 
261 #define ARGS 0,INT_MAX,0
262 
263 #define NO_ARGS 0,0,0
264 
265 #define CONCAT_ARGS 1,1,1
266 
267 #define GE(n) n,INT_MAX,0
268 
269 #define EQ(n) n,n,0
270 
273 typedef struct token_rule_t {
275  const char *t;
279  int min_args;
281  int max_args;
288  int min_cnt;
290  int max_cnt;
293  int pos;
296 } token_rule_t;
297 
298 void token_clear(directory_token_t *tok);
299 
300 int tokenize_string(memarea_t *area,
301  const char *start, const char *end,
302  smartlist_t *out,
303  token_rule_t *table,
304  int flags);
306  const char **s,
307  const char *eos,
308  token_rule_t *table);
309 
311  directory_keyword keyword,
312  const char *keyword_str);
313 
314 #define find_by_keyword(s, keyword) \
315  find_by_keyword_((s), (keyword), #keyword)
316 
318  directory_keyword keyword);
320 
321 #endif /* !defined(TOR_PARSECOMMON_H) */
322 
Definition: memarea.c:112
const char * t
Definition: parsecommon.h:275
Definition: parsecommon.h:220
crypto_pk_t * key
Definition: parsecommon.h:208
Headers for crypto.c.
int max_args
Definition: parsecommon.h:281
int max_cnt
Definition: parsecommon.h:290
char ** args
Definition: parsecommon.h:202
struct token_rule_t token_rule_t
Definition: parsecommon.h:218
directory_keyword v
Definition: parsecommon.h:277
directory_token_t * get_next_token(memarea_t *area, const char **s, const char *eos, token_rule_t *table)
Definition: parsecommon.c:251
Definition: container.h:18
directory_token_t * find_by_keyword_(smartlist_t *s, directory_keyword keyword, const char *keyword_str)
Definition: parsecommon.c:413
Definition: parsecommon.h:219
Definition: parsecommon.h:217
char * object_body
Definition: parsecommon.h:206
int n_args
Definition: parsecommon.h:201
int min_args
Definition: parsecommon.h:279
int concat_args
Definition: parsecommon.h:284
directory_token_t * find_opt_by_keyword(const smartlist_t *s, directory_keyword keyword)
Definition: parsecommon.c:429
int min_cnt
Definition: parsecommon.h:288
Definition: parsecommon.h:222
int tokenize_string(memarea_t *area, const char *start, const char *end, smartlist_t *out, token_rule_t *table, int flags)
Definition: parsecommon.c:44
int is_annotation
Definition: parsecommon.h:295
char * object_type
Definition: parsecommon.h:204
char * error
Definition: parsecommon.h:210
directory_keyword
Definition: parsecommon.h:21
obj_syntax
Definition: parsecommon.h:216
Definition: crypto_rsa.c:41
int pos
Definition: parsecommon.h:293
Definition: parsecommon.h:221
Definition: parsecommon.h:199
smartlist_t * find_all_by_keyword(const smartlist_t *s, directory_keyword k)
Definition: parsecommon.c:440
directory_keyword tp
Definition: parsecommon.h:200
void token_clear(directory_token_t *tok)
Definition: parsecommon.c:32
obj_syntax os
Definition: parsecommon.h:286
Definition: parsecommon.h:273
size_t object_size
Definition: parsecommon.h:205
struct directory_token_t directory_token_t