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 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 26 | #define ASSERT_RELEASE_CLEAR(via_ran) \ |
| 27 | switch (via_ran) { \ |
| 28 | case RAN_GERAN_A: \ |
| 29 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); \ |
| 30 | break; \ |
| 31 | case RAN_UTRAN_IU: \ |
| 32 | VERBOSE_ASSERT(iu_release_sent, == true, "%d"); \ |
| 33 | break; \ |
| 34 | default: \ |
| 35 | OSMO_ASSERT(false); \ |
| 36 | break; \ |
| 37 | } |
| 38 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 39 | void _test_umts_authen(enum ran_type via_ran) |
| 40 | { |
| 41 | struct vlr_subscr *vsub; |
| 42 | const char *imsi = "901700000010650"; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 43 | const char *sms = |
| 44 | "09" /* SMS messages */ |
| 45 | "01" /* CP-DATA */ |
| 46 | "58" /* length */ |
| 47 | "01" /* Network to MS */ |
| 48 | "00" /* reference */ |
| 49 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 50 | "0791" "447758100650" /* 447785016005 */ |
| 51 | "00" /* dest */ |
| 52 | /* SMS TPDU */ |
| 53 | "4c" /* len */ |
| 54 | "00" /* SMS deliver */ |
| 55 | "05802443f2" /* originating address 42342 */ |
| 56 | "00" /* TP-PID */ |
| 57 | "00" /* GSM default alphabet */ |
| 58 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 59 | "000000" /* H-M-S */ |
| 60 | "00" /* GMT+0 */ |
| 61 | "44" /* data length */ |
| 62 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 63 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 64 | "0c7ac3e9e9b7db05"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 65 | |
| 66 | net->authentication_required = true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 67 | net->vlr->cfg.assign_tmsi = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 68 | rx_from_ran = via_ran; |
| 69 | |
| 70 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 71 | lu_result_sent = RES_NONE; |
| 72 | gsup_expect_tx("080108" "09710000000156f0"); |
| 73 | ms_sends_msg("0508" /* MM LU */ |
| 74 | "7" /* ciph key seq: no key available */ |
| 75 | "0" /* LU type: normal */ |
| 76 | "ffffff" "0000" /* LAI, LAC */ |
| 77 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 78 | "089910070000106005" /* IMSI */ |
| 79 | "3303575886" /* classmark 2 */ |
| 80 | ); |
| 81 | OSMO_ASSERT(gsup_tx_confirmed); |
| 82 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 83 | |
| 84 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 85 | /* based on auc_3g: |
| 86 | * K = 'EB215756028D60E3275E613320AEC880', |
| 87 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 88 | * SQN = 0 |
| 89 | */ |
| 90 | auth_request_sent = false; |
| 91 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 92 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 93 | gsup_rx("0a" |
| 94 | /* imsi */ |
| 95 | "0108" "09710000000156f0" |
| 96 | /* 5 auth vectors... */ |
| 97 | /* TL TL rand */ |
| 98 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 99 | /* TL sres TL kc */ |
| 100 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 101 | /* TL 3G IK */ |
| 102 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 103 | /* TL 3G CK */ |
| 104 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 105 | /* TL AUTN */ |
| 106 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 107 | /* TL RES */ |
| 108 | "2708" "e229c19e791f2e41" |
| 109 | /* TL TL rand */ |
| 110 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 111 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 112 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 113 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 114 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 115 | "2708" "7db47cf7f81e4dc7" |
| 116 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 117 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 118 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 119 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 120 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 121 | "2708" "706f996719ba609c" |
| 122 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 123 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 124 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 125 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 126 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 127 | "2708" "3fd26072eaa2a04d" |
| 128 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 129 | "2104" "b072446f220823f39f9f425ad6e6" |
| 130 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 131 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 132 | "2510" "4bf4e564f75300009bc796706bc65744" |
| 133 | "2708" "0edb0eadbea94ac2", |
| 134 | NULL); |
| 135 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 136 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 137 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 138 | if (via_ran == RAN_GERAN_A) { |
| 139 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 140 | gsup_expect_tx("04010809710000000156f0"); |
| 141 | ms_sends_msg("0554" "e229c19e" "2104" "791f2e41"); |
| 142 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 143 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 144 | } else { |
| 145 | /* On UTRAN */ |
| 146 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 147 | cipher_mode_cmd_sent = false; |
| 148 | ms_sends_msg("0554" "e229c19e" "2104" "791f2e41"); |
| 149 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 150 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 151 | |
| 152 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR"); |
| 153 | gsup_expect_tx("04010809710000000156f0"); |
| 154 | ms_sends_security_mode_complete(); |
| 155 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 156 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 157 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 158 | |
| 159 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 160 | gsup_rx("10010809710000000156f00804032443f2", |
| 161 | "12010809710000000156f0"); |
| 162 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 163 | |
| 164 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 165 | gsup_rx("06010809710000000156f0", NULL); |
| 166 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 167 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 168 | |
| 169 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 170 | EXPECT_CONN_COUNT(1); |
| 171 | EXPECT_ACCEPTED(false); |
| 172 | thwart_rx_non_initial_requests(); |
| 173 | |
| 174 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 175 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 176 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 177 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 178 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 179 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 180 | vlr_subscr_put(vsub); |
| 181 | |
| 182 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 183 | expect_release_clear(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 184 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 185 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 186 | |
| 187 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 188 | EXPECT_CONN_COUNT(0); |
| 189 | |
| 190 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 191 | auth_request_sent = false; |
| 192 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 193 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 194 | cm_service_result_sent = RES_NONE; |
| 195 | ms_sends_msg("052478" |
| 196 | "03575886" /* classmark 2 */ |
| 197 | "089910070000106005" /* IMSI */); |
| 198 | OSMO_ASSERT(g_conn); |
| 199 | OSMO_ASSERT(g_conn->conn_fsm); |
| 200 | OSMO_ASSERT(g_conn->vsub); |
| 201 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 202 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 203 | |
| 204 | btw("needs auth, not yet accepted"); |
| 205 | EXPECT_ACCEPTED(false); |
| 206 | thwart_rx_non_initial_requests(); |
| 207 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 208 | if (via_ran == RAN_GERAN_A) { |
| 209 | btw("MS sends Authen Response, VLR accepts with a CM Service Accept"); |
| 210 | gsup_expect_tx(NULL); |
| 211 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 212 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 213 | } else { |
| 214 | /* On UTRAN */ |
| 215 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 216 | cipher_mode_cmd_sent = false; |
| 217 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 218 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 219 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 220 | |
| 221 | btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 222 | ms_sends_security_mode_complete(); |
| 223 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 224 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 225 | |
| 226 | btw("a USSD request is serviced"); |
| 227 | dtap_expect_tx_ussd("Your extension is 42342\r"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 228 | expect_release_clear(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 229 | ms_sends_msg("0b3b1c15a11302010002013b300b04010f0406aa510c061b017f0100"); |
| 230 | OSMO_ASSERT(dtap_tx_confirmed); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 231 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 232 | |
| 233 | btw("all requests serviced, conn has been released"); |
| 234 | EXPECT_CONN_COUNT(0); |
| 235 | |
| 236 | BTW("an SMS is sent, MS is paged"); |
| 237 | paging_expect_imsi(imsi); |
| 238 | paging_sent = false; |
| 239 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 240 | OSMO_ASSERT(vsub); |
| 241 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 242 | |
| 243 | send_sms(vsub, vsub, |
| 244 | "Privacy in residential applications is a desirable" |
| 245 | " marketing option."); |
| 246 | |
| 247 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 248 | vlr_subscr_put(vsub); |
| 249 | vsub = NULL; |
| 250 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 251 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 252 | |
| 253 | btw("the subscriber and its pending request should remain"); |
| 254 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 255 | OSMO_ASSERT(vsub); |
| 256 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 257 | vlr_subscr_put(vsub); |
| 258 | |
| 259 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 260 | auth_request_sent = false; |
| 261 | auth_request_expect_rand = "efa9c29a9742148d5c9070348716e1bb"; |
| 262 | auth_request_expect_autn = "f9375e6d41e1000096e7fe4ff1c27e39"; |
| 263 | ms_sends_msg("062707" |
| 264 | "03575886" /* classmark 2 */ |
| 265 | "089910070000106005" /* IMSI */); |
| 266 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 267 | |
| 268 | btw("needs auth, not yet accepted"); |
| 269 | EXPECT_ACCEPTED(false); |
| 270 | thwart_rx_non_initial_requests(); |
| 271 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 272 | if (via_ran == RAN_GERAN_A) { |
| 273 | btw("MS sends Authen Response, VLR accepts and sends pending SMS"); |
| 274 | dtap_expect_tx(sms); |
| 275 | ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */ |
| 276 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 277 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 278 | } else { |
| 279 | /* On UTRAN */ |
| 280 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 281 | cipher_mode_cmd_sent = false; |
| 282 | ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */ |
| 283 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 284 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 285 | |
| 286 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends SMS"); |
| 287 | dtap_expect_tx(sms); |
| 288 | ms_sends_security_mode_complete(); |
| 289 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 290 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 291 | |
| 292 | btw("SMS was delivered, no requests pending for subscr"); |
| 293 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 294 | OSMO_ASSERT(vsub); |
| 295 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 296 | vlr_subscr_put(vsub); |
| 297 | |
| 298 | btw("conn is still open to wait for SMS ack dance"); |
| 299 | EXPECT_CONN_COUNT(1); |
| 300 | |
| 301 | btw("MS replies with CP-ACK for received SMS"); |
| 302 | ms_sends_msg("8904"); |
| 303 | EXPECT_CONN_COUNT(1); |
| 304 | |
| 305 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 306 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 307 | expect_release_clear(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 308 | ms_sends_msg("890106020041020000"); |
| 309 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 310 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 311 | |
| 312 | btw("SMS is done, conn is gone"); |
| 313 | EXPECT_CONN_COUNT(0); |
| 314 | |
| 315 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 316 | expect_release_clear(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 317 | ms_sends_msg("050130" |
| 318 | "089910070000106005" /* IMSI */); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 319 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 320 | |
| 321 | EXPECT_CONN_COUNT(0); |
| 322 | clear_vlr(); |
| 323 | } |
| 324 | |
| 325 | void test_umts_authen_geran() |
| 326 | { |
| 327 | comment_start(); |
| 328 | _test_umts_authen(RAN_GERAN_A); |
| 329 | comment_end(); |
| 330 | } |
| 331 | |
| 332 | void test_umts_authen_utran() |
| 333 | { |
| 334 | comment_start(); |
| 335 | _test_umts_authen(RAN_UTRAN_IU); |
| 336 | comment_end(); |
| 337 | } |
| 338 | |
| 339 | #define RECALC_AUTS 0 |
| 340 | |
| 341 | #if RECALC_AUTS |
| 342 | typedef uint8_t u8; |
| 343 | extern int milenage_f2345(const u8 *opc, const u8 *k, const u8 *_rand, |
| 344 | u8 *res, u8 *ck, u8 *ik, u8 *ak, u8 *akstar); |
| 345 | extern int milenage_f1(const u8 *opc, const u8 *k, const u8 *_rand, |
| 346 | const u8 *sqn, const u8 *amf, u8 *mac_a, u8 *mac_s); |
| 347 | #endif |
| 348 | |
| 349 | void _test_umts_authen_resync(enum ran_type via_ran) |
| 350 | { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 351 | struct vlr_subscr *vsub; |
| 352 | const char *imsi = "901700000010650"; |
| 353 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 354 | net->authentication_required = true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 355 | net->vlr->cfg.assign_tmsi = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 356 | rx_from_ran = via_ran; |
| 357 | |
| 358 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 359 | lu_result_sent = RES_NONE; |
| 360 | gsup_expect_tx("080108" "09710000000156f0"); |
| 361 | ms_sends_msg("0508" /* MM LU */ |
| 362 | "7" /* ciph key seq: no key available */ |
| 363 | "0" /* LU type: normal */ |
| 364 | "ffffff" "0000" /* LAI, LAC */ |
| 365 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 366 | "089910070000106005" /* IMSI */ |
| 367 | "3303575886" /* classmark 2 */ |
| 368 | ); |
| 369 | OSMO_ASSERT(gsup_tx_confirmed); |
| 370 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 371 | |
| 372 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 373 | /* based on auc_3g: |
| 374 | * K = 'EB215756028D60E3275E613320AEC880', |
| 375 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 376 | * SQN = 0 |
| 377 | */ |
| 378 | auth_request_sent = false; |
| 379 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 380 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 381 | gsup_rx("0a" |
| 382 | /* imsi */ |
| 383 | "0108" "09710000000156f0" |
| 384 | /* auth vectors... */ |
| 385 | /* TL TL rand */ |
| 386 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 387 | /* TL sres TL kc */ |
| 388 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 389 | /* TL 3G IK */ |
| 390 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 391 | /* TL 3G CK */ |
| 392 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 393 | /* TL AUTN */ |
| 394 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 395 | /* TL RES */ |
| 396 | "2708" "e229c19e791f2e41" |
| 397 | ,NULL); |
| 398 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 399 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 400 | |
| 401 | /* The AUTN sent was 8704f5ba55f30000d2ee44b22c8ea919 |
| 402 | * (see expected error output) |
| 403 | * with the first 6 bytes being SQN ^ AK. |
| 404 | * K = EB215756028D60E3275E613320AEC880 |
| 405 | * OPC = FB2A3D1B360F599ABAB99DB8669F8308 |
| 406 | * RAND = 39fa2f4e3d523d8619a73b4f65c3e14d |
| 407 | * --milenage-f5--> |
| 408 | * AK = 8704f5ba55f3 |
| 409 | * |
| 410 | * The first six bytes are 8704f5ba55f3, |
| 411 | * and 8704f5ba55f3 ^ AK = 0. |
| 412 | * --> SQN = 0. |
| 413 | * |
| 414 | * Say the USIM doesn't like that, let's say it is at SQN 23. |
| 415 | * SQN_MS = 000000000017 |
| 416 | * |
| 417 | * AUTS = Conc(SQN_MS) || MAC-S |
| 418 | * Conc(SQN_MS) = SQN_MS ⊕ f5*[K](RAND) |
| 419 | * MAC-S = f1*[K] (SQN MS || RAND || AMF) |
| 420 | * |
| 421 | * f5*--> Conc(SQN_MS) = 000000000017 ^ 979498b1f73a |
| 422 | * = 979498b1f72d |
| 423 | * AMF = 0000 (TS 33.102 v7.0.0, 6.3.3) |
| 424 | * |
| 425 | * MAC-S = f1*[K] (000000000017 || 39fa2f4e3d523d8619a73b4f65c3e14d || 0000) |
| 426 | * = 3e28c59fa2e72f9c |
| 427 | * |
| 428 | * AUTS = 979498b1f72d || 3e28c59fa2e72f9c |
| 429 | */ |
| 430 | #if RECALC_AUTS |
| 431 | uint8_t ak[6]; |
| 432 | uint8_t akstar[6]; |
| 433 | uint8_t opc[16]; |
| 434 | uint8_t k[16]; |
| 435 | uint8_t rand[16]; |
| 436 | osmo_hexparse("EB215756028D60E3275E613320AEC880", k, sizeof(k)); |
| 437 | osmo_hexparse("FB2A3D1B360F599ABAB99DB8669F8308", opc, sizeof(opc)); |
| 438 | osmo_hexparse("39fa2f4e3d523d8619a73b4f65c3e14d", rand, sizeof(rand)); |
| 439 | milenage_f2345(opc, k, rand, NULL, NULL, NULL, ak, akstar); |
| 440 | btw("ak = %s", osmo_hexdump_nospc(ak, sizeof(ak))); |
| 441 | btw("akstar = %s", osmo_hexdump_nospc(akstar, sizeof(akstar))); |
| 442 | |
| 443 | uint8_t sqn_ms[6] = { 0, 0, 0, 0, 0, 23 }; |
| 444 | uint8_t amf[2] = { 0 }; |
| 445 | uint8_t mac_s[8]; |
| 446 | milenage_f1(opc, k, rand, sqn_ms, amf, NULL, mac_s); |
| 447 | btw("mac_s = %s", osmo_hexdump_nospc(mac_s, sizeof(mac_s))); |
| 448 | /* verify valid AUTS resulting in SQN 23 with: |
| 449 | osmo-auc-gen -3 -a milenage -k EB215756028D60E3275E613320AEC880 \ |
| 450 | -o FB2A3D1B360F599ABAB99DB8669F8308 \ |
| 451 | -r 39fa2f4e3d523d8619a73b4f65c3e14d \ |
| 452 | -A 979498b1f72d3e28c59fa2e72f9c |
| 453 | */ |
| 454 | #endif |
| 455 | |
| 456 | btw("MS sends Authen Failure with Resync cause, VLR sends GSUP to HLR to resync"); |
| 457 | auth_request_sent = false; |
| 458 | gsup_expect_tx("08" /* OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST */ |
| 459 | "0108" "09710000000156f0" /* IMSI */ |
| 460 | "260e" "979498b1f72d3e28c59fa2e72f9c" /* AUTS */ |
| 461 | "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" /* RAND */); |
| 462 | ms_sends_msg("051c" /* 05 = MM; 1c = Auth Failure */ |
| 463 | "15" /* cause = Synch Failure */ |
| 464 | "220e" "979498b1f72d3e28c59fa2e72f9c" /* AUTS */); |
| 465 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 466 | VERBOSE_ASSERT(auth_request_sent, == false, "%d"); |
| 467 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 468 | |
| 469 | btw("HLR replies with new tuples"); |
| 470 | auth_request_sent = false; |
| 471 | auth_request_expect_rand = "0f1feb1623e1bf626334e37ec448ac18"; |
| 472 | auth_request_expect_autn = "02a83f62e9470000660d51afc75f169d"; |
| 473 | gsup_rx("0a" |
| 474 | /* imsi */ |
| 475 | "0108" "09710000000156f0" |
| 476 | /* 1 auth vector */ |
| 477 | /* TL TL rand */ |
| 478 | "0362" "2010" "0f1feb1623e1bf626334e37ec448ac18" |
| 479 | /* TL sres TL kc */ |
| 480 | "2104" "efde99da" "2208" "14778c855c523730" |
| 481 | /* TL 3G IK */ |
| 482 | "2310" "8a90c769b7272f3bb7a1c1fbb1ea9349" |
| 483 | /* TL 3G CK */ |
| 484 | "2410" "43ffc1cf8c89a7fd6ab94bd8d6162cbf" |
| 485 | /* TL AUTN */ |
| 486 | "2510" "02a83f62e9470000660d51afc75f169d" |
| 487 | /* TL RES */ |
| 488 | "2708" "1df5f0b4f22b696e" |
| 489 | /* TL TL rand */ |
| 490 | "0362" "2010" "ac21d34937b4e1142a2c757af2949319" |
| 491 | /* TL sres TL kc */ |
| 492 | "2104" "7818bfdc" "2208" "d175571f41f314a4" |
| 493 | /* TL 3G IK */ |
| 494 | "2310" "ff8edbceb6dd24799c77c3b9a6790c10" |
| 495 | /* TL 3G CK */ |
| 496 | "2410" "157c39022ca9d885a7f0766a7dfee448" |
| 497 | /* TL AUTN */ |
| 498 | "2510" "8a43b91898e500002cf354c6f5d1f8c3" |
| 499 | /* TL RES */ |
| 500 | "2708" "f748a7078f5018db" |
| 501 | ,NULL); |
| 502 | |
| 503 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 504 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 505 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 506 | if (via_ran == RAN_GERAN_A) { |
| 507 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
| 508 | gsup_expect_tx("04010809710000000156f0"); |
| 509 | ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e"); |
| 510 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 511 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 512 | } else { |
| 513 | /* On UTRAN */ |
| 514 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
| 515 | cipher_mode_cmd_sent = false; |
| 516 | ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e"); |
| 517 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 518 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 519 | |
| 520 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR"); |
| 521 | gsup_expect_tx("04010809710000000156f0"); |
| 522 | ms_sends_security_mode_complete(); |
| 523 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 524 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 525 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 526 | |
| 527 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 528 | gsup_rx("10010809710000000156f00804032443f2", |
| 529 | "12010809710000000156f0"); |
| 530 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 531 | |
| 532 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 533 | gsup_rx("06010809710000000156f0", NULL); |
| 534 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 535 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 536 | |
| 537 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 538 | EXPECT_CONN_COUNT(1); |
| 539 | EXPECT_ACCEPTED(false); |
| 540 | thwart_rx_non_initial_requests(); |
| 541 | |
| 542 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 543 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 544 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 545 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 546 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 547 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 548 | vlr_subscr_put(vsub); |
| 549 | |
| 550 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 551 | expect_release_clear(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 552 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 553 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 554 | |
| 555 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 556 | EXPECT_CONN_COUNT(0); |
| 557 | |
| 558 | clear_vlr(); |
| 559 | } |
| 560 | |
| 561 | void test_umts_authen_resync_geran() |
| 562 | { |
| 563 | comment_start(); |
| 564 | _test_umts_authen_resync(RAN_GERAN_A); |
| 565 | comment_end(); |
| 566 | } |
| 567 | |
| 568 | void test_umts_authen_resync_utran() |
| 569 | { |
| 570 | comment_start(); |
| 571 | _test_umts_authen_resync(RAN_UTRAN_IU); |
| 572 | comment_end(); |
| 573 | } |
| 574 | |
| 575 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 576 | test_umts_authen_geran, |
| 577 | test_umts_authen_utran, |
| 578 | test_umts_authen_resync_geran, |
| 579 | test_umts_authen_resync_utran, |
| 580 | NULL |
| 581 | }; |