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 | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 26 | static void test_ciph() |
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 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 34 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 35 | |
| 36 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 37 | lu_result_sent = RES_NONE; |
| 38 | gsup_expect_tx("08010809710000004026f0"); |
| 39 | ms_sends_msg("050802008168000130089910070000006402"); |
| 40 | OSMO_ASSERT(gsup_tx_confirmed); |
| 41 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 42 | |
| 43 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 44 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 45 | auth_request_sent = false; |
| 46 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 47 | auth_request_expect_autn = NULL; |
| 48 | gsup_rx("0a" |
| 49 | /* imsi */ |
| 50 | "0108" "09710000004026f0" |
| 51 | /* 5 auth vectors... */ |
| 52 | /* TL TL rand */ |
| 53 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 54 | /* TL sres TL kc */ |
| 55 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 56 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 57 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 58 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 59 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 60 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 61 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 62 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 63 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 64 | NULL); |
| 65 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 66 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 67 | |
| 68 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 69 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 70 | ms_sends_msg("05542d8b2c3e"); |
| 71 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 72 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 73 | |
| 74 | btw("needs ciph, not yet accepted"); |
| 75 | EXPECT_ACCEPTED(false); |
| 76 | thwart_rx_non_initial_requests(); |
| 77 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 78 | |
| 79 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 80 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 81 | ms_sends_msg("0632"); |
| 82 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 83 | |
| 84 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 85 | gsup_rx("10010809710000004026f00804036470f1", |
| 86 | "12010809710000004026f0"); |
| 87 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 88 | |
| 89 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 90 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 91 | gsup_rx("06010809710000004026f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 92 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 93 | |
| 94 | btw("LU was successful, and the conn has already been closed"); |
| 95 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 96 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 97 | EXPECT_CONN_COUNT(0); |
| 98 | |
| 99 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 100 | cm_service_result_sent = RES_NONE; |
| 101 | auth_request_sent = false; |
| 102 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 103 | ms_sends_msg("05247803305886089910070000006402"); |
| 104 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 4d3a66b | 2018-03-31 18:45:59 +0200 | [diff] [blame] | 105 | OSMO_ASSERT(g_conn->fi); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 106 | OSMO_ASSERT(g_conn->vsub); |
| 107 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 108 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 109 | |
| 110 | btw("needs auth, not yet accepted"); |
| 111 | EXPECT_ACCEPTED(false); |
| 112 | thwart_rx_non_initial_requests(); |
| 113 | |
| 114 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 115 | expect_cipher_mode_cmd("07fa7502e07e1c00"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 116 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 117 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 118 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 119 | |
| 120 | btw("needs ciph, not yet accepted"); |
| 121 | EXPECT_ACCEPTED(false); |
| 122 | thwart_rx_non_initial_requests(); |
| 123 | |
| 124 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 125 | ms_sends_msg("0632"); |
| 126 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 127 | |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 128 | /* Release connection */ |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 129 | expect_bssap_clear(OSMO_RAT_GERAN_A); |
| 130 | conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 131 | |
| 132 | btw("all requests serviced, conn has been released"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 133 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 134 | EXPECT_CONN_COUNT(0); |
| 135 | |
| 136 | BTW("an SMS is sent, MS is paged"); |
| 137 | paging_expect_imsi(imsi); |
| 138 | paging_sent = false; |
| 139 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 140 | OSMO_ASSERT(vsub); |
| 141 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 142 | |
| 143 | send_sms(vsub, vsub, |
| 144 | "Privacy in residential applications is a desirable" |
| 145 | " marketing option."); |
| 146 | |
| 147 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 148 | vlr_subscr_put(vsub); |
| 149 | vsub = NULL; |
| 150 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 151 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 152 | |
| 153 | btw("the subscriber and its pending request should remain"); |
| 154 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 155 | OSMO_ASSERT(vsub); |
| 156 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 157 | vlr_subscr_put(vsub); |
| 158 | |
| 159 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 160 | auth_request_sent = false; |
| 161 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 162 | ms_sends_msg("06270703305882089910070000006402"); |
| 163 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 164 | |
| 165 | btw("needs auth, not yet accepted"); |
| 166 | EXPECT_ACCEPTED(false); |
| 167 | thwart_rx_non_initial_requests(); |
| 168 | |
| 169 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 170 | expect_cipher_mode_cmd("e2b234f807886400"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 171 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 172 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 173 | |
| 174 | btw("needs ciph, not yet accepted"); |
| 175 | EXPECT_ACCEPTED(false); |
| 176 | thwart_rx_non_initial_requests(); |
| 177 | |
| 178 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 179 | dtap_expect_tx("09" /* SMS messages */ |
| 180 | "01" /* CP-DATA */ |
| 181 | "58" /* length */ |
| 182 | "01" /* Network to MS */ |
| 183 | "00" /* reference */ |
| 184 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 185 | "0791" "447758100650" /* 447785016005 */ |
| 186 | "00" /* dest */ |
| 187 | /* SMS TPDU */ |
| 188 | "4c" /* len */ |
| 189 | "00" /* SMS deliver */ |
| 190 | "05806470f1" /* originating address 46071 */ |
| 191 | "00" /* TP-PID */ |
| 192 | "00" /* GSM default alphabet */ |
| 193 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 194 | "000000" /* H-M-S */ |
| 195 | "00" /* GMT+0 */ |
| 196 | "44" /* data length */ |
| 197 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 198 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 199 | "0c7ac3e9e9b7db05"); |
| 200 | ms_sends_msg("0632"); |
| 201 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 202 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 203 | |
| 204 | btw("SMS was delivered, no requests pending for subscr"); |
| 205 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 206 | OSMO_ASSERT(vsub); |
| 207 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 208 | vlr_subscr_put(vsub); |
| 209 | |
| 210 | btw("conn is still open to wait for SMS ack dance"); |
| 211 | EXPECT_CONN_COUNT(1); |
| 212 | |
| 213 | btw("MS replies with CP-ACK for received SMS"); |
| 214 | ms_sends_msg("8904"); |
| 215 | EXPECT_CONN_COUNT(1); |
| 216 | |
| 217 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 218 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 219 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 220 | ms_sends_msg("890106020041020000"); |
| 221 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 222 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 223 | |
| 224 | btw("SMS is done, conn is gone"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 225 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 226 | EXPECT_CONN_COUNT(0); |
| 227 | |
| 228 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 229 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 230 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 231 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 232 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 233 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 234 | EXPECT_CONN_COUNT(0); |
| 235 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 236 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 237 | } |
| 238 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 239 | static void test_ciph_tmsi() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 240 | { |
| 241 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 242 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 243 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 244 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 245 | |
| 246 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 247 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 248 | net->vlr->cfg.assign_tmsi = true; |
| 249 | |
| 250 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 251 | lu_result_sent = RES_NONE; |
| 252 | gsup_expect_tx("08010809710000004026f0"); |
| 253 | ms_sends_msg("050802008168000130089910070000006402"); |
| 254 | OSMO_ASSERT(gsup_tx_confirmed); |
| 255 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 256 | |
| 257 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 258 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 259 | auth_request_sent = false; |
| 260 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 261 | auth_request_expect_autn = NULL; |
| 262 | gsup_rx("0a" |
| 263 | /* imsi */ |
| 264 | "0108" "09710000004026f0" |
| 265 | /* 5 auth vectors... */ |
| 266 | /* TL TL rand */ |
| 267 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 268 | /* TL sres TL kc */ |
| 269 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 270 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 271 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 272 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 273 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 274 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 275 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 276 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 277 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 278 | NULL); |
| 279 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 280 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 281 | |
| 282 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 283 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 284 | ms_sends_msg("05542d8b2c3e"); |
| 285 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 286 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 287 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 288 | |
| 289 | btw("needs ciph, not yet accepted"); |
| 290 | EXPECT_ACCEPTED(false); |
| 291 | thwart_rx_non_initial_requests(); |
| 292 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 293 | |
| 294 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 295 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 296 | ms_sends_msg("0632"); |
| 297 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 298 | |
| 299 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 300 | gsup_rx("10010809710000004026f00804036470f1", |
| 301 | "12010809710000004026f0"); |
| 302 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 303 | |
| 304 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 305 | gsup_rx("06010809710000004026f0", NULL); |
| 306 | |
| 307 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 308 | EXPECT_CONN_COUNT(1); |
| 309 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 310 | EXPECT_ACCEPTED(false); |
| 311 | thwart_rx_non_initial_requests(); |
| 312 | |
| 313 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 314 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 315 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 316 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 317 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 318 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 319 | vlr_subscr_put(vsub); |
| 320 | |
| 321 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 322 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 323 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 324 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 325 | |
| 326 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 327 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 328 | EXPECT_CONN_COUNT(0); |
| 329 | |
| 330 | btw("Subscriber has the new TMSI"); |
| 331 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 332 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 333 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 334 | VERBOSE_ASSERT(vsub->tmsi_new, == GSM_RESERVED_TMSI, "0x%08x"); |
| 335 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 336 | vlr_subscr_put(vsub); |
| 337 | |
| 338 | BTW("after a while, a new conn sends a CM Service Request using above TMSI. VLR responds with Auth Req, 2nd auth vector"); |
| 339 | cm_service_result_sent = RES_NONE; |
| 340 | auth_request_sent = false; |
| 341 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 342 | auth_request_expect_autn = NULL; |
| 343 | ms_sends_msg("05247803305886" "05f4" "03020100"); |
| 344 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 4d3a66b | 2018-03-31 18:45:59 +0200 | [diff] [blame] | 345 | OSMO_ASSERT(g_conn->fi); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 346 | OSMO_ASSERT(g_conn->vsub); |
| 347 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 348 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 349 | |
| 350 | btw("needs auth, not yet accepted"); |
| 351 | EXPECT_ACCEPTED(false); |
| 352 | thwart_rx_non_initial_requests(); |
| 353 | |
| 354 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 355 | expect_cipher_mode_cmd("07fa7502e07e1c00"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 356 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 357 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 358 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 359 | |
| 360 | btw("needs ciph, not yet accepted"); |
| 361 | EXPECT_ACCEPTED(false); |
| 362 | thwart_rx_non_initial_requests(); |
| 363 | |
| 364 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 365 | ms_sends_msg("0632"); |
| 366 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 367 | |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 368 | /* Release connection */ |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 369 | expect_bssap_clear(OSMO_RAT_GERAN_A); |
| 370 | conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 371 | |
| 372 | btw("all requests serviced, conn has been released"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 373 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 374 | EXPECT_CONN_COUNT(0); |
| 375 | |
| 376 | BTW("an SMS is sent, MS is paged"); |
| 377 | paging_expect_tmsi(0x03020100); |
| 378 | paging_sent = false; |
| 379 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 380 | OSMO_ASSERT(vsub); |
| 381 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 382 | |
| 383 | send_sms(vsub, vsub, |
| 384 | "Privacy in residential applications is a desirable" |
| 385 | " marketing option."); |
| 386 | |
| 387 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 388 | vlr_subscr_put(vsub); |
| 389 | vsub = NULL; |
| 390 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 391 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 392 | |
| 393 | btw("the subscriber and its pending request should remain"); |
| 394 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 395 | OSMO_ASSERT(vsub); |
| 396 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 397 | vlr_subscr_put(vsub); |
| 398 | |
| 399 | btw("MS replies with Paging Response using TMSI, and VLR sends Auth Request with third key"); |
| 400 | auth_request_sent = false; |
| 401 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 402 | ms_sends_msg("06270703305882" "05f4" "03020100"); |
| 403 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 404 | |
| 405 | btw("needs auth, not yet accepted"); |
| 406 | EXPECT_ACCEPTED(false); |
| 407 | thwart_rx_non_initial_requests(); |
| 408 | |
| 409 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 410 | expect_cipher_mode_cmd("e2b234f807886400"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 411 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 412 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 413 | |
| 414 | btw("needs ciph, not yet accepted"); |
| 415 | EXPECT_ACCEPTED(false); |
| 416 | thwart_rx_non_initial_requests(); |
| 417 | |
| 418 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 419 | dtap_expect_tx("09" /* SMS messages */ |
| 420 | "01" /* CP-DATA */ |
| 421 | "58" /* length */ |
| 422 | "01" /* Network to MS */ |
| 423 | "00" /* reference */ |
| 424 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 425 | "0791" "447758100650" /* 447785016005 */ |
| 426 | "00" /* dest */ |
| 427 | /* SMS TPDU */ |
| 428 | "4c" /* len */ |
| 429 | "00" /* SMS deliver */ |
| 430 | "05806470f1" /* originating address 46071 */ |
| 431 | "00" /* TP-PID */ |
| 432 | "00" /* GSM default alphabet */ |
| 433 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 434 | "000000" /* H-M-S */ |
| 435 | "00" /* GMT+0 */ |
| 436 | "44" /* data length */ |
| 437 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 438 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 439 | "0c7ac3e9e9b7db05"); |
| 440 | ms_sends_msg("0632"); |
| 441 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 442 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 443 | |
| 444 | btw("SMS was delivered, no requests pending for subscr"); |
| 445 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 446 | OSMO_ASSERT(vsub); |
| 447 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 448 | vlr_subscr_put(vsub); |
| 449 | |
| 450 | btw("conn is still open to wait for SMS ack dance"); |
| 451 | EXPECT_CONN_COUNT(1); |
| 452 | |
| 453 | btw("MS replies with CP-ACK for received SMS"); |
| 454 | ms_sends_msg("8904"); |
| 455 | EXPECT_CONN_COUNT(1); |
| 456 | |
| 457 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 458 | dtap_expect_tx("0904"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 459 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 460 | ms_sends_msg("890106020041020000"); |
| 461 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 462 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 463 | |
| 464 | btw("SMS is done, conn is gone"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 465 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 466 | EXPECT_CONN_COUNT(0); |
| 467 | |
| 468 | BTW("subscriber detaches, using TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 469 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 470 | ms_sends_msg("050130" "05f4" "03020100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 471 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 472 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 473 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 474 | EXPECT_CONN_COUNT(0); |
| 475 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 476 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 479 | static void test_ciph_imei() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 480 | { |
| 481 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 482 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 483 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 484 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 485 | |
| 486 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 487 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 488 | net->vlr->cfg.check_imei_rqd = true; |
| 489 | |
| 490 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 491 | lu_result_sent = RES_NONE; |
| 492 | gsup_expect_tx("08010809710000004026f0"); |
| 493 | ms_sends_msg("050802008168000130089910070000006402"); |
| 494 | OSMO_ASSERT(gsup_tx_confirmed); |
| 495 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 496 | |
| 497 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 498 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 499 | auth_request_sent = false; |
| 500 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 501 | auth_request_expect_autn = NULL; |
| 502 | gsup_rx("0a" |
| 503 | /* imsi */ |
| 504 | "0108" "09710000004026f0" |
| 505 | /* 5 auth vectors... */ |
| 506 | /* TL TL rand */ |
| 507 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 508 | /* TL sres TL kc */ |
| 509 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 510 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 511 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 512 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 513 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 514 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 515 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 516 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 517 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 518 | NULL); |
| 519 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 520 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 521 | |
| 522 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 523 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 524 | ms_sends_msg("05542d8b2c3e"); |
| 525 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 526 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 527 | |
| 528 | btw("needs ciph, not yet accepted"); |
| 529 | EXPECT_ACCEPTED(false); |
| 530 | thwart_rx_non_initial_requests(); |
| 531 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 532 | |
| 533 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 534 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 535 | ms_sends_msg("0632"); |
| 536 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 537 | |
| 538 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 539 | gsup_rx("10010809710000004026f00804036470f1", |
| 540 | "12010809710000004026f0"); |
| 541 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 542 | |
| 543 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 544 | dtap_expect_tx("051802"); |
| 545 | gsup_rx("06010809710000004026f0", NULL); |
| 546 | |
| 547 | btw("We will only do business when the IMEI is known"); |
| 548 | EXPECT_CONN_COUNT(1); |
| 549 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 550 | OSMO_ASSERT(vsub); |
| 551 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 552 | vlr_subscr_put(vsub); |
| 553 | EXPECT_ACCEPTED(false); |
| 554 | thwart_rx_non_initial_requests(); |
| 555 | |
Oliver Smith | 7d05309 | 2018-12-14 17:37:38 +0100 | [diff] [blame] | 556 | btw("MS replies with an Identity Response, VLR sends the IMEI to HLR"); |
| 557 | gsup_expect_tx("30010809710000004026f050090824433224433224f0"); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 558 | ms_sends_msg("0559084a32244332244302"); |
Oliver Smith | 7d05309 | 2018-12-14 17:37:38 +0100 | [diff] [blame] | 559 | EXPECT_ACCEPTED(false); |
| 560 | thwart_rx_non_initial_requests(); |
| 561 | |
| 562 | btw("HLR accepts the IMEI"); |
| 563 | expect_bssap_clear(); |
| 564 | gsup_rx("32010809710000004026f0510100", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 565 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 566 | |
| 567 | btw("LU was successful, and the conn has already been closed"); |
| 568 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 569 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 570 | EXPECT_CONN_COUNT(0); |
| 571 | |
| 572 | btw("Subscriber has the IMEI"); |
| 573 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 574 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 575 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 576 | vlr_subscr_put(vsub); |
| 577 | |
| 578 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 579 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 580 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 581 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 582 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 583 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 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 | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 589 | static void test_ciph_imeisv() |
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 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 597 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 54a706c | 2017-07-18 15:39:27 +0200 | [diff] [blame] | 598 | net->vlr->cfg.retrieve_imeisv_ciphered = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 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 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 609 | auth_request_sent = false; |
| 610 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 611 | auth_request_expect_autn = NULL; |
| 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("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 633 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 634 | ms_sends_msg("05542d8b2c3e"); |
| 635 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 636 | VERBOSE_ASSERT(cipher_mode_cmd_sent_with_imeisv, == true, "%d"); |
| 637 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 638 | |
| 639 | btw("needs ciph, not yet accepted"); |
| 640 | EXPECT_ACCEPTED(false); |
| 641 | thwart_rx_non_initial_requests(); |
| 642 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 643 | |
| 644 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 645 | OSMO_ASSERT(vsub); |
| 646 | VERBOSE_ASSERT(vsub->imeisv[0], == 0, "%d"); |
| 647 | vlr_subscr_put(vsub); |
| 648 | |
| 649 | btw("MS sends Ciphering Mode Complete with IMEISV, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 650 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 651 | ms_sends_msg("063217094b32244332244372f5"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 652 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 653 | |
| 654 | btw("Subscriber has the IMEISV"); |
| 655 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 656 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 657 | VERBOSE_ASSERT(strcmp(vsub->imeisv, "4234234234234275"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 658 | vlr_subscr_put(vsub); |
| 659 | |
| 660 | EXPECT_ACCEPTED(false); |
| 661 | thwart_rx_non_initial_requests(); |
| 662 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 663 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 664 | gsup_rx("10010809710000004026f00804036470f1", |
| 665 | "12010809710000004026f0"); |
| 666 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 667 | |
| 668 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 669 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 670 | gsup_rx("06010809710000004026f0", NULL); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 671 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 672 | |
| 673 | btw("LU was successful, and the conn has already been closed"); |
| 674 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 675 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 676 | EXPECT_CONN_COUNT(0); |
| 677 | |
| 678 | BTW("subscriber detaches"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 679 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 680 | ms_sends_msg("050130089910070000006402"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 681 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 682 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 683 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 684 | EXPECT_CONN_COUNT(0); |
| 685 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 686 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 687 | } |
| 688 | |
Neels Hofmeyr | f3d81f6 | 2018-03-02 01:05:38 +0100 | [diff] [blame] | 689 | static void test_ciph_tmsi_imei() |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 690 | { |
| 691 | struct vlr_subscr *vsub; |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 692 | const char *imsi = "901700000004620"; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 693 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 694 | comment_start(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 695 | |
| 696 | /* implicit: net->authentication_required = true; */ |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 697 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 698 | net->vlr->cfg.assign_tmsi = true; |
| 699 | net->vlr->cfg.check_imei_rqd = true; |
| 700 | |
| 701 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 702 | lu_result_sent = RES_NONE; |
| 703 | gsup_expect_tx("08010809710000004026f0"); |
| 704 | ms_sends_msg("050802008168000130089910070000006402"); |
| 705 | OSMO_ASSERT(gsup_tx_confirmed); |
| 706 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 707 | |
| 708 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 709 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 710 | auth_request_sent = false; |
| 711 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 712 | auth_request_expect_autn = NULL; |
| 713 | gsup_rx("0a" |
| 714 | /* imsi */ |
| 715 | "0108" "09710000004026f0" |
| 716 | /* 5 auth vectors... */ |
| 717 | /* TL TL rand */ |
| 718 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 719 | /* TL sres TL kc */ |
| 720 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 721 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 722 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 723 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 724 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 725 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 726 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 727 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 728 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 729 | NULL); |
| 730 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 731 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 732 | |
| 733 | btw("MS sends Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 734 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 735 | ms_sends_msg("05542d8b2c3e"); |
| 736 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 737 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 738 | |
| 739 | btw("needs ciph, not yet accepted"); |
| 740 | EXPECT_ACCEPTED(false); |
| 741 | thwart_rx_non_initial_requests(); |
| 742 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 743 | |
| 744 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 745 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 746 | ms_sends_msg("0632"); |
| 747 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 748 | |
| 749 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 750 | gsup_rx("10010809710000004026f00804036470f1", |
| 751 | "12010809710000004026f0"); |
| 752 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 753 | |
| 754 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT, and we send an ID Request for the IMEI to the MS"); |
| 755 | dtap_expect_tx("051802"); |
| 756 | gsup_rx("06010809710000004026f0", NULL); |
| 757 | |
| 758 | btw("We will only do business when the IMEI is known"); |
| 759 | EXPECT_CONN_COUNT(1); |
| 760 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 761 | OSMO_ASSERT(vsub); |
| 762 | VERBOSE_ASSERT(vsub->imei[0], == 0, "%d"); |
| 763 | vlr_subscr_put(vsub); |
| 764 | EXPECT_ACCEPTED(false); |
| 765 | thwart_rx_non_initial_requests(); |
| 766 | |
Oliver Smith | 7d05309 | 2018-12-14 17:37:38 +0100 | [diff] [blame] | 767 | btw("MS replies with an Identity Response, VLR sends the IMEI to HLR"); |
| 768 | gsup_expect_tx("30010809710000004026f050090824433224433224f0"); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 769 | ms_sends_msg("0559084a32244332244302"); |
Oliver Smith | 7d05309 | 2018-12-14 17:37:38 +0100 | [diff] [blame] | 770 | EXPECT_ACCEPTED(false); |
| 771 | thwart_rx_non_initial_requests(); |
| 772 | |
| 773 | btw("HLR accepts the IMEI"); |
| 774 | gsup_rx("32010809710000004026f0510100", NULL); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 775 | |
| 776 | btw("a LU Accept with a new TMSI was sent, waiting for TMSI Realloc Compl"); |
| 777 | EXPECT_CONN_COUNT(1); |
| 778 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 779 | EXPECT_ACCEPTED(false); |
| 780 | thwart_rx_non_initial_requests(); |
| 781 | |
| 782 | btw("even though the TMSI is not acked, we can already find the subscr with it"); |
| 783 | vsub = vlr_subscr_find_by_tmsi(net->vlr, 0x03020100); |
| 784 | VERBOSE_ASSERT(vsub != NULL, == true, "%d"); |
| 785 | VERBOSE_ASSERT(strcmp(vsub->imsi, imsi), == 0, "%d"); |
| 786 | VERBOSE_ASSERT(vsub->tmsi_new, == 0x03020100, "0x%08x"); |
| 787 | VERBOSE_ASSERT(vsub->tmsi, == GSM_RESERVED_TMSI, "0x%08x"); |
| 788 | vlr_subscr_put(vsub); |
| 789 | |
| 790 | btw("MS sends TMSI Realloc Complete"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 791 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 792 | ms_sends_msg("055b"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 793 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 794 | |
| 795 | btw("LU was successful, and the conn has already been closed"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 796 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 797 | EXPECT_CONN_COUNT(0); |
| 798 | |
| 799 | btw("Subscriber has the IMEI and TMSI"); |
| 800 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 801 | OSMO_ASSERT(vsub); |
Neels Hofmeyr | 34d33bd | 2017-07-20 02:56:21 +0200 | [diff] [blame] | 802 | VERBOSE_ASSERT(strcmp(vsub->imei, "423423423423420"), == 0, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 803 | VERBOSE_ASSERT(vsub->tmsi, == 0x03020100, "0x%08x"); |
| 804 | vlr_subscr_put(vsub); |
| 805 | |
| 806 | BTW("subscriber detaches, using TMSI"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 807 | expect_bssap_clear(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 808 | ms_sends_msg("050130" "05f4" "03020100"); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 809 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 810 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 811 | bss_sends_clear_complete(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 812 | EXPECT_CONN_COUNT(0); |
| 813 | clear_vlr(); |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 814 | comment_end(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 815 | } |
| 816 | |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 817 | static void test_gsm_ciph_in_umts_env() |
| 818 | { |
| 819 | struct vlr_subscr *vsub; |
| 820 | const char *imsi = "901700000010650"; |
| 821 | const char *sms = |
| 822 | "09" /* SMS messages */ |
| 823 | "01" /* CP-DATA */ |
| 824 | "58" /* length */ |
| 825 | "01" /* Network to MS */ |
| 826 | "00" /* reference */ |
| 827 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 828 | "0791" "447758100650" /* 447785016005 */ |
| 829 | "00" /* dest */ |
| 830 | /* SMS TPDU */ |
| 831 | "4c" /* len */ |
| 832 | "00" /* SMS deliver */ |
| 833 | "05802443f2" /* originating address 42342 */ |
| 834 | "00" /* TP-PID */ |
| 835 | "00" /* GSM default alphabet */ |
| 836 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 837 | "000000" /* H-M-S */ |
| 838 | "00" /* GMT+0 */ |
| 839 | "44" /* data length */ |
| 840 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 841 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 842 | "0c7ac3e9e9b7db05"; |
| 843 | |
| 844 | comment_start(); |
| 845 | |
| 846 | /* implicit: net->authentication_required = true; */ |
| 847 | net->a5_encryption_mask = (1 << 1); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 848 | rx_from_ran = OSMO_RAT_GERAN_A; |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 849 | |
| 850 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 851 | lu_result_sent = RES_NONE; |
| 852 | gsup_expect_tx("080108" "09710000000156f0"); |
| 853 | ms_sends_msg("0508" /* MM LU */ |
| 854 | "7" /* ciph key seq: no key available */ |
| 855 | "0" /* LU type: normal */ |
| 856 | "ffffff" "0000" /* LAI, LAC */ |
| 857 | "57" /* classmark 1: R99, early classmark, no power lvl */ |
| 858 | "089910070000106005" /* IMSI */ |
| 859 | "3303575886" /* classmark 2 */ |
| 860 | ); |
| 861 | OSMO_ASSERT(gsup_tx_confirmed); |
| 862 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 863 | |
| 864 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends *UMTS AKA* Auth Req to MS"); |
| 865 | /* based on |
| 866 | * 2G auth: COMP128v1 |
| 867 | * KI=7bcd108be4c3d551ee6c67faaf52bd68 |
| 868 | * 3G auth: MILENAGE |
| 869 | * K=7bcd108be4c3d551ee6c67faaf52bd68 |
| 870 | * OPC=6e23f641ce724679b73d933515a8589d |
| 871 | * IND-bitlen=5 last-SQN=641 |
| 872 | * Note that the SRES will be calculated by COMP128v1, separately from 3G tokens; |
| 873 | * the resulting Kc to use for ciphering returned by the HLR is also calculated from COMP128v1. |
| 874 | */ |
| 875 | auth_request_sent = false; |
| 876 | auth_request_expect_rand = "4ac8d1cd1a51937597ca1016fe69a0fa"; |
| 877 | auth_request_expect_autn = "2d837d2b0d6f00004b282d5acf23428d"; |
| 878 | gsup_rx("0a" |
| 879 | /* imsi */ |
| 880 | "0108" "09710000000156f0" |
| 881 | /* 5 auth vectors... */ |
| 882 | /* TL TL rand */ |
| 883 | "0362" "2010" "4ac8d1cd1a51937597ca1016fe69a0fa" |
| 884 | /* TL sres TL kc */ |
| 885 | "2104" "dacc4b26" "2208" "7a75f0ac9b844400" |
| 886 | /* TL 3G IK */ |
| 887 | "2310" "3747da4e31545baa2db59e500bdae047" |
| 888 | /* TL 3G CK */ |
| 889 | "2410" "8544d35b945ccba01a7f1293575291c3" |
| 890 | /* TL AUTN */ |
| 891 | "2510" "2d837d2b0d6f00004b282d5acf23428d" |
| 892 | /* TL RES */ |
| 893 | "2708" "37527064741f8ddb" |
| 894 | /* TL TL rand */ |
| 895 | "0362" "2010" "b2661531b97b12c5a2edc21a0ed16fc5" |
| 896 | "2104" "2fb4cfad" "2208" "da149b11d473f400" |
| 897 | "2310" "3fe013b1a428ea737c37f8f0288c8edf" |
| 898 | "2410" "f275438c02b97e4d6f639dddda3d10b9" |
| 899 | "2510" "78cdd96c60840000322f421b3bb778b1" |
| 900 | "2708" "ed3ebf9cb6ea48ed" |
| 901 | "0362" "2010" "54d8f19778056666b41c8c25e52eb60c" |
| 902 | "2104" "0ff61e0f" "2208" "26ec67fad3073000" |
| 903 | "2310" "2868b0922c652616f1c975e3eaf7943a" |
| 904 | "2410" "6a84a20b1bc13ec9840466406d2dd91e" |
| 905 | "2510" "53f3e5632b3d00008865dd54d49663f2" |
| 906 | "2708" "86e848a9e7ad8cd5" |
| 907 | "0362" "2010" "1f05607ff9c8984f46ad97f8c9a94982" |
| 908 | "2104" "91a36e3d" "2208" "5d84421884fdcc00" |
| 909 | "2310" "2171fef54b81e30c83a598a5e44f634c" |
| 910 | "2410" "f02d088697509827565b46938fece211" |
| 911 | "2510" "1b43bbf9815e00001cb9b2a9f6b8a77c" |
| 912 | "2708" "373e67d62e719c51" |
| 913 | "0362" "2010" "80d89a58a2a41050918caf68a4e93c64" |
| 914 | "2104" "a319f5f1" "2208" "883df2b867293000" |
| 915 | "2310" "fa5d70f929ff298efb160413698dc107" |
| 916 | "2410" "ae9a3d8ce70ce13bac297bdb91cd6c68" |
| 917 | "2510" "5c0dc2eeaefa0000396882a1fe2cf80b" |
| 918 | "2708" "65ab1cad216bfe87", |
| 919 | NULL); |
| 920 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 921 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 922 | |
| 923 | btw("MS sends *GSM AKA* Authen Response, VLR accepts and sends Ciphering Mode Command to MS"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 924 | expect_cipher_mode_cmd("7a75f0ac9b844400"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 925 | ms_sends_msg("0554" "dacc4b26"); |
| 926 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 927 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 928 | |
| 929 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 930 | gsup_expect_tx("04010809710000000156f0280102"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 931 | ms_sends_msg("0632"); |
| 932 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 933 | |
| 934 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 935 | gsup_rx("10010809710000000156f00804032443f2", |
| 936 | "12010809710000000156f0"); |
| 937 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 938 | |
| 939 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 940 | expect_bssap_clear(); |
| 941 | gsup_rx("06010809710000000156f0", NULL); |
| 942 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 943 | |
| 944 | btw("LU was successful, and the conn has already been closed"); |
| 945 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 946 | bss_sends_clear_complete(); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 947 | EXPECT_CONN_COUNT(0); |
| 948 | |
| 949 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with *UMTS AKA* Auth Req, 2nd auth vector"); |
| 950 | auth_request_sent = false; |
| 951 | auth_request_expect_rand = "b2661531b97b12c5a2edc21a0ed16fc5"; |
| 952 | auth_request_expect_autn = "78cdd96c60840000322f421b3bb778b1"; |
| 953 | cm_service_result_sent = RES_NONE; |
| 954 | ms_sends_msg("052478" |
| 955 | "03575886" /* classmark 2 */ |
| 956 | "089910070000106005" /* IMSI */); |
| 957 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 4d3a66b | 2018-03-31 18:45:59 +0200 | [diff] [blame] | 958 | OSMO_ASSERT(g_conn->fi); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 959 | OSMO_ASSERT(g_conn->vsub); |
| 960 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 961 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 962 | |
| 963 | btw("needs auth, not yet accepted"); |
| 964 | EXPECT_ACCEPTED(false); |
| 965 | thwart_rx_non_initial_requests(); |
| 966 | |
| 967 | btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 968 | expect_cipher_mode_cmd("da149b11d473f400"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 969 | ms_sends_msg("0554" "2fb4cfad"); |
| 970 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 971 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 972 | |
| 973 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 974 | ms_sends_msg("0632"); |
| 975 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 976 | |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 977 | /* Release connection */ |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 978 | expect_bssap_clear(OSMO_RAT_GERAN_A); |
| 979 | conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 980 | |
| 981 | btw("all requests serviced, conn has been released"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 982 | bss_sends_clear_complete(); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 983 | EXPECT_CONN_COUNT(0); |
| 984 | |
| 985 | BTW("an SMS is sent, MS is paged"); |
| 986 | paging_expect_imsi(imsi); |
| 987 | paging_sent = false; |
| 988 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 989 | OSMO_ASSERT(vsub); |
| 990 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 991 | |
| 992 | send_sms(vsub, vsub, |
| 993 | "Privacy in residential applications is a desirable" |
| 994 | " marketing option."); |
| 995 | |
| 996 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 997 | vlr_subscr_put(vsub); |
| 998 | vsub = NULL; |
| 999 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 1000 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 1001 | |
| 1002 | btw("the subscriber and its pending request should remain"); |
| 1003 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1004 | OSMO_ASSERT(vsub); |
| 1005 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 1006 | vlr_subscr_put(vsub); |
| 1007 | |
| 1008 | btw("MS replies with Paging Response, and VLR sends *UMTS AKA* Auth Request with third key"); |
| 1009 | auth_request_sent = false; |
| 1010 | auth_request_expect_rand = "54d8f19778056666b41c8c25e52eb60c"; |
| 1011 | auth_request_expect_autn = "53f3e5632b3d00008865dd54d49663f2"; |
| 1012 | ms_sends_msg("062707" |
| 1013 | "03575886" /* classmark 2 */ |
| 1014 | "089910070000106005" /* IMSI */); |
| 1015 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1016 | |
| 1017 | btw("needs auth, not yet accepted"); |
| 1018 | EXPECT_ACCEPTED(false); |
| 1019 | thwart_rx_non_initial_requests(); |
| 1020 | |
| 1021 | btw("MS sends *GSM AKA* Authen Response, VLR accepts and requests Ciphering"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 1022 | expect_cipher_mode_cmd("26ec67fad3073000"); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 1023 | ms_sends_msg("0554" "0ff61e0f"); |
| 1024 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 1025 | |
| 1026 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 1027 | dtap_expect_tx(sms); |
| 1028 | ms_sends_msg("0632"); |
| 1029 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 1030 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 1031 | |
| 1032 | btw("SMS was delivered, no requests pending for subscr"); |
| 1033 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1034 | OSMO_ASSERT(vsub); |
| 1035 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 1036 | vlr_subscr_put(vsub); |
| 1037 | |
| 1038 | btw("conn is still open to wait for SMS ack dance"); |
| 1039 | EXPECT_CONN_COUNT(1); |
| 1040 | |
| 1041 | btw("MS replies with CP-ACK for received SMS"); |
| 1042 | ms_sends_msg("8904"); |
| 1043 | EXPECT_CONN_COUNT(1); |
| 1044 | |
| 1045 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 1046 | dtap_expect_tx("0904"); |
| 1047 | expect_bssap_clear(); |
| 1048 | ms_sends_msg("890106020041020000"); |
| 1049 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 1050 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1051 | |
| 1052 | btw("SMS is done, conn is gone"); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 1053 | bss_sends_clear_complete(); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 1054 | EXPECT_CONN_COUNT(0); |
| 1055 | |
| 1056 | BTW("subscriber detaches"); |
| 1057 | expect_bssap_clear(); |
| 1058 | ms_sends_msg("050130" |
| 1059 | "089910070000106005" /* IMSI */); |
| 1060 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1061 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 1062 | bss_sends_clear_complete(); |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 1063 | EXPECT_CONN_COUNT(0); |
| 1064 | clear_vlr(); |
| 1065 | comment_end(); |
| 1066 | } |
| 1067 | |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1068 | static void test_a5_3_supported() |
Neels Hofmeyr | a7fd88c | 2018-03-02 01:50:42 +0100 | [diff] [blame] | 1069 | { |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1070 | struct vlr_subscr *vsub; |
| 1071 | const char *imsi = "901700000004620"; |
| 1072 | |
Neels Hofmeyr | a7fd88c | 2018-03-02 01:50:42 +0100 | [diff] [blame] | 1073 | comment_start(); |
| 1074 | |
| 1075 | /* implicit: net->authentication_required = true; */ |
| 1076 | net->a5_encryption_mask = (1 << 3); /* A5/3 */ |
| 1077 | |
| 1078 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 1079 | lu_result_sent = RES_NONE; |
| 1080 | gsup_expect_tx("08010809710000004026f0"); |
| 1081 | ms_sends_msg("050802008168000130089910070000006402"); |
| 1082 | OSMO_ASSERT(gsup_tx_confirmed); |
| 1083 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1084 | |
| 1085 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 1086 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 1087 | auth_request_sent = false; |
| 1088 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 1089 | auth_request_expect_autn = NULL; |
| 1090 | gsup_rx("0a" |
| 1091 | /* imsi */ |
| 1092 | "0108" "09710000004026f0" |
| 1093 | /* 5 auth vectors... */ |
| 1094 | /* TL TL rand */ |
| 1095 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 1096 | /* TL sres TL kc */ |
| 1097 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 1098 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 1099 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 1100 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 1101 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 1102 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 1103 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 1104 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 1105 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 1106 | NULL); |
| 1107 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1108 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1109 | |
| 1110 | BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS" |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1111 | " -- but needs Classmark 2 to determine whether A5/3 is supported"); |
Neels Hofmeyr | a7fd88c | 2018-03-02 01:50:42 +0100 | [diff] [blame] | 1112 | cipher_mode_cmd_sent = false; |
Neels Hofmeyr | a7fd88c | 2018-03-02 01:50:42 +0100 | [diff] [blame] | 1113 | ms_sends_msg("05542d8b2c3e"); |
| 1114 | OSMO_ASSERT(!cipher_mode_cmd_sent); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1115 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1116 | |
| 1117 | btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3"); |
| 1118 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
| 1119 | bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100"); |
| 1120 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 1121 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1122 | |
| 1123 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 1124 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1125 | ms_sends_msg("0632"); |
| 1126 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1127 | |
| 1128 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 1129 | gsup_rx("10010809710000004026f00804032443f2", |
| 1130 | "12010809710000004026f0"); |
| 1131 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1132 | |
| 1133 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 1134 | expect_bssap_clear(); |
| 1135 | gsup_rx("06010809710000004026f0", NULL); |
| 1136 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1137 | |
| 1138 | btw("LU was successful, and the conn has already been closed"); |
| 1139 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 1140 | bss_sends_clear_complete(); |
| 1141 | EXPECT_CONN_COUNT(0); |
| 1142 | |
| 1143 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 1144 | cm_service_result_sent = RES_NONE; |
| 1145 | auth_request_sent = false; |
| 1146 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 1147 | ms_sends_msg("05247803305886089910070000006402"); |
| 1148 | OSMO_ASSERT(g_conn); |
| 1149 | OSMO_ASSERT(g_conn->fi); |
| 1150 | OSMO_ASSERT(g_conn->vsub); |
| 1151 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1152 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 1153 | |
| 1154 | btw("needs auth, not yet accepted"); |
| 1155 | EXPECT_ACCEPTED(false); |
| 1156 | thwart_rx_non_initial_requests(); |
| 1157 | |
| 1158 | btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3," |
| 1159 | " so no need to request Classmark Update."); |
| 1160 | expect_cipher_mode_cmd("07fa7502e07e1c00"); |
| 1161 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 1162 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 1163 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 1164 | |
| 1165 | btw("needs ciph, not yet accepted"); |
| 1166 | EXPECT_ACCEPTED(false); |
| 1167 | thwart_rx_non_initial_requests(); |
| 1168 | |
| 1169 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 1170 | ms_sends_msg("0632"); |
| 1171 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 1172 | |
| 1173 | /* Release connection */ |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 1174 | expect_bssap_clear(OSMO_RAT_GERAN_A); |
| 1175 | conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1176 | |
| 1177 | btw("all requests serviced, conn has been released"); |
| 1178 | bss_sends_clear_complete(); |
| 1179 | EXPECT_CONN_COUNT(0); |
| 1180 | |
| 1181 | BTW("an SMS is sent, MS is paged"); |
| 1182 | paging_expect_imsi(imsi); |
| 1183 | paging_sent = false; |
| 1184 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1185 | OSMO_ASSERT(vsub); |
| 1186 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 1187 | |
| 1188 | send_sms(vsub, vsub, |
| 1189 | "Privacy in residential applications is a desirable" |
| 1190 | " marketing option."); |
| 1191 | |
| 1192 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 1193 | vlr_subscr_put(vsub); |
| 1194 | vsub = NULL; |
| 1195 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 1196 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 1197 | |
| 1198 | btw("the subscriber and its pending request should remain"); |
| 1199 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1200 | OSMO_ASSERT(vsub); |
| 1201 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 1202 | vlr_subscr_put(vsub); |
| 1203 | |
| 1204 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 1205 | auth_request_sent = false; |
| 1206 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 1207 | ms_sends_msg("06270703305882089910070000006402"); |
| 1208 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1209 | |
| 1210 | btw("needs auth, not yet accepted"); |
| 1211 | EXPECT_ACCEPTED(false); |
| 1212 | thwart_rx_non_initial_requests(); |
| 1213 | |
| 1214 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
| 1215 | expect_cipher_mode_cmd("e2b234f807886400"); |
| 1216 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 1217 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 1218 | |
| 1219 | btw("needs ciph, not yet accepted"); |
| 1220 | EXPECT_ACCEPTED(false); |
| 1221 | thwart_rx_non_initial_requests(); |
| 1222 | |
| 1223 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 1224 | dtap_expect_tx("09" /* SMS messages */ |
| 1225 | "01" /* CP-DATA */ |
| 1226 | "58" /* length */ |
| 1227 | "01" /* Network to MS */ |
| 1228 | "00" /* reference */ |
| 1229 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 1230 | "0791" "447758100650" /* 447785016005 */ |
| 1231 | "00" /* dest */ |
| 1232 | /* SMS TPDU */ |
| 1233 | "4c" /* len */ |
| 1234 | "00" /* SMS deliver */ |
| 1235 | "05802443f2" /* originating address 42342 */ |
| 1236 | "00" /* TP-PID */ |
| 1237 | "00" /* GSM default alphabet */ |
| 1238 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 1239 | "000000" /* H-M-S */ |
| 1240 | "00" /* GMT+0 */ |
| 1241 | "44" /* data length */ |
| 1242 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 1243 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 1244 | "0c7ac3e9e9b7db05"); |
| 1245 | ms_sends_msg("0632"); |
| 1246 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 1247 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 1248 | |
| 1249 | btw("SMS was delivered, no requests pending for subscr"); |
| 1250 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1251 | OSMO_ASSERT(vsub); |
| 1252 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 1253 | vlr_subscr_put(vsub); |
| 1254 | |
| 1255 | btw("conn is still open to wait for SMS ack dance"); |
| 1256 | EXPECT_CONN_COUNT(1); |
| 1257 | |
| 1258 | btw("MS replies with CP-ACK for received SMS"); |
| 1259 | ms_sends_msg("8904"); |
| 1260 | EXPECT_CONN_COUNT(1); |
| 1261 | |
| 1262 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 1263 | dtap_expect_tx("0904"); |
| 1264 | expect_bssap_clear(); |
| 1265 | ms_sends_msg("890106020041020000"); |
| 1266 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 1267 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1268 | |
| 1269 | btw("SMS is done, conn is gone"); |
| 1270 | bss_sends_clear_complete(); |
| 1271 | EXPECT_CONN_COUNT(0); |
| 1272 | |
| 1273 | BTW("subscriber detaches"); |
| 1274 | expect_bssap_clear(); |
| 1275 | ms_sends_msg("050130089910070000006402"); |
| 1276 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1277 | |
| 1278 | bss_sends_clear_complete(); |
| 1279 | EXPECT_CONN_COUNT(0); |
| 1280 | clear_vlr(); |
| 1281 | comment_end(); |
| 1282 | } |
| 1283 | |
| 1284 | /* During CM Service Request or Paging Response we already have Classmark 2 that indicates A5/3 |
| 1285 | * availablity. Here, in a hacky way remove the knowledge of Classmark 2 to tickle a code path where |
| 1286 | * proc_arq_fsm needs a Classmark Update during Ciphering. Shouldn't happen in reality though. */ |
| 1287 | static void test_cm_service_needs_classmark_update() |
| 1288 | { |
| 1289 | struct vlr_subscr *vsub; |
| 1290 | const char *imsi = "901700000004620"; |
| 1291 | |
| 1292 | comment_start(); |
| 1293 | |
| 1294 | /* A5/3 support is indicated in Classmark 3. By configuring A5/3, trigger the code paths that |
| 1295 | * send a Classmark Request. */ |
| 1296 | net->a5_encryption_mask = (1 << 3); /* A5/3 */ |
| 1297 | /* implicit: net->authentication_required = true; */ |
| 1298 | |
| 1299 | btw("Location Update request causes a GSUP Send Auth Info request to HLR"); |
| 1300 | lu_result_sent = RES_NONE; |
| 1301 | gsup_expect_tx("08010809710000004026f0"); |
| 1302 | ms_sends_msg("050802008168000130089910070000006402"); |
| 1303 | OSMO_ASSERT(gsup_tx_confirmed); |
| 1304 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1305 | |
| 1306 | btw("from HLR, rx _SEND_AUTH_INFO_RESULT; VLR sends Auth Req to MS"); |
| 1307 | /* Based on a Ki of 000102030405060708090a0b0c0d0e0f */ |
| 1308 | auth_request_sent = false; |
| 1309 | auth_request_expect_rand = "585df1ae287f6e273dce07090d61320b"; |
| 1310 | auth_request_expect_autn = NULL; |
| 1311 | gsup_rx("0a" |
| 1312 | /* imsi */ |
| 1313 | "0108" "09710000004026f0" |
| 1314 | /* 5 auth vectors... */ |
| 1315 | /* TL TL rand */ |
| 1316 | "0322" "2010" "585df1ae287f6e273dce07090d61320b" |
| 1317 | /* TL sres TL kc */ |
| 1318 | "2104" "2d8b2c3e" "2208" "61855fb81fc2a800" |
| 1319 | "0322" "2010" "12aca96fb4ffdea5c985cbafa9b6e18b" |
| 1320 | "2104" "20bde240" "2208" "07fa7502e07e1c00" |
| 1321 | "0322" "2010" "e7c03ba7cf0e2fde82b2dc4d63077d42" |
| 1322 | "2104" "a29514ae" "2208" "e2b234f807886400" |
| 1323 | "0322" "2010" "fa8f20b781b5881329d4fea26b1a3c51" |
| 1324 | "2104" "5afc8d72" "2208" "2392f14f709ae000" |
| 1325 | "0322" "2010" "0fd4cc8dbe8715d1f439e304edfd68dc" |
| 1326 | "2104" "bc8d1c5b" "2208" "da7cdd6bfe2d7000", |
| 1327 | NULL); |
| 1328 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1329 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1330 | |
| 1331 | BTW("MS sends Authen Response, VLR accepts and wants to send Ciphering Mode Command to MS" |
| 1332 | " -- but needs Classmark 2 to determine whether A5/3 is supported"); |
| 1333 | cipher_mode_cmd_sent = false; |
| 1334 | ms_sends_msg("05542d8b2c3e"); |
| 1335 | OSMO_ASSERT(!cipher_mode_cmd_sent); |
| 1336 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1337 | |
| 1338 | btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3"); |
| 1339 | expect_cipher_mode_cmd("61855fb81fc2a800"); |
| 1340 | bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100"); |
| 1341 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 1342 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1343 | |
| 1344 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends GSUP LU Req to HLR"); |
Neels Hofmeyr | d0756b1 | 2018-09-28 02:41:39 +0200 | [diff] [blame] | 1345 | gsup_expect_tx("04010809710000004026f0280102"); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1346 | ms_sends_msg("0632"); |
| 1347 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1348 | |
| 1349 | btw("HLR sends _INSERT_DATA_REQUEST, VLR responds with _INSERT_DATA_RESULT"); |
| 1350 | gsup_rx("10010809710000004026f00804032443f2", |
| 1351 | "12010809710000004026f0"); |
| 1352 | VERBOSE_ASSERT(lu_result_sent, == RES_NONE, "%d"); |
| 1353 | |
| 1354 | btw("HLR also sends GSUP _UPDATE_LOCATION_RESULT"); |
| 1355 | expect_bssap_clear(); |
| 1356 | gsup_rx("06010809710000004026f0", NULL); |
| 1357 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1358 | |
| 1359 | btw("LU was successful, and the conn has already been closed"); |
| 1360 | VERBOSE_ASSERT(lu_result_sent, == RES_ACCEPT, "%d"); |
| 1361 | bss_sends_clear_complete(); |
| 1362 | EXPECT_CONN_COUNT(0); |
| 1363 | |
| 1364 | |
| 1365 | BTW("after a while, a new conn sends a CM Service Request. VLR responds with Auth Req, 2nd auth vector"); |
| 1366 | cm_service_result_sent = RES_NONE; |
| 1367 | auth_request_sent = false; |
| 1368 | auth_request_expect_rand = "12aca96fb4ffdea5c985cbafa9b6e18b"; |
| 1369 | ms_sends_msg("05247803305886089910070000006402"); |
| 1370 | OSMO_ASSERT(g_conn); |
| 1371 | OSMO_ASSERT(g_conn->fi); |
| 1372 | OSMO_ASSERT(g_conn->vsub); |
| 1373 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1374 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 1375 | |
| 1376 | btw("needs auth, not yet accepted"); |
| 1377 | EXPECT_ACCEPTED(false); |
| 1378 | thwart_rx_non_initial_requests(); |
| 1379 | |
| 1380 | btw("MS sends Authen Response, VLR accepts and requests Ciphering. We already know Classmark 3," |
| 1381 | " so no need to request Classmark Update."); |
| 1382 | expect_cipher_mode_cmd("07fa7502e07e1c00"); |
| 1383 | ms_sends_msg("0554" "20bde240" /* 2nd vector's sres, s.a. */); |
| 1384 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 1385 | VERBOSE_ASSERT(cipher_mode_cmd_sent, == true, "%d"); |
| 1386 | |
| 1387 | btw("needs ciph, not yet accepted"); |
| 1388 | EXPECT_ACCEPTED(false); |
| 1389 | thwart_rx_non_initial_requests(); |
| 1390 | |
| 1391 | btw("MS sends Ciphering Mode Complete, VLR accepts; above Ciphering is an implicit CM Service Accept"); |
| 1392 | ms_sends_msg("0632"); |
| 1393 | VERBOSE_ASSERT(cm_service_result_sent, == RES_NONE, "%d"); |
| 1394 | |
| 1395 | /* Release connection */ |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 1396 | expect_bssap_clear(OSMO_RAT_GERAN_A); |
| 1397 | conn_conclude_cm_service_req(g_conn, OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1398 | |
| 1399 | btw("all requests serviced, conn has been released"); |
| 1400 | bss_sends_clear_complete(); |
| 1401 | EXPECT_CONN_COUNT(0); |
| 1402 | |
| 1403 | BTW("an SMS is sent, MS is paged"); |
| 1404 | paging_expect_imsi(imsi); |
| 1405 | paging_sent = false; |
| 1406 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1407 | OSMO_ASSERT(vsub); |
| 1408 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 1409 | |
| 1410 | send_sms(vsub, vsub, "Privacy in residential applications is a desirable marketing option."); |
| 1411 | |
| 1412 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 1413 | vlr_subscr_put(vsub); |
| 1414 | vsub = NULL; |
| 1415 | VERBOSE_ASSERT(paging_sent, == true, "%d"); |
| 1416 | VERBOSE_ASSERT(paging_stopped, == false, "%d"); |
| 1417 | |
| 1418 | btw("the subscriber and its pending request should remain"); |
| 1419 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1420 | OSMO_ASSERT(vsub); |
| 1421 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 1, "%d"); |
| 1422 | vlr_subscr_put(vsub); |
| 1423 | |
| 1424 | btw("MS replies with Paging Response, and VLR sends Auth Request with third key"); |
| 1425 | auth_request_sent = false; |
| 1426 | auth_request_expect_rand = "e7c03ba7cf0e2fde82b2dc4d63077d42"; |
| 1427 | ms_sends_msg("06270703305882089910070000006402"); |
| 1428 | VERBOSE_ASSERT(auth_request_sent, == true, "%d"); |
| 1429 | |
| 1430 | BTW("Fake a situation where Classmark 2 is unknown during proc_arq_fsm"); |
| 1431 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1432 | OSMO_ASSERT(vsub); |
| 1433 | vsub->classmark.classmark2_len = 0; |
| 1434 | vsub->classmark.classmark3_len = 0; |
| 1435 | vlr_subscr_put(vsub); |
| 1436 | |
| 1437 | |
| 1438 | btw("MS sends Authen Response, VLR accepts and requests Ciphering"); |
| 1439 | btw("MS sends Authen Response, VLR accepts and requests Ciphering." |
| 1440 | " Normally, we'd know Classmark 3, but this test removed it." |
| 1441 | " Hence a Classmark Request is generated."); |
| 1442 | cipher_mode_cmd_sent = false; |
| 1443 | ms_sends_msg("0554" "a29514ae" /* 3rd vector's sres, s.a. */); |
| 1444 | OSMO_ASSERT(!cipher_mode_cmd_sent); |
| 1445 | |
| 1446 | btw("BSC sends back a BSSMAP Classmark Update, that triggers the Ciphering Mode Command in A5/3"); |
| 1447 | expect_cipher_mode_cmd("e2b234f807886400"); |
| 1448 | bss_sends_bssap_mgmt("541203505886130b6014042f6503b8800d2100"); |
| 1449 | OSMO_ASSERT(cipher_mode_cmd_sent); |
| 1450 | |
| 1451 | btw("needs ciph, not yet accepted"); |
| 1452 | EXPECT_ACCEPTED(false); |
| 1453 | |
| 1454 | btw("MS sends Ciphering Mode Complete, VLR accepts and sends pending SMS"); |
| 1455 | dtap_expect_tx("09" /* SMS messages */ |
| 1456 | "01" /* CP-DATA */ |
| 1457 | "58" /* length */ |
| 1458 | "01" /* Network to MS */ |
| 1459 | "00" /* reference */ |
| 1460 | /* originator (gsm411_send_sms() hardcodes this weird nr) */ |
| 1461 | "0791" "447758100650" /* 447785016005 */ |
| 1462 | "00" /* dest */ |
| 1463 | /* SMS TPDU */ |
| 1464 | "4c" /* len */ |
| 1465 | "00" /* SMS deliver */ |
| 1466 | "05802443f2" /* originating address 42342 */ |
| 1467 | "00" /* TP-PID */ |
| 1468 | "00" /* GSM default alphabet */ |
| 1469 | "071010" /* Y-M-D (from wrapped gsm340_gen_scts())*/ |
| 1470 | "000000" /* H-M-S */ |
| 1471 | "00" /* GMT+0 */ |
| 1472 | "44" /* data length */ |
| 1473 | "5079da1e1ee7416937485e9ea7c965373d1d6683c270383b3d0e" |
| 1474 | "d3d36ff71c949e83c22072799e9687c5ec32a81d96afcbf4b4fb" |
| 1475 | "0c7ac3e9e9b7db05"); |
| 1476 | ms_sends_msg("0632"); |
| 1477 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 1478 | VERBOSE_ASSERT(paging_stopped, == true, "%d"); |
| 1479 | |
| 1480 | btw("SMS was delivered, no requests pending for subscr"); |
| 1481 | vsub = vlr_subscr_find_by_imsi(net->vlr, imsi); |
| 1482 | OSMO_ASSERT(vsub); |
| 1483 | VERBOSE_ASSERT(llist_count(&vsub->cs.requests), == 0, "%d"); |
| 1484 | vlr_subscr_put(vsub); |
| 1485 | |
| 1486 | btw("conn is still open to wait for SMS ack dance"); |
| 1487 | EXPECT_CONN_COUNT(1); |
| 1488 | |
| 1489 | btw("MS replies with CP-ACK for received SMS"); |
| 1490 | ms_sends_msg("8904"); |
| 1491 | EXPECT_CONN_COUNT(1); |
| 1492 | |
| 1493 | btw("MS also sends RP-ACK, MSC in turn sends CP-ACK for that"); |
| 1494 | dtap_expect_tx("0904"); |
| 1495 | expect_bssap_clear(); |
| 1496 | ms_sends_msg("890106020041020000"); |
| 1497 | VERBOSE_ASSERT(dtap_tx_confirmed, == true, "%d"); |
| 1498 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
| 1499 | |
| 1500 | btw("SMS is done, conn is gone"); |
| 1501 | bss_sends_clear_complete(); |
| 1502 | EXPECT_CONN_COUNT(0); |
| 1503 | |
| 1504 | BTW("subscriber detaches"); |
| 1505 | expect_bssap_clear(); |
| 1506 | ms_sends_msg("050130089910070000006402"); |
| 1507 | VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); |
Neels Hofmeyr | a7fd88c | 2018-03-02 01:50:42 +0100 | [diff] [blame] | 1508 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 1509 | bss_sends_clear_complete(); |
Neels Hofmeyr | a7fd88c | 2018-03-02 01:50:42 +0100 | [diff] [blame] | 1510 | EXPECT_CONN_COUNT(0); |
| 1511 | clear_vlr(); |
| 1512 | comment_end(); |
| 1513 | } |
| 1514 | |
| 1515 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1516 | msc_vlr_test_func_t msc_vlr_tests[] = { |
| 1517 | test_ciph, |
| 1518 | test_ciph_tmsi, |
| 1519 | test_ciph_imei, |
| 1520 | test_ciph_imeisv, |
| 1521 | test_ciph_tmsi_imei, |
Neels Hofmeyr | cac6e89 | 2018-03-10 02:05:44 +0100 | [diff] [blame] | 1522 | test_gsm_ciph_in_umts_env, |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 1523 | test_a5_3_supported, |
| 1524 | test_cm_service_needs_classmark_update, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1525 | NULL |
| 1526 | }; |