Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file osmo-auc-gen.c |
| 2 | * GSM/GPRS/3G authentication testing tool. */ |
| 3 | /* |
Harald Welte | 53b4bbb | 2021-09-16 21:36:16 +0200 | [diff] [blame^] | 4 | * (C) 2010-2021 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include <stdio.h> |
| 27 | #include <errno.h> |
| 28 | #include <string.h> |
Jan Engelhardt | a6d8393 | 2013-06-03 01:38:57 +0200 | [diff] [blame] | 29 | #include <time.h> |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 30 | #include <getopt.h> |
Harald Welte | b53717f | 2012-08-02 08:42:59 +0200 | [diff] [blame] | 31 | #include <unistd.h> |
Holger Hans Peter Freyther | a652abc | 2013-07-14 09:11:47 +0200 | [diff] [blame] | 32 | #include <inttypes.h> |
| 33 | #include <time.h> |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 34 | |
| 35 | #include <osmocom/crypt/auth.h> |
| 36 | #include <osmocom/core/utils.h> |
Harald Welte | 53b4bbb | 2021-09-16 21:36:16 +0200 | [diff] [blame^] | 37 | #include <osmocom/core/base64.h> |
Max | 4b2b0cc | 2017-07-10 14:32:48 +0200 | [diff] [blame] | 38 | #include <osmocom/gsm/gsm_utils.h> |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 39 | |
Harald Welte | 53b4bbb | 2021-09-16 21:36:16 +0200 | [diff] [blame^] | 40 | static void print_base64(const char *fmt, const uint8_t *data, unsigned int len) |
| 41 | { |
| 42 | uint8_t outbuf[256]; |
| 43 | size_t olen; |
| 44 | |
| 45 | OSMO_ASSERT(osmo_base64_encode(outbuf, sizeof(outbuf), &olen, data, len) == 0); |
| 46 | OSMO_ASSERT(sizeof(outbuf) > olen); |
| 47 | outbuf[olen] = '\0'; |
| 48 | printf(fmt, outbuf); |
| 49 | } |
| 50 | |
Harald Welte | 57799ed | 2012-06-27 15:06:19 +0200 | [diff] [blame] | 51 | static void dump_triplets_dat(struct osmo_auth_vector *vec) |
| 52 | { |
| 53 | if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) { |
| 54 | fprintf(stderr, "triplets.dat doesn't support UMTS!\n"); |
| 55 | return; |
| 56 | } |
| 57 | printf("imsi,"); |
| 58 | printf("%s,", osmo_hexdump_nospc(vec->rand, sizeof(vec->rand))); |
| 59 | printf("%s,", osmo_hexdump_nospc(vec->sres, sizeof(vec->sres))); |
| 60 | printf("%s\n", osmo_hexdump_nospc(vec->kc, sizeof(vec->kc))); |
| 61 | } |
| 62 | |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 63 | static void dump_auth_vec(struct osmo_auth_vector *vec) |
| 64 | { |
Harald Welte | 4f511b6 | 2016-05-18 19:36:42 +0200 | [diff] [blame] | 65 | printf("RAND:\t%s\n", osmo_hexdump_nospc(vec->rand, sizeof(vec->rand))); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 66 | |
| 67 | if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) { |
Harald Welte | 53b4bbb | 2021-09-16 21:36:16 +0200 | [diff] [blame^] | 68 | uint8_t inbuf[sizeof(vec->rand) + sizeof(vec->autn)]; |
| 69 | |
Harald Welte | 4f511b6 | 2016-05-18 19:36:42 +0200 | [diff] [blame] | 70 | printf("AUTN:\t%s\n", osmo_hexdump_nospc(vec->autn, sizeof(vec->autn))); |
| 71 | printf("IK:\t%s\n", osmo_hexdump_nospc(vec->ik, sizeof(vec->ik))); |
| 72 | printf("CK:\t%s\n", osmo_hexdump_nospc(vec->ck, sizeof(vec->ck))); |
| 73 | printf("RES:\t%s\n", osmo_hexdump_nospc(vec->res, vec->res_len)); |
Harald Welte | 53b4bbb | 2021-09-16 21:36:16 +0200 | [diff] [blame^] | 74 | |
| 75 | memcpy(inbuf, vec->rand, sizeof(vec->rand)); |
| 76 | memcpy(inbuf + sizeof(vec->rand), vec->autn, sizeof(vec->autn)); |
| 77 | print_base64("IMS nonce:\t%s\n", inbuf, sizeof(inbuf)); |
| 78 | print_base64("IMS res:\t%s\n", vec->res, vec->res_len); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | if (vec->auth_types & OSMO_AUTH_TYPE_GSM) { |
Harald Welte | 4f511b6 | 2016-05-18 19:36:42 +0200 | [diff] [blame] | 82 | printf("SRES:\t%s\n", osmo_hexdump_nospc(vec->sres, sizeof(vec->sres))); |
| 83 | printf("Kc:\t%s\n", osmo_hexdump_nospc(vec->kc, sizeof(vec->kc))); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | static struct osmo_sub_auth_data test_aud = { |
| 88 | .type = OSMO_AUTH_TYPE_NONE, |
| 89 | .algo = OSMO_AUTH_ALG_NONE, |
| 90 | }; |
| 91 | |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 92 | static void help() |
| 93 | { |
Neels Hofmeyr | 18d65be | 2017-02-03 18:36:32 +0100 | [diff] [blame] | 94 | int alg; |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 95 | printf( "-2 --2g\tUse 2G (GSM) authentication\n" |
| 96 | "-3 --3g\tUse 3G (UMTS) authentication\n" |
| 97 | "-a --algorithm\tSpecify name of the algorithm\n" |
| 98 | "-k --key\tSpecify Ki / K\n" |
| 99 | "-o --opc\tSpecify OPC (only for 3G)\n" |
Harald Welte | a72e47b | 2012-03-21 09:03:16 +0100 | [diff] [blame] | 100 | "-O --op\tSpecify OP (only for 3G)\n" |
Holger Hans Peter Freyther | 91ff17c | 2015-05-26 00:11:37 +0800 | [diff] [blame] | 101 | "-f --amf\tSpecify AMF (only for 3G)\n" |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 102 | "-s --sqn\tSpecify SQN (only for 3G)\n" |
Neels Hofmeyr | 3cb0827 | 2017-08-26 21:45:33 +0200 | [diff] [blame] | 103 | "-i --ind\tSpecify IND slot for new SQN after AUTS (only for 3G)\n" |
Neels Hofmeyr | b1af6ef | 2017-08-26 21:38:51 +0200 | [diff] [blame] | 104 | "-l --ind-len\tSpecify IND bit length (default=5) (only for 3G)\n" |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 105 | "-A --auts\tSpecify AUTS (only for 3G)\n" |
Harald Welte | 57799ed | 2012-06-27 15:06:19 +0200 | [diff] [blame] | 106 | "-r --rand\tSpecify random value\n" |
| 107 | "-I --ipsec\tOutput in triplets.dat format for strongswan\n"); |
Neels Hofmeyr | 18d65be | 2017-02-03 18:36:32 +0100 | [diff] [blame] | 108 | |
| 109 | fprintf(stderr, "\nAvailable algorithms for option -a:\n"); |
| 110 | for (alg = 1; alg < _OSMO_AUTH_ALG_NUM; alg++) |
| 111 | fprintf(stderr, " %s\n", |
| 112 | osmo_auth_alg_name(alg)); |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 115 | int main(int argc, char **argv) |
| 116 | { |
| 117 | struct osmo_auth_vector _vec; |
| 118 | struct osmo_auth_vector *vec = &_vec; |
Neels Hofmeyr | 8352d31 | 2017-02-02 20:05:14 +0100 | [diff] [blame] | 119 | uint8_t _rand[16], _auts[14]; |
Pau Espin Pedrol | c30a76b | 2017-11-16 16:37:55 +0100 | [diff] [blame] | 120 | uint64_t sqn = 0; |
Neels Hofmeyr | b2e41cc | 2017-09-12 03:25:43 +0200 | [diff] [blame] | 121 | unsigned int ind = 0; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 122 | int rc, option_index; |
| 123 | int rand_is_set = 0; |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 124 | int auts_is_set = 0; |
Neels Hofmeyr | d157bbb | 2017-08-26 22:08:36 +0200 | [diff] [blame] | 125 | int sqn_is_set = 0; |
Neels Hofmeyr | 3cb0827 | 2017-08-26 21:45:33 +0200 | [diff] [blame] | 126 | int ind_is_set = 0; |
Harald Welte | 57799ed | 2012-06-27 15:06:19 +0200 | [diff] [blame] | 127 | int fmt_triplets_dat = 0; |
Neels Hofmeyr | b2e41cc | 2017-09-12 03:25:43 +0200 | [diff] [blame] | 128 | uint64_t ind_mask = 0; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 129 | |
Harald Welte | bc6f56c | 2012-03-21 17:37:53 +0100 | [diff] [blame] | 130 | printf("osmo-auc-gen (C) 2011-2012 by Harald Welte\n"); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 131 | printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n"); |
| 132 | |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 133 | memset(_auts, 0, sizeof(_auts)); |
| 134 | |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 135 | while (1) { |
| 136 | int c; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 137 | static struct option long_options[] = { |
| 138 | { "2g", 0, 0, '2' }, |
| 139 | { "3g", 0, 0, '3' }, |
| 140 | { "algorithm", 1, 0, 'a' }, |
| 141 | { "key", 1, 0, 'k' }, |
| 142 | { "opc", 1, 0, 'o' }, |
Harald Welte | a72e47b | 2012-03-21 09:03:16 +0100 | [diff] [blame] | 143 | { "op", 1, 0, 'O' }, |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 144 | { "amf", 1, 0, 'f' }, |
| 145 | { "sqn", 1, 0, 's' }, |
Neels Hofmeyr | 3cb0827 | 2017-08-26 21:45:33 +0200 | [diff] [blame] | 146 | { "ind", 1, 0, 'i' }, |
Neels Hofmeyr | b1af6ef | 2017-08-26 21:38:51 +0200 | [diff] [blame] | 147 | { "ind-len", 1, 0, 'l' }, |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 148 | { "rand", 1, 0, 'r' }, |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 149 | { "auts", 1, 0, 'A' }, |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 150 | { "help", 0, 0, 'h' }, |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 151 | { 0, 0, 0, 0 } |
| 152 | }; |
| 153 | |
| 154 | rc = 0; |
| 155 | |
Neels Hofmeyr | b1af6ef | 2017-08-26 21:38:51 +0200 | [diff] [blame] | 156 | c = getopt_long(argc, argv, "23a:k:o:f:s:i:l:r:hO:A:I", long_options, |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 157 | &option_index); |
| 158 | |
| 159 | if (c == -1) |
| 160 | break; |
| 161 | |
| 162 | switch (c) { |
| 163 | case '2': |
| 164 | test_aud.type = OSMO_AUTH_TYPE_GSM; |
| 165 | break; |
| 166 | case '3': |
| 167 | test_aud.type = OSMO_AUTH_TYPE_UMTS; |
Neels Hofmeyr | 4315e01 | 2017-08-26 21:40:11 +0200 | [diff] [blame] | 168 | test_aud.u.umts.ind_bitlen = 5; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 169 | break; |
| 170 | case 'a': |
| 171 | rc = osmo_auth_alg_parse(optarg); |
| 172 | if (rc < 0) |
| 173 | break; |
| 174 | test_aud.algo = rc; |
| 175 | break; |
| 176 | case 'k': |
| 177 | switch (test_aud.type) { |
| 178 | case OSMO_AUTH_TYPE_GSM: |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 179 | rc = osmo_hexparse(optarg, test_aud.u.gsm.ki, |
| 180 | sizeof(test_aud.u.gsm.ki)); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 181 | break; |
| 182 | case OSMO_AUTH_TYPE_UMTS: |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 183 | rc = osmo_hexparse(optarg, test_aud.u.umts.k, |
| 184 | sizeof(test_aud.u.umts.k)); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 185 | break; |
| 186 | default: |
| 187 | fprintf(stderr, "please specify 2g/3g first!\n"); |
| 188 | } |
| 189 | break; |
| 190 | case 'o': |
| 191 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 192 | fprintf(stderr, "Only UMTS has OPC\n"); |
| 193 | exit(2); |
| 194 | } |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 195 | rc = osmo_hexparse(optarg, test_aud.u.umts.opc, |
| 196 | sizeof(test_aud.u.umts.opc)); |
Harald Welte | a72e47b | 2012-03-21 09:03:16 +0100 | [diff] [blame] | 197 | test_aud.u.umts.opc_is_op = 0; |
| 198 | break; |
| 199 | case 'O': |
| 200 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 201 | fprintf(stderr, "Only UMTS has OP\n"); |
| 202 | exit(2); |
| 203 | } |
| 204 | rc = osmo_hexparse(optarg, test_aud.u.umts.opc, |
| 205 | sizeof(test_aud.u.umts.opc)); |
| 206 | test_aud.u.umts.opc_is_op = 1; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 207 | break; |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 208 | case 'A': |
| 209 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 210 | fprintf(stderr, "Only UMTS has AUTS\n"); |
| 211 | exit(2); |
| 212 | } |
| 213 | rc = osmo_hexparse(optarg, _auts, sizeof(_auts)); |
| 214 | auts_is_set = 1; |
| 215 | break; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 216 | case 'f': |
| 217 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 218 | fprintf(stderr, "Only UMTS has AMF\n"); |
| 219 | exit(2); |
| 220 | } |
Harald Welte | aae2362 | 2011-12-07 11:35:02 +0100 | [diff] [blame] | 221 | rc = osmo_hexparse(optarg, test_aud.u.umts.amf, |
| 222 | sizeof(test_aud.u.umts.amf)); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 223 | break; |
| 224 | case 's': |
| 225 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 226 | fprintf(stderr, "Only UMTS has SQN\n"); |
| 227 | exit(2); |
| 228 | } |
Harald Welte | b48f438 | 2021-09-17 07:56:09 +0200 | [diff] [blame] | 229 | sqn = strtoull(optarg, 0, 0); |
Neels Hofmeyr | d157bbb | 2017-08-26 22:08:36 +0200 | [diff] [blame] | 230 | sqn_is_set = 1; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 231 | break; |
Neels Hofmeyr | 3cb0827 | 2017-08-26 21:45:33 +0200 | [diff] [blame] | 232 | case 'i': |
| 233 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 234 | fprintf(stderr, "Only UMTS has IND\n"); |
| 235 | exit(2); |
| 236 | } |
| 237 | ind = atoi(optarg); |
| 238 | ind_is_set = 1; |
| 239 | break; |
Neels Hofmeyr | b1af6ef | 2017-08-26 21:38:51 +0200 | [diff] [blame] | 240 | case 'l': |
| 241 | if (test_aud.type != OSMO_AUTH_TYPE_UMTS) { |
| 242 | fprintf(stderr, "Only UMTS has IND bitlen\n"); |
| 243 | exit(2); |
| 244 | } |
| 245 | test_aud.u.umts.ind_bitlen = atoi(optarg); |
| 246 | break; |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 247 | case 'r': |
| 248 | rc = osmo_hexparse(optarg, _rand, sizeof(_rand)); |
| 249 | rand_is_set = 1; |
| 250 | break; |
Harald Welte | 57799ed | 2012-06-27 15:06:19 +0200 | [diff] [blame] | 251 | case 'I': |
| 252 | fmt_triplets_dat = 1; |
| 253 | break; |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 254 | case 'h': |
| 255 | help(); |
| 256 | exit(0); |
| 257 | default: |
| 258 | help(); |
| 259 | exit(1); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | if (rc < 0) { |
Neels Hofmeyr | 18d65be | 2017-02-03 18:36:32 +0100 | [diff] [blame] | 263 | help(); |
| 264 | fprintf(stderr, "\nError parsing argument of option `%c'\n", c); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 265 | exit(2); |
| 266 | } |
| 267 | } |
| 268 | |
Harald Welte | 278a6c8 | 2019-12-03 21:35:12 +0100 | [diff] [blame] | 269 | if (argc > optind) { |
| 270 | fprintf(stderr, "Unsupported positional arguments in command line\n"); |
| 271 | exit(2); |
| 272 | } |
| 273 | |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 274 | if (!rand_is_set) { |
Max | 4b2b0cc | 2017-07-10 14:32:48 +0200 | [diff] [blame] | 275 | rc = osmo_get_rand_id(_rand, 16); |
| 276 | if (rc < 0) { |
| 277 | fprintf(stderr, "\nError: unable to obtain secure random numbers: %s!\n", |
| 278 | strerror(-rc)); |
| 279 | exit(3); |
Holger Hans Peter Freyther | 17aa6b2 | 2014-06-22 16:53:55 +0200 | [diff] [blame] | 280 | } |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 283 | if (test_aud.type == OSMO_AUTH_TYPE_NONE || |
| 284 | test_aud.algo == OSMO_AUTH_ALG_NONE) { |
| 285 | help(); |
Neels Hofmeyr | 18d65be | 2017-02-03 18:36:32 +0100 | [diff] [blame] | 286 | fprintf(stderr, "\nError: you need to pass at least" |
| 287 | " -2 or -3, as well as an algorithm to use.\n"); |
Harald Welte | 5fb795e | 2012-03-21 08:51:48 +0100 | [diff] [blame] | 288 | exit(2); |
| 289 | } |
| 290 | |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 291 | memset(vec, 0, sizeof(*vec)); |
| 292 | |
Neels Hofmeyr | d157bbb | 2017-08-26 22:08:36 +0200 | [diff] [blame] | 293 | if (test_aud.type == OSMO_AUTH_TYPE_UMTS) { |
Neels Hofmeyr | b2e41cc | 2017-09-12 03:25:43 +0200 | [diff] [blame] | 294 | uint64_t seq_1 = 1LL << test_aud.u.umts.ind_bitlen; |
Neels Hofmeyr | e6e6446 | 2017-08-26 22:29:51 +0200 | [diff] [blame] | 295 | ind_mask = seq_1 - 1; |
Neels Hofmeyr | d157bbb | 2017-08-26 22:08:36 +0200 | [diff] [blame] | 296 | |
| 297 | if (sqn_is_set) { |
| 298 | /* Before calculating the UMTS auth vector, osmo_auth_gen_vec() increments SEQ. |
| 299 | * To end up with the SQN passed in by the user, we need to pass in SEQ-1, and |
| 300 | * indicate which IND slot to target. */ |
| 301 | test_aud.u.umts.sqn = sqn - seq_1; |
| 302 | test_aud.u.umts.ind = sqn & ind_mask; |
| 303 | } |
Neels Hofmeyr | 3cb0827 | 2017-08-26 21:45:33 +0200 | [diff] [blame] | 304 | |
| 305 | if (sqn_is_set && ind_is_set) { |
| 306 | fprintf(stderr, "Requesting --sqn %"PRIu64" implies IND=%u," |
| 307 | " so no further --ind argument is allowed.\n", |
| 308 | sqn, test_aud.u.umts.ind); |
| 309 | exit(2); |
| 310 | } |
| 311 | |
| 312 | if (ind_is_set) { |
| 313 | if (ind >= (1 << test_aud.u.umts.ind_bitlen)) { |
| 314 | fprintf(stderr, "Requested --ind %u is too large for IND bitlen of %u\n", |
| 315 | ind, test_aud.u.umts.ind_bitlen); |
| 316 | exit(2); |
| 317 | } |
| 318 | test_aud.u.umts.ind = ind; |
| 319 | } |
Neels Hofmeyr | d157bbb | 2017-08-26 22:08:36 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 322 | if (!auts_is_set) |
| 323 | rc = osmo_auth_gen_vec(vec, &test_aud, _rand); |
| 324 | else |
| 325 | rc = osmo_auth_gen_vec_auts(vec, &test_aud, _auts, _rand, _rand); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 326 | if (rc < 0) { |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 327 | if (!auts_is_set) |
| 328 | fprintf(stderr, "error generating auth vector\n"); |
| 329 | else |
| 330 | fprintf(stderr, "AUTS from MS seems incorrect\n"); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 331 | exit(1); |
| 332 | } |
| 333 | |
Harald Welte | 57799ed | 2012-06-27 15:06:19 +0200 | [diff] [blame] | 334 | if (fmt_triplets_dat) |
| 335 | dump_triplets_dat(vec); |
Neels Hofmeyr | 5fe3d1b | 2017-03-15 01:16:43 +0100 | [diff] [blame] | 336 | else { |
Harald Welte | 57799ed | 2012-06-27 15:06:19 +0200 | [diff] [blame] | 337 | dump_auth_vec(vec); |
Neels Hofmeyr | e6e6446 | 2017-08-26 22:29:51 +0200 | [diff] [blame] | 338 | if (test_aud.type == OSMO_AUTH_TYPE_UMTS) { |
Neels Hofmeyr | 82c9a0e | 2017-03-13 17:36:17 +0100 | [diff] [blame] | 339 | printf("SQN:\t%" PRIu64 "\n", test_aud.u.umts.sqn); |
Neels Hofmeyr | e6e6446 | 2017-08-26 22:29:51 +0200 | [diff] [blame] | 340 | printf("IND:\t%u\n", (unsigned int)(test_aud.u.umts.sqn & ind_mask)); |
Neels Hofmeyr | 2066a42 | 2017-08-26 22:43:50 +0200 | [diff] [blame] | 341 | if (auts_is_set) |
| 342 | printf("SQN.MS:\t%" PRIu64 "\n", test_aud.u.umts.sqn_ms); |
Neels Hofmeyr | e6e6446 | 2017-08-26 22:29:51 +0200 | [diff] [blame] | 343 | } |
Neels Hofmeyr | 5fe3d1b | 2017-03-15 01:16:43 +0100 | [diff] [blame] | 344 | } |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 345 | |
Harald Welte | cebf3f0 | 2012-03-22 16:45:23 +0100 | [diff] [blame] | 346 | exit(0); |
Harald Welte | 915e0ef | 2011-12-07 02:38:42 +0100 | [diff] [blame] | 347 | } |