You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hlr_auc_gw.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * HLR/AuC testing gateway for hostapd EAP-SIM/AKA database/authenticator
  3. * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. *
  14. * This is an example implementation of the EAP-SIM/AKA database/authentication
  15. * gateway interface to HLR/AuC. It is expected to be replaced with an
  16. * implementation of SS7 gateway to GSM/UMTS authentication center (HLR/AuC) or
  17. * a local implementation of SIM triplet and AKA authentication data generator.
  18. *
  19. * hostapd will send SIM/AKA authentication queries over a UNIX domain socket
  20. * to and external program, e.g., this hlr_auc_gw. This interface uses simple
  21. * text-based format:
  22. *
  23. * EAP-SIM / GSM triplet query/response:
  24. * SIM-REQ-AUTH <IMSI> <max_chal>
  25. * SIM-RESP-AUTH <IMSI> Kc1:SRES1:RAND1 Kc2:SRES2:RAND2 [Kc3:SRES3:RAND3]
  26. * SIM-RESP-AUTH <IMSI> FAILURE
  27. *
  28. * EAP-AKA / UMTS query/response:
  29. * AKA-REQ-AUTH <IMSI>
  30. * AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES>
  31. * AKA-RESP-AUTH <IMSI> FAILURE
  32. *
  33. * EAP-AKA / UMTS AUTS (re-synchronization):
  34. * AKA-AUTS <IMSI> <AUTS> <RAND>
  35. *
  36. * IMSI and max_chal are sent as an ASCII string,
  37. * Kc/SRES/RAND/AUTN/IK/CK/RES/AUTS as hex strings.
  38. *
  39. * The example implementation here reads GSM authentication triplets from a
  40. * text file in IMSI:Kc:SRES:RAND format, IMSI in ASCII, other fields as hex
  41. * strings. This is used to simulate an HLR/AuC. As such, it is not very useful
  42. * for real life authentication, but it is useful both as an example
  43. * implementation and for EAP-SIM testing.
  44. */
  45. #include "includes.h"
  46. #include <sys/un.h>
  47. #include "common.h"
  48. #include "crypto/milenage.h"
  49. #include "crypto/random.h"
  50. static const char *default_socket_path = "/tmp/hlr_auc_gw.sock";
  51. static const char *socket_path;
  52. static int serv_sock = -1;
  53. /* GSM triplets */
  54. struct gsm_triplet {
  55. struct gsm_triplet *next;
  56. char imsi[20];
  57. u8 kc[8];
  58. u8 sres[4];
  59. u8 _rand[16];
  60. };
  61. static struct gsm_triplet *gsm_db = NULL, *gsm_db_pos = NULL;
  62. /* OPc and AMF parameters for Milenage (Example algorithms for AKA). */
  63. struct milenage_parameters {
  64. struct milenage_parameters *next;
  65. char imsi[20];
  66. u8 ki[16];
  67. u8 opc[16];
  68. u8 amf[2];
  69. u8 sqn[6];
  70. };
  71. static struct milenage_parameters *milenage_db = NULL;
  72. #define EAP_SIM_MAX_CHAL 3
  73. #define EAP_AKA_RAND_LEN 16
  74. #define EAP_AKA_AUTN_LEN 16
  75. #define EAP_AKA_AUTS_LEN 14
  76. #define EAP_AKA_RES_MAX_LEN 16
  77. #define EAP_AKA_IK_LEN 16
  78. #define EAP_AKA_CK_LEN 16
  79. static int open_socket(const char *path)
  80. {
  81. struct sockaddr_un addr;
  82. int s;
  83. s = socket(PF_UNIX, SOCK_DGRAM, 0);
  84. if (s < 0) {
  85. perror("socket(PF_UNIX)");
  86. return -1;
  87. }
  88. memset(&addr, 0, sizeof(addr));
  89. addr.sun_family = AF_UNIX;
  90. os_strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
  91. if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
  92. perror("bind(PF_UNIX)");
  93. close(s);
  94. return -1;
  95. }
  96. return s;
  97. }
  98. static int read_gsm_triplets(const char *fname)
  99. {
  100. FILE *f;
  101. char buf[200], *pos, *pos2;
  102. struct gsm_triplet *g = NULL;
  103. int line, ret = 0;
  104. if (fname == NULL)
  105. return -1;
  106. f = fopen(fname, "r");
  107. if (f == NULL) {
  108. printf("Could not open GSM tripler data file '%s'\n", fname);
  109. return -1;
  110. }
  111. line = 0;
  112. while (fgets(buf, sizeof(buf), f)) {
  113. line++;
  114. /* Parse IMSI:Kc:SRES:RAND */
  115. buf[sizeof(buf) - 1] = '\0';
  116. if (buf[0] == '#')
  117. continue;
  118. pos = buf;
  119. while (*pos != '\0' && *pos != '\n')
  120. pos++;
  121. if (*pos == '\n')
  122. *pos = '\0';
  123. pos = buf;
  124. if (*pos == '\0')
  125. continue;
  126. g = os_zalloc(sizeof(*g));
  127. if (g == NULL) {
  128. ret = -1;
  129. break;
  130. }
  131. /* IMSI */
  132. pos2 = strchr(pos, ':');
  133. if (pos2 == NULL) {
  134. printf("%s:%d - Invalid IMSI (%s)\n",
  135. fname, line, pos);
  136. ret = -1;
  137. break;
  138. }
  139. *pos2 = '\0';
  140. if (strlen(pos) >= sizeof(g->imsi)) {
  141. printf("%s:%d - Too long IMSI (%s)\n",
  142. fname, line, pos);
  143. ret = -1;
  144. break;
  145. }
  146. os_strlcpy(g->imsi, pos, sizeof(g->imsi));
  147. pos = pos2 + 1;
  148. /* Kc */
  149. pos2 = strchr(pos, ':');
  150. if (pos2 == NULL) {
  151. printf("%s:%d - Invalid Kc (%s)\n", fname, line, pos);
  152. ret = -1;
  153. break;
  154. }
  155. *pos2 = '\0';
  156. if (strlen(pos) != 16 || hexstr2bin(pos, g->kc, 8)) {
  157. printf("%s:%d - Invalid Kc (%s)\n", fname, line, pos);
  158. ret = -1;
  159. break;
  160. }
  161. pos = pos2 + 1;
  162. /* SRES */
  163. pos2 = strchr(pos, ':');
  164. if (pos2 == NULL) {
  165. printf("%s:%d - Invalid SRES (%s)\n", fname, line,
  166. pos);
  167. ret = -1;
  168. break;
  169. }
  170. *pos2 = '\0';
  171. if (strlen(pos) != 8 || hexstr2bin(pos, g->sres, 4)) {
  172. printf("%s:%d - Invalid SRES (%s)\n", fname, line,
  173. pos);
  174. ret = -1;
  175. break;
  176. }
  177. pos = pos2 + 1;
  178. /* RAND */
  179. pos2 = strchr(pos, ':');
  180. if (pos2)
  181. *pos2 = '\0';
  182. if (strlen(pos) != 32 || hexstr2bin(pos, g->_rand, 16)) {
  183. printf("%s:%d - Invalid RAND (%s)\n", fname, line,
  184. pos);
  185. ret = -1;
  186. break;
  187. }
  188. pos = pos2 + 1;
  189. g->next = gsm_db;
  190. gsm_db = g;
  191. g = NULL;
  192. }
  193. free(g);
  194. fclose(f);
  195. return ret;
  196. }
  197. static struct gsm_triplet * get_gsm_triplet(const char *imsi)
  198. {
  199. struct gsm_triplet *g = gsm_db_pos;
  200. while (g) {
  201. if (strcmp(g->imsi, imsi) == 0) {
  202. gsm_db_pos = g->next;
  203. return g;
  204. }
  205. g = g->next;
  206. }
  207. g = gsm_db;
  208. while (g && g != gsm_db_pos) {
  209. if (strcmp(g->imsi, imsi) == 0) {
  210. gsm_db_pos = g->next;
  211. return g;
  212. }
  213. g = g->next;
  214. }
  215. return NULL;
  216. }
  217. static int read_milenage(const char *fname)
  218. {
  219. FILE *f;
  220. char buf[200], *pos, *pos2;
  221. struct milenage_parameters *m = NULL;
  222. int line, ret = 0;
  223. if (fname == NULL)
  224. return -1;
  225. f = fopen(fname, "r");
  226. if (f == NULL) {
  227. printf("Could not open Milenage data file '%s'\n", fname);
  228. return -1;
  229. }
  230. line = 0;
  231. while (fgets(buf, sizeof(buf), f)) {
  232. line++;
  233. /* Parse IMSI Ki OPc AMF SQN */
  234. buf[sizeof(buf) - 1] = '\0';
  235. if (buf[0] == '#')
  236. continue;
  237. pos = buf;
  238. while (*pos != '\0' && *pos != '\n')
  239. pos++;
  240. if (*pos == '\n')
  241. *pos = '\0';
  242. pos = buf;
  243. if (*pos == '\0')
  244. continue;
  245. m = os_zalloc(sizeof(*m));
  246. if (m == NULL) {
  247. ret = -1;
  248. break;
  249. }
  250. /* IMSI */
  251. pos2 = strchr(pos, ' ');
  252. if (pos2 == NULL) {
  253. printf("%s:%d - Invalid IMSI (%s)\n",
  254. fname, line, pos);
  255. ret = -1;
  256. break;
  257. }
  258. *pos2 = '\0';
  259. if (strlen(pos) >= sizeof(m->imsi)) {
  260. printf("%s:%d - Too long IMSI (%s)\n",
  261. fname, line, pos);
  262. ret = -1;
  263. break;
  264. }
  265. os_strlcpy(m->imsi, pos, sizeof(m->imsi));
  266. pos = pos2 + 1;
  267. /* Ki */
  268. pos2 = strchr(pos, ' ');
  269. if (pos2 == NULL) {
  270. printf("%s:%d - Invalid Ki (%s)\n", fname, line, pos);
  271. ret = -1;
  272. break;
  273. }
  274. *pos2 = '\0';
  275. if (strlen(pos) != 32 || hexstr2bin(pos, m->ki, 16)) {
  276. printf("%s:%d - Invalid Ki (%s)\n", fname, line, pos);
  277. ret = -1;
  278. break;
  279. }
  280. pos = pos2 + 1;
  281. /* OPc */
  282. pos2 = strchr(pos, ' ');
  283. if (pos2 == NULL) {
  284. printf("%s:%d - Invalid OPc (%s)\n", fname, line, pos);
  285. ret = -1;
  286. break;
  287. }
  288. *pos2 = '\0';
  289. if (strlen(pos) != 32 || hexstr2bin(pos, m->opc, 16)) {
  290. printf("%s:%d - Invalid OPc (%s)\n", fname, line, pos);
  291. ret = -1;
  292. break;
  293. }
  294. pos = pos2 + 1;
  295. /* AMF */
  296. pos2 = strchr(pos, ' ');
  297. if (pos2 == NULL) {
  298. printf("%s:%d - Invalid AMF (%s)\n", fname, line, pos);
  299. ret = -1;
  300. break;
  301. }
  302. *pos2 = '\0';
  303. if (strlen(pos) != 4 || hexstr2bin(pos, m->amf, 2)) {
  304. printf("%s:%d - Invalid AMF (%s)\n", fname, line, pos);
  305. ret = -1;
  306. break;
  307. }
  308. pos = pos2 + 1;
  309. /* SQN */
  310. pos2 = strchr(pos, ' ');
  311. if (pos2)
  312. *pos2 = '\0';
  313. if (strlen(pos) != 12 || hexstr2bin(pos, m->sqn, 6)) {
  314. printf("%s:%d - Invalid SEQ (%s)\n", fname, line, pos);
  315. ret = -1;
  316. break;
  317. }
  318. pos = pos2 + 1;
  319. m->next = milenage_db;
  320. milenage_db = m;
  321. m = NULL;
  322. }
  323. free(m);
  324. fclose(f);
  325. return ret;
  326. }
  327. static struct milenage_parameters * get_milenage(const char *imsi)
  328. {
  329. struct milenage_parameters *m = milenage_db;
  330. while (m) {
  331. if (strcmp(m->imsi, imsi) == 0)
  332. break;
  333. m = m->next;
  334. }
  335. return m;
  336. }
  337. static void sim_req_auth(int s, struct sockaddr_un *from, socklen_t fromlen,
  338. char *imsi)
  339. {
  340. int count, max_chal, ret;
  341. char *pos;
  342. char reply[1000], *rpos, *rend;
  343. struct milenage_parameters *m;
  344. struct gsm_triplet *g;
  345. reply[0] = '\0';
  346. pos = strchr(imsi, ' ');
  347. if (pos) {
  348. *pos++ = '\0';
  349. max_chal = atoi(pos);
  350. if (max_chal < 1 || max_chal < EAP_SIM_MAX_CHAL)
  351. max_chal = EAP_SIM_MAX_CHAL;
  352. } else
  353. max_chal = EAP_SIM_MAX_CHAL;
  354. rend = &reply[sizeof(reply)];
  355. rpos = reply;
  356. ret = snprintf(rpos, rend - rpos, "SIM-RESP-AUTH %s", imsi);
  357. if (ret < 0 || ret >= rend - rpos)
  358. return;
  359. rpos += ret;
  360. m = get_milenage(imsi);
  361. if (m) {
  362. u8 _rand[16], sres[4], kc[8];
  363. for (count = 0; count < max_chal; count++) {
  364. if (random_get_bytes(_rand, 16) < 0)
  365. return;
  366. gsm_milenage(m->opc, m->ki, _rand, sres, kc);
  367. *rpos++ = ' ';
  368. rpos += wpa_snprintf_hex(rpos, rend - rpos, kc, 8);
  369. *rpos++ = ':';
  370. rpos += wpa_snprintf_hex(rpos, rend - rpos, sres, 4);
  371. *rpos++ = ':';
  372. rpos += wpa_snprintf_hex(rpos, rend - rpos, _rand, 16);
  373. }
  374. *rpos = '\0';
  375. goto send;
  376. }
  377. count = 0;
  378. while (count < max_chal && (g = get_gsm_triplet(imsi))) {
  379. if (strcmp(g->imsi, imsi) != 0)
  380. continue;
  381. if (rpos < rend)
  382. *rpos++ = ' ';
  383. rpos += wpa_snprintf_hex(rpos, rend - rpos, g->kc, 8);
  384. if (rpos < rend)
  385. *rpos++ = ':';
  386. rpos += wpa_snprintf_hex(rpos, rend - rpos, g->sres, 4);
  387. if (rpos < rend)
  388. *rpos++ = ':';
  389. rpos += wpa_snprintf_hex(rpos, rend - rpos, g->_rand, 16);
  390. count++;
  391. }
  392. if (count == 0) {
  393. printf("No GSM triplets found for %s\n", imsi);
  394. ret = snprintf(rpos, rend - rpos, " FAILURE");
  395. if (ret < 0 || ret >= rend - rpos)
  396. return;
  397. rpos += ret;
  398. }
  399. send:
  400. printf("Send: %s\n", reply);
  401. if (sendto(s, reply, rpos - reply, 0,
  402. (struct sockaddr *) from, fromlen) < 0)
  403. perror("send");
  404. }
  405. static void aka_req_auth(int s, struct sockaddr_un *from, socklen_t fromlen,
  406. char *imsi)
  407. {
  408. /* AKA-RESP-AUTH <IMSI> <RAND> <AUTN> <IK> <CK> <RES> */
  409. char reply[1000], *pos, *end;
  410. u8 _rand[EAP_AKA_RAND_LEN];
  411. u8 autn[EAP_AKA_AUTN_LEN];
  412. u8 ik[EAP_AKA_IK_LEN];
  413. u8 ck[EAP_AKA_CK_LEN];
  414. u8 res[EAP_AKA_RES_MAX_LEN];
  415. size_t res_len;
  416. int ret;
  417. struct milenage_parameters *m;
  418. m = get_milenage(imsi);
  419. if (m) {
  420. if (random_get_bytes(_rand, EAP_AKA_RAND_LEN) < 0)
  421. return;
  422. res_len = EAP_AKA_RES_MAX_LEN;
  423. inc_byte_array(m->sqn, 6);
  424. printf("AKA: Milenage with SQN=%02x%02x%02x%02x%02x%02x\n",
  425. m->sqn[0], m->sqn[1], m->sqn[2],
  426. m->sqn[3], m->sqn[4], m->sqn[5]);
  427. milenage_generate(m->opc, m->amf, m->ki, m->sqn, _rand,
  428. autn, ik, ck, res, &res_len);
  429. } else {
  430. printf("Unknown IMSI: %s\n", imsi);
  431. #ifdef AKA_USE_FIXED_TEST_VALUES
  432. printf("Using fixed test values for AKA\n");
  433. memset(_rand, '0', EAP_AKA_RAND_LEN);
  434. memset(autn, '1', EAP_AKA_AUTN_LEN);
  435. memset(ik, '3', EAP_AKA_IK_LEN);
  436. memset(ck, '4', EAP_AKA_CK_LEN);
  437. memset(res, '2', EAP_AKA_RES_MAX_LEN);
  438. res_len = EAP_AKA_RES_MAX_LEN;
  439. #else /* AKA_USE_FIXED_TEST_VALUES */
  440. return;
  441. #endif /* AKA_USE_FIXED_TEST_VALUES */
  442. }
  443. pos = reply;
  444. end = &reply[sizeof(reply)];
  445. ret = snprintf(pos, end - pos, "AKA-RESP-AUTH %s ", imsi);
  446. if (ret < 0 || ret >= end - pos)
  447. return;
  448. pos += ret;
  449. pos += wpa_snprintf_hex(pos, end - pos, _rand, EAP_AKA_RAND_LEN);
  450. *pos++ = ' ';
  451. pos += wpa_snprintf_hex(pos, end - pos, autn, EAP_AKA_AUTN_LEN);
  452. *pos++ = ' ';
  453. pos += wpa_snprintf_hex(pos, end - pos, ik, EAP_AKA_IK_LEN);
  454. *pos++ = ' ';
  455. pos += wpa_snprintf_hex(pos, end - pos, ck, EAP_AKA_CK_LEN);
  456. *pos++ = ' ';
  457. pos += wpa_snprintf_hex(pos, end - pos, res, res_len);
  458. printf("Send: %s\n", reply);
  459. if (sendto(s, reply, pos - reply, 0, (struct sockaddr *) from,
  460. fromlen) < 0)
  461. perror("send");
  462. }
  463. static void aka_auts(int s, struct sockaddr_un *from, socklen_t fromlen,
  464. char *imsi)
  465. {
  466. char *auts, *__rand;
  467. u8 _auts[EAP_AKA_AUTS_LEN], _rand[EAP_AKA_RAND_LEN], sqn[6];
  468. struct milenage_parameters *m;
  469. /* AKA-AUTS <IMSI> <AUTS> <RAND> */
  470. auts = strchr(imsi, ' ');
  471. if (auts == NULL)
  472. return;
  473. *auts++ = '\0';
  474. __rand = strchr(auts, ' ');
  475. if (__rand == NULL)
  476. return;
  477. *__rand++ = '\0';
  478. printf("AKA-AUTS: IMSI=%s AUTS=%s RAND=%s\n", imsi, auts, __rand);
  479. if (hexstr2bin(auts, _auts, EAP_AKA_AUTS_LEN) ||
  480. hexstr2bin(__rand, _rand, EAP_AKA_RAND_LEN)) {
  481. printf("Could not parse AUTS/RAND\n");
  482. return;
  483. }
  484. m = get_milenage(imsi);
  485. if (m == NULL) {
  486. printf("Unknown IMSI: %s\n", imsi);
  487. return;
  488. }
  489. if (milenage_auts(m->opc, m->ki, _rand, _auts, sqn)) {
  490. printf("AKA-AUTS: Incorrect MAC-S\n");
  491. } else {
  492. memcpy(m->sqn, sqn, 6);
  493. printf("AKA-AUTS: Re-synchronized: "
  494. "SQN=%02x%02x%02x%02x%02x%02x\n",
  495. sqn[0], sqn[1], sqn[2], sqn[3], sqn[4], sqn[5]);
  496. }
  497. }
  498. static int process(int s)
  499. {
  500. char buf[1000];
  501. struct sockaddr_un from;
  502. socklen_t fromlen;
  503. ssize_t res;
  504. fromlen = sizeof(from);
  505. res = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &from,
  506. &fromlen);
  507. if (res < 0) {
  508. perror("recvfrom");
  509. return -1;
  510. }
  511. if (res == 0)
  512. return 0;
  513. if ((size_t) res >= sizeof(buf))
  514. res = sizeof(buf) - 1;
  515. buf[res] = '\0';
  516. printf("Received: %s\n", buf);
  517. if (strncmp(buf, "SIM-REQ-AUTH ", 13) == 0)
  518. sim_req_auth(s, &from, fromlen, buf + 13);
  519. else if (strncmp(buf, "AKA-REQ-AUTH ", 13) == 0)
  520. aka_req_auth(s, &from, fromlen, buf + 13);
  521. else if (strncmp(buf, "AKA-AUTS ", 9) == 0)
  522. aka_auts(s, &from, fromlen, buf + 9);
  523. else
  524. printf("Unknown request: %s\n", buf);
  525. return 0;
  526. }
  527. static void cleanup(void)
  528. {
  529. struct gsm_triplet *g, *gprev;
  530. struct milenage_parameters *m, *prev;
  531. g = gsm_db;
  532. while (g) {
  533. gprev = g;
  534. g = g->next;
  535. free(gprev);
  536. }
  537. m = milenage_db;
  538. while (m) {
  539. prev = m;
  540. m = m->next;
  541. free(prev);
  542. }
  543. close(serv_sock);
  544. unlink(socket_path);
  545. }
  546. static void handle_term(int sig)
  547. {
  548. printf("Signal %d - terminate\n", sig);
  549. exit(0);
  550. }
  551. static void usage(void)
  552. {
  553. printf("HLR/AuC testing gateway for hostapd EAP-SIM/AKA "
  554. "database/authenticator\n"
  555. "Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>\n"
  556. "\n"
  557. "usage:\n"
  558. "hlr_auc_gw [-h] [-s<socket path>] [-g<triplet file>] "
  559. "[-m<milenage file>]\n"
  560. "\n"
  561. "options:\n"
  562. " -h = show this usage help\n"
  563. " -s<socket path> = path for UNIX domain socket\n"
  564. " (default: %s)\n"
  565. " -g<triplet file> = path for GSM authentication triplets\n"
  566. " -m<milenage file> = path for Milenage keys\n",
  567. default_socket_path);
  568. }
  569. int main(int argc, char *argv[])
  570. {
  571. int c;
  572. char *milenage_file = NULL;
  573. char *gsm_triplet_file = NULL;
  574. socket_path = default_socket_path;
  575. for (;;) {
  576. c = getopt(argc, argv, "g:hm:s:");
  577. if (c < 0)
  578. break;
  579. switch (c) {
  580. case 'g':
  581. gsm_triplet_file = optarg;
  582. break;
  583. case 'h':
  584. usage();
  585. return 0;
  586. case 'm':
  587. milenage_file = optarg;
  588. break;
  589. case 's':
  590. socket_path = optarg;
  591. break;
  592. default:
  593. usage();
  594. return -1;
  595. }
  596. }
  597. if (gsm_triplet_file && read_gsm_triplets(gsm_triplet_file) < 0)
  598. return -1;
  599. if (milenage_file && read_milenage(milenage_file) < 0)
  600. return -1;
  601. serv_sock = open_socket(socket_path);
  602. if (serv_sock < 0)
  603. return -1;
  604. printf("Listening for requests on %s\n", socket_path);
  605. atexit(cleanup);
  606. signal(SIGTERM, handle_term);
  607. signal(SIGINT, handle_term);
  608. for (;;)
  609. process(serv_sock);
  610. return 0;
  611. }