29#define _TRACE_PREFIX_ "pjss",__LINE__, ""
54#define SIP_RESPONSE_CODE_OK_STR "OK"
56#define SIP_RESPONSE_CODE_STALE_DATE_STR "Stale Date"
57#define SIP_RESPONSE_CODE_USE_IDENTITY_HEADER_STR "Use Identity Header"
58#define SIP_RESPONSE_CODE_USE_SUPPORTED_PASSPORT_FORMAT_STR "Use Supported PASSporT Format"
59#define SIP_RESPONSE_CODE_BAD_IDENTITY_INFO_STR "Bad Identity Info"
60#define SIP_RESPONSE_CODE_UNSUPPORTED_CREDENTIAL_STR "Unsupported Credential"
61#define SIP_RESPONSE_CODE_INVALID_IDENTITY_HEADER_STR "Invalid Identity Header"
62#define SIP_RESPONSE_CODE_INTERNAL_ERROR_STR "Internal Error"
64#define response_to_str(_code) \
83#define translate_code(_vs_rc, _sip_rc) \
84case AST_STIR_SHAKEN_VS_ ## _vs_rc: \
85 return SIP_RESPONSE_CODE_ ## _sip_rc;
114 translate_code(CERT_NO_SPC_IN_TN_AUTH_EXT, UNSUPPORTED_CREDENTIAL)
154 pj_str_t response_str;
155 const char *response_string =
161 failure_action, response_code);
163 pj_cstr(&response_str, response_string);
168 "%s: Rejecting request and terminating session\n",
178 response_code, response_str.ptr);
181 "%s: Failed to add Reason header\n", tag);
184 "%s: Attaching reason code to session\n", tag);
187 "%s: Continuing\n", tag);
205 char *identity_hdr_val;
207 char *caller_id =
session->id.number.str;
225 if (rdata->msg_info.to->tag.slen) {
239 session->endpoint->stir_shaken_profile,
314 SCOPE_ENTER(4,
"%s: Check %zu media sessions for fingerprints\n",
321 for (i = 0; i < count; i++) {
326 ast_trace(1,
"Session: %d: No session or rtp instance\n", i);
330 h =
d->get_fingerprint_hash(m->
rtp);
331 f =
d->get_fingerprint(m->
rtp);
341 pjsip_fromto_hdr *to;
343 char *dest_tn =
NULL;
346 to = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_TO,
NULL);
351 uri = pjsip_uri_get_uri(to->uri);
354 "%s: Failed to retrieve URI from To header\n", tag);
360 "%s: Failed to allocate memory for dest_tn\n", tag);
370 pjsip_fromto_hdr *old_date;
376 SCOPE_EXIT_RTN(
"Found existing Date header, no need to add one\n");
384 pjsip_tx_data *tdata)
388 pjsip_generic_string_hdr *old_identity;
389 pjsip_generic_string_hdr *identity_hdr;
390 pj_str_t identity_val;
433 session->endpoint->stir_shaken_profile,
453 "%s: Failed to create attestation\n", session_name);
456 ast_trace(1,
"%s: Identity header: %s\n", session_name, identity_str);
457 identity_val = pj_str(identity_str);
458 identity_hdr = pjsip_generic_string_hdr_create(tdata->pool, &
identity_hdr_str, &identity_val);
463 "%s: Unable to create Identity header\n", session_name);
466 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)identity_hdr);
491#undef AST_BUILDOPT_SUM
492#define AST_BUILDOPT_SUM ""
499 .
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)
#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_INVALID_IDENTITY_HEADER
@ SIP_RESPONSE_CODE_UNSUPPORTED_CREDENTIAL
@ SIP_RESPONSE_CODE_BAD_IDENTITY_INFO
@ SIP_RESPONSE_CODE_USE_SUPPORTED_PASSPORT_FORMAT
@ 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)
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.
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_NO_DATE_HDR
@ AST_STIR_SHAKEN_VS_SUCCESS
@ AST_STIR_SHAKEN_VS_NO_IDENTITY_HDR
@ AST_STIR_SHAKEN_VS_DISABLED
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.
A structure describing a SIP session.
const ast_string_field dest_tn
#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.