blob: 870f993691fee8e471f5fb371a684bd610233807 [file] [log] [blame]
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +01001/* Osmocom MSC+VLR end-to-end tests */
2
3/* (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 *
5 * All Rights Reserved
6 *
7 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24/* NOTE that further auth re-use tests exist in msc_vlr_test_hlr_reject.c */
25
26#include "msc_vlr_tests.h"
27
Neels Hofmeyr7814a832018-12-26 00:40:18 +010028static void _test_auth_reuse(enum osmo_rat_type via_ran,
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010029 int set_max_reuse_count,
30 int loop_requests_without_hlr,
31 bool final_request_with_hlr)
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010032{
33 struct vlr_subscr *vsub;
34 const char *imsi = "901700000010650";
35 int expected_use_count;
36 int i;
37
38 net->authentication_required = true;
39 net->vlr->cfg.assign_tmsi = true;
40 net->vlr->cfg.auth_tuple_max_reuse_count = set_max_reuse_count;
41 net->vlr->cfg.auth_reuse_old_sets_on_error = false;
42 rx_from_ran = via_ran;
43
44 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
45 lu_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +010046 gsup_expect_tx("080108" "09710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010047 ms_sends_msg("0508" /* MM LU */
48 "7" /* ciph key seq: no key available */
49 "0" /* LU type: normal */
50 "ffffff" "0000" /* LAI, LAC */
51 "57" /* classmark 1: R99, early classmark, no power lvl */
52 "089910070000106005" /* IMSI */
53 "3303575886" /* classmark 2 */
54 );
55 OSMO_ASSERT(gsup_tx_confirmed);
56 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
57
58 btw("from HLR, rx _SEND_AUTH_INFO_RESULT, only one tuple; VLR sends Auth Req to MS");
59 /* based on auc_3g:
60 * K = 'EB215756028D60E3275E613320AEC880',
61 * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308'
62 * SQN = 0
63 */
64 auth_request_sent = false;
65 auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d";
66 auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919";
67 gsup_rx("0a"
68 /* imsi */
69 "0108" "09710000000156f0"
70 /* TL TL rand */
71 "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d"
72 /* TL sres TL kc */
73 "2104" "9b36efdf" "2208" "059a4f668f6fbe39"
74 /* TL 3G IK */
75 "2310" "27497388b6cb044648f396aa155b95ef"
76 /* TL 3G CK */
77 "2410" "f64735036e5871319c679f4742a75ea1"
78 /* TL AUTN */
79 "2510" "8704f5ba55f30000d2ee44b22c8ea919"
80 /* TL RES */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010081 "2708" "e229c19e791f2e41" HLR_TO_VLR,
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010082 NULL);
83 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
84 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
85
Neels Hofmeyr7814a832018-12-26 00:40:18 +010086 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010087 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +010088 gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010089 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
90 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
91 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
92 } else {
93 /* On UTRAN */
94 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010095 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010096 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010097 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010098 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
99
100 btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100101 gsup_expect_tx("04010809710000000156f0" CN_DOMAIN VLR_TO_HLR);
Alexander Couzens2aaff752021-10-19 17:09:11 +0200102 ms_sends_security_mode_complete(1);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100103 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
104 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
105 }
106
107 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100108 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
109 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100110 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
111
112 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100113 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100114
115 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
116
117 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
118 EXPECT_CONN_COUNT(1);
119 EXPECT_ACCEPTED(false);
120 thwart_rx_non_initial_requests();
121
122 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100123 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100124 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
125 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
126 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
127 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100128 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100129
130 btw("MS sends TMSI Realloc Complete");
131 expect_release_clear(via_ran);
132 ms_sends_msg("055b");
133 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100134 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100135
136 btw("LU was successful, and the conn has already been closed");
137 EXPECT_CONN_COUNT(0);
138
139 expected_use_count = 1;
140
141 for (i = 0; i < loop_requests_without_hlr; i++, expected_use_count++) {
142 BTW("Now the auth tuple has use_count == %d", expected_use_count);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100143 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100144 OSMO_ASSERT(vsub);
145 OSMO_ASSERT(vsub->last_tuple);
146 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100147 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100148
149 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req,"
150 " and reuses old auth vector");
151 auth_request_sent = true;
152 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100153 ms_sends_msg("052474"
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100154 "03575886" /* classmark 2 */
155 "089910070000106005" /* IMSI */);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100156 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
157 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
158
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100159 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100160 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
161 gsup_expect_tx(NULL);
162 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
163 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
164 } else {
165 /* On UTRAN */
166 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100167 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100168 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100169 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100170 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
171
172 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
Alexander Couzens2aaff752021-10-19 17:09:11 +0200173 ms_sends_security_mode_complete(1);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100174 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
175 }
176
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700177 /* Release connection */
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100178 expect_release_clear(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100179 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
180 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100181
182 btw("all requests serviced, conn has been released");
183 EXPECT_CONN_COUNT(0);
184 }
185
186 if (final_request_with_hlr) {
187 BTW("Now the auth tuple has use_count == %d, as much as is allowed.", expected_use_count);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100188 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100189 OSMO_ASSERT(vsub);
190 OSMO_ASSERT(vsub->last_tuple);
191 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100192 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100193
194 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req,"
195 " and needs to request a second auth vector from HLR");
196 auth_request_sent = false;
197 cm_service_result_sent = RES_NONE;
Neels Hofmeyr63b24642019-12-12 01:31:04 +0100198 gsup_expect_tx("080108" "09710000000156f0" CN_DOMAIN VLR_TO_HLR);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100199 ms_sends_msg("052474"
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100200 "03575886" /* classmark 2 */
201 "089910070000106005" /* IMSI */);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100202 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
203 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
204 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
205
206 btw("from HLR, rx _SEND_AUTH_INFO_RESULT, second tuple; VLR sends Auth Req to MS");
207 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
208 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
209 gsup_rx("0a"
210 /* imsi */
211 "0108" "09710000000156f0"
212 /* TL TL rand */
213 /* TL sres TL kc */
214 /* TL 3G IK */
215 /* TL 3G CK */
216 /* TL AUTN */
217 /* TL RES */
218 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
219 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
220 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
221 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
222 "2510" "1843a645b98d00005b2d666af46c45d9"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100223 "2708" "7db47cf7f81e4dc7" HLR_TO_VLR,
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100224 NULL);
225 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
226 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
227
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100228 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100229 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
230 gsup_expect_tx(NULL);
231 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
232 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
233 } else {
234 /* On UTRAN */
235 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100236 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100237 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100238 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100239 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
240
241 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
Alexander Couzens2aaff752021-10-19 17:09:11 +0200242 ms_sends_security_mode_complete(1);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100243 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
244 }
245
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700246 /* Release connection */
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100247 expect_release_clear(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100248 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
249 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100250
251 btw("all requests serviced, conn has been released");
252 EXPECT_CONN_COUNT(0);
253 }
254
255 BTW("subscriber detaches");
256 expect_release_clear(via_ran);
257 ms_sends_msg("050130"
258 "089910070000106005" /* IMSI */);
259 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100260 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100261
262 EXPECT_CONN_COUNT(0);
263 clear_vlr();
264}
265
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100266static void test_auth_use_twice_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100267{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100268 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100269 _test_auth_reuse(OSMO_RAT_GERAN_A, 1, 1, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100270 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100271}
272
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100273static void test_auth_use_twice_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100274{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100275 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100276 _test_auth_reuse(OSMO_RAT_UTRAN_IU, 1, 1, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100277 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100278}
279
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100280static void test_auth_use_infinitely_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100281{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100282 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100283 _test_auth_reuse(OSMO_RAT_GERAN_A, -1, 3, false);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100284 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100285}
286
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100287static void test_auth_use_infinitely_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100288{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100289 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100290 _test_auth_reuse(OSMO_RAT_UTRAN_IU, -1, 3, false);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100291 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100292}
293
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100294static void test_no_auth_reuse_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100295{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100296 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100297 _test_auth_reuse(OSMO_RAT_GERAN_A, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100298 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100299}
300
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100301static void test_no_auth_reuse_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100302{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100303 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100304 _test_auth_reuse(OSMO_RAT_UTRAN_IU, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100305 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100306}
307
308msc_vlr_test_func_t msc_vlr_tests[] = {
309 test_auth_use_twice_geran,
310 test_auth_use_twice_utran,
311 test_auth_use_infinitely_geran,
312 test_auth_use_infinitely_utran,
313 test_no_auth_reuse_geran,
314 test_no_auth_reuse_utran,
315 NULL
316};