21#define _TRACE_PREFIX_ "a",__LINE__, ""
68 const char *profile_name,
82 if (as_cfg->global_disable) {
84 "%s: Globally disabled\n", t);
89 "%s: Disabled due to missing profile name\n", t);
95 LOG_ERROR,
"%s: No profile for profile name '%s'. Call will continue\n",
tag,
101 "%s: Disabled by profile '%s'\n", t, profile_name);
109 if (!canon_orig_tn) {
111 LOG_ERROR,
"%s: Must provide caller_id/orig_tn\n",
tag);
114 if (!canon_dest_tn) {
127 "%s: No tn for orig_tn '%s'\n",
tag, canon_orig_tn);
140 "'%s': No attest_level specified in tn, profile or attestation objects\n",
146 LOG_ERROR,
"%s: No public cert url in tn %s, profile or attestation objects\n",
152 LOG_ERROR,
"%s: No private key in tn %s, profile or attestation objects\n",
160 LOG_ERROR,
"%s: Unable to allocate memory for ctx\n",
tag);
165 LOG_ERROR,
"%s: Unable to allocate memory for ctx\n",
tag);
170 LOG_ERROR,
"%s: Unable to allocate memory for ctx\n",
tag);
175 LOG_ERROR,
"%s: Unable to allocate memory for ctx\n",
tag);
180 LOG_ERROR,
"%s: Unable to allocate memory for ctx\n",
tag);
188 LOG_ERROR,
"%s: Unable to allocate memory for ctx\n",
tag);
209 char *compacted_fp =
ast_alloca(strlen(fingerprint) + 1);
210 const char *f = fingerprint;
211 char *fp = compacted_fp;
214 SCOPE_ENTER(4,
"%s: Add fingerprint %s:%s\n", ctx ? ctx->
tag :
"",
219 "%s: Missing arguments\n", ctx->
tag);
224 "%s: Not needed\n", ctx->
tag);
235 rc =
ast_asprintf(&combined,
"%s:%s", alg, compacted_fp);
238 "%s: Can't allocate memory for comobined string\n", ctx->
tag);
244 "%s: Can't add entry to vector\n", ctx->
tag);
248 "%s: Done\n", ctx->
tag);
256#define CREATE_JSON_SET_OBJ(__val, __obj, __name) \
258 struct ast_json *__var; \
259 if (!(__var = __val)) {\
260 SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INTERNAL_ERROR, \
261 LOG_ERROR, "%s: Cannot allocate one of the JSON objects\n", \
264 if (ast_json_object_set(__obj, __name, __var)) { \
265 SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INTERNAL_ERROR, \
266 LOG_ERROR, "%s: Cannot set one of the JSON objects\n", \
273#define CREATE_JSON_APPEND_ARRAY(__val, __obj) \
275 struct ast_json *__var; \
276 if (!(__var = __val)) {\
277 SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INTERNAL_ERROR, \
278 LOG_ERROR, "%s: Cannot allocate one of the JSON objects\n", \
281 if (ast_json_array_append(__obj, __var)) { \
282 SCOPE_EXIT_LOG_RTN_VALUE(AST_STIR_SHAKEN_AS_INTERNAL_ERROR, \
283 LOG_ERROR, "%s: Cannot set one of the JSON objects\n", \
302 char *payload_str =
NULL;
340 char *fp = strchr(afp,
':');
356 ast_trace(2,
"Payload: %s\n", payload_str);
357 jwt_add_grants_json(jwt, payload_str);
369 char *encoded =
NULL;
372 SCOPE_ENTER(3,
"%s: Attestation: orig: %s dest: %s\n",
373 ctx ? ctx->
tag :
"NULL", ctx ? ctx->
orig_tn :
"NULL",
378 "%s: No context object!\n",
"NULL");
408 encoded = jwt_encode_str(jwt);
411 LOG_ERROR,
"%s: Unable to sign/encode JWT\n", ctx->
tag);
420 LOG_ERROR,
"%s: Unable to allocate memory for identity header\n",
Asterisk main include file. File version handling, generic pbx functions.
void ast_std_free(void *ptr)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_alloc_options(data_size, destructor_fn, options)
int as_load()
Load the stir/shaken attestation service.
static const char * as_rc_map[]
const char * as_response_code_to_str(enum ast_stir_shaken_as_response_code as_rc)
Return string version of AS response code.
enum ast_stir_shaken_as_response_code ast_stir_shaken_as_ctx_add_fingerprint(struct ast_stir_shaken_as_ctx *ctx, const char *alg, const char *fingerprint)
Add DTLS fingerprints to AS context.
#define CREATE_JSON_APPEND_ARRAY(__val, __obj)
int as_unload()
Load the stir/shaken attestation service.
#define CREATE_JSON_SET_OBJ(__val, __obj, __name)
static void ctx_destructor(void *obj)
int as_reload()
Load the stir/shaken attestation service.
enum ast_stir_shaken_as_response_code ast_stir_shaken_attest(struct ast_stir_shaken_as_ctx *ctx, char **header)
Attest and return Identity header value.
enum ast_stir_shaken_as_response_code ast_stir_shaken_as_ctx_create(const char *orig_tn, const char *dest_tn, struct ast_channel *chan, const char *profile_name, const char *tag, struct ast_stir_shaken_as_ctx **ctxout)
Create Attestation Service Context.
int ast_stir_shaken_as_ctx_wants_fingerprints(struct ast_stir_shaken_as_ctx *ctx)
Indicates if the AS context needs DTLS fingerprints.
static enum ast_stir_shaken_as_response_code pack_payload(struct ast_stir_shaken_as_ctx *ctx, jwt_t *jwt)
int as_config_unload(void)
int as_config_reload(void)
struct attestation_cfg * as_get_cfg(void)
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
#define ast_channel_cleanup(c)
Cleanup a channel reference.
char * canonicalize_tn_alloc(const char *tn)
Canonicalize a TN into nre buffer.
struct profile_cfg * eprofile_get_cfg(const char *id)
#define ENUM_BOOL(__enum1, __field)
#define PROFILE_ALLOW_ATTEST(__profile)
struct tn_cfg * tn_get_etn(const char *tn, struct profile_cfg *eprofile)
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level,...)
#define SCOPE_ENTER(level,...)
#define ast_trace(level,...)
Asterisk JSON abstraction layer.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
char * ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format)
Encode a JSON value to a string.
Asterisk module definitions.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
ast_stir_shaken_as_response_code
@ AST_STIR_SHAKEN_AS_NO_TN_FOR_CALLERID
@ AST_STIR_SHAKEN_AS_INVALID_ARGUMENTS
@ AST_STIR_SHAKEN_AS_TO_HDR_BAD_URI
@ AST_STIR_SHAKEN_AS_MISSING_PARAMETERS
@ AST_STIR_SHAKEN_AS_NO_PRIVATE_KEY_AVAIL
@ AST_STIR_SHAKEN_AS_DISABLED
@ AST_STIR_SHAKEN_AS_SIGN_ENCODE_FAILURE
@ AST_STIR_SHAKEN_AS_NO_TO_HDR
@ AST_STIR_SHAKEN_AS_NO_PUBLIC_CERT_URL_AVAIL
@ AST_STIR_SHAKEN_AS_SUCCESS
@ AST_STIR_SHAKEN_AS_INTERNAL_ERROR
@ AST_STIR_SHAKEN_AS_IDENTITY_HDR_EXISTS
@ AST_STIR_SHAKEN_AS_NO_ATTEST_LEVEL
@ AST_STIR_SHAKEN_VS_INTERNAL_ERROR
#define STIR_SHAKEN_ENCRYPTION_ALGORITHM
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#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
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Main Channel structure associated with a channel.
Abstract JSON element (object, array, string, int, ...).
const ast_string_field dest_tn
const ast_string_field orig_tn
const ast_string_field tag
struct ast_channel * chan
struct ast_vector_string fingerprints
enum attest_level_enum attest_level
const ast_string_field public_cert_url
enum send_mky_enum send_mky
Profile configuration for stir/shaken.
TN configuration for stir/shaken.
struct attestation_cfg_common acfg_common
#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.
Universally unique identifier support.
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
#define AST_VECTOR_ADD_SORTED(vec, elem, cmp)
Add an element into a sorted vector.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.