[MERGED] osmo-sgsn[master]: Migrate from OpenSSL to osmo_get_rand_id()

2017-12-27 Thread Max
Max has submitted this change and it was merged.

Change subject: Migrate from OpenSSL to osmo_get_rand_id()
..


Migrate from OpenSSL to osmo_get_rand_id()

This avoids potential licensing incompatibility and makes integration of
Debian packaging patches easier.

The libosmocore version requirements are fine already but for jenkins
tests to pass we have to have Ic77866ce65acf524b768882c751a4f9c0635740b
merged into libosmocore master.

Related: OS#1694
Change-Id: I2b687b7f07ef05bbd861b8479cad5a958a3dde92
---
M configure.ac
M debian/control
M src/gprs/Makefile.am
M src/gprs/gb_proxy.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_llc.c
M src/gprs/gprs_sgsn.c
M tests/gbproxy/Makefile.am
M tests/gbproxy/gbproxy_test.c
M tests/sgsn/Makefile.am
M tests/sgsn/sgsn_test.c
M tests/sndcp_xid/Makefile.am
M tests/xid/Makefile.am
13 files changed, 57 insertions(+), 66 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/configure.ac b/configure.ac
index 2de31cc..e886fa5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,6 @@
 PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.2.0)
 PKG_CHECK_MODULES(LIBOSMOGB, libosmogb >= 0.6.4)
 PKG_CHECK_MODULES(LIBOSMONETIF, libosmo-netif >= 0.0.1)
-PKG_CHECK_MODULES(LIBCRYPTO, libcrypto >= 0.9.5)
 
 # Enable/disable 3G aka IuPS + IuCS support?
 AC_ARG_ENABLE([iu], [AS_HELP_STRING([--enable-iu], [Build 3G support, aka IuPS 
and IuCS interfaces])],
diff --git a/debian/control b/debian/control
index ce2167a..330945f 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,6 @@
automake,
libtool,
pkg-config,
-   libssl-dev,
libtalloc-dev,
libc-ares-dev,
libgtp-dev,
diff --git a/src/gprs/Makefile.am b/src/gprs/Makefile.am
index 764acba..b0fca6f 100644
--- a/src/gprs/Makefile.am
+++ b/src/gprs/Makefile.am
@@ -15,7 +15,6 @@
$(LIBOSMOGB_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBCARES_CFLAGS) \
-   $(LIBCRYPTO_CFLAGS) \
$(LIBGTP_CFLAGS) \
$(NULL)
 if BUILD_IU
@@ -61,7 +60,6 @@
$(NULL)
 osmo_gbproxy_LDADD = \
$(OSMO_LIBS) \
-   $(LIBCRYPTO_LIBS) \
-lrt \
$(NULL)
 
@@ -97,7 +95,6 @@
$(OSMO_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(LIBCARES_LIBS) \
-   $(LIBCRYPTO_LIBS) \
$(LIBGTP_LIBS) \
-lrt \
-lm \
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 6a9bc22..63c3a61 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -50,8 +50,6 @@
 #include 
 #include 
 
-#include 
-
 extern void *tall_bsc_ctx;
 
 static const struct rate_ctr_desc global_ctr_description[] = {
@@ -232,12 +230,13 @@
uint32_t sgsn_ptmsi)
 {
uint32_t bss_ptmsi;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
bss_ptmsi = sgsn_ptmsi;
} else {
do {
-   if (RAND_bytes((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi));
+   if (rc < 0) {
bss_ptmsi = GSM_RESERVED_TMSI;
break;
}
@@ -250,7 +249,7 @@
}
 
if (bss_ptmsi == GSM_RESERVED_TMSI)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI: %d 
(%s)\n", rc, strerror(-rc));
 
return bss_ptmsi;
 }
@@ -260,7 +259,7 @@
uint32_t bss_tlli)
 {
uint32_t sgsn_tlli;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
sgsn_tlli = bss_tlli;
} else if (link_info->sgsn_tlli.ptmsi != GSM_RESERVED_TMSI &&
@@ -274,7 +273,8 @@
} else {
do {
/* create random TLLI, 0b0xxx... */
-   if (RAND_bytes((uint8_t *) _tlli, 
sizeof(sgsn_tlli)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _tlli, 
sizeof(sgsn_tlli));
+   if (rc < 0) {
sgsn_tlli = 0;
break;
}
@@ -287,7 +287,7 @@
}
 
if (!sgsn_tlli)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI: %d 
(%s)\n", rc, strerror(-rc));
 
return sgsn_tlli;
 }
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index f07b806..ead958e 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -31,8 +31,6 @@
 #include 
 #include 
 
-#include 
-
 #include "bscconfig.h"
 
 #include 
@@ -587,6 +585,7 @@
 

osmo-sgsn[master]: Migrate from OpenSSL to osmo_get_rand_id()

2017-12-26 Thread Harald Welte

Patch Set 9: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/3821
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I2b687b7f07ef05bbd861b8479cad5a958a3dde92
Gerrit-PatchSet: 9
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] osmo-sgsn[master]: Migrate from OpenSSL to osmo_get_rand_id()

2017-11-01 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3821

to look at the new patch set (#8).

Migrate from OpenSSL to osmo_get_rand_id()

This avoids potential licensing incompatibility and makes integration of
Debian packaging patches easier.

The libosmocore version requirements are fine already but for jenkins
tests to pass we have to have Ic77866ce65acf524b768882c751a4f9c0635740b
merged into libosmocore master.

Related: OS#1694
Change-Id: I2b687b7f07ef05bbd861b8479cad5a958a3dde92
---
M configure.ac
M debian/control
M src/gprs/Makefile.am
M src/gprs/gb_proxy.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_llc.c
M src/gprs/gprs_sgsn.c
M tests/gbproxy/Makefile.am
M tests/gbproxy/gbproxy_test.c
M tests/sgsn/Makefile.am
M tests/sgsn/sgsn_test.c
M tests/sndcp_xid/Makefile.am
M tests/xid/Makefile.am
13 files changed, 57 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/21/3821/8

diff --git a/configure.ac b/configure.ac
index 0daa5e2..7919d99 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,6 @@
 PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.2.0)
 PKG_CHECK_MODULES(LIBOSMOGB, libosmogb >= 0.6.4)
 PKG_CHECK_MODULES(LIBOSMONETIF, libosmo-netif >= 0.0.1)
-PKG_CHECK_MODULES(LIBCRYPTO, libcrypto >= 0.9.5)
 
 # Enable/disable 3G aka IuPS + IuCS support?
 AC_ARG_ENABLE([iu], [AS_HELP_STRING([--enable-iu], [Build 3G support, aka IuPS 
and IuCS interfaces])],
diff --git a/debian/control b/debian/control
index ce2167a..330945f 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,6 @@
automake,
libtool,
pkg-config,
-   libssl-dev,
libtalloc-dev,
libc-ares-dev,
libgtp-dev,
diff --git a/src/gprs/Makefile.am b/src/gprs/Makefile.am
index 764acba..b0fca6f 100644
--- a/src/gprs/Makefile.am
+++ b/src/gprs/Makefile.am
@@ -15,7 +15,6 @@
$(LIBOSMOGB_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBCARES_CFLAGS) \
-   $(LIBCRYPTO_CFLAGS) \
$(LIBGTP_CFLAGS) \
$(NULL)
 if BUILD_IU
@@ -61,7 +60,6 @@
$(NULL)
 osmo_gbproxy_LDADD = \
$(OSMO_LIBS) \
-   $(LIBCRYPTO_LIBS) \
-lrt \
$(NULL)
 
@@ -97,7 +95,6 @@
$(OSMO_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(LIBCARES_LIBS) \
-   $(LIBCRYPTO_LIBS) \
$(LIBGTP_LIBS) \
-lrt \
-lm \
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 17a0109..09e291b 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -50,8 +50,6 @@
 #include 
 #include 
 
-#include 
-
 extern void *tall_bsc_ctx;
 
 static const struct rate_ctr_desc global_ctr_description[] = {
@@ -232,12 +230,13 @@
uint32_t sgsn_ptmsi)
 {
uint32_t bss_ptmsi;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
bss_ptmsi = sgsn_ptmsi;
} else {
do {
-   if (RAND_bytes((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi));
+   if (rc < 0) {
bss_ptmsi = GSM_RESERVED_TMSI;
break;
}
@@ -250,7 +249,7 @@
}
 
if (bss_ptmsi == GSM_RESERVED_TMSI)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI: %d 
(%s)\n", rc, strerror(-rc));
 
return bss_ptmsi;
 }
@@ -260,7 +259,7 @@
uint32_t bss_tlli)
 {
uint32_t sgsn_tlli;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
sgsn_tlli = bss_tlli;
} else if (link_info->sgsn_tlli.ptmsi != GSM_RESERVED_TMSI &&
@@ -274,7 +273,8 @@
} else {
do {
/* create random TLLI, 0b0xxx... */
-   if (RAND_bytes((uint8_t *) _tlli, 
sizeof(sgsn_tlli)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _tlli, 
sizeof(sgsn_tlli));
+   if (rc < 0) {
sgsn_tlli = 0;
break;
}
@@ -287,7 +287,7 @@
}
 
if (!sgsn_tlli)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI: %d 
(%s)\n", rc, strerror(-rc));
 
return sgsn_tlli;
 }
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 147e001..ee0a575 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -31,8 +31,6 @@
 #include 
 #include 
 
-#include 
-
 #include "bscconfig.h"
 
 #include 
@@ -587,6 +585,7 @@
struct gsm48_hdr *gh;
struct 

[PATCH] osmo-sgsn[master]: Migrate from OpenSSL to osmo_get_rand_id()

2017-11-01 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3821

to look at the new patch set (#7).

Migrate from OpenSSL to osmo_get_rand_id()

This avoids potential licensing incompatibility and makes integration of
Debian packaging patches easier.

Related: OS#1694

Change-Id: I2b687b7f07ef05bbd861b8479cad5a958a3dde92
---
M configure.ac
M debian/control
M src/gprs/Makefile.am
M src/gprs/gb_proxy.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_llc.c
M src/gprs/gprs_sgsn.c
M tests/gbproxy/Makefile.am
M tests/gbproxy/gbproxy_test.c
M tests/sgsn/Makefile.am
M tests/sgsn/sgsn_test.c
M tests/sndcp_xid/Makefile.am
M tests/xid/Makefile.am
13 files changed, 57 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/21/3821/7

diff --git a/configure.ac b/configure.ac
index 0daa5e2..7919d99 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,6 @@
 PKG_CHECK_MODULES(LIBOSMOABIS, libosmoabis >= 0.2.0)
 PKG_CHECK_MODULES(LIBOSMOGB, libosmogb >= 0.6.4)
 PKG_CHECK_MODULES(LIBOSMONETIF, libosmo-netif >= 0.0.1)
-PKG_CHECK_MODULES(LIBCRYPTO, libcrypto >= 0.9.5)
 
 # Enable/disable 3G aka IuPS + IuCS support?
 AC_ARG_ENABLE([iu], [AS_HELP_STRING([--enable-iu], [Build 3G support, aka IuPS 
and IuCS interfaces])],
diff --git a/debian/control b/debian/control
index ce2167a..330945f 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,6 @@
automake,
libtool,
pkg-config,
-   libssl-dev,
libtalloc-dev,
libc-ares-dev,
libgtp-dev,
diff --git a/src/gprs/Makefile.am b/src/gprs/Makefile.am
index 764acba..b0fca6f 100644
--- a/src/gprs/Makefile.am
+++ b/src/gprs/Makefile.am
@@ -15,7 +15,6 @@
$(LIBOSMOGB_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBCARES_CFLAGS) \
-   $(LIBCRYPTO_CFLAGS) \
$(LIBGTP_CFLAGS) \
$(NULL)
 if BUILD_IU
@@ -61,7 +60,6 @@
$(NULL)
 osmo_gbproxy_LDADD = \
$(OSMO_LIBS) \
-   $(LIBCRYPTO_LIBS) \
-lrt \
$(NULL)
 
@@ -97,7 +95,6 @@
$(OSMO_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(LIBCARES_LIBS) \
-   $(LIBCRYPTO_LIBS) \
$(LIBGTP_LIBS) \
-lrt \
-lm \
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 17a0109..09e291b 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -50,8 +50,6 @@
 #include 
 #include 
 
-#include 
-
 extern void *tall_bsc_ctx;
 
 static const struct rate_ctr_desc global_ctr_description[] = {
@@ -232,12 +230,13 @@
uint32_t sgsn_ptmsi)
 {
uint32_t bss_ptmsi;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
bss_ptmsi = sgsn_ptmsi;
} else {
do {
-   if (RAND_bytes((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi));
+   if (rc < 0) {
bss_ptmsi = GSM_RESERVED_TMSI;
break;
}
@@ -250,7 +249,7 @@
}
 
if (bss_ptmsi == GSM_RESERVED_TMSI)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI: %d 
(%s)\n", rc, strerror(-rc));
 
return bss_ptmsi;
 }
@@ -260,7 +259,7 @@
uint32_t bss_tlli)
 {
uint32_t sgsn_tlli;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
sgsn_tlli = bss_tlli;
} else if (link_info->sgsn_tlli.ptmsi != GSM_RESERVED_TMSI &&
@@ -274,7 +273,8 @@
} else {
do {
/* create random TLLI, 0b0xxx... */
-   if (RAND_bytes((uint8_t *) _tlli, 
sizeof(sgsn_tlli)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _tlli, 
sizeof(sgsn_tlli));
+   if (rc < 0) {
sgsn_tlli = 0;
break;
}
@@ -287,7 +287,7 @@
}
 
if (!sgsn_tlli)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI: %d 
(%s)\n", rc, strerror(-rc));
 
return sgsn_tlli;
 }
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 147e001..ee0a575 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -31,8 +31,6 @@
 #include 
 #include 
 
-#include 
-
 #include "bscconfig.h"
 
 #include 
@@ -587,6 +585,7 @@
struct gsm48_hdr *gh;
struct gsm48_auth_ciph_req *acreq;
uint8_t *m_rand, *m_cksn, rbyte;
+   int rc;
 
LOGMMCTXP(LOGL_INFO, mm, "<- GPRS AUTH AND CIPHERING REQ (rand = %s",
   

[PATCH] osmo-sgsn[master]: Migrate from OpenSSL to osmo_get_rand_id()

2017-10-09 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3821

to look at the new patch set (#5).

Migrate from OpenSSL to osmo_get_rand_id()

This avoids potential licensing incompatibility and makes integration of
Debian packaging patches easier.

Related: OS#1694

Change-Id: I2b687b7f07ef05bbd861b8479cad5a958a3dde92
---
M configure.ac
M debian/control
M src/gprs/Makefile.am
M src/gprs/gb_proxy.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_llc.c
M src/gprs/gprs_sgsn.c
M tests/gbproxy/Makefile.am
M tests/gbproxy/gbproxy_test.c
M tests/sgsn/Makefile.am
M tests/sgsn/sgsn_test.c
M tests/sndcp_xid/Makefile.am
M tests/xid/Makefile.am
13 files changed, 57 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/21/3821/5

diff --git a/configure.ac b/configure.ac
index c8e23e5..7921085 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,6 @@
 PKG_CHECK_MODULES(LIBOSMOGB, libosmogb >= 0.6.4)
 PKG_CHECK_MODULES(LIBOSMONETIF, libosmo-netif >= 0.0.1)
 PKG_CHECK_MODULES(LIBOSMOSIGTRAN, libosmo-sigtran) # TODO version?
-PKG_CHECK_MODULES(LIBCRYPTO, libcrypto >= 0.9.5)
 
 # Enable/disable 3G aka IuPS + IuCS support?
 AC_ARG_ENABLE([iu], [AS_HELP_STRING([--enable-iu], [Build 3G support, aka IuPS 
and IuCS interfaces])],
diff --git a/debian/control b/debian/control
index ce2167a..330945f 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,6 @@
automake,
libtool,
pkg-config,
-   libssl-dev,
libtalloc-dev,
libc-ares-dev,
libgtp-dev,
diff --git a/src/gprs/Makefile.am b/src/gprs/Makefile.am
index 654604b..0a88c01 100644
--- a/src/gprs/Makefile.am
+++ b/src/gprs/Makefile.am
@@ -15,7 +15,6 @@
$(LIBOSMOGB_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBCARES_CFLAGS) \
-   $(LIBCRYPTO_CFLAGS) \
$(LIBGTP_CFLAGS) \
$(NULL)
 if BUILD_IU
@@ -63,7 +62,6 @@
$(NULL)
 osmo_gbproxy_LDADD = \
$(OSMO_LIBS) \
-   $(LIBCRYPTO_LIBS) \
-lrt \
$(NULL)
 
@@ -99,7 +97,6 @@
$(OSMO_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(LIBCARES_LIBS) \
-   $(LIBCRYPTO_LIBS) \
$(LIBGTP_LIBS) \
-lrt \
-lm \
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 17a0109..09e291b 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -50,8 +50,6 @@
 #include 
 #include 
 
-#include 
-
 extern void *tall_bsc_ctx;
 
 static const struct rate_ctr_desc global_ctr_description[] = {
@@ -232,12 +230,13 @@
uint32_t sgsn_ptmsi)
 {
uint32_t bss_ptmsi;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
bss_ptmsi = sgsn_ptmsi;
} else {
do {
-   if (RAND_bytes((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi));
+   if (rc < 0) {
bss_ptmsi = GSM_RESERVED_TMSI;
break;
}
@@ -250,7 +249,7 @@
}
 
if (bss_ptmsi == GSM_RESERVED_TMSI)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI: %d 
(%s)\n", rc, strerror(-rc));
 
return bss_ptmsi;
 }
@@ -260,7 +259,7 @@
uint32_t bss_tlli)
 {
uint32_t sgsn_tlli;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
sgsn_tlli = bss_tlli;
} else if (link_info->sgsn_tlli.ptmsi != GSM_RESERVED_TMSI &&
@@ -274,7 +273,8 @@
} else {
do {
/* create random TLLI, 0b0xxx... */
-   if (RAND_bytes((uint8_t *) _tlli, 
sizeof(sgsn_tlli)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _tlli, 
sizeof(sgsn_tlli));
+   if (rc < 0) {
sgsn_tlli = 0;
break;
}
@@ -287,7 +287,7 @@
}
 
if (!sgsn_tlli)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI: %d 
(%s)\n", rc, strerror(-rc));
 
return sgsn_tlli;
 }
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 7e109b4..0ebe65a 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -31,8 +31,6 @@
 #include 
 #include 
 
-#include 
-
 #include "bscconfig.h"
 
 #include 
@@ -585,6 +583,7 @@
struct gsm48_hdr *gh;
struct gsm48_auth_ciph_req *acreq;
uint8_t *m_rand, *m_cksn, rbyte;
+   int rc;
 
LOGMMCTXP(LOGL_INFO, mm, "<- GPRS AUTH AND CIPHERING REQ (rand = 

[PATCH] osmo-sgsn[master]: Migrate from OpenSSL to osmo_get_rand_id()

2017-10-09 Thread Max
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/3821

to look at the new patch set (#4).

Migrate from OpenSSL to osmo_get_rand_id()

This avoids potential licensing incompatibility and makes integration of
Debian packaging patches easier.

Related: OS#1694

Change-Id: I2b687b7f07ef05bbd861b8479cad5a958a3dde92
---
M configure.ac
M debian/control
M src/gprs/Makefile.am
M src/gprs/gb_proxy.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_llc.c
M src/gprs/gprs_sgsn.c
M tests/gbproxy/Makefile.am
M tests/gbproxy/gbproxy_test.c
M tests/sgsn/Makefile.am
M tests/sgsn/sgsn_test.c
M tests/sndcp_xid/Makefile.am
M tests/xid/Makefile.am
13 files changed, 58 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/21/3821/4

diff --git a/configure.ac b/configure.ac
index c8e23e5..7921085 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,6 @@
 PKG_CHECK_MODULES(LIBOSMOGB, libosmogb >= 0.6.4)
 PKG_CHECK_MODULES(LIBOSMONETIF, libosmo-netif >= 0.0.1)
 PKG_CHECK_MODULES(LIBOSMOSIGTRAN, libosmo-sigtran) # TODO version?
-PKG_CHECK_MODULES(LIBCRYPTO, libcrypto >= 0.9.5)
 
 # Enable/disable 3G aka IuPS + IuCS support?
 AC_ARG_ENABLE([iu], [AS_HELP_STRING([--enable-iu], [Build 3G support, aka IuPS 
and IuCS interfaces])],
diff --git a/debian/control b/debian/control
index ce2167a..330945f 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,6 @@
automake,
libtool,
pkg-config,
-   libssl-dev,
libtalloc-dev,
libc-ares-dev,
libgtp-dev,
diff --git a/src/gprs/Makefile.am b/src/gprs/Makefile.am
index 654604b..0a88c01 100644
--- a/src/gprs/Makefile.am
+++ b/src/gprs/Makefile.am
@@ -15,7 +15,6 @@
$(LIBOSMOGB_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBCARES_CFLAGS) \
-   $(LIBCRYPTO_CFLAGS) \
$(LIBGTP_CFLAGS) \
$(NULL)
 if BUILD_IU
@@ -63,7 +62,6 @@
$(NULL)
 osmo_gbproxy_LDADD = \
$(OSMO_LIBS) \
-   $(LIBCRYPTO_LIBS) \
-lrt \
$(NULL)
 
@@ -99,7 +97,6 @@
$(OSMO_LIBS) \
$(LIBOSMOABIS_LIBS) \
$(LIBCARES_LIBS) \
-   $(LIBCRYPTO_LIBS) \
$(LIBGTP_LIBS) \
-lrt \
-lm \
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 17a0109..09e291b 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -50,8 +50,6 @@
 #include 
 #include 
 
-#include 
-
 extern void *tall_bsc_ctx;
 
 static const struct rate_ctr_desc global_ctr_description[] = {
@@ -232,12 +230,13 @@
uint32_t sgsn_ptmsi)
 {
uint32_t bss_ptmsi;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
bss_ptmsi = sgsn_ptmsi;
} else {
do {
-   if (RAND_bytes((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _ptmsi, 
sizeof(bss_ptmsi));
+   if (rc < 0) {
bss_ptmsi = GSM_RESERVED_TMSI;
break;
}
@@ -250,7 +249,7 @@
}
 
if (bss_ptmsi == GSM_RESERVED_TMSI)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a BSS P-TMSI: %d 
(%s)\n", rc, strerror(-rc));
 
return bss_ptmsi;
 }
@@ -260,7 +259,7 @@
uint32_t bss_tlli)
 {
uint32_t sgsn_tlli;
-   int max_retries = 23;
+   int max_retries = 23, rc = 0;
if (!peer->cfg->patch_ptmsi) {
sgsn_tlli = bss_tlli;
} else if (link_info->sgsn_tlli.ptmsi != GSM_RESERVED_TMSI &&
@@ -274,7 +273,8 @@
} else {
do {
/* create random TLLI, 0b0xxx... */
-   if (RAND_bytes((uint8_t *) _tlli, 
sizeof(sgsn_tlli)) != 1) {
+   rc = osmo_get_rand_id((uint8_t *) _tlli, 
sizeof(sgsn_tlli));
+   if (rc < 0) {
sgsn_tlli = 0;
break;
}
@@ -287,7 +287,7 @@
}
 
if (!sgsn_tlli)
-   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI\n");
+   LOGP(DGPRS, LOGL_ERROR, "Failed to allocate an SGSN TLLI: %d 
(%s)\n", rc, strerror(-rc));
 
return sgsn_tlli;
 }
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index 7e109b4..0ebe65a 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -31,8 +31,6 @@
 #include 
 #include 
 
-#include 
-
 #include "bscconfig.h"
 
 #include 
@@ -585,6 +583,7 @@
struct gsm48_hdr *gh;
struct gsm48_auth_ciph_req *acreq;
uint8_t *m_rand, *m_cksn, rbyte;
+   int rc;
 
LOGMMCTXP(LOGL_INFO, mm, "<- GPRS AUTH AND CIPHERING REQ (rand =