blob: c4cf3534a543cc93b61ff8368f4ab0ad16ffaba5 [file] [log] [blame]
Neels Hofmeyr6a29d322017-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;
41 gsup_rx("09" "010809710000004026f0" "020102", NULL);
42 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
43 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
44
45 EXPECT_CONN_COUNT(0);
46 clear_vlr();
47 comment_end();
48}
49
50void test_hlr_rej_auth_info_net_fail()
51{
52 comment_start();
53
54 net->authentication_required = true;
55
56 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
57 lu_result_sent = RES_NONE;
58 gsup_expect_tx("08010809710000004026f0");
59 ms_sends_msg("050802008168000130089910070000006402");
60 OSMO_ASSERT(gsup_tx_confirmed);
61 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
62
63 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
64 auth_request_sent = false;
65 gsup_rx("09" "010809710000004026f0" "020111", NULL);
66 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
67 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
68
69 EXPECT_CONN_COUNT(0);
70 clear_vlr();
71 comment_end();
72}
73
74void test_hlr_rej_auth_info_net_fail_no_reuse_tuples()
75{
76 struct vlr_subscr *vsub;
77 const char *imsi = "901700000004620";
78
79 comment_start();
80
81 net->authentication_required = true;
82 net->vlr->cfg.auth_reuse_old_sets_on_error = false;
83 net->vlr->cfg.auth_tuple_max_use_count = 0;
84
85 BTW("Submit a used auth tuple in the VLR");
86 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
87 lu_result_sent = RES_NONE;
88 gsup_expect_tx("08010809710000004026f0");
89 ms_sends_msg("050802008168000130089910070000006402");
90 OSMO_ASSERT(gsup_tx_confirmed);
91 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
92
93 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
94 auth_request_sent = false;
95 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
96 auth_request_expect_autn = NULL;
97 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
98 gsup_rx("0a"
99 /* imsi */
100 "0108" "09710000004026f0"
101 /* auth vectors... */
102 /* TL TL rand */
103 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
104 /* TL sres TL kc */
105 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
106 ,NULL);
107 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
108 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
109
110 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
111 gsup_expect_tx("04010809710000004026f0");
112 ms_sends_msg("05542d8b2c3e");
113 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
114
115 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
116 gsup_rx("10010809710000004026f00804036470f1",
117 "12010809710000004026f0");
118 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
119
120 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
121 gsup_rx("06010809710000004026f0", NULL);
122
123 btw("LU was successful, and the conn has already been closed");
124 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
125 EXPECT_CONN_COUNT(0);
126
127
128 BTW("Now one auth tuple is available, but used.");
129 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
130 OSMO_ASSERT(vsub);
131 OSMO_ASSERT(vsub->last_tuple);
132 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
133 /* no need to look at all auth tuples, the ongoing test would take an
134 * unexpected course if there were more. */
135 vlr_subscr_put(vsub);
136
137 BTW("Another LU wants to get new tuples; HLR sends Network Failure, we reject.");
138
139 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
140 lu_result_sent = RES_NONE;
141 gsup_expect_tx("08010809710000004026f0");
142 ms_sends_msg("050802008168000130089910070000006402");
143 OSMO_ASSERT(gsup_tx_confirmed);
144 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
145
146 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
147 auth_request_sent = false;
148 gsup_rx("09" "010809710000004026f0" "020111", NULL);
149 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
150 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
151
152 EXPECT_CONN_COUNT(0);
153 clear_vlr();
154 comment_end();
155}
156
157void test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples()
158{
159 struct vlr_subscr *vsub;
160 const char *imsi = "901700000004620";
161
162 comment_start();
163
164 net->authentication_required = true;
165 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
166 net->vlr->cfg.auth_tuple_max_use_count = 0;
167
168 BTW("Submit a used auth tuple in the VLR");
169 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
170 lu_result_sent = RES_NONE;
171 gsup_expect_tx("08010809710000004026f0");
172 ms_sends_msg("050802008168000130089910070000006402");
173 OSMO_ASSERT(gsup_tx_confirmed);
174 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
175
176 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
177 auth_request_sent = false;
178 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
179 auth_request_expect_autn = NULL;
180 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
181 gsup_rx("0a"
182 /* imsi */
183 "0108" "09710000004026f0"
184 /* auth vectors... */
185 /* TL TL rand */
186 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
187 /* TL sres TL kc */
188 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
189 ,NULL);
190 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
191 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
192
193 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
194 gsup_expect_tx("04010809710000004026f0");
195 ms_sends_msg("05542d8b2c3e");
196 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
197
198 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
199 gsup_rx("10010809710000004026f00804036470f1",
200 "12010809710000004026f0");
201 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
202
203 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
204 gsup_rx("06010809710000004026f0", NULL);
205
206 btw("LU was successful, and the conn has already been closed");
207 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
208 EXPECT_CONN_COUNT(0);
209
210
211 BTW("Now one auth tuple is available, but used.");
212 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
213 OSMO_ASSERT(vsub);
214 OSMO_ASSERT(vsub->last_tuple);
215 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
216 /* no need to look at all auth tuples, the ongoing test would take an
217 * unexpected course if there were more. */
218 vlr_subscr_put(vsub);
219
220 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.");
221 VERBOSE_ASSERT(net->vlr->cfg.auth_reuse_old_sets_on_error, == true, "%d");
222
223 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
224 lu_result_sent = RES_NONE;
225 gsup_expect_tx("08010809710000004026f0");
226 ms_sends_msg("050802008168000130089910070000006402");
227 OSMO_ASSERT(gsup_tx_confirmed);
228 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
229
230 btw("HLR sends _SEND_AUTH_INFO_ERROR = unknown IMSI");
231 auth_request_sent = false;
232 gsup_rx("09" "010809710000004026f0" "020102", NULL);
233 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
234 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
235
236 EXPECT_CONN_COUNT(0);
237 clear_vlr();
238 comment_end();
239}
240
241void test_hlr_acc_but_no_auth_tuples()
242{
243 comment_start();
244
245 net->authentication_required = true;
246 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
247 net->vlr->cfg.auth_tuple_max_use_count = 0;
248
249 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
250 lu_result_sent = RES_NONE;
251 gsup_expect_tx("08010809710000004026f0");
252 ms_sends_msg("050802008168000130089910070000006402");
253 OSMO_ASSERT(gsup_tx_confirmed);
254 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
255
256 btw("from HLR, rx _SEND_AUTH_INFO_RESULT but it lacks auth tuples");
257 auth_request_sent = false;
258 gsup_rx("0a"
259 /* imsi */
260 "0108" "09710000004026f0"
261 /* NO auth vectors */
262 ,NULL);
263 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
264 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
265
266 EXPECT_CONN_COUNT(0);
267 clear_vlr();
268 comment_end();
269}
270
271void test_hlr_rej_auth_info_net_fail_reuse_tuples()
272{
273 struct vlr_subscr *vsub;
274 const char *imsi = "901700000004620";
275
276 comment_start();
277
278 net->authentication_required = true;
279 net->vlr->cfg.auth_reuse_old_sets_on_error = true;
280 net->vlr->cfg.auth_tuple_max_use_count = 0;
281
282 BTW("Submit a used auth tuple in the VLR");
283 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
284 lu_result_sent = RES_NONE;
285 gsup_expect_tx("08010809710000004026f0");
286 ms_sends_msg("050802008168000130089910070000006402");
287 OSMO_ASSERT(gsup_tx_confirmed);
288 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
289
290 btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS");
291 auth_request_sent = false;
292 auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b";
293 auth_request_expect_autn = NULL;
294 /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */
295 gsup_rx("0a"
296 /* imsi */
297 "0108" "09710000004026f0"
298 /* auth vectors... */
299 /* TL TL rand */
300 "0322" "2010" "585df1ae287f6e273dce07090d61320b"
301 /* TL sres TL kc */
302 "2104" "2d8b2c3e" "2208" "61855fb81fc2a800"
303 ,NULL);
304 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
305 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
306
307 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
308 gsup_expect_tx("04010809710000004026f0");
309 ms_sends_msg("05542d8b2c3e");
310 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
311
312 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
313 gsup_rx("10010809710000004026f00804036470f1",
314 "12010809710000004026f0");
315 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
316
317 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
318 gsup_rx("06010809710000004026f0", NULL);
319
320 btw("LU was successful, and the conn has already been closed");
321 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
322 EXPECT_CONN_COUNT(0);
323
324
325 BTW("Now one auth tuple is available, but used.");
326 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
327 OSMO_ASSERT(vsub);
328 OSMO_ASSERT(vsub->last_tuple);
329 VERBOSE_ASSERT(vsub->last_tuple->use_count, == 1, "%d");
330 /* no need to look at all auth tuples, the ongoing test would take an
331 * unexpected course if there were more. */
332 vlr_subscr_put(vsub);
333
334 BTW("Another LU wants to get new tuples; even though HLR sends Network Failure, we are reusing the old tuples.");
335
336 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
337 lu_result_sent = RES_NONE;
338 gsup_expect_tx("08010809710000004026f0");
339 ms_sends_msg("050802008168000130089910070000006402");
340 OSMO_ASSERT(gsup_tx_confirmed);
341 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
342
343 btw("HLR sends _SEND_AUTH_INFO_ERROR = net fail");
344 auth_request_sent = false;
345 gsup_rx("09" "010809710000004026f0" "020111", NULL);
346 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
347 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
348
349 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
350 gsup_expect_tx("04010809710000004026f0");
351 ms_sends_msg("05542d8b2c3e");
352 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
353
354 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
355 gsup_rx("10010809710000004026f00804036470f1",
356 "12010809710000004026f0");
357 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
358
359 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
360 gsup_rx("06010809710000004026f0", NULL);
361
362 btw("LU was successful, and the conn has already been closed");
363 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
364 EXPECT_CONN_COUNT(0);
365
366 clear_vlr();
367 comment_end();
368}
369
370void test_hlr_rej_lu()
371{
372 comment_start();
373
374 btw("Location Update request causes a GSUP LU request to HLR");
375 lu_result_sent = RES_NONE;
376 gsup_expect_tx("04010809710000004026f0");
377 ms_sends_msg("050802008168000130089910070000006402");
378 OSMO_ASSERT(gsup_tx_confirmed);
379 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
380
381 btw("HLR sends UPDATE_LOCATION_ERROR");
382 gsup_rx("05" "010809710000004026f0" "020102",
383 NULL);
384 VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d");
385 EXPECT_CONN_COUNT(0);
386
387 clear_vlr();
388 comment_end();
389}
390
391void test_hlr_no_insert_data()
392{
393 comment_start();
394
395 btw("Location Update request causes a GSUP LU request to HLR");
396 lu_result_sent = RES_NONE;
397 gsup_expect_tx("04010809710000004026f0");
398 ms_sends_msg("050802008168000130089910070000006402");
399 OSMO_ASSERT(gsup_tx_confirmed);
400 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
401
402 btw("HLR sends only _UPDATE_LOCATION_RESULT, no INSERT DATA");
403 gsup_rx("06010809710000004026f0", NULL);
404
405 /* TODO should we wait for OSMO_GSUP_MSGT_INSERT_DATA_REQUEST? */
406
407 btw("LU was successful, and the conn has already been closed");
408 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
409
410 EXPECT_CONN_COUNT(0);
411 clear_vlr();
412 comment_end();
413}
414
415msc_vlr_test_func_t msc_vlr_tests[] = {
416 test_hlr_rej_auth_info_unknown_imsi,
417 test_hlr_rej_auth_info_net_fail,
418 test_hlr_rej_auth_info_net_fail_reuse_tuples,
419 test_hlr_rej_auth_info_net_fail_no_reuse_tuples,
420 test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples,
421 test_hlr_acc_but_no_auth_tuples,
422 test_hlr_rej_lu,
423 test_hlr_no_insert_data,
424 NULL
425};