blob: 09725843b0a2d3a9d0db820714134cdbc2afa31e [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;
47 gsup_expect_tx("080108" "09710000000156f0");
48 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 */
82 "2708" "e229c19e791f2e41",
83 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 Hofmeyrd0756b12018-09-28 02:41:39 +020089 gsup_expect_tx("04010809710000000156f0280102");
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 Hofmeyrd0756b12018-09-28 02:41:39 +0200102 gsup_expect_tx("04010809710000000156f0280102");
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");
109 gsup_rx("10010809710000000156f00804032443f2",
110 "12010809710000000156f0");
111 VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d");
112
113 btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT");
114 gsup_rx("06010809710000000156f0", NULL);
115
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");
124 vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100);
125 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");
129 vlr_subscr_put(vsub);
130
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 Hofmeyr4068ab22018-04-01 20:55:54 +0200135 bss_rnc_sends_release_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);
144 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
145 OSMO_ASSERT(vsub);
146 OSMO_ASSERT(vsub->last_tuple);
147 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
148 vlr_subscr_put(vsub);
149
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;
154 ms_sends_msg("052478"
155 "03575886" /* classmark 2 */
156 "089910070000106005" /* IMSI */);
157 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200158 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100159 OSMO_ASSERT(g_conn->vsub);
160 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
161 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
162
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100163 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100164 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
165 gsup_expect_tx(NULL);
166 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
167 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
168 } else {
169 /* On UTRAN */
170 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100171 expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100172 ms_sends_msg("0554" "e229c19e" "2104" "791f2e41");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100173 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100174 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
175
176 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
177 ms_sends_security_mode_complete();
178 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
179 }
180
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700181 /* Release connection */
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100182 expect_release_clear(via_ran);
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700183 conn_conclude_cm_service_req(g_conn, via_ran);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200184 bss_rnc_sends_release_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100185
186 btw("all requests serviced, conn has been released");
187 EXPECT_CONN_COUNT(0);
188 }
189
190 if (final_request_with_hlr) {
191 BTW("Now the auth tuple has use_count == %d, as much as is allowed.", expected_use_count);
192 vsub = vlr_subscr_find_by_imsi(net->vlr, imsi);
193 OSMO_ASSERT(vsub);
194 OSMO_ASSERT(vsub->last_tuple);
195 VERBOSE_ASSERT(vsub->last_tuple->use_count, == expected_use_count, "%d");
196 vlr_subscr_put(vsub);
197
198 BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req,"
199 " and needs to request a second auth vector from HLR");
200 auth_request_sent = false;
201 cm_service_result_sent = RES_NONE;
202 gsup_expect_tx("080108" "09710000000156f0");
203 ms_sends_msg("052478"
204 "03575886" /* classmark 2 */
205 "089910070000106005" /* IMSI */);
206 OSMO_ASSERT(g_conn);
Neels Hofmeyr4d3a66b2018-03-31 18:45:59 +0200207 OSMO_ASSERT(g_conn->fi);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100208 OSMO_ASSERT(g_conn->vsub);
209 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
210 VERBOSE_ASSERT(auth_request_sent, == false, "%d");
211 VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d");
212
213 btw("from HLR, rx _SEND_AUTH_INFO_RESULT, second tuple; VLR sends Auth Req to MS");
214 auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d";
215 auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9";
216 gsup_rx("0a"
217 /* imsi */
218 "0108" "09710000000156f0"
219 /* TL TL rand */
220 /* TL sres TL kc */
221 /* TL 3G IK */
222 /* TL 3G CK */
223 /* TL AUTN */
224 /* TL RES */
225 "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d"
226 "2104" "85aa3130" "2208" "d3d50a000bf04f6e"
227 "2310" "1159ec926a50e98c034a6b7d7c9f418d"
228 "2410" "df3a03d9ca5335641efc8e36d76cd20b"
229 "2510" "1843a645b98d00005b2d666af46c45d9"
230 "2708" "7db47cf7f81e4dc7",
231 NULL);
232 VERBOSE_ASSERT(auth_request_sent, == true, "%d");
233 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
234
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100235 if (via_ran == OSMO_RAT_GERAN_A) {
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100236 btw("MS sends Authen Response, VLR accepts with a CM Service Accept");
237 gsup_expect_tx(NULL);
238 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
239 VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d");
240 } else {
241 /* On UTRAN */
242 btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl");
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100243 expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100244 ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +0100245 VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d");
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100246 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
247
248 btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept");
249 ms_sends_security_mode_complete();
250 VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d");
251 }
252
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700253 /* Release connection */
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100254 expect_release_clear(via_ran);
Vadim Yanitskiy27605852018-06-15 23:57:30 +0700255 conn_conclude_cm_service_req(g_conn, via_ran);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200256 bss_rnc_sends_release_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100257
258 btw("all requests serviced, conn has been released");
259 EXPECT_CONN_COUNT(0);
260 }
261
262 BTW("subscriber detaches");
263 expect_release_clear(via_ran);
264 ms_sends_msg("050130"
265 "089910070000106005" /* IMSI */);
266 ASSERT_RELEASE_CLEAR(via_ran);
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200267 bss_rnc_sends_release_clear_complete(via_ran);
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100268
269 EXPECT_CONN_COUNT(0);
270 clear_vlr();
271}
272
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100273static void test_auth_use_twice_geran()
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_GERAN_A, 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_twice_utran()
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_UTRAN_IU, 1, 1, true);
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_geran()
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_GERAN_A, -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_auth_use_infinitely_utran()
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_UTRAN_IU, -1, 3, false);
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_geran()
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_GERAN_A, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100305 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100306}
307
Neels Hofmeyrf3d81f62018-03-02 01:05:38 +0100308static void test_no_auth_reuse_utran()
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100309{
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100310 comment_start();
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100311 _test_auth_reuse(OSMO_RAT_UTRAN_IU, 0, 0, true);
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100312 comment_end();
Neels Hofmeyr7b1418e2017-10-29 02:12:16 +0100313}
314
315msc_vlr_test_func_t msc_vlr_tests[] = {
316 test_auth_use_twice_geran,
317 test_auth_use_twice_utran,
318 test_auth_use_infinitely_geran,
319 test_auth_use_infinitely_utran,
320 test_no_auth_reuse_geran,
321 test_no_auth_reuse_utran,
322 NULL
323};