Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

res_pjsip_stir_shaken: Use correct Caller ID to lookup certificate. #62

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/asterisk/res_pjsip_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -963,4 +963,15 @@ struct ast_sip_session_media *ast_sip_session_media_get_transport(struct ast_sip
*/
const char *ast_sip_session_get_name(const struct ast_sip_session *session);

/*!
* \brief Determines if the Connected Line info can be presented for this session
*
* \param session The session
* \param id The Connected Line info to evaluate
*
* \retval 1 The Connected Line info can be presented
* \retval 0 The Connected Line info cannot be presented
*/
int ast_sip_can_present_connected_id(const struct ast_sip_session *session, const struct ast_party_id *id);

#endif /* _RES_PJSIP_SESSION_H */
4 changes: 1 addition & 3 deletions res/res_pjsip_caller_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,7 @@ static void add_rpid_header(const struct ast_sip_session *session, pjsip_tx_data
*/
static void add_id_headers(const struct ast_sip_session *session, pjsip_tx_data *tdata, const struct ast_party_id *id)
{
if (!id->number.valid
|| (!session->endpoint->id.trust_outbound
&& (ast_party_id_presentation(id) & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED)) {
if (!ast_sip_can_present_connected_id(session, id)) {
return;
}
if (session->endpoint->id.send_pai) {
Expand Down
7 changes: 7 additions & 0 deletions res/res_pjsip_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ const char *ast_sip_session_get_name(const struct ast_sip_session *session)
}
}

int ast_sip_can_present_connected_id(const struct ast_sip_session *session, const struct ast_party_id *id)
{
return id->number.valid
&& (session->endpoint->id.trust_outbound
|| (ast_party_id_presentation(id) & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED);
}

static int sdp_handler_list_cmp(void *obj, void *arg, int flags)
{
struct sdp_handler_list *handler_list1 = obj;
Expand Down
27 changes: 18 additions & 9 deletions res/res_pjsip_stir_shaken.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "asterisk.h"

#include "asterisk/callerid.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/module.h"
Expand Down Expand Up @@ -355,7 +356,7 @@ static int stir_shaken_incoming_request(struct ast_sip_session *session, pjsip_r
return 0;
}

static int add_identity_header(const struct ast_sip_session *session, pjsip_tx_data *tdata)
static int add_identity_header(pjsip_tx_data *tdata, const struct ast_party_id *party_id)
{
static const pj_str_t identity_str = { "Identity", 8 };
pjsip_generic_string_hdr *identity_hdr;
Expand Down Expand Up @@ -420,7 +421,7 @@ static int add_identity_header(const struct ast_sip_session *session, pjsip_tx_d
json = ast_json_pack("{s: {s: s, s: s, s: s}, s: {s: {s: [s]}, s: {s: s}}}",
"header", "alg", "ES256", "ppt", "shaken", "typ", "passport",
"payload", "dest", "tn", dest_tn, "orig", "tn",
session->id.number.str);
party_id->number.str);
if (!json) {
ast_log(LOG_ERROR, "Failed to allocate memory for STIR/SHAKEN JSON\n");
return -1;
Expand Down Expand Up @@ -498,6 +499,8 @@ static void add_date_header(const struct ast_sip_session *session, pjsip_tx_data
static void stir_shaken_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
RAII_VAR(struct stir_shaken_profile *, profile, NULL, ao2_cleanup);
struct ast_party_id effective_id;
struct ast_party_id connected_id;

profile = ast_stir_shaken_get_profile(session->endpoint->stir_shaken_profile);
/* Profile should be checked first as it takes priority over anything else.
Expand All @@ -510,17 +513,23 @@ static void stir_shaken_outgoing_request(struct ast_sip_session *session, pjsip_
return;
}

if (ast_strlen_zero(session->id.number.str) && session->id.number.valid) {
ast_party_id_init(&connected_id);
ast_channel_lock(session->channel);
effective_id = ast_channel_connected_effective_id(session->channel);
ast_party_id_copy(&connected_id, &effective_id);
ast_channel_unlock(session->channel);

if (!ast_sip_can_present_connected_id(session, &connected_id)) {
ast_party_id_free(&connected_id);
return;
}

/* If adding the Identity header fails for some reason, there's no point
* adding the Date header.
*/
if ((add_identity_header(session, tdata)) != 0) {
return;
if (add_identity_header(tdata, &connected_id) == 0) {
/* Only add the Date header if we succeeded in adding the Identity header */
add_date_header(session, tdata);
}
add_date_header(session, tdata);

ast_party_id_free(&connected_id);
}

static struct ast_sip_session_supplement stir_shaken_supplement = {
Expand Down