Tor  0.4.5.0-alpha-dev
Macros | Functions | Variables
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_ob.h"
#include "feature/hs/hs_service.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.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_tget_hs_opts_mgr (void)
 
static hs_opts_ths_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_ths_opts_mgr = NULL
 
static const char SECTION_HEADER [] = "HiddenServiceDir"
 

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.

Macro Definition Documentation

◆ CHECK_OOB

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

◆ hs_opts_free

#define hs_opts_free (   opts)     config_free(get_hs_opts_mgr(), (opts))

Free an hs_opts_t.

Definition at line 88 of file hs_config.c.

◆ HS_OPTS_MAGIC

#define HS_OPTS_MAGIC   0x6f6e796e

Magic number for hs_opts_t.

Definition at line 46 of file hs_config.c.

Function Documentation

◆ check_value_oob()

static bool check_value_oob ( int  i,
const char *  name,
int  low,
int  high 
)
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 179 of file hs_config.c.

◆ config_generic_service()

static int config_generic_service ( const hs_opts_t hs_opts,
const or_options_t options,
hs_service_t service 
)
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 456 of file hs_config.c.

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

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

◆ config_service()

static int config_service ( 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 541 of file hs_config.c.

◆ config_service_v3()

static int config_service_v3 ( const hs_opts_t hs_opts,
hs_service_config_t config 
)
static

Configuration funcion 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 371 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 339 of file hs_config.c.

◆ get_hs_opts_mgr()

static const config_mgr_t* get_hs_opts_mgr ( void  )
static

Return a configuration manager for the hs_opts_t configuration type.

Definition at line 63 of file hs_config.c.

Referenced by config_service(), and hs_opts_new().

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

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

◆ hs_config_free_all()

void hs_config_free_all ( void  )

Free all resources held by the hs_config.c module.

Definition at line 740 of file hs_config.c.

Referenced by hs_service_free_all().

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

◆ hs_opts_new()

static hs_opts_t* hs_opts_new ( void  )
static

Allocate, initialize, and return a new hs_opts_t.

Definition at line 76 of file hs_config.c.

Referenced by config_service().

◆ 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 132 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 101 of file hs_config.c.

Variable Documentation

◆ hs_opts_fmt

const config_format_t hs_opts_fmt
static
Initial value:
= {
.size = sizeof(hs_opts_t),
.magic = { "hs_opts_t",
offsetof(hs_opts_t, magic) },
.vars = hs_opts_t_vars,
}

Definition at line 48 of file hs_config.c.

◆ hs_opts_mgr

config_mgr_t* hs_opts_mgr = NULL
static

Global configuration manager to handle HS sections

Definition at line 57 of file hs_config.c.

◆ SECTION_HEADER

const char SECTION_HEADER[] = "HiddenServiceDir"
static

Header key indicating the start of a new hidden service configuration block.

Definition at line 246 of file hs_config.c.

Referenced by config_has_invalid_options(), and hs_config_service_all().

HS_OPTS_MAGIC
#define HS_OPTS_MAGIC
Definition: hs_config.c:46
hs_opts_t
Definition: hs_options.inc:18