29#define _TRACE_PREFIX_ "pjss",__LINE__, "" 
   55#define SIP_RESPONSE_CODE_OK_STR "OK" 
   57#define SIP_RESPONSE_CODE_STALE_DATE_STR "Stale Date" 
   58#define SIP_RESPONSE_CODE_USE_IDENTITY_HEADER_STR "Use Identity Header" 
   59#define SIP_RESPONSE_CODE_ANONYMITY_DISALLOWED_STR "Anonymity Disallowed" 
   60#define SIP_RESPONSE_CODE_BAD_IDENTITY_INFO_STR "Bad Identity Info" 
   61#define SIP_RESPONSE_CODE_UNSUPPORTED_CREDENTIAL_STR "Unsupported Credential" 
   62#define SIP_RESPONSE_CODE_INVALID_IDENTITY_HEADER_STR "Invalid Identity Header" 
   63#define SIP_RESPONSE_CODE_INTERNAL_ERROR_STR "Internal Error" 
   65#define response_to_str(_code) \ 
 
   85#define translate_code(_vs_rc, _sip_rc) \ 
   86case AST_STIR_SHAKEN_VS_ ## _vs_rc: \ 
   87    return SIP_RESPONSE_CODE_ ## _sip_rc; 
 
  116    translate_code(CERT_NO_SPC_IN_TN_AUTH_EXT,  UNSUPPORTED_CREDENTIAL)
 
 
  157    pj_str_t response_str;
 
  158    const char *response_string =
 
  164        failure_action, response_code);
 
  166    pj_cstr(&response_str, response_string);
 
  171            "%s: Rejecting request and terminating session\n",
 
  181            response_code, response_str.ptr);
 
  184                "%s: Failed to add Reason header\n", tag);
 
  187            "%s: Attaching reason code to session\n", tag);
 
  190        "%s: Continuing\n", tag);
 
 
  208    char *identity_hdr_val;
 
  210    char *caller_id = 
session->id.number.str;
 
  228    if (rdata->msg_info.to->tag.slen) {
 
  240        session->endpoint->stir_shaken_profile,
 
 
  317    SCOPE_ENTER(4, 
"%s: Check %zu media sessions for fingerprints\n",
 
  324    for (i = 0; i < count; i++) {
 
  329            ast_trace(1, 
"Session: %d: No session or rtp instance\n", i);
 
  333        h = 
d->get_fingerprint_hash(m->
rtp);
 
  334        f = 
d->get_fingerprint(m->
rtp);
 
 
  344    pjsip_fromto_hdr *to;
 
  346    char *dest_tn = 
NULL;
 
  349    to = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_TO, 
NULL);
 
  354    uri = pjsip_uri_get_uri(to->uri);
 
  357            "%s: Failed to retrieve URI from To header\n", tag);
 
  363            "%s: Failed to allocate memory for dest_tn\n", tag);
 
 
  373    pjsip_fromto_hdr *old_date;
 
  379        SCOPE_EXIT_RTN(
"Found existing Date header, no need to add one\n");
 
 
  387    pjsip_tx_data *tdata)
 
  391    pjsip_generic_string_hdr *old_identity;
 
  392    pjsip_generic_string_hdr *identity_hdr;
 
  393    pj_str_t identity_val;
 
  415    if (attestation_ds && attestation_ds->
suppress) {
 
  446        session->endpoint->stir_shaken_profile,
 
  466            "%s: Failed to create attestation\n", session_name);
 
  469    ast_trace(1, 
"%s: Identity header: %s\n", session_name, identity_str);
 
  470    identity_val = pj_str(identity_str);
 
  471    identity_hdr = pjsip_generic_string_hdr_create(tdata->pool, &
identity_hdr_str, &identity_val);
 
  476            "%s: Unable to create Identity header\n", session_name);
 
  479    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)identity_hdr);
 
 
  504#undef AST_BUILDOPT_SUM 
  505#define AST_BUILDOPT_SUM "" 
  512    .
requires = 
"res_pjsip,res_pjsip_session,res_stir_shaken",
 
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ast_malloc(len)
A wrapper for malloc()
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
#define ast_channel_lock(chan)
void ast_party_id_free(struct ast_party_id *doomed)
Destroy the party id contents.
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
Copy the source party id information to the destination party id.
struct ast_party_id ast_channel_connected_effective_id(struct ast_channel *chan)
#define ast_channel_unlock(chan)
Asterisk datastore objects.
#define SCOPE_EXIT_LOG(__log_level,...)
#define SCOPE_EXIT_RTN(...)
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level,...)
#define SCOPE_ENTER(level,...)
#define SCOPE_EXIT_LOG_RTN(__log_level,...)
#define ast_trace(level,...)
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
char * ast_sip_rdata_get_header_value(pjsip_rx_data *rdata, const pj_str_t str)
Get a specific header value from rdata.
void ast_sip_add_date_header(pjsip_tx_data *tdata)
Adds a Date header to the tdata, formatted like: Date: Wed, 01 Jan 2021 14:53:01 GMT.
@ AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
int ast_sip_can_present_connected_id(const struct ast_sip_session *session, const struct ast_party_id *id)
Determines if the Connected Line info can be presented for this session.
#define ast_sip_session_register_supplement(supplement)
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
int ast_sip_session_add_reason_header(struct ast_sip_session *session, const char *protocol, int code, const char *text)
Adds a Reason header in the next reponse to an incoming INVITE.
void ast_sip_session_terminate(struct ast_sip_session *session, int response)
Terminate a session and, if possible, send the provided response code.
const char * ast_sip_session_get_name(const struct ast_sip_session *session)
Get the channel or endpoint name associated with the session.
@ PROCESS_FAILURE_SYSTEM_FAILURE
@ PROCESS_FAILURE_CONTINUE
static void reject_incoming_call(struct ast_sip_session *session, enum sip_response_code response_code)
static enum sip_response_code vs_code_to_sip_code(enum ast_stir_shaken_vs_response_code vs_rc)
static void stir_shaken_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
static int stir_shaken_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
static const pj_str_t identity_hdr_str
static void add_date_header(const struct ast_sip_session *session, pjsip_tx_data *tdata)
@ SIP_RESPONSE_CODE_USE_IDENTITY_HEADER
@ SIP_RESPONSE_CODE_INTERNAL_ERROR
@ SIP_RESPONSE_CODE_ANONYMITY_DISALLOWED
@ SIP_RESPONSE_CODE_INVALID_IDENTITY_HEADER
@ SIP_RESPONSE_CODE_UNSUPPORTED_CREDENTIAL
@ SIP_RESPONSE_CODE_BAD_IDENTITY_INFO
@ SIP_RESPONSE_CODE_STALE_DATE
#define response_to_str(_code)
static enum process_failure_rc process_failure(struct ast_stir_shaken_vs_ctx *ctx, const char *caller_id, struct ast_sip_session *session, pjsip_rx_data *rdata, enum ast_stir_shaken_vs_response_code vs_rc)
static struct ast_sip_session_supplement stir_shaken_supplement
static const char * sip_response_code_to_str(enum sip_response_code code)
static int load_module(void)
static int unload_module(void)
static char * get_dest_tn(pjsip_tx_data *tdata, const char *tag)
static const pj_str_t date_hdr_str
#define translate_code(_vs_rc, _sip_rc)
static void add_fingerprints_if_present(struct ast_sip_session *session, struct ast_stir_shaken_as_ctx *ctx)
struct stir_shaken_attestation_ds * ast_stir_shaken_get_attestation_datastore(struct ast_channel *chan)
enum ast_stir_shaken_vs_response_code ast_stir_shaken_vs_ctx_add_date_hdr(struct ast_stir_shaken_vs_ctx *ctx, const char *date_hdr)
Add the received Date header value to the VS context.
int ast_stir_shaken_add_result_to_channel(struct ast_stir_shaken_vs_ctx *ctx)
Add a STIR/SHAKEN verification result to a channel.
const char * ast_stir_shaken_vs_get_caller_id(struct ast_stir_shaken_vs_ctx *ctx)
Get caller_id from context.
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.
ast_stir_shaken_as_response_code
@ AST_STIR_SHAKEN_AS_DISABLED
@ AST_STIR_SHAKEN_AS_SUCCESS
enum stir_shaken_failure_action_enum ast_stir_shaken_vs_get_failure_action(struct ast_stir_shaken_vs_ctx *ctx)
Get failure_action from context.
enum ast_stir_shaken_as_response_code ast_stir_shaken_as_ctx_create(const char *caller_id, 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.
enum ast_stir_shaken_vs_response_code ast_stir_shaken_vs_verify(struct ast_stir_shaken_vs_ctx *ctx)
Perform incoming call verification.
int ast_stir_shaken_vs_get_use_rfc9410_responses(struct ast_stir_shaken_vs_ctx *ctx)
Get use_rfc9410_responses from context.
enum ast_stir_shaken_vs_response_code ast_stir_shaken_vs_ctx_create(const char *caller_id, struct ast_channel *chan, const char *profile_name, const char *tag, struct ast_stir_shaken_vs_ctx **ctxout)
Create Verification Service context.
enum ast_stir_shaken_vs_response_code ast_stir_shaken_vs_ctx_add_identity_hdr(struct ast_stir_shaken_vs_ctx *ctx, const char *identity_hdr)
Add the received Identity header value to the VS context.
ast_stir_shaken_vs_response_code
@ AST_STIR_SHAKEN_VS_SUCCESS
@ AST_STIR_SHAKEN_VS_NO_IDENTITY_HDR
@ AST_STIR_SHAKEN_VS_DISABLED
@ AST_STIR_SHAKEN_VS_INVALID_OR_NO_CID
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.
int ast_stir_shaken_as_ctx_wants_fingerprints(struct ast_stir_shaken_as_ctx *ctx)
Indicates if the AS context needs DTLS fingerprints.
void ast_stir_shaken_vs_ctx_set_response_code(struct ast_stir_shaken_vs_ctx *ctx, enum ast_stir_shaken_vs_response_code vs_rc)
Sets response code on VS context.
stir_shaken_failure_action_enum
@ stir_shaken_failure_action_CONTINUE_RETURN_REASON
@ stir_shaken_failure_action_REJECT_REQUEST
Pluggable RTP Architecture.
ast_rtp_dtls_hash
DTLS fingerprint hashes.
@ AST_RTP_DTLS_HASH_SHA256
struct ast_rtp_engine_dtls * ast_rtp_instance_get_dtls(struct ast_rtp_instance *instance)
Obtain a pointer to the DTLS support present on an RTP instance.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Main Channel structure associated with a channel.
Information needed to identify an endpoint in a call.
struct ast_party_number number
Subscriber phone number.
char * str
Subscriber phone number (Malloced)
Structure that represents the optional DTLS SRTP support within an RTP engine.
A supplement to SIP message processing.
struct ast_module *const char * method
A structure describing a SIP session.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.