[PATCH] openbsc[master]: Generate random IOV-UI and send it via XID

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Tue Dec 20 16:21:52 UTC 2016


Review at  https://gerrit.osmocom.org/1462

Generate random IOV-UI and send it via XID

This ensures that encryption is using random IV value as per-spec
instead of hard-coded 0.

Fixes: OS#1794
Change-Id: Ia71d6ac668a629d0377dd5c685e1dcd166def1a4
---
M openbsc/include/openbsc/gprs_llc.h
M openbsc/src/gprs/gprs_llc.c
2 files changed, 25 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/62/1462/1

diff --git a/openbsc/include/openbsc/gprs_llc.h b/openbsc/include/openbsc/gprs_llc.h
index 8bc2267..ef3c66e 100644
--- a/openbsc/include/openbsc/gprs_llc.h
+++ b/openbsc/include/openbsc/gprs_llc.h
@@ -237,6 +237,7 @@
 int gprs_llgmm_reset(struct gprs_llc_llme *llme);
 int gprs_llgmm_reset_oldmsg(struct msgb* oldmsg, uint8_t sapi,
 			    struct gprs_llc_llme *llme);
+bool gprs_llgmm_gen_iov_ui(struct gprs_llc_llme *llme);
 
 /* Set of LL-XID negotiation (See also: TS 101 351, Section 7.2.2.4) */
 int gprs_ll_xid_req(struct gprs_llc_lle *lle,
diff --git a/openbsc/src/gprs/gprs_llc.c b/openbsc/src/gprs/gprs_llc.c
index c2c3900..8e8ad65 100644
--- a/openbsc/src/gprs/gprs_llc.c
+++ b/openbsc/src/gprs/gprs_llc.c
@@ -61,9 +61,15 @@
 
 	LLIST_HEAD(xid_fields);
 
+	struct gprs_llc_xid_field xid_iov_ui;
 	struct gprs_llc_xid_field xid_version;
 	struct gprs_llc_xid_field xid_n201u;
 	struct gprs_llc_xid_field xid_n201i;
+
+	bool iov = gprs_llgmm_gen_iov_ui(llme);
+	xid_iov_ui.type = GPRS_LLC_XID_T_IOV_UI;
+	xid_iov_ui.data = (uint8_t *) &llme->iov_ui;
+	xid_iov_ui.data_len = 4;
 
 	xid_version.type = GPRS_LLC_XID_T_VERSION;
 	xid_version.data = (uint8_t *) "\x00";
@@ -78,6 +84,9 @@
 	xid_n201i.data_len = 2;
 
 	/* Add locally managed XID Fields */
+	if (iov)
+		llist_add(&xid_iov_ui.list, &xid_fields);
+	LOGP(DLLC, LOGL_NOTICE, "XID gen with iov %d\n", iov);
 	llist_add(&xid_version.list, &xid_fields);
 	llist_add(&xid_n201u.list, &xid_fields);
 	llist_add(&xid_n201i.list, &xid_fields);
@@ -1060,6 +1069,19 @@
 	return gprs_llgmm_assign(llme, llme->tlli, 0xffffffff);
 }
 
+bool gprs_llgmm_gen_iov_ui(struct gprs_llc_llme *llme)
+{
+	if (llme->algo != GPRS_ALGO_GEA0) {
+		if (RAND_bytes((uint8_t *) &llme->iov_ui, 4) != 1) {
+			LOGP(DLLC, LOGL_NOTICE, "RAND_bytes failed for IOV-UI, "
+			     "falling back to rand()\n");
+			llme->iov_ui = rand();
+		}
+		return true;
+	}
+	return false;
+}
+
 /* Chapter 7.2.1.2 LLGMM-RESET.req */
 int gprs_llgmm_reset(struct gprs_llc_llme *llme)
 {
@@ -1070,11 +1092,7 @@
 	uint8_t *xid;
 
 	LOGP(DLLC, LOGL_NOTICE, "LLGM Reset\n");
-	if (RAND_bytes((uint8_t *) &llme->iov_ui, 4) != 1) {
-		LOGP(DLLC, LOGL_NOTICE, "RAND_bytes failed for LLC XID reset, "
-		     "falling back to rand()\n");
-		llme->iov_ui = rand();
-	}
+	gprs_llgmm_gen_iov_ui(llme);
 
 	/* Generate XID message */
 	xid_bytes_len = gprs_llc_generate_xid_for_gmm_reset(xid_bytes,
@@ -1103,11 +1121,7 @@
 	uint8_t *xid;
 
 	LOGP(DLLC, LOGL_NOTICE, "LLGM Reset\n");
-	if (RAND_bytes((uint8_t *) &llme->iov_ui, 4) != 1) {
-		LOGP(DLLC, LOGL_NOTICE, "RAND_bytes failed for LLC XID reset, "
-		     "falling back to rand()\n");
-		llme->iov_ui = rand();
-	}
+	gprs_llgmm_gen_iov_ui(llme);
 
 	/* Generate XID message */
 	xid_bytes_len = gprs_llc_generate_xid_for_gmm_reset(xid_bytes,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia71d6ac668a629d0377dd5c685e1dcd166def1a4
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list