r13021@Kushana: nickm | 2007-05-20 14:03:10 -0400

Provide actual reasons when dropping an uploaded extrainfo for incompatibility; also, clean whitespace.


svn:r10230
This commit is contained in:
Nick Mathewson 2007-05-20 18:03:26 +00:00
parent 5364833be0
commit 21a72520ce
6 changed files with 26 additions and 18 deletions

View File

@ -1973,7 +1973,8 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
case -2: case -2:
case -1: case -1:
case 1: case 1:
log_notice(LD_DIRSERV,"Rejected router descriptor from %s.", log_notice(LD_DIRSERV,
"Rejected router descriptor or extra-info from %s.",
conn->_base.address); conn->_base.address);
/* malformed descriptor, or something wrong */ /* malformed descriptor, or something wrong */
write_http_status_line(conn, 400, msg); write_http_status_line(conn, 400, msg);

View File

@ -630,8 +630,7 @@ dirserv_add_extrainfo(extrainfo_t *ei, const char **msg)
extrainfo_free(ei); extrainfo_free(ei);
return -1; return -1;
} }
if (routerinfo_incompatible_with_extrainfo(ri, ei)) { if (routerinfo_incompatible_with_extrainfo(ri, ei, msg)) {
*msg = "Router descriptor incompatible with extra-info descriptor";
extrainfo_free(ei); extrainfo_free(ei);
return -1; return -1;
} }

View File

@ -3185,7 +3185,8 @@ void networkstatus_list_update_recent(time_t now);
void router_reset_descriptor_download_failures(void); void router_reset_descriptor_download_failures(void);
void router_reset_status_download_failures(void); void router_reset_status_download_failures(void);
int router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2); int router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2);
int routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei); int routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei,
const char **msg);
const char *esc_router_info(routerinfo_t *router); const char *esc_router_info(routerinfo_t *router);
char *networkstatus_getinfo_helper_single(routerstatus_t *rs); char *networkstatus_getinfo_helper_single(routerstatus_t *rs);

View File

@ -1063,7 +1063,7 @@ router_rebuild_descriptor(int force)
ri->cache_info.signed_descriptor_body, ri->cache_info.signed_descriptor_body,
ri->cache_info.signed_descriptor_len); ri->cache_info.signed_descriptor_len);
tor_assert(! routerinfo_incompatible_with_extrainfo(ri, ei)); tor_assert(! routerinfo_incompatible_with_extrainfo(ri, ei, NULL));
if (desc_routerinfo) if (desc_routerinfo)
routerinfo_free(desc_routerinfo); routerinfo_free(desc_routerinfo);

View File

@ -1802,7 +1802,7 @@ extrainfo_insert(routerlist_t *rl, extrainfo_t *ei)
/* This router is unknown; we can't even verify the signature. Give up.*/ /* This router is unknown; we can't even verify the signature. Give up.*/
goto done; goto done;
} }
if (routerinfo_incompatible_with_extrainfo(ri, ei)) { if (routerinfo_incompatible_with_extrainfo(ri, ei, NULL)) {
if (ei->bad_sig) /* If the signature didn't check, it's just wrong. */ if (ei->bad_sig) /* If the signature didn't check, it's just wrong. */
goto done; goto done;
sd = digestmap_get(rl->desc_by_eid_map, sd = digestmap_get(rl->desc_by_eid_map,
@ -4029,7 +4029,8 @@ routerstatus_list_update_from_networkstatus(time_t now)
if ((rs_old = router_get_combined_status_by_digest(lowest))) { if ((rs_old = router_get_combined_status_by_digest(lowest))) {
if (!memcmp(rs_out->status.descriptor_digest, if (!memcmp(rs_out->status.descriptor_digest,
most_recent->descriptor_digest, DIGEST_LEN)) { most_recent->descriptor_digest, DIGEST_LEN)) {
rs_out->dl_status.n_download_failures = rs_old->dl_status.n_download_failures; rs_out->dl_status.n_download_failures =
rs_old->dl_status.n_download_failures;
rs_out->dl_status.next_attempt_at = rs_old->dl_status.next_attempt_at; rs_out->dl_status.next_attempt_at = rs_old->dl_status.next_attempt_at;
} }
rs_out->name_lookup_warned = rs_old->name_lookup_warned; rs_out->name_lookup_warned = rs_old->name_lookup_warned;
@ -4848,7 +4849,8 @@ router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2)
/** DOCDOC */ /** DOCDOC */
int int
routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei) routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei,
const char **msg)
{ {
tor_assert(ri); tor_assert(ri);
tor_assert(ei); tor_assert(ei);
@ -4860,8 +4862,10 @@ routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei)
* by the same rotuer. */ * by the same rotuer. */
if (strcmp(ri->nickname, ei->nickname) || if (strcmp(ri->nickname, ei->nickname) ||
memcmp(ri->cache_info.identity_digest, ei->cache_info.identity_digest, memcmp(ri->cache_info.identity_digest, ei->cache_info.identity_digest,
DIGEST_LEN)) DIGEST_LEN)) {
if (msg) *msg = "Extrainfo nickname or identity did not match routerinfo";
return 1; /* different servers */ return 1; /* different servers */
}
if (ei->pending_sig) { if (ei->pending_sig) {
char signed_digest[128]; char signed_digest[128];
@ -4871,20 +4875,26 @@ routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei)
DIGEST_LEN)) { DIGEST_LEN)) {
ei->bad_sig = 1; ei->bad_sig = 1;
tor_free(ei->pending_sig); tor_free(ei->pending_sig);
if (msg) *msg = "Extrainfo signature bad, or signed with wrong key";
return 1; /* Bad signature, or no match. */ return 1; /* Bad signature, or no match. */
} }
tor_free(ei->pending_sig); tor_free(ei->pending_sig);
} }
if (memcmp(ei->cache_info.signed_descriptor_digest, if (ei->cache_info.published_on < ei->cache_info.published_on) {
ri->cache_info.extra_info_digest, DIGEST_LEN)) if (msg) *msg = "Extrainfo published time did not match routerdesc";
return 1; /* Digest doesn't match declared value. */
if (ei->cache_info.published_on < ei->cache_info.published_on)
return 1; return 1;
else if (ei->cache_info.published_on > ei->cache_info.published_on) } else if (ei->cache_info.published_on > ei->cache_info.published_on) {
if (msg) *msg = "Extrainfo published time did not match routerdesc";
return -1; return -1;
}
if (memcmp(ei->cache_info.signed_descriptor_digest,
ri->cache_info.extra_info_digest, DIGEST_LEN)) {
if (msg) *msg = "Extrainfo digest did not match value from routerdesc";
return 1; /* Digest doesn't match declared value. */
}
return 0; return 0;
} }

View File

@ -1106,7 +1106,6 @@ test_smartlist(void)
test_assert(smartlist_string_isin(sl, "arma")); test_assert(smartlist_string_isin(sl, "arma"));
test_assert(smartlist_string_isin(sl, "the")); test_assert(smartlist_string_isin(sl, "the"));
/* Test bsearch. */ /* Test bsearch. */
smartlist_sort(sl, _compare_strs); smartlist_sort(sl, _compare_strs);
test_streq("nickm", smartlist_bsearch(sl, "zNicKM", test_streq("nickm", smartlist_bsearch(sl, "zNicKM",
@ -1114,8 +1113,6 @@ test_smartlist(void)
test_streq("and", smartlist_bsearch(sl, " AND", _compare_without_first_ch)); test_streq("and", smartlist_bsearch(sl, " AND", _compare_without_first_ch));
test_eq_ptr(NULL, smartlist_bsearch(sl, " ANz", _compare_without_first_ch)); test_eq_ptr(NULL, smartlist_bsearch(sl, " ANz", _compare_without_first_ch));
/* Test reverse() and pop_last() */ /* Test reverse() and pop_last() */
smartlist_reverse(sl); smartlist_reverse(sl);
cp = smartlist_join_strings(sl, ",", 0, NULL); cp = smartlist_join_strings(sl, ",", 0, NULL);