[MERGED] libosmocore[master]: osmo-auc-gen: umts: properly request --sqn

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
Tue Aug 29 12:46:48 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: osmo-auc-gen: umts: properly request --sqn
......................................................................


osmo-auc-gen: umts: properly request --sqn

The user supplied an --sqn to generate a vector for, but milenage_gen_vec()
performs a nontrivial SQN increment before generating the vector. To end up
with the user supplied SQN, we need to reverse this increment beforehand.

Do this after all cmdline args have been parsed, in case one of them modifies
the IND-bitlen parameter, which affects the SQN calculations.

Related: OS#2464 OS#2465
Change-Id: Ic51a8f6333fee9c02b4073ca360991d0aa69c74f
---
M utils/osmo-auc-gen.c
1 file changed, 17 insertions(+), 5 deletions(-)

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



diff --git a/utils/osmo-auc-gen.c b/utils/osmo-auc-gen.c
index fade6ec..87960ae 100644
--- a/utils/osmo-auc-gen.c
+++ b/utils/osmo-auc-gen.c
@@ -95,9 +95,11 @@
 	struct osmo_auth_vector _vec;
 	struct osmo_auth_vector *vec = &_vec;
 	uint8_t _rand[16], _auts[14];
+	uint64_t sqn;
 	int rc, option_index;
 	int rand_is_set = 0;
 	int auts_is_set = 0;
+	int sqn_is_set = 0;
 	int fmt_triplets_dat = 0;
 
 	printf("osmo-auc-gen (C) 2011-2012 by Harald Welte\n");
@@ -196,11 +198,8 @@
 				fprintf(stderr, "Only UMTS has SQN\n");
 				exit(2);
 			}
-			test_aud.u.umts.sqn = strtoull(optarg, 0, 10);
-			/* Before calculating the UMTS auth vector,
-			 * osmo_auth_gen_vec() increments the SQN. SQN-1 here
-			 * to end up with the SQN the user requested. */
-			test_aud.u.umts.sqn--;
+			sqn = strtoull(optarg, 0, 10);
+			sqn_is_set = 1;
 			break;
 		case 'r':
 			rc = osmo_hexparse(optarg, _rand, sizeof(_rand));
@@ -246,6 +245,19 @@
 
 	memset(vec, 0, sizeof(*vec));
 
+	if (test_aud.type == OSMO_AUTH_TYPE_UMTS) {
+		uint64_t seq_1 = 1LL << test_aud.u.umts.ind_bitlen;
+		uint64_t ind_mask = seq_1 - 1;
+
+		if (sqn_is_set) {
+			/* Before calculating the UMTS auth vector, osmo_auth_gen_vec() increments SEQ.
+			 * To end up with the SQN passed in by the user, we need to pass in SEQ-1, and
+			 * indicate which IND slot to target. */
+			test_aud.u.umts.sqn = sqn - seq_1;
+			test_aud.u.umts.ind = sqn & ind_mask;
+		}
+	}
+
 	if (!auts_is_set)
 		rc = osmo_auth_gen_vec(vec, &test_aud, _rand);
 	else

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic51a8f6333fee9c02b4073ca360991d0aa69c74f
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list