[Asterisk-code-review] res pjsip authenticator digest: Don't use source port in non... (asterisk[certified/13.8])

Kevin Harwell asteriskteam at digium.com
Thu May 5 11:54:14 CDT 2016


Kevin Harwell has uploaded a new change for review.

  https://gerrit.asterisk.org/2772

Change subject: res_pjsip_authenticator_digest: Don't use source port in nonce verification
......................................................................

res_pjsip_authenticator_digest: Don't use source port in nonce verification

>From the issue reporter:
"res_pjsip_outbound_authenticator_digest builds a nonce that is a hash of
the timestamp, the source address, the source port, a server UUID that is
calculated at startup, and the authentication realm.

Rather than caching nonces that we create, we instead attempt to re-calculate
the nonce when receiving an incoming request with authentication. We then
compare the re-calculated nonce to the incoming nonce, and if they don't match,
then authentication has failed early.

The problem is that it is possible, especially when using TCP, to receive two
requests from the same endpoint but have differing source ports for those
requests. Asterisk itself commonly will use different source ports for
outbound TCP requests."

This patch removes the source port dependency when building the nonce and now
instead uses the callid.

ASTERISK-25978 #close

Change-Id: I871b5f4adce102df1c4988066283095ec509dffe
---
M res/res_pjsip_authenticator_digest.c
1 file changed, 8 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/72/2772/1

diff --git a/res/res_pjsip_authenticator_digest.c b/res/res_pjsip_authenticator_digest.c
index 8a78125..8c3be31 100644
--- a/res/res_pjsip_authenticator_digest.c
+++ b/res/res_pjsip_authenticator_digest.c
@@ -202,9 +202,16 @@
 	RAII_VAR(char *, eid, ao2_global_obj_ref(entity_id), ao2_cleanup);
 	char hash[33];
 
+	/*
+	 * Note you may be tempted to think why not include the port. The reason
+	 * is that when using TCP the port can potentially differ from before.
+	 */
+	ast_copy_pj_str(ast_str_buffer(str), &rdata->msg_info.cid->id,
+			pj_strlen(&rdata->msg_info.cid->id) + 1);
+	ast_str_update(str);
+
 	ast_str_append(&str, 0, "%s", timestamp);
 	ast_str_append(&str, 0, ":%s", rdata->pkt_info.src_name);
-	ast_str_append(&str, 0, ":%d", rdata->pkt_info.src_port);
 	ast_str_append(&str, 0, ":%s", eid);
 	ast_str_append(&str, 0, ":%s", realm);
 	ast_md5_hash(hash, ast_str_buffer(str));

-- 
To view, visit https://gerrit.asterisk.org/2772
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I871b5f4adce102df1c4988066283095ec509dffe
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.8
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-code-review mailing list