19#ifndef COMMON_CONFIG_H_
20#define COMMON_CONFIG_H_
22#include <openssl/evp.h>
60#define generate_bool_string_prototypes(param_name) \
61enum param_name ## _enum { \
62 param_name ## _UNKNOWN = -1, \
63 param_name ## _NO = 0, \
65 param_name ## _NOT_SET, \
67enum param_name ## _enum \
68 param_name ## _from_str(const char *value); \
69const char *param_name ## _to_str(enum param_name ## _enum value);
94#define generate_enum_string_prototypes(param_name, ...) \
95enum param_name ## _enum { \
98enum param_name ## _enum \
99 param_name ## _from_str(const char *value); \
100const char *param_name ## _to_str(enum param_name ## _enum value);
103 endpoint_behavior_UNKNOWN = -1,
104 endpoint_behavior_OFF = 0,
105 endpoint_behavior_ATTEST,
106 endpoint_behavior_VERIFY,
107 endpoint_behavior_ON,
108 endpoint_behavior_NOT_SET
112 attest_level_UNKNOWN = -1,
113 attest_level_NOT_SET = 0,
145#define generate_sorcery_enum_to_str_ex(__struct, __substruct, __lc_param, __base_enum) \
146static int sorcery_ ## __lc_param ## _to_str(const void *obj, const intptr_t *args, char **buf) \
148 const struct __struct *cfg = obj; \
149 *buf = ast_strdup(__base_enum ## _to_str(cfg->__substruct __lc_param)); \
150 return *buf ? 0 : -1; \
153#define generate_sorcery_enum_to_str(__struct, __substruct, __lc_param) \
154 generate_sorcery_enum_to_str_ex(__struct, __substruct, __lc_param, __lc_param)
156#define generate_sorcery_enum_from_str_ex(__struct, __substruct, __lc_param, __base_enum, __unknown) \
157static int sorcery_ ## __lc_param ## _from_str(const struct aco_option *opt, struct ast_variable *var, void *obj) \
159 struct __struct *cfg = obj; \
160 cfg->__substruct __lc_param = __base_enum ## _from_str (var->value); \
161 if (cfg->__substruct __lc_param == __base_enum ## _ ## __unknown) { \
162 ast_log(LOG_WARNING, "Unknown value '%s' specified for %s\n", \
163 var->value, var->name); \
169#define generate_sorcery_enum_from_str(__struct, __substruct, __lc_param, __unknown) \
170 generate_sorcery_enum_from_str_ex(__struct, __substruct, __lc_param, __lc_param, __unknown) \
173#define generate_sorcery_acl_to_str(__struct, __lc_param) \
174static int sorcery_acl_to_str(const void *obj, const intptr_t *args, char **buf) \
176 const struct __struct *cfg = obj; \
177 struct ast_acl *first_acl; \
178 if (!ast_acl_list_is_empty(cfg->vcfg_common.acl)) { \
179 AST_LIST_LOCK(cfg->vcfg_common.acl); \
180 first_acl = AST_LIST_FIRST(cfg->vcfg_common.acl); \
181 if (ast_strlen_zero(first_acl->name)) { \
182 *buf = "deny/permit"; \
184 *buf = first_acl->name; \
186 AST_LIST_UNLOCK(cfg->vcfg_common.acl); \
188 *buf = ast_strdup(*buf); \
192#define generate_sorcery_acl_from_str(__struct, __lc_param, __unknown) \
193static int sorcery_acl_from_str(const struct aco_option *opt, struct ast_variable *var, void *obj) \
195 struct __struct *cfg = obj; \
198 const char *name = var->name + strlen("x5u_"); \
199 if (ast_strlen_zero(var->value)) { \
202 ast_append_acl(name, var->value, &cfg->vcfg_common.acl, &error, &ignore); \
208#define EFFECTIVE_ENUM(__enum1, __enum2, __field, __default) \
209 ( __enum1 != ( __field ## _ ## NOT_SET ) ? __enum1 : \
210 (__enum2 != __field ## _ ## NOT_SET ? \
211 __enum2 : __default ))
213#define EFFECTIVE_ENUM_BOOL(__enum1, __enum2, __field, __default) \
214 (( __enum1 != ( __field ## _ ## NOT_SET ) ? __enum1 : \
215 (__enum2 != __field ## _ ## NOT_SET ? \
216 __enum2 : __field ## _ ## __default )) == __field ## _ ## YES)
218#define ENUM_BOOL(__enum1, __field) \
219 (__enum1 == ( __field ## _ ## YES ))
231#define cfg_stringfield_copy(__cfg_dst, __cfg_src, __field) \
234 if (!ast_strlen_zero(__cfg_src->__field)) { \
235 __res = ast_string_field_set(__cfg_dst, __field, __cfg_src->__field); \
246#define cfg_sf_copy_wrapper(id, __cfg_dst, __cfg_src, __field) \
248 int rc = cfg_stringfield_copy(__cfg_dst, __cfg_src, __field); \
250 ast_log(LOG_ERROR, "%s: Unable to copy field %s from %s to %s\n", \
251 id, #__field, #__cfg_src, #__cfg_dst); \
262#define cfg_uint_copy(__cfg_dst, __cfg_src, __field) \
264 if (__cfg_src->__field > 0) { \
265 __cfg_dst->__field = __cfg_src->__field; \
275#define cfg_enum_copy_ex(__cfg_dst, __cfg_src, __field, __not_set, __unknown) \
277 if (__cfg_src->__field != __not_set \
278 && __cfg_src->__field != __unknown) { \
279 __cfg_dst->__field = __cfg_src->__field; \
283#define cfg_enum_copy(__cfg_dst, __cfg_src, __field) \
284 cfg_enum_copy_ex(__cfg_dst, __cfg_src, __field, __field ## _NOT_SET, __field ## _UNKNOWN)
304#define generate_acfg_common_sorcery_handlers(object) \
305 generate_sorcery_enum_from_str(object, acfg_common., check_tn_cert_public_url, UNKNOWN); \
306 generate_sorcery_enum_to_str(object, acfg_common., check_tn_cert_public_url); \
307 generate_sorcery_enum_from_str(object, acfg_common., send_mky, UNKNOWN); \
308 generate_sorcery_enum_to_str(object, acfg_common., send_mky); \
309 generate_sorcery_enum_from_str(object, acfg_common., attest_level, UNKNOWN); \
310 generate_sorcery_enum_to_str(object, acfg_common., attest_level);
363 enum relax_x5u_port_scheme_restrictions_enum
365 enum relax_x5u_path_restrictions_enum
373#define generate_vcfg_common_sorcery_handlers(object) \
374 generate_sorcery_enum_from_str(object, vcfg_common.,use_rfc9410_responses, UNKNOWN); \
375 generate_sorcery_enum_to_str(object, vcfg_common.,use_rfc9410_responses); \
376 generate_sorcery_enum_from_str(object, vcfg_common.,stir_shaken_failure_action, UNKNOWN); \
377 generate_sorcery_enum_to_str(object, vcfg_common.,stir_shaken_failure_action); \
378 generate_sorcery_enum_from_str(object, vcfg_common.,relax_x5u_port_scheme_restrictions, UNKNOWN); \
379 generate_sorcery_enum_to_str(object, vcfg_common.,relax_x5u_port_scheme_restrictions); \
380 generate_sorcery_enum_from_str(object, vcfg_common.,relax_x5u_path_restrictions, UNKNOWN); \
381 generate_sorcery_enum_to_str(object, vcfg_common.,relax_x5u_path_restrictions); \
382 generate_sorcery_enum_from_str(object, vcfg_common.,load_system_certs, UNKNOWN); \
383 generate_sorcery_enum_to_str(object, vcfg_common.,load_system_certs); \
384 generate_sorcery_acl_from_str(object, acl, NULL); \
385 generate_sorcery_acl_to_str(object, acl);
441#define PROFILE_ALLOW_ATTEST(__profile) \
442 (__profile->endpoint_behavior == endpoint_behavior_ON || \
443 __profile->endpoint_behavior == endpoint_behavior_ATTEST)
445#define PROFILE_ALLOW_VERIFY(__profile) \
446 (__profile->endpoint_behavior == endpoint_behavior_ON || \
447 __profile->endpoint_behavior == endpoint_behavior_VERIFY)
494#define stringfield_option_register(sorcery, CONFIG_TYPE, object, name, field, nodoc) \
495 ast_sorcery_object_field_register ## nodoc(sorcery, CONFIG_TYPE, #name, \
496 DEFAULT_ ## name, OPT_STRINGFIELD_T, 0, \
497 STRFLDSET(struct object, field))
499#define uint_option_register(sorcery, CONFIG_TYPE, object, name, field, nodoc) \
500 ast_sorcery_object_field_register ## nodoc(sorcery, CONFIG_TYPE, #name, \
501 __stringify(DEFAULT_ ## name), OPT_UINT_T, 0, \
502 FLDSET(struct object, field))
504#define enum_option_register_ex(sorcery, CONFIG_TYPE, name, field, function_prefix, nodoc) \
505 ast_sorcery_object_field_register_custom ## nodoc(sorcery, CONFIG_TYPE, \
506 #name, function_prefix ## _to_str(DEFAULT_ ## field), \
507 sorcery_ ## field ## _from_str, sorcery_ ## field ## _to_str, NULL, 0, 0)
509#define enum_option_register(sorcery, CONFIG_TYPE, name, nodoc) \
510 enum_option_register_ex(sorcery, CONFIG_TYPE, name, name, name, nodoc)
512#define register_common_verification_fields(sorcery, object, CONFIG_TYPE, nodoc) \
514 stringfield_option_register(sorcery, CONFIG_TYPE, object, ca_file, vcfg_common.ca_file, nodoc); \
515 stringfield_option_register(sorcery, CONFIG_TYPE, object, ca_path, vcfg_common.ca_path, nodoc); \
516 stringfield_option_register(sorcery, CONFIG_TYPE, object, crl_file, vcfg_common.crl_file, nodoc); \
517 stringfield_option_register(sorcery, CONFIG_TYPE, object, crl_path, vcfg_common.crl_path, nodoc); \
518 stringfield_option_register(sorcery, CONFIG_TYPE, object, untrusted_cert_file, vcfg_common.untrusted_cert_file, nodoc); \
519 stringfield_option_register(sorcery, CONFIG_TYPE, object, untrusted_cert_path, vcfg_common.untrusted_cert_path, nodoc); \
520 stringfield_option_register(sorcery, CONFIG_TYPE, object, cert_cache_dir, vcfg_common.cert_cache_dir, nodoc); \
522 uint_option_register(sorcery, CONFIG_TYPE, object, curl_timeout, vcfg_common.curl_timeout, nodoc);\
523 uint_option_register(sorcery, CONFIG_TYPE, object, max_iat_age, vcfg_common.max_iat_age, nodoc);\
524 uint_option_register(sorcery, CONFIG_TYPE, object, max_date_header_age, vcfg_common.max_date_header_age, nodoc);\
525 uint_option_register(sorcery, CONFIG_TYPE, object, max_cache_entry_age, vcfg_common.max_cache_entry_age, nodoc);\
526 uint_option_register(sorcery, CONFIG_TYPE, object, max_cache_size, vcfg_common.max_cache_size, nodoc);\
528 enum_option_register_ex(sorcery, CONFIG_TYPE, failure_action, stir_shaken_failure_action, stir_shaken_failure_action, nodoc); \
529 enum_option_register(sorcery, CONFIG_TYPE, use_rfc9410_responses, nodoc); \
530 enum_option_register(sorcery, CONFIG_TYPE, \
531 relax_x5u_port_scheme_restrictions, nodoc); \
532 enum_option_register(sorcery, CONFIG_TYPE, \
533 relax_x5u_path_restrictions, nodoc); \
534 enum_option_register(sorcery, CONFIG_TYPE, \
535 load_system_certs, nodoc); \
537 ast_sorcery_object_field_register_custom ## nodoc(sorcery, CONFIG_TYPE, "x5u_deny", "", sorcery_acl_from_str, NULL, NULL, 0, 0); \
538 ast_sorcery_object_field_register_custom ## nodoc(sorcery, CONFIG_TYPE, "x5u_permit", "", sorcery_acl_from_str, NULL, NULL, 0, 0); \
539 ast_sorcery_object_field_register_custom ## nodoc(sorcery, CONFIG_TYPE, "x5u_acl", "", sorcery_acl_from_str, sorcery_acl_to_str, NULL, 0, 0); \
542#define register_common_attestation_fields(sorcery, object, CONFIG_TYPE, nodoc) \
544 stringfield_option_register(sorcery, CONFIG_TYPE, object, private_key_file, acfg_common.private_key_file, nodoc); \
545 stringfield_option_register(sorcery, CONFIG_TYPE, object, public_cert_url, acfg_common.public_cert_url, nodoc); \
546 enum_option_register(sorcery, CONFIG_TYPE, attest_level, nodoc); \
547 enum_option_register(sorcery, CONFIG_TYPE, check_tn_cert_public_url, nodoc); \
548 enum_option_register(sorcery, CONFIG_TYPE, send_mky, nodoc); \
Asterisk main include file. File version handling, generic pbx functions.
int as_config_unload(void)
int as_config_reload(void)
@ config_object_type_attestation
@ config_object_type_profile
@ config_object_type_verification
int vs_config_reload(void)
int config_object_cli_show(void *obj, void *arg, void *data, int flags)
Output configuration settings to the Asterisk CLI.
char * config_object_tab_complete_name(const char *word, struct ao2_container *container)
Tab completion for name matching with STIR/SHAKEN CLI commands.
int common_config_unload(void)
struct ast_acl_list * get_default_acl_list(void)
#define generate_enum_string_prototypes(param_name,...)
Enum field to/from string prototype generator.
int common_config_reload(void)
struct attestation_cfg * as_get_cfg(void)
int vs_is_config_loaded(void)
char * canonicalize_tn_alloc(const char *tn)
Canonicalize a TN into nre buffer.
int common_config_load(void)
struct tn_cfg * tn_get_cfg(const char *tn)
const char * unknown_tn_attest_level_to_str(enum attest_level_enum value)
struct verification_cfg * vs_get_cfg(void)
struct profile_cfg * eprofile_get_cfg(const char *id)
int tn_config_unload(void)
int as_check_common_config(const char *id, struct attestation_cfg_common *acfg_common)
struct ao2_container * eprofile_get_all(void)
struct profile_cfg * profile_get_cfg(const char *id)
struct ao2_container * profile_get_all(void)
char * canonicalize_tn(const char *tn, char *dest_tn)
Canonicalize a TN.
int vs_copy_cfg_common(const char *id, struct verification_cfg_common *cfg_dst, struct verification_cfg_common *cfg_src)
int as_is_config_loaded(void)
int tn_config_reload(void)
enum attest_level_enum unknown_tn_attest_level_from_str(const char *value)
struct tn_cfg * tn_get_etn(const char *tn, struct profile_cfg *eprofile)
int as_copy_cfg_common(const char *id, struct attestation_cfg_common *cfg_dst, struct attestation_cfg_common *cfg_src)
int vs_config_unload(void)
enum stir_shaken_failure_action_enum stir_shaken_failure_action_from_str(const char *action_str)
#define generate_bool_string_prototypes(param_name)
Boolean field to/from string prototype generator.
int vs_check_common_config(const char *id, struct verification_cfg_common *vcfg_common)
void vcfg_cleanup(struct verification_cfg_common *cfg)
void acfg_cleanup(struct attestation_cfg_common *cfg)
const char * stir_shaken_failure_action_to_str(enum stir_shaken_failure_action_enum action)
Asterisk file paths, configured in asterisk.conf.
struct ao2_container * container
stir_shaken_failure_action_enum
Sorcery Data Access Layer API.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
Wrapper for an ast_acl linked list.
Attestation Service configuration for stir/shaken.
enum check_tn_cert_public_url_enum check_tn_cert_public_url
enum attest_level_enum attest_level
const ast_string_field public_cert_url
const ast_string_field private_key_file
enum send_mky_enum send_mky
struct attestation_cfg_common acfg_common
enum attest_level_enum unknown_tn_attest_level
enum config_object_type object_type
ao2 object wrapper for X509_STORE that provides locking and refcounting
Profile configuration for stir/shaken.
enum endpoint_behavior_enum endpoint_behavior
struct attestation_cfg_common acfg_common
struct profile_cfg * eprofile
enum attest_level_enum unknown_tn_attest_level
struct verification_cfg_common vcfg_common
TN configuration for stir/shaken.
struct attestation_cfg_common acfg_common
Verification Service configuration for stir/shaken.
struct crypto_cert_store * tcs
unsigned int max_cache_size
enum stir_shaken_failure_action_enum stir_shaken_failure_action
enum use_rfc9410_responses_enum use_rfc9410_responses
const ast_string_field cert_cache_dir
const ast_string_field ca_path
enum relax_x5u_path_restrictions_enum relax_x5u_path_restrictions
unsigned int curl_timeout
const ast_string_field crl_file
const ast_string_field crl_path
enum load_system_certs_enum load_system_certs
const ast_string_field ca_file
enum relax_x5u_port_scheme_restrictions_enum relax_x5u_port_scheme_restrictions
unsigned int max_date_header_age
const ast_string_field untrusted_cert_file
struct ast_acl_list * acl
const ast_string_field untrusted_cert_path
unsigned int max_cache_entry_age
struct verification_cfg_common vcfg_common