Tor  0.4.3.1-alpha-dev
Functions
hs_config.c File Reference

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_service.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.h"
#include "lib/encoding/confline.h"
#include "app/config/or_options_st.h"

Go to the source code of this file.

Functions

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 uint64_t helper_parse_uint64 (const char *opt, const char *value, uint64_t min, uint64_t max, int *ok)
 
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 config_line_t *line_, hs_service_config_t *config)
 
static int config_generic_service (const config_line_t *line_, const or_options_t *options, hs_service_t *service)
 
static int config_service (const 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)
 

Detailed Description

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, transfert 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.

Function Documentation

◆ config_generic_service()

static int config_generic_service ( const config_line_t line_,
const or_options_t options,
hs_service_t service 
)
static

Configure a service using the given options in line_ 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 436 of file hs_config.c.

Referenced by config_service().

◆ config_has_invalid_options()

static int config_has_invalid_options ( const config_line_t line_,
const hs_service_t service 
)
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 200 of file hs_config.c.

Referenced by config_service().

◆ config_learn_service_version()

static int config_learn_service_version ( hs_service_t service)
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 178 of file hs_config.c.

Referenced by config_service().

◆ config_service()

static int config_service ( const config_line_t line,
const or_options_t options,
smartlist_t service_list 
)
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 584 of file hs_config.c.

◆ config_service_v3()

static int config_service_v3 ( const config_line_t line_,
hs_service_config_t config 
)
static

Configuration funcion for a version 3 service. 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. 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 314 of file hs_config.c.

◆ config_validate_service()

static int config_validate_service ( const hs_service_config_t config)
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 279 of file hs_config.c.

◆ helper_parse_circuit_id_protocol()

static hs_circuit_id_protocol_t helper_parse_circuit_id_protocol ( const char *  key,
const char *  value,
int *  ok 
)
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 151 of file hs_config.c.

◆ helper_parse_uint64()

static uint64_t helper_parse_uint64 ( const char *  opt,
const char *  value,
uint64_t  min,
uint64_t  max,
int *  ok 
)
static

Helper function: Given an configuration option name, its value, a minimum min and a maxium max, parse the value as a uint64_t. On success, ok is set to 1 and ret is the parsed value. On error, ok is set to 0 and ret must be ignored. This function logs both on error and success.

Definition at line 124 of file hs_config.c.

Referenced by config_service_v3().

◆ hs_config_client_auth_all()

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 737 of file hs_config.c.

◆ hs_config_service_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 668 of file hs_config.c.

◆ service_is_duplicate_in_list()

static int service_is_duplicate_in_list ( const smartlist_t service_list,
const hs_service_t 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 76 of file hs_config.c.

◆ stage_services()

static void stage_services ( smartlist_t service_list)
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 45 of file hs_config.c.