Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
certificate.c File Reference
#include "asterisk.h"
#include <sys/stat.h>
#include "asterisk/cli.h"
#include "asterisk/sorcery.h"
#include "stir_shaken.h"
#include "certificate.h"
#include "asterisk/res_stir_shaken.h"
Include dependency graph for certificate.c:

Go to the source code of this file.

Data Structures

struct  stir_shaken_certificate
 

Macros

#define CONFIG_TYPE   "certificate"
 
#define TEST_CONFIG_NAME   "test_stir_shaken_certificate"
 
#define TEST_CONFIG_URL   "http://testing123"
 

Functions

static int attestation_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int on_load_attestation (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int on_load_path (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int on_load_public_cert_url (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int path_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int public_cert_url_to_str (const void *obj, const intptr_t *args, char **buf)
 
static void * stir_shaken_certificate_alloc (const char *name)
 
static int stir_shaken_certificate_apply (const struct ast_sorcery *sorcery, void *obj)
 
static void stir_shaken_certificate_destructor (void *obj)
 
static struct stir_shaken_certificatestir_shaken_certificate_get (const char *id)
 
static struct ao2_containerstir_shaken_certificate_get_all (void)
 
const char * stir_shaken_certificate_get_attestation (struct stir_shaken_certificate *cert)
 Get the attestation level associated with a certificate. More...
 
struct stir_shaken_certificatestir_shaken_certificate_get_by_caller_id_number (const char *caller_id_number)
 Get a STIR/SHAKEN certificate by caller ID number. More...
 
EVP_PKEY * stir_shaken_certificate_get_private_key (struct stir_shaken_certificate *cert)
 Get the private key associated with a certificate. More...
 
const char * stir_shaken_certificate_get_public_cert_url (struct stir_shaken_certificate *cert)
 Get the public key URL associated with a certificate. More...
 
int stir_shaken_certificate_load (void)
 Load time initialization for the stir/shaken 'certificate' configuration. More...
 
static char * stir_shaken_certificate_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * stir_shaken_certificate_show_all (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
int stir_shaken_certificate_unload (void)
 Unload time cleanup for the stir/shaken 'certificate' configuration. More...
 
int test_stir_shaken_cleanup_cert (const char *caller_id_number)
 
int test_stir_shaken_create_cert (const char *caller_id_number, const char *file_path)
 

Variables

static struct ast_cli_entry stir_shaken_certificate_cli []
 

Macro Definition Documentation

◆ CONFIG_TYPE

#define CONFIG_TYPE   "certificate"

◆ TEST_CONFIG_NAME

#define TEST_CONFIG_NAME   "test_stir_shaken_certificate"

Definition at line 276 of file certificate.c.

Referenced by test_stir_shaken_create_cert().

◆ TEST_CONFIG_URL

#define TEST_CONFIG_URL   "http://testing123"

Definition at line 278 of file certificate.c.

Referenced by test_stir_shaken_create_cert().

Function Documentation

◆ attestation_to_str()

static int attestation_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 264 of file certificate.c.

References ast_strdup, and stir_shaken_certificate::attestation.

Referenced by stir_shaken_certificate_load().

265 {
266  const struct stir_shaken_certificate *cfg = obj;
267 
268  *buf = ast_strdup(cfg->attestation);
269 
270  return 0;
271 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const ast_string_field attestation
Definition: certificate.c:43

◆ on_load_attestation()

static int on_load_attestation ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 251 of file certificate.c.

References ast_log, ast_sorcery_object_get_id(), ast_string_field_set, stir_shaken_certificate::attestation, LOG_ERROR, and ast_variable::value.

Referenced by stir_shaken_certificate_load().

252 {
253  struct stir_shaken_certificate *cfg = obj;
254 
255  if (strcmp(var->value, "A") && strcmp(var->value, "B") && strcmp(var->value, "C")) {
256  ast_log(LOG_ERROR, "stir/shaken - attestation level must be A, B, or C (object=%s)\n",
258  return -1;
259  }
260 
261  return ast_string_field_set(cfg, attestation, var->value);
262 }
const ast_string_field attestation
Definition: certificate.c:43
#define ast_log
Definition: astobj2.c:42
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define LOG_ERROR
Definition: logger.h:285
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ on_load_path()

static int on_load_path ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 203 of file certificate.c.

References ast_log, ast_string_field_set, LOG_ERROR, stir_shaken_certificate::path, and ast_variable::value.

Referenced by stir_shaken_certificate_load().

204 {
205  struct stir_shaken_certificate *cfg = obj;
206  struct stat statbuf;
207 
208  if (stat(var->value, &statbuf)) {
209  ast_log(LOG_ERROR, "stir/shaken - path '%s' not found\n", var->value);
210  return -1;
211  }
212 
213  if (!S_ISREG(statbuf.st_mode)) {
214  ast_log(LOG_ERROR, "stir/shaken - path '%s' is not a file\n", var->value);
215  return -1;
216  }
217 
218  return ast_string_field_set(cfg, path, var->value);
219 }
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ on_load_public_cert_url()

static int on_load_public_cert_url ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 230 of file certificate.c.

References ast_begins_with(), ast_log, ast_string_field_set, LOG_ERROR, stir_shaken_certificate::public_cert_url, and ast_variable::value.

Referenced by stir_shaken_certificate_load().

231 {
232  struct stir_shaken_certificate *cfg = obj;
233 
234  if (!ast_begins_with(var->value, "http")) {
235  ast_log(LOG_ERROR, "stir/shaken - public_cert_url scheme must be 'http[s]'\n");
236  return -1;
237  }
238 
239  return ast_string_field_set(cfg, public_cert_url, var->value);
240 }
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
const ast_string_field public_cert_url
Definition: certificate.c:43
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Definition: strings.h:94
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ path_to_str()

static int path_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 221 of file certificate.c.

References ast_strdup, and stir_shaken_certificate::path.

Referenced by stir_shaken_certificate_load().

222 {
223  const struct stir_shaken_certificate *cfg = obj;
224 
225  *buf = ast_strdup(cfg->path);
226 
227  return 0;
228 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const ast_string_field path
Definition: certificate.c:43

◆ public_cert_url_to_str()

static int public_cert_url_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 242 of file certificate.c.

References ast_strdup, and stir_shaken_certificate::public_cert_url.

Referenced by stir_shaken_certificate_load().

243 {
244  const struct stir_shaken_certificate *cfg = obj;
245 
246  *buf = ast_strdup(cfg->public_cert_url);
247 
248  return 0;
249 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const ast_string_field public_cert_url
Definition: certificate.c:43

◆ stir_shaken_certificate_alloc()

static void* stir_shaken_certificate_alloc ( const char *  name)
static

Definition at line 67 of file certificate.c.

References ao2_ref, ast_sorcery_generic_alloc(), ast_string_field_init, NULL, and stir_shaken_certificate_destructor().

Referenced by stir_shaken_certificate_load().

68 {
69  struct stir_shaken_certificate *cfg;
70 
72  if (!cfg) {
73  return NULL;
74  }
75 
76  if (ast_string_field_init(cfg, 512)) {
77  ao2_ref(cfg, -1);
78  return NULL;
79  }
80 
81  return cfg;
82 }
#define NULL
Definition: resample.c:96
static void stir_shaken_certificate_destructor(void *obj)
Definition: certificate.c:59
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728

◆ stir_shaken_certificate_apply()

static int stir_shaken_certificate_apply ( const struct ast_sorcery sorcery,
void *  obj 
)
static

Definition at line 111 of file certificate.c.

References ast_log, ast_strlen_zero, stir_shaken_certificate::attestation, stir_shaken_certificate::caller_id_number, LOG_ERROR, stir_shaken_certificate::path, stir_shaken_certificate::private_key, and stir_shaken_read_key().

Referenced by stir_shaken_certificate_load().

112 {
113  EVP_PKEY *private_key;
114  struct stir_shaken_certificate *cert = obj;
115 
116  if (ast_strlen_zero(cert->caller_id_number)) {
117  ast_log(LOG_ERROR, "Caller ID must be present\n");
118  return -1;
119  }
120 
121  if (ast_strlen_zero(cert->attestation)) {
122  ast_log(LOG_ERROR, "Attestation must be present\n");
123  return -1;
124  }
125 
126  private_key = stir_shaken_read_key(cert->path, 1);
127  if (!private_key) {
128  return -1;
129  }
130 
131  cert->private_key = private_key;
132 
133  return 0;
134 }
EVP_PKEY * stir_shaken_read_key(const char *path, int priv)
Reads the public (or private) key from the specified path.
Definition: stir_shaken.c:89
const ast_string_field attestation
Definition: certificate.c:43
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
const ast_string_field caller_id_number
Definition: certificate.c:43
const ast_string_field path
Definition: certificate.c:43

◆ stir_shaken_certificate_destructor()

static void stir_shaken_certificate_destructor ( void *  obj)
static

Definition at line 59 of file certificate.c.

References ast_string_field_free_memory, and stir_shaken_certificate::private_key.

Referenced by stir_shaken_certificate_alloc().

60 {
61  struct stir_shaken_certificate *cfg = obj;
62 
63  EVP_PKEY_free(cfg->private_key);
65 }
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ stir_shaken_certificate_get()

static struct stir_shaken_certificate* stir_shaken_certificate_get ( const char *  id)
static

Definition at line 48 of file certificate.c.

References ast_sorcery_retrieve_by_id(), ast_stir_shaken_sorcery(), and CONFIG_TYPE.

Referenced by stir_shaken_certificate_show().

49 {
51 }
#define CONFIG_TYPE
Definition: certificate.c:30
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.

◆ stir_shaken_certificate_get_all()

static struct ao2_container* stir_shaken_certificate_get_all ( void  )
static

Definition at line 53 of file certificate.c.

References AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_retrieve_by_fields(), ast_stir_shaken_sorcery(), CONFIG_TYPE, and NULL.

Referenced by stir_shaken_certificate_show(), and stir_shaken_certificate_show_all().

54 {
57 }
#define CONFIG_TYPE
Definition: certificate.c:30
Perform no matching, return all objects.
Definition: sorcery.h:123
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897

◆ stir_shaken_certificate_get_attestation()

const char* stir_shaken_certificate_get_attestation ( struct stir_shaken_certificate cert)

Get the attestation level associated with a certificate.

Parameters
certThe certificate
Return values
NULLon failure
Theattestation on success

Definition at line 101 of file certificate.c.

References stir_shaken_certificate::attestation, and NULL.

Referenced by ast_stir_shaken_sign().

102 {
103  return cert ? cert->attestation : NULL;
104 }
#define NULL
Definition: resample.c:96
const ast_string_field attestation
Definition: certificate.c:43

◆ stir_shaken_certificate_get_by_caller_id_number()

struct stir_shaken_certificate* stir_shaken_certificate_get_by_caller_id_number ( const char *  caller_id_number)

Get a STIR/SHAKEN certificate by caller ID number.

Parameters
callier_id_numberThe caller ID number
Return values
NULLif not found
Thecertificate on success

Definition at line 84 of file certificate.c.

References AST_RETRIEVE_FLAG_DEFAULT, ast_sorcery_retrieve_by_fields(), ast_stir_shaken_sorcery(), stir_shaken_certificate::caller_id_number, ast_variable::name, and NULL.

Referenced by ast_stir_shaken_sign(), and test_stir_shaken_cleanup_cert().

85 {
86  struct ast_variable fields = {
87  .name = "caller_id_number",
88  .value = caller_id_number,
89  .next = NULL,
90  };
91 
93  "certificate", AST_RETRIEVE_FLAG_DEFAULT, &fields);
94 }
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
Default retrieval flags.
Definition: sorcery.h:117
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897

◆ stir_shaken_certificate_get_private_key()

EVP_PKEY* stir_shaken_certificate_get_private_key ( struct stir_shaken_certificate cert)

Get the private key associated with a certificate.

Parameters
certThe certificate to get the private key from
Return values
NULLon failure
Theprivate key on success

Definition at line 106 of file certificate.c.

References NULL, and stir_shaken_certificate::private_key.

Referenced by ast_stir_shaken_sign().

107 {
108  return cert ? cert->private_key : NULL;
109 }
#define NULL
Definition: resample.c:96

◆ stir_shaken_certificate_get_public_cert_url()

const char* stir_shaken_certificate_get_public_cert_url ( struct stir_shaken_certificate cert)

Get the public key URL associated with a certificate.

Parameters
certThe certificate to get the public key URL from
Return values
NULLon failure
Thepublic key URL on success

Definition at line 96 of file certificate.c.

References NULL, and stir_shaken_certificate::public_cert_url.

Referenced by ast_stir_shaken_sign().

97 {
98  return cert ? cert->public_cert_url : NULL;
99 }
#define NULL
Definition: resample.c:96
const ast_string_field public_cert_url
Definition: certificate.c:43

◆ stir_shaken_certificate_load()

int stir_shaken_certificate_load ( void  )

Load time initialization for the stir/shaken 'certificate' configuration.

Return values
0on success, -1 on error

Definition at line 355 of file certificate.c.

References ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_sorcery_apply_default, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_register, ast_stir_shaken_sorcery(), attestation_to_str(), stir_shaken_certificate::caller_id_number, CONFIG_TYPE, LOG_ERROR, NULL, on_load_attestation(), on_load_path(), on_load_public_cert_url(), OPT_NOOP_T, OPT_STRINGFIELD_T, path_to_str(), public_cert_url_to_str(), sorcery, stir_shaken_certificate_alloc(), stir_shaken_certificate_apply(), and STRFLDSET.

Referenced by load_module().

356 {
358 
359  ast_sorcery_apply_default(sorcery, CONFIG_TYPE, "config", "stir_shaken.conf,criteria=type=certificate");
360 
363  ast_log(LOG_ERROR, "stir/shaken - failed to register '%s' sorcery object\n", CONFIG_TYPE);
364  return -1;
365  }
366 
367  ast_sorcery_object_field_register(sorcery, CONFIG_TYPE, "type", "", OPT_NOOP_T, 0, 0);
369  on_load_path, path_to_str, NULL, 0, 0);
370  ast_sorcery_object_field_register_custom(sorcery, CONFIG_TYPE, "public_cert_url", "",
372  ast_sorcery_object_field_register_custom(sorcery, CONFIG_TYPE, "attestation", "",
374  ast_sorcery_object_field_register(sorcery, CONFIG_TYPE, "caller_id_number", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct stir_shaken_certificate, caller_id_number));
375 
378 
379  return 0;
380 }
static int on_load_path(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: certificate.c:203
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define CONFIG_TYPE
Definition: certificate.c:30
static int on_load_public_cert_url(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: certificate.c:230
Full structure for sorcery.
Definition: sorcery.c:230
Type for a default handler that should do nothing.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define NULL
Definition: resample.c:96
static void * stir_shaken_certificate_alloc(const char *name)
Definition: certificate.c:67
#define ast_log
Definition: astobj2.c:42
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
Definition: sorcery.h:1005
static int public_cert_url_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: certificate.c:242
static struct ast_cli_entry stir_shaken_certificate_cli[]
Definition: certificate.c:198
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:838
#define LOG_ERROR
Definition: logger.h:285
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:477
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
static int path_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: certificate.c:221
static struct ast_sorcery * sorcery
static int stir_shaken_certificate_apply(const struct ast_sorcery *sorcery, void *obj)
Definition: certificate.c:111
Type for default option handler for stringfields.
static int attestation_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: certificate.c:264
static int on_load_attestation(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: certificate.c:251

◆ stir_shaken_certificate_show()

static char* stir_shaken_certificate_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 136 of file certificate.c.

References ao2_cleanup, ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, NULL, ast_cli_args::pos, stir_shaken_certificate_get(), stir_shaken_certificate_get_all(), stir_shaken_cli_show(), stir_shaken_tab_complete_name(), ast_cli_entry::usage, and ast_cli_args::word.

137 {
138  struct stir_shaken_certificate *cfg;
139 
140  switch(cmd) {
141  case CLI_INIT:
142  e->command = "stir_shaken show certificate";
143  e->usage =
144  "Usage: stir_shaken show certificate <id>\n"
145  " Show the certificate stir/shaken settings for a given id\n";
146  return NULL;
147  case CLI_GENERATE:
148  if (a->pos == 3) {
150  } else {
151  return NULL;
152  }
153  }
154 
155  if (a->argc != 4) {
156  return CLI_SHOWUSAGE;
157  }
158 
159  cfg = stir_shaken_certificate_get(a->argv[3]);
160  stir_shaken_cli_show(cfg, a, 0);
161  ao2_cleanup(cfg);
162 
163  return CLI_SUCCESS;
164 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
char * stir_shaken_tab_complete_name(const char *word, struct ao2_container *container)
Tab completion for name matching with STIR/SHAKEN CLI commands.
Definition: stir_shaken.c:66
int stir_shaken_cli_show(void *obj, void *arg, int flags)
Output configuration settings to the Asterisk CLI.
Definition: stir_shaken.c:35
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
static struct stir_shaken_certificate * stir_shaken_certificate_get(const char *id)
Definition: certificate.c:48
static struct ao2_container * stir_shaken_certificate_get_all(void)
Definition: certificate.c:53
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const int pos
Definition: cli.h:164

◆ stir_shaken_certificate_show_all()

static char* stir_shaken_certificate_show_all ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 166 of file certificate.c.

References ao2_callback, ao2_cleanup, ao2_container_count(), ao2_ref, ast_cli_args::argc, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, container, ast_cli_args::fd, NULL, OBJ_NODATA, stir_shaken_certificate_get_all(), stir_shaken_cli_show(), and ast_cli_entry::usage.

167 {
168  struct ao2_container *container;
169 
170  switch(cmd) {
171  case CLI_INIT:
172  e->command = "stir_shaken show certificates";
173  e->usage =
174  "Usage: stir_shaken show certificates\n"
175  " Show all configured certificates for stir/shaken\n";
176  return NULL;
177  case CLI_GENERATE:
178  return NULL;
179  }
180 
181  if (a->argc != 3) {
182  return CLI_SHOWUSAGE;
183  }
184 
185  container = stir_shaken_certificate_get_all();
186  if (!container || ao2_container_count(container) == 0) {
187  ast_cli(a->fd, "No stir/shaken certificates found\n");
188  ao2_cleanup(container);
189  return CLI_SUCCESS;
190  }
191 
193  ao2_ref(container, -1);
194 
195  return CLI_SUCCESS;
196 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
const int argc
Definition: cli.h:160
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * container
Definition: res_fax.c:502
int stir_shaken_cli_show(void *obj, void *arg, int flags)
Output configuration settings to the Asterisk CLI.
Definition: stir_shaken.c:35
#define CLI_SHOWUSAGE
Definition: cli.h:45
static struct ao2_container * stir_shaken_certificate_get_all(void)
Definition: certificate.c:53
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ stir_shaken_certificate_unload()

int stir_shaken_certificate_unload ( void  )

Unload time cleanup for the stir/shaken 'certificate' configuration.

Return values
0on success, -1 on error

Definition at line 347 of file certificate.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by unload_module().

348 {
351 
352  return 0;
353 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry stir_shaken_certificate_cli[]
Definition: certificate.c:198

◆ test_stir_shaken_cleanup_cert()

int test_stir_shaken_cleanup_cert ( const char *  caller_id_number)

Definition at line 280 of file certificate.c.

References ao2_cleanup, ast_log, ast_sorcery_delete(), ast_sorcery_remove_wizard_mapping, ast_stir_shaken_sorcery(), CONFIG_TYPE, LOG_ERROR, sorcery, and stir_shaken_certificate_get_by_caller_id_number().

Referenced by AST_TEST_DEFINE(), and test_stir_shaken_create_cert().

281 {
282  struct stir_shaken_certificate *cert;
283  struct ast_sorcery *sorcery;
284  int res = 0;
285 
286  sorcery = ast_stir_shaken_sorcery();
287 
288  cert = stir_shaken_certificate_get_by_caller_id_number(caller_id_number);
289  if (!cert) {
290  return 0;
291  }
292 
293  res = ast_sorcery_delete(sorcery, cert);
294  ao2_cleanup(cert);
295  if (res) {
296  ast_log(LOG_ERROR, "Failed to delete sorcery object with caller ID "
297  "'%s'\n", caller_id_number);
298  return -1;
299  }
300 
301  res = ast_sorcery_remove_wizard_mapping(sorcery, CONFIG_TYPE, "memory");
302 
303  return res;
304 }
#define ast_sorcery_remove_wizard_mapping(sorcery, type, name)
Remove an object wizard mapping.
Definition: sorcery.h:758
#define CONFIG_TYPE
Definition: certificate.c:30
Full structure for sorcery.
Definition: sorcery.c:230
#define ast_log
Definition: astobj2.c:42
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
Definition: sorcery.c:2233
#define LOG_ERROR
Definition: logger.h:285
struct stir_shaken_certificate * stir_shaken_certificate_get_by_caller_id_number(const char *caller_id_number)
Get a STIR/SHAKEN certificate by caller ID number.
Definition: certificate.c:84
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
static struct ast_sorcery * sorcery
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ test_stir_shaken_create_cert()

int test_stir_shaken_create_cert ( const char *  caller_id_number,
const char *  file_path 
)

Definition at line 306 of file certificate.c.

References ast_log, ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_insert_wizard_mapping, ast_stir_shaken_sorcery(), ast_string_field_set, CONFIG_TYPE, LOG_ERROR, stir_shaken_certificate::path, stir_shaken_certificate::private_key, stir_shaken_certificate::public_cert_url, sorcery, stir_shaken_read_key(), TEST_CONFIG_NAME, TEST_CONFIG_URL, and test_stir_shaken_cleanup_cert().

Referenced by AST_TEST_DEFINE().

307 {
308  struct stir_shaken_certificate *cert;
309  struct ast_sorcery *sorcery;
310  EVP_PKEY *private_key;
311  int res = 0;
312 
313  sorcery = ast_stir_shaken_sorcery();
314 
315  res = ast_sorcery_insert_wizard_mapping(sorcery, CONFIG_TYPE, "memory", "testing", 0, 0);
316  if (res) {
317  ast_log(LOG_ERROR, "Failed to insert STIR/SHAKEN test certificate mapping\n");
318  return -1;
319  }
320 
322  if (!cert) {
323  ast_log(LOG_ERROR, "Failed to allocate test certificate\n");
324  return -1;
325  }
326 
327  ast_string_field_set(cert, path, file_path);
328  ast_string_field_set(cert, public_cert_url, TEST_CONFIG_URL);
329  ast_string_field_set(cert, caller_id_number, caller_id_number);
330 
331  private_key = stir_shaken_read_key(cert->path, 1);
332  if (!private_key) {
333  ast_log(LOG_ERROR, "Failed to read test key from %s\n", cert->path);
334  test_stir_shaken_cleanup_cert(caller_id_number);
335  return -1;
336  }
337 
338  cert->private_key = private_key;
339 
340  ast_sorcery_create(sorcery, cert);
341 
342  return res;
343 }
#define CONFIG_TYPE
Definition: certificate.c:30
EVP_PKEY * stir_shaken_read_key(const char *path, int priv)
Reads the public (or private) key from the specified path.
Definition: stir_shaken.c:89
Full structure for sorcery.
Definition: sorcery.c:230
#define ast_sorcery_insert_wizard_mapping(sorcery, type, name, data, caching, position)
Insert an additional object wizard mapping at a specific position in the wizard list.
Definition: sorcery.h:563
#define ast_log
Definition: astobj2.c:42
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
Definition: sorcery.c:2057
#define LOG_ERROR
Definition: logger.h:285
int test_stir_shaken_cleanup_cert(const char *caller_id_number)
Definition: certificate.c:280
#define TEST_CONFIG_NAME
Definition: certificate.c:276
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
#define TEST_CONFIG_URL
Definition: certificate.c:278
static struct ast_sorcery * sorcery
const ast_string_field path
Definition: certificate.c:43
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

Variable Documentation

◆ stir_shaken_certificate_cli

struct ast_cli_entry stir_shaken_certificate_cli[]
static
Initial value:
= {
{ .handler = stir_shaken_certificate_show , .summary = "Show stir/shaken certificate configuration by id" ,},
{ .handler = stir_shaken_certificate_show_all , .summary = "Show all stir/shaken certificate configurations" ,},
}
static char * stir_shaken_certificate_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: certificate.c:166
static char * stir_shaken_certificate_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: certificate.c:136

Definition at line 198 of file certificate.c.