Change in osmo-bsc[master]: implement A5/4 in Ciphering Mode procedure

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

neels gerrit-no-reply at lists.osmocom.org
Sun Jun 20 21:00:55 UTC 2021


neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/24635 )

Change subject: implement A5/4 in Ciphering Mode procedure
......................................................................

implement A5/4 in Ciphering Mode procedure

Receive and store the Kc128 key from MSC, and use as key sent to BTS if
A5/4 is the chosen encryption algorithm.

(A5/4 in handover will follow in a separate patch)

Related: SYS#5324
Change-Id: I7c458c8a7350f34ff79531b3c891e1b367614469
---
M include/osmocom/bsc/gsm_data.h
M src/osmo-bsc/abis_rsl.c
M src/osmo-bsc/osmo_bsc_bssap.c
3 files changed, 29 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  fixeria: Looks good to me, approved
  laforge: Looks good to me, but someone else must approve



diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 2a73f46..1755b92 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -554,6 +554,8 @@
 	uint8_t alg_id;
 	uint8_t key_len;
 	uint8_t key[MAX_A5_KEY_LEN];
+	bool kc128_present;
+	uint8_t kc128[16];
 };
 
 #define LOGPLCHAN(lchan, ss, level, fmt, args...) \
diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c
index c844f18..86b1790 100644
--- a/src/osmo-bsc/abis_rsl.c
+++ b/src/osmo-bsc/abis_rsl.c
@@ -178,6 +178,14 @@
 			memcpy(out, lchan->encr.key, lchan->encr.key_len);
 		return 1 + lchan->encr.key_len;
 
+	case GSM0808_ALG_ID_A5_4:
+		if (!lchan->encr.kc128_present) {
+			LOG_LCHAN(lchan, LOGL_ERROR, "A5/4 encryption chosen, but missing Kc128\n");
+			return -EINVAL;
+		}
+		memcpy(out, lchan->encr.kc128, sizeof(lchan->encr.kc128));
+		return 1 + sizeof(lchan->encr.kc128);
+
 	default:
 		LOG_LCHAN(lchan, LOGL_ERROR, "A5/%d encryption not supported\n", lchan->encr.alg_id);
 		return -EINVAL;
diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index 9177e6b..6f0caa7 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -466,6 +466,7 @@
 	uint16_t enc_key_len;
 	uint8_t enc_bits_msc;
 	int chosen_cipher;
+	const struct tlv_p_entry *ie_kc128;
 
 	if (!conn || !conn->lchan) {
 		LOGP(DMSC, LOGL_ERROR, "No lchan/msc_data in cipher mode command.\n");
@@ -544,9 +545,26 @@
 		conn->lchan->encr.key_len = enc_key_len;
 		memcpy(conn->lchan->encr.key, enc_key, enc_key_len);
 	}
+	if ((ie_kc128 = TLVP_GET(&tp, GSM0808_IE_KC_128))) {
+		if (ie_kc128->len != sizeof(conn->lchan->encr.kc128)) {
+			LOGPFSML(conn->fi, LOGL_ERROR, "Kc128 IE has wrong length: %u (expect %zu)\n",
+				 ie_kc128->len, sizeof(conn->lchan->encr.kc128));
+			reject_cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
+			goto reject;
+		}
+		memcpy(conn->lchan->encr.kc128, ie_kc128->val, sizeof(conn->lchan->encr.kc128));
+		conn->lchan->encr.kc128_present = true;
+	}
 
-	LOGP(DRSL, LOGL_DEBUG, "(subscr %s) Cipher Mode: cipher=%d key=%s include_imeisv=%d\n",
+	if (chosen_cipher == 4 && !conn->lchan->encr.kc128_present) {
+		LOGPFSML(conn->fi, LOGL_ERROR, "A5/4 encryption selected, but no Kc128\n");
+		reject_cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
+		goto reject;
+	}
+
+	LOGP(DRSL, LOGL_DEBUG, "(subscr %s) Cipher Mode: cipher=%d key=%s kc128=%s include_imeisv=%d\n",
 	     bsc_subscr_name(conn->bsub), chosen_cipher, osmo_hexdump_nospc(enc_key, enc_key_len),
+	     ie_kc128? osmo_hexdump_nospc_c(OTC_SELECT, ie_kc128->val, ie_kc128->len) : "-",
 	     include_imeisv);
 
 	if (gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv) < 0) {

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/24635
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I7c458c8a7350f34ff79531b3c891e1b367614469
Gerrit-Change-Number: 24635
Gerrit-PatchSet: 5
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210620/6b1ac812/attachment.htm>


More information about the gerrit-log mailing list