Ticket #18620: tor.patch

File tor.patch, 5.6 KB (added by str4d, 3 years ago)

Patch to implement HSFORGET command in Tor 0.2.7.6

  • src/or/control.c

    diff --git a/src/or/control.c b/src/or/control.c
    index 220e7e5..a54c8a2 100644
    a b static int handle_control_hsfetch(control_connection_t *conn, uint32_t len, 
    176176                                  const char *body);
    177177static int handle_control_hspost(control_connection_t *conn, uint32_t len,
    178178                                 const char *body);
     179static int handle_control_hsforget(control_connection_t *conn, uint32_t len,
     180                                   const char *body);
    179181static int handle_control_add_onion(control_connection_t *conn, uint32_t len,
    180182                                    const char *body);
    181183static int handle_control_del_onion(control_connection_t *conn, uint32_t len,
    handle_control_hspost(control_connection_t *conn, 
    37253727  return 0;
    37263728}
    37273729
     3730/** Called when we get an HSFORGET command: parse the hidden service's onion
     3731 * address and purge any cached state related to the service. */
     3732static int
     3733handle_control_hsforget(control_connection_t *conn, uint32_t len,
     3734                        const char *body)
     3735{
     3736  smartlist_t *args;
     3737  char *onion_address;
     3738
     3739  args = getargs_helper("HSFORGET", conn, body, 1, 1);
     3740  if (!args)
     3741    return -1;
     3742  onion_address = smartlist_get(args, 0);
     3743  smartlist_free(args);
     3744
     3745  if (!rend_valid_service_id(onion_address)) {
     3746    connection_write_str_to_buf("513 Invalid hidden service address\r\n", conn);
     3747    tor_free(onion_address);
     3748    return -1;
     3749  }
     3750
     3751  rend_client_purge_hidden_service(onion_address);
     3752  tor_free(onion_address);
     3753  send_control_done(conn);
     3754  return 0;
     3755}
     3756
    37283757/** Called when we get a ADD_ONION command; parse the body, and set up
    37293758 * the new ephemeral Onion Service. */
    37303759static int
    connection_control_process_inbuf(control_connection_t *conn) 
    43964425  } else if (!strcasecmp(conn->incoming_cmd, "+HSPOST")) {
    43974426    if (handle_control_hspost(conn, cmd_data_len, args))
    43984427      return -1;
     4428  } else if (!strcasecmp(conn->incoming_cmd, "HSFORGET")) {
     4429    if (handle_control_hsforget(conn, cmd_data_len, args))
     4430      return -1;
    43994431  } else if (!strcasecmp(conn->incoming_cmd, "ADD_ONION")) {
    44004432    int ret = handle_control_add_onion(conn, cmd_data_len, args);
    44014433    memwipe(args, 0, cmd_data_len); /* Scrub the private key. */
  • src/or/rendcache.c

    diff --git a/src/or/rendcache.c b/src/or/rendcache.c
    index d4bdd68..b9d79b8 100644
    a b rend_cache_lookup_entry(const char *query, int version, rend_cache_entry_t **e) 
    535535  return ret;
    536536}
    537537
     538/** Remove any cached descriptors for <b>service_id</b>. */
     539void
     540rend_cache_remove_entry(const char *service_id)
     541{
     542  char key[REND_SERVICE_ID_LEN_BASE32 + 2]; /* <version><service_id>\0 */
     543  rend_cache_entry_t *removed;
     544
     545  tor_assert(rend_valid_service_id(service_id));
     546  if (!rend_cache)
     547    return;
     548
     549  tor_snprintf(key, sizeof(key), "2%s", service_id);
     550  removed = strmap_remove_lc(rend_cache, key);
     551  if (removed) {
     552    log_info(LD_REND, "Removed cached v2 descriptor for service %s.",
     553               safe_str_client(service_id));
     554    rend_cache_entry_free(removed);
     555  }
     556
     557  tor_snprintf(key, sizeof(key), "0%s", service_id);
     558  removed = strmap_remove_lc(rend_cache, key);
     559  if (removed) {
     560    log_info(LD_REND, "Removed cached v0 descriptor for service %s.",
     561               safe_str_client(service_id));
     562    rend_cache_entry_free(removed);
     563  }
     564}
     565
    538566/** Lookup the v2 service descriptor with base32-encoded <b>desc_id</b> and
    539567 * copy the pointer to it to *<b>desc</b>.  Return 1 on success, 0 on
    540568 * well-formed-but-not-found, and -1 on failure.
  • src/or/rendcache.h

    diff --git a/src/or/rendcache.h b/src/or/rendcache.h
    index 0512058..2c8ebfd 100644
    a b void rend_cache_purge(void); 
    5656void rend_cache_free_all(void);
    5757int rend_cache_lookup_entry(const char *query, int version,
    5858                            rend_cache_entry_t **entry_out);
     59void rend_cache_remove_entry(const char *service_id);
    5960int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
    6061/** Return value from rend_cache_store_v2_desc_as_{dir,client}. */
    6162typedef enum {
  • src/or/rendclient.c

    diff --git a/src/or/rendclient.c b/src/or/rendclient.c
    index a39e518..909e47f 100644
    a b static extend_info_t *rend_client_get_random_intro_impl( 
    3232                          const rend_cache_entry_t *rend_query,
    3333                          const int strict, const int warnings);
    3434
     35static void purge_hid_serv_from_last_hid_serv_requests(
     36                          const char *onion_address);
     37
    3538/** Purge all potentially remotely-detectable state held in the hidden
    3639 * service client code.  Called on SIGNAL NEWNYM. */
    3740void
    rend_client_purge_state(void) 
    4346  rend_client_purge_last_hid_serv_requests();
    4447}
    4548
     49/** Purge all cached state relating to the given hidden service. */
     50void
     51rend_client_purge_hidden_service(const char *onion_address)
     52{
     53  tor_assert(rend_valid_service_id(onion_address));
     54  rend_cache_remove_entry(onion_address);
     55  purge_hid_serv_from_last_hid_serv_requests(onion_address);
     56}
     57
    4658/** Called when we've established a circuit to an introduction point:
    4759 * send the introduction request. */
    4860void
  • src/or/rendclient.h

    diff --git a/src/or/rendclient.h b/src/or/rendclient.h
    index 124433e..b27d2db 100644
    a b  
    1515#include "rendcache.h"
    1616
    1717void rend_client_purge_state(void);
     18void rend_client_purge_hidden_service(const char *onion_address);
    1819
    1920void rend_client_introcirc_has_opened(origin_circuit_t *circ);
    2021void rend_client_rendcirc_has_opened(origin_circuit_t *circ);