Tor
0.4.7.0-alpha-dev
|
Implement hidden service configuration subsystem. More...
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_config.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_ob.h"
#include "feature/hs/hs_service.h"
#include "lib/encoding/confline.h"
#include "lib/conf/confdecl.h"
#include "lib/confmgt/confmgt.h"
#include "feature/hs/hs_opts_st.h"
#include "app/config/or_options_st.h"
#include "feature/hs/hs_options.inc"
Go to the source code of this file.
Macros | |
#define | CONF_CONTEXT TABLE |
#define | HS_OPTS_MAGIC 0x6f6e796e |
#define | hs_opts_free(opts) config_free(get_hs_opts_mgr(), (opts)) |
#define | CHECK_OOB(opts, name, low, high) check_value_oob((opts)->name, #name, (low), (high)) |
Functions | |
static const config_mgr_t * | get_hs_opts_mgr (void) |
static hs_opts_t * | hs_opts_new (void) |
static void | stage_services (smartlist_t *service_list) |
static int | service_is_duplicate_in_list (const smartlist_t *service_list, const hs_service_t *service) |
static bool | check_value_oob (int i, const char *name, int low, int high) |
static hs_circuit_id_protocol_t | helper_parse_circuit_id_protocol (const char *key, const char *value, int *ok) |
static int | config_learn_service_version (hs_service_t *service) |
static int | config_has_invalid_options (const config_line_t *line_, const hs_service_t *service) |
static int | config_validate_service (const hs_service_config_t *config) |
static int | config_service_v3 (const hs_opts_t *hs_opts, hs_service_config_t *config) |
static int | config_generic_service (const hs_opts_t *hs_opts, const or_options_t *options, hs_service_t *service) |
static int | config_service (config_line_t *line, const or_options_t *options, smartlist_t *service_list) |
int | hs_config_service_all (const or_options_t *options, int validate_only) |
int | hs_config_client_auth_all (const or_options_t *options, int validate_only) |
void | hs_config_free_all (void) |
Variables | |
static const config_format_t | hs_opts_fmt |
static config_mgr_t * | hs_opts_mgr = NULL |
static const char | SECTION_HEADER [] = "HiddenServiceDir" |
Implement hidden service configuration subsystem.
This file has basically one main entry point: hs_config_service_all(). It takes the torrc options and configure hidden service from it. In validate mode, nothing is added to the global service list or keys are not generated nor loaded.
A service is configured in two steps. It is first created using the tor options and then put in a staging list. It will stay there until hs_service_load_all_keys() is called. That function is responsible to load/generate the keys for the service in the staging list and if successful, transferred the service to the main global service list where at that point it is ready to be used.
Configuration functions are per-version and there is a main generic one for every option that is common to all version (config_generic_service).
Definition in file hs_config.c.
#define CHECK_OOB | ( | opts, | |
name, | |||
low, | |||
high | |||
) | check_value_oob((opts)->name, #name, (low), (high)) |
Helper: check whether the integer value called name in opts is out-of-bounds.
Definition at line 173 of file hs_config.c.
#define hs_opts_free | ( | opts | ) | config_free(get_hs_opts_mgr(), (opts)) |
Free an hs_opts_t.
Definition at line 86 of file hs_config.c.
#define HS_OPTS_MAGIC 0x6f6e796e |
Magic number for hs_opts_t.
Definition at line 44 of file hs_config.c.
|
static |
Check whether an integer i is out of bounds (not between low and high incusive). If it is, then log a warning about the option name, and return true. Otherwise return false.
Definition at line 159 of file hs_config.c.
|
static |
Configure a service using the given options in hs_opts and options. This is called for any service regardless of its version which means that all directives in this function are generic to any service version. This function will also check the validity of the service directory path.
The line_ must be pointing to the directive directly after a HiddenServiceDir. That way, when hitting the next HiddenServiceDir line or reaching the end of the list of lines, we know that we have to stop looking for more options.
Return 0 on success else -1.
Definition at line 417 of file hs_config.c.
|
static |
Return true iff the given options starting at line_ for a hidden service contains at least one invalid option. Each hidden service option don't apply to all versions so this function can find out. The line_ MUST start right after the HiddenServiceDir line of this service.
This is mainly for usability so we can inform the user of any invalid option for the hidden service version instead of silently ignoring.
Definition at line 236 of file hs_config.c.
|
static |
Return the service version by trying to learn it from the key on disk if any. If nothing is found, the current service configured version is returned.
Definition at line 208 of file hs_config.c.
|
static |
Configure a service using the given line and options. This function will call the corresponding configuration function for a specific service version and validate the service against the other ones. On success, add the service to the given list and return 0. On error, nothing is added to the list and a negative value is returned.
Definition at line 508 of file hs_config.c.
|
static |
Configuration function for a version 3 service. The given service object must be already allocated and passed through config_generic_service() prior to calling this function.
Return 0 on success else a negative value.
Definition at line 332 of file hs_config.c.
|
static |
Validate service configuration. This is used when loading the configuration and once we've setup a service object, it's config object is passed to this function for further validation. This does not validate service key material. Return 0 if valid else -1 if invalid.
Definition at line 300 of file hs_config.c.
|
static |
Return a configuration manager for the hs_opts_t configuration type.
Definition at line 61 of file hs_config.c.
Referenced by config_service(), and hs_opts_new().
|
static |
Helper function: Given a configuration option and its value, parse the value as a hs_circuit_id_protocol_t. On success, ok is set to 1 and ret is the parse value. On error, ok is set to 0 and the "none" hs_circuit_id_protocol_t is returned. This function logs on error.
Definition at line 181 of file hs_config.c.
int hs_config_client_auth_all | ( | const or_options_t * | options, |
int | validate_only | ||
) |
From a set of options, setup every client authorization found. Return 0 on success or -1 on failure. If validate_only is set, parse, warn and return as normal, but don't actually change the configured state.
Definition at line 674 of file hs_config.c.
void hs_config_free_all | ( | void | ) |
Free all resources held by the hs_config.c module.
Definition at line 693 of file hs_config.c.
Referenced by hs_service_free_all().
int hs_config_service_all | ( | const or_options_t * | options, |
int | validate_only | ||
) |
From a set of options, setup every hidden service found. Return 0 on success or -1 on failure. If validate_only is set, parse, warn and return as normal, but don't actually change the configured services.
Definition at line 609 of file hs_config.c.
|
static |
Allocate, initialize, and return a new hs_opts_t.
Definition at line 74 of file hs_config.c.
Referenced by config_service().
|
static |
Validate the given service against all service in the given list. If the service is ephemeral, this function ignores it. Services with the same directory path aren't allowed and will return an error. If a duplicate is found, 1 is returned else 0 if none found.
Definition at line 113 of file hs_config.c.
|
static |
Using the given list of services, stage them into our global state. Every service version are handled. This function can remove entries in the given service_list.
Staging a service means that we take all services in service_list and we put them in the staging list (global) which acts as a temporary list that is used by the service loading key process. In other words, staging a service puts it in a list to be considered when loading the keys and then moved to the main global list.
Definition at line 99 of file hs_config.c.
|
static |
Definition at line 46 of file hs_config.c.
|
static |
Global configuration manager to handle HS sections
Definition at line 55 of file hs_config.c.
|
static |
Header key indicating the start of a new hidden service configuration block.
Definition at line 226 of file hs_config.c.
Referenced by config_has_invalid_options(), and hs_config_service_all().