|
Tor 0.4.9.3-alpha-dev
|
Handle hidden service descriptor caches. More...
#include "core/or/or.h"#include "app/config/config.h"#include "lib/crypt_ops/crypto_format.h"#include "lib/crypt_ops/crypto_util.h"#include "lib/cc/torint.h"#include "feature/hs/hs_ident.h"#include "feature/hs/hs_common.h"#include "feature/hs/hs_client.h"#include "feature/hs/hs_descriptor.h"#include "feature/nodelist/microdesc.h"#include "feature/nodelist/networkstatus.h"#include "feature/stats/rephist.h"#include "feature/hs/hs_cache.h"#include "feature/nodelist/networkstatus_st.h"Go to the source code of this file.
Macros | |
| #define | HS_CACHE_PRIVATE |
| #define | HSCACHE_PRUNE_SPARE_ROOM (1000 * HS_DESC_MAX_LEN) |
| #define | cache_dir_desc_free(val) FREE_AND_NULL(hs_cache_dir_descriptor_t, cache_dir_desc_free_, (val)) |
| #define | cache_client_desc_free(val) FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val)) |
| #define | cache_intro_state_free(val) FREE_AND_NULL(hs_cache_intro_state_t, cache_intro_state_free_, (val)) |
| #define | cache_client_intro_state_free(val) |
Variables | |
| static size_t | hs_cache_total_allocation = 0 |
| static digest256map_t * | hs_cache_v3_dir |
| static digest256map_t * | hs_cache_v3_client |
| static digest256map_t * | hs_cache_client_intro_state |
Handle hidden service descriptor caches.
Definition in file hs_cache.c.
| #define cache_client_desc_free | ( | val | ) | FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val)) |
Definition at line 472 of file hs_cache.c.
| #define cache_client_intro_state_free | ( | val | ) |
Definition at line 664 of file hs_cache.c.
| #define cache_dir_desc_free | ( | val | ) | FREE_AND_NULL(hs_cache_dir_descriptor_t, cache_dir_desc_free_, (val)) |
Definition at line 84 of file hs_cache.c.
| #define cache_intro_state_free | ( | val | ) | FREE_AND_NULL(hs_cache_intro_state_t, cache_intro_state_free_, (val)) |
Definition at line 637 of file hs_cache.c.
| #define HS_CACHE_PRIVATE |
Definition at line 10 of file hs_cache.c.
| #define HSCACHE_PRUNE_SPARE_ROOM (1000 * HS_DESC_MAX_LEN) |
Spare room for 1000 descriptors when pruning cache to avoid thrashing and memory fragmentation.
Definition at line 32 of file hs_cache.c.
|
static |
clean the client cache using now as the current time. Return the total size of removed bytes from the cache.
Definition at line 891 of file hs_cache.c.
Referenced by hs_cache_clean_as_client().
| STATIC size_t cache_clean_v3_as_dir | ( | time_t | now, |
| time_t | global_cutoff | ||
| ) |
Clean the v3 cache by removing any entry that has expired using the global_cutoff value. If global_cutoff is 0, the cleaning process will use the lifetime found in the plaintext data section. Return the number of bytes cleaned.
Definition at line 332 of file hs_cache.c.
Referenced by hs_cache_clean_as_dir().
| STATIC size_t cache_clean_v3_by_downloaded_as_dir | ( | const uint64_t | target, |
| const size_t | max_remove_bytes, | ||
| uint64_t * | next_lowest | ||
| ) |
Clean the v3 cache by removing entries that are below or equal the downloaded target.
Stop when the max_remove_bytes is reached. It is possible that more bytes are removed if max_remove_bytes is not aligned on cache entry size.
Return the amount of bytes freed. The next_lowest param is set to the lowest n_downloaded value in the cache that is above target.
If both next_lowest and returned value are 0, the cache is empty.
Definition at line 272 of file hs_cache.c.
Referenced by hs_cache_handle_oom().
|
static |
Free memory allocated by desc.
Definition at line 477 of file hs_cache.c.
|
static |
Helper function: Use by the free all function to clear the client cache
Definition at line 491 of file hs_cache.c.
Referenced by hs_cache_free_all().
|
static |
Parse the encoded descriptor in desc_str using service_identity_pk to decrypt it first.
If everything goes well, allocate and return a new hs_cache_client_descriptor_t object. In case of error, return NULL.
Definition at line 580 of file hs_cache.c.
Referenced by hs_cache_store_as_client().
|
static |
For the given service identity key service_pk and an introduction authentication key auth_key, add an entry in the client intro state cache If no entry exists for the service, it will create one. If state is non NULL, it will point to the new intro state entry.
Definition at line 750 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_note().
|
static |
Remove every intro point state entry from cache that has been created before or at the cutoff.
Definition at line 782 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_clean().
|
static |
Free a cache_client_intro_state object.
Definition at line 670 of file hs_cache.c.
Referenced by cache_client_intro_state_free_void().
|
static |
Helper function: used by the free all function.
Definition at line 681 of file hs_cache.c.
Referenced by hs_cache_free_all().
|
static |
Return true iff no intro points are in this cache.
Definition at line 798 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_clean().
|
static |
For the given service identity key service_pk and an introduction authentication key auth_key, lookup the intro state object. Return 1 if found and put it in entry if not NULL. Return 0 if not found and entry is untouched.
Definition at line 691 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_find(), and hs_cache_client_intro_state_note().
|
static |
Return a newly allocated and initialized hs_cache_client_intro_state_t object.
Definition at line 657 of file hs_cache.c.
Referenced by cache_client_intro_state_add().
|
static |
Note the given failure in state.
Definition at line 725 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_note().
|
static |
Free a directory descriptor object.
Definition at line 89 of file hs_cache.c.
Referenced by cache_dir_desc_free_void().
|
static |
Helper function: Use by the free all function using the digest256map interface to cache entries.
Definition at line 102 of file hs_cache.c.
Referenced by hs_cache_free_all().
|
static |
Create a new directory cache descriptor object from a encoded descriptor. On success, return the heap-allocated cache object, otherwise return NULL if we can't decode the descriptor.
Definition at line 111 of file hs_cache.c.
Referenced by hs_cache_store_as_dir().
|
static |
Return the size of a client cache entry in bytes.
Definition at line 499 of file hs_cache.c.
Referenced by cache_clean_v3_as_client(), hs_cache_purge_as_client(), remove_v3_desc_as_client(), and store_v3_desc_as_client().
|
static |
Return the size of a cache entry in bytes.
Definition at line 139 of file hs_cache.c.
Referenced by cache_clean_v3_as_dir(), cache_clean_v3_by_downloaded_as_dir(), and cache_store_v3_as_dir().
|
static |
Free an hs_cache_intro_state_t object.
Definition at line 642 of file hs_cache.c.
Referenced by cache_intro_state_free_void().
|
static |
Helper function: used by the free all function.
Definition at line 649 of file hs_cache.c.
Referenced by cache_client_intro_state_free_().
|
static |
Return a newly allocated and initialized hs_cache_intro_state_t object.
Definition at line 630 of file hs_cache.c.
Referenced by cache_client_intro_state_add().
|
static |
Using the query which is the base64 encoded blinded key of a version 3 descriptor, lookup in our directory cache the entry. If found, 1 is returned and desc_out is populated with a newly allocated string being the encoded descriptor. If not found, 0 is returned and desc_out is untouched. On error, a negative value is returned and desc_out is untouched.
Definition at line 232 of file hs_cache.c.
Referenced by hs_cache_lookup_as_dir().
|
static |
Check whether client_desc is useful for us, and store it in the client-side HS cache if so. The client_desc is freed if we already have a fresher (higher revision counter count) in the cache.
Definition at line 807 of file hs_cache.c.
Referenced by hs_cache_store_as_client().
|
static |
Try to store a valid version 3 descriptor in the directory cache. Return 0 on success else a negative value is returned indicating that we have a newer version in our cache. On error, caller is responsible to free the given descriptor desc.
Definition at line 150 of file hs_cache.c.
Referenced by hs_cache_store_as_dir().
|
static |
Return true iff the cached client descriptor at cached_desc has expired.
Definition at line 866 of file hs_cache.c.
Referenced by cache_clean_v3_as_client(), and lookup_v3_desc_as_client().
|
inlinestatic |
Helper function: Return true iff the cache entry has a decrypted descriptor.
A NULL desc object in the entry means that we were not able to decrypt the descriptor because we are likely lacking client authorization. It is still a valid entry but some operations can't be done without the decrypted descriptor thus this function MUST be used to safe guard access to the decrypted desc object.
Definition at line 49 of file hs_cache.c.
Referenced by cache_clean_v3_as_client(), cache_get_client_entry_size(), cache_store_as_client(), hs_cache_lookup_as_client(), and hs_cache_remove_as_client().
| void hs_cache_clean_as_client | ( | time_t | now | ) |
Clean all client caches using the current time now.
Definition at line 1060 of file hs_cache.c.
Referenced by clean_caches_callback().
| void hs_cache_clean_as_dir | ( | time_t | now | ) |
Clean all directory caches using the current time now.
Definition at line 455 of file hs_cache.c.
Referenced by clean_caches_callback().
| void hs_cache_client_intro_state_clean | ( | time_t | now | ) |
Cleanup the client introduction state cache.
Definition at line 1119 of file hs_cache.c.
Referenced by rend_cache_failure_clean_callback().
| const hs_cache_intro_state_t * hs_cache_client_intro_state_find | ( | const ed25519_public_key_t * | service_pk, |
| const ed25519_public_key_t * | auth_key | ||
| ) |
For a given service identity public key and an introduction authentication key, return true iff it is present in the failure cache.
Definition at line 1109 of file hs_cache.c.
Referenced by consider_sending_introduce1(), intro_point_is_usable(), and intro_points_all_timed_out().
| void hs_cache_client_intro_state_note | ( | const ed25519_public_key_t * | service_pk, |
| const ed25519_public_key_t * | auth_key, | ||
| rend_intro_point_failure_t | failure | ||
| ) |
For a given service identity public key and an introduction authentication key, note the given failure in the client intro state cache.
Definition at line 1087 of file hs_cache.c.
Referenced by handle_introduce_ack_bad(), hs_client_circuit_cleanup_on_free(), and send_introduce1().
| void hs_cache_client_intro_state_purge | ( | void | ) |
Purge the client introduction state cache.
Definition at line 1139 of file hs_cache.c.
Referenced by hs_client_purge_state().
| bool hs_cache_client_new_auth_parse | ( | const ed25519_public_key_t * | service_pk | ) |
Definition at line 1156 of file hs_cache.c.
| void hs_cache_decrement_allocation | ( | size_t | n | ) |
Decrement the total bytes attributed to the rendezvous cache by n.
Definition at line 1274 of file hs_cache.c.
Referenced by cache_clean_v3_as_client(), cache_clean_v3_as_dir(), cache_clean_v3_by_downloaded_as_dir(), cache_store_v3_as_dir(), hs_cache_purge_as_client(), and remove_v3_desc_as_client().
| void hs_cache_free_all | ( | void | ) |
Cleanup the hidden service cache subsystem.
Definition at line 1243 of file hs_cache.c.
Referenced by hs_free_all().
| uint64_t hs_cache_get_max_bytes | ( | void | ) |
Get the configured maximum cache size.
Definition at line 1259 of file hs_cache.c.
Referenced by cache_store_v3_as_dir(), and cell_queues_check_size().
| unsigned int hs_cache_get_max_descriptor_size | ( | void | ) |
Return the maximum size of a v3 HS descriptor.
Definition at line 1219 of file hs_cache.c.
Referenced by desc_encode_v3(), and hs_desc_decode_plaintext().
| size_t hs_cache_get_total_allocation | ( | void | ) |
Definition at line 1267 of file hs_cache.c.
| size_t hs_cache_handle_oom | ( | size_t | min_remove_bytes | ) |
Do a round of OOM cleanup on all directory caches. Return the amount of removed bytes. It is possible that the returned value is lower than min_remove_bytes if the caches get emptied out so the caller should be aware of this.
Definition at line 1190 of file hs_cache.c.
Referenced by cache_store_v3_as_dir(), and cell_queues_check_size().
| void hs_cache_increment_allocation | ( | size_t | n | ) |
Increase the total bytes attributed to the rendezvous cache by n.
Definition at line 1291 of file hs_cache.c.
Referenced by cache_store_v3_as_dir(), and store_v3_desc_as_client().
| void hs_cache_init | ( | void | ) |
Initialize the hidden service cache subsystem.
Definition at line 1228 of file hs_cache.c.
Referenced by hs_init().
| const hs_descriptor_t * hs_cache_lookup_as_client | ( | const ed25519_public_key_t * | key | ) |
Public API: Given the HS ed25519 identity public key in key, return its HS descriptor if it's stored in our cache, or NULL if not or if the descriptor was never decrypted. The later can happen if we are waiting for client authorization to be added.
Definition at line 961 of file hs_cache.c.
Referenced by can_client_refetch_desc(), client_desc_has_arrived(), client_get_random_intro(), close_or_reextend_intro_circ(), connection_ap_handle_onion(), consider_sending_introduce1(), hs_client_setup_intro_circ_auth_key(), intro_points_all_timed_out(), pow_worker_replyfn(), and setup_rendezvous_circ_congestion_control().
| int hs_cache_lookup_as_dir | ( | uint32_t | version, |
| const char * | query, | ||
| const char ** | desc_out | ||
| ) |
Using the query, lookup in our directory cache the entry. If found, 1 is returned and desc_out is populated with a newly allocated string being the encoded descriptor. If not found, 0 is returned and desc_out is untouched. On error, a negative value is returned and desc_out is untouched.
Definition at line 418 of file hs_cache.c.
Referenced by handle_get_hs_descriptor_v3().
| const char * hs_cache_lookup_encoded_as_client | ( | const ed25519_public_key_t * | key | ) |
Public API: Given the HS ed25519 identity public key in key, return its HS encoded descriptor if it's stored in our cache, or NULL if not.
Definition at line 941 of file hs_cache.c.
Referenced by getinfo_helper_dir().
| void hs_cache_mark_dowloaded_as_dir | ( | const hs_ident_dir_conn_t * | ident | ) |
Using the given directory identifier, lookup the descriptor in our cache and if present, increment the downloaded counter. This is done when the directory connection fetching this descriptor is closed.
Definition at line 441 of file hs_cache.c.
Referenced by connection_dir_about_to_close().
| void hs_cache_purge_as_client | ( | void | ) |
Purge the client descriptor cache.
Definition at line 1069 of file hs_cache.c.
Referenced by hs_client_purge_state().
| void hs_cache_remove_as_client | ( | const ed25519_public_key_t * | key | ) |
Remove and free a client cache descriptor entry for the given onion service ed25519 public key. If the descriptor is decoded, the intro circuits are closed if any.
This does nothing if no descriptor exists for the given key.
Definition at line 1028 of file hs_cache.c.
Referenced by hs_client_remove_auth_credentials().
| hs_desc_decode_status_t hs_cache_store_as_client | ( | const char * | desc_str, |
| const ed25519_public_key_t * | identity_pk | ||
| ) |
Public API: Given an encoded descriptor, store it in the client HS cache. Return a decode status which changes how we handle the SOCKS connection depending on its value:
HS_DESC_DECODE_OK: Returned on success. Descriptor was properly decoded and is now stored.
HS_DESC_DECODE_NEED_CLIENT_AUTH: Client authorization is needed but the descriptor was still stored.
HS_DESC_DECODE_BAD_CLIENT_AUTH: Client authorization for this descriptor was not usable but the descriptor was still stored.
Any other codes means indicate where the error occurred and the descriptor was not stored.
Definition at line 992 of file hs_cache.c.
Referenced by client_dir_fetch_200().
| int hs_cache_store_as_dir | ( | const char * | desc | ) |
Given an encoded descriptor, store it in the directory cache depending on which version it is. Return a negative value on error. On success, 0 is returned.
Definition at line 381 of file hs_cache.c.
| STATIC hs_cache_client_descriptor_t * lookup_v3_desc_as_client | ( | const uint8_t * | key | ) |
Query our cache and return the entry or NULL if not found or if expired.
Definition at line 553 of file hs_cache.c.
Referenced by cache_store_as_client(), hs_cache_lookup_as_client(), hs_cache_lookup_encoded_as_client(), and hs_cache_remove_as_client().
| STATIC hs_cache_dir_descriptor_t * lookup_v3_desc_as_dir | ( | const uint8_t * | key | ) |
Query our cache and return the entry or NULL if not found.
Definition at line 78 of file hs_cache.c.
Referenced by cache_lookup_v3_as_dir(), cache_store_v3_as_dir(), and hs_cache_mark_dowloaded_as_dir().
|
static |
Remove a given descriptor from our cache.
Definition at line 522 of file hs_cache.c.
Referenced by cache_store_as_client(), and hs_cache_remove_as_client().
|
static |
Remove a given descriptor from our cache.
Definition at line 62 of file hs_cache.c.
Referenced by cache_store_v3_as_dir().
|
static |
Store a given descriptor in our cache.
Definition at line 532 of file hs_cache.c.
Referenced by cache_store_as_client().
|
static |
Store a given descriptor in our cache.
Definition at line 70 of file hs_cache.c.
Referenced by cache_store_v3_as_dir().
|
static |
Client-side introduction point state cache. Map indexed by service public identity key (onion address). It contains hs_cache_client_intro_state_t objects all related to a specific service.
Definition at line 470 of file hs_cache.c.
Referenced by cache_client_intro_state_add(), cache_client_intro_state_lookup(), hs_cache_client_intro_state_clean(), hs_cache_client_intro_state_purge(), hs_cache_free_all(), and hs_cache_init().
|
static |
Definition at line 35 of file hs_cache.c.
|
static |
Client-side HS descriptor cache. Map indexed by service identity key.
Definition at line 465 of file hs_cache.c.
Referenced by cache_clean_v3_as_client(), hs_cache_free_all(), hs_cache_init(), hs_cache_purge_as_client(), lookup_v3_desc_as_client(), remove_v3_desc_as_client(), and store_v3_desc_as_client().
|
static |
Directory descriptor cache. Map indexed by blinded key.
Definition at line 58 of file hs_cache.c.
Referenced by cache_clean_v3_as_dir(), cache_clean_v3_by_downloaded_as_dir(), hs_cache_free_all(), hs_cache_init(), lookup_v3_desc_as_dir(), remove_v3_desc_as_dir(), and store_v3_desc_as_dir().