Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <osmocom/core/utils.h> |
| 4 | #include <osmocom/core/application.h> |
| 5 | |
| 6 | #include "db.h" |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 7 | #include "hlr.h" |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 8 | #include "rand.h" |
| 9 | #include "logging.h" |
| 10 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 11 | static struct hlr *g_hlr; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 12 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 13 | static int test(const char *imsi, struct db_context *dbc) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 14 | { |
| 15 | struct osmo_auth_vector vec[3]; |
| 16 | int rc, i; |
| 17 | |
| 18 | /* initialize all vectors with a known token pattern */ |
| 19 | memset(vec, 0x55, sizeof(vec)); |
| 20 | for (i = 0; i < ARRAY_SIZE(vec); i++) |
| 21 | vec[i].res_len = 0; |
| 22 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 23 | rc = db_get_auc(dbc, imsi, vec, ARRAY_SIZE(vec), NULL, NULL); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 24 | if (rc <= 0) { |
| 25 | LOGP(DMAIN, LOGL_ERROR, "Cannot obtain auth tuples for '%s'\n", imsi); |
| 26 | return rc; |
| 27 | } |
| 28 | LOGP(DMAIN, LOGL_INFO, "Obtained %u tuples for subscriber IMSI %s\n", |
| 29 | rc, imsi); |
| 30 | |
| 31 | for (i = 0; i < rc; i++) { |
| 32 | struct osmo_auth_vector *v = vec + i; |
| 33 | LOGP(DMAIN, LOGL_DEBUG, "Tuple %u, auth_types=0x%x\n", i, v->auth_types); |
| 34 | LOGP(DMAIN, LOGL_DEBUG, "RAND=%s\n", osmo_hexdump_nospc(v->rand, sizeof(v->rand))); |
| 35 | LOGP(DMAIN, LOGL_DEBUG, "AUTN=%s\n", osmo_hexdump_nospc(v->autn, sizeof(v->autn))); |
| 36 | LOGP(DMAIN, LOGL_DEBUG, "CK=%s\n", osmo_hexdump_nospc(v->ck, sizeof(v->ck))); |
| 37 | LOGP(DMAIN, LOGL_DEBUG, "IK=%s\n", osmo_hexdump_nospc(v->ik, sizeof(v->ik))); |
| 38 | LOGP(DMAIN, LOGL_DEBUG, "RES=%s\n", osmo_hexdump_nospc(v->res, v->res_len)); |
| 39 | LOGP(DMAIN, LOGL_DEBUG, "Kc=%s\n", osmo_hexdump_nospc(v->kc, sizeof(v->kc))); |
| 40 | LOGP(DMAIN, LOGL_DEBUG, "SRES=%s\n", osmo_hexdump_nospc(v->sres, sizeof(v->sres))); |
| 41 | } |
| 42 | |
| 43 | return rc; |
| 44 | } |
| 45 | |
| 46 | int main(int argc, char **argv) |
| 47 | { |
| 48 | int rc; |
| 49 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 50 | g_hlr = talloc_zero(NULL, struct hlr); |
| 51 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 52 | rc = osmo_init_logging(&hlr_log_info); |
| 53 | if (rc < 0) { |
| 54 | fprintf(stderr, "Error initializing logging\n"); |
| 55 | exit(1); |
| 56 | } |
| 57 | LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n"); |
| 58 | |
| 59 | rc = rand_init(); |
| 60 | if (rc < 0) { |
| 61 | LOGP(DMAIN, LOGL_ERROR, "Error initializing random source\n"); |
| 62 | exit(1); |
| 63 | } |
| 64 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 65 | g_hlr->dbc = db_open(NULL, "hlr.db"); |
| 66 | if (!g_hlr->dbc) { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 67 | LOGP(DMAIN, LOGL_ERROR, "Error opening database\n"); |
| 68 | exit(1); |
| 69 | } |
| 70 | |
| 71 | /* non-existing subscriber */ |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 72 | rc = test("901990123456789", g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 73 | /* 2G only AUC data (COMP128v1 / MILENAGE) */ |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 74 | rc = test("901990000000001", g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 75 | /* 2G + 3G AUC data (COMP128v1 / MILENAGE) */ |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 76 | rc = test("901990000000002", g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 77 | /* 3G AUC data (MILENAGE) */ |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 78 | rc = test("901990000000003", g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 79 | |
| 80 | LOGP(DMAIN, LOGL_NOTICE, "Exiting\n"); |
| 81 | |
Max | d4bebbd | 2017-03-02 12:00:19 +0100 | [diff] [blame] | 82 | db_close(g_hlr->dbc); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 83 | |
| 84 | log_fini(); |
| 85 | |
| 86 | exit(0); |
| 87 | } |