mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
teach alice to recognize y.onion addresses
svn:r1430
This commit is contained in:
parent
7993382ba1
commit
f05937355e
1 changed files with 29 additions and 2 deletions
|
@ -177,12 +177,27 @@ void rend_cache_clean(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return 1 if query is a valid service id, else return 0. */
|
||||||
|
int rend_valid_service_id(char *query) {
|
||||||
|
if(strlen(query) != REND_SERVICE_ID_LEN)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* XXXX also check for bad chars. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 'query' is a base-32'ed service id. If it's malformed, return -1.
|
||||||
|
* Else look it up.
|
||||||
|
* If it is found, point *desc to it, and write its length into
|
||||||
|
* *desc_len, and return 1.
|
||||||
|
* If it is not found, return 0.
|
||||||
|
*/
|
||||||
int rend_cache_lookup(char *query, const char **desc, int *desc_len)
|
int rend_cache_lookup(char *query, const char **desc, int *desc_len)
|
||||||
{
|
{
|
||||||
rend_cache_entry_t *e;
|
rend_cache_entry_t *e;
|
||||||
assert(rend_cache);
|
assert(rend_cache);
|
||||||
if (strlen(query) != REND_SERVICE_ID_LEN)
|
if (!rend_valid_service_id(query))
|
||||||
return -1; /* XXXX also check for bad chars. */
|
return -1;
|
||||||
e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, query);
|
e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, query);
|
||||||
if (!e)
|
if (!e)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -191,6 +206,9 @@ int rend_cache_lookup(char *query, const char **desc, int *desc_len)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calculate desc's service id, and store it.
|
||||||
|
* Return -1 if it's malformed or otherwise rejected, else return 0.
|
||||||
|
*/
|
||||||
int rend_cache_store(char *desc, int desc_len)
|
int rend_cache_store(char *desc, int desc_len)
|
||||||
{
|
{
|
||||||
rend_cache_entry_t *e;
|
rend_cache_entry_t *e;
|
||||||
|
@ -251,8 +269,17 @@ int rend_cache_store(char *desc, int desc_len)
|
||||||
* Else return -1 and change nothing.
|
* Else return -1 and change nothing.
|
||||||
*/
|
*/
|
||||||
int rend_parse_rendezvous_address(char *address) {
|
int rend_parse_rendezvous_address(char *address) {
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
s = strchr(address,'.');
|
||||||
|
if(!s) return -1; /* no dot */
|
||||||
|
if(strcmp(s+1,"onion")) return -1; /* not .onion */
|
||||||
|
|
||||||
|
*s = 0; /* null terminate it */
|
||||||
|
if(rend_valid_service_id(address))
|
||||||
|
return 0; /* success */
|
||||||
|
/* otherwise, return to previous state and return -1 */
|
||||||
|
*s = '.';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue