Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

eapol_test.c 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. /*
  2. * WPA Supplicant - test code
  3. * Copyright (c) 2003-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. * IEEE 802.1X Supplicant test code (to be used in place of wpa_supplicant.c.
  15. * Not used in production version.
  16. */
  17. #include "includes.h"
  18. #include <assert.h>
  19. #include "common.h"
  20. #include "config.h"
  21. #include "eapol_supp/eapol_supp_sm.h"
  22. #include "eap_peer/eap.h"
  23. #include "eap_server/eap_methods.h"
  24. #include "eloop.h"
  25. #include "rsn_supp/wpa.h"
  26. #include "eap_peer/eap_i.h"
  27. #include "wpa_supplicant_i.h"
  28. #include "radius/radius.h"
  29. #include "radius/radius_client.h"
  30. #include "ctrl_iface.h"
  31. #include "pcsc_funcs.h"
  32. extern int wpa_debug_level;
  33. extern int wpa_debug_show_keys;
  34. struct wpa_driver_ops *wpa_drivers[] = { NULL };
  35. struct extra_radius_attr {
  36. u8 type;
  37. char syntax;
  38. char *data;
  39. struct extra_radius_attr *next;
  40. };
  41. struct eapol_test_data {
  42. struct wpa_supplicant *wpa_s;
  43. int eapol_test_num_reauths;
  44. int no_mppe_keys;
  45. int num_mppe_ok, num_mppe_mismatch;
  46. u8 radius_identifier;
  47. struct radius_msg *last_recv_radius;
  48. struct in_addr own_ip_addr;
  49. struct radius_client_data *radius;
  50. struct hostapd_radius_servers *radius_conf;
  51. u8 *last_eap_radius; /* last received EAP Response from Authentication
  52. * Server */
  53. size_t last_eap_radius_len;
  54. u8 authenticator_pmk[PMK_LEN];
  55. size_t authenticator_pmk_len;
  56. int radius_access_accept_received;
  57. int radius_access_reject_received;
  58. int auth_timed_out;
  59. u8 *eap_identity;
  60. size_t eap_identity_len;
  61. char *connect_info;
  62. u8 own_addr[ETH_ALEN];
  63. struct extra_radius_attr *extra_attrs;
  64. };
  65. static struct eapol_test_data eapol_test;
  66. static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx);
  67. static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
  68. int level, const char *txt, size_t len)
  69. {
  70. if (addr)
  71. wpa_printf(MSG_DEBUG, "STA " MACSTR ": %s\n",
  72. MAC2STR(addr), txt);
  73. else
  74. wpa_printf(MSG_DEBUG, "%s", txt);
  75. }
  76. static int add_extra_attr(struct radius_msg *msg,
  77. struct extra_radius_attr *attr)
  78. {
  79. size_t len;
  80. char *pos;
  81. u32 val;
  82. char buf[128];
  83. switch (attr->syntax) {
  84. case 's':
  85. os_snprintf(buf, sizeof(buf), "%s", attr->data);
  86. len = os_strlen(buf);
  87. break;
  88. case 'n':
  89. buf[0] = '\0';
  90. len = 1;
  91. break;
  92. case 'x':
  93. pos = attr->data;
  94. if (pos[0] == '0' && pos[1] == 'x')
  95. pos += 2;
  96. len = os_strlen(pos);
  97. if ((len & 1) || (len / 2) > sizeof(buf)) {
  98. printf("Invalid extra attribute hexstring\n");
  99. return -1;
  100. }
  101. len /= 2;
  102. if (hexstr2bin(pos, (u8 *) buf, len) < 0) {
  103. printf("Invalid extra attribute hexstring\n");
  104. return -1;
  105. }
  106. break;
  107. case 'd':
  108. val = htonl(atoi(attr->data));
  109. os_memcpy(buf, &val, 4);
  110. len = 4;
  111. break;
  112. default:
  113. printf("Incorrect extra attribute syntax specification\n");
  114. return -1;
  115. }
  116. if (!radius_msg_add_attr(msg, attr->type, (u8 *) buf, len)) {
  117. printf("Could not add attribute %d\n", attr->type);
  118. return -1;
  119. }
  120. return 0;
  121. }
  122. static int add_extra_attrs(struct radius_msg *msg,
  123. struct extra_radius_attr *attrs)
  124. {
  125. struct extra_radius_attr *p;
  126. for (p = attrs; p; p = p->next) {
  127. if (add_extra_attr(msg, p) < 0)
  128. return -1;
  129. }
  130. return 0;
  131. }
  132. static struct extra_radius_attr *
  133. find_extra_attr(struct extra_radius_attr *attrs, u8 type)
  134. {
  135. struct extra_radius_attr *p;
  136. for (p = attrs; p; p = p->next) {
  137. if (p->type == type)
  138. return p;
  139. }
  140. return NULL;
  141. }
  142. static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
  143. const u8 *eap, size_t len)
  144. {
  145. struct radius_msg *msg;
  146. char buf[128];
  147. const struct eap_hdr *hdr;
  148. const u8 *pos;
  149. wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
  150. "packet");
  151. e->radius_identifier = radius_client_get_id(e->radius);
  152. msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
  153. e->radius_identifier);
  154. if (msg == NULL) {
  155. printf("Could not create net RADIUS packet\n");
  156. return;
  157. }
  158. radius_msg_make_authenticator(msg, (u8 *) e, sizeof(*e));
  159. hdr = (const struct eap_hdr *) eap;
  160. pos = (const u8 *) (hdr + 1);
  161. if (len > sizeof(*hdr) && hdr->code == EAP_CODE_RESPONSE &&
  162. pos[0] == EAP_TYPE_IDENTITY) {
  163. pos++;
  164. os_free(e->eap_identity);
  165. e->eap_identity_len = len - sizeof(*hdr) - 1;
  166. e->eap_identity = os_malloc(e->eap_identity_len);
  167. if (e->eap_identity) {
  168. os_memcpy(e->eap_identity, pos, e->eap_identity_len);
  169. wpa_hexdump(MSG_DEBUG, "Learned identity from "
  170. "EAP-Response-Identity",
  171. e->eap_identity, e->eap_identity_len);
  172. }
  173. }
  174. if (e->eap_identity &&
  175. !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
  176. e->eap_identity, e->eap_identity_len)) {
  177. printf("Could not add User-Name\n");
  178. goto fail;
  179. }
  180. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_NAS_IP_ADDRESS) &&
  181. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
  182. (u8 *) &e->own_ip_addr, 4)) {
  183. printf("Could not add NAS-IP-Address\n");
  184. goto fail;
  185. }
  186. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
  187. MAC2STR(e->wpa_s->own_addr));
  188. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_CALLING_STATION_ID)
  189. &&
  190. !radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
  191. (u8 *) buf, os_strlen(buf))) {
  192. printf("Could not add Calling-Station-Id\n");
  193. goto fail;
  194. }
  195. /* TODO: should probably check MTU from driver config; 2304 is max for
  196. * IEEE 802.11, but use 1400 to avoid problems with too large packets
  197. */
  198. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_FRAMED_MTU) &&
  199. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
  200. printf("Could not add Framed-MTU\n");
  201. goto fail;
  202. }
  203. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_NAS_PORT_TYPE) &&
  204. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
  205. RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
  206. printf("Could not add NAS-Port-Type\n");
  207. goto fail;
  208. }
  209. os_snprintf(buf, sizeof(buf), "%s", e->connect_info);
  210. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_CONNECT_INFO) &&
  211. !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
  212. (u8 *) buf, os_strlen(buf))) {
  213. printf("Could not add Connect-Info\n");
  214. goto fail;
  215. }
  216. if (add_extra_attrs(msg, e->extra_attrs) < 0)
  217. goto fail;
  218. if (eap && !radius_msg_add_eap(msg, eap, len)) {
  219. printf("Could not add EAP-Message\n");
  220. goto fail;
  221. }
  222. /* State attribute must be copied if and only if this packet is
  223. * Access-Request reply to the previous Access-Challenge */
  224. if (e->last_recv_radius &&
  225. radius_msg_get_hdr(e->last_recv_radius)->code ==
  226. RADIUS_CODE_ACCESS_CHALLENGE) {
  227. int res = radius_msg_copy_attr(msg, e->last_recv_radius,
  228. RADIUS_ATTR_STATE);
  229. if (res < 0) {
  230. printf("Could not copy State attribute from previous "
  231. "Access-Challenge\n");
  232. goto fail;
  233. }
  234. if (res > 0) {
  235. wpa_printf(MSG_DEBUG, " Copied RADIUS State "
  236. "Attribute");
  237. }
  238. }
  239. radius_client_send(e->radius, msg, RADIUS_AUTH, e->wpa_s->own_addr);
  240. return;
  241. fail:
  242. radius_msg_free(msg);
  243. }
  244. static int eapol_test_eapol_send(void *ctx, int type, const u8 *buf,
  245. size_t len)
  246. {
  247. /* struct wpa_supplicant *wpa_s = ctx; */
  248. printf("WPA: eapol_test_eapol_send(type=%d len=%lu)\n",
  249. type, (unsigned long) len);
  250. if (type == IEEE802_1X_TYPE_EAP_PACKET) {
  251. wpa_hexdump(MSG_DEBUG, "TX EAP -> RADIUS", buf, len);
  252. ieee802_1x_encapsulate_radius(&eapol_test, buf, len);
  253. }
  254. return 0;
  255. }
  256. static void eapol_test_set_config_blob(void *ctx,
  257. struct wpa_config_blob *blob)
  258. {
  259. struct wpa_supplicant *wpa_s = ctx;
  260. wpa_config_set_blob(wpa_s->conf, blob);
  261. }
  262. static const struct wpa_config_blob *
  263. eapol_test_get_config_blob(void *ctx, const char *name)
  264. {
  265. struct wpa_supplicant *wpa_s = ctx;
  266. return wpa_config_get_blob(wpa_s->conf, name);
  267. }
  268. static void eapol_test_eapol_done_cb(void *ctx)
  269. {
  270. printf("WPA: EAPOL processing complete\n");
  271. }
  272. static void eapol_sm_reauth(void *eloop_ctx, void *timeout_ctx)
  273. {
  274. struct eapol_test_data *e = eloop_ctx;
  275. printf("\n\n\n\n\neapol_test: Triggering EAP reauthentication\n\n");
  276. e->radius_access_accept_received = 0;
  277. send_eap_request_identity(e->wpa_s, NULL);
  278. }
  279. static int eapol_test_compare_pmk(struct eapol_test_data *e)
  280. {
  281. u8 pmk[PMK_LEN];
  282. int ret = 1;
  283. if (eapol_sm_get_key(e->wpa_s->eapol, pmk, PMK_LEN) == 0) {
  284. wpa_hexdump(MSG_DEBUG, "PMK from EAPOL", pmk, PMK_LEN);
  285. if (os_memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0) {
  286. printf("WARNING: PMK mismatch\n");
  287. wpa_hexdump(MSG_DEBUG, "PMK from AS",
  288. e->authenticator_pmk, PMK_LEN);
  289. } else if (e->radius_access_accept_received)
  290. ret = 0;
  291. } else if (e->authenticator_pmk_len == 16 &&
  292. eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
  293. wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
  294. if (os_memcmp(pmk, e->authenticator_pmk, 16) != 0) {
  295. printf("WARNING: PMK mismatch\n");
  296. wpa_hexdump(MSG_DEBUG, "PMK from AS",
  297. e->authenticator_pmk, 16);
  298. } else if (e->radius_access_accept_received)
  299. ret = 0;
  300. } else if (e->radius_access_accept_received && e->no_mppe_keys) {
  301. /* No keying material expected */
  302. ret = 0;
  303. }
  304. if (ret && !e->no_mppe_keys)
  305. e->num_mppe_mismatch++;
  306. else if (!e->no_mppe_keys)
  307. e->num_mppe_ok++;
  308. return ret;
  309. }
  310. static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
  311. {
  312. struct eapol_test_data *e = ctx;
  313. printf("eapol_sm_cb: success=%d\n", success);
  314. e->eapol_test_num_reauths--;
  315. if (e->eapol_test_num_reauths < 0)
  316. eloop_terminate();
  317. else {
  318. eapol_test_compare_pmk(e);
  319. eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
  320. }
  321. }
  322. static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
  323. struct wpa_ssid *ssid)
  324. {
  325. struct eapol_config eapol_conf;
  326. struct eapol_ctx *ctx;
  327. ctx = os_zalloc(sizeof(*ctx));
  328. if (ctx == NULL) {
  329. printf("Failed to allocate EAPOL context.\n");
  330. return -1;
  331. }
  332. ctx->ctx = wpa_s;
  333. ctx->msg_ctx = wpa_s;
  334. ctx->scard_ctx = wpa_s->scard;
  335. ctx->cb = eapol_sm_cb;
  336. ctx->cb_ctx = e;
  337. ctx->eapol_send_ctx = wpa_s;
  338. ctx->preauth = 0;
  339. ctx->eapol_done_cb = eapol_test_eapol_done_cb;
  340. ctx->eapol_send = eapol_test_eapol_send;
  341. ctx->set_config_blob = eapol_test_set_config_blob;
  342. ctx->get_config_blob = eapol_test_get_config_blob;
  343. ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
  344. ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
  345. ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
  346. wpa_s->eapol = eapol_sm_init(ctx);
  347. if (wpa_s->eapol == NULL) {
  348. os_free(ctx);
  349. printf("Failed to initialize EAPOL state machines.\n");
  350. return -1;
  351. }
  352. wpa_s->current_ssid = ssid;
  353. os_memset(&eapol_conf, 0, sizeof(eapol_conf));
  354. eapol_conf.accept_802_1x_keys = 1;
  355. eapol_conf.required_keys = 0;
  356. eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
  357. eapol_conf.workaround = ssid->eap_workaround;
  358. eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
  359. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  360. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  361. /* 802.1X::portControl = Auto */
  362. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  363. return 0;
  364. }
  365. static void test_eapol_clean(struct eapol_test_data *e,
  366. struct wpa_supplicant *wpa_s)
  367. {
  368. struct extra_radius_attr *p, *prev;
  369. radius_client_deinit(e->radius);
  370. os_free(e->last_eap_radius);
  371. radius_msg_free(e->last_recv_radius);
  372. e->last_recv_radius = NULL;
  373. os_free(e->eap_identity);
  374. e->eap_identity = NULL;
  375. eapol_sm_deinit(wpa_s->eapol);
  376. wpa_s->eapol = NULL;
  377. if (e->radius_conf && e->radius_conf->auth_server) {
  378. os_free(e->radius_conf->auth_server->shared_secret);
  379. os_free(e->radius_conf->auth_server);
  380. }
  381. os_free(e->radius_conf);
  382. e->radius_conf = NULL;
  383. scard_deinit(wpa_s->scard);
  384. if (wpa_s->ctrl_iface) {
  385. wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
  386. wpa_s->ctrl_iface = NULL;
  387. }
  388. wpa_config_free(wpa_s->conf);
  389. p = e->extra_attrs;
  390. while (p) {
  391. prev = p;
  392. p = p->next;
  393. os_free(prev);
  394. }
  395. }
  396. static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
  397. {
  398. struct wpa_supplicant *wpa_s = eloop_ctx;
  399. u8 buf[100], *pos;
  400. struct ieee802_1x_hdr *hdr;
  401. struct eap_hdr *eap;
  402. hdr = (struct ieee802_1x_hdr *) buf;
  403. hdr->version = EAPOL_VERSION;
  404. hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
  405. hdr->length = htons(5);
  406. eap = (struct eap_hdr *) (hdr + 1);
  407. eap->code = EAP_CODE_REQUEST;
  408. eap->identifier = 0;
  409. eap->length = htons(5);
  410. pos = (u8 *) (eap + 1);
  411. *pos = EAP_TYPE_IDENTITY;
  412. printf("Sending fake EAP-Request-Identity\n");
  413. eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
  414. sizeof(*hdr) + 5);
  415. }
  416. static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
  417. {
  418. struct eapol_test_data *e = eloop_ctx;
  419. printf("EAPOL test timed out\n");
  420. e->auth_timed_out = 1;
  421. eloop_terminate();
  422. }
  423. static char *eap_type_text(u8 type)
  424. {
  425. switch (type) {
  426. case EAP_TYPE_IDENTITY: return "Identity";
  427. case EAP_TYPE_NOTIFICATION: return "Notification";
  428. case EAP_TYPE_NAK: return "Nak";
  429. case EAP_TYPE_TLS: return "TLS";
  430. case EAP_TYPE_TTLS: return "TTLS";
  431. case EAP_TYPE_PEAP: return "PEAP";
  432. case EAP_TYPE_SIM: return "SIM";
  433. case EAP_TYPE_GTC: return "GTC";
  434. case EAP_TYPE_MD5: return "MD5";
  435. case EAP_TYPE_OTP: return "OTP";
  436. case EAP_TYPE_FAST: return "FAST";
  437. case EAP_TYPE_SAKE: return "SAKE";
  438. case EAP_TYPE_PSK: return "PSK";
  439. default: return "Unknown";
  440. }
  441. }
  442. static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
  443. {
  444. u8 *eap;
  445. size_t len;
  446. struct eap_hdr *hdr;
  447. int eap_type = -1;
  448. char buf[64];
  449. struct radius_msg *msg;
  450. if (e->last_recv_radius == NULL)
  451. return;
  452. msg = e->last_recv_radius;
  453. eap = radius_msg_get_eap(msg, &len);
  454. if (eap == NULL) {
  455. /* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
  456. * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
  457. * attribute */
  458. wpa_printf(MSG_DEBUG, "could not extract "
  459. "EAP-Message from RADIUS message");
  460. os_free(e->last_eap_radius);
  461. e->last_eap_radius = NULL;
  462. e->last_eap_radius_len = 0;
  463. return;
  464. }
  465. if (len < sizeof(*hdr)) {
  466. wpa_printf(MSG_DEBUG, "too short EAP packet "
  467. "received from authentication server");
  468. os_free(eap);
  469. return;
  470. }
  471. if (len > sizeof(*hdr))
  472. eap_type = eap[sizeof(*hdr)];
  473. hdr = (struct eap_hdr *) eap;
  474. switch (hdr->code) {
  475. case EAP_CODE_REQUEST:
  476. os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
  477. eap_type >= 0 ? eap_type_text(eap_type) : "??",
  478. eap_type);
  479. break;
  480. case EAP_CODE_RESPONSE:
  481. os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
  482. eap_type >= 0 ? eap_type_text(eap_type) : "??",
  483. eap_type);
  484. break;
  485. case EAP_CODE_SUCCESS:
  486. os_strlcpy(buf, "EAP Success", sizeof(buf));
  487. /* LEAP uses EAP Success within an authentication, so must not
  488. * stop here with eloop_terminate(); */
  489. break;
  490. case EAP_CODE_FAILURE:
  491. os_strlcpy(buf, "EAP Failure", sizeof(buf));
  492. eloop_terminate();
  493. break;
  494. default:
  495. os_strlcpy(buf, "unknown EAP code", sizeof(buf));
  496. wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
  497. break;
  498. }
  499. wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
  500. "id=%d len=%d) from RADIUS server: %s",
  501. hdr->code, hdr->identifier, ntohs(hdr->length), buf);
  502. /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
  503. os_free(e->last_eap_radius);
  504. e->last_eap_radius = eap;
  505. e->last_eap_radius_len = len;
  506. {
  507. struct ieee802_1x_hdr *dot1x;
  508. dot1x = os_malloc(sizeof(*dot1x) + len);
  509. assert(dot1x != NULL);
  510. dot1x->version = EAPOL_VERSION;
  511. dot1x->type = IEEE802_1X_TYPE_EAP_PACKET;
  512. dot1x->length = htons(len);
  513. os_memcpy((u8 *) (dot1x + 1), eap, len);
  514. eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
  515. (u8 *) dot1x, sizeof(*dot1x) + len);
  516. os_free(dot1x);
  517. }
  518. }
  519. static void ieee802_1x_get_keys(struct eapol_test_data *e,
  520. struct radius_msg *msg, struct radius_msg *req,
  521. const u8 *shared_secret,
  522. size_t shared_secret_len)
  523. {
  524. struct radius_ms_mppe_keys *keys;
  525. keys = radius_msg_get_ms_keys(msg, req, shared_secret,
  526. shared_secret_len);
  527. if (keys && keys->send == NULL && keys->recv == NULL) {
  528. os_free(keys);
  529. keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
  530. shared_secret_len);
  531. }
  532. if (keys) {
  533. if (keys->send) {
  534. wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
  535. keys->send, keys->send_len);
  536. }
  537. if (keys->recv) {
  538. wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
  539. keys->recv, keys->recv_len);
  540. e->authenticator_pmk_len =
  541. keys->recv_len > PMK_LEN ? PMK_LEN :
  542. keys->recv_len;
  543. os_memcpy(e->authenticator_pmk, keys->recv,
  544. e->authenticator_pmk_len);
  545. if (e->authenticator_pmk_len == 16 && keys->send &&
  546. keys->send_len == 16) {
  547. /* MS-CHAP-v2 derives 16 octet keys */
  548. wpa_printf(MSG_DEBUG, "Use MS-MPPE-Send-Key "
  549. "to extend PMK to 32 octets");
  550. os_memcpy(e->authenticator_pmk +
  551. e->authenticator_pmk_len,
  552. keys->send, keys->send_len);
  553. e->authenticator_pmk_len += keys->send_len;
  554. }
  555. }
  556. os_free(keys->send);
  557. os_free(keys->recv);
  558. os_free(keys);
  559. }
  560. }
  561. /* Process the RADIUS frames from Authentication Server */
  562. static RadiusRxResult
  563. ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
  564. const u8 *shared_secret, size_t shared_secret_len,
  565. void *data)
  566. {
  567. struct eapol_test_data *e = data;
  568. struct radius_hdr *hdr = radius_msg_get_hdr(msg);
  569. /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
  570. * present when packet contains an EAP-Message attribute */
  571. if (hdr->code == RADIUS_CODE_ACCESS_REJECT &&
  572. radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
  573. 0) < 0 &&
  574. radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
  575. wpa_printf(MSG_DEBUG, "Allowing RADIUS "
  576. "Access-Reject without Message-Authenticator "
  577. "since it does not include EAP-Message\n");
  578. } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
  579. req, 1)) {
  580. printf("Incoming RADIUS packet did not have correct "
  581. "Message-Authenticator - dropped\n");
  582. return RADIUS_RX_UNKNOWN;
  583. }
  584. if (hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
  585. hdr->code != RADIUS_CODE_ACCESS_REJECT &&
  586. hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
  587. printf("Unknown RADIUS message code\n");
  588. return RADIUS_RX_UNKNOWN;
  589. }
  590. e->radius_identifier = -1;
  591. wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
  592. radius_msg_free(e->last_recv_radius);
  593. e->last_recv_radius = msg;
  594. switch (hdr->code) {
  595. case RADIUS_CODE_ACCESS_ACCEPT:
  596. e->radius_access_accept_received = 1;
  597. ieee802_1x_get_keys(e, msg, req, shared_secret,
  598. shared_secret_len);
  599. break;
  600. case RADIUS_CODE_ACCESS_REJECT:
  601. e->radius_access_reject_received = 1;
  602. break;
  603. }
  604. ieee802_1x_decapsulate_radius(e);
  605. if ((hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
  606. e->eapol_test_num_reauths < 0) ||
  607. hdr->code == RADIUS_CODE_ACCESS_REJECT) {
  608. eloop_terminate();
  609. }
  610. return RADIUS_RX_QUEUED;
  611. }
  612. static void wpa_init_conf(struct eapol_test_data *e,
  613. struct wpa_supplicant *wpa_s, const char *authsrv,
  614. int port, const char *secret,
  615. const char *cli_addr)
  616. {
  617. struct hostapd_radius_server *as;
  618. int res;
  619. wpa_s->bssid[5] = 1;
  620. os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN);
  621. e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
  622. os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
  623. e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers));
  624. assert(e->radius_conf != NULL);
  625. e->radius_conf->num_auth_servers = 1;
  626. as = os_zalloc(sizeof(struct hostapd_radius_server));
  627. assert(as != NULL);
  628. #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
  629. {
  630. int a[4];
  631. u8 *pos;
  632. sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
  633. pos = (u8 *) &as->addr.u.v4;
  634. *pos++ = a[0];
  635. *pos++ = a[1];
  636. *pos++ = a[2];
  637. *pos++ = a[3];
  638. }
  639. #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
  640. inet_aton(authsrv, &as->addr.u.v4);
  641. #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
  642. as->addr.af = AF_INET;
  643. as->port = port;
  644. as->shared_secret = (u8 *) os_strdup(secret);
  645. as->shared_secret_len = os_strlen(secret);
  646. e->radius_conf->auth_server = as;
  647. e->radius_conf->auth_servers = as;
  648. e->radius_conf->msg_dumps = 1;
  649. if (cli_addr) {
  650. if (hostapd_parse_ip_addr(cli_addr,
  651. &e->radius_conf->client_addr) == 0)
  652. e->radius_conf->force_client_addr = 1;
  653. else {
  654. wpa_printf(MSG_ERROR, "Invalid IP address '%s'",
  655. cli_addr);
  656. assert(0);
  657. }
  658. }
  659. e->radius = radius_client_init(wpa_s, e->radius_conf);
  660. assert(e->radius != NULL);
  661. res = radius_client_register(e->radius, RADIUS_AUTH,
  662. ieee802_1x_receive_auth, e);
  663. assert(res == 0);
  664. }
  665. static int scard_test(void)
  666. {
  667. struct scard_data *scard;
  668. size_t len;
  669. char imsi[20];
  670. unsigned char _rand[16];
  671. #ifdef PCSC_FUNCS
  672. unsigned char sres[4];
  673. unsigned char kc[8];
  674. #endif /* PCSC_FUNCS */
  675. #define num_triplets 5
  676. unsigned char rand_[num_triplets][16];
  677. unsigned char sres_[num_triplets][4];
  678. unsigned char kc_[num_triplets][8];
  679. int i, res;
  680. size_t j;
  681. #define AKA_RAND_LEN 16
  682. #define AKA_AUTN_LEN 16
  683. #define AKA_AUTS_LEN 14
  684. #define RES_MAX_LEN 16
  685. #define IK_LEN 16
  686. #define CK_LEN 16
  687. unsigned char aka_rand[AKA_RAND_LEN];
  688. unsigned char aka_autn[AKA_AUTN_LEN];
  689. unsigned char aka_auts[AKA_AUTS_LEN];
  690. unsigned char aka_res[RES_MAX_LEN];
  691. size_t aka_res_len;
  692. unsigned char aka_ik[IK_LEN];
  693. unsigned char aka_ck[CK_LEN];
  694. scard = scard_init(SCARD_TRY_BOTH);
  695. if (scard == NULL)
  696. return -1;
  697. if (scard_set_pin(scard, "1234")) {
  698. wpa_printf(MSG_WARNING, "PIN validation failed");
  699. scard_deinit(scard);
  700. return -1;
  701. }
  702. len = sizeof(imsi);
  703. if (scard_get_imsi(scard, imsi, &len))
  704. goto failed;
  705. wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
  706. /* NOTE: Permanent Username: 1 | IMSI */
  707. os_memset(_rand, 0, sizeof(_rand));
  708. if (scard_gsm_auth(scard, _rand, sres, kc))
  709. goto failed;
  710. os_memset(_rand, 0xff, sizeof(_rand));
  711. if (scard_gsm_auth(scard, _rand, sres, kc))
  712. goto failed;
  713. for (i = 0; i < num_triplets; i++) {
  714. os_memset(rand_[i], i, sizeof(rand_[i]));
  715. if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
  716. goto failed;
  717. }
  718. for (i = 0; i < num_triplets; i++) {
  719. printf("1");
  720. for (j = 0; j < len; j++)
  721. printf("%c", imsi[j]);
  722. printf(",");
  723. for (j = 0; j < 16; j++)
  724. printf("%02X", rand_[i][j]);
  725. printf(",");
  726. for (j = 0; j < 4; j++)
  727. printf("%02X", sres_[i][j]);
  728. printf(",");
  729. for (j = 0; j < 8; j++)
  730. printf("%02X", kc_[i][j]);
  731. printf("\n");
  732. }
  733. wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
  734. /* seq 39 (0x28) */
  735. os_memset(aka_rand, 0xaa, 16);
  736. os_memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
  737. "\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
  738. res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
  739. aka_ik, aka_ck, aka_auts);
  740. if (res == 0) {
  741. wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
  742. wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
  743. wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
  744. wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
  745. } else if (res == -2) {
  746. wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
  747. "failure");
  748. wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
  749. } else {
  750. wpa_printf(MSG_DEBUG, "UMTS auth failed");
  751. }
  752. failed:
  753. scard_deinit(scard);
  754. return 0;
  755. #undef num_triplets
  756. }
  757. static int scard_get_triplets(int argc, char *argv[])
  758. {
  759. struct scard_data *scard;
  760. size_t len;
  761. char imsi[20];
  762. unsigned char _rand[16];
  763. unsigned char sres[4];
  764. unsigned char kc[8];
  765. int num_triplets;
  766. int i;
  767. size_t j;
  768. if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
  769. printf("invalid parameters for sim command\n");
  770. return -1;
  771. }
  772. if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) {
  773. /* disable debug output */
  774. wpa_debug_level = 99;
  775. }
  776. scard = scard_init(SCARD_GSM_SIM_ONLY);
  777. if (scard == NULL) {
  778. printf("Failed to open smartcard connection\n");
  779. return -1;
  780. }
  781. if (scard_set_pin(scard, argv[0])) {
  782. wpa_printf(MSG_WARNING, "PIN validation failed");
  783. scard_deinit(scard);
  784. return -1;
  785. }
  786. len = sizeof(imsi);
  787. if (scard_get_imsi(scard, imsi, &len)) {
  788. scard_deinit(scard);
  789. return -1;
  790. }
  791. for (i = 0; i < num_triplets; i++) {
  792. os_memset(_rand, i, sizeof(_rand));
  793. if (scard_gsm_auth(scard, _rand, sres, kc))
  794. break;
  795. /* IMSI:Kc:SRES:RAND */
  796. for (j = 0; j < len; j++)
  797. printf("%c", imsi[j]);
  798. printf(":");
  799. for (j = 0; j < 8; j++)
  800. printf("%02X", kc[j]);
  801. printf(":");
  802. for (j = 0; j < 4; j++)
  803. printf("%02X", sres[j]);
  804. printf(":");
  805. for (j = 0; j < 16; j++)
  806. printf("%02X", _rand[j]);
  807. printf("\n");
  808. }
  809. scard_deinit(scard);
  810. return 0;
  811. }
  812. static void eapol_test_terminate(int sig, void *signal_ctx)
  813. {
  814. struct wpa_supplicant *wpa_s = signal_ctx;
  815. wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
  816. eloop_terminate();
  817. }
  818. static void usage(void)
  819. {
  820. printf("usage:\n"
  821. "eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] "
  822. "[-s<AS secret>]\\\n"
  823. " [-r<count>] [-t<timeout>] [-C<Connect-Info>] \\\n"
  824. " [-M<client MAC address>] \\\n"
  825. " [-N<attr spec>] \\\n"
  826. " [-A<client IP>]\n"
  827. "eapol_test scard\n"
  828. "eapol_test sim <PIN> <num triplets> [debug]\n"
  829. "\n");
  830. printf("options:\n"
  831. " -c<conf> = configuration file\n"
  832. " -a<AS IP> = IP address of the authentication server, "
  833. "default 127.0.0.1\n"
  834. " -p<AS port> = UDP port of the authentication server, "
  835. "default 1812\n"
  836. " -s<AS secret> = shared secret with the authentication "
  837. "server, default 'radius'\n"
  838. " -A<client IP> = IP address of the client, default: select "
  839. "automatically\n"
  840. " -r<count> = number of re-authentications\n"
  841. " -W = wait for a control interface monitor before starting\n"
  842. " -S = save configuration after authentication\n"
  843. " -n = no MPPE keys expected\n"
  844. " -t<timeout> = sets timeout in seconds (default: 30 s)\n"
  845. " -C<Connect-Info> = RADIUS Connect-Info (default: "
  846. "CONNECT 11Mbps 802.11b)\n"
  847. " -M<client MAC address> = Set own MAC address "
  848. "(Calling-Station-Id,\n"
  849. " default: 02:00:00:00:00:01)\n"
  850. " -N<attr spec> = send arbitrary attribute specified by:\n"
  851. " attr_id:syntax:value or attr_id\n"
  852. " attr_id - number id of the attribute\n"
  853. " syntax - one of: s, d, x\n"
  854. " s = string\n"
  855. " d = integer\n"
  856. " x = octet string\n"
  857. " value - attribute value.\n"
  858. " When only attr_id is specified, NULL will be used as "
  859. "value.\n"
  860. " Multiple attributes can be specified by using the "
  861. "option several times.\n");
  862. }
  863. int main(int argc, char *argv[])
  864. {
  865. struct wpa_supplicant wpa_s;
  866. int c, ret = 1, wait_for_monitor = 0, save_config = 0;
  867. char *as_addr = "127.0.0.1";
  868. int as_port = 1812;
  869. char *as_secret = "radius";
  870. char *cli_addr = NULL;
  871. char *conf = NULL;
  872. int timeout = 30;
  873. char *pos;
  874. struct extra_radius_attr *p = NULL, *p1;
  875. if (os_program_init())
  876. return -1;
  877. hostapd_logger_register_cb(hostapd_logger_cb);
  878. os_memset(&eapol_test, 0, sizeof(eapol_test));
  879. eapol_test.connect_info = "CONNECT 11Mbps 802.11b";
  880. os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN);
  881. wpa_debug_level = 0;
  882. wpa_debug_show_keys = 1;
  883. for (;;) {
  884. c = getopt(argc, argv, "a:A:c:C:M:nN:p:r:s:St:W");
  885. if (c < 0)
  886. break;
  887. switch (c) {
  888. case 'a':
  889. as_addr = optarg;
  890. break;
  891. case 'A':
  892. cli_addr = optarg;
  893. break;
  894. case 'c':
  895. conf = optarg;
  896. break;
  897. case 'C':
  898. eapol_test.connect_info = optarg;
  899. break;
  900. case 'M':
  901. if (hwaddr_aton(optarg, eapol_test.own_addr)) {
  902. usage();
  903. return -1;
  904. }
  905. break;
  906. case 'n':
  907. eapol_test.no_mppe_keys++;
  908. break;
  909. case 'p':
  910. as_port = atoi(optarg);
  911. break;
  912. case 'r':
  913. eapol_test.eapol_test_num_reauths = atoi(optarg);
  914. break;
  915. case 's':
  916. as_secret = optarg;
  917. break;
  918. case 'S':
  919. save_config++;
  920. break;
  921. case 't':
  922. timeout = atoi(optarg);
  923. break;
  924. case 'W':
  925. wait_for_monitor++;
  926. break;
  927. case 'N':
  928. p1 = os_zalloc(sizeof(p1));
  929. if (p1 == NULL)
  930. break;
  931. if (!p)
  932. eapol_test.extra_attrs = p1;
  933. else
  934. p->next = p1;
  935. p = p1;
  936. p->type = atoi(optarg);
  937. pos = os_strchr(optarg, ':');
  938. if (pos == NULL) {
  939. p->syntax = 'n';
  940. p->data = NULL;
  941. break;
  942. }
  943. pos++;
  944. if (pos[0] == '\0' || pos[1] != ':') {
  945. printf("Incorrect format of attribute "
  946. "specification\n");
  947. break;
  948. }
  949. p->syntax = pos[0];
  950. p->data = pos + 2;
  951. break;
  952. default:
  953. usage();
  954. return -1;
  955. }
  956. }
  957. if (argc > optind && os_strcmp(argv[optind], "scard") == 0) {
  958. return scard_test();
  959. }
  960. if (argc > optind && os_strcmp(argv[optind], "sim") == 0) {
  961. return scard_get_triplets(argc - optind - 1,
  962. &argv[optind + 1]);
  963. }
  964. if (conf == NULL) {
  965. usage();
  966. printf("Configuration file is required.\n");
  967. return -1;
  968. }
  969. if (eap_register_methods()) {
  970. wpa_printf(MSG_ERROR, "Failed to register EAP methods");
  971. return -1;
  972. }
  973. if (eloop_init()) {
  974. wpa_printf(MSG_ERROR, "Failed to initialize event loop");
  975. return -1;
  976. }
  977. os_memset(&wpa_s, 0, sizeof(wpa_s));
  978. eapol_test.wpa_s = &wpa_s;
  979. wpa_s.conf = wpa_config_read(conf);
  980. if (wpa_s.conf == NULL) {
  981. printf("Failed to parse configuration file '%s'.\n", conf);
  982. return -1;
  983. }
  984. if (wpa_s.conf->ssid == NULL) {
  985. printf("No networks defined.\n");
  986. return -1;
  987. }
  988. wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret,
  989. cli_addr);
  990. wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s);
  991. if (wpa_s.ctrl_iface == NULL) {
  992. printf("Failed to initialize control interface '%s'.\n"
  993. "You may have another eapol_test process already "
  994. "running or the file was\n"
  995. "left by an unclean termination of eapol_test in "
  996. "which case you will need\n"
  997. "to manually remove this file before starting "
  998. "eapol_test again.\n",
  999. wpa_s.conf->ctrl_interface);
  1000. return -1;
  1001. }
  1002. if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
  1003. return -1;
  1004. if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
  1005. return -1;
  1006. if (wait_for_monitor)
  1007. wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface);
  1008. eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
  1009. NULL);
  1010. eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
  1011. eloop_register_signal_terminate(eapol_test_terminate, &wpa_s);
  1012. eloop_register_signal_reconfig(eapol_test_terminate, &wpa_s);
  1013. eloop_run();
  1014. eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL);
  1015. eloop_cancel_timeout(eapol_sm_reauth, &eapol_test, NULL);
  1016. if (eapol_test_compare_pmk(&eapol_test) == 0 ||
  1017. eapol_test.no_mppe_keys)
  1018. ret = 0;
  1019. if (eapol_test.auth_timed_out)
  1020. ret = -2;
  1021. if (eapol_test.radius_access_reject_received)
  1022. ret = -3;
  1023. if (save_config)
  1024. wpa_config_write(conf, wpa_s.conf);
  1025. test_eapol_clean(&eapol_test, &wpa_s);
  1026. eap_peer_unregister_methods();
  1027. #ifdef CONFIG_AP
  1028. eap_server_unregister_methods();
  1029. #endif /* CONFIG_AP */
  1030. eloop_destroy();
  1031. printf("MPPE keys OK: %d mismatch: %d\n",
  1032. eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
  1033. if (eapol_test.num_mppe_mismatch)
  1034. ret = -4;
  1035. if (ret)
  1036. printf("FAILURE\n");
  1037. else
  1038. printf("SUCCESS\n");
  1039. os_program_deinit();
  1040. return ret;
  1041. }