31#ifndef HAVE_PJSIP_AUTH_NEW_DIGESTS
39#include "openssl/md5.h"
40#include "openssl/sha.h"
42#define MD5_DIGEST_LENGTH 16
43#define SHA256_DIGEST_LENGTH 32
69#ifdef HAVE_PJSIP_AUTH_NEW_DIGESTS
70 return pjsip_auth_get_algorithm_by_type(algorithm_type);
84 const pj_str_t *iana_name)
86#ifdef HAVE_PJSIP_AUTH_NEW_DIGESTS
87 return pjsip_auth_get_algorithm_by_iana_name(iana_name);
97 if (iana_name->slen == 0 || pj_stricmp2(iana_name,
"MD5") == 0) {
107#ifdef HAVE_PJSIP_AUTH_NEW_DIGESTS
108 return pjsip_auth_is_algorithm_supported(algorithm_type);
151 if (!strcasecmp(
var->value,
"userpass")) {
153 }
else if (!strcasecmp(
var->value,
"md5")) {
155 }
else if (!strcasecmp(
var->value,
"digest")) {
157 }
else if (!strcasecmp(
var->value,
"google_oauth")) {
158#ifdef HAVE_PJSIP_OAUTH_AUTHENTICATION
161 ast_log(
LOG_WARNING,
"OAuth support is not available in the version of PJSIP in use\n");
208 val.slen = strlen(
val.ptr);
218 ast_log(
LOG_WARNING,
"%s: %s digest algorithm '%s' is not supported by the version of OpenSSL in use\n",
272 return *
buf ? 0 : -1;
292 char *unparsed_digest =
NULL;
299 pj_str_t pj_iana_name;
305 if (strchr(unparsed_digest,
':') !=
NULL) {
316 pj_iana_name = pj_str(iana_name);
321 auth_name, iana_name);
325 ast_log(
LOG_WARNING,
"%s: password_digest algorithm '%s' is not supported by the version of OpenSSL in use\n",
326 auth_name, iana_name);
414 *cred_type = PJSIP_CRED_DATA_DIGEST;
418 *cred_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
430 ast_log(
LOG_ERROR,
"%s: No plain text or digest password found for algorithm "
455 ast_log(
LOG_ERROR,
"%s: 'google_oauth' authentication specified but refresh_token,"
456 " oauth_clientid, or oauth_secret not specified\n",
id);
503 if (on_auth(auth, arg, 0)) {
553 ami->
arg = (
void *)endpoint;
669 "%*s: <AuthId/UserName%*.*s>\n", indent,
"I/OAuth", filler, filler,
683 snprintf(title,
sizeof(title),
"%sAuth",
691 || (
context->show_details_only_level_0 &&
context->indent_level == 0)) {
702 .
usage =
"Usage: pjsip list auths [ like <pattern> ]\n"
703 " List the configured PJSIP Auths\n"
704 " Optional regular expression pattern is used to filter the list.\n"),
707 .
usage =
"Usage: pjsip show auths [ like <pattern> ]\n"
708 " Show the configured PJSIP Auths\n"
709 " Optional regular expression pattern is used to filter the list.\n"),
712 .
usage =
"Usage: pjsip show auth <id>\n"
713 " Show the configured PJSIP Auth\n"),
static struct aco_type agent_type
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_calloc(num, len)
A wrapper for calloc()
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
#define ao2_alloc(data_size, destructor_fn)
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static struct ast_sorcery_observer global_observer
Observer which is used to update our interval and default_realm when the global setting changes.
#define MD5_DIGEST_LENGTH
const pjsip_auth_algorithm * ast_sip_auth_get_algorithm_by_iana_name(const pj_str_t *iana_name)
Get algorithm by IANA name.
const pjsip_auth_algorithm * ast_sip_auth_get_algorithm_by_type(pjsip_auth_algorithm_type algorithm_type)
Get algorithm by algorithm type.
static struct ast_cli_entry cli_commands[]
static void global_loaded(const char *object_type)
static int cli_print_header(void *obj, void *arg, int flags)
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
static int md5cred_to_str(const void *obj, const intptr_t *args, char **buf)
int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths, struct ast_sip_ami *ami)
Format auth details for AMI.
static int sip_auth_to_ami(const struct ast_sip_auth *auth, struct ast_str **buf)
static const char * auth_types_map[]
int ast_sip_auth_digest_algorithms_vector_init(const char *id, struct pjsip_auth_algorithm_type_vector *algorithms, const char *agent_type, const char *value)
Populate a vector of algorithm types from a string.
static int format_ami_authlist_handler(void *obj, void *arg, int flags)
static struct ast_sip_endpoint_formatter endpoint_auth_formatter
static int password_digest_to_str(const void *obj, const intptr_t *args, char **buf)
pj_bool_t ast_sip_auth_is_algorithm_supported(pjsip_auth_algorithm_type algorithm_type)
Is algorithm supported by OpenSSL and pjproject?
static void * auth_alloc(const char *name)
static struct ao2_container * cli_get_auths(void)
static int format_ami_auth_handler(void *obj, void *arg, int flags)
static void * cli_retrieve_by_id(const char *id)
static int auth_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static int uac_algorithms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
int ast_sip_auth_digest_algorithms_vector_to_str(const struct pjsip_auth_algorithm_type_vector *algorithms, char **buf)
Dump a vector of algorithm types to a string.
#define SHA256_DIGEST_LENGTH
static int auth_apply(const struct ast_sorcery *sorcery, void *obj)
static struct ao2_container * cli_get_container(const char *regex)
static int password_digest_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static int format_ami_endpoint_auth(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
static int cli_print_body(void *obj, void *arg, int flags)
static int ami_show_auths(struct mansession *s, const struct message *m)
static int uas_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
static int uas_algorithms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
int ast_sip_for_each_auth(const struct ast_sip_auth_vector *vector, ao2_callback_fn on_auth, void *arg)
For every auth in the array call the given 'on_auth' handler.
const char * ast_sip_auth_get_creds(const struct ast_sip_auth *auth, const pjsip_auth_algorithm_type algorithm_type, int *cred_type)
Get the plain text or digest password from an auth object.
int ast_sip_auth_is_algorithm_available(const struct ast_sip_auth *auth, const struct pjsip_auth_algorithm_type_vector *algorithms, pjsip_auth_algorithm_type algorithm_type)
Checks an pjsip_auth_algorithm_type_vector to see if it contains an algorithm.
static int auth_type_to_str(const void *obj, const intptr_t *args, char **buf)
int ast_sip_destroy_sorcery_auth(void)
const pjsip_auth_algorithm pjsip_auth_algorithms[]
const char * ast_sip_auth_type_to_str(enum ast_sip_auth_type type)
Converts the given auth type to a string.
static struct ast_sip_cli_formatter_entry * cli_formatter
static int uac_algorithms_to_str(const void *obj, const intptr_t *args, char **buf)
int ast_sip_initialize_sorcery_auth(void)
Initialize sorcery with auth support.
static int check_algorithm(const struct ast_sip_auth *auth, const pjsip_auth_algorithm_type algorithm_type, const char *which_supported)
static void auth_destroy(void *obj)
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
void astman_append(struct mansession *s, const char *fmt,...)
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Support for logging to various files, console and syslog Configuration in file logger....
#define EVENT_FLAG_SYSTEM
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
struct ao2_container * container
pjsip_auth_algorithm_type
@ PJSIP_AUTH_ALGORITHM_COUNT
@ PJSIP_AUTH_ALGORITHM_AKAV1_MD5
@ PJSIP_AUTH_ALGORITHM_NOT_SET
@ PJSIP_AUTH_ALGORITHM_SHA512_256
@ PJSIP_AUTH_ALGORITHM_SHA256
@ PJSIP_AUTH_ALGORITHM_MD5
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
ast_sip_auth_type
Authentication methods.
@ AST_SIP_AUTH_TYPE_GOOGLE_OAUTH
@ AST_SIP_AUTH_TYPE_DIGEST
@ AST_SIP_AUTH_TYPE_USER_PASS
#define AST_SIP_AUTH_MAX_SUPPORTED_ALGORITHMS_LENGTH
#define SIP_SORCERY_AUTH_TYPE
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define PJSTR_PRINTF_VAR(_v)
void ast_sip_get_default_auth_algorithms_uac(char *default_auth_algorithms_uac, size_t size)
Retrieve the global auth algorithms for UAC.
void ast_sip_get_default_auth_algorithms_uas(char *default_auth_algorithms_uas, size_t size)
Retrieve the global auth algorithms for UAS.
#define PJSTR_PRINTF_SPEC
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
#define CLI_HEADER_FILLER
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define CLI_INDENT_TO_SPACES(x)
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
static struct ast_sorcery * sorcery
Sorcery Data Access Layer API.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
#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.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
void ast_sorcery_force_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects even if no changes determin...
#define ast_sorcery_apply_default(sorcery, type, name, data)
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.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_alloca(init_len)
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
descriptor for a cli entry.
pjsip_auth_algorithm_type algorithm_type
struct pjsip_auth_algorithm_type_vector supported_algorithms_uac
const ast_string_field oauth_clientid
const ast_string_field oauth_secret
const ast_string_field auth_user
struct ast_sip_auth_password_digest * password_digests[PJSIP_AUTH_ALGORITHM_COUNT]
struct pjsip_auth_algorithm_type_vector supported_algorithms_uas
const ast_string_field refresh_token
const ast_string_field auth_pass
enum ast_sip_auth_type type
CLI Formatter Context passed to all formatters.
CLI Formatter Registry Entry.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
ao2_callback_fn * print_header
void *(* retrieve_by_id)(const char *id)
const char *(* get_id)(const void *obj)
ao2_callback_fn * print_body
struct ao2_container *(* get_container)(const char *regex)
An entity with which Asterisk communicates.
struct ast_sip_auth_vector outbound_auths
struct ast_sip_auth_vector inbound_auths
Interface for a sorcery object type observer.
void(* loaded)(const char *object_type)
Callback for when an object type is loaded/reloaded.
Full structure for sorcery.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
In case you didn't read that giant block of text above the mansession_session struct,...
pjsip_auth_algorithm_type algorithm_type
unsigned digest_str_length
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Vector container support.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.