Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
hs_ob.c File Reference

Implement Onion Balance specific code. More...

#include "feature/hs/hs_service.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/networkstatus_st.h"
#include "lib/confmgt/confmgt.h"
#include "lib/encoding/confline.h"
#include "feature/hs/hs_ob.h"

Go to the source code of this file.

Macros

#define HS_OB_PRIVATE
 
#define OB_OPTIONS_MAGIC   0x631DE7EA
 
#define VAR(varname, conftype, member, initvalue)    CONFIG_VAR_ETYPE(ob_options_t, varname, conftype, member, 0, initvalue)
 
#define V(member, conftype, initvalue)    VAR(#member, conftype, member, initvalue)
 
#define ob_option_free(val)    FREE_AND_NULL(ob_options_t, ob_option_free_, (val))
 

Functions

 DUMMY_TYPECHECK_INSTANCE (ob_options_t)
 
static const config_mgr_tget_config_options_mgr (void)
 
static void ob_option_free_ (ob_options_t *opts)
 
static ob_options_t * ob_option_new (void)
 
static bool get_onion_public_key (const char *value, ed25519_public_key_t *pkey_out)
 
static int ob_option_parse (hs_service_config_t *config, const ob_options_t *opts)
 
static void build_subcredential (const ed25519_public_key_t *pkey, uint64_t tp, hs_subcredential_t *subcredential)
 
bool hs_ob_service_is_instance (const hs_service_t *service)
 
int hs_ob_parse_config_file (hs_service_config_t *config)
 
STATIC size_t compute_subcredentials (const hs_service_t *service, hs_subcredential_t **subcredentials_out)
 
void hs_ob_refresh_keys (hs_service_t *service)
 
void hs_ob_free_all (void)
 

Variables

static const config_var_t config_vars []
 
static const struct_member_t config_extra_vars
 
static const config_format_t config_format
 
static config_mgr_tconfig_options_mgr = NULL
 

Detailed Description

Implement Onion Balance specific code.

Definition in file hs_ob.c.

Function Documentation

◆ build_subcredential()

static void build_subcredential ( const ed25519_public_key_t pkey,
uint64_t  tp,
hs_subcredential_t subcredential 
)
static

For the given master public key and time period, compute the subcredential and put them into subcredential. The subcredential parameter needs to be at least DIGEST256_LEN in size.

Definition at line 181 of file hs_ob.c.

◆ compute_subcredentials()

STATIC size_t compute_subcredentials ( const hs_service_t service,
hs_subcredential_t **  subcredentials_out 
)

Compute all possible subcredentials for every onion master key in the given service config object. subcredentials_out is allocated and set as an continuous array containing all possible values.

On success, return the number of subcredential put in the array which will correspond to an array of size: n * DIGEST256_LEN where DIGEST256_LEN is the length of a single subcredential.

If the given configuration object has no OB master keys configured, 0 is returned and subcredentials_out is set to NULL.

Otherwise, this can't fail.

Definition at line 278 of file hs_ob.c.

Referenced by hs_ob_refresh_keys().

◆ get_onion_public_key()

static bool get_onion_public_key ( const char *  value,
ed25519_public_key_t pkey_out 
)
static

Helper function: From the configuration line value which is an onion address with the ".onion" extension, find the public key and put it in pkey_out.

On success, true is returned. Else, false and pkey is untouched.

Definition at line 103 of file hs_ob.c.

◆ hs_ob_free_all()

void hs_ob_free_all ( void  )

Free any memory allocated by the onionblance subsystem.

Definition at line 406 of file hs_ob.c.

Referenced by hs_free_all().

◆ hs_ob_parse_config_file()

int hs_ob_parse_config_file ( hs_service_config_t config)

Read and parse the config file at fname on disk. The service config object is populated with the options if any.

Return 1 on success else 0. This is to follow the "ok" convention in hs_config.c.

Definition at line 221 of file hs_ob.c.

◆ hs_ob_refresh_keys()

void hs_ob_refresh_keys ( hs_service_t service)

If we are an Onionbalance instance, refresh our keys.

If we are not an Onionbalance instance or we are not ready to do so, this is a NOP.

This function is called every time we build a new descriptor. That's because we want our Onionbalance keys to always use up-to-date subcredentials both for the instance (ourselves) and for the onionbalance frontend.

Definition at line 365 of file hs_ob.c.

◆ hs_ob_service_is_instance()

bool hs_ob_service_is_instance ( const hs_service_t service)

Return true iff the given service is configured as an onion balance instance. To satisfy that condition, there must at least be one master ed25519 public key configured.

Definition at line 201 of file hs_ob.c.

Referenced by get_subcredential_for_handling_intro2_cell(), and hs_ob_refresh_keys().

◆ ob_option_free_()

static void ob_option_free_ ( ob_options_t *  opts)
static

Helper: Free a config options object.

Definition at line 80 of file hs_ob.c.

◆ ob_option_new()

static ob_options_t* ob_option_new ( void  )
static

Return an allocated config options object.

Definition at line 90 of file hs_ob.c.

◆ ob_option_parse()

static int ob_option_parse ( hs_service_config_t config,
const ob_options_t *  opts 
)
static

Parse the given ob options in opts and set the service config object accordingly.

Return 1 on success else 0.

Definition at line 140 of file hs_ob.c.

Variable Documentation

◆ config_extra_vars

const struct_member_t config_extra_vars
static
Initial value:
= {
.name = "__extra",
.offset = offsetof(ob_options_t, ExtraLines),
}
@ CONFIG_TYPE_LINELIST
Definition: conftypes.h:61

Definition at line 43 of file hs_ob.c.

◆ config_format

const config_format_t config_format
static
Initial value:
= {
.size = sizeof(ob_options_t),
.magic = {
"ob_options_t",
OB_OPTIONS_MAGIC,
offsetof(ob_options_t, magic_),
},
.vars = config_vars,
.extra = &config_extra_vars,
}

Definition at line 50 of file hs_ob.c.

◆ config_vars

const config_var_t config_vars[]
static
Initial value:
= {
V(MasterOnionAddress, LINELIST, NULL),
}
#define END_OF_CONFIG_VARS
Definition: confmacros.h:22

Definition at line 35 of file hs_ob.c.