]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
AST-2020-002 - res_pjsip: Stop sending INVITEs after challenge limit.
authorBen Ford <bford@digium.com>
Mon, 2 Nov 2020 16:29:31 +0000 (10:29 -0600)
committerKevin Harwell <kharwell@digium.com>
Thu, 5 Nov 2020 21:23:50 +0000 (15:23 -0600)
If Asterisk sends out an INVITE and receives a challenge with a
different nonce value each time, it will continuously send out INVITEs,
even if the call is hung up. The endpoint must be configured for
outbound authentication for this to occur. A limit has been set on
outbound INVITEs so that, once reached, Asterisk will stop sending
INVITEs and the transaction will terminate.

ASTERISK-29013

Change-Id: I2d001ca745b00ca8aa12030f2240cd72363b46f7

include/asterisk/res_pjsip.h
include/asterisk/res_pjsip_session.h
res/res_pjsip.c
res/res_pjsip_session.c

index 7076dc738209a8c01b1ba99bf69d3190647a06a2..36c11a1dc61f3006fac1b65567e5250d5aa7eaf8 100644 (file)
@@ -78,6 +78,9 @@ struct pjsip_tpselector;
 
 AST_VECTOR(ast_sip_service_route_vector, char *);
 
+/*! Maximum number of challenges before assuming that we are in a loop */
+#define MAX_RX_CHALLENGES      10
+
 /*!
  * \brief Structure for SIP transport information
  */
index 9db68a89221d5ea35762257d618573ddc1811ac3..b4bfa81ead16db825e34596267038c6c975616f7 100644 (file)
@@ -233,6 +233,8 @@ struct ast_sip_session {
        AST_VECTOR(, struct ast_rtp_instance_stats *) media_stats;
        /*! The direction of the call respective to Asterisk */
        enum ast_sip_session_call_direction call_direction;
+       /*! Number of challenges received during outgoing requests to determine if we are in a loop */
+       unsigned int authentication_challenge_count:4;
 };
 
 typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
index a9d10090ac2043a5680e2b5698adc63004f93e55..c30f2aa6a0d0d1d18a13bfe393bb6ded927e657f 100644 (file)
@@ -4445,8 +4445,6 @@ static pj_bool_t does_method_match(const pj_str_t *message_method, const char *s
        return pj_stristr(&method, message_method) ? PJ_TRUE : PJ_FALSE;
 }
 
-/*! Maximum number of challenges before assuming that we are in a loop */
-#define MAX_RX_CHALLENGES      10
 #define TIMER_INACTIVE         0
 #define TIMEOUT_TIMER2         5
 
index 5f94cea654f819e7cc80fddb0495dee9b9056f3e..0c27df977d38cc94dd5a558ba537bf2c857f6074 100644 (file)
@@ -2246,7 +2246,6 @@ static pjsip_module session_reinvite_module = {
        .on_rx_request = session_reinvite_on_rx_request,
 };
 
-
 void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
                ast_sip_session_response_cb on_response)
 {
@@ -2499,6 +2498,9 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
                return NULL;
        }
 
+       /* Track the number of challenges received on outbound requests */
+       session->authentication_challenge_count = 0;
+
        /* Fire seesion begin handlers */
        handle_session_begin(session);
 
@@ -2668,6 +2670,11 @@ static pj_bool_t outbound_invite_auth(pjsip_rx_data *rdata)
 
        session = inv->mod_data[session_module.id];
 
+       if (++session->authentication_challenge_count > MAX_RX_CHALLENGES) {
+               ast_debug(3, "%s: Initial INVITE reached maximum number of auth attempts.\n", ast_sip_session_get_name(session));
+               return PJ_FALSE;
+       }
+
        if (ast_sip_create_request_with_auth(&session->endpoint->outbound_auths, rdata,
                tsx->last_tx, &tdata)) {
                return PJ_FALSE;
@@ -4181,6 +4188,7 @@ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_trans
                                                ast_debug(1, "reINVITE received final response code %d\n",
                                                        tsx->status_code);
                                                if ((tsx->status_code == 401 || tsx->status_code == 407)
+                                                       && ++session->authentication_challenge_count < MAX_RX_CHALLENGES
                                                        && !ast_sip_create_request_with_auth(
                                                                &session->endpoint->outbound_auths,
                                                                e->body.tsx_state.src.rdata, tsx->last_tx, &tdata)) {
@@ -4275,6 +4283,7 @@ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_trans
                                                (int) pj_strlen(&tsx->method.name), pj_strbuf(&tsx->method.name),
                                                tsx->status_code);
                                        if ((tsx->status_code == 401 || tsx->status_code == 407)
+                                               && ++session->authentication_challenge_count < MAX_RX_CHALLENGES
                                                && !ast_sip_create_request_with_auth(
                                                        &session->endpoint->outbound_auths,
                                                        e->body.tsx_state.src.rdata, tsx->last_tx, &tdata)) {