diff mbox

[2/4] gprs: Use RAND_bytes for p-tmsi

Message ID d863bc51e2f2a2853def6badf78ba4367b24065a.1444298449.git.daniel@totalueberwachung.de
State Accepted
Headers show

Commit Message

Daniel Willmann Oct. 8, 2015, 2:10 p.m. UTC
From: Daniel Willmann <dwillmann@sysmocom.de>

---
 openbsc/src/gprs/gprs_sgsn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Holger Freyther Oct. 12, 2015, 7:59 a.m. UTC | #1
> On 08 Oct 2015, at 16:10, Daniel Willmann <dwilllmann@sysmocom.de> wrote:
> 
> From: Daniel Willmann <dwillmann@sysmocom.de>


* missing include for the RAND_bytes prototype
* missing cat of ptmsi
* missing linking to LIBCRYPTO_LIBS
* missing linking to LIBCRYPTO_LIBS in the test


and after that.. the sgsn tests fail because of the TMSI situation. I have now
reverted the code. Please look at it with Jacob and extract the TMSI from the
SGSN state instead of resetting the RNG in the test.

holger
Daniel Willmann Oct. 12, 2015, 5:31 p.m. UTC | #2
On Mon, 2015-10-12 at 09:59 +0200, Holger Freyther wrote:
> > On 08 Oct 2015, at 16:10, Daniel Willmann <dwilllmann@sysmocom.de> wrote:
> > 
> > From: Daniel Willmann <dwillmann@sysmocom.de>
> 
> 
> * missing include for the RAND_bytes prototype
> * missing cat of ptmsi
> * missing linking to LIBCRYPTO_LIBS
> * missing linking to LIBCRYPTO_LIBS in the test

> and after that.. the sgsn tests fail because of the TMSI situation. I have now
> reverted the code. Please look at it with Jacob and extract the TMSI from the
> SGSN state instead of resetting the RNG in the test.

...sorry, it seems that it never even executed the test on my new system
due to missing libgtp.

I'll send another patchset which solves this issue (and does the same
for gbproxy).

Daniel
diff mbox

Patch

diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index f40de0b..2af1e97 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -525,7 +525,9 @@  uint32_t sgsn_alloc_ptmsi(void)
 	int max_retries = 100;
 
 restart:
-	ptmsi = rand();
+	if (RAND_bytes(&ptmsi, sizeof(ptmsi)) != 1)
+		goto failed;
+
 	/* Enforce that the 2 MSB are set without loosing the distance between
 	 * identical values. Since rand() has no duplicate values within a
 	 * period (because the size of the state is the same like the size of