Module: kamailio
Branch: master
Commit: 04686c40d380e16e55c359cbc6bfc28f644a4c0b
URL: 
https://github.com/kamailio/kamailio/commit/04686c40d380e16e55c359cbc6bfc28f644a4c0b

Author: Henning Westerholt <h...@gilawa.com>
Committer: Henning Westerholt <h...@gilawa.com>
Date: 2025-06-18T11:09:38Z

rtpproxy: improve randomness of cookie by using PNRG and random sequence numbers

---

Modified: src/modules/rtpproxy/rtpproxy.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/04686c40d380e16e55c359cbc6bfc28f644a4c0b.diff
Patch: 
https://github.com/kamailio/kamailio/commit/04686c40d380e16e55c359cbc6bfc28f644a4c0b.patch

---

diff --git a/src/modules/rtpproxy/rtpproxy.c b/src/modules/rtpproxy/rtpproxy.c
index 2057cdfba5d..02641ce2ce3 100644
--- a/src/modules/rtpproxy/rtpproxy.c
+++ b/src/modules/rtpproxy/rtpproxy.c
@@ -76,6 +76,7 @@
 #include "../../core/dset.h"
 #include "../../core/route.h"
 #include "../../core/kemi.h"
+#include "../../core/rand/fastrand.h"
 #include "../../modules/tm/tm_load.h"
 #include "rtpproxy.h"
 #include "rtpproxy_funcs.h"
@@ -153,7 +154,6 @@ static int pv_get_rtppstat_f(struct sip_msg *, pv_param_t 
*, pv_value_t *);
 static int rtpproxy_disable_tout = 60;
 static int rtpproxy_retr = 5;
 static int rtpproxy_tout = 1;
-static pid_t mypid;
 static unsigned int myseqn = 0;
 static str nortpproxy_str = str_init("a=nortpproxy:yes");
 static str extra_id_pv_param = {NULL, 0};
@@ -788,9 +788,10 @@ static int child_init(int rank)
                return 0;
        }
 
-       /* Iterate known RTP proxies - create sockets */
-       mypid = getpid();
+       /* random start value for for cookie sequence number */
+       myseqn = fastrand();
 
+       /* Iterate known RTP proxies - create sockets */
        rtpp_socks = (int *)pkg_malloc(sizeof(int) * rtpp_no);
        if(rtpp_socks == NULL) {
                LM_ERR("no more pkg memory\n");
@@ -1206,7 +1207,7 @@ static char *gencookie(void)
 {
        static char cook[34];
 
-       sprintf(cook, "%d_%u ", (int)mypid, myseqn);
+       sprintf(cook, "%u_%u ", fastrand(), myseqn);
        myseqn++;
        return cook;
 }

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to