diff options
author | George Kadianakis <desnacked@riseup.net> | 2021-05-05 11:05:09 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2021-05-05 11:05:45 +0300 |
commit | f230beadf469e300c783791847a346c593033dd0 (patch) | |
tree | 61347ac86393d40795eed3b1b89878097c416399 /src/core/or | |
parent | cf6e72b7020c47ba20677dc19602663723bd8491 (diff) | |
download | tor-f230beadf469e300c783791847a346c593033dd0.tar.gz tor-f230beadf469e300c783791847a346c593033dd0.zip |
Prepare for #40373: Re-introduce parsing for v2 onion addresses.
Welcome back ONION_V2_HOSTNAME! :)
Diffstat (limited to 'src/core/or')
-rw-r--r-- | src/core/or/connection_edge.c | 28 | ||||
-rw-r--r-- | src/core/or/connection_edge.h | 1 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c index b89f3336dc..8e13161348 100644 --- a/src/core/or/connection_edge.c +++ b/src/core/or/connection_edge.c @@ -1612,6 +1612,23 @@ consider_plaintext_ports(entry_connection_t *conn, uint16_t port) return 0; } +/** Return true iff <b>query</b> is a syntactically valid service ID (as + * generated by rend_get_service_id). */ +static int +rend_valid_v2_service_id(const char *query) +{ + /** Length of 'y' portion of 'y.onion' URL. */ +#define REND_SERVICE_ID_LEN_BASE32 16 + + if (strlen(query) != REND_SERVICE_ID_LEN_BASE32) + return 0; + + if (strspn(query, BASE32_CHARS) != REND_SERVICE_ID_LEN_BASE32) + return 0; + + return 1; +} + /** Parse the given hostname in address. Returns true if the parsing was * successful and type_out contains the type of the hostname. Else, false is * returned which means it was not recognized and type_out is set to @@ -1675,6 +1692,14 @@ parse_extended_hostname(char *address, hostname_type_t *type_out) if (q != address) { memmove(address, q, strlen(q) + 1 /* also get \0 */); } + /* v2 onion address check. */ + if (strlen(query) == REND_SERVICE_ID_LEN_BASE32) { + *type_out = ONION_V2_HOSTNAME; + if (rend_valid_v2_service_id(query)) { + goto success; + } + goto failed; + } /* v3 onion address check. */ if (strlen(query) == HS_SERVICE_ADDR_LEN_BASE32) { @@ -1694,7 +1719,8 @@ parse_extended_hostname(char *address, hostname_type_t *type_out) failed: /* otherwise, return to previous state and return 0 */ *s = '.'; - const bool is_onion = (*type_out == ONION_V3_HOSTNAME); + const bool is_onion = (*type_out == ONION_V2_HOSTNAME) || + (*type_out == ONION_V3_HOSTNAME); log_warn(LD_APP, "Invalid %shostname %s; rejecting", is_onion ? "onion " : "", safe_str_client(address)); diff --git a/src/core/or/connection_edge.h b/src/core/or/connection_edge.h index 966a9391d8..72869f348b 100644 --- a/src/core/or/connection_edge.h +++ b/src/core/or/connection_edge.h @@ -80,6 +80,7 @@ typedef enum hostname_type_t { BAD_HOSTNAME, EXIT_HOSTNAME, NORMAL_HOSTNAME, + ONION_V2_HOSTNAME, ONION_V3_HOSTNAME, } hostname_type_t; |