summaryrefslogtreecommitdiff
path: root/res/res_pjsip_authenticator_digest.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2016-05-05 11:37:37 -0500
committerKevin Harwell <kharwell@digium.com>2016-05-09 14:17:43 -0500
commit1e876d691588a9196ad987b0f81192c12d3a0c81 (patch)
tree32350ad3b43f94fff8716928dc7d2c72d428a692 /res/res_pjsip_authenticator_digest.c
parent5b15ec966db9c686ca7fbc74be8d57b4c63253d7 (diff)
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. ASTERISK-25978 #close Change-Id: I871b5f4adce102df1c4988066283095ec509dffe
Diffstat (limited to 'res/res_pjsip_authenticator_digest.c')
-rw-r--r--res/res_pjsip_authenticator_digest.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/res/res_pjsip_authenticator_digest.c b/res/res_pjsip_authenticator_digest.c
index a512b45b1..4bc35c5ff 100644
--- a/res/res_pjsip_authenticator_digest.c
+++ b/res/res_pjsip_authenticator_digest.c
@@ -206,9 +206,12 @@ static int build_nonce(struct ast_str **nonce, const char *timestamp, const pjsi
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_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));