blob: 389837ad68ff0034bc2981d8aec877d4186c4805 [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 Hofmeyrf3d81f62018-03-02 01:05:38 +010028static void _test_auth_reuse(enum ran_type via_ran,
29 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;
46 gsup_expect_tx("080108" "09710000000156f0");
47 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 */
81 "2708" "e229c19e791f2e41",
82 NULL);
83 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
84 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
85
86 if (via_ran == RAN_GERAN_A) {
87 btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR");
88 gsup_expect_tx("04010809710000000156f0");
89 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");
101 gsup_expect_tx("04010809710000000156f0");
102 ms_sends_security_mode_complete();
103 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");
108 gsup_rx("10010809710000000156f00804032443f2",
109 "12010809710000000156f0");
110 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
111
112 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
113 gsup_rx("06010809710000000156f0", NULL);
114
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");
123 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
124 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");
128 vlr_subscr_put(vsub);
129
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 Hofmeyr4068ab22018-04-01 20:55:54 +0200134 bss_rnc_sends_release_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);
143 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
144 OSMO_ASSERT(vsub);
145 OSMO_ASSERT(vsub->last_tuple);
146 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
147 vlr_subscr_put(vsub);
148
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;
153 ms_sends_msg("052478"
154 "03575886" /* classmark 2 */
155 "089910070000106005" /* IMSI */);
156 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200157 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100158 OSMO_ASSERT(g_conn->vsub);
159 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
160 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
161
162 if (via_ran == RAN_GERAN_A) {
163 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
164 gsup_expect_tx(NULL);
165 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
166 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
167 } else {
168 /* On UTRAN */
169 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100170 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100171 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100172 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100173 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
174
175 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
176 ms_sends_security_mode_complete();
177 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
178 }
179
180 btw("a USSD request is serviced");
181 dtap_expect_tx_ussd("Your extension is 42342\r");
182 expect_release_clear(via_ran);
183 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
184 OSMO_ASSERT(dtap_tx_confirmed);
185 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200186 bss_rnc_sends_release_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100187
188 btw("all requests serviced, conn has been released");
189 EXPECT_CONN_COUNT(0);
190 }
191
192 if (final_request_with_hlr) {
193 BTW("Now the auth tuple has use_count == %d, as much as is allowed.", expected_use_count);
194 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
195 OSMO_ASSERT(vsub);
196 OSMO_ASSERT(vsub->last_tuple);
197 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
198 vlr_subscr_put(vsub);
199
200 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req,"
201 " and needs to request a second auth vector from HLR");
202 auth_request_sent = false;
203 cm_service_result_sent = RES_NONE;
204 gsup_expect_tx("080108" "09710000000156f0");
205 ms_sends_msg("052478"
206 "03575886" /* classmark 2 */
207 "089910070000106005" /* IMSI */);
208 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200209 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100210 OSMO_ASSERT(g_conn->vsub);
211 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
212 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
213 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
214
215 btw("from HLR, rx _SEND_AUTH_INFO_RESULT, second tuple; VLR sends Auth Req to MS");
216 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
217 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
218 gsup_rx("0a"
219 /* imsi */
220 "0108" "09710000000156f0"
221 /* TL TL rand */
222 /* TL sres TL kc */
223 /* TL 3G IK */
224 /* TL 3G CK */
225 /* TL AUTN */
226 /* TL RES */
227 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
228 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
229 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
230 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
231 "2510" "1843a645b98d00005b2d666af46c45d9"
232 "2708" "7db47cf7f81e4dc7",
233 NULL);
234 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
235 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
236
237 if (via_ran == RAN_GERAN_A) {
238 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
239 gsup_expect_tx(NULL);
240 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
241 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
242 } else {
243 /* On UTRAN */
244 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100245 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100246 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100247 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100248 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
249
250 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
251 ms_sends_security_mode_complete();
252 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
253 }
254
255 btw("a USSD request is serviced");
256 dtap_expect_tx_ussd("Your extension is 42342\r");
257 expect_release_clear(via_ran);
258 ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100");
259 OSMO_ASSERT(dtap_tx_confirmed);
260 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200261 bss_rnc_sends_release_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100262
263 btw("all requests serviced, conn has been released");
264 EXPECT_CONN_COUNT(0);
265 }
266
267 BTW("subscriber detaches");
268 expect_release_clear(via_ran);
269 ms_sends_msg("050130"
270 "089910070000106005" /* IMSI */);
271 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200272 bss_rnc_sends_release_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100273
274 EXPECT_CONN_COUNT(0);
275 clear_vlr();
276}
277
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100278static void test_auth_use_twice_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100279{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100280 comment_start();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100281 _test_auth_reuse(RAN_GERAN_A, 1, 1, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100282 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100283}
284
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100285static void test_auth_use_twice_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100286{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100287 comment_start();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100288 _test_auth_reuse(RAN_UTRAN_IU, 1, 1, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100289 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100290}
291
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100292static void test_auth_use_infinitely_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100293{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100294 comment_start();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100295 _test_auth_reuse(RAN_GERAN_A, -1, 3, false);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100296 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100297}
298
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100299static void test_auth_use_infinitely_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100300{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100301 comment_start();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100302 _test_auth_reuse(RAN_UTRAN_IU, -1, 3, false);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100303 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100304}
305
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100306static void test_no_auth_reuse_geran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100307{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100308 comment_start();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100309 _test_auth_reuse(RAN_GERAN_A, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100310 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100311}
312
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100313static void test_no_auth_reuse_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100314{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100315 comment_start();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100316 _test_auth_reuse(RAN_UTRAN_IU, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100317 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100318}
319
320msc_vlr_test_func_t msc_vlr_tests[] = {
321 test_auth_use_twice_geran,
322 test_auth_use_twice_utran,
323 test_auth_use_infinitely_geran,
324 test_auth_use_infinitely_utran,
325 test_no_auth_reuse_geran,
326 test_no_auth_reuse_utran,
327 NULL
328};