blob: 9eadec7f98819c8e8ee6e954de33457c0ad06c7e [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"
Harald Welte0df904d2018-12-03 11:00:04 +010027#include "stubs.h"
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010028
Neels Hofmeyr7814a832018-12-26 00:40:18 +010029static void _test_auth_reuse(enum osmo_rat_type via_ran,
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +010030 int set_max_reuse_count,
31 int loop_requests_without_hlr,
32 bool final_request_with_hlr)
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010033{
34 struct vlr_subscr *vsub;
35 const char *imsi = "901700000010650";
36 int expected_use_count;
37 int i;
38
39 net->authentication_required = true;
40 net->vlr->cfg.assign_tmsi = true;
41 net->vlr->cfg.auth_tuple_max_reuse_count = set_max_reuse_count;
42 net->vlr->cfg.auth_reuse_old_sets_on_error = false;
43 rx_from_ran = via_ran;
44
45 btw("Location Update request causes a GSUP Send Auth Info request to HLR");
46 lu_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010047 gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010048 ms_sends_msg("0508" /* MM LU */
49 "7" /* ciph key seq: no key available */
50 "0" /* LU type: normal */
51 "ffffff" "0000" /* LAI, LAC */
52 "57" /* classmark 1: R99, early classmark, no power lvl */
53 "089910070000106005" /* IMSI */
54 "3303575886" /* classmark 2 */
55 );
56 OSMO_ASSERT(gsup_tx_confirmed);
57 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
58
59 btw("from HLR, rx _SEND_AUTH_INFO_RESULT, only one tuple; VLR sends Auth Req to MS");
60 /* based on auc_3g:
61 * K = 'EB215756028D60E3275E613320AEC880',
62 * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308'
63 * SQN = 0
64 */
65 auth_request_sent = false;
66 auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d";
67 auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919";
68 gsup_rx("0a"
69 /* imsi */
70 "0108" "09710000000156f0"
71 /* TL TL rand */
72 "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d"
73 /* TL sres TL kc */
74 "2104" "9b36efdf" "2208" "059a4f668f6fbe39"
75 /* TL 3G IK */
76 "2310" "27497388b6cb044648f396aa155b95ef"
77 /* TL 3G CK */
78 "2410" "f64735036e5871319c679f4742a75ea1"
79 /* TL AUTN */
80 "2510" "8704f5ba55f30000d2ee44b22c8ea919"
81 /* TL RES */
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010082 "2708" "e229c19e791f2e41" HLR_TO_VLR,
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010083 NULL);
84 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
85 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
86
Neels Hofmeyr7814a832018-12-26 00:40:18 +010087 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010088 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010089 gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010090 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
91 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
92 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
93 } else {
94 /* On UTRAN */
95 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010096 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010097 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010098 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +010099 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
100
101 btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100102 gsup_expect_tx("04010809710000000156f0280102" VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100103 ms_sends_security_mode_complete();
104 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
105 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
106 }
107
108 btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100109 gsup_rx("10010809710000000156f00804032443f2" HLR_TO_VLR,
110 "12010809710000000156f0" VLR_TO_HLR);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100111 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
112
113 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100114 gsup_rx("06010809710000000156f0" HLR_TO_VLR, NULL);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100115
116 VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d");
117
118 btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl");
119 EXPECT_CONN_COUNT(1);
120 EXPECT_ACCEPTED(false);
121 thwart_rx_non_initial_requests();
122
123 btw("even though the TMSI is not acked, we can already find the subscr with it");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100124 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100125 VERBOSE_ASSERT(vsub != NULL, == true, "%d");
126 VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d");
127 VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x");
128 VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100129 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100130
131 btw("MS sends TMSI Realloc Complete");
132 expect_release_clear(via_ran);
133 ms_sends_msg("055b");
134 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100135 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100136
137 btw("LU was successful, and the conn has already been closed");
138 EXPECT_CONN_COUNT(0);
139
140 expected_use_count = 1;
141
142 for (i = 0; i < loop_requests_without_hlr; i++, expected_use_count++) {
143 BTW("Now the auth tuple has use_count == %d", expected_use_count);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100144 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100145 OSMO_ASSERT(vsub);
146 OSMO_ASSERT(vsub->last_tuple);
147 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100148 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100149
150 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req,"
151 " and reuses old auth vector");
152 auth_request_sent = true;
153 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100154 ms_sends_msg("052474"
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100155 "03575886" /* classmark 2 */
156 "089910070000106005" /* IMSI */);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100157 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
158 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
159
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100160 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100161 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
162 gsup_expect_tx(NULL);
163 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
164 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
165 } else {
166 /* On UTRAN */
167 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100168 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100169 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100170 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100171 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
172
173 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
174 ms_sends_security_mode_complete();
175 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
176 }
177
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700178 /* Release connection */
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100179 expect_release_clear(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100180 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
181 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100182
183 btw("all requests serviced, conn has been released");
184 EXPECT_CONN_COUNT(0);
185 }
186
187 if (final_request_with_hlr) {
188 BTW("Now the auth tuple has use_count == %d, as much as is allowed.", expected_use_count);
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100189 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100190 OSMO_ASSERT(vsub);
191 OSMO_ASSERT(vsub->last_tuple);
192 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +0100193 vlr_subscr_put(vsub, __func__);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100194
195 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req,"
196 " and needs to request a second auth vector from HLR");
197 auth_request_sent = false;
198 cm_service_result_sent = RES_NONE;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100199 gsup_expect_tx("080108" "09710000000156f0" VLR_TO_HLR);
200 ms_sends_msg("052474"
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100201 "03575886" /* classmark 2 */
202 "089910070000106005" /* IMSI */);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100203 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
204 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
205 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
206
207 btw("from HLR, rx _SEND_AUTH_INFO_RESULT, second tuple; VLR sends Auth Req to MS");
208 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
209 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
210 gsup_rx("0a"
211 /* imsi */
212 "0108" "09710000000156f0"
213 /* TL TL rand */
214 /* TL sres TL kc */
215 /* TL 3G IK */
216 /* TL 3G CK */
217 /* TL AUTN */
218 /* TL RES */
219 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
220 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
221 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
222 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
223 "2510" "1843a645b98d00005b2d666af46c45d9"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100224 "2708" "7db47cf7f81e4dc7" HLR_TO_VLR,
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100225 NULL);
226 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
227 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
228
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100229 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100230 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
231 gsup_expect_tx(NULL);
232 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
233 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
234 } else {
235 /* On UTRAN */
236 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100237 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100238 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100239 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100240 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
241
242 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
243 ms_sends_security_mode_complete();
244 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
245 }
246
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700247 /* Release connection */
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100248 expect_release_clear(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100249 conn_conclude_cm_service_req(g_msub, MSC_A_USE_CM_SERVICE_SMS);
250 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100251
252 btw("all requests serviced, conn has been released");
253 EXPECT_CONN_COUNT(0);
254 }
255
256 BTW("subscriber detaches");
257 expect_release_clear(via_ran);
258 ms_sends_msg("050130"
259 "089910070000106005" /* IMSI */);
260 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100261 ran_sends_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100262
263 EXPECT_CONN_COUNT(0);
264 clear_vlr();
265}
266
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100267static void test_auth_use_twice_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100268{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100269 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100270 _test_auth_reuse(OSMO_RAT_GERAN_A, 1, 1, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100271 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100272}
273
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100274static void test_auth_use_twice_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100275{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100276 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100277 _test_auth_reuse(OSMO_RAT_UTRAN_IU, 1, 1, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100278 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100279}
280
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100281static void test_auth_use_infinitely_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100282{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100283 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100284 _test_auth_reuse(OSMO_RAT_GERAN_A, -1, 3, false);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100285 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100286}
287
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100288static void test_auth_use_infinitely_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100289{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100290 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100291 _test_auth_reuse(OSMO_RAT_UTRAN_IU, -1, 3, false);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100292 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100293}
294
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100295static void test_no_auth_reuse_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100296{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100297 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100298 _test_auth_reuse(OSMO_RAT_GERAN_A, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100299 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100300}
301
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100302static void test_no_auth_reuse_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100303{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100304 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100305 _test_auth_reuse(OSMO_RAT_UTRAN_IU, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100306 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100307}
308
309msc_vlr_test_func_t msc_vlr_tests[] = {
310 test_auth_use_twice_geran,
311 test_auth_use_twice_utran,
312 test_auth_use_infinitely_geran,
313 test_auth_use_infinitely_utran,
314 test_no_auth_reuse_geran,
315 test_no_auth_reuse_utran,
316 NULL
317};