tor.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. diff --git a/src/or/control.c b/src/or/control.c
  2. index c8c5062..f38ba23 100644
  3. --- a/src/or/control.c
  4. +++ b/src/or/control.c
  5. @@ -196,6 +196,8 @@ static int handle_control_hsfetch(control_connection_t *conn, uint32_t len,
  6. const char *body);
  7. static int handle_control_hspost(control_connection_t *conn, uint32_t len,
  8. const char *body);
  9. +static int handle_control_hsforget(control_connection_t *conn, uint32_t len,
  10. + const char *body);
  11. static int handle_control_add_onion(control_connection_t *conn, uint32_t len,
  12. const char *body);
  13. static int handle_control_del_onion(control_connection_t *conn, uint32_t len,
  14. @@ -4246,6 +4248,33 @@ handle_control_hspost(control_connection_t *conn,
  15. return 0;
  16. }
  17. +/** Called when we get an HSFORGET command: parse the hidden service's onion
  18. + * address and purge any cached state related to the service. */
  19. +static int
  20. +handle_control_hsforget(control_connection_t *conn, uint32_t len,
  21. + const char *body)
  22. +{
  23. + smartlist_t *args;
  24. + char *onion_address;
  25. +
  26. + args = getargs_helper("HSFORGET", conn, body, 1, 1);
  27. + if (!args)
  28. + return -1;
  29. + onion_address = smartlist_get(args, 0);
  30. + smartlist_free(args);
  31. +
  32. + if (!rend_valid_service_id(onion_address)) {
  33. + connection_write_str_to_buf("513 Invalid hidden service address\r\n", conn);
  34. + tor_free(onion_address);
  35. + return -1;
  36. + }
  37. +
  38. + rend_client_purge_hidden_service(onion_address);
  39. + tor_free(onion_address);
  40. + send_control_done(conn);
  41. + return 0;
  42. +}
  43. +
  44. /** Called when we get a ADD_ONION command; parse the body, and set up
  45. * the new ephemeral Onion Service. */
  46. static int
  47. @@ -5065,6 +5094,9 @@ connection_control_process_inbuf(control_connection_t *conn)
  48. } else if (!strcasecmp(conn->incoming_cmd, "+HSPOST")) {
  49. if (handle_control_hspost(conn, cmd_data_len, args))
  50. return -1;
  51. + } else if (!strcasecmp(conn->incoming_cmd, "HSFORGET")) {
  52. + if (handle_control_hsforget(conn, cmd_data_len, args))
  53. + return -1;
  54. } else if (!strcasecmp(conn->incoming_cmd, "ADD_ONION")) {
  55. int ret = handle_control_add_onion(conn, cmd_data_len, args);
  56. memwipe(args, 0, cmd_data_len); /* Scrub the private key. */
  57. diff --git a/src/or/rendcache.c b/src/or/rendcache.c
  58. index aa69d73..473a6a4 100644
  59. --- a/src/or/rendcache.c
  60. +++ b/src/or/rendcache.c
  61. @@ -587,6 +587,34 @@ rend_cache_lookup_v2_desc_as_service(const char *query, rend_cache_entry_t **e)
  62. return ret;
  63. }
  64. +/** Remove any cached descriptors for <b>service_id</b>. */
  65. +void
  66. +rend_cache_remove_entry(const char *service_id)
  67. +{
  68. + char key[REND_SERVICE_ID_LEN_BASE32 + 2]; /* <version><service_id>\0 */
  69. + rend_cache_entry_t *removed;
  70. +
  71. + tor_assert(rend_valid_service_id(service_id));
  72. + if (!rend_cache)
  73. + return;
  74. +
  75. + tor_snprintf(key, sizeof(key), "2%s", service_id);
  76. + removed = (rend_cache_entry_t *)strmap_remove_lc(rend_cache, key);
  77. + if (removed) {
  78. + log_info(LD_REND, "Removed cached v2 descriptor for service %s.",
  79. + safe_str_client(service_id));
  80. + rend_cache_entry_free(removed);
  81. + }
  82. +
  83. + tor_snprintf(key, sizeof(key), "0%s", service_id);
  84. + removed = (rend_cache_entry_t *)strmap_remove_lc(rend_cache, key);
  85. + if (removed) {
  86. + log_info(LD_REND, "Removed cached v0 descriptor for service %s.",
  87. + safe_str_client(service_id));
  88. + rend_cache_entry_free(removed);
  89. + }
  90. +}
  91. +
  92. /** Lookup the v2 service descriptor with base32-encoded <b>desc_id</b> and
  93. * copy the pointer to it to *<b>desc</b>. Return 1 on success, 0 on
  94. * well-formed-but-not-found, and -1 on failure.
  95. diff --git a/src/or/rendcache.h b/src/or/rendcache.h
  96. index 270b614..69d1b1b 100644
  97. --- a/src/or/rendcache.h
  98. +++ b/src/or/rendcache.h
  99. @@ -61,6 +61,7 @@ void rend_cache_purge(void);
  100. void rend_cache_free_all(void);
  101. int rend_cache_lookup_entry(const char *query, int version,
  102. rend_cache_entry_t **entry_out);
  103. +void rend_cache_remove_entry(const char *service_id);
  104. int rend_cache_lookup_v2_desc_as_service(const char *query,
  105. rend_cache_entry_t **entry_out);
  106. int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
  107. diff --git a/src/or/rendclient.c b/src/or/rendclient.c
  108. index a93bc94..f311e1f 100644
  109. --- a/src/or/rendclient.c
  110. +++ b/src/or/rendclient.c
  111. @@ -32,6 +32,9 @@ static extend_info_t *rend_client_get_random_intro_impl(
  112. const rend_cache_entry_t *rend_query,
  113. const int strict, const int warnings);
  114. +static void purge_hid_serv_from_last_hid_serv_requests(
  115. + const char *onion_address);
  116. +
  117. /** Purge all potentially remotely-detectable state held in the hidden
  118. * service client code. Called on SIGNAL NEWNYM. */
  119. void
  120. @@ -43,6 +46,15 @@ rend_client_purge_state(void)
  121. rend_client_purge_last_hid_serv_requests();
  122. }
  123. +/** Purge all cached state relating to the given hidden service. */
  124. +void
  125. +rend_client_purge_hidden_service(const char *onion_address)
  126. +{
  127. + tor_assert(rend_valid_service_id(onion_address));
  128. + rend_cache_remove_entry(onion_address);
  129. + purge_hid_serv_from_last_hid_serv_requests(onion_address);
  130. +}
  131. +
  132. /** Called when we've established a circuit to an introduction point:
  133. * send the introduction request. */
  134. void
  135. diff --git a/src/or/rendclient.h b/src/or/rendclient.h
  136. index b8f8c2f..b1da48c 100644
  137. --- a/src/or/rendclient.h
  138. +++ b/src/or/rendclient.h
  139. @@ -15,6 +15,7 @@
  140. #include "rendcache.h"
  141. void rend_client_purge_state(void);
  142. +void rend_client_purge_hidden_service(const char *onion_address);
  143. void rend_client_introcirc_has_opened(origin_circuit_t *circ);
  144. void rend_client_rendcirc_has_opened(origin_circuit_t *circ);
  145. --
  146. 2.9.3