diff options
author | John Brooks <john.brooks@dereferenced.net> | 2016-02-19 16:32:25 -0700 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-05-09 14:30:34 -0400 |
commit | 162aa14eef69bc97233d6b2c47bc1317e30f9364 (patch) | |
tree | c8b768498d077a262e491b0fe4725933893b5160 /src | |
parent | dcc11674db53cc89228ec2e8d49f30bdf6c9b8a3 (diff) | |
download | tor-162aa14eef69bc97233d6b2c47bc1317e30f9364.tar.gz tor-162aa14eef69bc97233d6b2c47bc1317e30f9364.zip |
Move rend client name checks to one function
Diffstat (limited to 'src')
-rw-r--r-- | src/or/rendcommon.c | 16 | ||||
-rw-r--r-- | src/or/rendcommon.h | 1 | ||||
-rw-r--r-- | src/or/rendservice.c | 18 | ||||
-rw-r--r-- | src/or/routerparse.c | 9 |
4 files changed, 24 insertions, 20 deletions
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index a9fdf84c04..dfa6c1e8be 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -750,6 +750,22 @@ rend_valid_descriptor_id(const char *query) return 0; } +/** Return true iff <b>client_name</b> is a syntactically valid name + * for rendezvous client authentication. */ +int +rend_valid_client_name(const char *client_name) +{ + size_t len = strlen(client_name); + if (len < 1 || len > REND_CLIENTNAME_MAX_LEN) { + return 0; + } + if (strspn(client_name, REND_LEGAL_CLIENTNAME_CHARACTERS) != len) { + return 0; + } + + return 1; +} + /** Called when we get a rendezvous-related relay cell on circuit * <b>circ</b>. Dispatch on rendezvous relay command. */ void diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h index 983cd73892..f0a740b75f 100644 --- a/src/or/rendcommon.h +++ b/src/or/rendcommon.h @@ -45,6 +45,7 @@ void rend_intro_point_free(rend_intro_point_t *intro); int rend_valid_service_id(const char *query); int rend_valid_descriptor_id(const char *query); +int rend_valid_client_name(const char *client_name); int rend_encode_v2_descriptors(smartlist_t *descs_out, rend_service_descriptor_t *desc, time_t now, uint8_t period, rend_auth_type_t auth_type, diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 5b9320922b..030c836e78 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -672,27 +672,17 @@ rend_config_services(const or_options_t *options, int validate_only) SMARTLIST_FOREACH_BEGIN(clients, const char *, client_name) { rend_authorized_client_t *client; - size_t len = strlen(client_name); - if (len < 1 || len > REND_CLIENTNAME_MAX_LEN) { + if (!rend_valid_client_name(client_name)) { log_warn(LD_CONFIG, "HiddenServiceAuthorizeClient contains an " - "illegal client name: '%s'. Length must be " - "between 1 and %d characters.", + "illegal client name: '%s'. Names must be " + "between 1 and %d characters and contain " + "only [A-Za-z0-9+_-].", client_name, REND_CLIENTNAME_MAX_LEN); SMARTLIST_FOREACH(clients, char *, cp, tor_free(cp)); smartlist_free(clients); rend_service_free(service); return -1; } - if (strspn(client_name, REND_LEGAL_CLIENTNAME_CHARACTERS) != len) { - log_warn(LD_CONFIG, "HiddenServiceAuthorizeClient contains an " - "illegal client name: '%s'. Valid " - "characters are [A-Za-z0-9+_-].", - client_name); - SMARTLIST_FOREACH(clients, char *, cp, tor_free(cp)); - smartlist_free(clients); - rend_service_free(service); - return -1; - } client = tor_malloc_zero(sizeof(rend_authorized_client_t)); client->client_name = tor_strdup(client_name); smartlist_add(service->clients, client); diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 35f76cdc3e..b1ac3dfee2 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -5300,7 +5300,6 @@ rend_parse_client_keys(strmap_t *parsed_clients, const char *ckstr) current_entry = eat_whitespace(ckstr); while (!strcmpstart(current_entry, "client-name ")) { rend_authorized_client_t *parsed_entry; - size_t len; /* Determine end of string. */ const char *eos = strstr(current_entry, "\nclient-name "); if (!eos) @@ -5329,12 +5328,10 @@ rend_parse_client_keys(strmap_t *parsed_clients, const char *ckstr) tor_assert(tok == smartlist_get(tokens, 0)); tor_assert(tok->n_args == 1); - len = strlen(tok->args[0]); - if (len < 1 || len > 19 || - strspn(tok->args[0], REND_LEGAL_CLIENTNAME_CHARACTERS) != len) { + if (!rend_valid_client_name(tok->args[0])) { log_warn(LD_CONFIG, "Illegal client name: %s. (Length must be " - "between 1 and 19, and valid characters are " - "[A-Za-z0-9+-_].)", tok->args[0]); + "between 1 and %d, and valid characters are " + "[A-Za-z0-9+-_].)", tok->args[0], REND_CLIENTNAME_MAX_LEN); goto err; } /* Check if client name is duplicate. */ |