[PATCH] libosmocore[master]: auth_milenage: Fix non-AUTS case with OP

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Aug 16 21:32:58 UTC 2017


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

auth_milenage: Fix non-AUTS case with OP

We only implemented OPC generation from OP in the AUTS case, but not
in the case of normal authentication vector generation.  This never
really was visible so far due to the fact that we use OPC at sysmocom,
and never the shared OP value.

Change-Id: Id3fa038dfc2ff1ba63616fa5e8eab0520481ff26
---
M include/osmocom/vty/ports.h
M src/gsm/auth_milenage.c
2 files changed, 25 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/41/3541/1

diff --git a/include/osmocom/vty/ports.h b/include/osmocom/vty/ports.h
index 8f8ef75..c3ad389 100644
--- a/include/osmocom/vty/ports.h
+++ b/include/osmocom/vty/ports.h
@@ -26,4 +26,5 @@
 #define OSMO_VTY_PORT_MNCC_SIP	4256
 /* 4257 used by control interface */
 #define OSMO_VTY_PORT_HLR	4258
+#define OSMO_VTY_PORT_GGSN	4259
 /* When adding/changing port numbers, keep docs and wiki in sync. See above. */
diff --git a/src/gsm/auth_milenage.c b/src/gsm/auth_milenage.c
index 8d50990..6dd4f45 100644
--- a/src/gsm/auth_milenage.c
+++ b/src/gsm/auth_milenage.c
@@ -30,16 +30,36 @@
  *  @{
  */
 
+static const uint8_t *gen_opc_if_needed(const struct osmo_sub_auth_data *aud, uint8_t *gen_opc)
+{
+	int rc;
+
+	/* Check if we only know OP and compute OPC if required */
+	if (aud->type == OSMO_AUTH_TYPE_UMTS && aud->u.umts.opc_is_op) {
+		rc = milenage_opc_gen(gen_opc, aud->u.umts.k, aud->u.umts.opc);
+		if (rc < 0)
+			return NULL;
+		return gen_opc;
+	} else
+		return aud->u.umts.opc;
+}
+
 static int milenage_gen_vec(struct osmo_auth_vector *vec,
 			    struct osmo_sub_auth_data *aud,
 			    const uint8_t *_rand)
 {
 	size_t res_len = sizeof(vec->res);
 	uint64_t next_sqn;
+	uint8_t gen_opc[16];
+	const uint8_t *opc;
 	uint8_t sqn[6];
 	uint64_t ind_mask;
 	uint64_t seq_1;
 	int rc;
+
+	opc = gen_opc_if_needed(aud, gen_opc);
+	if (!opc)
+		return -1;
 
 	/* Determine next SQN, according to 3GPP TS 33.102:
 	 * SQN consists of SEQ and a lower significant part of IND bits:
@@ -106,11 +126,11 @@
 	next_sqn = ((aud->u.umts.sqn + seq_1) & ind_mask) + aud->u.umts.ind;
 
 	osmo_store64be_ext(next_sqn, sqn, 6);
-	milenage_generate(aud->u.umts.opc, aud->u.umts.amf, aud->u.umts.k,
+	milenage_generate(opc, aud->u.umts.amf, aud->u.umts.k,
 			  sqn, _rand,
 			  vec->autn, vec->ik, vec->ck, vec->res, &res_len);
 	vec->res_len = res_len;
-	rc = gsm_milenage(aud->u.umts.opc, aud->u.umts.k, _rand, vec->sres, vec->kc);
+	rc = gsm_milenage(opc, aud->u.umts.k, _rand, vec->sres, vec->kc);
 	if (rc < 0)
 		return rc;
 
@@ -129,18 +149,10 @@
 {
 	uint8_t sqn_out[6];
 	uint8_t gen_opc[16];
-	uint8_t *opc;
+	const uint8_t *opc;
 	int rc;
 
-	/* Check if we only know OP and compute OPC if required */
-	if (aud->type == OSMO_AUTH_TYPE_UMTS && aud->u.umts.opc_is_op) {
-		rc = milenage_opc_gen(gen_opc, aud->u.umts.k,
-				      aud->u.umts.opc);
-		if (rc < 0)
-			return rc;
-		opc = gen_opc;
-	} else
-		opc = aud->u.umts.opc;
+	opc = gen_opc_if_needed(aud, gen_opc);
 
 	rc = milenage_auts(opc, aud->u.umts.k, rand_auts, auts, sqn_out);
 	if (rc < 0)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3fa038dfc2ff1ba63616fa5e8eab0520481ff26
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list