12 #define NS_PARSE_PRIVATE
66 T1_START(
"network-status-version", K_NETWORK_STATUS_VERSION,
68 T1(
"vote-status", K_VOTE_STATUS,
GE(1),
NO_OBJ ),
73 T1(
"voting-delay", K_VOTING_DELAY,
GE(2),
NO_OBJ ),
79 T0N(
"shared-rand-commit", K_COMMIT,
GE(3),
NO_OBJ ),
80 T01(
"shared-rand-previous-value", K_PREVIOUS_SRV,
EQ(2),
NO_OBJ ),
81 T01(
"shared-rand-current-value", K_CURRENT_SRV,
EQ(2),
NO_OBJ ),
83 T01(
"recommended-client-protocols", K_RECOMMENDED_CLIENT_PROTOCOLS,
85 T01(
"recommended-relay-protocols", K_RECOMMENDED_RELAY_PROTOCOLS,
87 T01(
"required-client-protocols", K_REQUIRED_CLIENT_PROTOCOLS,
89 T01(
"required-relay-protocols", K_REQUIRED_RELAY_PROTOCOLS,
96 T1(
"dir-source", K_DIR_SOURCE,
GE(6),
NO_OBJ ),
97 T01(
"legacy-dir-key", K_LEGACY_DIR_KEY,
GE(1),
NO_OBJ ),
101 T1(
"consensus-methods", K_CONSENSUS_METHODS,
GE(1),
NO_OBJ ),
109 static token_rule_t networkstatus_consensus_token_table[] = {
110 T1_START(
"network-status-version", K_NETWORK_STATUS_VERSION,
112 T1(
"vote-status", K_VOTE_STATUS,
GE(1),
NO_OBJ ),
116 T1(
"voting-delay", K_VOTING_DELAY,
GE(2),
NO_OBJ ),
128 T01(
"consensus-method", K_CONSENSUS_METHOD,
EQ(1),
NO_OBJ),
131 T01(
"shared-rand-previous-value", K_PREVIOUS_SRV,
EQ(2),
NO_OBJ ),
132 T01(
"shared-rand-current-value", K_CURRENT_SRV,
EQ(2),
NO_OBJ ),
134 T01(
"recommended-client-protocols", K_RECOMMENDED_CLIENT_PROTOCOLS,
136 T01(
"recommended-relay-protocols", K_RECOMMENDED_RELAY_PROTOCOLS,
138 T01(
"required-client-protocols", K_REQUIRED_CLIENT_PROTOCOLS,
140 T01(
"required-relay-protocols", K_REQUIRED_RELAY_PROTOCOLS,
149 static token_rule_t networkstatus_vote_footer_token_table[] = {
152 T(
"directory-signature", K_DIRECTORY_SIGNATURE,
GE(2),
NEED_OBJ ),
165 const char **start_out,
166 const char **end_out)
169 "network-status-version",
170 "\ndirectory-signature",
180 const char *s,
size_t len)
182 const char *start, *end;
201 "network-status-version",
202 "\ndirectory-signature",
210 static inline const char *
211 find_start_of_next_routerstatus(
const char *s,
const char *s_eos)
213 const char *eos, *footer, *sig;
214 if ((eos = tor_memstr(s, s_eos - s,
"\nr ")))
219 footer = tor_memstr(s, eos-s,
"\ndirectory-footer");
220 sig = tor_memstr(s, eos-s,
"\ndirectory-signature");
223 return MIN(footer, sig) + 1;
238 routerstatus_parse_guardfraction(
const char *guardfraction_str,
244 const char *end_of_header = NULL;
245 int is_consensus = !vote_rs;
246 uint32_t guardfraction;
256 end_of_header = strchr(guardfraction_str,
'=');
257 if (!end_of_header) {
262 10, 0, 100, &ok, NULL);
264 log_warn(
LD_DIR,
"Invalid GuardFraction %s",
escaped(guardfraction_str));
268 log_debug(
LD_GENERAL,
"[*] Parsed %s guardfraction '%s' for '%s'.",
269 is_consensus ?
"consensus" :
"vote",
281 log_warn(
LD_BUG,
"Got GuardFraction for non-guard %s. "
282 "This is not supposed to happen. Not applying. ", rs->
nickname);
304 routerstatus_parse_entry_from_string(
memarea_t *area,
305 const char **s,
const char *s_eos,
309 int consensus_method,
312 const char *eos, *s_dup = *s;
315 char timebuf[ISO_TIME_LEN+1];
321 if (!consensus_method)
323 tor_assert(flav == FLAV_NS || flav == FLAV_MICRODESC);
325 eos = find_start_of_next_routerstatus(*s, s_eos);
328 log_warn(
LD_DIR,
"Error tokenizing router status");
331 if (smartlist_len(tokens) < 1) {
332 log_warn(
LD_DIR,
"Impossibly short router status");
335 tok = find_by_keyword(tokens, K_R);
337 if (flav == FLAV_NS) {
339 log_warn(
LD_DIR,
"Too few arguments to r");
342 }
else if (flav == FLAV_MICRODESC) {
354 "Invalid nickname %s in router status; skipping.",
361 log_warn(
LD_DIR,
"Error decoding identity digest %s",
366 if (flav == FLAV_NS) {
368 log_warn(
LD_DIR,
"Error decoding descriptor digest %s",
375 tok->
args[3+offset], tok->
args[4+offset]) < 0 ||
377 log_warn(
LD_DIR,
"Error parsing time '%s %s' [%d %d]",
378 tok->
args[3+offset], tok->
args[4+offset],
384 log_warn(
LD_DIR,
"Error parsing router address in network-status %s",
391 10,0,65535,NULL,NULL);
393 10,0,65535,NULL,NULL);
399 smartlist_free(a_lines);
407 for (i=0; i < tok->
n_args; ++i) {
410 vote_rs->
flags |= (UINT64_C(1)<<p);
412 log_warn(
LD_DIR,
"Flags line had a flag %s not listed in known_flags.",
420 for (i=0; i < tok->
n_args; ++i) {
421 if (!strcmp(tok->
args[i],
"Exit"))
423 else if (!strcmp(tok->
args[i],
"Stable"))
425 else if (!strcmp(tok->
args[i],
"Fast"))
427 else if (!strcmp(tok->
args[i],
"Running"))
429 else if (!strcmp(tok->
args[i],
"Named"))
431 else if (!strcmp(tok->
args[i],
"Valid"))
433 else if (!strcmp(tok->
args[i],
"Guard"))
435 else if (!strcmp(tok->
args[i],
"BadExit"))
437 else if (!strcmp(tok->
args[i],
"Authority"))
439 else if (!strcmp(tok->
args[i],
"Unnamed") &&
440 consensus_method >= 2) {
443 }
else if (!strcmp(tok->
args[i],
"HSDir")) {
445 }
else if (!strcmp(tok->
args[i],
"V2Dir")) {
447 }
else if (!strcmp(tok->
args[i],
"StaleDesc")) {
449 }
else if (!strcmp(tok->
args[i],
"Sybil")) {
459 const char *protocols = NULL, *version = NULL;
462 protocols = tok->
args[0];
466 version = tok->
args[0];
482 for (i=0; i < tok->
n_args; ++i) {
498 10, 0, UINT32_MAX, &ok, NULL);
500 log_warn(
LD_DIR,
"Invalid Measured Bandwidth %s",
509 if (routerstatus_parse_guardfraction(tok->
args[i],
510 vote, vote_rs, rs) < 0) {
522 log_warn(
LD_DIR,
"Unknown exit policy summary type %s.",
536 if (t->tp == K_M && t->n_args) {
545 if (!strcmp(t->args[0],
"ed25519")) {
547 if (strcmp(t->args[1],
"none") &&
550 log_warn(
LD_DIR,
"Bogus ed25519 key in networkstatus vote");
555 if (t->tp == K_PROTO) {
557 vote_rs->
protocols = tor_strdup(t->args[0]);
559 } SMARTLIST_FOREACH_END(t);
560 }
else if (flav == FLAV_MICRODESC) {
565 log_warn(
LD_DIR,
"Error decoding microdescriptor digest %s",
570 log_info(
LD_BUG,
"Found an entry in networkstatus with no "
571 "microdescriptor digest. (Router %s ($%s) at %s:%d.)",
584 routerstatus_free(rs);
590 DUMP_AREA(area,
"routerstatus entry");
599 compare_vote_routerstatus_entries(
const void **_a,
const void **_b)
610 int64_t G=0, M=0, E=0, D=0,
T=0;
611 double Wgg, Wgm, Wgd, Wmg, Wmm, Wme, Wmd, Weg, Wem, Wee, Wed;
612 double Gtotal=0, Mtotal=0, Etotal=0;
613 const char *casename = NULL;
615 (void) consensus_method;
631 if (Wgg<0 || Wgm<0 || Wgd<0 || Wmg<0 || Wmm<0 || Wme<0 || Wmd<0 || Weg<0
632 || Wem<0 || Wee<0 || Wed<0) {
633 log_warn(
LD_BUG,
"No bandwidth weights produced in consensus!");
640 if (fabs(Wmm - weight_scale) > 1) {
641 log_warn(
LD_BUG,
"Wmm=%f != %"PRId64,
642 Wmm, (weight_scale));
646 if (fabs(Wem - Wee) > 1) {
647 log_warn(
LD_BUG,
"Wem=%f != Wee=%f", Wem, Wee);
651 if (fabs(Wgm - Wgg) > 1) {
652 log_warn(
LD_BUG,
"Wgm=%f != Wgg=%f", Wgm, Wgg);
656 if (fabs(Weg - Wed) > 1) {
657 log_warn(
LD_BUG,
"Wed=%f != Weg=%f", Wed, Weg);
661 if (fabs(Wgg + Wmg - weight_scale) > 0.001*weight_scale) {
662 log_warn(
LD_BUG,
"Wgg=%f != %"PRId64
" - Wmg=%f", Wgg,
663 (weight_scale), Wmg);
667 if (fabs(Wee + Wme - weight_scale) > 0.001*weight_scale) {
668 log_warn(
LD_BUG,
"Wee=%f != %"PRId64
" - Wme=%f", Wee,
669 (weight_scale), Wme);
673 if (fabs(Wgd + Wmd + Wed - weight_scale) > 0.001*weight_scale) {
674 log_warn(
LD_BUG,
"Wgd=%f + Wmd=%f + Wed=%f != %"PRId64,
675 Wgd, Wmd, Wed, (weight_scale));
680 Wgm /= weight_scale; (void) Wgm;
688 Weg /= weight_scale; (void) Weg;
689 Wem /= weight_scale; (void) Wem;
705 }
else if (is_exit) {
718 log_warn(
LD_BUG,
"Missing consensus bandwidth for router %s",
721 } SMARTLIST_FOREACH_END(rs);
727 if (3*E >=
T && 3*G >=
T) {
730 if (fabs(Etotal-Mtotal) > 0.01*
MAX(Etotal,Mtotal)) {
732 "Bw Weight Failure for %s: Etotal %f != Mtotal %f. "
733 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
735 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
736 casename, Etotal, Mtotal,
739 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
742 if (fabs(Etotal-Gtotal) > 0.01*
MAX(Etotal,Gtotal)) {
744 "Bw Weight Failure for %s: Etotal %f != Gtotal %f. "
745 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
747 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
748 casename, Etotal, Gtotal,
751 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
754 if (fabs(Gtotal-Mtotal) > 0.01*
MAX(Gtotal,Mtotal)) {
756 "Bw Weight Failure for %s: Mtotal %f != Gtotal %f. "
757 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
759 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
760 casename, Mtotal, Gtotal,
763 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
766 }
else if (3*E <
T && 3*G <
T) {
767 int64_t R = MIN(E, G);
768 int64_t S =
MAX(E, G);
776 double Rtotal, Stotal;
784 casename =
"Case 2a";
786 if (Rtotal > Stotal) {
788 "Bw Weight Failure for %s: Rtotal %f > Stotal %f. "
789 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
791 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
792 casename, Rtotal, Stotal,
795 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
801 "Bw Weight Failure for %s: 3*Rtotal %f > T "
802 "%"PRId64
". G=%"PRId64
" M=%"PRId64
" E=%"PRId64
803 " D=%"PRId64
" T=%"PRId64
". "
804 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
805 casename, Rtotal*3, (
T),
808 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
814 "Bw Weight Failure for %s: 3*Stotal %f > T "
815 "%"PRId64
". G=%"PRId64
" M=%"PRId64
" E=%"PRId64
816 " D=%"PRId64
" T=%"PRId64
". "
817 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
818 casename, Stotal*3, (
T),
821 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
827 "Bw Weight Failure for %s: 3*Mtotal %f < T "
829 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
831 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
832 casename, Mtotal*3, (
T),
835 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
839 casename =
"Case 2b";
842 if (D != 0 && 3*M <
T) {
843 casename =
"Case 2b (balanced)";
844 if (fabs(Etotal-Mtotal) > 0.01*
MAX(Etotal,Mtotal)) {
846 "Bw Weight Failure for %s: Etotal %f != Mtotal %f. "
847 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
849 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
850 casename, Etotal, Mtotal,
853 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
856 if (fabs(Etotal-Gtotal) > 0.01*
MAX(Etotal,Gtotal)) {
858 "Bw Weight Failure for %s: Etotal %f != Gtotal %f. "
859 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
861 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
862 casename, Etotal, Gtotal,
865 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
868 if (fabs(Gtotal-Mtotal) > 0.01*
MAX(Gtotal,Mtotal)) {
870 "Bw Weight Failure for %s: Mtotal %f != Gtotal %f. "
871 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
873 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
874 casename, Mtotal, Gtotal,
877 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
881 if (fabs(Etotal-Gtotal) > 0.01*
MAX(Etotal,Gtotal)) {
883 "Bw Weight Failure for %s: Etotal %f != Gtotal %f. "
884 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
886 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
887 casename, Etotal, Gtotal,
890 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
896 int64_t S = MIN(E, G);
897 int64_t NS =
MAX(E, G);
902 casename =
"Case 3a (G scarce)";
906 casename =
"Case 3a (E scarce)";
913 "Bw Weight Failure for %s: 3*Stotal %f > T "
914 "%"PRId64
". G=%"PRId64
" M=%"PRId64
" E=%"PRId64
915 " D=%"PRId64
" T=%"PRId64
". "
916 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
917 casename, Stotal*3, (
T),
920 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
924 if (fabs(NStotal-Mtotal) > 0.01*
MAX(NStotal,Mtotal)) {
926 "Bw Weight Failure for %s: NStotal %f != Mtotal %f. "
927 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
929 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
930 casename, NStotal, Mtotal,
933 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
940 "Bw Weight Failure for %s: 3*NStotal %f < T "
941 "%"PRId64
". G=%"PRId64
" M=%"PRId64
942 " E=%"PRId64
" D=%"PRId64
" T=%"PRId64
". "
943 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
944 casename, NStotal*3, (
T),
947 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
952 casename =
"Case 3b";
953 if (fabs(Etotal-Mtotal) > 0.01*
MAX(Etotal,Mtotal)) {
955 "Bw Weight Failure for %s: Etotal %f != Mtotal %f. "
956 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
958 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
959 casename, Etotal, Mtotal,
962 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
965 if (fabs(Etotal-Gtotal) > 0.01*
MAX(Etotal,Gtotal)) {
967 "Bw Weight Failure for %s: Etotal %f != Gtotal %f. "
968 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
970 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
971 casename, Etotal, Gtotal,
974 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
977 if (fabs(Gtotal-Mtotal) > 0.01*
MAX(Gtotal,Mtotal)) {
979 "Bw Weight Failure for %s: Mtotal %f != Gtotal %f. "
980 "G=%"PRId64
" M=%"PRId64
" E=%"PRId64
" D=%"PRId64
982 "Wgg=%f Wgd=%f Wmg=%f Wme=%f Wmd=%f Wee=%f Wed=%f",
983 casename, Mtotal, Gtotal,
986 Wgg, Wgd, Wmg, Wme, Wmd, Wee, Wed);
993 log_notice(
LD_DIR,
"Bandwidth-weight %s is verified and valid.",
1021 for (
int i = 0; i < tok->
n_args; i++) {
1033 smartlist_free(chunks);
1042 const char *voter_identity;
1050 if (ns->
type == NS_TYPE_VOTE) {
1051 voter = smartlist_get(ns->
voters, 0);
1057 voter_identity =
"consensus";
1062 if (extract_one_srv(tokens, K_PREVIOUS_SRV, &ns->
sr_info.previous_srv) < 0) {
1063 log_warn(
LD_DIR,
"SR: Unable to parse previous SRV from %s",
1067 if (extract_one_srv(tokens, K_CURRENT_SRV, &ns->
sr_info.current_srv) < 0) {
1068 log_warn(
LD_DIR,
"SR: Unable to parse current SRV from %s",
1083 return tor_strdup(tok->
args[0]);
1091 const char **eos_out,
1095 smartlist_t *rs_tokens = NULL, *footer_tokens = NULL;
1100 const char *cert, *end_of_header, *end_of_footer, *s_dup = s;
1103 int i, inorder, n_signatures = 0;
1104 memarea_t *area = NULL, *rs_area = NULL;
1106 char *last_kwd=NULL;
1107 const char *eos = s + s_len;
1117 log_warn(
LD_DIR,
"Unable to compute digest of network-status");
1122 end_of_header = find_start_of_next_routerstatus(s, eos);
1124 (ns_type == NS_TYPE_CONSENSUS) ?
1125 networkstatus_consensus_token_table :
1126 networkstatus_token_table, 0)) {
1127 log_warn(
LD_DIR,
"Error tokenizing network-status header");
1132 memcpy(&ns->
digests, &ns_digests,
sizeof(ns_digests));
1135 tok = find_by_keyword(tokens, K_NETWORK_STATUS_VERSION);
1140 log_warn(
LD_DIR,
"Can't parse document with unknown flavor %s",
1144 ns->
flavor = flav = flavor;
1146 if (flav != FLAV_NS && ns_type != NS_TYPE_CONSENSUS) {
1147 log_warn(
LD_DIR,
"Flavor found on non-consensus networkstatus.");
1151 if (ns_type != NS_TYPE_CONSENSUS) {
1152 const char *end_of_cert = NULL;
1153 if (!(cert = tor_memstr(s, end_of_header - s,
1154 "\ndir-key-certificate-version")))
1159 if (!ns->
cert || !end_of_cert || end_of_cert > end_of_header)
1163 tok = find_by_keyword(tokens, K_VOTE_STATUS);
1165 if (!strcmp(tok->
args[0],
"vote")) {
1166 ns->
type = NS_TYPE_VOTE;
1167 }
else if (!strcmp(tok->
args[0],
"consensus")) {
1168 ns->
type = NS_TYPE_CONSENSUS;
1169 }
else if (!strcmp(tok->
args[0],
"opinion")) {
1170 ns->
type = NS_TYPE_OPINION;
1172 log_warn(
LD_DIR,
"Unrecognized vote status %s in network-status",
1176 if (ns_type != ns->
type) {
1177 log_warn(
LD_DIR,
"Got the wrong kind of v3 networkstatus.");
1181 if (ns->
type == NS_TYPE_VOTE || ns->
type == NS_TYPE_OPINION) {
1182 tok = find_by_keyword(tokens, K_PUBLISHED);
1189 for (i=0; i < tok->
n_args; ++i)
1208 bool unparseable =
false;
1209 ns->recommended_client_protocols = dup_protocols_string(tokens, &unparseable,
1210 K_RECOMMENDED_CLIENT_PROTOCOLS);
1212 K_RECOMMENDED_RELAY_PROTOCOLS);
1213 ns->required_client_protocols = dup_protocols_string(tokens, &unparseable,
1214 K_REQUIRED_CLIENT_PROTOCOLS);
1215 ns->required_relay_protocols = dup_protocols_string(tokens, &unparseable,
1216 K_REQUIRED_RELAY_PROTOCOLS);
1220 tok = find_by_keyword(tokens, K_VALID_AFTER);
1224 tok = find_by_keyword(tokens, K_FRESH_UNTIL);
1228 tok = find_by_keyword(tokens, K_VALID_UNTIL);
1232 tok = find_by_keyword(tokens, K_VOTING_DELAY);
1248 log_warn(
LD_DIR,
"Vote/consensus freshness interval is too short");
1254 log_warn(
LD_DIR,
"Vote/consensus liveness interval is too short");
1258 log_warn(
LD_DIR,
"Vote seconds is too short");
1262 log_warn(
LD_DIR,
"Dist seconds is too short");
1270 ns->server_versions = tor_strdup(tok->
args[0]);
1280 smartlist_free(package_lst);
1283 tok = find_by_keyword(tokens, K_KNOWN_FLAGS);
1286 for (i = 0; i < tok->
n_args; ++i) {
1288 if (i>0 && strcmp(tok->
args[i-1], tok->
args[i])>= 0) {
1294 log_warn(
LD_DIR,
"known-flags not in order");
1297 if (ns->
type != NS_TYPE_CONSENSUS &&
1304 log_warn(
LD_DIR,
"Too many known-flags in consensus vote or opinion");
1313 for (i = 0; i < tok->
n_args; ++i) {
1315 char *eq = strchr(tok->
args[i],
'=');
1321 eq_pos = eq-tok->
args[i];
1327 if (i > 0 && strcmp(tok->
args[i-1], tok->
args[i]) >= 0) {
1331 if (last_kwd && eq_pos == strlen(last_kwd) &&
1333 log_warn(
LD_DIR,
"Duplicate value for %s parameter",
1338 last_kwd = tor_strndup(tok->
args[i], eq_pos);
1342 log_warn(
LD_DIR,
"params not in order");
1346 log_warn(
LD_DIR,
"Duplicate in parameters");
1355 if (tok->
tp == K_DIR_SOURCE) {
1362 if (ns->
type != NS_TYPE_CONSENSUS)
1370 log_warn(
LD_DIR,
"Error decoding identity digest %s in "
1371 "network-status document.",
escaped(tok->
args[1]));
1374 if (ns->
type != NS_TYPE_CONSENSUS &&
1377 log_warn(
LD_DIR,
"Mismatch between identities in certificate and vote");
1380 if (ns->
type != NS_TYPE_CONSENSUS) {
1382 log_warn(
LD_DIR,
"Rejecting vote signature made with denylisted "
1390 log_warn(
LD_DIR,
"Error decoding IP address %s in network-status.",
1404 }
else if (tok->
tp == K_CONTACT) {
1405 if (!voter || voter->
contact) {
1406 log_warn(
LD_DIR,
"contact element is out of place.");
1410 }
else if (tok->
tp == K_VOTE_DIGEST) {
1414 log_warn(
LD_DIR,
"vote-digest element is out of place.");
1421 log_warn(
LD_DIR,
"Error decoding vote digest %s in "
1422 "network-status consensus.",
escaped(tok->
args[0]));
1426 } SMARTLIST_FOREACH_END(_tok);
1431 if (smartlist_len(ns->
voters) == 0) {
1432 log_warn(
LD_DIR,
"Missing dir-source elements in a networkstatus.");
1434 }
else if (ns->
type != NS_TYPE_CONSENSUS && smartlist_len(ns->
voters) != 1) {
1435 log_warn(
LD_DIR,
"Too many dir-source elements in a vote networkstatus.");
1439 if (ns->
type != NS_TYPE_CONSENSUS &&
1451 log_warn(
LD_DIR,
"Invalid legacy key digest %s on vote.",
1458 if (ns->
type == NS_TYPE_VOTE) {
1459 dirvote_parse_sr_commits(ns, tokens);
1462 if (ns->
type == NS_TYPE_VOTE || ns->
type == NS_TYPE_CONSENSUS) {
1463 extract_shared_random_srvs(ns, tokens);
1472 while (eos - s >= 2 &&
fast_memeq(s,
"r ", 2)) {
1473 if (ns->
type != NS_TYPE_CONSENSUS) {
1475 if (routerstatus_parse_entry_from_string(rs_area, &s, eos, rs_tokens, ns,
1479 vote_routerstatus_free(rs);
1484 if ((rs = routerstatus_parse_entry_from_string(rs_area, &s, eos,
1498 if (ns->
type != NS_TYPE_CONSENSUS) {
1508 log_warn(
LD_DIR,
"Networkstatus entries not sorted by identity digest");
1512 if (ns_type != NS_TYPE_CONSENSUS) {
1513 digest256map_t *ed_id_map = digest256map_new();
1516 if (! vrs->has_ed25519_listing ||
1519 if (digest256map_get(ed_id_map, vrs->ed25519_id) != NULL) {
1520 log_warn(
LD_DIR,
"Vote networkstatus ed25519 identities were not "
1522 digest256map_free(ed_id_map, NULL);
1525 digest256map_set(ed_id_map, vrs->ed25519_id, (
void*)1);
1526 } SMARTLIST_FOREACH_END(vrs);
1527 digest256map_free(ed_id_map, NULL);
1532 if ((end_of_footer = tor_memstr(s, eos-s,
"\nnetwork-status-version ")))
1535 end_of_footer = eos;
1537 networkstatus_vote_footer_token_table, 0)) {
1538 log_warn(
LD_DIR,
"Error tokenizing network-status vote footer.");
1546 if (tok->
tp == K_DIRECTORY_SIGNATURE)
1548 else if (found_sig) {
1549 log_warn(
LD_DIR,
"Extraneous token after first directory-signature");
1552 } SMARTLIST_FOREACH_END(_tok);
1556 if (tok != smartlist_get(footer_tokens, 0)) {
1557 log_warn(
LD_DIR,
"Misplaced directory-footer token");
1565 for (i = 0; i < tok->
n_args; ++i) {
1567 char *eq = strchr(tok->
args[i],
'=');
1569 log_warn(
LD_DIR,
"Bad element '%s' in weight params",
1586 const char *id_hexdigest = NULL;
1587 const char *sk_hexdigest = NULL;
1590 if (tok->
tp != K_DIRECTORY_SIGNATURE)
1594 id_hexdigest = tok->
args[0];
1595 sk_hexdigest = tok->
args[1];
1597 const char *algname = tok->
args[0];
1599 id_hexdigest = tok->
args[1];
1600 sk_hexdigest = tok->
args[2];
1603 log_warn(
LD_DIR,
"Unknown digest algorithm %s; skipping",
1613 log_warn(
LD_DIR,
"Bad object type or length on directory-signature");
1620 !=
sizeof(declared_identity)) {
1621 log_warn(
LD_DIR,
"Error decoding declared identity %s in "
1622 "network-status document.",
escaped(id_hexdigest));
1626 log_warn(
LD_DIR,
"ID on signature on network-status document does "
1627 "not match any declared directory source.");
1637 log_warn(
LD_DIR,
"Error decoding declared signing key digest %s in "
1638 "network-status document.",
escaped(sk_hexdigest));
1643 if (ns->
type != NS_TYPE_CONSENSUS) {
1646 log_warn(
LD_DIR,
"Digest mismatch between declared and actual on "
1647 "network-status vote.");
1656 log_fn(LOG_PROTOCOL_WARN,
LD_DIR,
"We received a networkstatus "
1657 "that contains two signatures from the same voter with the same "
1658 "algorithm. Ignoring the second signature.");
1663 if (ns->
type != NS_TYPE_CONSENSUS) {
1666 "network-status document")) {
1682 } SMARTLIST_FOREACH_END(_tok);
1684 if (! n_signatures) {
1685 log_warn(
LD_DIR,
"No signatures on networkstatus document.");
1687 }
else if (ns->
type == NS_TYPE_VOTE && n_signatures != 1) {
1688 log_warn(
LD_DIR,
"Received more than one signature on a "
1689 "network-status vote.");
1694 *eos_out = end_of_footer;
1699 networkstatus_vote_free(ns);
1704 smartlist_free(tokens);
1709 document_signature_free(sig));
1710 smartlist_free(voter->
sigs);
1719 smartlist_free(rs_tokens);
1721 if (footer_tokens) {
1723 smartlist_free(footer_tokens);
1726 DUMP_AREA(area,
"v3 networkstatus");
#define tor_addr_from_in(dest, in)
int authority_cert_is_denylisted(const authority_cert_t *cert)
Header file for authcert.c.
List of tokens common to V3 authority certificates and V3 consensuses.
authority_cert_t * authority_cert_parse_from_string(const char *s, size_t maxlen, const char **end_of_string)
Header file for authcert_parse.c.
Authority certificate structure.
const char * hex_str(const char *from, size_t fromlen)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
const or_options_t * get_options(void)
Header file for config.c.
int crypto_digest_algorithm_parse_name(const char *name)
int crypto_digest256(char *digest, const char *m, size_t len, digest_algorithm_t algorithm)
const char * routerstatus_describe(const routerstatus_t *rs)
Header file for describe.c.
#define fast_memeq(a, b, c)
#define fast_memcmp(a, b, c)
#define tor_memneq(a, b, sz)
Header file for dirvote.c.
#define MIN_VOTE_INTERVAL_TESTING
#define MIN_VOTE_INTERVAL
Authority signature structure.
int should_apply_guardfraction(const networkstatus_t *ns)
Header file for circuitbuild.c.
const char * escaped(const char *s)
int tor_inet_aton(const char *str, struct in_addr *addr)
#define log_fn(severity, domain, args,...)
void memarea_clear(memarea_t *area)
memarea_t * memarea_new(void)
#define memarea_drop_all(area)
int networkstatus_parse_flavor_name(const char *flavname)
networkstatus_voter_info_t * networkstatus_get_voter_by_id(networkstatus_t *vote, const char *identity)
int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight_name, int32_t default_val)
document_signature_t * networkstatus_get_voter_sig_by_alg(const networkstatus_voter_info_t *voter, digest_algorithm_t alg)
int networkstatus_get_weight_scale_param(networkstatus_t *ns)
Header file for networkstatus.c.
Networkstatus consensus/vote structure.
Single consensus voter structure.
int is_legal_nickname(const char *s)
Header file for nickname.c.
Header file for ns_parse.c.
int router_get_networkstatus_v3_sha3_as_signed(uint8_t *digest_out, const char *s, size_t len)
networkstatus_t * networkstatus_parse_vote_from_string(const char *s, size_t len, const char **eos_out, enum networkstatus_type_t ns_type)
int router_get_networkstatus_v3_signed_boundaries(const char *s, size_t len, const char **start_out, const char **end_out)
int networkstatus_verify_bw_weights(networkstatus_t *ns, int)
int router_get_networkstatus_v3_hashes(const char *s, size_t len, common_digests_t *digests)
Master header file for Tor-specific functionality.
#define UNNAMED_ROUTER_NICKNAME
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
unsigned long tor_parse_ulong(const char *s, int base, unsigned long min, unsigned long max, int *ok, char **next)
void token_clear(directory_token_t *tok)
int tokenize_string(memarea_t *area, const char *start, const char *end, smartlist_t *out, const token_rule_t *table, int flags)
directory_token_t * find_opt_by_keyword(const smartlist_t *s, directory_keyword keyword)
smartlist_t * find_all_by_keyword(const smartlist_t *s, directory_keyword k)
Header file for parsecommon.c.
#define T1_START(s, t, a, o)
int tor_snprintf(char *str, size_t size, const char *format,...)
bool protover_list_is_invalid(const char *s)
Headers and type declarations for protover.c.
int find_single_ipv6_orport(const smartlist_t *list, tor_addr_t *addr_out, uint16_t *port_out)
Header file for routerparse.c.
sr_srv_t * sr_parse_srv(const smartlist_t *args)
Header file for shared_random_client.c.
int check_signature_token(const char *digest, ssize_t digest_len, directory_token_t *tok, crypto_pk_t *pkey, int flags, const char *doctype)
int router_get_hash_impl_helper(const char *s, size_t s_len, const char *start_str, const char *end_str, char end_c, int log_severity, const char **start_out, const char **end_out)
int router_get_hashes_impl(const char *s, size_t s_len, common_digests_t *digests, const char *start_str, const char *end_str, char end_c)
Header file for sigcommon.c.
int smartlist_string_pos(const smartlist_t *sl, const char *element)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_clear(smartlist_t *sl)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
crypto_pk_t * signing_key
char signing_key_digest[DIGEST_LEN]
signed_descriptor_t cache_info
char d[N_COMMON_DIGEST_ALGORITHMS][DIGEST256_LEN]
unsigned int good_signature
char identity_digest[DIGEST_LEN]
char signing_key_digest[DIGEST_LEN]
smartlist_t * known_flags
char * recommended_relay_protocols
smartlist_t * weight_params
smartlist_t * package_lines
smartlist_t * supported_methods
smartlist_t * routerstatus_list
unsigned int has_measured_bws
networkstatus_sr_info_t sr_info
uint8_t digest_sha3_as_signed[DIGEST256_LEN]
struct authority_cert_t * cert
consensus_flavor_t flavor
networkstatus_type_t type
char legacy_id_digest[DIGEST_LEN]
char identity_digest[DIGEST_LEN]
char vote_digest[DIGEST_LEN]
protover_summary_flags_t pv
unsigned int is_staledesc
char descriptor_digest[DIGEST256_LEN]
unsigned int has_exitsummary
char identity_digest[DIGEST_LEN]
unsigned int has_guardfraction
unsigned int bw_is_unmeasured
char nickname[MAX_NICKNAME_LEN+1]
unsigned int has_bandwidth
unsigned int is_possible_guard
unsigned int is_flagged_running
unsigned int is_authority
uint32_t guardfraction_percentage
char identity_digest[DIGEST_LEN]
struct vote_microdesc_hash_t * next
char * microdesc_hash_line
uint8_t ed25519_id[ED25519_PUBKEY_LEN]
unsigned int has_ed25519_listing
vote_microdesc_hash_t * microdesc
unsigned int has_measured_bw
int parse_iso_time(const char *cp, time_t *t)
void dump_desc(const char *desc, const char *type)
Header file for unparseable.c.
int strcmpstart(const char *s1, const char *s2)
int fast_mem_is_zero(const char *mem, size_t len)
int tor_digest_is_zero(const char *digest)
void summarize_protover_flags(protover_summary_flags_t *out, const char *protocols, const char *version)
Header file for versions.c.
Microdescriptor-hash voting structure.
Routerstatus (vote entry) structure.
#define MAX_KNOWN_FLAGS_IN_VOTE