aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bsc
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2021-06-15 01:09:37 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2021-06-18 23:31:31 +0200
commit498e55a9a4a99aaea7e62b8a477a978e35a597f2 (patch)
tree20ed95d5562029a99f7d2d7ce7a8714147e78217 /src/osmo-bsc
parent0256c891878be531c24aa0c62e7c56ef8d71ab65 (diff)
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
Diffstat (limited to 'src/osmo-bsc')
-rw-r--r--src/osmo-bsc/abis_rsl.c8
-rw-r--r--src/osmo-bsc/osmo_bsc_bssap.c20
2 files changed, 27 insertions, 1 deletions
diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c
index c844f181e..86b179067 100644
--- a/src/osmo-bsc/abis_rsl.c
+++ b/src/osmo-bsc/abis_rsl.c
@@ -178,6 +178,14 @@ static int build_encr_info(uint8_t *out, struct gsm_lchan *lchan)
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 9177e6b00..6f0caa76d 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -466,6 +466,7 @@ static int bssmap_handle_cipher_mode(struct gsm_subscriber_connection *conn,
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 @@ static int bssmap_handle_cipher_mode(struct gsm_subscriber_connection *conn,
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;
+ }
+
+ 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 include_imeisv=%d\n",
+ 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) {