From 8a9bf6f21518925c2c1a62ffa7935fe80401cbfe Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 10 May 2018 22:00:49 +0200 Subject: bsc: Verify correct encryption n RSL CHAN_ACT during assignment Change-Id: Iff77586ea39da32df570048b1d83f5a0edb5a533 --- bsc/BSC_Tests.ttcn | 1 - bsc/MSC_ConnectionHandler.ttcn | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn index b3c7c614..14f3724a 100644 --- a/bsc/BSC_Tests.ttcn +++ b/bsc/BSC_Tests.ttcn @@ -1443,7 +1443,6 @@ private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr { ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR})); f_establish_fully(ass_cmd, exp_compl); - f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key); } testcase TC_assignment_fr_a5_0() runs on test_CT { var MSC_ConnHdlr vc_conn; diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn index c1ff9636..fe524dcf 100644 --- a/bsc/MSC_ConnectionHandler.ttcn +++ b/bsc/MSC_ConnectionHandler.ttcn @@ -544,6 +544,37 @@ template (value) AssignmentState ts_AssignmentStateInit := { modify_done := false } +private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := { + encr_info := { + len := ?, + alg_id := alg, + key := key + } +} + +/* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */ +private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr { + var RSL_IE_Body encr_info; + if (ispresent(g_pars.encr) and g_pars.encr.enc_alg != '01'O) { + if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) { + setverdict(fail, "Missing Encryption IE in CHAN ACT"); + } else { + var RSL_AlgId alg := f_chipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg); + if (not match(encr_info, tr_EncrInfo(alg, g_pars.encr.enc_key))) { + setverdict(fail, "Wrong Encryption IE in CHAN ACT"); + } + } + } else { + if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) { + if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) { + setverdict(fail, "Unexpected Encryption in CHAN ACT"); + } + } + } + /* FIXME: validate RSL_IE_ACT_TYPE, RSL_IE_CHAN_MODE, RSL_IE_CHAN_IDENT, RSL_IE_BS_POWER, + * RSL_IE_MS_POWER, RSL_IE_TIMING_ADVANCE */ +} + altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr { var RSL_Message rsl; [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { @@ -566,6 +597,10 @@ altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr { st.old_chan_nr := g_chan_nr; g_chan_nr := new_chan_nr; st.rr_ass_cmpl_seen := true; + /* obtain channel activation from RSL_Emulation for new channel */ + var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr); + /* check it (e.g. for correct ciphering parameters) */ + f_check_chan_act(st, chan_act); repeat; } else { setverdict(fail, "Unexpected L3 received", l3); @@ -666,6 +701,12 @@ runs on MSC_ConnHdlr return PDU_BSSAP { f_create_chan_and_exp(); /* we should now have a COMPL_L3 at the MSC */ BSSAP.receive(tr_BSSMAP_ComplL3); + + /* start ciphering, if requested */ + if (ispresent(g_pars.encr)) { + f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key); + } + f_create_mgcp_expect(mgcpcrit); BSSAP.send(ass_cmd); -- cgit v1.2.3