blob: 095da8172d133f7835cfa8db6d4f3a14111cedfa [file] [log] [blame]
Neels Hofmeyrf8178142017-01-25 15:04: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#include "msc_vlr_tests.h"
25
26void test_hlr_rej_auth_info_unknown_imsi()
27{
28 comment_start();
29
30 net->authentication_required = true;
31
32 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
33 lu_result_sent = RES_NONE;
34 gsup_expect_tx("08010809710000004026f0");
35 ms_sends_msg("050802008168000130089910070000006402");
36 OSMO_ASSERT(gsup_tx_confirmed);
37 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
38
39 btw("HLR sends _SEND_AUTH_INFO_ERROR = unknown IMSI");
40 auth_request_sent = false;
Philipp Maier4b60d072017-04-09 12:32:51 +020041 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +010042 gsup_rx("09" "010809710000004026f0" "020102", NULL);
43 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
44 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +020045 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +010046
47 EXPECT_CONN_COUNT(0);
48 clear_vlr();
49 comment_end();
50}
51
52void test_hlr_rej_auth_info_net_fail()
53{
54 comment_start();
55
56 net->authentication_required = true;
57
58 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
59 lu_result_sent = RES_NONE;
60 gsup_expect_tx("08010809710000004026f0");
61 ms_sends_msg("050802008168000130089910070000006402");
62 OSMO_ASSERT(gsup_tx_confirmed);
63 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
64
65 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
66 auth_request_sent = false;
Philipp Maier4b60d072017-04-09 12:32:51 +020067 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +010068 gsup_rx("09" "010809710000004026f0" "020111", NULL);
69 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
70 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +020071 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +010072
73 EXPECT_CONN_COUNT(0);
74 clear_vlr();
75 comment_end();
76}
77
78void test_hlr_rej_auth_info_net_fail_no_reuse_tuples()
79{
80 struct vlr_subscr *vsub;
81 const char *imsi = "901700000004620";
82
83 comment_start();
84
85 net->authentication_required = true;
86 net->vlr->cfg.auth_reuse_old_sets_on_error = false;
87 net->vlr->cfg.auth_tuple_max_use_count = 0;
88
89 BTW("Submit a used auth tuple in the VLR");
90 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
91 lu_result_sent = RES_NONE;
92 gsup_expect_tx("08010809710000004026f0");
93 ms_sends_msg("050802008168000130089910070000006402");
94 OSMO_ASSERT(gsup_tx_confirmed);
95 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
96
97 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
98 auth_request_sent = false;
99 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
100 auth_request_expect_autn = NULL;
101 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
102 gsup_rx("0a"
103 /* imsi */
104 "0108" "09710000004026f0"
105 /* auth vectors... */
106 /* TL TL rand */
107 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
108 /* TL sres TL kc */
109 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
110 ,NULL);
111 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
112 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
113
114 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
115 gsup_expect_tx("04010809710000004026f0");
116 ms_sends_msg("05542d8b2c3e");
117 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
118
119 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
120 gsup_rx("10010809710000004026f00804036470f1",
121 "12010809710000004026f0");
122 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
123
124 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maier4b60d072017-04-09 12:32:51 +0200125 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100126 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +0200127 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100128
129 btw("LU was successful, and the conn has already been closed");
130 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
131 EXPECT_CONN_COUNT(0);
132
133
134 BTW("Now one auth tuple is available, but used.");
135 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
136 OSMO_ASSERT(vsub);
137 OSMO_ASSERT(vsub->last_tuple);
138 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
139 /* no need to look at all auth tuples, the ongoing test would take an
140 * unexpected course if there were more. */
141 vlr_subscr_put(vsub);
142
143 BTW("Another LU wants to get new tuples; HLR sends Network Failure, we reject.");
144
145 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
146 lu_result_sent = RES_NONE;
147 gsup_expect_tx("08010809710000004026f0");
148 ms_sends_msg("050802008168000130089910070000006402");
149 OSMO_ASSERT(gsup_tx_confirmed);
150 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
151
152 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
153 auth_request_sent = false;
Philipp Maier4b60d072017-04-09 12:32:51 +0200154 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100155 gsup_rx("09" "010809710000004026f0" "020111", NULL);
156 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
157 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +0200158 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100159
160 EXPECT_CONN_COUNT(0);
161 clear_vlr();
162 comment_end();
163}
164
165void test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples()
166{
167 struct vlr_subscr *vsub;
168 const char *imsi = "901700000004620";
169
170 comment_start();
171
172 net->authentication_required = true;
173 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
174 net->vlr->cfg.auth_tuple_max_use_count = 0;
175
176 BTW("Submit a used auth tuple in the VLR");
177 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
178 lu_result_sent = RES_NONE;
179 gsup_expect_tx("08010809710000004026f0");
180 ms_sends_msg("050802008168000130089910070000006402");
181 OSMO_ASSERT(gsup_tx_confirmed);
182 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
183
184 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
185 auth_request_sent = false;
186 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
187 auth_request_expect_autn = NULL;
188 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
189 gsup_rx("0a"
190 /* imsi */
191 "0108" "09710000004026f0"
192 /* auth vectors... */
193 /* TL TL rand */
194 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
195 /* TL sres TL kc */
196 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
197 ,NULL);
198 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
199 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
200
201 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
202 gsup_expect_tx("04010809710000004026f0");
203 ms_sends_msg("05542d8b2c3e");
204 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
205
206 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
207 gsup_rx("10010809710000004026f00804036470f1",
208 "12010809710000004026f0");
209 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
210
211 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maier4b60d072017-04-09 12:32:51 +0200212 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100213 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +0200214 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100215
216 btw("LU was successful, and the conn has already been closed");
217 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
218 EXPECT_CONN_COUNT(0);
219
220
221 BTW("Now one auth tuple is available, but used.");
222 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
223 OSMO_ASSERT(vsub);
224 OSMO_ASSERT(vsub->last_tuple);
225 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
226 /* no need to look at all auth tuples, the ongoing test would take an
227 * unexpected course if there were more. */
228 vlr_subscr_put(vsub);
229
230 BTW("Another LU wants to get new tuples; HLR sends IMSI Unknown. Even though we would re-use an old tuple, reject the unknown IMSI.");
231 VERBOSE_ASSERT(net->vlr->cfg.auth_reuse_old_sets_on_error, == true, "%d");
232
233 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
234 lu_result_sent = RES_NONE;
235 gsup_expect_tx("08010809710000004026f0");
236 ms_sends_msg("050802008168000130089910070000006402");
237 OSMO_ASSERT(gsup_tx_confirmed);
238 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
239
240 btw("HLR sends _SEND_AUTH_INFO_ERROR = unknown IMSI");
241 auth_request_sent = false;
Philipp Maier4b60d072017-04-09 12:32:51 +0200242 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100243 gsup_rx("09" "010809710000004026f0" "020102", NULL);
244 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
245 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +0200246 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100247
248 EXPECT_CONN_COUNT(0);
249 clear_vlr();
250 comment_end();
251}
252
253void test_hlr_acc_but_no_auth_tuples()
254{
255 comment_start();
256
257 net->authentication_required = true;
258 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
259 net->vlr->cfg.auth_tuple_max_use_count = 0;
260
261 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
262 lu_result_sent = RES_NONE;
263 gsup_expect_tx("08010809710000004026f0");
264 ms_sends_msg("050802008168000130089910070000006402");
265 OSMO_ASSERT(gsup_tx_confirmed);
266 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
267
268 btw("from HLR, rx _SEND_AUTH_INFO_RESULT but it lacks auth tuples");
269 auth_request_sent = false;
Philipp Maier4b60d072017-04-09 12:32:51 +0200270 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100271 gsup_rx("0a"
272 /* imsi */
273 "0108" "09710000004026f0"
274 /* NO auth vectors */
275 ,NULL);
276 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
277 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +0200278 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100279
280 EXPECT_CONN_COUNT(0);
281 clear_vlr();
282 comment_end();
283}
284
285void test_hlr_rej_auth_info_net_fail_reuse_tuples()
286{
287 struct vlr_subscr *vsub;
288 const char *imsi = "901700000004620";
289
290 comment_start();
291
292 net->authentication_required = true;
293 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
294 net->vlr->cfg.auth_tuple_max_use_count = 0;
295
296 BTW("Submit a used auth tuple in the VLR");
297 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
298 lu_result_sent = RES_NONE;
299 gsup_expect_tx("08010809710000004026f0");
300 ms_sends_msg("050802008168000130089910070000006402");
301 OSMO_ASSERT(gsup_tx_confirmed);
302 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
303
304 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
305 auth_request_sent = false;
306 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
307 auth_request_expect_autn = NULL;
308 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
309 gsup_rx("0a"
310 /* imsi */
311 "0108" "09710000004026f0"
312 /* auth vectors... */
313 /* TL TL rand */
314 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
315 /* TL sres TL kc */
316 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
317 ,NULL);
318 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
319 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
320
321 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
322 gsup_expect_tx("04010809710000004026f0");
323 ms_sends_msg("05542d8b2c3e");
324 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
325
326 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
327 gsup_rx("10010809710000004026f00804036470f1",
328 "12010809710000004026f0");
329 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
330
331 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maier4b60d072017-04-09 12:32:51 +0200332 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100333 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +0200334 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100335
336 btw("LU was successful, and the conn has already been closed");
337 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
338 EXPECT_CONN_COUNT(0);
339
340
341 BTW("Now one auth tuple is available, but used.");
342 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
343 OSMO_ASSERT(vsub);
344 OSMO_ASSERT(vsub->last_tuple);
345 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
346 /* no need to look at all auth tuples, the ongoing test would take an
347 * unexpected course if there were more. */
348 vlr_subscr_put(vsub);
349
350 BTW("Another LU wants to get new tuples; even though HLR sends Network Failure, we are reusing the old tuples.");
351
352 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
353 lu_result_sent = RES_NONE;
354 gsup_expect_tx("08010809710000004026f0");
355 ms_sends_msg("050802008168000130089910070000006402");
356 OSMO_ASSERT(gsup_tx_confirmed);
357 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
358
359 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
360 auth_request_sent = false;
361 gsup_rx("09" "010809710000004026f0" "020111", NULL);
362 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
363 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
364
365 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
366 gsup_expect_tx("04010809710000004026f0");
367 ms_sends_msg("05542d8b2c3e");
368 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
369
370 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
371 gsup_rx("10010809710000004026f00804036470f1",
372 "12010809710000004026f0");
373 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
374
375 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Philipp Maier4b60d072017-04-09 12:32:51 +0200376 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100377 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +0200378 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100379
380 btw("LU was successful, and the conn has already been closed");
381 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
382 EXPECT_CONN_COUNT(0);
383
384 clear_vlr();
385 comment_end();
386}
387
388void test_hlr_rej_lu()
389{
390 comment_start();
391
392 btw("Location Update request causes a GSUP LU request to HLR");
393 lu_result_sent = RES_NONE;
394 gsup_expect_tx("04010809710000004026f0");
395 ms_sends_msg("050802008168000130089910070000006402");
396 OSMO_ASSERT(gsup_tx_confirmed);
397 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
398
399 btw("HLR sends UPDATE_LOCATION_ERROR");
Philipp Maier4b60d072017-04-09 12:32:51 +0200400 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100401 gsup_rx("05" "010809710000004026f0" "020102",
402 NULL);
403 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
Philipp Maier4b60d072017-04-09 12:32:51 +0200404 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100405 EXPECT_CONN_COUNT(0);
406
407 clear_vlr();
408 comment_end();
409}
410
411void test_hlr_no_insert_data()
412{
413 comment_start();
414
415 btw("Location Update request causes a GSUP LU request to HLR");
416 lu_result_sent = RES_NONE;
417 gsup_expect_tx("04010809710000004026f0");
418 ms_sends_msg("050802008168000130089910070000006402");
419 OSMO_ASSERT(gsup_tx_confirmed);
420 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
421
422 btw("HLR sends only _UPDATE_LOCATION_RESULT, no INSERT DATA");
Philipp Maier4b60d072017-04-09 12:32:51 +0200423 expect_bssap_clear();
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100424 gsup_rx("06010809710000004026f0", NULL);
Philipp Maier4b60d072017-04-09 12:32:51 +0200425 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d");
Neels Hofmeyrf8178142017-01-25 15:04:16 +0100426
427 /* TODO should we wait for OSMO_GSUP_MSGT_INSERT_DATA_REQUEST? */
428
429 btw("LU was successful, and the conn has already been closed");
430 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
431
432 EXPECT_CONN_COUNT(0);
433 clear_vlr();
434 comment_end();
435}
436
437msc_vlr_test_func_t msc_vlr_tests[] = {
438 test_hlr_rej_auth_info_unknown_imsi,
439 test_hlr_rej_auth_info_net_fail,
440 test_hlr_rej_auth_info_net_fail_reuse_tuples,
441 test_hlr_rej_auth_info_net_fail_no_reuse_tuples,
442 test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples,
443 test_hlr_acc_but_no_auth_tuples,
444 test_hlr_rej_lu,
445 test_hlr_no_insert_data,
446 NULL
447};