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" |
Harald Welte | 0df904d | 2018-12-03 11:00:04 +0100 | [diff] [blame] | 25 | #include "stubs.h" |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 26 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 27 | static void _test_umts_authen(enum osmo_rat_type via_ran) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 28 | { |
| 29 | struct vlr_subscr *vsub; |
| 30 | const char *imsi = "901700000010650"; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 31 | const char *sms = |
| 32 | "09" /* SMS messages */ |
| 33 | "01" /* CP-DATA */ |
| 34 | "58" /* length */ |
| 35 | "01" /* Network to MS */ |
| 36 | "00" /* reference */ |
| 37 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 38 | "0791" "447758100650" /* 447785016005 */ |
| 39 | "00" /* dest */ |
| 40 | /* SMS TPDU */ |
| 41 | "4c" /* len */ |
| 42 | "00" /* SMS deliver */ |
| 43 | "05802443f2" /* originating address 42342 */ |
| 44 | "00" /* TP-PID */ |
| 45 | "00" /* GSM default alphabet */ |
| 46 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 47 | "000000" /* H-M-S */ |
| 48 | "00" /* GMT+0 */ |
| 49 | "44" /* data length */ |
| 50 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 51 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 52 | "0c7ac3e9e9b7db05"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 53 | |
| 54 | net->authentication_required = true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 55 | net->vlr->cfg.assign_tmsi = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 56 | rx_from_ran = via_ran; |
| 57 | |
| 58 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 59 | lu_result_sent = RES_NONE; |
| 60 | gsup_expect_tx("080108" "09710000000156f0"); |
| 61 | ms_sends_msg("0508" /* MM LU */ |
| 62 | "7" /* ciph key seq: no key available */ |
| 63 | "0" /* LU type: normal */ |
| 64 | "ffffff" "0000" /* LAI, LAC */ |
| 65 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 66 | "089910070000106005" /* IMSI */ |
| 67 | "3303575886" /* classmark 2 */ |
| 68 | ); |
| 69 | OSMO_ASSERT(gsup_tx_confirmed); |
| 70 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 71 | |
| 72 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 73 | /* based on auc_3g: |
| 74 | * K = 'EB215756028D60E3275E613320AEC880', |
| 75 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 76 | * SQN = 0 |
| 77 | */ |
| 78 | auth_request_sent = false; |
| 79 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 80 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 81 | gsup_rx("0a" |
| 82 | /* imsi */ |
| 83 | "0108" "09710000000156f0" |
| 84 | /* 5 auth vectors... */ |
| 85 | /* TL TL rand */ |
| 86 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 87 | /* TL sres TL kc */ |
| 88 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 89 | /* TL 3G IK */ |
| 90 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 91 | /* TL 3G CK */ |
| 92 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 93 | /* TL AUTN */ |
| 94 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 95 | /* TL RES */ |
| 96 | "2708" "e229c19e791f2e41" |
| 97 | /* TL TL rand */ |
| 98 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 99 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 100 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 101 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 102 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 103 | "2708" "7db47cf7f81e4dc7" |
| 104 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 105 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 106 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 107 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 108 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 109 | "2708" "706f996719ba609c" |
| 110 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 111 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 112 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 113 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 114 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 115 | "2708" "3fd26072eaa2a04d" |
| 116 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 117 | "2104" "b072446f220823f39f9f425ad6e6" |
| 118 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 119 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 120 | "2510" "4bf4e564f75300009bc796706bc65744" |
| 121 | "2708" "0edb0eadbea94ac2", |
| 122 | NULL); |
| 123 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 124 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 125 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 126 | if (via_ran == OSMO_RAT_GERAN_A) { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 127 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 128 | gsup_expect_tx("04010809710000000156f0280102"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 129 | ms_sends_msg("0554" "e229c19e" "2104" "791f2e41"); |
| 130 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 131 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 132 | } else { |
| 133 | /* On UTRAN */ |
| 134 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 135 | expect_security_mode_ctrl(NULL, "27497388b6cb044648f396aa155b95ef"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 136 | ms_sends_msg("0554" "e229c19e" "2104" "791f2e41"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 137 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 138 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 139 | |
| 140 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 141 | gsup_expect_tx("04010809710000000156f0280102"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 142 | ms_sends_security_mode_complete(); |
| 143 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 144 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 145 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 146 | |
| 147 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 148 | gsup_rx("10010809710000000156f00804032443f2", |
| 149 | "12010809710000000156f0"); |
| 150 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 151 | |
| 152 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 153 | gsup_rx("06010809710000000156f0", NULL); |
| 154 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 155 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 156 | |
| 157 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 158 | EXPECT_CONN_COUNT(1); |
| 159 | EXPECT_ACCEPTED(false); |
| 160 | thwart_rx_non_initial_requests(); |
| 161 | |
| 162 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 163 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 164 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 165 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 166 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 167 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 168 | vlr_subscr_put(vsub, __func__); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 169 | |
| 170 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 171 | expect_release_clear(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 172 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 173 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 174 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 175 | |
| 176 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 177 | EXPECT_CONN_COUNT(0); |
| 178 | |
| 179 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 180 | auth_request_sent = false; |
| 181 | auth_request_expect_rand = "c187a53a5e6b9d573cac7c74451fd46d"; |
| 182 | auth_request_expect_autn = "1843a645b98d00005b2d666af46c45d9"; |
| 183 | cm_service_result_sent = RES_NONE; |
| 184 | ms_sends_msg("052478" |
| 185 | "03575886" /* classmark 2 */ |
| 186 | "089910070000106005" /* IMSI */); |
| 187 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 4d3a66b | 2018-03-31 18:45:59 +0200 | [diff] [blame] | 188 | OSMO_ASSERT(g_conn->fi); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 189 | OSMO_ASSERT(g_conn->vsub); |
| 190 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 191 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 192 | |
| 193 | btw("needs auth, not yet accepted"); |
| 194 | EXPECT_ACCEPTED(false); |
| 195 | thwart_rx_non_initial_requests(); |
| 196 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 197 | if (via_ran == OSMO_RAT_GERAN_A) { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 198 | btw("MS sends Authen Response, VLR accepts with a CM Service Accept"); |
| 199 | gsup_expect_tx(NULL); |
| 200 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
| 201 | VERBOSE_ASSERT(cm_service_result_sent, == RES_ACCEPT, "%d"); |
| 202 | } else { |
| 203 | /* On UTRAN */ |
| 204 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 205 | expect_security_mode_ctrl(NULL, "1159ec926a50e98c034a6b7d7c9f418d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 206 | ms_sends_msg("0554" "7db47cf7" "2104" "f81e4dc7"); /* 2nd vector's res, s.a. */ |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 207 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 208 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 209 | |
| 210 | btw("MS sends SecurityModeControl acceptance, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 211 | ms_sends_security_mode_complete(); |
| 212 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 213 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 214 | |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 215 | /* Release connection */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 216 | expect_release_clear(via_ran); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 217 | conn_conclude_cm_service_req(g_conn, via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 218 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 219 | |
| 220 | btw("all requests serviced, conn has been released"); |
| 221 | EXPECT_CONN_COUNT(0); |
| 222 | |
| 223 | BTW("an SMS is sent, MS is paged"); |
| 224 | paging_expect_imsi(imsi); |
| 225 | paging_sent = false; |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 226 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 227 | OSMO_ASSERT(vsub); |
| 228 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 229 | |
| 230 | send_sms(vsub, vsub, |
| 231 | "Privacy in residential applications is a desirable" |
| 232 | " marketing option."); |
| 233 | |
| 234 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 235 | vlr_subscr_put(vsub, __func__); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 236 | vsub = NULL; |
| 237 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 238 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 239 | |
| 240 | btw("the subscriber and its pending request should remain"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 241 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 242 | OSMO_ASSERT(vsub); |
| 243 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 244 | vlr_subscr_put(vsub, __func__); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 245 | |
| 246 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 247 | auth_request_sent = false; |
| 248 | auth_request_expect_rand = "efa9c29a9742148d5c9070348716e1bb"; |
| 249 | auth_request_expect_autn = "f9375e6d41e1000096e7fe4ff1c27e39"; |
| 250 | ms_sends_msg("062707" |
| 251 | "03575886" /* classmark 2 */ |
| 252 | "089910070000106005" /* IMSI */); |
| 253 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 254 | |
| 255 | btw("needs auth, not yet accepted"); |
| 256 | EXPECT_ACCEPTED(false); |
| 257 | thwart_rx_non_initial_requests(); |
| 258 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 259 | if (via_ran == OSMO_RAT_GERAN_A) { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 260 | btw("MS sends Authen Response, VLR accepts and sends pending SMS"); |
| 261 | dtap_expect_tx(sms); |
| 262 | ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */ |
| 263 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 264 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 265 | } else { |
| 266 | /* On UTRAN */ |
| 267 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 268 | expect_security_mode_ctrl(NULL, "eb50e770ddcc3060101d2f43b6c2b884"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 269 | ms_sends_msg("0554" "706f9967" "2104" "19ba609c"); /* 3nd vector's res, s.a. */ |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 270 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 271 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 272 | |
| 273 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends SMS"); |
| 274 | dtap_expect_tx(sms); |
| 275 | ms_sends_security_mode_complete(); |
| 276 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 277 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 278 | |
| 279 | btw("SMS was delivered, no requests pending for subscr"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 280 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi, __func__); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 281 | OSMO_ASSERT(vsub); |
| 282 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 283 | vlr_subscr_put(vsub, __func__); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 284 | |
| 285 | btw("conn is still open to wait for SMS ack dance"); |
| 286 | EXPECT_CONN_COUNT(1); |
| 287 | |
| 288 | btw("MS replies with CP-ACK for received SMS"); |
| 289 | ms_sends_msg("8904"); |
| 290 | EXPECT_CONN_COUNT(1); |
| 291 | |
| 292 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 293 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 294 | expect_release_clear(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 295 | ms_sends_msg("890106020041020000"); |
| 296 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 297 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 298 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 299 | |
| 300 | btw("SMS is done, conn is gone"); |
| 301 | EXPECT_CONN_COUNT(0); |
| 302 | |
| 303 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 304 | expect_release_clear(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 305 | ms_sends_msg("050130" |
| 306 | "089910070000106005" /* IMSI */); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 307 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 308 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 309 | |
| 310 | EXPECT_CONN_COUNT(0); |
| 311 | clear_vlr(); |
| 312 | } |
| 313 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 314 | static void test_umts_authen_geran() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 315 | { |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 316 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 317 | _test_umts_authen(OSMO_RAT_GERAN_A); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 318 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 319 | } |
| 320 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 321 | static void test_umts_authen_utran() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 322 | { |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 323 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 324 | _test_umts_authen(OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 325 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | #define RECALC_AUTS 0 |
| 329 | |
| 330 | #if RECALC_AUTS |
| 331 | typedef uint8_t u8; |
| 332 | extern int milenage_f2345(const u8 *opc, const u8 *k, const u8 *_rand, |
| 333 | u8 *res, u8 *ck, u8 *ik, u8 *ak, u8 *akstar); |
| 334 | extern int milenage_f1(const u8 *opc, const u8 *k, const u8 *_rand, |
| 335 | const u8 *sqn, const u8 *amf, u8 *mac_a, u8 *mac_s); |
| 336 | #endif |
| 337 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 338 | static void _test_umts_authen_resync(enum osmo_rat_type via_ran) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 339 | { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 340 | struct vlr_subscr *vsub; |
| 341 | const char *imsi = "901700000010650"; |
| 342 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 343 | net->authentication_required = true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 344 | net->vlr->cfg.assign_tmsi = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 345 | rx_from_ran = via_ran; |
| 346 | |
| 347 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 348 | lu_result_sent = RES_NONE; |
| 349 | gsup_expect_tx("080108" "09710000000156f0"); |
| 350 | ms_sends_msg("0508" /* MM LU */ |
| 351 | "7" /* ciph key seq: no key available */ |
| 352 | "0" /* LU type: normal */ |
| 353 | "ffffff" "0000" /* LAI, LAC */ |
| 354 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 355 | "089910070000106005" /* IMSI */ |
| 356 | "3303575886" /* classmark 2 */ |
| 357 | ); |
| 358 | OSMO_ASSERT(gsup_tx_confirmed); |
| 359 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 360 | |
| 361 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 362 | /* based on auc_3g: |
| 363 | * K = 'EB215756028D60E3275E613320AEC880', |
| 364 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 365 | * SQN = 0 |
| 366 | */ |
| 367 | auth_request_sent = false; |
| 368 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 369 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 370 | gsup_rx("0a" |
| 371 | /* imsi */ |
| 372 | "0108" "09710000000156f0" |
| 373 | /* auth vectors... */ |
| 374 | /* TL TL rand */ |
| 375 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 376 | /* TL sres TL kc */ |
| 377 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 378 | /* TL 3G IK */ |
| 379 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 380 | /* TL 3G CK */ |
| 381 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 382 | /* TL AUTN */ |
| 383 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 384 | /* TL RES */ |
| 385 | "2708" "e229c19e791f2e41" |
| 386 | ,NULL); |
| 387 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 388 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 389 | |
| 390 | /* The AUTN sent was 8704f5ba55f30000d2ee44b22c8ea919 |
| 391 | * (see expected error output) |
| 392 | * with the first 6 bytes being SQN ^ AK. |
| 393 | * K = EB215756028D60E3275E613320AEC880 |
| 394 | * OPC = FB2A3D1B360F599ABAB99DB8669F8308 |
| 395 | * RAND = 39fa2f4e3d523d8619a73b4f65c3e14d |
| 396 | * --milenage-f5--> |
| 397 | * AK = 8704f5ba55f3 |
| 398 | * |
| 399 | * The first six bytes are 8704f5ba55f3, |
| 400 | * and 8704f5ba55f3 ^ AK = 0. |
| 401 | * --> SQN = 0. |
| 402 | * |
| 403 | * Say the USIM doesn't like that, let's say it is at SQN 23. |
| 404 | * SQN_MS = 000000000017 |
| 405 | * |
| 406 | * AUTS = Conc(SQN_MS) || MAC-S |
| 407 | * Conc(SQN_MS) = SQN_MS ⊕ f5*[K](RAND) |
| 408 | * MAC-S = f1*[K] (SQN MS || RAND || AMF) |
| 409 | * |
| 410 | * f5*--> Conc(SQN_MS) = 000000000017 ^ 979498b1f73a |
| 411 | * = 979498b1f72d |
| 412 | * AMF = 0000 (TS 33.102 v7.0.0, 6.3.3) |
| 413 | * |
| 414 | * MAC-S = f1*[K] (000000000017 || 39fa2f4e3d523d8619a73b4f65c3e14d || 0000) |
| 415 | * = 3e28c59fa2e72f9c |
| 416 | * |
| 417 | * AUTS = 979498b1f72d || 3e28c59fa2e72f9c |
| 418 | */ |
| 419 | #if RECALC_AUTS |
| 420 | uint8_t ak[6]; |
| 421 | uint8_t akstar[6]; |
| 422 | uint8_t opc[16]; |
| 423 | uint8_t k[16]; |
| 424 | uint8_t rand[16]; |
| 425 | osmo_hexparse("EB215756028D60E3275E613320AEC880", k, sizeof(k)); |
| 426 | osmo_hexparse("FB2A3D1B360F599ABAB99DB8669F8308", opc, sizeof(opc)); |
| 427 | osmo_hexparse("39fa2f4e3d523d8619a73b4f65c3e14d", rand, sizeof(rand)); |
| 428 | milenage_f2345(opc, k, rand, NULL, NULL, NULL, ak, akstar); |
| 429 | btw("ak = %s", osmo_hexdump_nospc(ak, sizeof(ak))); |
| 430 | btw("akstar = %s", osmo_hexdump_nospc(akstar, sizeof(akstar))); |
| 431 | |
| 432 | uint8_t sqn_ms[6] = { 0, 0, 0, 0, 0, 23 }; |
| 433 | uint8_t amf[2] = { 0 }; |
| 434 | uint8_t mac_s[8]; |
| 435 | milenage_f1(opc, k, rand, sqn_ms, amf, NULL, mac_s); |
| 436 | btw("mac_s = %s", osmo_hexdump_nospc(mac_s, sizeof(mac_s))); |
| 437 | /* verify valid AUTS resulting in SQN 23 with: |
| 438 | osmo-auc-gen -3 -a milenage -k EB215756028D60E3275E613320AEC880 \ |
| 439 | -o FB2A3D1B360F599ABAB99DB8669F8308 \ |
| 440 | -r 39fa2f4e3d523d8619a73b4f65c3e14d \ |
| 441 | -A 979498b1f72d3e28c59fa2e72f9c |
| 442 | */ |
| 443 | #endif |
| 444 | |
| 445 | btw("MS sends Authen Failure with Resync cause, VLR sends GSUP to HLR to resync"); |
| 446 | auth_request_sent = false; |
| 447 | gsup_expect_tx("08" /* OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST */ |
| 448 | "0108" "09710000000156f0" /* IMSI */ |
| 449 | "260e" "979498b1f72d3e28c59fa2e72f9c" /* AUTS */ |
| 450 | "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" /* RAND */); |
| 451 | ms_sends_msg("051c" /* 05 = MM; 1c = Auth Failure */ |
| 452 | "15" /* cause = Synch Failure */ |
| 453 | "220e" "979498b1f72d3e28c59fa2e72f9c" /* AUTS */); |
| 454 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 455 | VERBOSE_ASSERT(auth_request_sent, == false, "%d"); |
| 456 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 457 | |
| 458 | btw("HLR replies with new tuples"); |
| 459 | auth_request_sent = false; |
| 460 | auth_request_expect_rand = "0f1feb1623e1bf626334e37ec448ac18"; |
| 461 | auth_request_expect_autn = "02a83f62e9470000660d51afc75f169d"; |
| 462 | gsup_rx("0a" |
| 463 | /* imsi */ |
| 464 | "0108" "09710000000156f0" |
| 465 | /* 1 auth vector */ |
| 466 | /* TL TL rand */ |
| 467 | "0362" "2010" "0f1feb1623e1bf626334e37ec448ac18" |
| 468 | /* TL sres TL kc */ |
| 469 | "2104" "efde99da" "2208" "14778c855c523730" |
| 470 | /* TL 3G IK */ |
| 471 | "2310" "8a90c769b7272f3bb7a1c1fbb1ea9349" |
| 472 | /* TL 3G CK */ |
| 473 | "2410" "43ffc1cf8c89a7fd6ab94bd8d6162cbf" |
| 474 | /* TL AUTN */ |
| 475 | "2510" "02a83f62e9470000660d51afc75f169d" |
| 476 | /* TL RES */ |
| 477 | "2708" "1df5f0b4f22b696e" |
| 478 | /* TL TL rand */ |
| 479 | "0362" "2010" "ac21d34937b4e1142a2c757af2949319" |
| 480 | /* TL sres TL kc */ |
| 481 | "2104" "7818bfdc" "2208" "d175571f41f314a4" |
| 482 | /* TL 3G IK */ |
| 483 | "2310" "ff8edbceb6dd24799c77c3b9a6790c10" |
| 484 | /* TL 3G CK */ |
| 485 | "2410" "157c39022ca9d885a7f0766a7dfee448" |
| 486 | /* TL AUTN */ |
| 487 | "2510" "8a43b91898e500002cf354c6f5d1f8c3" |
| 488 | /* TL RES */ |
| 489 | "2708" "f748a7078f5018db" |
| 490 | ,NULL); |
| 491 | |
| 492 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 493 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 494 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 495 | if (via_ran == OSMO_RAT_GERAN_A) { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 496 | btw("MS sends Authen Response, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 497 | gsup_expect_tx("04010809710000000156f0280102"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 498 | ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e"); |
| 499 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 500 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 501 | } else { |
| 502 | /* On UTRAN */ |
| 503 | btw("MS sends Authen Response, VLR accepts and sends SecurityModeControl"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 504 | expect_security_mode_ctrl(NULL, "8a90c769b7272f3bb7a1c1fbb1ea9349"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 505 | ms_sends_msg("0554" "1df5f0b4" "2104" "f22b696e"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 506 | VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 507 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 508 | |
| 509 | btw("MS sends SecurityModeControl acceptance, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 510 | gsup_expect_tx("04010809710000000156f0280102"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 511 | ms_sends_security_mode_complete(); |
| 512 | VERBOSE_ASSERT(gsup_tx_confirmed, == true, "%d"); |
| 513 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 514 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 515 | |
| 516 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 517 | gsup_rx("10010809710000000156f00804032443f2", |
| 518 | "12010809710000000156f0"); |
| 519 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 520 | |
| 521 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 522 | gsup_rx("06010809710000000156f0", NULL); |
| 523 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 524 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 525 | |
| 526 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 527 | EXPECT_CONN_COUNT(1); |
| 528 | EXPECT_ACCEPTED(false); |
| 529 | thwart_rx_non_initial_requests(); |
| 530 | |
| 531 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 532 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100, __func__); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 533 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 534 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 535 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 536 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
Neels Hofmeyr | 7c5346c | 2019-02-19 02:36:35 +0100 | [diff] [blame^] | 537 | vlr_subscr_put(vsub, __func__); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 538 | |
| 539 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 540 | expect_release_clear(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 541 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 542 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 543 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 544 | |
| 545 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 546 | EXPECT_CONN_COUNT(0); |
| 547 | |
| 548 | clear_vlr(); |
| 549 | } |
| 550 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 551 | static void test_umts_authen_resync_geran() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 552 | { |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 553 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 554 | _test_umts_authen_resync(OSMO_RAT_GERAN_A); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 555 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 556 | } |
| 557 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 558 | static void test_umts_authen_resync_utran() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 559 | { |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 560 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 561 | _test_umts_authen_resync(OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 562 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 565 | static void _test_umts_authen_too_short_res(enum osmo_rat_type via_ran) |
Neels Hofmeyr | 15ed426 | 2018-03-10 04:02:44 +0100 | [diff] [blame] | 566 | { |
| 567 | net->authentication_required = true; |
| 568 | net->vlr->cfg.assign_tmsi = true; |
| 569 | rx_from_ran = via_ran; |
| 570 | |
| 571 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 572 | lu_result_sent = RES_NONE; |
| 573 | gsup_expect_tx("080108" "09710000000156f0"); |
| 574 | ms_sends_msg("0508" /* MM LU */ |
| 575 | "7" /* ciph key seq: no key available */ |
| 576 | "0" /* LU type: normal */ |
| 577 | "ffffff" "0000" /* LAI, LAC */ |
| 578 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 579 | "089910070000106005" /* IMSI */ |
| 580 | "3303575886" /* classmark 2 */ |
| 581 | ); |
| 582 | OSMO_ASSERT(gsup_tx_confirmed); |
| 583 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 584 | |
| 585 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 586 | /* based on auc_3g: |
| 587 | * K = 'EB215756028D60E3275E613320AEC880', |
| 588 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 589 | * SQN = 0 |
| 590 | */ |
| 591 | auth_request_sent = false; |
| 592 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 593 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 594 | gsup_rx("0a" |
| 595 | /* imsi */ |
| 596 | "0108" "09710000000156f0" |
| 597 | /* 5 auth vectors... */ |
| 598 | /* TL TL rand */ |
| 599 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 600 | /* TL sres TL kc */ |
| 601 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 602 | /* TL 3G IK */ |
| 603 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 604 | /* TL 3G CK */ |
| 605 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 606 | /* TL AUTN */ |
| 607 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 608 | /* TL RES */ |
| 609 | "2708" "e229c19e791f2e41" |
| 610 | /* TL TL rand */ |
| 611 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 612 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 613 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 614 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 615 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 616 | "2708" "7db47cf7f81e4dc7" |
| 617 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 618 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 619 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 620 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 621 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 622 | "2708" "706f996719ba609c" |
| 623 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 624 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 625 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 626 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 627 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 628 | "2708" "3fd26072eaa2a04d" |
| 629 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 630 | "2104" "b072446f220823f39f9f425ad6e6" |
| 631 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 632 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 633 | "2510" "4bf4e564f75300009bc796706bc65744" |
| 634 | "2708" "0edb0eadbea94ac2", |
| 635 | NULL); |
| 636 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 637 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 638 | |
| 639 | btw("MS sends Authen Response of wrong RES size, VLR thwarts"); |
| 640 | gsup_expect_tx("0b010809710000000156f0"); /* OSMO_GSUP_MSGT_AUTH_FAIL_REPORT */ |
| 641 | expect_release_clear(via_ran); |
| 642 | ms_sends_msg("0554" "e229c19e" "2103" "791f2e" /* nipped one byte */); |
| 643 | VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d"); |
| 644 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 645 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 15ed426 | 2018-03-10 04:02:44 +0100 | [diff] [blame] | 646 | |
| 647 | EXPECT_CONN_COUNT(0); |
| 648 | clear_vlr(); |
| 649 | } |
| 650 | |
| 651 | static void test_umts_authen_too_short_res_geran() |
| 652 | { |
| 653 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 654 | _test_umts_authen_too_short_res(OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 15ed426 | 2018-03-10 04:02:44 +0100 | [diff] [blame] | 655 | comment_end(); |
| 656 | } |
| 657 | |
| 658 | static void test_umts_authen_too_short_res_utran() |
| 659 | { |
| 660 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 661 | _test_umts_authen_too_short_res(OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | 15ed426 | 2018-03-10 04:02:44 +0100 | [diff] [blame] | 662 | comment_end(); |
| 663 | } |
| 664 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 665 | static void _test_umts_authen_too_long_res(enum osmo_rat_type via_ran) |
Neels Hofmeyr | c6d20dd | 2018-03-10 04:03:43 +0100 | [diff] [blame] | 666 | { |
| 667 | net->authentication_required = true; |
| 668 | net->vlr->cfg.assign_tmsi = true; |
| 669 | rx_from_ran = via_ran; |
| 670 | |
| 671 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 672 | lu_result_sent = RES_NONE; |
| 673 | gsup_expect_tx("080108" "09710000000156f0"); |
| 674 | ms_sends_msg("0508" /* MM LU */ |
| 675 | "7" /* ciph key seq: no key available */ |
| 676 | "0" /* LU type: normal */ |
| 677 | "ffffff" "0000" /* LAI, LAC */ |
| 678 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 679 | "089910070000106005" /* IMSI */ |
| 680 | "3303575886" /* classmark 2 */ |
| 681 | ); |
| 682 | OSMO_ASSERT(gsup_tx_confirmed); |
| 683 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 684 | |
| 685 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 686 | /* based on auc_3g: |
| 687 | * K = 'EB215756028D60E3275E613320AEC880', |
| 688 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 689 | * SQN = 0 |
| 690 | */ |
| 691 | auth_request_sent = false; |
| 692 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 693 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 694 | gsup_rx("0a" |
| 695 | /* imsi */ |
| 696 | "0108" "09710000000156f0" |
| 697 | /* 5 auth vectors... */ |
| 698 | /* TL TL rand */ |
| 699 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 700 | /* TL sres TL kc */ |
| 701 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 702 | /* TL 3G IK */ |
| 703 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 704 | /* TL 3G CK */ |
| 705 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 706 | /* TL AUTN */ |
| 707 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 708 | /* TL RES */ |
| 709 | "2708" "e229c19e791f2e41" |
| 710 | /* TL TL rand */ |
| 711 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 712 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 713 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 714 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 715 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 716 | "2708" "7db47cf7f81e4dc7" |
| 717 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 718 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 719 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 720 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 721 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 722 | "2708" "706f996719ba609c" |
| 723 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 724 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 725 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 726 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 727 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 728 | "2708" "3fd26072eaa2a04d" |
| 729 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 730 | "2104" "b072446f220823f39f9f425ad6e6" |
| 731 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 732 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 733 | "2510" "4bf4e564f75300009bc796706bc65744" |
| 734 | "2708" "0edb0eadbea94ac2", |
| 735 | NULL); |
| 736 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 737 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 738 | |
| 739 | btw("MS sends Authen Response of wrong RES size, VLR thwarts"); |
| 740 | gsup_expect_tx("0b010809710000000156f0"); /* OSMO_GSUP_MSGT_AUTH_FAIL_REPORT */ |
| 741 | expect_release_clear(via_ran); |
| 742 | ms_sends_msg("0554" "e229c19e" "2105" "791f2e4123" /* added one byte */); |
| 743 | VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d"); |
| 744 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 745 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | c6d20dd | 2018-03-10 04:03:43 +0100 | [diff] [blame] | 746 | |
| 747 | EXPECT_CONN_COUNT(0); |
| 748 | clear_vlr(); |
| 749 | } |
| 750 | |
| 751 | static void test_umts_authen_too_long_res_geran() |
| 752 | { |
| 753 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 754 | _test_umts_authen_too_long_res(OSMO_RAT_GERAN_A); |
Neels Hofmeyr | c6d20dd | 2018-03-10 04:03:43 +0100 | [diff] [blame] | 755 | comment_end(); |
| 756 | } |
| 757 | |
| 758 | static void test_umts_authen_too_long_res_utran() |
| 759 | { |
| 760 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 761 | _test_umts_authen_too_long_res(OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | c6d20dd | 2018-03-10 04:03:43 +0100 | [diff] [blame] | 762 | comment_end(); |
| 763 | } |
| 764 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 765 | static void _test_umts_authen_only_sres(enum osmo_rat_type via_ran) |
Neels Hofmeyr | 31adcae | 2018-03-10 04:08:45 +0100 | [diff] [blame] | 766 | { |
| 767 | net->authentication_required = true; |
| 768 | net->vlr->cfg.assign_tmsi = true; |
| 769 | rx_from_ran = via_ran; |
| 770 | |
| 771 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 772 | lu_result_sent = RES_NONE; |
| 773 | gsup_expect_tx("080108" "09710000000156f0"); |
| 774 | ms_sends_msg("0508" /* MM LU */ |
| 775 | "7" /* ciph key seq: no key available */ |
| 776 | "0" /* LU type: normal */ |
| 777 | "ffffff" "0000" /* LAI, LAC */ |
| 778 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 779 | "089910070000106005" /* IMSI */ |
| 780 | "3303575886" /* classmark 2 */ |
| 781 | ); |
| 782 | OSMO_ASSERT(gsup_tx_confirmed); |
| 783 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 784 | |
| 785 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 786 | /* based on auc_3g: |
| 787 | * K = 'EB215756028D60E3275E613320AEC880', |
| 788 | * OPC = 'FB2A3D1B360F599ABAB99DB8669F8308' |
| 789 | * SQN = 0 |
| 790 | */ |
| 791 | auth_request_sent = false; |
| 792 | auth_request_expect_rand = "39fa2f4e3d523d8619a73b4f65c3e14d"; |
| 793 | auth_request_expect_autn = "8704f5ba55f30000d2ee44b22c8ea919"; |
| 794 | gsup_rx("0a" |
| 795 | /* imsi */ |
| 796 | "0108" "09710000000156f0" |
| 797 | /* 5 auth vectors... */ |
| 798 | /* TL TL rand */ |
| 799 | "0362" "2010" "39fa2f4e3d523d8619a73b4f65c3e14d" |
| 800 | /* TL sres TL kc */ |
| 801 | "2104" "9b36efdf" "2208" "059a4f668f6fbe39" |
| 802 | /* TL 3G IK */ |
| 803 | "2310" "27497388b6cb044648f396aa155b95ef" |
| 804 | /* TL 3G CK */ |
| 805 | "2410" "f64735036e5871319c679f4742a75ea1" |
| 806 | /* TL AUTN */ |
| 807 | "2510" "8704f5ba55f30000d2ee44b22c8ea919" |
| 808 | /* TL RES */ |
| 809 | "2708" "e229c19e791f2e41" |
| 810 | /* TL TL rand */ |
| 811 | "0362" "2010" "c187a53a5e6b9d573cac7c74451fd46d" |
| 812 | "2104" "85aa3130" "2208" "d3d50a000bf04f6e" |
| 813 | "2310" "1159ec926a50e98c034a6b7d7c9f418d" |
| 814 | "2410" "df3a03d9ca5335641efc8e36d76cd20b" |
| 815 | "2510" "1843a645b98d00005b2d666af46c45d9" |
| 816 | "2708" "7db47cf7f81e4dc7" |
| 817 | "0362" "2010" "efa9c29a9742148d5c9070348716e1bb" |
| 818 | "2104" "69d5f9fb" "2208" "3df176f0c29f1a3d" |
| 819 | "2310" "eb50e770ddcc3060101d2f43b6c2b884" |
| 820 | "2410" "76542abce5ff9345b0e8947f4c6e019c" |
| 821 | "2510" "f9375e6d41e1000096e7fe4ff1c27e39" |
| 822 | "2708" "706f996719ba609c" |
| 823 | "0362" "2010" "f023d5a3b24726e0631b64b3840f8253" |
| 824 | "2104" "d570c03f" "2208" "ec011be8919883d6" |
| 825 | "2310" "c4e58af4ba43f3bcd904e16984f086d7" |
| 826 | "2410" "0593f65e752e5cb7f473862bda05aa0a" |
| 827 | "2510" "541ff1f077270000c5ea00d658bc7e9a" |
| 828 | "2708" "3fd26072eaa2a04d" |
| 829 | "0362" "2010" "2f8f90c780d6a9c0c53da7ac57b6707e" |
| 830 | "2104" "b072446f220823f39f9f425ad6e6" |
| 831 | "2310" "65af0527fda95b0dc5ae4aa515cdf32f" |
| 832 | "2410" "537c3b35a3b13b08d08eeb28098f45cc" |
| 833 | "2510" "4bf4e564f75300009bc796706bc65744" |
| 834 | "2708" "0edb0eadbea94ac2", |
| 835 | NULL); |
| 836 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 837 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 838 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 839 | if (via_ran == OSMO_RAT_GERAN_A) |
Neels Hofmeyr | 31adcae | 2018-03-10 04:08:45 +0100 | [diff] [blame] | 840 | btw("MS sends Authen Response of wrong RES size, VLR thwarts:" |
| 841 | " GERAN reports an SRES mismatch"); |
| 842 | else |
| 843 | btw("MS sends Authen Response of wrong RES size, VLR thwarts:" |
| 844 | " UTRAN disallows GSM AKA altogether"); |
| 845 | gsup_expect_tx("0b010809710000000156f0"); /* OSMO_GSUP_MSGT_AUTH_FAIL_REPORT */ |
| 846 | expect_release_clear(via_ran); |
| 847 | ms_sends_msg("0554" "e229c19e" /* Only the SRES half of the RES */); |
| 848 | VERBOSE_ASSERT(lu_result_sent, == RES_REJECT, "%d"); |
| 849 | ASSERT_RELEASE_CLEAR(via_ran); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 850 | bss_rnc_sends_release_clear_complete(via_ran); |
Neels Hofmeyr | 31adcae | 2018-03-10 04:08:45 +0100 | [diff] [blame] | 851 | |
| 852 | EXPECT_CONN_COUNT(0); |
| 853 | clear_vlr(); |
| 854 | } |
| 855 | |
| 856 | static void test_umts_authen_only_sres_geran() |
| 857 | { |
| 858 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 859 | _test_umts_authen_only_sres(OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 31adcae | 2018-03-10 04:08:45 +0100 | [diff] [blame] | 860 | comment_end(); |
| 861 | } |
| 862 | |
| 863 | static void test_umts_authen_only_sres_utran() |
| 864 | { |
| 865 | comment_start(); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 866 | _test_umts_authen_only_sres(OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | 31adcae | 2018-03-10 04:08:45 +0100 | [diff] [blame] | 867 | comment_end(); |
| 868 | } |
| 869 | |
Neels Hofmeyr | 15ed426 | 2018-03-10 04:02:44 +0100 | [diff] [blame] | 870 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 871 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 872 | test_umts_authen_geran, |
| 873 | test_umts_authen_utran, |
| 874 | test_umts_authen_resync_geran, |
| 875 | test_umts_authen_resync_utran, |
Neels Hofmeyr | 15ed426 | 2018-03-10 04:02:44 +0100 | [diff] [blame] | 876 | test_umts_authen_too_short_res_geran, |
| 877 | test_umts_authen_too_short_res_utran, |
Neels Hofmeyr | c6d20dd | 2018-03-10 04:03:43 +0100 | [diff] [blame] | 878 | test_umts_authen_too_long_res_geran, |
| 879 | test_umts_authen_too_long_res_utran, |
Neels Hofmeyr | 31adcae | 2018-03-10 04:08:45 +0100 | [diff] [blame] | 880 | test_umts_authen_only_sres_geran, |
| 881 | test_umts_authen_only_sres_utran, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 882 | NULL |
| 883 | }; |