[PATCH] osmo-ttcn3-hacks[master]: BSC_Tests: Implement ecnryption related procedures

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
Sun Dec 17 10:06:42 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5453

to look at the new patch set (#2).

BSC_Tests: Implement ecnryption related procedures

Let's verify the operation of the CIPHERING MODE COMMAND as issued
by MSC, performed by BSC and implemented by simulated BTS/MS.

Change-Id: Ibc06bd2177c63837a794a0ca1f54ebef17499e78
---
M bsc/BSC_Tests.ttcn
M bsc/MSC_ConnectionHandler.ttcn
M library/BSSMAP_Templates.ttcn
M library/L3_Templates.ttcn
M library/RSL_Types.ttcn
5 files changed, 138 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/53/5453/2

diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index ce61984..2d65e57 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -1211,9 +1211,9 @@
 
 	ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
 	ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
-	ass_cmd.pdu.bssmap.assignmentRequest.encryptionInformation :=
-							valueof(ts_BSSMAP_IE_EncrInfo(kc, '01'O));
+
 	f_establish_fully(pars, ass_cmd, exp_compl);
+	f_cipher_mode('01'O, kc);
 }
 
 testcase TC_assignment_fr_a5_0() runs on test_CT {
@@ -1238,10 +1238,9 @@
 
 	ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
 	ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
-	ass_cmd.pdu.bssmap.assignmentRequest.encryptionInformation :=
-							valueof(ts_BSSMAP_IE_EncrInfo(kc, '02'O));
 
 	f_establish_fully(pars, ass_cmd, exp_compl);
+	f_cipher_mode('02'O, kc);
 }
 
 testcase TC_assignment_fr_a5_1() runs on test_CT {
@@ -1263,8 +1262,6 @@
 	const OCT8 kc := '0001020304050607'O;
 
 	ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
-	ass_cmd.pdu.bssmap.assignmentRequest.encryptionInformation :=
-							valueof(ts_BSSMAP_IE_EncrInfo(kc, '02'O));
 	f_establish_fully(pars, ass_cmd, exp_fail);
 }
 
@@ -1288,9 +1285,9 @@
 
 	ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
 	ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
-	ass_cmd.pdu.bssmap.assignmentRequest.encryptionInformation :=
-							valueof(ts_BSSMAP_IE_EncrInfo(kc, '08'O));
+
 	f_establish_fully(pars, ass_cmd, exp_compl);
+	f_cipher_mode('08'O, kc);
 }
 
 testcase TC_assignment_fr_a5_3() runs on test_CT {
@@ -1314,11 +1311,9 @@
 
 	ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
 	ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
-	ass_cmd.pdu.bssmap.assignmentRequest.encryptionInformation :=
-							valueof(ts_BSSMAP_IE_EncrInfo(kc, '10'O));
-	ass_cmd.pdu.bssmap.assignmentRequest.kC128 := valueof(ts_BSSMAP_IE_Kc128(kc128));
 	/* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
 	f_establish_fully(pars, ass_cmd, exp_fail);
+	f_cipher_mode('10'O, kc, kc128);
 }
 
 testcase TC_assignment_fr_a5_4() runs on test_CT {
diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn
index d615497..a76d1d6 100644
--- a/bsc/MSC_ConnectionHandler.ttcn
+++ b/bsc/MSC_ConnectionHandler.ttcn
@@ -99,6 +99,35 @@
 	RSL.send(ts_RSL_DATA_IND(chan_nr, link_id, enc_PDU_ML3_MS_NW(valueof(l3))));
 }
 
+function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit) runs on MSC_ConnHdlr {
+	var PDU_BSSAP bssap;
+	var RSL_Message rsl;
+
+	if (isvalue(kc128)) {
+		BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128)));
+	} else {
+		BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key));
+	}
+	alt {
+	/* RSL/UE Side */
+	[] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg, key)) -> value rsl {
+		var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload);
+		log("Rx L3 from net: ", l3);
+		if (ischosen(l3.msgs.rrm.cipheringModeCommand)) {
+			f_rsl_reply(ts_RRM_CiphModeCompl, rsl);
+		}
+		repeat;
+		}
+	[] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap {
+		// bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier
+		setverdict(pass);
+		}
+	[] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap {
+		setverdict(fail, "Ciphering Mode Reject");
+		}
+	}
+}
+
 /* establish a channel fully, expecting an assignment matching 'exp' */
 function f_establish_fully(TestHdlrParams pars, PDU_BSSAP ass_cmd, template PDU_BSSAP exp_ass_cpl)
 runs on MSC_ConnHdlr return PDU_BSSAP {
diff --git a/library/BSSMAP_Templates.ttcn b/library/BSSMAP_Templates.ttcn
index 24a888c..bb1b537 100644
--- a/library/BSSMAP_Templates.ttcn
+++ b/library/BSSMAP_Templates.ttcn
@@ -703,5 +703,62 @@
 	}
 }
 
+template PDU_BSSAP ts_BSSMAP_CipherModeCmd(OCT1 alg, OCT8 key)
+modifies ts_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeCommand := {
+				messageType := '53'O,
+				layer3HeaderInfo := omit,
+				encryptionInformation := ts_BSSMAP_IE_EncrInfo(key, alg),
+				cipherResponseMode := omit,
+				kC128 := omit
+			}
+		}
+	}
+}
+
+template PDU_BSSAP ts_BSSMAP_CipherModeCmdKc128(OCT1 alg, OCT8 key, OCT16 kc128)
+modifies ts_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeCommand := {
+				messageType := '53'O,
+				layer3HeaderInfo := omit,
+				encryptionInformation := ts_BSSMAP_IE_EncrInfo(key, alg),
+				cipherResponseMode := omit,
+				kC128 := { '83'O, kc128 }
+			}
+		}
+	}
+}
+
+template PDU_BSSAP tr_BSSMAP_CipherModeCompl(template OCT1 alg := ?) modifies tr_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeComplete := {
+				messageType := '55'O,
+				layer3MessageContents := *,
+				chosenEncryptionAlgorithm := {
+					elementIdentifier := '2C'O,
+					algorithmIdentifier := alg
+				}
+			}
+		}
+	}
+}
+
+template PDU_BSSAP tr_BSSMAP_CipherModeRej modifies tr_BSSAP_BSSMAP := {
+	pdu := {
+		bssmap := {
+			cipherModeReject := {
+				messageType := '59'O,
+				cause  := ?
+			}
+		}
+	}
+}
+
+
 
 } with { encode "RAW" };
diff --git a/library/L3_Templates.ttcn b/library/L3_Templates.ttcn
index 4755989..f0f3d38 100644
--- a/library/L3_Templates.ttcn
+++ b/library/L3_Templates.ttcn
@@ -126,5 +126,20 @@
 	}
 }
 
+template (value) PDU_ML3_MS_NW ts_RRM_CiphModeCompl := {
+	discriminator := '0000'B, /* overwritten */
+	tiOrSkip := {
+		skipIndicator := '0000'B
+	},
+	msgs := {
+		rrm := {
+			cipheringModeComplete := {
+				messageType := '00110010'B,
+				mobileEquipmentIdentity := omit
+			}
+		}
+	}
+}
+
 
 }
diff --git a/library/RSL_Types.ttcn b/library/RSL_Types.ttcn
index 67e4dc9..0604440 100644
--- a/library/RSL_Types.ttcn
+++ b/library/RSL_Types.ttcn
@@ -330,6 +330,19 @@
 		uint5_t		power_level
 	}
 
+	/* 9.3.7 */
+	type record RSL_IE_EncryptionInfo {
+		uint8_t		len,
+		OCT1		alg_id,
+		octetstring	key
+	} with { variant (len) "LENGTHTO(alg_id,key)" };
+
+	template RSL_IE_EncryptionInfo tr_RSL_IE_EncrInfo(template OCT1 alg, template octetstring key) := {
+		len := ?,
+		alg_id := alg,
+		key := key
+	}
+
 	/* 9.3.8 */
 	type record RSL_IE_FrameNumber {
 		uint5_t		t1_p,
@@ -550,6 +563,7 @@
 		uint8_t			paging_group,
 		RSL_IE_ChanNeeded	chan_needed,
 		RSL_IE_StartingTime	starting_time,
+		RSL_IE_EncryptionInfo	encr_info,
 		RSL_IE_RequestRef	req_ref,
 		RSL_LV			full_imm_ass_info,
 		RSL_LV			ms_identity,
@@ -595,6 +609,7 @@
 					paging_group, iei = RSL_IE_PAGING_GROUP;
 					chan_needed, iei = RSL_IE_CHAN_NEEDED;
 					starting_time, iei = RSL_IE_STARTNG_TIME;
+					encr_info, iei = RSL_IE_ENCR_INFO;
 
 					req_ref, iei = RSL_IE_REQ_REFERENCE;
 					full_imm_ass_info, iei = RSL_IE_FULL_IMM_ASS_INFO;
@@ -852,6 +867,22 @@
 		}
 	}
 
+	/* 8.4.6 BSC ->BTS */
+	template RSL_Message tr_RSL_ENCR_CMD(template RslChannelNr chan_nr,
+					     template RslLinkId link_id := ?,
+					     template OCT1 alg := ?,
+					     template octetstring key := ?,
+					     template octetstring l3_info := ?) := {
+		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
+		msg_type := RSL_MT_ENCR_CMD,
+		ies := {
+			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
+			tr_RSL_IE(RSL_IE_Body:{encr_info := tr_RSL_IE_EncrInfo(alg, key)}),
+			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
+			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
+		}
+	}
+
 	/* 8.4.10 BTS -> BSC */
 	template RSL_Message ts_RSL_MODE_MODIFY_ACK(RslChannelNr chan_nr) := {
 		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ibc06bd2177c63837a794a0ca1f54ebef17499e78
Gerrit-PatchSet: 2
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list