Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1 | /* 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 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 26 | void test_gsm_authen() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 27 | { |
| 28 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 29 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 30 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 31 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 32 | |
| 33 | net->authentication_required = true; |
| 34 | |
| 35 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 36 | lu_result_sent = RES_NONE; |
| 37 | gsup_expect_tx("08010809710000004026f0"); |
| 38 | ms_sends_msg("050802008168000130089910070000006402"); |
| 39 | OSMO_ASSERT(gsup_tx_confirmed); |
| 40 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 41 | |
| 42 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 43 | auth_request_sent = false; |
| 44 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 45 | auth_request_expect_autn = NULL; |
| 46 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 47 | gsup_rx("0a" |
| 48 | /* imsi */ |
| 49 | "0108" "09710000004026f0" |
| 50 | /* 5 auth vectors... */ |
| 51 | /* TL TL rand */ |
| 52 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 53 | /* TL sres TL kc */ |
| 54 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 55 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 56 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 57 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 58 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 59 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 60 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 61 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 62 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 63 | NULL); |
| 64 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 65 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 66 | |
| 67 | btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject"); |
| 68 | gsup_rx("06010809710000004026f0", NULL); |
| 69 | EXPECT_ACCEPTED(false); |
| 70 | |
| 71 | thwart_rx_non_initial_requests(); |
| 72 | |
| 73 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 74 | |
| 75 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 76 | gsup_expect_tx("04010809710000004026f0"); |
| 77 | ms_sends_msg("05542d8b2c3e"); |
| 78 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 79 | |
| 80 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 81 | gsup_rx("10010809710000004026f00804036470f1", |
| 82 | "12010809710000004026f0"); |
| 83 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 84 | |
| 85 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 86 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 87 | gsup_rx("06010809710000004026f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 88 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 89 | |
| 90 | btw("LU was successful, and the conn has already been closed"); |
| 91 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 92 | EXPECT_CONN_COUNT(0); |
| 93 | |
| 94 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 95 | auth_request_sent = false; |
| 96 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 97 | cm_service_result_sent = RES_NONE; |
| 98 | ms_sends_msg("05247803305886089910070000006402"); |
| 99 | OSMO_ASSERT(g_conn); |
| 100 | OSMO_ASSERT(g_conn->conn_fsm); |
| 101 | OSMO_ASSERT(g_conn->vsub); |
| 102 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 103 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 104 | |
| 105 | btw("needs auth, not yet accepted"); |
| 106 | EXPECT_ACCEPTED(false); |
| 107 | thwart_rx_non_initial_requests(); |
| 108 | |
| 109 | btw("MS sends Authen Response, VLR accepts with a CM Service Accept"); |
| 110 | gsup_expect_tx(NULL); |
| 111 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 112 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 113 | |
| 114 | btw("a USSD request is serviced"); |
| 115 | dtap_expect_tx_ussd("Your extension is 46071\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 116 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 117 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
| 118 | OSMO_ASSERT(dtap_tx_confirmed); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 119 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 120 | |
| 121 | btw("all requests serviced, conn has been released"); |
| 122 | EXPECT_CONN_COUNT(0); |
| 123 | |
| 124 | BTW("an SMS is sent, MS is paged"); |
| 125 | paging_expect_imsi(imsi); |
| 126 | paging_sent = false; |
| 127 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 128 | OSMO_ASSERT(vsub); |
| 129 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 130 | |
| 131 | send_sms(vsub, vsub, |
| 132 | "Privacy in residential applications is a desirable" |
| 133 | " marketing option."); |
| 134 | |
| 135 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 136 | vlr_subscr_put(vsub); |
| 137 | vsub = NULL; |
| 138 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 139 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 140 | |
| 141 | btw("the subscriber and its pending request should remain"); |
| 142 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 143 | OSMO_ASSERT(vsub); |
| 144 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 145 | vlr_subscr_put(vsub); |
| 146 | |
| 147 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 148 | auth_request_sent = false; |
| 149 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 150 | ms_sends_msg("06270703305882089910070000006402"); |
| 151 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 152 | |
| 153 | btw("needs auth, not yet accepted"); |
| 154 | EXPECT_ACCEPTED(false); |
| 155 | thwart_rx_non_initial_requests(); |
| 156 | |
| 157 | btw("MS sends Authen Response, VLR accepts and sends pending SMS"); |
| 158 | dtap_expect_tx("09" /* SMS messages */ |
| 159 | "01" /* CP-DATA */ |
| 160 | "58" /* length */ |
| 161 | "01" /* Network to MS */ |
| 162 | "00" /* reference */ |
| 163 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 164 | "0791" "447758100650" /* 447785016005 */ |
| 165 | "00" /* dest */ |
| 166 | /* SMS TPDU */ |
| 167 | "4c" /* len */ |
| 168 | "00" /* SMS deliver */ |
| 169 | "05806470f1" /* originating address 46071 */ |
| 170 | "00" /* TP-PID */ |
| 171 | "00" /* GSM default alphabet */ |
| 172 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 173 | "000000" /* H-M-S */ |
| 174 | "00" /* GMT+0 */ |
| 175 | "44" /* data length */ |
| 176 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 177 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 178 | "0c7ac3e9e9b7db05"); |
| 179 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 180 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 181 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 182 | |
| 183 | btw("SMS was delivered, no requests pending for subscr"); |
| 184 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 185 | OSMO_ASSERT(vsub); |
| 186 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 187 | vlr_subscr_put(vsub); |
| 188 | |
| 189 | btw("conn is still open to wait for SMS ack dance"); |
| 190 | EXPECT_CONN_COUNT(1); |
| 191 | |
| 192 | btw("MS replies with CP-ACK for received SMS"); |
| 193 | ms_sends_msg("8904"); |
| 194 | EXPECT_CONN_COUNT(1); |
| 195 | |
| 196 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 197 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 198 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 199 | ms_sends_msg("890106020041020000"); |
| 200 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 201 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 202 | |
| 203 | btw("SMS is done, conn is gone"); |
| 204 | EXPECT_CONN_COUNT(0); |
| 205 | |
| 206 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 207 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 208 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 209 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 210 | |
| 211 | EXPECT_CONN_COUNT(0); |
| 212 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 213 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 216 | void test_gsm_authen_tmsi() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 217 | { |
| 218 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 219 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 220 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 221 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 222 | |
| 223 | net->authentication_required = true; |
| 224 | net->vlr->cfg.assign_tmsi = true; |
| 225 | |
| 226 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 227 | lu_result_sent = RES_NONE; |
| 228 | gsup_expect_tx("08010809710000004026f0"); |
| 229 | ms_sends_msg("050802008168000130089910070000006402"); |
| 230 | OSMO_ASSERT(gsup_tx_confirmed); |
| 231 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 232 | |
| 233 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 234 | auth_request_sent = false; |
| 235 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 236 | auth_request_expect_autn = NULL; |
| 237 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 238 | gsup_rx("0a" |
| 239 | /* imsi */ |
| 240 | "0108" "09710000004026f0" |
| 241 | /* 5 auth vectors... */ |
| 242 | /* TL TL rand */ |
| 243 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 244 | /* TL sres TL kc */ |
| 245 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 246 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 247 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 248 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 249 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 250 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 251 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 252 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 253 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 254 | NULL); |
| 255 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 256 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 257 | |
| 258 | btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject"); |
| 259 | gsup_rx("06010809710000004026f0", NULL); |
| 260 | EXPECT_ACCEPTED(false); |
| 261 | |
| 262 | thwart_rx_non_initial_requests(); |
| 263 | |
| 264 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 265 | |
| 266 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 267 | gsup_expect_tx("04010809710000004026f0"); |
| 268 | ms_sends_msg("05542d8b2c3e"); |
| 269 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 270 | |
| 271 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 272 | gsup_rx("10010809710000004026f00804036470f1", |
| 273 | "12010809710000004026f0"); |
| 274 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 275 | |
| 276 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 277 | gsup_rx("06010809710000004026f0", NULL); |
| 278 | |
| 279 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 280 | EXPECT_CONN_COUNT(1); |
| 281 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 282 | EXPECT_ACCEPTED(false); |
| 283 | thwart_rx_non_initial_requests(); |
| 284 | |
| 285 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 286 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 287 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 288 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 289 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 290 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 291 | vlr_subscr_put(vsub); |
| 292 | |
| 293 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 294 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 295 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 296 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 297 | |
| 298 | btw("LU was successful, and the conn has already been closed"); |
| 299 | EXPECT_CONN_COUNT(0); |
| 300 | |
| 301 | btw("Subscriber has the new TMSI"); |
| 302 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 303 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 304 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 305 | VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x"); |
| 306 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 307 | vlr_subscr_put(vsub); |
| 308 | |
| 309 | BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector"); |
| 310 | auth_request_sent = false; |
| 311 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 312 | cm_service_result_sent = RES_NONE; |
| 313 | ms_sends_msg("05247803305886" "05f4" "03020100"); |
| 314 | OSMO_ASSERT(g_conn); |
| 315 | OSMO_ASSERT(g_conn->conn_fsm); |
| 316 | OSMO_ASSERT(g_conn->vsub); |
| 317 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 318 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 319 | |
| 320 | btw("needs auth, not yet accepted"); |
| 321 | EXPECT_ACCEPTED(false); |
| 322 | thwart_rx_non_initial_requests(); |
| 323 | |
| 324 | btw("MS sends Authen Response, VLR accepts with a CM Service Accept"); |
| 325 | gsup_expect_tx(NULL); |
| 326 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 327 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 328 | |
| 329 | btw("a USSD request is serviced"); |
| 330 | dtap_expect_tx_ussd("Your extension is 46071\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 331 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 332 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
| 333 | OSMO_ASSERT(dtap_tx_confirmed); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 334 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 335 | |
| 336 | btw("all requests serviced, conn has been released"); |
| 337 | EXPECT_CONN_COUNT(0); |
| 338 | |
| 339 | BTW("an SMS is sent, MS is paged"); |
| 340 | paging_expect_tmsi(0x03020100); |
| 341 | paging_sent = false; |
| 342 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 343 | OSMO_ASSERT(vsub); |
| 344 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 345 | |
| 346 | send_sms(vsub, vsub, |
| 347 | "Privacy in residential applications is a desirable" |
| 348 | " marketing option."); |
| 349 | |
| 350 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 351 | vlr_subscr_put(vsub); |
| 352 | vsub = NULL; |
| 353 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 354 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 355 | |
| 356 | btw("the subscriber and its pending request should remain"); |
| 357 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 358 | OSMO_ASSERT(vsub); |
| 359 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 360 | vlr_subscr_put(vsub); |
| 361 | |
| 362 | btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key"); |
| 363 | auth_request_sent = false; |
| 364 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 365 | ms_sends_msg("06270703305882" "05f4" "03020100"); |
| 366 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 367 | |
| 368 | btw("needs auth, not yet accepted"); |
| 369 | EXPECT_ACCEPTED(false); |
| 370 | thwart_rx_non_initial_requests(); |
| 371 | |
| 372 | btw("MS sends Authen Response, VLR accepts and sends pending SMS"); |
| 373 | dtap_expect_tx("09" /* SMS messages */ |
| 374 | "01" /* CP-DATA */ |
| 375 | "58" /* length */ |
| 376 | "01" /* Network to MS */ |
| 377 | "00" /* reference */ |
| 378 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 379 | "0791" "447758100650" /* 447785016005 */ |
| 380 | "00" /* dest */ |
| 381 | /* SMS TPDU */ |
| 382 | "4c" /* len */ |
| 383 | "00" /* SMS deliver */ |
| 384 | "05806470f1" /* originating address 46071 */ |
| 385 | "00" /* TP-PID */ |
| 386 | "00" /* GSM default alphabet */ |
| 387 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 388 | "000000" /* H-M-S */ |
| 389 | "00" /* GMT+0 */ |
| 390 | "44" /* data length */ |
| 391 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 392 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 393 | "0c7ac3e9e9b7db05"); |
| 394 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 395 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 396 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 397 | |
| 398 | btw("SMS was delivered, no requests pending for subscr"); |
| 399 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 400 | OSMO_ASSERT(vsub); |
| 401 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 402 | vlr_subscr_put(vsub); |
| 403 | |
| 404 | btw("conn is still open to wait for SMS ack dance"); |
| 405 | EXPECT_CONN_COUNT(1); |
| 406 | |
| 407 | btw("MS replies with CP-ACK for received SMS"); |
| 408 | ms_sends_msg("8904"); |
| 409 | EXPECT_CONN_COUNT(1); |
| 410 | |
| 411 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 412 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 413 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 414 | ms_sends_msg("890106020041020000"); |
| 415 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 416 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 417 | |
| 418 | btw("SMS is done, conn is gone"); |
| 419 | EXPECT_CONN_COUNT(0); |
| 420 | |
| 421 | /* TODO: when the subscriber detaches, the vlr_subscr gets |
| 422 | * deallocated and we no longer know the TMSI. This case is covered by |
| 423 | * test_lu_unknown_tmsi(), so here I'd like to still have the TMSI. |
| 424 | BTW("subscriber detaches, using TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 425 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 426 | ms_sends_msg("050130" "05f4" "03020100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 427 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 428 | EXPECT_CONN_COUNT(0); |
| 429 | */ |
| 430 | |
| 431 | BTW("subscriber sends LU Request, this time with the TMSI"); |
| 432 | btw("Location Update request causes an Auth Req to MS"); |
| 433 | lu_result_sent = RES_NONE; |
| 434 | auth_request_sent = false; |
| 435 | auth_request_expect_rand = "fa8f20b781b5881329d4fea26b1a3c51"; |
| 436 | ms_sends_msg("050802008168000130" "05f4" "03020100"); |
| 437 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 438 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 439 | |
| 440 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 441 | gsup_expect_tx("04010809710000004026f0"); |
| 442 | ms_sends_msg("05545afc8d72"); |
| 443 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 444 | |
| 445 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 446 | gsup_rx("10010809710000004026f00804036470f1", |
| 447 | "12010809710000004026f0"); |
| 448 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 449 | |
| 450 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 451 | gsup_rx("06010809710000004026f0", NULL); |
| 452 | |
| 453 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 454 | EXPECT_CONN_COUNT(1); |
| 455 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 456 | EXPECT_ACCEPTED(false); |
| 457 | thwart_rx_non_initial_requests(); |
| 458 | |
| 459 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 460 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504); |
| 461 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 462 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 463 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x07060504, "0x%08x"); |
| 464 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 465 | vlr_subscr_put(vsub); |
| 466 | |
| 467 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 468 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 469 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 470 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 471 | |
| 472 | btw("LU was successful, and the conn has already been closed"); |
| 473 | EXPECT_CONN_COUNT(0); |
| 474 | |
| 475 | btw("subscriber has the new TMSI"); |
| 476 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x07060504); |
| 477 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 478 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 479 | VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x"); |
| 480 | VERBOSE_ASSERT(vsub->tmsi, == 0x07060504, "0x%08x"); |
| 481 | vlr_subscr_put(vsub); |
| 482 | |
| 483 | BTW("subscriber detaches, using new TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 484 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 485 | ms_sends_msg("050130" "05f4" "07060504"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 486 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 487 | |
| 488 | EXPECT_CONN_COUNT(0); |
| 489 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 490 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 491 | } |
| 492 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 493 | void test_gsm_authen_imei() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 494 | { |
| 495 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 496 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 497 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 498 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 499 | |
| 500 | net->authentication_required = true; |
| 501 | net->vlr->cfg.check_imei_rqd = true; |
| 502 | |
| 503 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 504 | lu_result_sent = RES_NONE; |
| 505 | gsup_expect_tx("08010809710000004026f0"); |
| 506 | ms_sends_msg("050802008168000130089910070000006402"); |
| 507 | OSMO_ASSERT(gsup_tx_confirmed); |
| 508 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 509 | |
| 510 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 511 | auth_request_sent = false; |
| 512 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 513 | auth_request_expect_autn = NULL; |
| 514 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 515 | gsup_rx("0a" |
| 516 | /* imsi */ |
| 517 | "0108" "09710000004026f0" |
| 518 | /* 5 auth vectors... */ |
| 519 | /* TL TL rand */ |
| 520 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 521 | /* TL sres TL kc */ |
| 522 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 523 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 524 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 525 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 526 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 527 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 528 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 529 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 530 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 531 | NULL); |
| 532 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 533 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 534 | |
| 535 | btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject"); |
| 536 | gsup_rx("06010809710000004026f0", NULL); |
| 537 | EXPECT_ACCEPTED(false); |
| 538 | thwart_rx_non_initial_requests(); |
| 539 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 540 | |
| 541 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 542 | gsup_expect_tx("04010809710000004026f0"); |
| 543 | ms_sends_msg("05542d8b2c3e"); |
| 544 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 545 | |
| 546 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 547 | gsup_rx("10010809710000004026f00804036470f1", |
| 548 | "12010809710000004026f0"); |
| 549 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 550 | |
| 551 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 552 | dtap_expect_tx("051802"); |
| 553 | gsup_rx("06010809710000004026f0", NULL); |
| 554 | |
| 555 | btw("We will only do business when the IMEI is known"); |
| 556 | EXPECT_CONN_COUNT(1); |
| 557 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 558 | OSMO_ASSERT(vsub); |
| 559 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 560 | vlr_subscr_put(vsub); |
| 561 | EXPECT_ACCEPTED(false); |
| 562 | thwart_rx_non_initial_requests(); |
| 563 | |
| 564 | btw("MS replies with an Identity Response"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 565 | expect_bssap_clear(); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 566 | ms_sends_msg("0559084a32244332244302"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 567 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 568 | |
| 569 | btw("LU was successful, and the conn has already been closed"); |
| 570 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 571 | EXPECT_CONN_COUNT(0); |
| 572 | |
| 573 | btw("Subscriber has the IMEI"); |
| 574 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 575 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 576 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 577 | vlr_subscr_put(vsub); |
| 578 | |
| 579 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 580 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 581 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 582 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 583 | |
| 584 | EXPECT_CONN_COUNT(0); |
| 585 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 586 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 589 | void test_gsm_authen_tmsi_imei() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 590 | { |
| 591 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 592 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 593 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 594 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 595 | |
| 596 | net->authentication_required = true; |
| 597 | net->vlr->cfg.assign_tmsi = true; |
| 598 | net->vlr->cfg.check_imei_rqd = true; |
| 599 | |
| 600 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 601 | lu_result_sent = RES_NONE; |
| 602 | gsup_expect_tx("08010809710000004026f0"); |
| 603 | ms_sends_msg("050802008168000130089910070000006402"); |
| 604 | OSMO_ASSERT(gsup_tx_confirmed); |
| 605 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 606 | |
| 607 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 608 | auth_request_sent = false; |
| 609 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 610 | auth_request_expect_autn = NULL; |
| 611 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 612 | gsup_rx("0a" |
| 613 | /* imsi */ |
| 614 | "0108" "09710000004026f0" |
| 615 | /* 5 auth vectors... */ |
| 616 | /* TL TL rand */ |
| 617 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 618 | /* TL sres TL kc */ |
| 619 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 620 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 621 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 622 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 623 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 624 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 625 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 626 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 627 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 628 | NULL); |
| 629 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 630 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 631 | |
| 632 | btw("If the HLR were to send a GSUP _UPDATE_LOCATION_RESULT we'd still reject"); |
| 633 | gsup_rx("06010809710000004026f0", NULL); |
| 634 | EXPECT_ACCEPTED(false); |
| 635 | |
| 636 | thwart_rx_non_initial_requests(); |
| 637 | |
| 638 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 639 | |
| 640 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 641 | gsup_expect_tx("04010809710000004026f0"); |
| 642 | ms_sends_msg("05542d8b2c3e"); |
| 643 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 644 | |
| 645 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 646 | gsup_rx("10010809710000004026f00804036470f1", |
| 647 | "12010809710000004026f0"); |
| 648 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 649 | |
| 650 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 651 | dtap_expect_tx("051802"); |
| 652 | gsup_rx("06010809710000004026f0", NULL); |
| 653 | |
| 654 | btw("We will only do business when the IMEI is known"); |
| 655 | EXPECT_CONN_COUNT(1); |
| 656 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 657 | OSMO_ASSERT(vsub); |
| 658 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 659 | vlr_subscr_put(vsub); |
| 660 | EXPECT_ACCEPTED(false); |
| 661 | thwart_rx_non_initial_requests(); |
| 662 | |
| 663 | btw("MS replies with an Identity Response"); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 664 | ms_sends_msg("0559084a32244332244302"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 665 | |
| 666 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 667 | EXPECT_CONN_COUNT(1); |
| 668 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 669 | EXPECT_ACCEPTED(false); |
| 670 | thwart_rx_non_initial_requests(); |
| 671 | |
| 672 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 673 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 674 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 675 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 676 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 677 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 678 | vlr_subscr_put(vsub); |
| 679 | |
| 680 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 681 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 682 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 683 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 684 | |
| 685 | btw("LU was successful, and the conn has already been closed"); |
| 686 | EXPECT_CONN_COUNT(0); |
| 687 | |
| 688 | btw("Subscriber has the IMEI and TMSI"); |
| 689 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 690 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 691 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 692 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 693 | vlr_subscr_put(vsub); |
| 694 | |
| 695 | BTW("subscriber detaches, using TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 696 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 697 | ms_sends_msg("050130" "05f4" "03020100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 698 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 699 | |
| 700 | EXPECT_CONN_COUNT(0); |
| 701 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 702 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 703 | } |
| 704 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 705 | void test_gsm_milenage_authen() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 706 | { |
| 707 | struct vlr_subscr *vsub; |
| 708 | const char *imsi = "901700000010650"; |
| 709 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 710 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 711 | |
| 712 | net->authentication_required = true; |
| 713 | rx_from_ran = RAN_GERAN_A; |
| 714 | |
| 715 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 716 | lu_result_sent = RES_NONE; |
| 717 | gsup_expect_tx("080108" "09710000000156f0"); |
| 718 | ms_sends_msg("0508" /* MM LU */ |
| 719 | "7" /* ciph key seq: no key available */ |
| 720 | "0" /* LU type: normal */ |
| 721 | "ffffff" "0000" /* LAI, LAC */ |
| 722 | "30" /* classmark 1: GSM phase 2 */ |
| 723 | "089910070000106005" /* IMSI */ |
| 724 | ); |
| 725 | OSMO_ASSERT(gsup_tx_confirmed); |
| 726 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 727 | |
| 728 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 729 | /* based on auc_3g: |
| 730 | * K = 'EB215756028D60E3275E613320AEC880', |
| 731 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 732 | * SQN = 0 |
| 733 | */ |
| 734 | auth_request_sent = false; |
| 735 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 736 | auth_request_expect_autn = NULL; |
| 737 | gsup_rx("0a" |
| 738 | /* imsi */ |
| 739 | "0108" "09710000000156f0" |
| 740 | /* 5 auth vectors... */ |
| 741 | /* TL TL rand */ |
| 742 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 743 | /* TL sres TL kc */ |
| 744 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 745 | /* TL 3G IK */ |
| 746 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 747 | /* TL 3G CK */ |
| 748 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 749 | /* TL AUTN */ |
| 750 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 751 | /* TL RES */ |
| 752 | "2708" "e229c19e791f2e41" |
| 753 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 754 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 755 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 756 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 757 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 758 | "2708" "7db47cf7f81e4dc7" |
| 759 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 760 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 761 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 762 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 763 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 764 | "2708" "706f996719ba609c" |
| 765 | ,NULL); |
| 766 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 767 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 768 | |
| 769 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 770 | gsup_expect_tx("04010809710000000156f0"); |
| 771 | ms_sends_msg("0554" "9b36efdf"); |
| 772 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 773 | |
| 774 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 775 | gsup_rx("10010809710000000156f00804032443f2", |
| 776 | "12010809710000000156f0"); |
| 777 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 778 | |
| 779 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 780 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 781 | gsup_rx("06010809710000000156f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 782 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 783 | |
| 784 | btw("LU was successful, and the conn has already been closed"); |
| 785 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 786 | EXPECT_CONN_COUNT(0); |
| 787 | |
| 788 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 789 | auth_request_sent = false; |
| 790 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 791 | auth_request_expect_autn = NULL; |
| 792 | cm_service_result_sent = RES_NONE; |
| 793 | ms_sends_msg("052478" |
| 794 | "03305886" /* classmark 2: GSM phase 2 */ |
| 795 | "089910070000106005" /* IMSI */); |
| 796 | OSMO_ASSERT(g_conn); |
| 797 | OSMO_ASSERT(g_conn->conn_fsm); |
| 798 | OSMO_ASSERT(g_conn->vsub); |
| 799 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 800 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 801 | |
| 802 | btw("needs auth, not yet accepted"); |
| 803 | EXPECT_ACCEPTED(false); |
| 804 | thwart_rx_non_initial_requests(); |
| 805 | |
| 806 | btw("MS sends Authen Response, VLR accepts with a CM Service Accept"); |
| 807 | gsup_expect_tx(NULL); |
| 808 | ms_sends_msg("0554" "85aa3130"); /* 2nd vector's sres, s.a. */ |
| 809 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 810 | |
| 811 | btw("a USSD request is serviced"); |
| 812 | dtap_expect_tx_ussd("Your extension is 42342\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 813 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 814 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
| 815 | OSMO_ASSERT(dtap_tx_confirmed); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 816 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 817 | |
| 818 | btw("all requests serviced, conn has been released"); |
| 819 | EXPECT_CONN_COUNT(0); |
| 820 | |
| 821 | BTW("an SMS is sent, MS is paged"); |
| 822 | paging_expect_imsi(imsi); |
| 823 | paging_sent = false; |
| 824 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 825 | OSMO_ASSERT(vsub); |
| 826 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 827 | |
| 828 | send_sms(vsub, vsub, |
| 829 | "Privacy in residential applications is a desirable" |
| 830 | " marketing option."); |
| 831 | |
| 832 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 833 | vlr_subscr_put(vsub); |
| 834 | vsub = NULL; |
| 835 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 836 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 837 | |
| 838 | btw("the subscriber and its pending request should remain"); |
| 839 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 840 | OSMO_ASSERT(vsub); |
| 841 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 842 | vlr_subscr_put(vsub); |
| 843 | |
| 844 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 845 | auth_request_sent = false; |
| 846 | auth_request_expect_rand = "efa9c29a9742148d5c9070348716e1bb"; |
| 847 | auth_request_expect_autn = NULL; |
| 848 | ms_sends_msg("062707" |
| 849 | "03305886" /* classmark 2 */ |
| 850 | "089910070000106005" /* IMSI */); |
| 851 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 852 | |
| 853 | btw("needs auth, not yet accepted"); |
| 854 | EXPECT_ACCEPTED(false); |
| 855 | thwart_rx_non_initial_requests(); |
| 856 | |
| 857 | btw("MS sends Authen Response, VLR accepts and sends pending SMS"); |
| 858 | dtap_expect_tx("09" /* SMS messages */ |
| 859 | "01" /* CP-DATA */ |
| 860 | "58" /* length */ |
| 861 | "01" /* Network to MS */ |
| 862 | "00" /* reference */ |
| 863 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 864 | "0791" "447758100650" /* 447785016005 */ |
| 865 | "00" /* dest */ |
| 866 | /* SMS TPDU */ |
| 867 | "4c" /* len */ |
| 868 | "00" /* SMS deliver */ |
| 869 | "05802443f2" /* originating address 42342 */ |
| 870 | "00" /* TP-PID */ |
| 871 | "00" /* GSM default alphabet */ |
| 872 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 873 | "000000" /* H-M-S */ |
| 874 | "00" /* GMT+0 */ |
| 875 | "44" /* data length */ |
| 876 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 877 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 878 | "0c7ac3e9e9b7db05"); |
| 879 | ms_sends_msg("0554" "69d5f9fb"); /* 3nd vector's sres, s.a. */ |
| 880 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 881 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 882 | |
| 883 | btw("SMS was delivered, no requests pending for subscr"); |
| 884 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 885 | OSMO_ASSERT(vsub); |
| 886 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 887 | vlr_subscr_put(vsub); |
| 888 | |
| 889 | btw("conn is still open to wait for SMS ack dance"); |
| 890 | EXPECT_CONN_COUNT(1); |
| 891 | |
| 892 | btw("MS replies with CP-ACK for received SMS"); |
| 893 | ms_sends_msg("8904"); |
| 894 | EXPECT_CONN_COUNT(1); |
| 895 | |
| 896 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 897 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 898 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 899 | ms_sends_msg("890106020041020000"); |
| 900 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 901 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 902 | |
| 903 | btw("SMS is done, conn is gone"); |
| 904 | EXPECT_CONN_COUNT(0); |
| 905 | |
| 906 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 907 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 908 | ms_sends_msg("050130" |
| 909 | "089910070000106005" /* IMSI */); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 910 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 911 | |
| 912 | EXPECT_CONN_COUNT(0); |
| 913 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 914 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 918 | test_gsm_authen, |
| 919 | test_gsm_authen_tmsi, |
| 920 | test_gsm_authen_imei, |
| 921 | test_gsm_authen_tmsi_imei, |
| 922 | test_gsm_milenage_authen, |
| 923 | NULL |
| 924 | }; |